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"
67 #include "gdb_string.h"
68 #include "gdb_assert.h"
69 #include <sys/types.h>
76 #define MAP_FAILED ((void *) -1)
80 typedef struct symbol
*symbolp
;
83 /* When non-zero, dump DIEs after they are read in. */
84 static int dwarf2_die_debug
= 0;
86 /* When non-zero, cross-check physname against demangler. */
87 static int check_physname
= 0;
89 /* When non-zero, do not reject deprecated .gdb_index sections. */
90 int use_deprecated_index_sections
= 0;
94 /* When set, the file that we're processing is known to have debugging
95 info for C++ namespaces. GCC 3.3.x did not produce this information,
96 but later versions do. */
98 static int processing_has_namespace_info
;
100 static const struct objfile_data
*dwarf2_objfile_data_key
;
102 struct dwarf2_section_info
107 /* Not NULL if the section was actually mmapped. */
109 /* Page aligned size of mmapped area. */
110 bfd_size_type map_len
;
111 /* True if we have tried to read this section. */
115 typedef struct dwarf2_section_info dwarf2_section_info_def
;
116 DEF_VEC_O (dwarf2_section_info_def
);
118 /* All offsets in the index are of this type. It must be
119 architecture-independent. */
120 typedef uint32_t offset_type
;
122 DEF_VEC_I (offset_type
);
124 /* A description of the mapped index. The file format is described in
125 a comment by the code that writes the index. */
128 /* Index data format version. */
131 /* The total length of the buffer. */
134 /* A pointer to the address table data. */
135 const gdb_byte
*address_table
;
137 /* Size of the address table data in bytes. */
138 offset_type address_table_size
;
140 /* The symbol table, implemented as a hash table. */
141 const offset_type
*symbol_table
;
143 /* Size in slots, each slot is 2 offset_types. */
144 offset_type symbol_table_slots
;
146 /* A pointer to the constant pool. */
147 const char *constant_pool
;
150 /* Collection of data recorded per objfile.
151 This hangs off of dwarf2_objfile_data_key. */
153 struct dwarf2_per_objfile
155 struct dwarf2_section_info info
;
156 struct dwarf2_section_info abbrev
;
157 struct dwarf2_section_info line
;
158 struct dwarf2_section_info loc
;
159 struct dwarf2_section_info macinfo
;
160 struct dwarf2_section_info macro
;
161 struct dwarf2_section_info str
;
162 struct dwarf2_section_info ranges
;
163 struct dwarf2_section_info frame
;
164 struct dwarf2_section_info eh_frame
;
165 struct dwarf2_section_info gdb_index
;
167 VEC (dwarf2_section_info_def
) *types
;
170 struct objfile
*objfile
;
172 /* Table of all the compilation units. This is used to locate
173 the target compilation unit of a particular reference. */
174 struct dwarf2_per_cu_data
**all_comp_units
;
176 /* The number of compilation units in ALL_COMP_UNITS. */
179 /* The number of .debug_types-related CUs. */
182 /* The .debug_types-related CUs (TUs). */
183 struct dwarf2_per_cu_data
**all_type_units
;
185 /* A chain of compilation units that are currently read in, so that
186 they can be freed later. */
187 struct dwarf2_per_cu_data
*read_in_chain
;
189 /* A table mapping .debug_types signatures to its signatured_type entry.
190 This is NULL if the .debug_types section hasn't been read in yet. */
191 htab_t signatured_types
;
193 /* A flag indicating wether this objfile has a section loaded at a
195 int has_section_at_zero
;
197 /* True if we are using the mapped index,
198 or we are faking it for OBJF_READNOW's sake. */
199 unsigned char using_index
;
201 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
202 struct mapped_index
*index_table
;
204 /* When using index_table, this keeps track of all quick_file_names entries.
205 TUs can share line table entries with CUs or other TUs, and there can be
206 a lot more TUs than unique line tables, so we maintain a separate table
207 of all line table entries to support the sharing. */
208 htab_t quick_file_names_table
;
210 /* Set during partial symbol reading, to prevent queueing of full
212 int reading_partial_symbols
;
214 /* Table mapping type DIEs to their struct type *.
215 This is NULL if not allocated yet.
216 The mapping is done via (CU/TU signature + DIE offset) -> type. */
217 htab_t die_type_hash
;
220 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
222 /* Default names of the debugging sections. */
224 /* Note that if the debugging section has been compressed, it might
225 have a name like .zdebug_info. */
227 static const struct dwarf2_debug_sections dwarf2_elf_names
=
229 { ".debug_info", ".zdebug_info" },
230 { ".debug_abbrev", ".zdebug_abbrev" },
231 { ".debug_line", ".zdebug_line" },
232 { ".debug_loc", ".zdebug_loc" },
233 { ".debug_macinfo", ".zdebug_macinfo" },
234 { ".debug_macro", ".zdebug_macro" },
235 { ".debug_str", ".zdebug_str" },
236 { ".debug_ranges", ".zdebug_ranges" },
237 { ".debug_types", ".zdebug_types" },
238 { ".debug_frame", ".zdebug_frame" },
239 { ".eh_frame", NULL
},
240 { ".gdb_index", ".zgdb_index" },
244 /* local data types */
246 /* We hold several abbreviation tables in memory at the same time. */
247 #ifndef ABBREV_HASH_SIZE
248 #define ABBREV_HASH_SIZE 121
251 /* The data in a compilation unit header, after target2host
252 translation, looks like this. */
253 struct comp_unit_head
257 unsigned char addr_size
;
258 unsigned char signed_addr_p
;
259 sect_offset abbrev_offset
;
261 /* Size of file offsets; either 4 or 8. */
262 unsigned int offset_size
;
264 /* Size of the length field; either 4 or 12. */
265 unsigned int initial_length_size
;
267 /* Offset to the first byte of this compilation unit header in the
268 .debug_info section, for resolving relative reference dies. */
271 /* Offset to first die in this cu from the start of the cu.
272 This will be the first byte following the compilation unit header. */
273 cu_offset first_die_offset
;
276 /* Type used for delaying computation of method physnames.
277 See comments for compute_delayed_physnames. */
278 struct delayed_method_info
280 /* The type to which the method is attached, i.e., its parent class. */
283 /* The index of the method in the type's function fieldlists. */
286 /* The index of the method in the fieldlist. */
289 /* The name of the DIE. */
292 /* The DIE associated with this method. */
293 struct die_info
*die
;
296 typedef struct delayed_method_info delayed_method_info
;
297 DEF_VEC_O (delayed_method_info
);
299 /* Internal state when decoding a particular compilation unit. */
302 /* The objfile containing this compilation unit. */
303 struct objfile
*objfile
;
305 /* The header of the compilation unit. */
306 struct comp_unit_head header
;
308 /* Base address of this compilation unit. */
309 CORE_ADDR base_address
;
311 /* Non-zero if base_address has been set. */
314 /* The language we are debugging. */
315 enum language language
;
316 const struct language_defn
*language_defn
;
318 const char *producer
;
320 /* The generic symbol table building routines have separate lists for
321 file scope symbols and all all other scopes (local scopes). So
322 we need to select the right one to pass to add_symbol_to_list().
323 We do it by keeping a pointer to the correct list in list_in_scope.
325 FIXME: The original dwarf code just treated the file scope as the
326 first local scope, and all other local scopes as nested local
327 scopes, and worked fine. Check to see if we really need to
328 distinguish these in buildsym.c. */
329 struct pending
**list_in_scope
;
331 /* DWARF abbreviation table associated with this compilation unit. */
332 struct abbrev_info
**dwarf2_abbrevs
;
334 /* Storage for the abbrev table. */
335 struct obstack abbrev_obstack
;
337 /* Hash table holding all the loaded partial DIEs
338 with partial_die->offset.SECT_OFF as hash. */
341 /* Storage for things with the same lifetime as this read-in compilation
342 unit, including partial DIEs. */
343 struct obstack comp_unit_obstack
;
345 /* When multiple dwarf2_cu structures are living in memory, this field
346 chains them all together, so that they can be released efficiently.
347 We will probably also want a generation counter so that most-recently-used
348 compilation units are cached... */
349 struct dwarf2_per_cu_data
*read_in_chain
;
351 /* Backchain to our per_cu entry if the tree has been built. */
352 struct dwarf2_per_cu_data
*per_cu
;
354 /* How many compilation units ago was this CU last referenced? */
357 /* A hash table of DIE cu_offset for following references with
358 die_info->offset.sect_off as hash. */
361 /* Full DIEs if read in. */
362 struct die_info
*dies
;
364 /* A set of pointers to dwarf2_per_cu_data objects for compilation
365 units referenced by this one. Only set during full symbol processing;
366 partial symbol tables do not have dependencies. */
369 /* Header data from the line table, during full symbol processing. */
370 struct line_header
*line_header
;
372 /* A list of methods which need to have physnames computed
373 after all type information has been read. */
374 VEC (delayed_method_info
) *method_list
;
376 /* To be copied to symtab->call_site_htab. */
377 htab_t call_site_htab
;
379 /* Mark used when releasing cached dies. */
380 unsigned int mark
: 1;
382 /* This CU references .debug_loc. See the symtab->locations_valid field.
383 This test is imperfect as there may exist optimized debug code not using
384 any location list and still facing inlining issues if handled as
385 unoptimized code. For a future better test see GCC PR other/32998. */
386 unsigned int has_loclist
: 1;
388 /* These cache the results of producer_is_gxx_lt_4_6.
389 CHECKED_PRODUCER is set if PRODUCER_IS_GXX_LT_4_6 is valid. This
390 information is cached because profiling CU expansion showed
391 excessive time spent in producer_is_gxx_lt_4_6. */
392 unsigned int checked_producer
: 1;
393 unsigned int producer_is_gxx_lt_4_6
: 1;
396 /* Persistent data held for a compilation unit, even when not
397 processing it. We put a pointer to this structure in the
398 read_symtab_private field of the psymtab. */
400 struct dwarf2_per_cu_data
402 /* The start offset and length of this compilation unit. 2**29-1
403 bytes should suffice to store the length of any compilation unit
404 - if it doesn't, GDB will fall over anyway.
405 NOTE: Unlike comp_unit_head.length, this length includes
406 initial_length_size. */
408 unsigned int length
: 29;
410 /* Flag indicating this compilation unit will be read in before
411 any of the current compilation units are processed. */
412 unsigned int queued
: 1;
414 /* This flag will be set when reading partial DIEs if we need to load
415 absolutely all DIEs for this compilation unit, instead of just the ones
416 we think are interesting. It gets set if we look for a DIE in the
417 hash table and don't find it. */
418 unsigned int load_all_dies
: 1;
420 /* Non-null if this CU is from .debug_types; in which case it points
421 to the section. Otherwise it's from .debug_info. */
422 struct dwarf2_section_info
*debug_types_section
;
424 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
425 of the CU cache it gets reset to NULL again. */
426 struct dwarf2_cu
*cu
;
428 /* The corresponding objfile.
429 Normally we can get the objfile from dwarf2_per_objfile.
430 However we can enter this file with just a "per_cu" handle. */
431 struct objfile
*objfile
;
433 /* When using partial symbol tables, the 'psymtab' field is active.
434 Otherwise the 'quick' field is active. */
437 /* The partial symbol table associated with this compilation unit,
438 or NULL for partial units (which do not have an associated
440 struct partial_symtab
*psymtab
;
442 /* Data needed by the "quick" functions. */
443 struct dwarf2_per_cu_quick_data
*quick
;
447 /* Entry in the signatured_types hash table. */
449 struct signatured_type
453 /* Offset in this TU of the type defined by this TU. */
454 cu_offset type_offset
;
456 /* The CU(/TU) of this type. */
457 struct dwarf2_per_cu_data per_cu
;
460 /* Struct used to pass misc. parameters to read_die_and_children, et
461 al. which are used for both .debug_info and .debug_types dies.
462 All parameters here are unchanging for the life of the call. This
463 struct exists to abstract away the constant parameters of die reading. */
465 struct die_reader_specs
467 /* die_section->asection->owner. */
470 /* The CU of the DIE we are parsing. */
471 struct dwarf2_cu
*cu
;
473 /* The section the die comes from.
474 This is either .debug_info or .debug_types. */
475 struct dwarf2_section_info
*die_section
;
477 /* die_section->buffer. */
481 /* Type of function passed to init_cu_and_read_dies, et.al. */
482 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
484 struct die_info
*comp_unit_die
,
488 /* The line number information for a compilation unit (found in the
489 .debug_line section) begins with a "statement program header",
490 which contains the following information. */
493 unsigned int total_length
;
494 unsigned short version
;
495 unsigned int header_length
;
496 unsigned char minimum_instruction_length
;
497 unsigned char maximum_ops_per_instruction
;
498 unsigned char default_is_stmt
;
500 unsigned char line_range
;
501 unsigned char opcode_base
;
503 /* standard_opcode_lengths[i] is the number of operands for the
504 standard opcode whose value is i. This means that
505 standard_opcode_lengths[0] is unused, and the last meaningful
506 element is standard_opcode_lengths[opcode_base - 1]. */
507 unsigned char *standard_opcode_lengths
;
509 /* The include_directories table. NOTE! These strings are not
510 allocated with xmalloc; instead, they are pointers into
511 debug_line_buffer. If you try to free them, `free' will get
513 unsigned int num_include_dirs
, include_dirs_size
;
516 /* The file_names table. NOTE! These strings are not allocated
517 with xmalloc; instead, they are pointers into debug_line_buffer.
518 Don't try to free them directly. */
519 unsigned int num_file_names
, file_names_size
;
523 unsigned int dir_index
;
524 unsigned int mod_time
;
526 int included_p
; /* Non-zero if referenced by the Line Number Program. */
527 struct symtab
*symtab
; /* The associated symbol table, if any. */
530 /* The start and end of the statement program following this
531 header. These point into dwarf2_per_objfile->line_buffer. */
532 gdb_byte
*statement_program_start
, *statement_program_end
;
535 /* When we construct a partial symbol table entry we only
536 need this much information. */
537 struct partial_die_info
539 /* Offset of this DIE. */
542 /* DWARF-2 tag for this DIE. */
543 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
545 /* Assorted flags describing the data found in this DIE. */
546 unsigned int has_children
: 1;
547 unsigned int is_external
: 1;
548 unsigned int is_declaration
: 1;
549 unsigned int has_type
: 1;
550 unsigned int has_specification
: 1;
551 unsigned int has_pc_info
: 1;
552 unsigned int may_be_inlined
: 1;
554 /* Flag set if the SCOPE field of this structure has been
556 unsigned int scope_set
: 1;
558 /* Flag set if the DIE has a byte_size attribute. */
559 unsigned int has_byte_size
: 1;
561 /* Flag set if any of the DIE's children are template arguments. */
562 unsigned int has_template_arguments
: 1;
564 /* Flag set if fixup_partial_die has been called on this die. */
565 unsigned int fixup_called
: 1;
567 /* The name of this DIE. Normally the value of DW_AT_name, but
568 sometimes a default name for unnamed DIEs. */
571 /* The linkage name, if present. */
572 const char *linkage_name
;
574 /* The scope to prepend to our children. This is generally
575 allocated on the comp_unit_obstack, so will disappear
576 when this compilation unit leaves the cache. */
579 /* The location description associated with this DIE, if any. */
580 struct dwarf_block
*locdesc
;
582 /* If HAS_PC_INFO, the PC range associated with this DIE. */
586 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
587 DW_AT_sibling, if any. */
588 /* NOTE: This member isn't strictly necessary, read_partial_die could
589 return DW_AT_sibling values to its caller load_partial_dies. */
592 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
593 DW_AT_specification (or DW_AT_abstract_origin or
595 sect_offset spec_offset
;
597 /* Pointers to this DIE's parent, first child, and next sibling,
599 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
602 /* This data structure holds the information of an abbrev. */
605 unsigned int number
; /* number identifying abbrev */
606 enum dwarf_tag tag
; /* dwarf tag */
607 unsigned short has_children
; /* boolean */
608 unsigned short num_attrs
; /* number of attributes */
609 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
610 struct abbrev_info
*next
; /* next in chain */
615 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
616 ENUM_BITFIELD(dwarf_form
) form
: 16;
619 /* Attributes have a name and a value. */
622 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
623 ENUM_BITFIELD(dwarf_form
) form
: 15;
625 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
626 field should be in u.str (existing only for DW_STRING) but it is kept
627 here for better struct attribute alignment. */
628 unsigned int string_is_canonical
: 1;
633 struct dwarf_block
*blk
;
637 struct signatured_type
*signatured_type
;
642 /* This data structure holds a complete die structure. */
645 /* DWARF-2 tag for this DIE. */
646 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
648 /* Number of attributes */
649 unsigned char num_attrs
;
651 /* True if we're presently building the full type name for the
652 type derived from this DIE. */
653 unsigned char building_fullname
: 1;
658 /* Offset in .debug_info or .debug_types section. */
661 /* The dies in a compilation unit form an n-ary tree. PARENT
662 points to this die's parent; CHILD points to the first child of
663 this node; and all the children of a given node are chained
664 together via their SIBLING fields. */
665 struct die_info
*child
; /* Its first child, if any. */
666 struct die_info
*sibling
; /* Its next sibling, if any. */
667 struct die_info
*parent
; /* Its parent, if any. */
669 /* An array of attributes, with NUM_ATTRS elements. There may be
670 zero, but it's not common and zero-sized arrays are not
671 sufficiently portable C. */
672 struct attribute attrs
[1];
675 /* Get at parts of an attribute structure. */
677 #define DW_STRING(attr) ((attr)->u.str)
678 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
679 #define DW_UNSND(attr) ((attr)->u.unsnd)
680 #define DW_BLOCK(attr) ((attr)->u.blk)
681 #define DW_SND(attr) ((attr)->u.snd)
682 #define DW_ADDR(attr) ((attr)->u.addr)
683 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
685 /* Blocks are a bunch of untyped bytes. */
690 /* Valid only if SIZE is not zero. */
694 #ifndef ATTR_ALLOC_CHUNK
695 #define ATTR_ALLOC_CHUNK 4
698 /* Allocate fields for structs, unions and enums in this size. */
699 #ifndef DW_FIELD_ALLOC_CHUNK
700 #define DW_FIELD_ALLOC_CHUNK 4
703 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
704 but this would require a corresponding change in unpack_field_as_long
706 static int bits_per_byte
= 8;
708 /* The routines that read and process dies for a C struct or C++ class
709 pass lists of data member fields and lists of member function fields
710 in an instance of a field_info structure, as defined below. */
713 /* List of data member and baseclasses fields. */
716 struct nextfield
*next
;
721 *fields
, *baseclasses
;
723 /* Number of fields (including baseclasses). */
726 /* Number of baseclasses. */
729 /* Set if the accesibility of one of the fields is not public. */
730 int non_public_fields
;
732 /* Member function fields array, entries are allocated in the order they
733 are encountered in the object file. */
736 struct nextfnfield
*next
;
737 struct fn_field fnfield
;
741 /* Member function fieldlist array, contains name of possibly overloaded
742 member function, number of overloaded member functions and a pointer
743 to the head of the member function field chain. */
748 struct nextfnfield
*head
;
752 /* Number of entries in the fnfieldlists array. */
755 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
756 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
757 struct typedef_field_list
759 struct typedef_field field
;
760 struct typedef_field_list
*next
;
763 unsigned typedef_field_list_count
;
766 /* One item on the queue of compilation units to read in full symbols
768 struct dwarf2_queue_item
770 struct dwarf2_per_cu_data
*per_cu
;
771 struct dwarf2_queue_item
*next
;
774 /* The current queue. */
775 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
777 /* Loaded secondary compilation units are kept in memory until they
778 have not been referenced for the processing of this many
779 compilation units. Set this to zero to disable caching. Cache
780 sizes of up to at least twenty will improve startup time for
781 typical inter-CU-reference binaries, at an obvious memory cost. */
782 static int dwarf2_max_cache_age
= 5;
784 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
785 struct cmd_list_element
*c
, const char *value
)
787 fprintf_filtered (file
, _("The upper bound on the age of cached "
788 "dwarf2 compilation units is %s.\n"),
793 /* Various complaints about symbol reading that don't abort the process. */
796 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
798 complaint (&symfile_complaints
,
799 _("statement list doesn't fit in .debug_line section"));
803 dwarf2_debug_line_missing_file_complaint (void)
805 complaint (&symfile_complaints
,
806 _(".debug_line section has line data without a file"));
810 dwarf2_debug_line_missing_end_sequence_complaint (void)
812 complaint (&symfile_complaints
,
813 _(".debug_line section has line "
814 "program sequence without an end"));
818 dwarf2_complex_location_expr_complaint (void)
820 complaint (&symfile_complaints
, _("location expression too complex"));
824 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
827 complaint (&symfile_complaints
,
828 _("const value length mismatch for '%s', got %d, expected %d"),
833 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
835 complaint (&symfile_complaints
,
836 _("macro info runs off end of `%s' section"),
837 section
->asection
->name
);
841 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
843 complaint (&symfile_complaints
,
844 _("macro debug info contains a "
845 "malformed macro definition:\n`%s'"),
850 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
852 complaint (&symfile_complaints
,
853 _("invalid attribute class or form for '%s' in '%s'"),
857 /* local function prototypes */
859 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
861 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
864 static void dwarf2_find_base_address (struct die_info
*die
,
865 struct dwarf2_cu
*cu
);
867 static void dwarf2_build_psymtabs_hard (struct objfile
*);
869 static void scan_partial_symbols (struct partial_die_info
*,
870 CORE_ADDR
*, CORE_ADDR
*,
871 int, struct dwarf2_cu
*);
873 static void add_partial_symbol (struct partial_die_info
*,
876 static void add_partial_namespace (struct partial_die_info
*pdi
,
877 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
878 int need_pc
, struct dwarf2_cu
*cu
);
880 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
881 CORE_ADDR
*highpc
, int need_pc
,
882 struct dwarf2_cu
*cu
);
884 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
885 struct dwarf2_cu
*cu
);
887 static void add_partial_subprogram (struct partial_die_info
*pdi
,
888 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
889 int need_pc
, struct dwarf2_cu
*cu
);
891 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
893 static void psymtab_to_symtab_1 (struct partial_symtab
*);
895 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
896 struct dwarf2_section_info
*);
898 static void dwarf2_free_abbrev_table (void *);
900 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
902 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
905 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
908 static struct partial_die_info
*load_partial_dies
909 (const struct die_reader_specs
*, gdb_byte
*, int);
911 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
912 struct partial_die_info
*,
913 struct abbrev_info
*,
917 static struct partial_die_info
*find_partial_die (sect_offset
,
920 static void fixup_partial_die (struct partial_die_info
*,
923 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
924 struct attribute
*, struct attr_abbrev
*,
927 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
929 static int read_1_signed_byte (bfd
*, gdb_byte
*);
931 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
933 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
935 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
937 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
940 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
942 static LONGEST read_checked_initial_length_and_offset
943 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
944 unsigned int *, unsigned int *);
946 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
949 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
951 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
953 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
955 static char *read_indirect_string (bfd
*, gdb_byte
*,
956 const struct comp_unit_head
*,
959 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
961 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
963 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
965 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
967 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
970 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
974 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
975 struct dwarf2_cu
*cu
);
977 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
979 static struct die_info
*die_specification (struct die_info
*die
,
980 struct dwarf2_cu
**);
982 static void free_line_header (struct line_header
*lh
);
984 static void add_file_name (struct line_header
*, char *, unsigned int,
985 unsigned int, unsigned int);
987 static struct line_header
*(dwarf_decode_line_header
988 (unsigned int offset
,
989 bfd
*abfd
, struct dwarf2_cu
*cu
));
991 static void dwarf_decode_lines (struct line_header
*, const char *,
992 struct dwarf2_cu
*, struct partial_symtab
*,
995 static void dwarf2_start_subfile (char *, const char *, const char *);
997 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1000 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1001 struct dwarf2_cu
*, struct symbol
*);
1003 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1004 struct dwarf2_cu
*);
1006 static void dwarf2_const_value_attr (struct attribute
*attr
,
1009 struct obstack
*obstack
,
1010 struct dwarf2_cu
*cu
, LONGEST
*value
,
1012 struct dwarf2_locexpr_baton
**baton
);
1014 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1016 static int need_gnat_info (struct dwarf2_cu
*);
1018 static struct type
*die_descriptive_type (struct die_info
*,
1019 struct dwarf2_cu
*);
1021 static void set_descriptive_type (struct type
*, struct die_info
*,
1022 struct dwarf2_cu
*);
1024 static struct type
*die_containing_type (struct die_info
*,
1025 struct dwarf2_cu
*);
1027 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1028 struct dwarf2_cu
*);
1030 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1032 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1034 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1036 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1037 const char *suffix
, int physname
,
1038 struct dwarf2_cu
*cu
);
1040 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1042 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1044 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1046 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1048 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1050 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1051 struct dwarf2_cu
*, struct partial_symtab
*);
1053 static int dwarf2_get_pc_bounds (struct die_info
*,
1054 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1055 struct partial_symtab
*);
1057 static void get_scope_pc_bounds (struct die_info
*,
1058 CORE_ADDR
*, CORE_ADDR
*,
1059 struct dwarf2_cu
*);
1061 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1062 CORE_ADDR
, struct dwarf2_cu
*);
1064 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1065 struct dwarf2_cu
*);
1067 static void dwarf2_attach_fields_to_type (struct field_info
*,
1068 struct type
*, struct dwarf2_cu
*);
1070 static void dwarf2_add_member_fn (struct field_info
*,
1071 struct die_info
*, struct type
*,
1072 struct dwarf2_cu
*);
1074 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1076 struct dwarf2_cu
*);
1078 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1080 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1082 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1084 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1086 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1088 static struct type
*read_module_type (struct die_info
*die
,
1089 struct dwarf2_cu
*cu
);
1091 static const char *namespace_name (struct die_info
*die
,
1092 int *is_anonymous
, struct dwarf2_cu
*);
1094 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1096 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1098 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1099 struct dwarf2_cu
*);
1101 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1103 gdb_byte
**new_info_ptr
,
1104 struct die_info
*parent
);
1106 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1108 gdb_byte
**new_info_ptr
,
1109 struct die_info
*parent
);
1111 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1112 struct die_info
**, gdb_byte
*, int *);
1114 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1116 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1119 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1121 static const char *dwarf2_full_name (char *name
,
1122 struct die_info
*die
,
1123 struct dwarf2_cu
*cu
);
1125 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1126 struct dwarf2_cu
**);
1128 static char *dwarf_tag_name (unsigned int);
1130 static char *dwarf_attr_name (unsigned int);
1132 static char *dwarf_form_name (unsigned int);
1134 static char *dwarf_bool_name (unsigned int);
1136 static char *dwarf_type_encoding_name (unsigned int);
1139 static char *dwarf_cfi_name (unsigned int);
1142 static struct die_info
*sibling_die (struct die_info
*);
1144 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1146 static void dump_die_for_error (struct die_info
*);
1148 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1151 /*static*/ void dump_die (struct die_info
*, int max_level
);
1153 static void store_in_ref_table (struct die_info
*,
1154 struct dwarf2_cu
*);
1156 static int is_ref_attr (struct attribute
*);
1158 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1160 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1162 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1164 struct dwarf2_cu
**);
1166 static struct die_info
*follow_die_ref (struct die_info
*,
1168 struct dwarf2_cu
**);
1170 static struct die_info
*follow_die_sig (struct die_info
*,
1172 struct dwarf2_cu
**);
1174 static struct signatured_type
*lookup_signatured_type_at_offset
1175 (struct objfile
*objfile
,
1176 struct dwarf2_section_info
*section
, sect_offset offset
);
1178 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1180 static void read_signatured_type (struct signatured_type
*);
1182 /* memory allocation interface */
1184 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1186 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1188 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1190 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1191 char *, bfd
*, struct dwarf2_cu
*,
1192 struct dwarf2_section_info
*,
1195 static int attr_form_is_block (struct attribute
*);
1197 static int attr_form_is_section_offset (struct attribute
*);
1199 static int attr_form_is_constant (struct attribute
*);
1201 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1202 struct dwarf2_loclist_baton
*baton
,
1203 struct attribute
*attr
);
1205 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1207 struct dwarf2_cu
*cu
);
1209 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1211 struct abbrev_info
*abbrev
);
1213 static void free_stack_comp_unit (void *);
1215 static hashval_t
partial_die_hash (const void *item
);
1217 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1219 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1220 (sect_offset offset
, struct objfile
*objfile
);
1222 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1223 struct dwarf2_per_cu_data
*per_cu
);
1225 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1226 struct die_info
*comp_unit_die
);
1228 static void free_heap_comp_unit (void *);
1230 static void free_cached_comp_units (void *);
1232 static void age_cached_comp_units (void);
1234 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1236 static struct type
*set_die_type (struct die_info
*, struct type
*,
1237 struct dwarf2_cu
*);
1239 static void create_all_comp_units (struct objfile
*);
1241 static int create_all_type_units (struct objfile
*);
1243 static void load_full_comp_unit (struct dwarf2_per_cu_data
*);
1245 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1247 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1248 struct dwarf2_per_cu_data
*);
1250 static void dwarf2_mark (struct dwarf2_cu
*);
1252 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1254 static struct type
*get_die_type_at_offset (sect_offset
,
1255 struct dwarf2_per_cu_data
*per_cu
);
1257 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1259 static void dwarf2_release_queue (void *dummy
);
1261 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
);
1263 static void process_queue (void);
1265 static void find_file_and_directory (struct die_info
*die
,
1266 struct dwarf2_cu
*cu
,
1267 char **name
, char **comp_dir
);
1269 static char *file_full_name (int file
, struct line_header
*lh
,
1270 const char *comp_dir
);
1272 static gdb_byte
*read_and_check_comp_unit_head
1273 (struct comp_unit_head
*header
,
1274 struct dwarf2_section_info
*section
, gdb_byte
*info_ptr
,
1275 int is_debug_types_section
);
1277 static void init_cutu_and_read_dies_simple
1278 (struct dwarf2_per_cu_data
*this_cu
,
1279 die_reader_func_ftype
*die_reader_func
, void *data
);
1281 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1283 static void process_psymtab_comp_unit (struct dwarf2_per_cu_data
*);
1287 /* Convert VALUE between big- and little-endian. */
1289 byte_swap (offset_type value
)
1293 result
= (value
& 0xff) << 24;
1294 result
|= (value
& 0xff00) << 8;
1295 result
|= (value
& 0xff0000) >> 8;
1296 result
|= (value
& 0xff000000) >> 24;
1300 #define MAYBE_SWAP(V) byte_swap (V)
1303 #define MAYBE_SWAP(V) (V)
1304 #endif /* WORDS_BIGENDIAN */
1306 /* The suffix for an index file. */
1307 #define INDEX_SUFFIX ".gdb-index"
1309 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1310 struct dwarf2_cu
*cu
);
1312 /* Try to locate the sections we need for DWARF 2 debugging
1313 information and return true if we have enough to do something.
1314 NAMES points to the dwarf2 section names, or is NULL if the standard
1315 ELF names are used. */
1318 dwarf2_has_info (struct objfile
*objfile
,
1319 const struct dwarf2_debug_sections
*names
)
1321 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1322 if (!dwarf2_per_objfile
)
1324 /* Initialize per-objfile state. */
1325 struct dwarf2_per_objfile
*data
1326 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1328 memset (data
, 0, sizeof (*data
));
1329 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1330 dwarf2_per_objfile
= data
;
1332 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1334 dwarf2_per_objfile
->objfile
= objfile
;
1336 return (dwarf2_per_objfile
->info
.asection
!= NULL
1337 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1340 /* When loading sections, we look either for uncompressed section or for
1341 compressed section names. */
1344 section_is_p (const char *section_name
,
1345 const struct dwarf2_section_names
*names
)
1347 if (names
->normal
!= NULL
1348 && strcmp (section_name
, names
->normal
) == 0)
1350 if (names
->compressed
!= NULL
1351 && strcmp (section_name
, names
->compressed
) == 0)
1356 /* This function is mapped across the sections and remembers the
1357 offset and size of each of the debugging sections we are interested
1361 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1363 const struct dwarf2_debug_sections
*names
;
1366 names
= &dwarf2_elf_names
;
1368 names
= (const struct dwarf2_debug_sections
*) vnames
;
1370 if (section_is_p (sectp
->name
, &names
->info
))
1372 dwarf2_per_objfile
->info
.asection
= sectp
;
1373 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1375 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1377 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1378 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1380 else if (section_is_p (sectp
->name
, &names
->line
))
1382 dwarf2_per_objfile
->line
.asection
= sectp
;
1383 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1385 else if (section_is_p (sectp
->name
, &names
->loc
))
1387 dwarf2_per_objfile
->loc
.asection
= sectp
;
1388 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1390 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1392 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1393 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1395 else if (section_is_p (sectp
->name
, &names
->macro
))
1397 dwarf2_per_objfile
->macro
.asection
= sectp
;
1398 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1400 else if (section_is_p (sectp
->name
, &names
->str
))
1402 dwarf2_per_objfile
->str
.asection
= sectp
;
1403 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1405 else if (section_is_p (sectp
->name
, &names
->frame
))
1407 dwarf2_per_objfile
->frame
.asection
= sectp
;
1408 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1410 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1412 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1414 if (aflag
& SEC_HAS_CONTENTS
)
1416 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1417 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1420 else if (section_is_p (sectp
->name
, &names
->ranges
))
1422 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1423 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1425 else if (section_is_p (sectp
->name
, &names
->types
))
1427 struct dwarf2_section_info type_section
;
1429 memset (&type_section
, 0, sizeof (type_section
));
1430 type_section
.asection
= sectp
;
1431 type_section
.size
= bfd_get_section_size (sectp
);
1433 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1436 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1438 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1439 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1442 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1443 && bfd_section_vma (abfd
, sectp
) == 0)
1444 dwarf2_per_objfile
->has_section_at_zero
= 1;
1447 /* Decompress a section that was compressed using zlib. Store the
1448 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1451 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1452 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1454 bfd
*abfd
= objfile
->obfd
;
1456 error (_("Support for zlib-compressed DWARF data (from '%s') "
1457 "is disabled in this copy of GDB"),
1458 bfd_get_filename (abfd
));
1460 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1461 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1462 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1463 bfd_size_type uncompressed_size
;
1464 gdb_byte
*uncompressed_buffer
;
1467 int header_size
= 12;
1469 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1470 || bfd_bread (compressed_buffer
,
1471 compressed_size
, abfd
) != compressed_size
)
1472 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1473 bfd_get_filename (abfd
));
1475 /* Read the zlib header. In this case, it should be "ZLIB" followed
1476 by the uncompressed section size, 8 bytes in big-endian order. */
1477 if (compressed_size
< header_size
1478 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1479 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1480 bfd_get_filename (abfd
));
1481 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1482 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1483 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1484 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1485 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1486 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1487 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1488 uncompressed_size
+= compressed_buffer
[11];
1490 /* It is possible the section consists of several compressed
1491 buffers concatenated together, so we uncompress in a loop. */
1495 strm
.avail_in
= compressed_size
- header_size
;
1496 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1497 strm
.avail_out
= uncompressed_size
;
1498 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1500 rc
= inflateInit (&strm
);
1501 while (strm
.avail_in
> 0)
1504 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1505 bfd_get_filename (abfd
), rc
);
1506 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1507 + (uncompressed_size
- strm
.avail_out
));
1508 rc
= inflate (&strm
, Z_FINISH
);
1509 if (rc
!= Z_STREAM_END
)
1510 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1511 bfd_get_filename (abfd
), rc
);
1512 rc
= inflateReset (&strm
);
1514 rc
= inflateEnd (&strm
);
1516 || strm
.avail_out
!= 0)
1517 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1518 bfd_get_filename (abfd
), rc
);
1520 do_cleanups (cleanup
);
1521 *outbuf
= uncompressed_buffer
;
1522 *outsize
= uncompressed_size
;
1526 /* A helper function that decides whether a section is empty. */
1529 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1531 return info
->asection
== NULL
|| info
->size
== 0;
1534 /* Read the contents of the section INFO from object file specified by
1535 OBJFILE, store info about the section into INFO.
1536 If the section is compressed, uncompress it before returning. */
1539 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1541 bfd
*abfd
= objfile
->obfd
;
1542 asection
*sectp
= info
->asection
;
1543 gdb_byte
*buf
, *retbuf
;
1544 unsigned char header
[4];
1548 info
->buffer
= NULL
;
1549 info
->map_addr
= NULL
;
1552 if (dwarf2_section_empty_p (info
))
1555 /* Check if the file has a 4-byte header indicating compression. */
1556 if (info
->size
> sizeof (header
)
1557 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1558 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1560 /* Upon decompression, update the buffer and its size. */
1561 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1563 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1571 pagesize
= getpagesize ();
1573 /* Only try to mmap sections which are large enough: we don't want to
1574 waste space due to fragmentation. Also, only try mmap for sections
1575 without relocations. */
1577 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1579 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1580 MAP_PRIVATE
, sectp
->filepos
,
1581 &info
->map_addr
, &info
->map_len
);
1583 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1585 #if HAVE_POSIX_MADVISE
1586 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1593 /* If we get here, we are a normal, not-compressed section. */
1595 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1597 /* When debugging .o files, we may need to apply relocations; see
1598 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1599 We never compress sections in .o files, so we only need to
1600 try this when the section is not compressed. */
1601 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1604 info
->buffer
= retbuf
;
1608 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1609 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1610 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1611 bfd_get_filename (abfd
));
1614 /* A helper function that returns the size of a section in a safe way.
1615 If you are positive that the section has been read before using the
1616 size, then it is safe to refer to the dwarf2_section_info object's
1617 "size" field directly. In other cases, you must call this
1618 function, because for compressed sections the size field is not set
1619 correctly until the section has been read. */
1621 static bfd_size_type
1622 dwarf2_section_size (struct objfile
*objfile
,
1623 struct dwarf2_section_info
*info
)
1626 dwarf2_read_section (objfile
, info
);
1630 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1634 dwarf2_get_section_info (struct objfile
*objfile
,
1635 enum dwarf2_section_enum sect
,
1636 asection
**sectp
, gdb_byte
**bufp
,
1637 bfd_size_type
*sizep
)
1639 struct dwarf2_per_objfile
*data
1640 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1641 struct dwarf2_section_info
*info
;
1643 /* We may see an objfile without any DWARF, in which case we just
1654 case DWARF2_DEBUG_FRAME
:
1655 info
= &data
->frame
;
1657 case DWARF2_EH_FRAME
:
1658 info
= &data
->eh_frame
;
1661 gdb_assert_not_reached ("unexpected section");
1664 dwarf2_read_section (objfile
, info
);
1666 *sectp
= info
->asection
;
1667 *bufp
= info
->buffer
;
1668 *sizep
= info
->size
;
1672 /* DWARF quick_symbols_functions support. */
1674 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1675 unique line tables, so we maintain a separate table of all .debug_line
1676 derived entries to support the sharing.
1677 All the quick functions need is the list of file names. We discard the
1678 line_header when we're done and don't need to record it here. */
1679 struct quick_file_names
1681 /* The offset in .debug_line of the line table. We hash on this. */
1682 unsigned int offset
;
1684 /* The number of entries in file_names, real_names. */
1685 unsigned int num_file_names
;
1687 /* The file names from the line table, after being run through
1689 const char **file_names
;
1691 /* The file names from the line table after being run through
1692 gdb_realpath. These are computed lazily. */
1693 const char **real_names
;
1696 /* When using the index (and thus not using psymtabs), each CU has an
1697 object of this type. This is used to hold information needed by
1698 the various "quick" methods. */
1699 struct dwarf2_per_cu_quick_data
1701 /* The file table. This can be NULL if there was no file table
1702 or it's currently not read in.
1703 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1704 struct quick_file_names
*file_names
;
1706 /* The corresponding symbol table. This is NULL if symbols for this
1707 CU have not yet been read. */
1708 struct symtab
*symtab
;
1710 /* A temporary mark bit used when iterating over all CUs in
1711 expand_symtabs_matching. */
1712 unsigned int mark
: 1;
1714 /* True if we've tried to read the file table and found there isn't one.
1715 There will be no point in trying to read it again next time. */
1716 unsigned int no_file_data
: 1;
1719 /* Hash function for a quick_file_names. */
1722 hash_file_name_entry (const void *e
)
1724 const struct quick_file_names
*file_data
= e
;
1726 return file_data
->offset
;
1729 /* Equality function for a quick_file_names. */
1732 eq_file_name_entry (const void *a
, const void *b
)
1734 const struct quick_file_names
*ea
= a
;
1735 const struct quick_file_names
*eb
= b
;
1737 return ea
->offset
== eb
->offset
;
1740 /* Delete function for a quick_file_names. */
1743 delete_file_name_entry (void *e
)
1745 struct quick_file_names
*file_data
= e
;
1748 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1750 xfree ((void*) file_data
->file_names
[i
]);
1751 if (file_data
->real_names
)
1752 xfree ((void*) file_data
->real_names
[i
]);
1755 /* The space for the struct itself lives on objfile_obstack,
1756 so we don't free it here. */
1759 /* Create a quick_file_names hash table. */
1762 create_quick_file_names_table (unsigned int nr_initial_entries
)
1764 return htab_create_alloc (nr_initial_entries
,
1765 hash_file_name_entry
, eq_file_name_entry
,
1766 delete_file_name_entry
, xcalloc
, xfree
);
1769 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1770 have to be created afterwards. You should call age_cached_comp_units after
1771 processing PER_CU->CU. dw2_setup must have been already called. */
1774 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1776 if (per_cu
->debug_types_section
)
1777 load_full_type_unit (per_cu
);
1779 load_full_comp_unit (per_cu
);
1781 gdb_assert (per_cu
->cu
!= NULL
);
1783 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1786 /* Read in the symbols for PER_CU. */
1789 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1791 struct cleanup
*back_to
;
1793 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1795 queue_comp_unit (per_cu
);
1801 /* Age the cache, releasing compilation units that have not
1802 been used recently. */
1803 age_cached_comp_units ();
1805 do_cleanups (back_to
);
1808 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1809 the objfile from which this CU came. Returns the resulting symbol
1812 static struct symtab
*
1813 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1815 if (!per_cu
->v
.quick
->symtab
)
1817 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1818 increment_reading_symtab ();
1819 dw2_do_instantiate_symtab (per_cu
);
1820 do_cleanups (back_to
);
1822 return per_cu
->v
.quick
->symtab
;
1825 /* Return the CU given its index. */
1827 static struct dwarf2_per_cu_data
*
1828 dw2_get_cu (int index
)
1830 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1832 index
-= dwarf2_per_objfile
->n_comp_units
;
1833 return dwarf2_per_objfile
->all_type_units
[index
];
1835 return dwarf2_per_objfile
->all_comp_units
[index
];
1838 /* A helper function that knows how to read a 64-bit value in a way
1839 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1843 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1845 if (sizeof (ULONGEST
) < 8)
1849 /* Ignore the upper 4 bytes if they are all zero. */
1850 for (i
= 0; i
< 4; ++i
)
1851 if (bytes
[i
+ 4] != 0)
1854 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1857 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1861 /* Read the CU list from the mapped index, and use it to create all
1862 the CU objects for this objfile. Return 0 if something went wrong,
1863 1 if everything went ok. */
1866 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1867 offset_type cu_list_elements
)
1871 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1872 dwarf2_per_objfile
->all_comp_units
1873 = obstack_alloc (&objfile
->objfile_obstack
,
1874 dwarf2_per_objfile
->n_comp_units
1875 * sizeof (struct dwarf2_per_cu_data
*));
1877 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1879 struct dwarf2_per_cu_data
*the_cu
;
1880 ULONGEST offset
, length
;
1882 if (!extract_cu_value (cu_list
, &offset
)
1883 || !extract_cu_value (cu_list
+ 8, &length
))
1887 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1888 struct dwarf2_per_cu_data
);
1889 the_cu
->offset
.sect_off
= offset
;
1890 the_cu
->length
= length
;
1891 the_cu
->objfile
= objfile
;
1892 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1893 struct dwarf2_per_cu_quick_data
);
1894 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1900 /* Create the signatured type hash table from the index. */
1903 create_signatured_type_table_from_index (struct objfile
*objfile
,
1904 struct dwarf2_section_info
*section
,
1905 const gdb_byte
*bytes
,
1906 offset_type elements
)
1909 htab_t sig_types_hash
;
1911 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
1912 dwarf2_per_objfile
->all_type_units
1913 = obstack_alloc (&objfile
->objfile_obstack
,
1914 dwarf2_per_objfile
->n_type_units
1915 * sizeof (struct dwarf2_per_cu_data
*));
1917 sig_types_hash
= allocate_signatured_type_table (objfile
);
1919 for (i
= 0; i
< elements
; i
+= 3)
1921 struct signatured_type
*sig_type
;
1922 ULONGEST offset
, type_offset_in_tu
, signature
;
1925 if (!extract_cu_value (bytes
, &offset
)
1926 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
1928 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1931 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1932 struct signatured_type
);
1933 sig_type
->signature
= signature
;
1934 sig_type
->type_offset
.cu_off
= type_offset_in_tu
;
1935 sig_type
->per_cu
.debug_types_section
= section
;
1936 sig_type
->per_cu
.offset
.sect_off
= offset
;
1937 sig_type
->per_cu
.objfile
= objfile
;
1938 sig_type
->per_cu
.v
.quick
1939 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1940 struct dwarf2_per_cu_quick_data
);
1942 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
1945 dwarf2_per_objfile
->all_type_units
[i
/ 3] = &sig_type
->per_cu
;
1948 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1953 /* Read the address map data from the mapped index, and use it to
1954 populate the objfile's psymtabs_addrmap. */
1957 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1959 const gdb_byte
*iter
, *end
;
1960 struct obstack temp_obstack
;
1961 struct addrmap
*mutable_map
;
1962 struct cleanup
*cleanup
;
1965 obstack_init (&temp_obstack
);
1966 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1967 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1969 iter
= index
->address_table
;
1970 end
= iter
+ index
->address_table_size
;
1972 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1976 ULONGEST hi
, lo
, cu_index
;
1977 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1979 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1981 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1984 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1985 dw2_get_cu (cu_index
));
1988 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1989 &objfile
->objfile_obstack
);
1990 do_cleanups (cleanup
);
1993 /* The hash function for strings in the mapped index. This is the same as
1994 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
1995 implementation. This is necessary because the hash function is tied to the
1996 format of the mapped index file. The hash values do not have to match with
1999 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2002 mapped_index_string_hash (int index_version
, const void *p
)
2004 const unsigned char *str
= (const unsigned char *) p
;
2008 while ((c
= *str
++) != 0)
2010 if (index_version
>= 5)
2012 r
= r
* 67 + c
- 113;
2018 /* Find a slot in the mapped index INDEX for the object named NAME.
2019 If NAME is found, set *VEC_OUT to point to the CU vector in the
2020 constant pool and return 1. If NAME cannot be found, return 0. */
2023 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2024 offset_type
**vec_out
)
2026 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2028 offset_type slot
, step
;
2029 int (*cmp
) (const char *, const char *);
2031 if (current_language
->la_language
== language_cplus
2032 || current_language
->la_language
== language_java
2033 || current_language
->la_language
== language_fortran
)
2035 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2037 const char *paren
= strchr (name
, '(');
2043 dup
= xmalloc (paren
- name
+ 1);
2044 memcpy (dup
, name
, paren
- name
);
2045 dup
[paren
- name
] = 0;
2047 make_cleanup (xfree
, dup
);
2052 /* Index version 4 did not support case insensitive searches. But the
2053 indices for case insensitive languages are built in lowercase, therefore
2054 simulate our NAME being searched is also lowercased. */
2055 hash
= mapped_index_string_hash ((index
->version
== 4
2056 && case_sensitivity
== case_sensitive_off
2057 ? 5 : index
->version
),
2060 slot
= hash
& (index
->symbol_table_slots
- 1);
2061 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2062 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2066 /* Convert a slot number to an offset into the table. */
2067 offset_type i
= 2 * slot
;
2069 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2071 do_cleanups (back_to
);
2075 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2076 if (!cmp (name
, str
))
2078 *vec_out
= (offset_type
*) (index
->constant_pool
2079 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2080 do_cleanups (back_to
);
2084 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2088 /* Read the index file. If everything went ok, initialize the "quick"
2089 elements of all the CUs and return 1. Otherwise, return 0. */
2092 dwarf2_read_index (struct objfile
*objfile
)
2095 struct mapped_index
*map
;
2096 offset_type
*metadata
;
2097 const gdb_byte
*cu_list
;
2098 const gdb_byte
*types_list
= NULL
;
2099 offset_type version
, cu_list_elements
;
2100 offset_type types_list_elements
= 0;
2103 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2106 /* Older elfutils strip versions could keep the section in the main
2107 executable while splitting it for the separate debug info file. */
2108 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2109 & SEC_HAS_CONTENTS
) == 0)
2112 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2114 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2115 /* Version check. */
2116 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2117 /* Versions earlier than 3 emitted every copy of a psymbol. This
2118 causes the index to behave very poorly for certain requests. Version 3
2119 contained incomplete addrmap. So, it seems better to just ignore such
2123 static int warning_printed
= 0;
2124 if (!warning_printed
)
2126 warning (_("Skipping obsolete .gdb_index section in %s."),
2128 warning_printed
= 1;
2132 /* Index version 4 uses a different hash function than index version
2135 Versions earlier than 6 did not emit psymbols for inlined
2136 functions. Using these files will cause GDB not to be able to
2137 set breakpoints on inlined functions by name, so we ignore these
2138 indices unless the --use-deprecated-index-sections command line
2139 option was supplied. */
2140 if (version
< 6 && !use_deprecated_index_sections
)
2142 static int warning_printed
= 0;
2143 if (!warning_printed
)
2145 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2146 "--use-deprecated-index-sections to use them anyway"),
2148 warning_printed
= 1;
2152 /* Indexes with higher version than the one supported by GDB may be no
2153 longer backward compatible. */
2157 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2158 map
->version
= version
;
2159 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2161 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2164 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2165 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2169 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2170 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2171 - MAYBE_SWAP (metadata
[i
]))
2175 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2176 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2177 - MAYBE_SWAP (metadata
[i
]));
2180 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2181 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2182 - MAYBE_SWAP (metadata
[i
]))
2183 / (2 * sizeof (offset_type
)));
2186 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2188 /* Don't use the index if it's empty. */
2189 if (map
->symbol_table_slots
== 0)
2192 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2195 if (types_list_elements
)
2197 struct dwarf2_section_info
*section
;
2199 /* We can only handle a single .debug_types when we have an
2201 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2204 section
= VEC_index (dwarf2_section_info_def
,
2205 dwarf2_per_objfile
->types
, 0);
2207 if (!create_signatured_type_table_from_index (objfile
, section
,
2209 types_list_elements
))
2213 create_addrmap_from_index (objfile
, map
);
2215 dwarf2_per_objfile
->index_table
= map
;
2216 dwarf2_per_objfile
->using_index
= 1;
2217 dwarf2_per_objfile
->quick_file_names_table
=
2218 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2223 /* A helper for the "quick" functions which sets the global
2224 dwarf2_per_objfile according to OBJFILE. */
2227 dw2_setup (struct objfile
*objfile
)
2229 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2230 gdb_assert (dwarf2_per_objfile
);
2233 /* die_reader_func for dw2_get_file_names. */
2236 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2238 struct die_info
*comp_unit_die
,
2242 struct dwarf2_cu
*cu
= reader
->cu
;
2243 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2244 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2245 bfd
*abfd
= objfile
->obfd
;
2246 struct line_header
*lh
;
2247 struct attribute
*attr
;
2249 unsigned int bytes_read
;
2250 char *name
, *comp_dir
;
2252 struct quick_file_names
*qfn
;
2253 unsigned int line_offset
;
2259 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2262 struct quick_file_names find_entry
;
2264 line_offset
= DW_UNSND (attr
);
2266 /* We may have already read in this line header (TU line header sharing).
2267 If we have we're done. */
2268 find_entry
.offset
= line_offset
;
2269 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2270 &find_entry
, INSERT
);
2273 this_cu
->v
.quick
->file_names
= *slot
;
2277 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2281 this_cu
->v
.quick
->no_file_data
= 1;
2285 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2286 qfn
->offset
= line_offset
;
2287 gdb_assert (slot
!= NULL
);
2290 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2292 qfn
->num_file_names
= lh
->num_file_names
;
2293 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2294 lh
->num_file_names
* sizeof (char *));
2295 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2296 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2297 qfn
->real_names
= NULL
;
2299 free_line_header (lh
);
2301 this_cu
->v
.quick
->file_names
= qfn
;
2304 /* A helper for the "quick" functions which attempts to read the line
2305 table for THIS_CU. */
2307 static struct quick_file_names
*
2308 dw2_get_file_names (struct objfile
*objfile
,
2309 struct dwarf2_per_cu_data
*this_cu
)
2311 if (this_cu
->v
.quick
->file_names
!= NULL
)
2312 return this_cu
->v
.quick
->file_names
;
2313 /* If we know there is no line data, no point in looking again. */
2314 if (this_cu
->v
.quick
->no_file_data
)
2317 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2319 if (this_cu
->v
.quick
->no_file_data
)
2321 return this_cu
->v
.quick
->file_names
;
2324 /* A helper for the "quick" functions which computes and caches the
2325 real path for a given file name from the line table. */
2328 dw2_get_real_path (struct objfile
*objfile
,
2329 struct quick_file_names
*qfn
, int index
)
2331 if (qfn
->real_names
== NULL
)
2332 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2333 qfn
->num_file_names
, sizeof (char *));
2335 if (qfn
->real_names
[index
] == NULL
)
2336 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2338 return qfn
->real_names
[index
];
2341 static struct symtab
*
2342 dw2_find_last_source_symtab (struct objfile
*objfile
)
2346 dw2_setup (objfile
);
2347 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2348 return dw2_instantiate_symtab (dw2_get_cu (index
));
2351 /* Traversal function for dw2_forget_cached_source_info. */
2354 dw2_free_cached_file_names (void **slot
, void *info
)
2356 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2358 if (file_data
->real_names
)
2362 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2364 xfree ((void*) file_data
->real_names
[i
]);
2365 file_data
->real_names
[i
] = NULL
;
2373 dw2_forget_cached_source_info (struct objfile
*objfile
)
2375 dw2_setup (objfile
);
2377 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2378 dw2_free_cached_file_names
, NULL
);
2381 /* Helper function for dw2_map_symtabs_matching_filename that expands
2382 the symtabs and calls the iterator. */
2385 dw2_map_expand_apply (struct objfile
*objfile
,
2386 struct dwarf2_per_cu_data
*per_cu
,
2388 const char *full_path
, const char *real_path
,
2389 int (*callback
) (struct symtab
*, void *),
2392 struct symtab
*last_made
= objfile
->symtabs
;
2394 /* Don't visit already-expanded CUs. */
2395 if (per_cu
->v
.quick
->symtab
)
2398 /* This may expand more than one symtab, and we want to iterate over
2400 dw2_instantiate_symtab (per_cu
);
2402 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2403 objfile
->symtabs
, last_made
);
2406 /* Implementation of the map_symtabs_matching_filename method. */
2409 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2410 const char *full_path
, const char *real_path
,
2411 int (*callback
) (struct symtab
*, void *),
2415 const char *name_basename
= lbasename (name
);
2416 int name_len
= strlen (name
);
2417 int is_abs
= IS_ABSOLUTE_PATH (name
);
2419 dw2_setup (objfile
);
2421 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2422 + dwarf2_per_objfile
->n_type_units
); ++i
)
2425 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2426 struct quick_file_names
*file_data
;
2428 /* We only need to look at symtabs not already expanded. */
2429 if (per_cu
->v
.quick
->symtab
)
2432 file_data
= dw2_get_file_names (objfile
, per_cu
);
2433 if (file_data
== NULL
)
2436 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2438 const char *this_name
= file_data
->file_names
[j
];
2440 if (FILENAME_CMP (name
, this_name
) == 0
2441 || (!is_abs
&& compare_filenames_for_search (this_name
,
2444 if (dw2_map_expand_apply (objfile
, per_cu
,
2445 name
, full_path
, real_path
,
2450 /* Before we invoke realpath, which can get expensive when many
2451 files are involved, do a quick comparison of the basenames. */
2452 if (! basenames_may_differ
2453 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2456 if (full_path
!= NULL
)
2458 const char *this_real_name
= dw2_get_real_path (objfile
,
2461 if (this_real_name
!= NULL
2462 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2464 && compare_filenames_for_search (this_real_name
,
2467 if (dw2_map_expand_apply (objfile
, per_cu
,
2468 name
, full_path
, real_path
,
2474 if (real_path
!= NULL
)
2476 const char *this_real_name
= dw2_get_real_path (objfile
,
2479 if (this_real_name
!= NULL
2480 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2482 && compare_filenames_for_search (this_real_name
,
2485 if (dw2_map_expand_apply (objfile
, per_cu
,
2486 name
, full_path
, real_path
,
2497 static struct symtab
*
2498 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2499 const char *name
, domain_enum domain
)
2501 /* We do all the work in the pre_expand_symtabs_matching hook
2506 /* A helper function that expands all symtabs that hold an object
2510 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2512 dw2_setup (objfile
);
2514 /* index_table is NULL if OBJF_READNOW. */
2515 if (dwarf2_per_objfile
->index_table
)
2519 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2522 offset_type i
, len
= MAYBE_SWAP (*vec
);
2523 for (i
= 0; i
< len
; ++i
)
2525 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2526 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2528 dw2_instantiate_symtab (per_cu
);
2535 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2536 enum block_enum block_kind
, const char *name
,
2539 dw2_do_expand_symtabs_matching (objfile
, name
);
2543 dw2_print_stats (struct objfile
*objfile
)
2547 dw2_setup (objfile
);
2549 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2550 + dwarf2_per_objfile
->n_type_units
); ++i
)
2552 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2554 if (!per_cu
->v
.quick
->symtab
)
2557 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2561 dw2_dump (struct objfile
*objfile
)
2563 /* Nothing worth printing. */
2567 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2568 struct section_offsets
*delta
)
2570 /* There's nothing to relocate here. */
2574 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2575 const char *func_name
)
2577 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2581 dw2_expand_all_symtabs (struct objfile
*objfile
)
2585 dw2_setup (objfile
);
2587 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2588 + dwarf2_per_objfile
->n_type_units
); ++i
)
2590 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2592 dw2_instantiate_symtab (per_cu
);
2597 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2598 const char *filename
)
2602 dw2_setup (objfile
);
2604 /* We don't need to consider type units here.
2605 This is only called for examining code, e.g. expand_line_sal.
2606 There can be an order of magnitude (or more) more type units
2607 than comp units, and we avoid them if we can. */
2609 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2612 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2613 struct quick_file_names
*file_data
;
2615 /* We only need to look at symtabs not already expanded. */
2616 if (per_cu
->v
.quick
->symtab
)
2619 file_data
= dw2_get_file_names (objfile
, per_cu
);
2620 if (file_data
== NULL
)
2623 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2625 const char *this_name
= file_data
->file_names
[j
];
2626 if (FILENAME_CMP (this_name
, filename
) == 0)
2628 dw2_instantiate_symtab (per_cu
);
2636 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2638 struct dwarf2_per_cu_data
*per_cu
;
2640 struct quick_file_names
*file_data
;
2642 dw2_setup (objfile
);
2644 /* index_table is NULL if OBJF_READNOW. */
2645 if (!dwarf2_per_objfile
->index_table
)
2649 ALL_OBJFILE_SYMTABS (objfile
, s
)
2652 struct blockvector
*bv
= BLOCKVECTOR (s
);
2653 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2654 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2657 return sym
->symtab
->filename
;
2662 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2666 /* Note that this just looks at the very first one named NAME -- but
2667 actually we are looking for a function. find_main_filename
2668 should be rewritten so that it doesn't require a custom hook. It
2669 could just use the ordinary symbol tables. */
2670 /* vec[0] is the length, which must always be >0. */
2671 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2673 file_data
= dw2_get_file_names (objfile
, per_cu
);
2674 if (file_data
== NULL
)
2677 return file_data
->file_names
[file_data
->num_file_names
- 1];
2681 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2682 struct objfile
*objfile
, int global
,
2683 int (*callback
) (struct block
*,
2684 struct symbol
*, void *),
2685 void *data
, symbol_compare_ftype
*match
,
2686 symbol_compare_ftype
*ordered_compare
)
2688 /* Currently unimplemented; used for Ada. The function can be called if the
2689 current language is Ada for a non-Ada objfile using GNU index. As Ada
2690 does not look for non-Ada symbols this function should just return. */
2694 dw2_expand_symtabs_matching
2695 (struct objfile
*objfile
,
2696 int (*file_matcher
) (const char *, void *),
2697 int (*name_matcher
) (const char *, void *),
2698 enum search_domain kind
,
2703 struct mapped_index
*index
;
2705 dw2_setup (objfile
);
2707 /* index_table is NULL if OBJF_READNOW. */
2708 if (!dwarf2_per_objfile
->index_table
)
2710 index
= dwarf2_per_objfile
->index_table
;
2712 if (file_matcher
!= NULL
)
2714 struct cleanup
*cleanup
;
2715 htab_t visited_found
, visited_not_found
;
2717 visited_found
= htab_create_alloc (10,
2718 htab_hash_pointer
, htab_eq_pointer
,
2719 NULL
, xcalloc
, xfree
);
2720 cleanup
= make_cleanup_htab_delete (visited_found
);
2721 visited_not_found
= htab_create_alloc (10,
2722 htab_hash_pointer
, htab_eq_pointer
,
2723 NULL
, xcalloc
, xfree
);
2724 make_cleanup_htab_delete (visited_not_found
);
2726 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2727 + dwarf2_per_objfile
->n_type_units
); ++i
)
2730 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2731 struct quick_file_names
*file_data
;
2734 per_cu
->v
.quick
->mark
= 0;
2736 /* We only need to look at symtabs not already expanded. */
2737 if (per_cu
->v
.quick
->symtab
)
2740 file_data
= dw2_get_file_names (objfile
, per_cu
);
2741 if (file_data
== NULL
)
2744 if (htab_find (visited_not_found
, file_data
) != NULL
)
2746 else if (htab_find (visited_found
, file_data
) != NULL
)
2748 per_cu
->v
.quick
->mark
= 1;
2752 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2754 if (file_matcher (file_data
->file_names
[j
], data
))
2756 per_cu
->v
.quick
->mark
= 1;
2761 slot
= htab_find_slot (per_cu
->v
.quick
->mark
2763 : visited_not_found
,
2768 do_cleanups (cleanup
);
2771 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2773 offset_type idx
= 2 * iter
;
2775 offset_type
*vec
, vec_len
, vec_idx
;
2777 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2780 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2782 if (! (*name_matcher
) (name
, data
))
2785 /* The name was matched, now expand corresponding CUs that were
2787 vec
= (offset_type
*) (index
->constant_pool
2788 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2789 vec_len
= MAYBE_SWAP (vec
[0]);
2790 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2792 struct dwarf2_per_cu_data
*per_cu
;
2794 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2795 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2796 dw2_instantiate_symtab (per_cu
);
2801 static struct symtab
*
2802 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2803 struct minimal_symbol
*msymbol
,
2805 struct obj_section
*section
,
2808 struct dwarf2_per_cu_data
*data
;
2810 dw2_setup (objfile
);
2812 if (!objfile
->psymtabs_addrmap
)
2815 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2819 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2820 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2821 paddress (get_objfile_arch (objfile
), pc
));
2823 return dw2_instantiate_symtab (data
);
2827 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2828 void *data
, int need_fullname
)
2831 struct cleanup
*cleanup
;
2832 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
2833 NULL
, xcalloc
, xfree
);
2835 cleanup
= make_cleanup_htab_delete (visited
);
2836 dw2_setup (objfile
);
2838 /* We can ignore file names coming from already-expanded CUs. */
2839 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2840 + dwarf2_per_objfile
->n_type_units
); ++i
)
2842 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2844 if (per_cu
->v
.quick
->symtab
)
2846 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
2849 *slot
= per_cu
->v
.quick
->file_names
;
2853 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2854 + dwarf2_per_objfile
->n_type_units
); ++i
)
2857 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2858 struct quick_file_names
*file_data
;
2861 /* We only need to look at symtabs not already expanded. */
2862 if (per_cu
->v
.quick
->symtab
)
2865 file_data
= dw2_get_file_names (objfile
, per_cu
);
2866 if (file_data
== NULL
)
2869 slot
= htab_find_slot (visited
, file_data
, INSERT
);
2872 /* Already visited. */
2877 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2879 const char *this_real_name
;
2882 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
2884 this_real_name
= NULL
;
2885 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2889 do_cleanups (cleanup
);
2893 dw2_has_symbols (struct objfile
*objfile
)
2898 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2901 dw2_find_last_source_symtab
,
2902 dw2_forget_cached_source_info
,
2903 dw2_map_symtabs_matching_filename
,
2905 dw2_pre_expand_symtabs_matching
,
2909 dw2_expand_symtabs_for_function
,
2910 dw2_expand_all_symtabs
,
2911 dw2_expand_symtabs_with_filename
,
2912 dw2_find_symbol_file
,
2913 dw2_map_matching_symbols
,
2914 dw2_expand_symtabs_matching
,
2915 dw2_find_pc_sect_symtab
,
2916 dw2_map_symbol_filenames
2919 /* Initialize for reading DWARF for this objfile. Return 0 if this
2920 file will use psymtabs, or 1 if using the GNU index. */
2923 dwarf2_initialize_objfile (struct objfile
*objfile
)
2925 /* If we're about to read full symbols, don't bother with the
2926 indices. In this case we also don't care if some other debug
2927 format is making psymtabs, because they are all about to be
2929 if ((objfile
->flags
& OBJF_READNOW
))
2933 dwarf2_per_objfile
->using_index
= 1;
2934 create_all_comp_units (objfile
);
2935 create_all_type_units (objfile
);
2936 dwarf2_per_objfile
->quick_file_names_table
=
2937 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2939 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2940 + dwarf2_per_objfile
->n_type_units
); ++i
)
2942 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2944 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2945 struct dwarf2_per_cu_quick_data
);
2948 /* Return 1 so that gdb sees the "quick" functions. However,
2949 these functions will be no-ops because we will have expanded
2954 if (dwarf2_read_index (objfile
))
2962 /* Build a partial symbol table. */
2965 dwarf2_build_psymtabs (struct objfile
*objfile
)
2967 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2969 init_psymbol_list (objfile
, 1024);
2972 dwarf2_build_psymtabs_hard (objfile
);
2975 /* Return TRUE if OFFSET is within CU_HEADER. */
2978 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
2980 sect_offset bottom
= { cu_header
->offset
.sect_off
};
2981 sect_offset top
= { (cu_header
->offset
.sect_off
+ cu_header
->length
2982 + cu_header
->initial_length_size
) };
2984 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
2987 /* Read in the comp unit header information from the debug_info at info_ptr.
2988 NOTE: This leaves members offset, first_die_offset to be filled in
2992 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2993 gdb_byte
*info_ptr
, bfd
*abfd
)
2996 unsigned int bytes_read
;
2998 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2999 cu_header
->initial_length_size
= bytes_read
;
3000 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3001 info_ptr
+= bytes_read
;
3002 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3004 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3006 info_ptr
+= bytes_read
;
3007 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3009 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3010 if (signed_addr
< 0)
3011 internal_error (__FILE__
, __LINE__
,
3012 _("read_comp_unit_head: dwarf from non elf file"));
3013 cu_header
->signed_addr_p
= signed_addr
;
3018 /* Subroutine of read_and_check_comp_unit_head and
3019 read_and_check_type_unit_head to simplify them.
3020 Perform various error checking on the header. */
3023 error_check_comp_unit_head (struct comp_unit_head
*header
,
3024 struct dwarf2_section_info
*section
)
3026 bfd
*abfd
= section
->asection
->owner
;
3027 const char *filename
= bfd_get_filename (abfd
);
3029 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3030 error (_("Dwarf Error: wrong version in compilation unit header "
3031 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3034 if (header
->abbrev_offset
.sect_off
3035 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3036 &dwarf2_per_objfile
->abbrev
))
3037 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3038 "(offset 0x%lx + 6) [in module %s]"),
3039 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3042 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3043 avoid potential 32-bit overflow. */
3044 if (((unsigned long) header
->offset
.sect_off
3045 + header
->length
+ header
->initial_length_size
)
3047 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3048 "(offset 0x%lx + 0) [in module %s]"),
3049 (long) header
->length
, (long) header
->offset
.sect_off
,
3053 /* Read in a CU/TU header and perform some basic error checking.
3054 The contents of the header are stored in HEADER.
3055 The result is a pointer to the start of the first DIE. */
3058 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3059 struct dwarf2_section_info
*section
,
3061 int is_debug_types_section
)
3063 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3064 bfd
*abfd
= section
->asection
->owner
;
3066 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3068 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3070 /* If we're reading a type unit, skip over the signature and
3071 type_offset fields. */
3072 if (is_debug_types_section
)
3073 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3075 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3077 error_check_comp_unit_head (header
, section
);
3082 /* Read in the types comp unit header information from .debug_types entry at
3083 types_ptr. The result is a pointer to one past the end of the header. */
3086 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3087 struct dwarf2_section_info
*section
,
3089 ULONGEST
*signature
,
3090 cu_offset
*type_offset_in_tu
)
3092 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3093 bfd
*abfd
= section
->asection
->owner
;
3095 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3097 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3099 /* If we're reading a type unit, skip over the signature and
3100 type_offset fields. */
3101 if (signature
!= NULL
)
3102 *signature
= read_8_bytes (abfd
, info_ptr
);
3104 if (type_offset_in_tu
!= NULL
)
3105 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3106 header
->offset_size
);
3107 info_ptr
+= header
->offset_size
;
3109 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3111 error_check_comp_unit_head (header
, section
);
3116 /* Allocate a new partial symtab for file named NAME and mark this new
3117 partial symtab as being an include of PST. */
3120 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3121 struct objfile
*objfile
)
3123 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3125 subpst
->section_offsets
= pst
->section_offsets
;
3126 subpst
->textlow
= 0;
3127 subpst
->texthigh
= 0;
3129 subpst
->dependencies
= (struct partial_symtab
**)
3130 obstack_alloc (&objfile
->objfile_obstack
,
3131 sizeof (struct partial_symtab
*));
3132 subpst
->dependencies
[0] = pst
;
3133 subpst
->number_of_dependencies
= 1;
3135 subpst
->globals_offset
= 0;
3136 subpst
->n_global_syms
= 0;
3137 subpst
->statics_offset
= 0;
3138 subpst
->n_static_syms
= 0;
3139 subpst
->symtab
= NULL
;
3140 subpst
->read_symtab
= pst
->read_symtab
;
3143 /* No private part is necessary for include psymtabs. This property
3144 can be used to differentiate between such include psymtabs and
3145 the regular ones. */
3146 subpst
->read_symtab_private
= NULL
;
3149 /* Read the Line Number Program data and extract the list of files
3150 included by the source file represented by PST. Build an include
3151 partial symtab for each of these included files. */
3154 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3155 struct die_info
*die
,
3156 struct partial_symtab
*pst
)
3158 struct objfile
*objfile
= cu
->objfile
;
3159 bfd
*abfd
= objfile
->obfd
;
3160 struct line_header
*lh
= NULL
;
3161 struct attribute
*attr
;
3163 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3166 unsigned int line_offset
= DW_UNSND (attr
);
3168 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3171 return; /* No linetable, so no includes. */
3173 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3174 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3176 free_line_header (lh
);
3180 hash_signatured_type (const void *item
)
3182 const struct signatured_type
*sig_type
= item
;
3184 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3185 return sig_type
->signature
;
3189 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3191 const struct signatured_type
*lhs
= item_lhs
;
3192 const struct signatured_type
*rhs
= item_rhs
;
3194 return lhs
->signature
== rhs
->signature
;
3197 /* Allocate a hash table for signatured types. */
3200 allocate_signatured_type_table (struct objfile
*objfile
)
3202 return htab_create_alloc_ex (41,
3203 hash_signatured_type
,
3206 &objfile
->objfile_obstack
,
3207 hashtab_obstack_allocate
,
3208 dummy_obstack_deallocate
);
3211 /* A helper function to add a signatured type CU to a table. */
3214 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3216 struct signatured_type
*sigt
= *slot
;
3217 struct dwarf2_per_cu_data
***datap
= datum
;
3219 **datap
= &sigt
->per_cu
;
3225 /* Create the hash table of all entries in the .debug_types section(s).
3226 The result is zero if there are no .debug_types sections,
3227 otherwise non-zero. */
3230 create_all_type_units (struct objfile
*objfile
)
3232 struct bfd
*abfd
= objfile
->obfd
;
3233 htab_t types_htab
= NULL
;
3234 struct dwarf2_per_cu_data
**iter
;
3236 struct dwarf2_section_info
*section
;
3238 if (VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
))
3240 dwarf2_per_objfile
->signatured_types
= NULL
;
3245 VEC_iterate (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
3249 gdb_byte
*info_ptr
, *end_ptr
;
3251 dwarf2_read_section (objfile
, section
);
3252 info_ptr
= section
->buffer
;
3254 if (info_ptr
== NULL
)
3257 if (types_htab
== NULL
)
3258 types_htab
= allocate_signatured_type_table (objfile
);
3260 if (dwarf2_die_debug
)
3261 fprintf_unfiltered (gdb_stdlog
, "Reading signatured types for %s:\n",
3262 bfd_get_filename (abfd
));
3264 /* We don't use init_cutu_and_read_dies_simple, or some such, here
3265 because we don't need to read any dies: the signature is in the
3268 end_ptr
= info_ptr
+ section
->size
;
3269 while (info_ptr
< end_ptr
)
3272 cu_offset type_offset
;
3274 struct signatured_type
*sig_type
;
3276 gdb_byte
*ptr
= info_ptr
;
3277 struct comp_unit_head header
;
3278 unsigned int length
;
3280 offset
.sect_off
= ptr
- section
->buffer
;
3282 /* We need to read the type's signature in order to build the hash
3283 table, but we don't need anything else just yet. */
3285 ptr
= read_and_check_type_unit_head (&header
, section
, ptr
,
3286 &signature
, &type_offset
);
3288 length
= header
.initial_length_size
+ header
.length
;
3290 /* Skip dummy type units. */
3291 if (ptr
>= info_ptr
+ length
3292 || peek_abbrev_code (abfd
, ptr
) == 0)
3294 info_ptr
+= header
.initial_length_size
+ header
.length
;
3298 sig_type
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*sig_type
));
3299 memset (sig_type
, 0, sizeof (*sig_type
));
3300 sig_type
->signature
= signature
;
3301 sig_type
->type_offset
= type_offset
;
3302 sig_type
->per_cu
.objfile
= objfile
;
3303 sig_type
->per_cu
.debug_types_section
= section
;
3304 sig_type
->per_cu
.offset
= offset
;
3306 slot
= htab_find_slot (types_htab
, sig_type
, INSERT
);
3307 gdb_assert (slot
!= NULL
);
3310 const struct signatured_type
*dup_sig
= *slot
;
3312 complaint (&symfile_complaints
,
3313 _("debug type entry at offset 0x%x is duplicate to the "
3314 "entry at offset 0x%x, signature 0x%s"),
3315 offset
.sect_off
, dup_sig
->per_cu
.offset
.sect_off
,
3316 phex (signature
, sizeof (signature
)));
3317 gdb_assert (signature
== dup_sig
->signature
);
3321 if (dwarf2_die_debug
)
3322 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3324 phex (signature
, sizeof (signature
)));
3330 dwarf2_per_objfile
->signatured_types
= types_htab
;
3332 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3333 dwarf2_per_objfile
->all_type_units
3334 = obstack_alloc (&objfile
->objfile_obstack
,
3335 dwarf2_per_objfile
->n_type_units
3336 * sizeof (struct dwarf2_per_cu_data
*));
3337 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3338 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3339 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3340 == dwarf2_per_objfile
->n_type_units
);
3345 /* Lookup a signature based type for DW_FORM_ref_sig8.
3346 Returns NULL if signature SIG is not present in the table. */
3348 static struct signatured_type
*
3349 lookup_signatured_type (ULONGEST sig
)
3351 struct signatured_type find_entry
, *entry
;
3353 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3355 complaint (&symfile_complaints
,
3356 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3360 find_entry
.signature
= sig
;
3361 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3365 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3368 init_cu_die_reader (struct die_reader_specs
*reader
,
3369 struct dwarf2_cu
*cu
,
3370 struct dwarf2_section_info
*section
)
3372 gdb_assert (section
->readin
);
3373 reader
->abfd
= section
->asection
->owner
;
3375 reader
->die_section
= section
;
3376 reader
->buffer
= section
->buffer
;
3379 /* Find the base address of the compilation unit for range lists and
3380 location lists. It will normally be specified by DW_AT_low_pc.
3381 In DWARF-3 draft 4, the base address could be overridden by
3382 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3383 compilation units with discontinuous ranges. */
3386 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3388 struct attribute
*attr
;
3391 cu
->base_address
= 0;
3393 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3396 cu
->base_address
= DW_ADDR (attr
);
3401 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3404 cu
->base_address
= DW_ADDR (attr
);
3410 /* Subroutine of init_{cu,tu}_and_read_dies.
3411 Do all the work necessary to initialize THIS_CU->cu and read in its DIE(s).
3413 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
3414 Otherwise, a new CU is allocated with xmalloc.
3416 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
3417 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
3419 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3420 linker) then DIE_READER_FUNC will not get called.
3422 FIXME: As an implementation detail between our callers and us,
3423 USE_EXISTING_CU and KEEP are OK. But bubbling them up into their callers
3424 isn't as clean as I'd like. Having more callers with good names
3425 may be the way to go. */
3428 init_and_read_dies_worker (struct dwarf2_per_cu_data
*this_cu
,
3429 int use_existing_cu
, int keep
,
3430 die_reader_func_ftype
*die_reader_func
,
3433 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3434 struct dwarf2_section_info
*section
;
3436 struct dwarf2_cu
*cu
;
3437 gdb_byte
*begin_info_ptr
, *info_ptr
;
3438 struct die_reader_specs reader
;
3439 struct die_info
*comp_unit_die
;
3441 struct attribute
*attr
;
3442 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
3443 struct signatured_type
*sig_type
= NULL
;
3445 if (use_existing_cu
)
3447 if (this_cu
->debug_types_section
)
3448 gdb_assert (! use_existing_cu
);
3450 if (this_cu
->debug_types_section
)
3451 section
= this_cu
->debug_types_section
;
3453 section
= &dwarf2_per_objfile
->info
;
3454 abfd
= section
->asection
->owner
;
3456 cleanups
= make_cleanup (null_cleanup
, NULL
);
3458 /* This is cheap if the section is already read in. */
3459 dwarf2_read_section (objfile
, section
);
3461 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3463 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
3466 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
3470 /* If !use_existing_cu, this_cu->cu must be NULL. */
3471 gdb_assert (this_cu
->cu
== NULL
);
3473 cu
= xmalloc (sizeof (*cu
));
3474 init_one_comp_unit (cu
, this_cu
);
3476 /* If an error occurs while loading, release our storage. */
3477 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3479 if (this_cu
->debug_types_section
)
3483 info_ptr
= read_and_check_type_unit_head (&cu
->header
,
3487 /* There's no way to get from PER_CU to its containing
3488 struct signatured_type.
3489 But we have the signature so we can use that. */
3490 sig_type
= lookup_signatured_type (signature
);
3491 /* We've already scanned all the signatured types,
3492 this must succeed. */
3493 gdb_assert (sig_type
!= NULL
);
3494 gdb_assert (&sig_type
->per_cu
== this_cu
);
3495 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3497 /* LENGTH has not been set yet for type units. */
3498 this_cu
->length
= cu
->header
.length
+ cu
->header
.initial_length_size
;
3502 info_ptr
= read_and_check_comp_unit_head (&cu
->header
,
3503 section
, info_ptr
, 0);
3505 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3506 gdb_assert (this_cu
->length
3507 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3511 /* Skip dummy compilation units. */
3512 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
3513 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3515 do_cleanups (cleanups
);
3519 /* Read the abbrevs for this compilation unit into a table. */
3520 if (cu
->dwarf2_abbrevs
== NULL
)
3522 dwarf2_read_abbrevs (cu
, &dwarf2_per_objfile
->abbrev
);
3523 make_cleanup (dwarf2_free_abbrev_table
, cu
);
3526 /* Read the top level CU/TU die. */
3527 init_cu_die_reader (&reader
, cu
, section
);
3528 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
3530 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
3532 if (free_cu_cleanup
!= NULL
)
3536 /* We've successfully allocated this compilation unit. Let our
3537 caller clean it up when finished with it. */
3538 discard_cleanups (free_cu_cleanup
);
3540 /* We can only discard free_cu_cleanup and all subsequent cleanups.
3541 So we have to manually free the abbrev table. */
3542 dwarf2_free_abbrev_table (cu
);
3544 /* Link this CU into read_in_chain. */
3545 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3546 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3549 do_cleanups (free_cu_cleanup
);
3552 do_cleanups (cleanups
);
3555 /* Main entry point for reading a CU.
3556 Do all the work necessary to initialize THIS_CU->cu and read in its DIE(s).
3558 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
3559 Otherwise, a new CU is allocated with xmalloc.
3561 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
3562 read_in_chain. Otherwise the dwarf2_cu data is freed at the end. */
3565 init_cu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
3566 int use_existing_cu
, int keep
,
3567 die_reader_func_ftype
*die_reader_func
,
3570 init_and_read_dies_worker (this_cu
, use_existing_cu
, keep
,
3571 die_reader_func
, data
);
3574 /* Main entry point for reading a TU.
3575 Do all the work necessary to initialize THIS_CU->cu and read in its DIE(s).
3577 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
3578 read_in_chain. Otherwise the dwarf2_cu data is freed at the end. */
3581 init_tu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
3583 die_reader_func_ftype
*die_reader_func
,
3586 gdb_assert (this_cu
->debug_types_section
);
3587 init_and_read_dies_worker (this_cu
, 0, keep
, die_reader_func
, data
);
3590 /* Read the CU/TU at OFFSET in section SECTION.
3592 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
3593 THIS_CU->debug_types_section, but nothing else.
3595 We fill in THIS_CU->length.
3597 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3598 linker) then DIE_READER_FUNC will not get called.
3600 THIS_CU->cu is always freed when done.
3601 [This is done for Fission reasons, to be specified.] */
3604 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
3605 struct dwarf2_section_info
*abbrev_section
,
3606 die_reader_func_ftype
*die_reader_func
,
3609 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3610 struct dwarf2_section_info
*section
;
3612 struct dwarf2_cu cu
;
3613 gdb_byte
*begin_info_ptr
, *info_ptr
;
3614 struct die_reader_specs reader
;
3615 struct cleanup
*cleanups
;
3616 struct die_info
*comp_unit_die
;
3619 gdb_assert (this_cu
->cu
== NULL
);
3621 if (this_cu
->debug_types_section
)
3622 section
= this_cu
->debug_types_section
;
3624 section
= &dwarf2_per_objfile
->info
;
3625 abfd
= section
->asection
->owner
;
3627 /* This is cheap if the section is already read in. */
3628 dwarf2_read_section (objfile
, section
);
3630 init_one_comp_unit (&cu
, this_cu
);
3632 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
3634 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3635 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
, info_ptr
,
3636 this_cu
->debug_types_section
!= NULL
);
3638 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3640 /* Skip dummy compilation units. */
3641 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
3642 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3644 do_cleanups (cleanups
);
3648 dwarf2_read_abbrevs (&cu
, abbrev_section
);
3649 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3651 init_cu_die_reader (&reader
, &cu
, section
);
3652 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
3654 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
3656 do_cleanups (cleanups
);
3660 [This is a separate routine for Fission, to be specified.]
3662 THIS_CU->cu is always freed when done.
3663 [This is done for Fission reasons, to be specified.] */
3666 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
3667 die_reader_func_ftype
*die_reader_func
,
3670 init_cutu_and_read_dies_no_follow (this_cu
,
3671 &dwarf2_per_objfile
->abbrev
,
3672 die_reader_func
, data
);
3675 /* die_reader_func for process_psymtab_comp_unit. */
3678 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
3680 struct die_info
*comp_unit_die
,
3684 struct dwarf2_cu
*cu
= reader
->cu
;
3685 struct objfile
*objfile
= cu
->objfile
;
3686 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
3687 bfd
*abfd
= objfile
->obfd
;
3688 struct attribute
*attr
;
3690 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3691 struct partial_symtab
*pst
;
3693 const char *filename
;
3695 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3698 prepare_one_comp_unit (cu
, comp_unit_die
);
3700 cu
->list_in_scope
= &file_symbols
;
3702 /* Allocate a new partial symbol table structure. */
3703 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
3704 if (attr
== NULL
|| !DW_STRING (attr
))
3707 filename
= DW_STRING (attr
);
3708 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3710 /* TEXTLOW and TEXTHIGH are set below. */
3712 objfile
->global_psymbols
.next
,
3713 objfile
->static_psymbols
.next
);
3714 pst
->psymtabs_addrmap_supported
= 1;
3716 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
3718 pst
->dirname
= DW_STRING (attr
);
3720 pst
->read_symtab_private
= per_cu
;
3722 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3724 /* Store the function that reads in the rest of the symbol table. */
3725 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3727 per_cu
->v
.psymtab
= pst
;
3729 dwarf2_find_base_address (comp_unit_die
, cu
);
3731 /* Possibly set the default values of LOWPC and HIGHPC from
3733 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3734 &best_highpc
, cu
, pst
);
3735 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3736 /* Store the contiguous range if it is not empty; it can be empty for
3737 CUs with no code. */
3738 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3739 best_lowpc
+ baseaddr
,
3740 best_highpc
+ baseaddr
- 1, pst
);
3742 /* Check if comp unit has_children.
3743 If so, read the rest of the partial symbols from this comp unit.
3744 If not, there's no more debug_info for this comp unit. */
3747 struct partial_die_info
*first_die
;
3748 CORE_ADDR lowpc
, highpc
;
3750 lowpc
= ((CORE_ADDR
) -1);
3751 highpc
= ((CORE_ADDR
) 0);
3753 first_die
= load_partial_dies (reader
, info_ptr
, 1);
3755 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3758 /* If we didn't find a lowpc, set it to highpc to avoid
3759 complaints from `maint check'. */
3760 if (lowpc
== ((CORE_ADDR
) -1))
3763 /* If the compilation unit didn't have an explicit address range,
3764 then use the information extracted from its child dies. */
3768 best_highpc
= highpc
;
3771 pst
->textlow
= best_lowpc
+ baseaddr
;
3772 pst
->texthigh
= best_highpc
+ baseaddr
;
3774 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3775 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3776 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3777 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3778 sort_pst_symbols (pst
);
3780 if (per_cu
->debug_types_section
)
3782 /* It's not clear we want to do anything with stmt lists here.
3783 Waiting to see what gcc ultimately does. */
3787 /* Get the list of files included in the current compilation unit,
3788 and build a psymtab for each of them. */
3789 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
3793 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3794 Process compilation unit THIS_CU for a psymtab. */
3797 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
3799 /* If this compilation unit was already read in, free the
3800 cached copy in order to read it in again. This is
3801 necessary because we skipped some symbols when we first
3802 read in the compilation unit (see load_partial_dies).
3803 This problem could be avoided, but the benefit is unclear. */
3804 if (this_cu
->cu
!= NULL
)
3805 free_one_cached_comp_unit (this_cu
);
3807 gdb_assert (! this_cu
->debug_types_section
);
3808 init_cu_and_read_dies (this_cu
, 0, 0, process_psymtab_comp_unit_reader
,
3811 /* Age out any secondary CUs. */
3812 age_cached_comp_units ();
3815 /* Traversal function for htab_traverse_noresize.
3816 Process one .debug_types comp-unit. */
3819 process_psymtab_type_unit (void **slot
, void *info
)
3821 struct signatured_type
*sig_type
= (struct signatured_type
*) *slot
;
3822 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
3824 gdb_assert (info
== NULL
);
3826 /* If this compilation unit was already read in, free the
3827 cached copy in order to read it in again. This is
3828 necessary because we skipped some symbols when we first
3829 read in the compilation unit (see load_partial_dies).
3830 This problem could be avoided, but the benefit is unclear. */
3831 if (per_cu
->cu
!= NULL
)
3832 free_one_cached_comp_unit (per_cu
);
3834 gdb_assert (per_cu
->debug_types_section
);
3835 init_tu_and_read_dies (per_cu
, 0, process_psymtab_comp_unit_reader
, NULL
);
3837 /* Age out any secondary CUs. */
3838 age_cached_comp_units ();
3843 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3844 Build partial symbol tables for the .debug_types comp-units. */
3847 build_type_psymtabs (struct objfile
*objfile
)
3849 if (! create_all_type_units (objfile
))
3852 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3853 process_psymtab_type_unit
, NULL
);
3856 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3859 psymtabs_addrmap_cleanup (void *o
)
3861 struct objfile
*objfile
= o
;
3863 objfile
->psymtabs_addrmap
= NULL
;
3866 /* Build the partial symbol table by doing a quick pass through the
3867 .debug_info and .debug_abbrev sections. */
3870 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3872 struct cleanup
*back_to
, *addrmap_cleanup
;
3873 struct obstack temp_obstack
;
3876 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3878 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3880 /* Any cached compilation units will be linked by the per-objfile
3881 read_in_chain. Make sure to free them when we're done. */
3882 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3884 build_type_psymtabs (objfile
);
3886 create_all_comp_units (objfile
);
3888 /* Create a temporary address map on a temporary obstack. We later
3889 copy this to the final obstack. */
3890 obstack_init (&temp_obstack
);
3891 make_cleanup_obstack_free (&temp_obstack
);
3892 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3893 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3895 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3897 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3899 process_psymtab_comp_unit (per_cu
);
3902 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3903 &objfile
->objfile_obstack
);
3904 discard_cleanups (addrmap_cleanup
);
3906 do_cleanups (back_to
);
3909 /* Load the partial DIEs for a secondary CU into memory. */
3912 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
3914 struct die_info
*comp_unit_die
,
3918 struct dwarf2_cu
*cu
= reader
->cu
;
3920 prepare_one_comp_unit (cu
, comp_unit_die
);
3922 /* Check if comp unit has_children.
3923 If so, read the rest of the partial symbols from this comp unit.
3924 If not, there's no more debug_info for this comp unit. */
3926 load_partial_dies (reader
, info_ptr
, 0);
3929 /* Load the partial DIEs for a secondary CU into memory.
3930 This is also used when rereading a primary CU with load_all_dies. */
3933 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
3935 if (this_cu
->debug_types_section
)
3936 init_tu_and_read_dies (this_cu
, 1, load_partial_comp_unit_reader
, NULL
);
3938 init_cu_and_read_dies (this_cu
, 0, 1, load_partial_comp_unit_reader
, NULL
);
3941 /* Create a list of all compilation units in OBJFILE.
3942 This is only done for -readnow and building partial symtabs. */
3945 create_all_comp_units (struct objfile
*objfile
)
3949 struct dwarf2_per_cu_data
**all_comp_units
;
3952 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3953 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3957 all_comp_units
= xmalloc (n_allocated
3958 * sizeof (struct dwarf2_per_cu_data
*));
3960 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3961 + dwarf2_per_objfile
->info
.size
)
3963 unsigned int length
, initial_length_size
;
3964 struct dwarf2_per_cu_data
*this_cu
;
3967 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3969 /* Read just enough information to find out where the next
3970 compilation unit is. */
3971 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3972 &initial_length_size
);
3974 /* Save the compilation unit for later lookup. */
3975 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3976 sizeof (struct dwarf2_per_cu_data
));
3977 memset (this_cu
, 0, sizeof (*this_cu
));
3978 this_cu
->offset
= offset
;
3979 this_cu
->length
= length
+ initial_length_size
;
3980 this_cu
->objfile
= objfile
;
3982 if (n_comp_units
== n_allocated
)
3985 all_comp_units
= xrealloc (all_comp_units
,
3987 * sizeof (struct dwarf2_per_cu_data
*));
3989 all_comp_units
[n_comp_units
++] = this_cu
;
3991 info_ptr
= info_ptr
+ this_cu
->length
;
3994 dwarf2_per_objfile
->all_comp_units
3995 = obstack_alloc (&objfile
->objfile_obstack
,
3996 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3997 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3998 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3999 xfree (all_comp_units
);
4000 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
4003 /* Process all loaded DIEs for compilation unit CU, starting at
4004 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
4005 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
4006 DW_AT_ranges). If NEED_PC is set, then this function will set
4007 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
4008 and record the covered ranges in the addrmap. */
4011 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
4012 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4014 struct partial_die_info
*pdi
;
4016 /* Now, march along the PDI's, descending into ones which have
4017 interesting children but skipping the children of the other ones,
4018 until we reach the end of the compilation unit. */
4024 fixup_partial_die (pdi
, cu
);
4026 /* Anonymous namespaces or modules have no name but have interesting
4027 children, so we need to look at them. Ditto for anonymous
4030 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
4031 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
4035 case DW_TAG_subprogram
:
4036 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4038 case DW_TAG_constant
:
4039 case DW_TAG_variable
:
4040 case DW_TAG_typedef
:
4041 case DW_TAG_union_type
:
4042 if (!pdi
->is_declaration
)
4044 add_partial_symbol (pdi
, cu
);
4047 case DW_TAG_class_type
:
4048 case DW_TAG_interface_type
:
4049 case DW_TAG_structure_type
:
4050 if (!pdi
->is_declaration
)
4052 add_partial_symbol (pdi
, cu
);
4055 case DW_TAG_enumeration_type
:
4056 if (!pdi
->is_declaration
)
4057 add_partial_enumeration (pdi
, cu
);
4059 case DW_TAG_base_type
:
4060 case DW_TAG_subrange_type
:
4061 /* File scope base type definitions are added to the partial
4063 add_partial_symbol (pdi
, cu
);
4065 case DW_TAG_namespace
:
4066 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
4069 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
4076 /* If the die has a sibling, skip to the sibling. */
4078 pdi
= pdi
->die_sibling
;
4082 /* Functions used to compute the fully scoped name of a partial DIE.
4084 Normally, this is simple. For C++, the parent DIE's fully scoped
4085 name is concatenated with "::" and the partial DIE's name. For
4086 Java, the same thing occurs except that "." is used instead of "::".
4087 Enumerators are an exception; they use the scope of their parent
4088 enumeration type, i.e. the name of the enumeration type is not
4089 prepended to the enumerator.
4091 There are two complexities. One is DW_AT_specification; in this
4092 case "parent" means the parent of the target of the specification,
4093 instead of the direct parent of the DIE. The other is compilers
4094 which do not emit DW_TAG_namespace; in this case we try to guess
4095 the fully qualified name of structure types from their members'
4096 linkage names. This must be done using the DIE's children rather
4097 than the children of any DW_AT_specification target. We only need
4098 to do this for structures at the top level, i.e. if the target of
4099 any DW_AT_specification (if any; otherwise the DIE itself) does not
4102 /* Compute the scope prefix associated with PDI's parent, in
4103 compilation unit CU. The result will be allocated on CU's
4104 comp_unit_obstack, or a copy of the already allocated PDI->NAME
4105 field. NULL is returned if no prefix is necessary. */
4107 partial_die_parent_scope (struct partial_die_info
*pdi
,
4108 struct dwarf2_cu
*cu
)
4110 char *grandparent_scope
;
4111 struct partial_die_info
*parent
, *real_pdi
;
4113 /* We need to look at our parent DIE; if we have a DW_AT_specification,
4114 then this means the parent of the specification DIE. */
4117 while (real_pdi
->has_specification
)
4118 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
4120 parent
= real_pdi
->die_parent
;
4124 if (parent
->scope_set
)
4125 return parent
->scope
;
4127 fixup_partial_die (parent
, cu
);
4129 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
4131 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
4132 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
4133 Work around this problem here. */
4134 if (cu
->language
== language_cplus
4135 && parent
->tag
== DW_TAG_namespace
4136 && strcmp (parent
->name
, "::") == 0
4137 && grandparent_scope
== NULL
)
4139 parent
->scope
= NULL
;
4140 parent
->scope_set
= 1;
4144 if (pdi
->tag
== DW_TAG_enumerator
)
4145 /* Enumerators should not get the name of the enumeration as a prefix. */
4146 parent
->scope
= grandparent_scope
;
4147 else if (parent
->tag
== DW_TAG_namespace
4148 || parent
->tag
== DW_TAG_module
4149 || parent
->tag
== DW_TAG_structure_type
4150 || parent
->tag
== DW_TAG_class_type
4151 || parent
->tag
== DW_TAG_interface_type
4152 || parent
->tag
== DW_TAG_union_type
4153 || parent
->tag
== DW_TAG_enumeration_type
)
4155 if (grandparent_scope
== NULL
)
4156 parent
->scope
= parent
->name
;
4158 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
4160 parent
->name
, 0, cu
);
4164 /* FIXME drow/2004-04-01: What should we be doing with
4165 function-local names? For partial symbols, we should probably be
4167 complaint (&symfile_complaints
,
4168 _("unhandled containing DIE tag %d for DIE at %d"),
4169 parent
->tag
, pdi
->offset
.sect_off
);
4170 parent
->scope
= grandparent_scope
;
4173 parent
->scope_set
= 1;
4174 return parent
->scope
;
4177 /* Return the fully scoped name associated with PDI, from compilation unit
4178 CU. The result will be allocated with malloc. */
4181 partial_die_full_name (struct partial_die_info
*pdi
,
4182 struct dwarf2_cu
*cu
)
4186 /* If this is a template instantiation, we can not work out the
4187 template arguments from partial DIEs. So, unfortunately, we have
4188 to go through the full DIEs. At least any work we do building
4189 types here will be reused if full symbols are loaded later. */
4190 if (pdi
->has_template_arguments
)
4192 fixup_partial_die (pdi
, cu
);
4194 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4196 struct die_info
*die
;
4197 struct attribute attr
;
4198 struct dwarf2_cu
*ref_cu
= cu
;
4200 /* DW_FORM_ref_addr is using section offset. */
4202 attr
.form
= DW_FORM_ref_addr
;
4203 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
4204 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4206 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4210 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4211 if (parent_scope
== NULL
)
4214 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4218 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4220 struct objfile
*objfile
= cu
->objfile
;
4222 char *actual_name
= NULL
;
4224 int built_actual_name
= 0;
4226 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4228 actual_name
= partial_die_full_name (pdi
, cu
);
4230 built_actual_name
= 1;
4232 if (actual_name
== NULL
)
4233 actual_name
= pdi
->name
;
4237 case DW_TAG_subprogram
:
4238 if (pdi
->is_external
|| cu
->language
== language_ada
)
4240 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4241 of the global scope. But in Ada, we want to be able to access
4242 nested procedures globally. So all Ada subprograms are stored
4243 in the global scope. */
4244 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4245 mst_text, objfile); */
4246 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4248 VAR_DOMAIN
, LOC_BLOCK
,
4249 &objfile
->global_psymbols
,
4250 0, pdi
->lowpc
+ baseaddr
,
4251 cu
->language
, objfile
);
4255 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4256 mst_file_text, objfile); */
4257 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4259 VAR_DOMAIN
, LOC_BLOCK
,
4260 &objfile
->static_psymbols
,
4261 0, pdi
->lowpc
+ baseaddr
,
4262 cu
->language
, objfile
);
4265 case DW_TAG_constant
:
4267 struct psymbol_allocation_list
*list
;
4269 if (pdi
->is_external
)
4270 list
= &objfile
->global_psymbols
;
4272 list
= &objfile
->static_psymbols
;
4273 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4274 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4275 list
, 0, 0, cu
->language
, objfile
);
4278 case DW_TAG_variable
:
4280 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4284 && !dwarf2_per_objfile
->has_section_at_zero
)
4286 /* A global or static variable may also have been stripped
4287 out by the linker if unused, in which case its address
4288 will be nullified; do not add such variables into partial
4289 symbol table then. */
4291 else if (pdi
->is_external
)
4294 Don't enter into the minimal symbol tables as there is
4295 a minimal symbol table entry from the ELF symbols already.
4296 Enter into partial symbol table if it has a location
4297 descriptor or a type.
4298 If the location descriptor is missing, new_symbol will create
4299 a LOC_UNRESOLVED symbol, the address of the variable will then
4300 be determined from the minimal symbol table whenever the variable
4302 The address for the partial symbol table entry is not
4303 used by GDB, but it comes in handy for debugging partial symbol
4306 if (pdi
->locdesc
|| pdi
->has_type
)
4307 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4309 VAR_DOMAIN
, LOC_STATIC
,
4310 &objfile
->global_psymbols
,
4312 cu
->language
, objfile
);
4316 /* Static Variable. Skip symbols without location descriptors. */
4317 if (pdi
->locdesc
== NULL
)
4319 if (built_actual_name
)
4320 xfree (actual_name
);
4323 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4324 mst_file_data, objfile); */
4325 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4327 VAR_DOMAIN
, LOC_STATIC
,
4328 &objfile
->static_psymbols
,
4330 cu
->language
, objfile
);
4333 case DW_TAG_typedef
:
4334 case DW_TAG_base_type
:
4335 case DW_TAG_subrange_type
:
4336 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4338 VAR_DOMAIN
, LOC_TYPEDEF
,
4339 &objfile
->static_psymbols
,
4340 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4342 case DW_TAG_namespace
:
4343 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4345 VAR_DOMAIN
, LOC_TYPEDEF
,
4346 &objfile
->global_psymbols
,
4347 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4349 case DW_TAG_class_type
:
4350 case DW_TAG_interface_type
:
4351 case DW_TAG_structure_type
:
4352 case DW_TAG_union_type
:
4353 case DW_TAG_enumeration_type
:
4354 /* Skip external references. The DWARF standard says in the section
4355 about "Structure, Union, and Class Type Entries": "An incomplete
4356 structure, union or class type is represented by a structure,
4357 union or class entry that does not have a byte size attribute
4358 and that has a DW_AT_declaration attribute." */
4359 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4361 if (built_actual_name
)
4362 xfree (actual_name
);
4366 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4367 static vs. global. */
4368 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4370 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4371 (cu
->language
== language_cplus
4372 || cu
->language
== language_java
)
4373 ? &objfile
->global_psymbols
4374 : &objfile
->static_psymbols
,
4375 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4378 case DW_TAG_enumerator
:
4379 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4381 VAR_DOMAIN
, LOC_CONST
,
4382 (cu
->language
== language_cplus
4383 || cu
->language
== language_java
)
4384 ? &objfile
->global_psymbols
4385 : &objfile
->static_psymbols
,
4386 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4392 if (built_actual_name
)
4393 xfree (actual_name
);
4396 /* Read a partial die corresponding to a namespace; also, add a symbol
4397 corresponding to that namespace to the symbol table. NAMESPACE is
4398 the name of the enclosing namespace. */
4401 add_partial_namespace (struct partial_die_info
*pdi
,
4402 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4403 int need_pc
, struct dwarf2_cu
*cu
)
4405 /* Add a symbol for the namespace. */
4407 add_partial_symbol (pdi
, cu
);
4409 /* Now scan partial symbols in that namespace. */
4411 if (pdi
->has_children
)
4412 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4415 /* Read a partial die corresponding to a Fortran module. */
4418 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4419 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4421 /* Now scan partial symbols in that module. */
4423 if (pdi
->has_children
)
4424 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4427 /* Read a partial die corresponding to a subprogram and create a partial
4428 symbol for that subprogram. When the CU language allows it, this
4429 routine also defines a partial symbol for each nested subprogram
4430 that this subprogram contains.
4432 DIE my also be a lexical block, in which case we simply search
4433 recursively for suprograms defined inside that lexical block.
4434 Again, this is only performed when the CU language allows this
4435 type of definitions. */
4438 add_partial_subprogram (struct partial_die_info
*pdi
,
4439 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4440 int need_pc
, struct dwarf2_cu
*cu
)
4442 if (pdi
->tag
== DW_TAG_subprogram
)
4444 if (pdi
->has_pc_info
)
4446 if (pdi
->lowpc
< *lowpc
)
4447 *lowpc
= pdi
->lowpc
;
4448 if (pdi
->highpc
> *highpc
)
4449 *highpc
= pdi
->highpc
;
4453 struct objfile
*objfile
= cu
->objfile
;
4455 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4456 SECT_OFF_TEXT (objfile
));
4457 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4458 pdi
->lowpc
+ baseaddr
,
4459 pdi
->highpc
- 1 + baseaddr
,
4460 cu
->per_cu
->v
.psymtab
);
4464 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
4466 if (!pdi
->is_declaration
)
4467 /* Ignore subprogram DIEs that do not have a name, they are
4468 illegal. Do not emit a complaint at this point, we will
4469 do so when we convert this psymtab into a symtab. */
4471 add_partial_symbol (pdi
, cu
);
4475 if (! pdi
->has_children
)
4478 if (cu
->language
== language_ada
)
4480 pdi
= pdi
->die_child
;
4483 fixup_partial_die (pdi
, cu
);
4484 if (pdi
->tag
== DW_TAG_subprogram
4485 || pdi
->tag
== DW_TAG_lexical_block
)
4486 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4487 pdi
= pdi
->die_sibling
;
4492 /* Read a partial die corresponding to an enumeration type. */
4495 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4496 struct dwarf2_cu
*cu
)
4498 struct partial_die_info
*pdi
;
4500 if (enum_pdi
->name
!= NULL
)
4501 add_partial_symbol (enum_pdi
, cu
);
4503 pdi
= enum_pdi
->die_child
;
4506 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4507 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4509 add_partial_symbol (pdi
, cu
);
4510 pdi
= pdi
->die_sibling
;
4514 /* Return the initial uleb128 in the die at INFO_PTR. */
4517 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4519 unsigned int bytes_read
;
4521 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4524 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4525 Return the corresponding abbrev, or NULL if the number is zero (indicating
4526 an empty DIE). In either case *BYTES_READ will be set to the length of
4527 the initial number. */
4529 static struct abbrev_info
*
4530 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4531 struct dwarf2_cu
*cu
)
4533 bfd
*abfd
= cu
->objfile
->obfd
;
4534 unsigned int abbrev_number
;
4535 struct abbrev_info
*abbrev
;
4537 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4539 if (abbrev_number
== 0)
4542 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4545 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4546 abbrev_number
, bfd_get_filename (abfd
));
4552 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4553 Returns a pointer to the end of a series of DIEs, terminated by an empty
4554 DIE. Any children of the skipped DIEs will also be skipped. */
4557 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
4559 struct dwarf2_cu
*cu
= reader
->cu
;
4560 struct abbrev_info
*abbrev
;
4561 unsigned int bytes_read
;
4565 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4567 return info_ptr
+ bytes_read
;
4569 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
4573 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4574 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4575 abbrev corresponding to that skipped uleb128 should be passed in
4576 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4580 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
4581 struct abbrev_info
*abbrev
)
4583 unsigned int bytes_read
;
4584 struct attribute attr
;
4585 bfd
*abfd
= reader
->abfd
;
4586 struct dwarf2_cu
*cu
= reader
->cu
;
4587 gdb_byte
*buffer
= reader
->buffer
;
4588 unsigned int form
, i
;
4590 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4592 /* The only abbrev we care about is DW_AT_sibling. */
4593 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4595 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
4596 if (attr
.form
== DW_FORM_ref_addr
)
4597 complaint (&symfile_complaints
,
4598 _("ignoring absolute DW_AT_sibling"));
4600 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
4603 /* If it isn't DW_AT_sibling, skip this attribute. */
4604 form
= abbrev
->attrs
[i
].form
;
4608 case DW_FORM_ref_addr
:
4609 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4610 and later it is offset sized. */
4611 if (cu
->header
.version
== 2)
4612 info_ptr
+= cu
->header
.addr_size
;
4614 info_ptr
+= cu
->header
.offset_size
;
4617 info_ptr
+= cu
->header
.addr_size
;
4624 case DW_FORM_flag_present
:
4636 case DW_FORM_ref_sig8
:
4639 case DW_FORM_string
:
4640 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4641 info_ptr
+= bytes_read
;
4643 case DW_FORM_sec_offset
:
4645 info_ptr
+= cu
->header
.offset_size
;
4647 case DW_FORM_exprloc
:
4649 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4650 info_ptr
+= bytes_read
;
4652 case DW_FORM_block1
:
4653 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4655 case DW_FORM_block2
:
4656 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4658 case DW_FORM_block4
:
4659 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4663 case DW_FORM_ref_udata
:
4664 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4666 case DW_FORM_indirect
:
4667 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4668 info_ptr
+= bytes_read
;
4669 /* We need to continue parsing from here, so just go back to
4671 goto skip_attribute
;
4674 error (_("Dwarf Error: Cannot handle %s "
4675 "in DWARF reader [in module %s]"),
4676 dwarf_form_name (form
),
4677 bfd_get_filename (abfd
));
4681 if (abbrev
->has_children
)
4682 return skip_children (reader
, info_ptr
);
4687 /* Locate ORIG_PDI's sibling.
4688 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
4691 locate_pdi_sibling (const struct die_reader_specs
*reader
,
4692 struct partial_die_info
*orig_pdi
,
4695 /* Do we know the sibling already? */
4697 if (orig_pdi
->sibling
)
4698 return orig_pdi
->sibling
;
4700 /* Are there any children to deal with? */
4702 if (!orig_pdi
->has_children
)
4705 /* Skip the children the long way. */
4707 return skip_children (reader
, info_ptr
);
4710 /* Expand this partial symbol table into a full symbol table. */
4713 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4719 warning (_("bug: psymtab for %s is already read in."),
4726 printf_filtered (_("Reading in symbols for %s..."),
4728 gdb_flush (gdb_stdout
);
4731 /* Restore our global data. */
4732 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4733 dwarf2_objfile_data_key
);
4735 /* If this psymtab is constructed from a debug-only objfile, the
4736 has_section_at_zero flag will not necessarily be correct. We
4737 can get the correct value for this flag by looking at the data
4738 associated with the (presumably stripped) associated objfile. */
4739 if (pst
->objfile
->separate_debug_objfile_backlink
)
4741 struct dwarf2_per_objfile
*dpo_backlink
4742 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4743 dwarf2_objfile_data_key
);
4745 dwarf2_per_objfile
->has_section_at_zero
4746 = dpo_backlink
->has_section_at_zero
;
4749 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4751 psymtab_to_symtab_1 (pst
);
4753 /* Finish up the debug error message. */
4755 printf_filtered (_("done.\n"));
4760 /* Reading in full CUs. */
4762 /* Add PER_CU to the queue. */
4765 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4767 struct dwarf2_queue_item
*item
;
4770 item
= xmalloc (sizeof (*item
));
4771 item
->per_cu
= per_cu
;
4774 if (dwarf2_queue
== NULL
)
4775 dwarf2_queue
= item
;
4777 dwarf2_queue_tail
->next
= item
;
4779 dwarf2_queue_tail
= item
;
4782 /* Process the queue. */
4785 process_queue (void)
4787 struct dwarf2_queue_item
*item
, *next_item
;
4789 /* The queue starts out with one item, but following a DIE reference
4790 may load a new CU, adding it to the end of the queue. */
4791 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4793 if (dwarf2_per_objfile
->using_index
4794 ? !item
->per_cu
->v
.quick
->symtab
4795 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4796 process_full_comp_unit (item
->per_cu
);
4798 item
->per_cu
->queued
= 0;
4799 next_item
= item
->next
;
4803 dwarf2_queue_tail
= NULL
;
4806 /* Free all allocated queue entries. This function only releases anything if
4807 an error was thrown; if the queue was processed then it would have been
4808 freed as we went along. */
4811 dwarf2_release_queue (void *dummy
)
4813 struct dwarf2_queue_item
*item
, *last
;
4815 item
= dwarf2_queue
;
4818 /* Anything still marked queued is likely to be in an
4819 inconsistent state, so discard it. */
4820 if (item
->per_cu
->queued
)
4822 if (item
->per_cu
->cu
!= NULL
)
4823 free_one_cached_comp_unit (item
->per_cu
);
4824 item
->per_cu
->queued
= 0;
4832 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4835 /* Read in full symbols for PST, and anything it depends on. */
4838 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4840 struct dwarf2_per_cu_data
*per_cu
;
4841 struct cleanup
*back_to
;
4844 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4845 if (!pst
->dependencies
[i
]->readin
)
4847 /* Inform about additional files that need to be read in. */
4850 /* FIXME: i18n: Need to make this a single string. */
4851 fputs_filtered (" ", gdb_stdout
);
4853 fputs_filtered ("and ", gdb_stdout
);
4855 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4856 wrap_here (""); /* Flush output. */
4857 gdb_flush (gdb_stdout
);
4859 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4862 per_cu
= pst
->read_symtab_private
;
4866 /* It's an include file, no symbols to read for it.
4867 Everything is in the parent symtab. */
4872 dw2_do_instantiate_symtab (per_cu
);
4875 /* Trivial hash function for die_info: the hash value of a DIE
4876 is its offset in .debug_info for this objfile. */
4879 die_hash (const void *item
)
4881 const struct die_info
*die
= item
;
4883 return die
->offset
.sect_off
;
4886 /* Trivial comparison function for die_info structures: two DIEs
4887 are equal if they have the same offset. */
4890 die_eq (const void *item_lhs
, const void *item_rhs
)
4892 const struct die_info
*die_lhs
= item_lhs
;
4893 const struct die_info
*die_rhs
= item_rhs
;
4895 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
4898 /* die_reader_func for load_full_comp_unit.
4899 This is identical to read_signatured_type_reader,
4900 but is kept separate for now. */
4903 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
4905 struct die_info
*comp_unit_die
,
4909 struct dwarf2_cu
*cu
= reader
->cu
;
4910 struct attribute
*attr
;
4912 gdb_assert (cu
->die_hash
== NULL
);
4914 htab_create_alloc_ex (cu
->header
.length
/ 12,
4918 &cu
->comp_unit_obstack
,
4919 hashtab_obstack_allocate
,
4920 dummy_obstack_deallocate
);
4923 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
4924 &info_ptr
, comp_unit_die
);
4925 cu
->dies
= comp_unit_die
;
4926 /* comp_unit_die is not stored in die_hash, no need. */
4928 /* We try not to read any attributes in this function, because not
4929 all CUs needed for references have been loaded yet, and symbol
4930 table processing isn't initialized. But we have to set the CU language,
4931 or we won't be able to build types correctly.
4932 Similarly, if we do not read the producer, we can not apply
4933 producer-specific interpretation. */
4934 prepare_one_comp_unit (cu
, cu
->dies
);
4937 /* Load the DIEs associated with PER_CU into memory. */
4940 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
4942 gdb_assert (! this_cu
->debug_types_section
);
4944 init_cu_and_read_dies (this_cu
, 1, 1, load_full_comp_unit_reader
, NULL
);
4947 /* Add a DIE to the delayed physname list. */
4950 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4951 const char *name
, struct die_info
*die
,
4952 struct dwarf2_cu
*cu
)
4954 struct delayed_method_info mi
;
4956 mi
.fnfield_index
= fnfield_index
;
4960 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4963 /* A cleanup for freeing the delayed method list. */
4966 free_delayed_list (void *ptr
)
4968 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4969 if (cu
->method_list
!= NULL
)
4971 VEC_free (delayed_method_info
, cu
->method_list
);
4972 cu
->method_list
= NULL
;
4976 /* Compute the physnames of any methods on the CU's method list.
4978 The computation of method physnames is delayed in order to avoid the
4979 (bad) condition that one of the method's formal parameters is of an as yet
4983 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4986 struct delayed_method_info
*mi
;
4987 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4989 const char *physname
;
4990 struct fn_fieldlist
*fn_flp
4991 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4992 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4993 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4997 /* Go objects should be embedded in a DW_TAG_module DIE,
4998 and it's not clear if/how imported objects will appear.
4999 To keep Go support simple until that's worked out,
5000 go back through what we've read and create something usable.
5001 We could do this while processing each DIE, and feels kinda cleaner,
5002 but that way is more invasive.
5003 This is to, for example, allow the user to type "p var" or "b main"
5004 without having to specify the package name, and allow lookups
5005 of module.object to work in contexts that use the expression
5009 fixup_go_packaging (struct dwarf2_cu
*cu
)
5011 char *package_name
= NULL
;
5012 struct pending
*list
;
5015 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
5017 for (i
= 0; i
< list
->nsyms
; ++i
)
5019 struct symbol
*sym
= list
->symbol
[i
];
5021 if (SYMBOL_LANGUAGE (sym
) == language_go
5022 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
5024 char *this_package_name
= go_symbol_package_name (sym
);
5026 if (this_package_name
== NULL
)
5028 if (package_name
== NULL
)
5029 package_name
= this_package_name
;
5032 if (strcmp (package_name
, this_package_name
) != 0)
5033 complaint (&symfile_complaints
,
5034 _("Symtab %s has objects from two different Go packages: %s and %s"),
5035 (sym
->symtab
&& sym
->symtab
->filename
5036 ? sym
->symtab
->filename
5037 : cu
->objfile
->name
),
5038 this_package_name
, package_name
);
5039 xfree (this_package_name
);
5045 if (package_name
!= NULL
)
5047 struct objfile
*objfile
= cu
->objfile
;
5048 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
5049 package_name
, objfile
);
5052 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5054 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
5055 SYMBOL_SET_LANGUAGE (sym
, language_go
);
5056 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
5057 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
5058 e.g., "main" finds the "main" module and not C's main(). */
5059 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5060 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5061 SYMBOL_TYPE (sym
) = type
;
5063 add_symbol_to_list (sym
, &global_symbols
);
5065 xfree (package_name
);
5069 /* Generate full symbol information for PER_CU, whose DIEs have
5070 already been loaded into memory. */
5073 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
5075 struct dwarf2_cu
*cu
= per_cu
->cu
;
5076 struct objfile
*objfile
= per_cu
->objfile
;
5077 CORE_ADDR lowpc
, highpc
;
5078 struct symtab
*symtab
;
5079 struct cleanup
*back_to
, *delayed_list_cleanup
;
5082 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5085 back_to
= make_cleanup (really_free_pendings
, NULL
);
5086 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
5088 cu
->list_in_scope
= &file_symbols
;
5090 /* Do line number decoding in read_file_scope () */
5091 process_die (cu
->dies
, cu
);
5093 /* For now fudge the Go package. */
5094 if (cu
->language
== language_go
)
5095 fixup_go_packaging (cu
);
5097 /* Now that we have processed all the DIEs in the CU, all the types
5098 should be complete, and it should now be safe to compute all of the
5100 compute_delayed_physnames (cu
);
5101 do_cleanups (delayed_list_cleanup
);
5103 /* Some compilers don't define a DW_AT_high_pc attribute for the
5104 compilation unit. If the DW_AT_high_pc is missing, synthesize
5105 it, by scanning the DIE's below the compilation unit. */
5106 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
5108 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
5112 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
5114 /* Set symtab language to language from DW_AT_language. If the
5115 compilation is from a C file generated by language preprocessors, do
5116 not set the language if it was already deduced by start_subfile. */
5117 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
5118 symtab
->language
= cu
->language
;
5120 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
5121 produce DW_AT_location with location lists but it can be possibly
5122 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
5123 there were bugs in prologue debug info, fixed later in GCC-4.5
5124 by "unwind info for epilogues" patch (which is not directly related).
5126 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
5127 needed, it would be wrong due to missing DW_AT_producer there.
5129 Still one can confuse GDB by using non-standard GCC compilation
5130 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
5132 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
5133 symtab
->locations_valid
= 1;
5135 if (gcc_4_minor
>= 5)
5136 symtab
->epilogue_unwind_valid
= 1;
5138 symtab
->call_site_htab
= cu
->call_site_htab
;
5141 if (dwarf2_per_objfile
->using_index
)
5142 per_cu
->v
.quick
->symtab
= symtab
;
5145 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5146 pst
->symtab
= symtab
;
5150 do_cleanups (back_to
);
5153 /* Process a die and its children. */
5156 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5160 case DW_TAG_padding
:
5162 case DW_TAG_compile_unit
:
5163 read_file_scope (die
, cu
);
5165 case DW_TAG_type_unit
:
5166 read_type_unit_scope (die
, cu
);
5168 case DW_TAG_subprogram
:
5169 case DW_TAG_inlined_subroutine
:
5170 read_func_scope (die
, cu
);
5172 case DW_TAG_lexical_block
:
5173 case DW_TAG_try_block
:
5174 case DW_TAG_catch_block
:
5175 read_lexical_block_scope (die
, cu
);
5177 case DW_TAG_GNU_call_site
:
5178 read_call_site_scope (die
, cu
);
5180 case DW_TAG_class_type
:
5181 case DW_TAG_interface_type
:
5182 case DW_TAG_structure_type
:
5183 case DW_TAG_union_type
:
5184 process_structure_scope (die
, cu
);
5186 case DW_TAG_enumeration_type
:
5187 process_enumeration_scope (die
, cu
);
5190 /* These dies have a type, but processing them does not create
5191 a symbol or recurse to process the children. Therefore we can
5192 read them on-demand through read_type_die. */
5193 case DW_TAG_subroutine_type
:
5194 case DW_TAG_set_type
:
5195 case DW_TAG_array_type
:
5196 case DW_TAG_pointer_type
:
5197 case DW_TAG_ptr_to_member_type
:
5198 case DW_TAG_reference_type
:
5199 case DW_TAG_string_type
:
5202 case DW_TAG_base_type
:
5203 case DW_TAG_subrange_type
:
5204 case DW_TAG_typedef
:
5205 /* Add a typedef symbol for the type definition, if it has a
5207 new_symbol (die
, read_type_die (die
, cu
), cu
);
5209 case DW_TAG_common_block
:
5210 read_common_block (die
, cu
);
5212 case DW_TAG_common_inclusion
:
5214 case DW_TAG_namespace
:
5215 processing_has_namespace_info
= 1;
5216 read_namespace (die
, cu
);
5219 processing_has_namespace_info
= 1;
5220 read_module (die
, cu
);
5222 case DW_TAG_imported_declaration
:
5223 case DW_TAG_imported_module
:
5224 processing_has_namespace_info
= 1;
5225 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
5226 || cu
->language
!= language_fortran
))
5227 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
5228 dwarf_tag_name (die
->tag
));
5229 read_import_statement (die
, cu
);
5232 new_symbol (die
, NULL
, cu
);
5237 /* A helper function for dwarf2_compute_name which determines whether DIE
5238 needs to have the name of the scope prepended to the name listed in the
5242 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5244 struct attribute
*attr
;
5248 case DW_TAG_namespace
:
5249 case DW_TAG_typedef
:
5250 case DW_TAG_class_type
:
5251 case DW_TAG_interface_type
:
5252 case DW_TAG_structure_type
:
5253 case DW_TAG_union_type
:
5254 case DW_TAG_enumeration_type
:
5255 case DW_TAG_enumerator
:
5256 case DW_TAG_subprogram
:
5260 case DW_TAG_variable
:
5261 case DW_TAG_constant
:
5262 /* We only need to prefix "globally" visible variables. These include
5263 any variable marked with DW_AT_external or any variable that
5264 lives in a namespace. [Variables in anonymous namespaces
5265 require prefixing, but they are not DW_AT_external.] */
5267 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
5269 struct dwarf2_cu
*spec_cu
= cu
;
5271 return die_needs_namespace (die_specification (die
, &spec_cu
),
5275 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5276 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
5277 && die
->parent
->tag
!= DW_TAG_module
)
5279 /* A variable in a lexical block of some kind does not need a
5280 namespace, even though in C++ such variables may be external
5281 and have a mangled name. */
5282 if (die
->parent
->tag
== DW_TAG_lexical_block
5283 || die
->parent
->tag
== DW_TAG_try_block
5284 || die
->parent
->tag
== DW_TAG_catch_block
5285 || die
->parent
->tag
== DW_TAG_subprogram
)
5294 /* Retrieve the last character from a mem_file. */
5297 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
5299 char *last_char_p
= (char *) object
;
5302 *last_char_p
= buffer
[length
- 1];
5305 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5306 compute the physname for the object, which include a method's:
5307 - formal parameters (C++/Java),
5308 - receiver type (Go),
5309 - return type (Java).
5311 The term "physname" is a bit confusing.
5312 For C++, for example, it is the demangled name.
5313 For Go, for example, it's the mangled name.
5315 For Ada, return the DIE's linkage name rather than the fully qualified
5316 name. PHYSNAME is ignored..
5318 The result is allocated on the objfile_obstack and canonicalized. */
5321 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5324 struct objfile
*objfile
= cu
->objfile
;
5327 name
= dwarf2_name (die
, cu
);
5329 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5330 compute it by typename_concat inside GDB. */
5331 if (cu
->language
== language_ada
5332 || (cu
->language
== language_fortran
&& physname
))
5334 /* For Ada unit, we prefer the linkage name over the name, as
5335 the former contains the exported name, which the user expects
5336 to be able to reference. Ideally, we want the user to be able
5337 to reference this entity using either natural or linkage name,
5338 but we haven't started looking at this enhancement yet. */
5339 struct attribute
*attr
;
5341 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5343 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5344 if (attr
&& DW_STRING (attr
))
5345 return DW_STRING (attr
);
5348 /* These are the only languages we know how to qualify names in. */
5350 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5351 || cu
->language
== language_fortran
))
5353 if (die_needs_namespace (die
, cu
))
5357 struct ui_file
*buf
;
5359 prefix
= determine_prefix (die
, cu
);
5360 buf
= mem_fileopen ();
5361 if (*prefix
!= '\0')
5363 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5366 fputs_unfiltered (prefixed_name
, buf
);
5367 xfree (prefixed_name
);
5370 fputs_unfiltered (name
, buf
);
5372 /* Template parameters may be specified in the DIE's DW_AT_name, or
5373 as children with DW_TAG_template_type_param or
5374 DW_TAG_value_type_param. If the latter, add them to the name
5375 here. If the name already has template parameters, then
5376 skip this step; some versions of GCC emit both, and
5377 it is more efficient to use the pre-computed name.
5379 Something to keep in mind about this process: it is very
5380 unlikely, or in some cases downright impossible, to produce
5381 something that will match the mangled name of a function.
5382 If the definition of the function has the same debug info,
5383 we should be able to match up with it anyway. But fallbacks
5384 using the minimal symbol, for instance to find a method
5385 implemented in a stripped copy of libstdc++, will not work.
5386 If we do not have debug info for the definition, we will have to
5387 match them up some other way.
5389 When we do name matching there is a related problem with function
5390 templates; two instantiated function templates are allowed to
5391 differ only by their return types, which we do not add here. */
5393 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5395 struct attribute
*attr
;
5396 struct die_info
*child
;
5399 die
->building_fullname
= 1;
5401 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5406 struct dwarf2_locexpr_baton
*baton
;
5409 if (child
->tag
!= DW_TAG_template_type_param
5410 && child
->tag
!= DW_TAG_template_value_param
)
5415 fputs_unfiltered ("<", buf
);
5419 fputs_unfiltered (", ", buf
);
5421 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5424 complaint (&symfile_complaints
,
5425 _("template parameter missing DW_AT_type"));
5426 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5429 type
= die_type (child
, cu
);
5431 if (child
->tag
== DW_TAG_template_type_param
)
5433 c_print_type (type
, "", buf
, -1, 0);
5437 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5440 complaint (&symfile_complaints
,
5441 _("template parameter missing "
5442 "DW_AT_const_value"));
5443 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5447 dwarf2_const_value_attr (attr
, type
, name
,
5448 &cu
->comp_unit_obstack
, cu
,
5449 &value
, &bytes
, &baton
);
5451 if (TYPE_NOSIGN (type
))
5452 /* GDB prints characters as NUMBER 'CHAR'. If that's
5453 changed, this can use value_print instead. */
5454 c_printchar (value
, type
, buf
);
5457 struct value_print_options opts
;
5460 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5464 else if (bytes
!= NULL
)
5466 v
= allocate_value (type
);
5467 memcpy (value_contents_writeable (v
), bytes
,
5468 TYPE_LENGTH (type
));
5471 v
= value_from_longest (type
, value
);
5473 /* Specify decimal so that we do not depend on
5475 get_formatted_print_options (&opts
, 'd');
5477 value_print (v
, buf
, &opts
);
5483 die
->building_fullname
= 0;
5487 /* Close the argument list, with a space if necessary
5488 (nested templates). */
5489 char last_char
= '\0';
5490 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5491 if (last_char
== '>')
5492 fputs_unfiltered (" >", buf
);
5494 fputs_unfiltered (">", buf
);
5498 /* For Java and C++ methods, append formal parameter type
5499 information, if PHYSNAME. */
5501 if (physname
&& die
->tag
== DW_TAG_subprogram
5502 && (cu
->language
== language_cplus
5503 || cu
->language
== language_java
))
5505 struct type
*type
= read_type_die (die
, cu
);
5507 c_type_print_args (type
, buf
, 1, cu
->language
);
5509 if (cu
->language
== language_java
)
5511 /* For java, we must append the return type to method
5513 if (die
->tag
== DW_TAG_subprogram
)
5514 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5517 else if (cu
->language
== language_cplus
)
5519 /* Assume that an artificial first parameter is
5520 "this", but do not crash if it is not. RealView
5521 marks unnamed (and thus unused) parameters as
5522 artificial; there is no way to differentiate
5524 if (TYPE_NFIELDS (type
) > 0
5525 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5526 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5527 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5529 fputs_unfiltered (" const", buf
);
5533 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
5535 ui_file_delete (buf
);
5537 if (cu
->language
== language_cplus
)
5540 = dwarf2_canonicalize_name (name
, cu
,
5541 &objfile
->objfile_obstack
);
5552 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5553 If scope qualifiers are appropriate they will be added. The result
5554 will be allocated on the objfile_obstack, or NULL if the DIE does
5555 not have a name. NAME may either be from a previous call to
5556 dwarf2_name or NULL.
5558 The output string will be canonicalized (if C++/Java). */
5561 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5563 return dwarf2_compute_name (name
, die
, cu
, 0);
5566 /* Construct a physname for the given DIE in CU. NAME may either be
5567 from a previous call to dwarf2_name or NULL. The result will be
5568 allocated on the objfile_objstack or NULL if the DIE does not have a
5571 The output string will be canonicalized (if C++/Java). */
5574 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5576 struct objfile
*objfile
= cu
->objfile
;
5577 struct attribute
*attr
;
5578 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5579 struct cleanup
*back_to
;
5582 /* In this case dwarf2_compute_name is just a shortcut not building anything
5584 if (!die_needs_namespace (die
, cu
))
5585 return dwarf2_compute_name (name
, die
, cu
, 1);
5587 back_to
= make_cleanup (null_cleanup
, NULL
);
5589 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5591 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5593 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5595 if (attr
&& DW_STRING (attr
))
5599 mangled
= DW_STRING (attr
);
5601 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5602 type. It is easier for GDB users to search for such functions as
5603 `name(params)' than `long name(params)'. In such case the minimal
5604 symbol names do not match the full symbol names but for template
5605 functions there is never a need to look up their definition from their
5606 declaration so the only disadvantage remains the minimal symbol
5607 variant `long name(params)' does not have the proper inferior type.
5610 if (cu
->language
== language_go
)
5612 /* This is a lie, but we already lie to the caller new_symbol_full.
5613 new_symbol_full assumes we return the mangled name.
5614 This just undoes that lie until things are cleaned up. */
5619 demangled
= cplus_demangle (mangled
,
5620 (DMGL_PARAMS
| DMGL_ANSI
5621 | (cu
->language
== language_java
5622 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5627 make_cleanup (xfree
, demangled
);
5637 if (canon
== NULL
|| check_physname
)
5639 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5641 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5643 /* It may not mean a bug in GDB. The compiler could also
5644 compute DW_AT_linkage_name incorrectly. But in such case
5645 GDB would need to be bug-to-bug compatible. */
5647 complaint (&symfile_complaints
,
5648 _("Computed physname <%s> does not match demangled <%s> "
5649 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5650 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
5652 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5653 is available here - over computed PHYSNAME. It is safer
5654 against both buggy GDB and buggy compilers. */
5668 retval
= obsavestring (retval
, strlen (retval
),
5669 &objfile
->objfile_obstack
);
5671 do_cleanups (back_to
);
5675 /* Read the import statement specified by the given die and record it. */
5678 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5680 struct objfile
*objfile
= cu
->objfile
;
5681 struct attribute
*import_attr
;
5682 struct die_info
*imported_die
, *child_die
;
5683 struct dwarf2_cu
*imported_cu
;
5684 const char *imported_name
;
5685 const char *imported_name_prefix
;
5686 const char *canonical_name
;
5687 const char *import_alias
;
5688 const char *imported_declaration
= NULL
;
5689 const char *import_prefix
;
5690 VEC (const_char_ptr
) *excludes
= NULL
;
5691 struct cleanup
*cleanups
;
5695 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5696 if (import_attr
== NULL
)
5698 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5699 dwarf_tag_name (die
->tag
));
5704 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5705 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5706 if (imported_name
== NULL
)
5708 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5710 The import in the following code:
5724 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5725 <52> DW_AT_decl_file : 1
5726 <53> DW_AT_decl_line : 6
5727 <54> DW_AT_import : <0x75>
5728 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5730 <5b> DW_AT_decl_file : 1
5731 <5c> DW_AT_decl_line : 2
5732 <5d> DW_AT_type : <0x6e>
5734 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5735 <76> DW_AT_byte_size : 4
5736 <77> DW_AT_encoding : 5 (signed)
5738 imports the wrong die ( 0x75 instead of 0x58 ).
5739 This case will be ignored until the gcc bug is fixed. */
5743 /* Figure out the local name after import. */
5744 import_alias
= dwarf2_name (die
, cu
);
5746 /* Figure out where the statement is being imported to. */
5747 import_prefix
= determine_prefix (die
, cu
);
5749 /* Figure out what the scope of the imported die is and prepend it
5750 to the name of the imported die. */
5751 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5753 if (imported_die
->tag
!= DW_TAG_namespace
5754 && imported_die
->tag
!= DW_TAG_module
)
5756 imported_declaration
= imported_name
;
5757 canonical_name
= imported_name_prefix
;
5759 else if (strlen (imported_name_prefix
) > 0)
5761 temp
= alloca (strlen (imported_name_prefix
)
5762 + 2 + strlen (imported_name
) + 1);
5763 strcpy (temp
, imported_name_prefix
);
5764 strcat (temp
, "::");
5765 strcat (temp
, imported_name
);
5766 canonical_name
= temp
;
5769 canonical_name
= imported_name
;
5771 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5773 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5774 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5775 child_die
= sibling_die (child_die
))
5777 /* DWARF-4: A Fortran use statement with a “rename list” may be
5778 represented by an imported module entry with an import attribute
5779 referring to the module and owned entries corresponding to those
5780 entities that are renamed as part of being imported. */
5782 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5784 complaint (&symfile_complaints
,
5785 _("child DW_TAG_imported_declaration expected "
5786 "- DIE at 0x%x [in module %s]"),
5787 child_die
->offset
.sect_off
, objfile
->name
);
5791 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5792 if (import_attr
== NULL
)
5794 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5795 dwarf_tag_name (child_die
->tag
));
5800 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5802 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5803 if (imported_name
== NULL
)
5805 complaint (&symfile_complaints
,
5806 _("child DW_TAG_imported_declaration has unknown "
5807 "imported name - DIE at 0x%x [in module %s]"),
5808 child_die
->offset
.sect_off
, objfile
->name
);
5812 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5814 process_die (child_die
, cu
);
5817 cp_add_using_directive (import_prefix
,
5820 imported_declaration
,
5822 &objfile
->objfile_obstack
);
5824 do_cleanups (cleanups
);
5827 /* Cleanup function for read_file_scope. */
5830 free_cu_line_header (void *arg
)
5832 struct dwarf2_cu
*cu
= arg
;
5834 free_line_header (cu
->line_header
);
5835 cu
->line_header
= NULL
;
5839 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5840 char **name
, char **comp_dir
)
5842 struct attribute
*attr
;
5847 /* Find the filename. Do not use dwarf2_name here, since the filename
5848 is not a source language identifier. */
5849 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5852 *name
= DW_STRING (attr
);
5855 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5857 *comp_dir
= DW_STRING (attr
);
5858 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5860 *comp_dir
= ldirname (*name
);
5861 if (*comp_dir
!= NULL
)
5862 make_cleanup (xfree
, *comp_dir
);
5864 if (*comp_dir
!= NULL
)
5866 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5867 directory, get rid of it. */
5868 char *cp
= strchr (*comp_dir
, ':');
5870 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5875 *name
= "<unknown>";
5878 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
5879 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
5880 COMP_DIR is the compilation directory.
5881 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
5884 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
5885 const char *comp_dir
, int want_line_info
)
5887 struct attribute
*attr
;
5888 struct objfile
*objfile
= cu
->objfile
;
5889 bfd
*abfd
= objfile
->obfd
;
5891 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5894 unsigned int line_offset
= DW_UNSND (attr
);
5895 struct line_header
*line_header
5896 = dwarf_decode_line_header (line_offset
, abfd
, cu
);
5900 cu
->line_header
= line_header
;
5901 make_cleanup (free_cu_line_header
, cu
);
5902 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
5907 /* Process DW_TAG_compile_unit. */
5910 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5912 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5913 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5914 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5915 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5916 struct attribute
*attr
;
5918 char *comp_dir
= NULL
;
5919 struct die_info
*child_die
;
5920 bfd
*abfd
= objfile
->obfd
;
5923 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5925 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5927 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5928 from finish_block. */
5929 if (lowpc
== ((CORE_ADDR
) -1))
5934 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5936 prepare_one_comp_unit (cu
, die
);
5938 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5939 standardised yet. As a workaround for the language detection we fall
5940 back to the DW_AT_producer string. */
5941 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5942 cu
->language
= language_opencl
;
5944 /* Similar hack for Go. */
5945 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
5946 set_cu_language (DW_LANG_Go
, cu
);
5948 /* We assume that we're processing GCC output. */
5949 processing_gcc_compilation
= 2;
5951 processing_has_namespace_info
= 0;
5953 start_symtab (name
, comp_dir
, lowpc
);
5954 record_debugformat ("DWARF 2");
5955 record_producer (cu
->producer
);
5957 /* Decode line number information if present. We do this before
5958 processing child DIEs, so that the line header table is available
5959 for DW_AT_decl_file. */
5960 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
5962 /* Process all dies in compilation unit. */
5963 if (die
->child
!= NULL
)
5965 child_die
= die
->child
;
5966 while (child_die
&& child_die
->tag
)
5968 process_die (child_die
, cu
);
5969 child_die
= sibling_die (child_die
);
5973 /* Decode macro information, if present. Dwarf 2 macro information
5974 refers to information in the line number info statement program
5975 header, so we can only read it if we've read the header
5977 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
5978 if (attr
&& cu
->line_header
)
5980 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
5981 complaint (&symfile_complaints
,
5982 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5984 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
5986 &dwarf2_per_objfile
->macro
, 1);
5990 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5991 if (attr
&& cu
->line_header
)
5993 unsigned int macro_offset
= DW_UNSND (attr
);
5995 dwarf_decode_macros (cu
->line_header
, macro_offset
,
5997 &dwarf2_per_objfile
->macinfo
, 0);
6001 do_cleanups (back_to
);
6004 /* Process DW_TAG_type_unit.
6005 For TUs we want to skip the first top level sibling if it's not the
6006 actual type being defined by this TU. In this case the first top
6007 level sibling is there to provide context only. */
6010 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6012 struct objfile
*objfile
= cu
->objfile
;
6013 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6015 struct attribute
*attr
;
6017 char *comp_dir
= NULL
;
6018 struct die_info
*child_die
;
6019 bfd
*abfd
= objfile
->obfd
;
6021 /* start_symtab needs a low pc, but we don't really have one.
6022 Do what read_file_scope would do in the absence of such info. */
6023 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6025 /* Find the filename. Do not use dwarf2_name here, since the filename
6026 is not a source language identifier. */
6027 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6029 name
= DW_STRING (attr
);
6031 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6033 comp_dir
= DW_STRING (attr
);
6034 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
6036 comp_dir
= ldirname (name
);
6037 if (comp_dir
!= NULL
)
6038 make_cleanup (xfree
, comp_dir
);
6044 prepare_one_comp_unit (cu
, die
);
6046 /* We assume that we're processing GCC output. */
6047 processing_gcc_compilation
= 2;
6049 processing_has_namespace_info
= 0;
6051 start_symtab (name
, comp_dir
, lowpc
);
6052 record_debugformat ("DWARF 2");
6053 record_producer (cu
->producer
);
6055 /* Decode line number information if present. We do this before
6056 processing child DIEs, so that the line header table is available
6057 for DW_AT_decl_file.
6058 We don't need the pc/line-number mapping for type units. */
6059 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
6061 /* Process the dies in the type unit. */
6062 if (die
->child
== NULL
)
6064 dump_die_for_error (die
);
6065 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
6066 bfd_get_filename (abfd
));
6069 child_die
= die
->child
;
6071 while (child_die
&& child_die
->tag
)
6073 process_die (child_die
, cu
);
6075 child_die
= sibling_die (child_die
);
6078 do_cleanups (back_to
);
6081 /* qsort helper for inherit_abstract_dies. */
6084 unsigned_int_compar (const void *ap
, const void *bp
)
6086 unsigned int a
= *(unsigned int *) ap
;
6087 unsigned int b
= *(unsigned int *) bp
;
6089 return (a
> b
) - (b
> a
);
6092 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
6093 Inherit only the children of the DW_AT_abstract_origin DIE not being
6094 already referenced by DW_AT_abstract_origin from the children of the
6098 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
6100 struct die_info
*child_die
;
6101 unsigned die_children_count
;
6102 /* CU offsets which were referenced by children of the current DIE. */
6103 sect_offset
*offsets
;
6104 sect_offset
*offsets_end
, *offsetp
;
6105 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
6106 struct die_info
*origin_die
;
6107 /* Iterator of the ORIGIN_DIE children. */
6108 struct die_info
*origin_child_die
;
6109 struct cleanup
*cleanups
;
6110 struct attribute
*attr
;
6111 struct dwarf2_cu
*origin_cu
;
6112 struct pending
**origin_previous_list_in_scope
;
6114 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
6118 /* Note that following die references may follow to a die in a
6122 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
6124 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
6126 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
6127 origin_cu
->list_in_scope
= cu
->list_in_scope
;
6129 if (die
->tag
!= origin_die
->tag
6130 && !(die
->tag
== DW_TAG_inlined_subroutine
6131 && origin_die
->tag
== DW_TAG_subprogram
))
6132 complaint (&symfile_complaints
,
6133 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
6134 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
6136 child_die
= die
->child
;
6137 die_children_count
= 0;
6138 while (child_die
&& child_die
->tag
)
6140 child_die
= sibling_die (child_die
);
6141 die_children_count
++;
6143 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
6144 cleanups
= make_cleanup (xfree
, offsets
);
6146 offsets_end
= offsets
;
6147 child_die
= die
->child
;
6148 while (child_die
&& child_die
->tag
)
6150 /* For each CHILD_DIE, find the corresponding child of
6151 ORIGIN_DIE. If there is more than one layer of
6152 DW_AT_abstract_origin, follow them all; there shouldn't be,
6153 but GCC versions at least through 4.4 generate this (GCC PR
6155 struct die_info
*child_origin_die
= child_die
;
6156 struct dwarf2_cu
*child_origin_cu
= cu
;
6160 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
6164 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
6168 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
6169 counterpart may exist. */
6170 if (child_origin_die
!= child_die
)
6172 if (child_die
->tag
!= child_origin_die
->tag
6173 && !(child_die
->tag
== DW_TAG_inlined_subroutine
6174 && child_origin_die
->tag
== DW_TAG_subprogram
))
6175 complaint (&symfile_complaints
,
6176 _("Child DIE 0x%x and its abstract origin 0x%x have "
6177 "different tags"), child_die
->offset
.sect_off
,
6178 child_origin_die
->offset
.sect_off
);
6179 if (child_origin_die
->parent
!= origin_die
)
6180 complaint (&symfile_complaints
,
6181 _("Child DIE 0x%x and its abstract origin 0x%x have "
6182 "different parents"), child_die
->offset
.sect_off
,
6183 child_origin_die
->offset
.sect_off
);
6185 *offsets_end
++ = child_origin_die
->offset
;
6187 child_die
= sibling_die (child_die
);
6189 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
6190 unsigned_int_compar
);
6191 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
6192 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
6193 complaint (&symfile_complaints
,
6194 _("Multiple children of DIE 0x%x refer "
6195 "to DIE 0x%x as their abstract origin"),
6196 die
->offset
.sect_off
, offsetp
->sect_off
);
6199 origin_child_die
= origin_die
->child
;
6200 while (origin_child_die
&& origin_child_die
->tag
)
6202 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
6203 while (offsetp
< offsets_end
6204 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
6206 if (offsetp
>= offsets_end
6207 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
6209 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
6210 process_die (origin_child_die
, origin_cu
);
6212 origin_child_die
= sibling_die (origin_child_die
);
6214 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
6216 do_cleanups (cleanups
);
6220 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6222 struct objfile
*objfile
= cu
->objfile
;
6223 struct context_stack
*new;
6226 struct die_info
*child_die
;
6227 struct attribute
*attr
, *call_line
, *call_file
;
6230 struct block
*block
;
6231 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
6232 VEC (symbolp
) *template_args
= NULL
;
6233 struct template_symbol
*templ_func
= NULL
;
6237 /* If we do not have call site information, we can't show the
6238 caller of this inlined function. That's too confusing, so
6239 only use the scope for local variables. */
6240 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
6241 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
6242 if (call_line
== NULL
|| call_file
== NULL
)
6244 read_lexical_block_scope (die
, cu
);
6249 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6251 name
= dwarf2_name (die
, cu
);
6253 /* Ignore functions with missing or empty names. These are actually
6254 illegal according to the DWARF standard. */
6257 complaint (&symfile_complaints
,
6258 _("missing name for subprogram DIE at %d"),
6259 die
->offset
.sect_off
);
6263 /* Ignore functions with missing or invalid low and high pc attributes. */
6264 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6266 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6267 if (!attr
|| !DW_UNSND (attr
))
6268 complaint (&symfile_complaints
,
6269 _("cannot get low and high bounds "
6270 "for subprogram DIE at %d"),
6271 die
->offset
.sect_off
);
6278 /* If we have any template arguments, then we must allocate a
6279 different sort of symbol. */
6280 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
6282 if (child_die
->tag
== DW_TAG_template_type_param
6283 || child_die
->tag
== DW_TAG_template_value_param
)
6285 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6286 struct template_symbol
);
6287 templ_func
->base
.is_cplus_template_function
= 1;
6292 new = push_context (0, lowpc
);
6293 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
6294 (struct symbol
*) templ_func
);
6296 /* If there is a location expression for DW_AT_frame_base, record
6298 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
6300 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
6301 expression is being recorded directly in the function's symbol
6302 and not in a separate frame-base object. I guess this hack is
6303 to avoid adding some sort of frame-base adjunct/annex to the
6304 function's symbol :-(. The problem with doing this is that it
6305 results in a function symbol with a location expression that
6306 has nothing to do with the location of the function, ouch! The
6307 relationship should be: a function's symbol has-a frame base; a
6308 frame-base has-a location expression. */
6309 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
6311 cu
->list_in_scope
= &local_symbols
;
6313 if (die
->child
!= NULL
)
6315 child_die
= die
->child
;
6316 while (child_die
&& child_die
->tag
)
6318 if (child_die
->tag
== DW_TAG_template_type_param
6319 || child_die
->tag
== DW_TAG_template_value_param
)
6321 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6324 VEC_safe_push (symbolp
, template_args
, arg
);
6327 process_die (child_die
, cu
);
6328 child_die
= sibling_die (child_die
);
6332 inherit_abstract_dies (die
, cu
);
6334 /* If we have a DW_AT_specification, we might need to import using
6335 directives from the context of the specification DIE. See the
6336 comment in determine_prefix. */
6337 if (cu
->language
== language_cplus
6338 && dwarf2_attr (die
, DW_AT_specification
, cu
))
6340 struct dwarf2_cu
*spec_cu
= cu
;
6341 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
6345 child_die
= spec_die
->child
;
6346 while (child_die
&& child_die
->tag
)
6348 if (child_die
->tag
== DW_TAG_imported_module
)
6349 process_die (child_die
, spec_cu
);
6350 child_die
= sibling_die (child_die
);
6353 /* In some cases, GCC generates specification DIEs that
6354 themselves contain DW_AT_specification attributes. */
6355 spec_die
= die_specification (spec_die
, &spec_cu
);
6359 new = pop_context ();
6360 /* Make a block for the local symbols within. */
6361 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
6362 lowpc
, highpc
, objfile
);
6364 /* For C++, set the block's scope. */
6365 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
6366 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
6367 determine_prefix (die
, cu
),
6368 processing_has_namespace_info
);
6370 /* If we have address ranges, record them. */
6371 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6373 /* Attach template arguments to function. */
6374 if (! VEC_empty (symbolp
, template_args
))
6376 gdb_assert (templ_func
!= NULL
);
6378 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
6379 templ_func
->template_arguments
6380 = obstack_alloc (&objfile
->objfile_obstack
,
6381 (templ_func
->n_template_arguments
6382 * sizeof (struct symbol
*)));
6383 memcpy (templ_func
->template_arguments
,
6384 VEC_address (symbolp
, template_args
),
6385 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
6386 VEC_free (symbolp
, template_args
);
6389 /* In C++, we can have functions nested inside functions (e.g., when
6390 a function declares a class that has methods). This means that
6391 when we finish processing a function scope, we may need to go
6392 back to building a containing block's symbol lists. */
6393 local_symbols
= new->locals
;
6394 param_symbols
= new->params
;
6395 using_directives
= new->using_directives
;
6397 /* If we've finished processing a top-level function, subsequent
6398 symbols go in the file symbol list. */
6399 if (outermost_context_p ())
6400 cu
->list_in_scope
= &file_symbols
;
6403 /* Process all the DIES contained within a lexical block scope. Start
6404 a new scope, process the dies, and then close the scope. */
6407 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6409 struct objfile
*objfile
= cu
->objfile
;
6410 struct context_stack
*new;
6411 CORE_ADDR lowpc
, highpc
;
6412 struct die_info
*child_die
;
6415 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6417 /* Ignore blocks with missing or invalid low and high pc attributes. */
6418 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6419 as multiple lexical blocks? Handling children in a sane way would
6420 be nasty. Might be easier to properly extend generic blocks to
6422 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6427 push_context (0, lowpc
);
6428 if (die
->child
!= NULL
)
6430 child_die
= die
->child
;
6431 while (child_die
&& child_die
->tag
)
6433 process_die (child_die
, cu
);
6434 child_die
= sibling_die (child_die
);
6437 new = pop_context ();
6439 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6442 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6445 /* Note that recording ranges after traversing children, as we
6446 do here, means that recording a parent's ranges entails
6447 walking across all its children's ranges as they appear in
6448 the address map, which is quadratic behavior.
6450 It would be nicer to record the parent's ranges before
6451 traversing its children, simply overriding whatever you find
6452 there. But since we don't even decide whether to create a
6453 block until after we've traversed its children, that's hard
6455 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6457 local_symbols
= new->locals
;
6458 using_directives
= new->using_directives
;
6461 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6464 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6466 struct objfile
*objfile
= cu
->objfile
;
6467 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6468 CORE_ADDR pc
, baseaddr
;
6469 struct attribute
*attr
;
6470 struct call_site
*call_site
, call_site_local
;
6473 struct die_info
*child_die
;
6475 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6477 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6480 complaint (&symfile_complaints
,
6481 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6482 "DIE 0x%x [in module %s]"),
6483 die
->offset
.sect_off
, objfile
->name
);
6486 pc
= DW_ADDR (attr
) + baseaddr
;
6488 if (cu
->call_site_htab
== NULL
)
6489 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
6490 NULL
, &objfile
->objfile_obstack
,
6491 hashtab_obstack_allocate
, NULL
);
6492 call_site_local
.pc
= pc
;
6493 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
6496 complaint (&symfile_complaints
,
6497 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6498 "DIE 0x%x [in module %s]"),
6499 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
6503 /* Count parameters at the caller. */
6506 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6507 child_die
= sibling_die (child_die
))
6509 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6511 complaint (&symfile_complaints
,
6512 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6513 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6514 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
6521 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
6522 (sizeof (*call_site
)
6523 + (sizeof (*call_site
->parameter
)
6526 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
6529 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
6531 struct die_info
*func_die
;
6533 /* Skip also over DW_TAG_inlined_subroutine. */
6534 for (func_die
= die
->parent
;
6535 func_die
&& func_die
->tag
!= DW_TAG_subprogram
6536 && func_die
->tag
!= DW_TAG_subroutine_type
;
6537 func_die
= func_die
->parent
);
6539 /* DW_AT_GNU_all_call_sites is a superset
6540 of DW_AT_GNU_all_tail_call_sites. */
6542 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
6543 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
6545 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6546 not complete. But keep CALL_SITE for look ups via call_site_htab,
6547 both the initial caller containing the real return address PC and
6548 the final callee containing the current PC of a chain of tail
6549 calls do not need to have the tail call list complete. But any
6550 function candidate for a virtual tail call frame searched via
6551 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6552 determined unambiguously. */
6556 struct type
*func_type
= NULL
;
6559 func_type
= get_die_type (func_die
, cu
);
6560 if (func_type
!= NULL
)
6562 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
6564 /* Enlist this call site to the function. */
6565 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
6566 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
6569 complaint (&symfile_complaints
,
6570 _("Cannot find function owning DW_TAG_GNU_call_site "
6571 "DIE 0x%x [in module %s]"),
6572 die
->offset
.sect_off
, objfile
->name
);
6576 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
6578 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
6579 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
6580 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
6581 /* Keep NULL DWARF_BLOCK. */;
6582 else if (attr_form_is_block (attr
))
6584 struct dwarf2_locexpr_baton
*dlbaton
;
6586 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
6587 dlbaton
->data
= DW_BLOCK (attr
)->data
;
6588 dlbaton
->size
= DW_BLOCK (attr
)->size
;
6589 dlbaton
->per_cu
= cu
->per_cu
;
6591 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
6593 else if (is_ref_attr (attr
))
6595 struct dwarf2_cu
*target_cu
= cu
;
6596 struct die_info
*target_die
;
6598 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
6599 gdb_assert (target_cu
->objfile
== objfile
);
6600 if (die_is_declaration (target_die
, target_cu
))
6602 const char *target_physname
;
6604 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
6605 if (target_physname
== NULL
)
6606 complaint (&symfile_complaints
,
6607 _("DW_AT_GNU_call_site_target target DIE has invalid "
6608 "physname, for referencing DIE 0x%x [in module %s]"),
6609 die
->offset
.sect_off
, objfile
->name
);
6611 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
6617 /* DW_AT_entry_pc should be preferred. */
6618 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
6619 complaint (&symfile_complaints
,
6620 _("DW_AT_GNU_call_site_target target DIE has invalid "
6621 "low pc, for referencing DIE 0x%x [in module %s]"),
6622 die
->offset
.sect_off
, objfile
->name
);
6624 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
6628 complaint (&symfile_complaints
,
6629 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6630 "block nor reference, for DIE 0x%x [in module %s]"),
6631 die
->offset
.sect_off
, objfile
->name
);
6633 call_site
->per_cu
= cu
->per_cu
;
6635 for (child_die
= die
->child
;
6636 child_die
&& child_die
->tag
;
6637 child_die
= sibling_die (child_die
))
6639 struct dwarf2_locexpr_baton
*dlbaton
;
6640 struct call_site_parameter
*parameter
;
6642 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6644 /* Already printed the complaint above. */
6648 gdb_assert (call_site
->parameter_count
< nparams
);
6649 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
6651 /* DW_AT_location specifies the register number. Value of the data
6652 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6654 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
6655 if (!attr
|| !attr_form_is_block (attr
))
6657 complaint (&symfile_complaints
,
6658 _("No DW_FORM_block* DW_AT_location for "
6659 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6660 child_die
->offset
.sect_off
, objfile
->name
);
6663 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
6664 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
6665 if (parameter
->dwarf_reg
== -1
6666 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
6667 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
6668 ¶meter
->fb_offset
))
6670 complaint (&symfile_complaints
,
6671 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6672 "for DW_FORM_block* DW_AT_location for "
6673 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6674 child_die
->offset
.sect_off
, objfile
->name
);
6678 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
6679 if (!attr_form_is_block (attr
))
6681 complaint (&symfile_complaints
,
6682 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6683 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6684 child_die
->offset
.sect_off
, objfile
->name
);
6687 parameter
->value
= DW_BLOCK (attr
)->data
;
6688 parameter
->value_size
= DW_BLOCK (attr
)->size
;
6690 /* Parameters are not pre-cleared by memset above. */
6691 parameter
->data_value
= NULL
;
6692 parameter
->data_value_size
= 0;
6693 call_site
->parameter_count
++;
6695 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
6698 if (!attr_form_is_block (attr
))
6699 complaint (&symfile_complaints
,
6700 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6701 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6702 child_die
->offset
.sect_off
, objfile
->name
);
6705 parameter
->data_value
= DW_BLOCK (attr
)->data
;
6706 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
6712 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6713 Return 1 if the attributes are present and valid, otherwise, return 0.
6714 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6717 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6718 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6719 struct partial_symtab
*ranges_pst
)
6721 struct objfile
*objfile
= cu
->objfile
;
6722 struct comp_unit_head
*cu_header
= &cu
->header
;
6723 bfd
*obfd
= objfile
->obfd
;
6724 unsigned int addr_size
= cu_header
->addr_size
;
6725 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6726 /* Base address selection entry. */
6737 found_base
= cu
->base_known
;
6738 base
= cu
->base_address
;
6740 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6741 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6743 complaint (&symfile_complaints
,
6744 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6748 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6750 /* Read in the largest possible address. */
6751 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6752 if ((marker
& mask
) == mask
)
6754 /* If we found the largest possible address, then
6755 read the base address. */
6756 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6757 buffer
+= 2 * addr_size
;
6758 offset
+= 2 * addr_size
;
6764 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6768 CORE_ADDR range_beginning
, range_end
;
6770 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6771 buffer
+= addr_size
;
6772 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6773 buffer
+= addr_size
;
6774 offset
+= 2 * addr_size
;
6776 /* An end of list marker is a pair of zero addresses. */
6777 if (range_beginning
== 0 && range_end
== 0)
6778 /* Found the end of list entry. */
6781 /* Each base address selection entry is a pair of 2 values.
6782 The first is the largest possible address, the second is
6783 the base address. Check for a base address here. */
6784 if ((range_beginning
& mask
) == mask
)
6786 /* If we found the largest possible address, then
6787 read the base address. */
6788 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6795 /* We have no valid base address for the ranges
6797 complaint (&symfile_complaints
,
6798 _("Invalid .debug_ranges data (no base address)"));
6802 if (range_beginning
> range_end
)
6804 /* Inverted range entries are invalid. */
6805 complaint (&symfile_complaints
,
6806 _("Invalid .debug_ranges data (inverted range)"));
6810 /* Empty range entries have no effect. */
6811 if (range_beginning
== range_end
)
6814 range_beginning
+= base
;
6817 if (ranges_pst
!= NULL
)
6818 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6819 range_beginning
+ baseaddr
,
6820 range_end
- 1 + baseaddr
,
6823 /* FIXME: This is recording everything as a low-high
6824 segment of consecutive addresses. We should have a
6825 data structure for discontiguous block ranges
6829 low
= range_beginning
;
6835 if (range_beginning
< low
)
6836 low
= range_beginning
;
6837 if (range_end
> high
)
6843 /* If the first entry is an end-of-list marker, the range
6844 describes an empty scope, i.e. no instructions. */
6850 *high_return
= high
;
6854 /* Get low and high pc attributes from a die. Return 1 if the attributes
6855 are present and valid, otherwise, return 0. Return -1 if the range is
6856 discontinuous, i.e. derived from DW_AT_ranges information. */
6859 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6860 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6861 struct partial_symtab
*pst
)
6863 struct attribute
*attr
;
6864 struct attribute
*attr_high
;
6869 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6872 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6875 low
= DW_ADDR (attr
);
6876 if (attr_high
->form
== DW_FORM_addr
)
6877 high
= DW_ADDR (attr_high
);
6879 high
= low
+ DW_UNSND (attr_high
);
6882 /* Found high w/o low attribute. */
6885 /* Found consecutive range of addresses. */
6890 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6893 /* Value of the DW_AT_ranges attribute is the offset in the
6894 .debug_ranges section. */
6895 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6897 /* Found discontinuous range of addresses. */
6902 /* read_partial_die has also the strict LOW < HIGH requirement. */
6906 /* When using the GNU linker, .gnu.linkonce. sections are used to
6907 eliminate duplicate copies of functions and vtables and such.
6908 The linker will arbitrarily choose one and discard the others.
6909 The AT_*_pc values for such functions refer to local labels in
6910 these sections. If the section from that file was discarded, the
6911 labels are not in the output, so the relocs get a value of 0.
6912 If this is a discarded function, mark the pc bounds as invalid,
6913 so that GDB will ignore it. */
6914 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6923 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6924 its low and high PC addresses. Do nothing if these addresses could not
6925 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6926 and HIGHPC to the high address if greater than HIGHPC. */
6929 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6930 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6931 struct dwarf2_cu
*cu
)
6933 CORE_ADDR low
, high
;
6934 struct die_info
*child
= die
->child
;
6936 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6938 *lowpc
= min (*lowpc
, low
);
6939 *highpc
= max (*highpc
, high
);
6942 /* If the language does not allow nested subprograms (either inside
6943 subprograms or lexical blocks), we're done. */
6944 if (cu
->language
!= language_ada
)
6947 /* Check all the children of the given DIE. If it contains nested
6948 subprograms, then check their pc bounds. Likewise, we need to
6949 check lexical blocks as well, as they may also contain subprogram
6951 while (child
&& child
->tag
)
6953 if (child
->tag
== DW_TAG_subprogram
6954 || child
->tag
== DW_TAG_lexical_block
)
6955 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6956 child
= sibling_die (child
);
6960 /* Get the low and high pc's represented by the scope DIE, and store
6961 them in *LOWPC and *HIGHPC. If the correct values can't be
6962 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6965 get_scope_pc_bounds (struct die_info
*die
,
6966 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6967 struct dwarf2_cu
*cu
)
6969 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6970 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6971 CORE_ADDR current_low
, current_high
;
6973 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6975 best_low
= current_low
;
6976 best_high
= current_high
;
6980 struct die_info
*child
= die
->child
;
6982 while (child
&& child
->tag
)
6984 switch (child
->tag
) {
6985 case DW_TAG_subprogram
:
6986 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6988 case DW_TAG_namespace
:
6990 /* FIXME: carlton/2004-01-16: Should we do this for
6991 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6992 that current GCC's always emit the DIEs corresponding
6993 to definitions of methods of classes as children of a
6994 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6995 the DIEs giving the declarations, which could be
6996 anywhere). But I don't see any reason why the
6997 standards says that they have to be there. */
6998 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
7000 if (current_low
!= ((CORE_ADDR
) -1))
7002 best_low
= min (best_low
, current_low
);
7003 best_high
= max (best_high
, current_high
);
7011 child
= sibling_die (child
);
7016 *highpc
= best_high
;
7019 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
7023 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
7024 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
7026 struct objfile
*objfile
= cu
->objfile
;
7027 struct attribute
*attr
;
7028 struct attribute
*attr_high
;
7030 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
7033 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7036 CORE_ADDR low
= DW_ADDR (attr
);
7038 if (attr_high
->form
== DW_FORM_addr
)
7039 high
= DW_ADDR (attr_high
);
7041 high
= low
+ DW_UNSND (attr_high
);
7043 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
7047 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
7050 bfd
*obfd
= objfile
->obfd
;
7052 /* The value of the DW_AT_ranges attribute is the offset of the
7053 address range list in the .debug_ranges section. */
7054 unsigned long offset
= DW_UNSND (attr
);
7055 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
7057 /* For some target architectures, but not others, the
7058 read_address function sign-extends the addresses it returns.
7059 To recognize base address selection entries, we need a
7061 unsigned int addr_size
= cu
->header
.addr_size
;
7062 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
7064 /* The base address, to which the next pair is relative. Note
7065 that this 'base' is a DWARF concept: most entries in a range
7066 list are relative, to reduce the number of relocs against the
7067 debugging information. This is separate from this function's
7068 'baseaddr' argument, which GDB uses to relocate debugging
7069 information from a shared library based on the address at
7070 which the library was loaded. */
7071 CORE_ADDR base
= cu
->base_address
;
7072 int base_known
= cu
->base_known
;
7074 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
7075 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
7077 complaint (&symfile_complaints
,
7078 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
7085 unsigned int bytes_read
;
7086 CORE_ADDR start
, end
;
7088 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
7089 buffer
+= bytes_read
;
7090 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
7091 buffer
+= bytes_read
;
7093 /* Did we find the end of the range list? */
7094 if (start
== 0 && end
== 0)
7097 /* Did we find a base address selection entry? */
7098 else if ((start
& base_select_mask
) == base_select_mask
)
7104 /* We found an ordinary address range. */
7109 complaint (&symfile_complaints
,
7110 _("Invalid .debug_ranges data "
7111 "(no base address)"));
7117 /* Inverted range entries are invalid. */
7118 complaint (&symfile_complaints
,
7119 _("Invalid .debug_ranges data "
7120 "(inverted range)"));
7124 /* Empty range entries have no effect. */
7128 record_block_range (block
,
7129 baseaddr
+ base
+ start
,
7130 baseaddr
+ base
+ end
- 1);
7136 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
7137 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
7138 during 4.6.0 experimental. */
7141 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
7144 int major
, minor
, release
;
7147 if (cu
->producer
== NULL
)
7149 /* For unknown compilers expect their behavior is DWARF version
7152 GCC started to support .debug_types sections by -gdwarf-4 since
7153 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
7154 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
7155 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
7156 interpreted incorrectly by GDB now - GCC PR debug/48229. */
7161 if (cu
->checked_producer
)
7162 return cu
->producer_is_gxx_lt_4_6
;
7164 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
7166 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
7168 /* For non-GCC compilers expect their behavior is DWARF version
7173 cs
= &cu
->producer
[strlen ("GNU ")];
7174 while (*cs
&& !isdigit (*cs
))
7176 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
7178 /* Not recognized as GCC. */
7181 result
= major
< 4 || (major
== 4 && minor
< 6);
7184 cu
->checked_producer
= 1;
7185 cu
->producer_is_gxx_lt_4_6
= result
;
7190 /* Return the default accessibility type if it is not overriden by
7191 DW_AT_accessibility. */
7193 static enum dwarf_access_attribute
7194 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
7196 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
7198 /* The default DWARF 2 accessibility for members is public, the default
7199 accessibility for inheritance is private. */
7201 if (die
->tag
!= DW_TAG_inheritance
)
7202 return DW_ACCESS_public
;
7204 return DW_ACCESS_private
;
7208 /* DWARF 3+ defines the default accessibility a different way. The same
7209 rules apply now for DW_TAG_inheritance as for the members and it only
7210 depends on the container kind. */
7212 if (die
->parent
->tag
== DW_TAG_class_type
)
7213 return DW_ACCESS_private
;
7215 return DW_ACCESS_public
;
7219 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
7220 offset. If the attribute was not found return 0, otherwise return
7221 1. If it was found but could not properly be handled, set *OFFSET
7225 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
7228 struct attribute
*attr
;
7230 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
7235 /* Note that we do not check for a section offset first here.
7236 This is because DW_AT_data_member_location is new in DWARF 4,
7237 so if we see it, we can assume that a constant form is really
7238 a constant and not a section offset. */
7239 if (attr_form_is_constant (attr
))
7240 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
7241 else if (attr_form_is_section_offset (attr
))
7242 dwarf2_complex_location_expr_complaint ();
7243 else if (attr_form_is_block (attr
))
7244 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7246 dwarf2_complex_location_expr_complaint ();
7254 /* Add an aggregate field to the field list. */
7257 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
7258 struct dwarf2_cu
*cu
)
7260 struct objfile
*objfile
= cu
->objfile
;
7261 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7262 struct nextfield
*new_field
;
7263 struct attribute
*attr
;
7265 char *fieldname
= "";
7267 /* Allocate a new field list entry and link it in. */
7268 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
7269 make_cleanup (xfree
, new_field
);
7270 memset (new_field
, 0, sizeof (struct nextfield
));
7272 if (die
->tag
== DW_TAG_inheritance
)
7274 new_field
->next
= fip
->baseclasses
;
7275 fip
->baseclasses
= new_field
;
7279 new_field
->next
= fip
->fields
;
7280 fip
->fields
= new_field
;
7284 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7286 new_field
->accessibility
= DW_UNSND (attr
);
7288 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
7289 if (new_field
->accessibility
!= DW_ACCESS_public
)
7290 fip
->non_public_fields
= 1;
7292 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7294 new_field
->virtuality
= DW_UNSND (attr
);
7296 new_field
->virtuality
= DW_VIRTUALITY_none
;
7298 fp
= &new_field
->field
;
7300 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
7304 /* Data member other than a C++ static data member. */
7306 /* Get type of field. */
7307 fp
->type
= die_type (die
, cu
);
7309 SET_FIELD_BITPOS (*fp
, 0);
7311 /* Get bit size of field (zero if none). */
7312 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
7315 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
7319 FIELD_BITSIZE (*fp
) = 0;
7322 /* Get bit offset of field. */
7323 if (handle_data_member_location (die
, cu
, &offset
))
7324 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7325 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
7328 if (gdbarch_bits_big_endian (gdbarch
))
7330 /* For big endian bits, the DW_AT_bit_offset gives the
7331 additional bit offset from the MSB of the containing
7332 anonymous object to the MSB of the field. We don't
7333 have to do anything special since we don't need to
7334 know the size of the anonymous object. */
7335 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
7339 /* For little endian bits, compute the bit offset to the
7340 MSB of the anonymous object, subtract off the number of
7341 bits from the MSB of the field to the MSB of the
7342 object, and then subtract off the number of bits of
7343 the field itself. The result is the bit offset of
7344 the LSB of the field. */
7346 int bit_offset
= DW_UNSND (attr
);
7348 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7351 /* The size of the anonymous object containing
7352 the bit field is explicit, so use the
7353 indicated size (in bytes). */
7354 anonymous_size
= DW_UNSND (attr
);
7358 /* The size of the anonymous object containing
7359 the bit field must be inferred from the type
7360 attribute of the data member containing the
7362 anonymous_size
= TYPE_LENGTH (fp
->type
);
7364 SET_FIELD_BITPOS (*fp
,
7366 + anonymous_size
* bits_per_byte
7367 - bit_offset
- FIELD_BITSIZE (*fp
)));
7371 /* Get name of field. */
7372 fieldname
= dwarf2_name (die
, cu
);
7373 if (fieldname
== NULL
)
7376 /* The name is already allocated along with this objfile, so we don't
7377 need to duplicate it for the type. */
7378 fp
->name
= fieldname
;
7380 /* Change accessibility for artificial fields (e.g. virtual table
7381 pointer or virtual base class pointer) to private. */
7382 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
7384 FIELD_ARTIFICIAL (*fp
) = 1;
7385 new_field
->accessibility
= DW_ACCESS_private
;
7386 fip
->non_public_fields
= 1;
7389 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
7391 /* C++ static member. */
7393 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7394 is a declaration, but all versions of G++ as of this writing
7395 (so through at least 3.2.1) incorrectly generate
7396 DW_TAG_variable tags. */
7398 const char *physname
;
7400 /* Get name of field. */
7401 fieldname
= dwarf2_name (die
, cu
);
7402 if (fieldname
== NULL
)
7405 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7407 /* Only create a symbol if this is an external value.
7408 new_symbol checks this and puts the value in the global symbol
7409 table, which we want. If it is not external, new_symbol
7410 will try to put the value in cu->list_in_scope which is wrong. */
7411 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
7413 /* A static const member, not much different than an enum as far as
7414 we're concerned, except that we can support more types. */
7415 new_symbol (die
, NULL
, cu
);
7418 /* Get physical name. */
7419 physname
= dwarf2_physname (fieldname
, die
, cu
);
7421 /* The name is already allocated along with this objfile, so we don't
7422 need to duplicate it for the type. */
7423 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
7424 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7425 FIELD_NAME (*fp
) = fieldname
;
7427 else if (die
->tag
== DW_TAG_inheritance
)
7431 /* C++ base class field. */
7432 if (handle_data_member_location (die
, cu
, &offset
))
7433 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7434 FIELD_BITSIZE (*fp
) = 0;
7435 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7436 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
7437 fip
->nbaseclasses
++;
7441 /* Add a typedef defined in the scope of the FIP's class. */
7444 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
7445 struct dwarf2_cu
*cu
)
7447 struct objfile
*objfile
= cu
->objfile
;
7448 struct typedef_field_list
*new_field
;
7449 struct attribute
*attr
;
7450 struct typedef_field
*fp
;
7451 char *fieldname
= "";
7453 /* Allocate a new field list entry and link it in. */
7454 new_field
= xzalloc (sizeof (*new_field
));
7455 make_cleanup (xfree
, new_field
);
7457 gdb_assert (die
->tag
== DW_TAG_typedef
);
7459 fp
= &new_field
->field
;
7461 /* Get name of field. */
7462 fp
->name
= dwarf2_name (die
, cu
);
7463 if (fp
->name
== NULL
)
7466 fp
->type
= read_type_die (die
, cu
);
7468 new_field
->next
= fip
->typedef_field_list
;
7469 fip
->typedef_field_list
= new_field
;
7470 fip
->typedef_field_list_count
++;
7473 /* Create the vector of fields, and attach it to the type. */
7476 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
7477 struct dwarf2_cu
*cu
)
7479 int nfields
= fip
->nfields
;
7481 /* Record the field count, allocate space for the array of fields,
7482 and create blank accessibility bitfields if necessary. */
7483 TYPE_NFIELDS (type
) = nfields
;
7484 TYPE_FIELDS (type
) = (struct field
*)
7485 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
7486 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
7488 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
7490 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7492 TYPE_FIELD_PRIVATE_BITS (type
) =
7493 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7494 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
7496 TYPE_FIELD_PROTECTED_BITS (type
) =
7497 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7498 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
7500 TYPE_FIELD_IGNORE_BITS (type
) =
7501 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7502 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
7505 /* If the type has baseclasses, allocate and clear a bit vector for
7506 TYPE_FIELD_VIRTUAL_BITS. */
7507 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
7509 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
7510 unsigned char *pointer
;
7512 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7513 pointer
= TYPE_ALLOC (type
, num_bytes
);
7514 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
7515 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
7516 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
7519 /* Copy the saved-up fields into the field vector. Start from the head of
7520 the list, adding to the tail of the field array, so that they end up in
7521 the same order in the array in which they were added to the list. */
7522 while (nfields
-- > 0)
7524 struct nextfield
*fieldp
;
7528 fieldp
= fip
->fields
;
7529 fip
->fields
= fieldp
->next
;
7533 fieldp
= fip
->baseclasses
;
7534 fip
->baseclasses
= fieldp
->next
;
7537 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
7538 switch (fieldp
->accessibility
)
7540 case DW_ACCESS_private
:
7541 if (cu
->language
!= language_ada
)
7542 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
7545 case DW_ACCESS_protected
:
7546 if (cu
->language
!= language_ada
)
7547 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
7550 case DW_ACCESS_public
:
7554 /* Unknown accessibility. Complain and treat it as public. */
7556 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
7557 fieldp
->accessibility
);
7561 if (nfields
< fip
->nbaseclasses
)
7563 switch (fieldp
->virtuality
)
7565 case DW_VIRTUALITY_virtual
:
7566 case DW_VIRTUALITY_pure_virtual
:
7567 if (cu
->language
== language_ada
)
7568 error (_("unexpected virtuality in component of Ada type"));
7569 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
7576 /* Add a member function to the proper fieldlist. */
7579 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
7580 struct type
*type
, struct dwarf2_cu
*cu
)
7582 struct objfile
*objfile
= cu
->objfile
;
7583 struct attribute
*attr
;
7584 struct fnfieldlist
*flp
;
7586 struct fn_field
*fnp
;
7588 struct nextfnfield
*new_fnfield
;
7589 struct type
*this_type
;
7590 enum dwarf_access_attribute accessibility
;
7592 if (cu
->language
== language_ada
)
7593 error (_("unexpected member function in Ada type"));
7595 /* Get name of member function. */
7596 fieldname
= dwarf2_name (die
, cu
);
7597 if (fieldname
== NULL
)
7600 /* Look up member function name in fieldlist. */
7601 for (i
= 0; i
< fip
->nfnfields
; i
++)
7603 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7607 /* Create new list element if necessary. */
7608 if (i
< fip
->nfnfields
)
7609 flp
= &fip
->fnfieldlists
[i
];
7612 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7614 fip
->fnfieldlists
= (struct fnfieldlist
*)
7615 xrealloc (fip
->fnfieldlists
,
7616 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7617 * sizeof (struct fnfieldlist
));
7618 if (fip
->nfnfields
== 0)
7619 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7621 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7622 flp
->name
= fieldname
;
7625 i
= fip
->nfnfields
++;
7628 /* Create a new member function field and chain it to the field list
7630 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7631 make_cleanup (xfree
, new_fnfield
);
7632 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7633 new_fnfield
->next
= flp
->head
;
7634 flp
->head
= new_fnfield
;
7637 /* Fill in the member function field info. */
7638 fnp
= &new_fnfield
->fnfield
;
7640 /* Delay processing of the physname until later. */
7641 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7643 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7648 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7649 fnp
->physname
= physname
? physname
: "";
7652 fnp
->type
= alloc_type (objfile
);
7653 this_type
= read_type_die (die
, cu
);
7654 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7656 int nparams
= TYPE_NFIELDS (this_type
);
7658 /* TYPE is the domain of this method, and THIS_TYPE is the type
7659 of the method itself (TYPE_CODE_METHOD). */
7660 smash_to_method_type (fnp
->type
, type
,
7661 TYPE_TARGET_TYPE (this_type
),
7662 TYPE_FIELDS (this_type
),
7663 TYPE_NFIELDS (this_type
),
7664 TYPE_VARARGS (this_type
));
7666 /* Handle static member functions.
7667 Dwarf2 has no clean way to discern C++ static and non-static
7668 member functions. G++ helps GDB by marking the first
7669 parameter for non-static member functions (which is the this
7670 pointer) as artificial. We obtain this information from
7671 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7672 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7673 fnp
->voffset
= VOFFSET_STATIC
;
7676 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7677 dwarf2_full_name (fieldname
, die
, cu
));
7679 /* Get fcontext from DW_AT_containing_type if present. */
7680 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7681 fnp
->fcontext
= die_containing_type (die
, cu
);
7683 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7684 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7686 /* Get accessibility. */
7687 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7689 accessibility
= DW_UNSND (attr
);
7691 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7692 switch (accessibility
)
7694 case DW_ACCESS_private
:
7695 fnp
->is_private
= 1;
7697 case DW_ACCESS_protected
:
7698 fnp
->is_protected
= 1;
7702 /* Check for artificial methods. */
7703 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7704 if (attr
&& DW_UNSND (attr
) != 0)
7705 fnp
->is_artificial
= 1;
7707 /* Get index in virtual function table if it is a virtual member
7708 function. For older versions of GCC, this is an offset in the
7709 appropriate virtual table, as specified by DW_AT_containing_type.
7710 For everyone else, it is an expression to be evaluated relative
7711 to the object address. */
7713 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7716 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7718 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7720 /* Old-style GCC. */
7721 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7723 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7724 || (DW_BLOCK (attr
)->size
> 1
7725 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7726 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7728 struct dwarf_block blk
;
7731 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7733 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7734 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7735 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7736 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7737 dwarf2_complex_location_expr_complaint ();
7739 fnp
->voffset
/= cu
->header
.addr_size
;
7743 dwarf2_complex_location_expr_complaint ();
7746 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7748 else if (attr_form_is_section_offset (attr
))
7750 dwarf2_complex_location_expr_complaint ();
7754 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7760 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7761 if (attr
&& DW_UNSND (attr
))
7763 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7764 complaint (&symfile_complaints
,
7765 _("Member function \"%s\" (offset %d) is virtual "
7766 "but the vtable offset is not specified"),
7767 fieldname
, die
->offset
.sect_off
);
7768 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7769 TYPE_CPLUS_DYNAMIC (type
) = 1;
7774 /* Create the vector of member function fields, and attach it to the type. */
7777 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7778 struct dwarf2_cu
*cu
)
7780 struct fnfieldlist
*flp
;
7783 if (cu
->language
== language_ada
)
7784 error (_("unexpected member functions in Ada type"));
7786 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7787 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7788 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7790 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7792 struct nextfnfield
*nfp
= flp
->head
;
7793 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7796 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7797 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7798 fn_flp
->fn_fields
= (struct fn_field
*)
7799 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7800 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7801 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7804 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7807 /* Returns non-zero if NAME is the name of a vtable member in CU's
7808 language, zero otherwise. */
7810 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7812 static const char vptr
[] = "_vptr";
7813 static const char vtable
[] = "vtable";
7815 /* Look for the C++ and Java forms of the vtable. */
7816 if ((cu
->language
== language_java
7817 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7818 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7819 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7825 /* GCC outputs unnamed structures that are really pointers to member
7826 functions, with the ABI-specified layout. If TYPE describes
7827 such a structure, smash it into a member function type.
7829 GCC shouldn't do this; it should just output pointer to member DIEs.
7830 This is GCC PR debug/28767. */
7833 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7835 struct type
*pfn_type
, *domain_type
, *new_type
;
7837 /* Check for a structure with no name and two children. */
7838 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7841 /* Check for __pfn and __delta members. */
7842 if (TYPE_FIELD_NAME (type
, 0) == NULL
7843 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7844 || TYPE_FIELD_NAME (type
, 1) == NULL
7845 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7848 /* Find the type of the method. */
7849 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7850 if (pfn_type
== NULL
7851 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7852 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7855 /* Look for the "this" argument. */
7856 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7857 if (TYPE_NFIELDS (pfn_type
) == 0
7858 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7859 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7862 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7863 new_type
= alloc_type (objfile
);
7864 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7865 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7866 TYPE_VARARGS (pfn_type
));
7867 smash_to_methodptr_type (type
, new_type
);
7870 /* Called when we find the DIE that starts a structure or union scope
7871 (definition) to create a type for the structure or union. Fill in
7872 the type's name and general properties; the members will not be
7873 processed until process_structure_type.
7875 NOTE: we need to call these functions regardless of whether or not the
7876 DIE has a DW_AT_name attribute, since it might be an anonymous
7877 structure or union. This gets the type entered into our set of
7880 However, if the structure is incomplete (an opaque struct/union)
7881 then suppress creating a symbol table entry for it since gdb only
7882 wants to find the one with the complete definition. Note that if
7883 it is complete, we just call new_symbol, which does it's own
7884 checking about whether the struct/union is anonymous or not (and
7885 suppresses creating a symbol table entry itself). */
7887 static struct type
*
7888 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7890 struct objfile
*objfile
= cu
->objfile
;
7892 struct attribute
*attr
;
7895 /* If the definition of this type lives in .debug_types, read that type.
7896 Don't follow DW_AT_specification though, that will take us back up
7897 the chain and we want to go down. */
7898 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7901 struct dwarf2_cu
*type_cu
= cu
;
7902 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7904 /* We could just recurse on read_structure_type, but we need to call
7905 get_die_type to ensure only one type for this DIE is created.
7906 This is important, for example, because for c++ classes we need
7907 TYPE_NAME set which is only done by new_symbol. Blech. */
7908 type
= read_type_die (type_die
, type_cu
);
7910 /* TYPE_CU may not be the same as CU.
7911 Ensure TYPE is recorded in CU's type_hash table. */
7912 return set_die_type (die
, type
, cu
);
7915 type
= alloc_type (objfile
);
7916 INIT_CPLUS_SPECIFIC (type
);
7918 name
= dwarf2_name (die
, cu
);
7921 if (cu
->language
== language_cplus
7922 || cu
->language
== language_java
)
7924 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7926 /* dwarf2_full_name might have already finished building the DIE's
7927 type. If so, there is no need to continue. */
7928 if (get_die_type (die
, cu
) != NULL
)
7929 return get_die_type (die
, cu
);
7931 TYPE_TAG_NAME (type
) = full_name
;
7932 if (die
->tag
== DW_TAG_structure_type
7933 || die
->tag
== DW_TAG_class_type
)
7934 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7938 /* The name is already allocated along with this objfile, so
7939 we don't need to duplicate it for the type. */
7940 TYPE_TAG_NAME (type
) = (char *) name
;
7941 if (die
->tag
== DW_TAG_class_type
)
7942 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7946 if (die
->tag
== DW_TAG_structure_type
)
7948 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7950 else if (die
->tag
== DW_TAG_union_type
)
7952 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7956 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7959 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7960 TYPE_DECLARED_CLASS (type
) = 1;
7962 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7965 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7969 TYPE_LENGTH (type
) = 0;
7972 TYPE_STUB_SUPPORTED (type
) = 1;
7973 if (die_is_declaration (die
, cu
))
7974 TYPE_STUB (type
) = 1;
7975 else if (attr
== NULL
&& die
->child
== NULL
7976 && producer_is_realview (cu
->producer
))
7977 /* RealView does not output the required DW_AT_declaration
7978 on incomplete types. */
7979 TYPE_STUB (type
) = 1;
7981 /* We need to add the type field to the die immediately so we don't
7982 infinitely recurse when dealing with pointers to the structure
7983 type within the structure itself. */
7984 set_die_type (die
, type
, cu
);
7986 /* set_die_type should be already done. */
7987 set_descriptive_type (type
, die
, cu
);
7992 /* Finish creating a structure or union type, including filling in
7993 its members and creating a symbol for it. */
7996 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7998 struct objfile
*objfile
= cu
->objfile
;
7999 struct die_info
*child_die
= die
->child
;
8002 type
= get_die_type (die
, cu
);
8004 type
= read_structure_type (die
, cu
);
8006 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
8008 struct field_info fi
;
8009 struct die_info
*child_die
;
8010 VEC (symbolp
) *template_args
= NULL
;
8011 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
8013 memset (&fi
, 0, sizeof (struct field_info
));
8015 child_die
= die
->child
;
8017 while (child_die
&& child_die
->tag
)
8019 if (child_die
->tag
== DW_TAG_member
8020 || child_die
->tag
== DW_TAG_variable
)
8022 /* NOTE: carlton/2002-11-05: A C++ static data member
8023 should be a DW_TAG_member that is a declaration, but
8024 all versions of G++ as of this writing (so through at
8025 least 3.2.1) incorrectly generate DW_TAG_variable
8026 tags for them instead. */
8027 dwarf2_add_field (&fi
, child_die
, cu
);
8029 else if (child_die
->tag
== DW_TAG_subprogram
)
8031 /* C++ member function. */
8032 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
8034 else if (child_die
->tag
== DW_TAG_inheritance
)
8036 /* C++ base class field. */
8037 dwarf2_add_field (&fi
, child_die
, cu
);
8039 else if (child_die
->tag
== DW_TAG_typedef
)
8040 dwarf2_add_typedef (&fi
, child_die
, cu
);
8041 else if (child_die
->tag
== DW_TAG_template_type_param
8042 || child_die
->tag
== DW_TAG_template_value_param
)
8044 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
8047 VEC_safe_push (symbolp
, template_args
, arg
);
8050 child_die
= sibling_die (child_die
);
8053 /* Attach template arguments to type. */
8054 if (! VEC_empty (symbolp
, template_args
))
8056 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8057 TYPE_N_TEMPLATE_ARGUMENTS (type
)
8058 = VEC_length (symbolp
, template_args
);
8059 TYPE_TEMPLATE_ARGUMENTS (type
)
8060 = obstack_alloc (&objfile
->objfile_obstack
,
8061 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
8062 * sizeof (struct symbol
*)));
8063 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
8064 VEC_address (symbolp
, template_args
),
8065 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
8066 * sizeof (struct symbol
*)));
8067 VEC_free (symbolp
, template_args
);
8070 /* Attach fields and member functions to the type. */
8072 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
8075 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
8077 /* Get the type which refers to the base class (possibly this
8078 class itself) which contains the vtable pointer for the current
8079 class from the DW_AT_containing_type attribute. This use of
8080 DW_AT_containing_type is a GNU extension. */
8082 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
8084 struct type
*t
= die_containing_type (die
, cu
);
8086 TYPE_VPTR_BASETYPE (type
) = t
;
8091 /* Our own class provides vtbl ptr. */
8092 for (i
= TYPE_NFIELDS (t
) - 1;
8093 i
>= TYPE_N_BASECLASSES (t
);
8096 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
8098 if (is_vtable_name (fieldname
, cu
))
8100 TYPE_VPTR_FIELDNO (type
) = i
;
8105 /* Complain if virtual function table field not found. */
8106 if (i
< TYPE_N_BASECLASSES (t
))
8107 complaint (&symfile_complaints
,
8108 _("virtual function table pointer "
8109 "not found when defining class '%s'"),
8110 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
8115 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
8118 else if (cu
->producer
8119 && strncmp (cu
->producer
,
8120 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
8122 /* The IBM XLC compiler does not provide direct indication
8123 of the containing type, but the vtable pointer is
8124 always named __vfp. */
8128 for (i
= TYPE_NFIELDS (type
) - 1;
8129 i
>= TYPE_N_BASECLASSES (type
);
8132 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
8134 TYPE_VPTR_FIELDNO (type
) = i
;
8135 TYPE_VPTR_BASETYPE (type
) = type
;
8142 /* Copy fi.typedef_field_list linked list elements content into the
8143 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
8144 if (fi
.typedef_field_list
)
8146 int i
= fi
.typedef_field_list_count
;
8148 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8149 TYPE_TYPEDEF_FIELD_ARRAY (type
)
8150 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
8151 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
8153 /* Reverse the list order to keep the debug info elements order. */
8156 struct typedef_field
*dest
, *src
;
8158 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
8159 src
= &fi
.typedef_field_list
->field
;
8160 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
8165 do_cleanups (back_to
);
8167 if (HAVE_CPLUS_STRUCT (type
))
8168 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
8171 quirk_gcc_member_function_pointer (type
, objfile
);
8173 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
8174 snapshots) has been known to create a die giving a declaration
8175 for a class that has, as a child, a die giving a definition for a
8176 nested class. So we have to process our children even if the
8177 current die is a declaration. Normally, of course, a declaration
8178 won't have any children at all. */
8180 while (child_die
!= NULL
&& child_die
->tag
)
8182 if (child_die
->tag
== DW_TAG_member
8183 || child_die
->tag
== DW_TAG_variable
8184 || child_die
->tag
== DW_TAG_inheritance
8185 || child_die
->tag
== DW_TAG_template_value_param
8186 || child_die
->tag
== DW_TAG_template_type_param
)
8191 process_die (child_die
, cu
);
8193 child_die
= sibling_die (child_die
);
8196 /* Do not consider external references. According to the DWARF standard,
8197 these DIEs are identified by the fact that they have no byte_size
8198 attribute, and a declaration attribute. */
8199 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
8200 || !die_is_declaration (die
, cu
))
8201 new_symbol (die
, type
, cu
);
8204 /* Given a DW_AT_enumeration_type die, set its type. We do not
8205 complete the type's fields yet, or create any symbols. */
8207 static struct type
*
8208 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8210 struct objfile
*objfile
= cu
->objfile
;
8212 struct attribute
*attr
;
8215 /* If the definition of this type lives in .debug_types, read that type.
8216 Don't follow DW_AT_specification though, that will take us back up
8217 the chain and we want to go down. */
8218 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
8221 struct dwarf2_cu
*type_cu
= cu
;
8222 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
8224 type
= read_type_die (type_die
, type_cu
);
8226 /* TYPE_CU may not be the same as CU.
8227 Ensure TYPE is recorded in CU's type_hash table. */
8228 return set_die_type (die
, type
, cu
);
8231 type
= alloc_type (objfile
);
8233 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
8234 name
= dwarf2_full_name (NULL
, die
, cu
);
8236 TYPE_TAG_NAME (type
) = (char *) name
;
8238 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8241 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8245 TYPE_LENGTH (type
) = 0;
8248 /* The enumeration DIE can be incomplete. In Ada, any type can be
8249 declared as private in the package spec, and then defined only
8250 inside the package body. Such types are known as Taft Amendment
8251 Types. When another package uses such a type, an incomplete DIE
8252 may be generated by the compiler. */
8253 if (die_is_declaration (die
, cu
))
8254 TYPE_STUB (type
) = 1;
8256 return set_die_type (die
, type
, cu
);
8259 /* Given a pointer to a die which begins an enumeration, process all
8260 the dies that define the members of the enumeration, and create the
8261 symbol for the enumeration type.
8263 NOTE: We reverse the order of the element list. */
8266 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8268 struct type
*this_type
;
8270 this_type
= get_die_type (die
, cu
);
8271 if (this_type
== NULL
)
8272 this_type
= read_enumeration_type (die
, cu
);
8274 if (die
->child
!= NULL
)
8276 struct die_info
*child_die
;
8278 struct field
*fields
= NULL
;
8280 int unsigned_enum
= 1;
8285 child_die
= die
->child
;
8286 while (child_die
&& child_die
->tag
)
8288 if (child_die
->tag
!= DW_TAG_enumerator
)
8290 process_die (child_die
, cu
);
8294 name
= dwarf2_name (child_die
, cu
);
8297 sym
= new_symbol (child_die
, this_type
, cu
);
8298 if (SYMBOL_VALUE (sym
) < 0)
8303 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
8306 mask
|= SYMBOL_VALUE (sym
);
8308 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8310 fields
= (struct field
*)
8312 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
8313 * sizeof (struct field
));
8316 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
8317 FIELD_TYPE (fields
[num_fields
]) = NULL
;
8318 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
8319 FIELD_BITSIZE (fields
[num_fields
]) = 0;
8325 child_die
= sibling_die (child_die
);
8330 TYPE_NFIELDS (this_type
) = num_fields
;
8331 TYPE_FIELDS (this_type
) = (struct field
*)
8332 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
8333 memcpy (TYPE_FIELDS (this_type
), fields
,
8334 sizeof (struct field
) * num_fields
);
8338 TYPE_UNSIGNED (this_type
) = 1;
8340 TYPE_FLAG_ENUM (this_type
) = 1;
8343 /* If we are reading an enum from a .debug_types unit, and the enum
8344 is a declaration, and the enum is not the signatured type in the
8345 unit, then we do not want to add a symbol for it. Adding a
8346 symbol would in some cases obscure the true definition of the
8347 enum, giving users an incomplete type when the definition is
8348 actually available. Note that we do not want to do this for all
8349 enums which are just declarations, because C++0x allows forward
8350 enum declarations. */
8351 if (cu
->per_cu
->debug_types_section
8352 && die_is_declaration (die
, cu
))
8354 struct signatured_type
*sig_type
;
8357 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
8358 cu
->per_cu
->debug_types_section
,
8359 cu
->per_cu
->offset
);
8360 if (sig_type
->per_cu
.offset
.sect_off
+ sig_type
->type_offset
.cu_off
8361 != die
->offset
.sect_off
)
8365 new_symbol (die
, this_type
, cu
);
8368 /* Extract all information from a DW_TAG_array_type DIE and put it in
8369 the DIE's type field. For now, this only handles one dimensional
8372 static struct type
*
8373 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8375 struct objfile
*objfile
= cu
->objfile
;
8376 struct die_info
*child_die
;
8378 struct type
*element_type
, *range_type
, *index_type
;
8379 struct type
**range_types
= NULL
;
8380 struct attribute
*attr
;
8382 struct cleanup
*back_to
;
8385 element_type
= die_type (die
, cu
);
8387 /* The die_type call above may have already set the type for this DIE. */
8388 type
= get_die_type (die
, cu
);
8392 /* Irix 6.2 native cc creates array types without children for
8393 arrays with unspecified length. */
8394 if (die
->child
== NULL
)
8396 index_type
= objfile_type (objfile
)->builtin_int
;
8397 range_type
= create_range_type (NULL
, index_type
, 0, -1);
8398 type
= create_array_type (NULL
, element_type
, range_type
);
8399 return set_die_type (die
, type
, cu
);
8402 back_to
= make_cleanup (null_cleanup
, NULL
);
8403 child_die
= die
->child
;
8404 while (child_die
&& child_die
->tag
)
8406 if (child_die
->tag
== DW_TAG_subrange_type
)
8408 struct type
*child_type
= read_type_die (child_die
, cu
);
8410 if (child_type
!= NULL
)
8412 /* The range type was succesfully read. Save it for the
8413 array type creation. */
8414 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
8416 range_types
= (struct type
**)
8417 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
8418 * sizeof (struct type
*));
8420 make_cleanup (free_current_contents
, &range_types
);
8422 range_types
[ndim
++] = child_type
;
8425 child_die
= sibling_die (child_die
);
8428 /* Dwarf2 dimensions are output from left to right, create the
8429 necessary array types in backwards order. */
8431 type
= element_type
;
8433 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
8438 type
= create_array_type (NULL
, type
, range_types
[i
++]);
8443 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
8446 /* Understand Dwarf2 support for vector types (like they occur on
8447 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8448 array type. This is not part of the Dwarf2/3 standard yet, but a
8449 custom vendor extension. The main difference between a regular
8450 array and the vector variant is that vectors are passed by value
8452 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
8454 make_vector_type (type
);
8456 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8457 implementation may choose to implement triple vectors using this
8459 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8462 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
8463 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8465 complaint (&symfile_complaints
,
8466 _("DW_AT_byte_size for array type smaller "
8467 "than the total size of elements"));
8470 name
= dwarf2_name (die
, cu
);
8472 TYPE_NAME (type
) = name
;
8474 /* Install the type in the die. */
8475 set_die_type (die
, type
, cu
);
8477 /* set_die_type should be already done. */
8478 set_descriptive_type (type
, die
, cu
);
8480 do_cleanups (back_to
);
8485 static enum dwarf_array_dim_ordering
8486 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
8488 struct attribute
*attr
;
8490 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
8492 if (attr
) return DW_SND (attr
);
8494 /* GNU F77 is a special case, as at 08/2004 array type info is the
8495 opposite order to the dwarf2 specification, but data is still
8496 laid out as per normal fortran.
8498 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8499 version checking. */
8501 if (cu
->language
== language_fortran
8502 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
8504 return DW_ORD_row_major
;
8507 switch (cu
->language_defn
->la_array_ordering
)
8509 case array_column_major
:
8510 return DW_ORD_col_major
;
8511 case array_row_major
:
8513 return DW_ORD_row_major
;
8517 /* Extract all information from a DW_TAG_set_type DIE and put it in
8518 the DIE's type field. */
8520 static struct type
*
8521 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8523 struct type
*domain_type
, *set_type
;
8524 struct attribute
*attr
;
8526 domain_type
= die_type (die
, cu
);
8528 /* The die_type call above may have already set the type for this DIE. */
8529 set_type
= get_die_type (die
, cu
);
8533 set_type
= create_set_type (NULL
, domain_type
);
8535 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8537 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
8539 return set_die_type (die
, set_type
, cu
);
8542 /* First cut: install each common block member as a global variable. */
8545 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
8547 struct die_info
*child_die
;
8548 struct attribute
*attr
;
8550 CORE_ADDR base
= (CORE_ADDR
) 0;
8552 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8555 /* Support the .debug_loc offsets. */
8556 if (attr_form_is_block (attr
))
8558 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
8560 else if (attr_form_is_section_offset (attr
))
8562 dwarf2_complex_location_expr_complaint ();
8566 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8567 "common block member");
8570 if (die
->child
!= NULL
)
8572 child_die
= die
->child
;
8573 while (child_die
&& child_die
->tag
)
8577 sym
= new_symbol (child_die
, NULL
, cu
);
8579 && handle_data_member_location (child_die
, cu
, &offset
))
8581 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
8582 add_symbol_to_list (sym
, &global_symbols
);
8584 child_die
= sibling_die (child_die
);
8589 /* Create a type for a C++ namespace. */
8591 static struct type
*
8592 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8594 struct objfile
*objfile
= cu
->objfile
;
8595 const char *previous_prefix
, *name
;
8599 /* For extensions, reuse the type of the original namespace. */
8600 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
8602 struct die_info
*ext_die
;
8603 struct dwarf2_cu
*ext_cu
= cu
;
8605 ext_die
= dwarf2_extension (die
, &ext_cu
);
8606 type
= read_type_die (ext_die
, ext_cu
);
8608 /* EXT_CU may not be the same as CU.
8609 Ensure TYPE is recorded in CU's type_hash table. */
8610 return set_die_type (die
, type
, cu
);
8613 name
= namespace_name (die
, &is_anonymous
, cu
);
8615 /* Now build the name of the current namespace. */
8617 previous_prefix
= determine_prefix (die
, cu
);
8618 if (previous_prefix
[0] != '\0')
8619 name
= typename_concat (&objfile
->objfile_obstack
,
8620 previous_prefix
, name
, 0, cu
);
8622 /* Create the type. */
8623 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8625 TYPE_NAME (type
) = (char *) name
;
8626 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8628 return set_die_type (die
, type
, cu
);
8631 /* Read a C++ namespace. */
8634 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8636 struct objfile
*objfile
= cu
->objfile
;
8639 /* Add a symbol associated to this if we haven't seen the namespace
8640 before. Also, add a using directive if it's an anonymous
8643 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8647 type
= read_type_die (die
, cu
);
8648 new_symbol (die
, type
, cu
);
8650 namespace_name (die
, &is_anonymous
, cu
);
8653 const char *previous_prefix
= determine_prefix (die
, cu
);
8655 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8656 NULL
, NULL
, &objfile
->objfile_obstack
);
8660 if (die
->child
!= NULL
)
8662 struct die_info
*child_die
= die
->child
;
8664 while (child_die
&& child_die
->tag
)
8666 process_die (child_die
, cu
);
8667 child_die
= sibling_die (child_die
);
8672 /* Read a Fortran module as type. This DIE can be only a declaration used for
8673 imported module. Still we need that type as local Fortran "use ... only"
8674 declaration imports depend on the created type in determine_prefix. */
8676 static struct type
*
8677 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8679 struct objfile
*objfile
= cu
->objfile
;
8683 module_name
= dwarf2_name (die
, cu
);
8685 complaint (&symfile_complaints
,
8686 _("DW_TAG_module has no name, offset 0x%x"),
8687 die
->offset
.sect_off
);
8688 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8690 /* determine_prefix uses TYPE_TAG_NAME. */
8691 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8693 return set_die_type (die
, type
, cu
);
8696 /* Read a Fortran module. */
8699 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8701 struct die_info
*child_die
= die
->child
;
8703 while (child_die
&& child_die
->tag
)
8705 process_die (child_die
, cu
);
8706 child_die
= sibling_die (child_die
);
8710 /* Return the name of the namespace represented by DIE. Set
8711 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8715 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8717 struct die_info
*current_die
;
8718 const char *name
= NULL
;
8720 /* Loop through the extensions until we find a name. */
8722 for (current_die
= die
;
8723 current_die
!= NULL
;
8724 current_die
= dwarf2_extension (die
, &cu
))
8726 name
= dwarf2_name (current_die
, cu
);
8731 /* Is it an anonymous namespace? */
8733 *is_anonymous
= (name
== NULL
);
8735 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8740 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8741 the user defined type vector. */
8743 static struct type
*
8744 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8746 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8747 struct comp_unit_head
*cu_header
= &cu
->header
;
8749 struct attribute
*attr_byte_size
;
8750 struct attribute
*attr_address_class
;
8751 int byte_size
, addr_class
;
8752 struct type
*target_type
;
8754 target_type
= die_type (die
, cu
);
8756 /* The die_type call above may have already set the type for this DIE. */
8757 type
= get_die_type (die
, cu
);
8761 type
= lookup_pointer_type (target_type
);
8763 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8765 byte_size
= DW_UNSND (attr_byte_size
);
8767 byte_size
= cu_header
->addr_size
;
8769 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8770 if (attr_address_class
)
8771 addr_class
= DW_UNSND (attr_address_class
);
8773 addr_class
= DW_ADDR_none
;
8775 /* If the pointer size or address class is different than the
8776 default, create a type variant marked as such and set the
8777 length accordingly. */
8778 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8780 if (gdbarch_address_class_type_flags_p (gdbarch
))
8784 type_flags
= gdbarch_address_class_type_flags
8785 (gdbarch
, byte_size
, addr_class
);
8786 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8788 type
= make_type_with_address_space (type
, type_flags
);
8790 else if (TYPE_LENGTH (type
) != byte_size
)
8792 complaint (&symfile_complaints
,
8793 _("invalid pointer size %d"), byte_size
);
8797 /* Should we also complain about unhandled address classes? */
8801 TYPE_LENGTH (type
) = byte_size
;
8802 return set_die_type (die
, type
, cu
);
8805 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8806 the user defined type vector. */
8808 static struct type
*
8809 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8812 struct type
*to_type
;
8813 struct type
*domain
;
8815 to_type
= die_type (die
, cu
);
8816 domain
= die_containing_type (die
, cu
);
8818 /* The calls above may have already set the type for this DIE. */
8819 type
= get_die_type (die
, cu
);
8823 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8824 type
= lookup_methodptr_type (to_type
);
8826 type
= lookup_memberptr_type (to_type
, domain
);
8828 return set_die_type (die
, type
, cu
);
8831 /* Extract all information from a DW_TAG_reference_type DIE and add to
8832 the user defined type vector. */
8834 static struct type
*
8835 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8837 struct comp_unit_head
*cu_header
= &cu
->header
;
8838 struct type
*type
, *target_type
;
8839 struct attribute
*attr
;
8841 target_type
= die_type (die
, cu
);
8843 /* The die_type call above may have already set the type for this DIE. */
8844 type
= get_die_type (die
, cu
);
8848 type
= lookup_reference_type (target_type
);
8849 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8852 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8856 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8858 return set_die_type (die
, type
, cu
);
8861 static struct type
*
8862 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8864 struct type
*base_type
, *cv_type
;
8866 base_type
= die_type (die
, cu
);
8868 /* The die_type call above may have already set the type for this DIE. */
8869 cv_type
= get_die_type (die
, cu
);
8873 /* In case the const qualifier is applied to an array type, the element type
8874 is so qualified, not the array type (section 6.7.3 of C99). */
8875 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8877 struct type
*el_type
, *inner_array
;
8879 base_type
= copy_type (base_type
);
8880 inner_array
= base_type
;
8882 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8884 TYPE_TARGET_TYPE (inner_array
) =
8885 copy_type (TYPE_TARGET_TYPE (inner_array
));
8886 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8889 el_type
= TYPE_TARGET_TYPE (inner_array
);
8890 TYPE_TARGET_TYPE (inner_array
) =
8891 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8893 return set_die_type (die
, base_type
, cu
);
8896 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8897 return set_die_type (die
, cv_type
, cu
);
8900 static struct type
*
8901 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8903 struct type
*base_type
, *cv_type
;
8905 base_type
= die_type (die
, cu
);
8907 /* The die_type call above may have already set the type for this DIE. */
8908 cv_type
= get_die_type (die
, cu
);
8912 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8913 return set_die_type (die
, cv_type
, cu
);
8916 /* Extract all information from a DW_TAG_string_type DIE and add to
8917 the user defined type vector. It isn't really a user defined type,
8918 but it behaves like one, with other DIE's using an AT_user_def_type
8919 attribute to reference it. */
8921 static struct type
*
8922 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8924 struct objfile
*objfile
= cu
->objfile
;
8925 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8926 struct type
*type
, *range_type
, *index_type
, *char_type
;
8927 struct attribute
*attr
;
8928 unsigned int length
;
8930 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8933 length
= DW_UNSND (attr
);
8937 /* Check for the DW_AT_byte_size attribute. */
8938 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8941 length
= DW_UNSND (attr
);
8949 index_type
= objfile_type (objfile
)->builtin_int
;
8950 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8951 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8952 type
= create_string_type (NULL
, char_type
, range_type
);
8954 return set_die_type (die
, type
, cu
);
8957 /* Handle DIES due to C code like:
8961 int (*funcp)(int a, long l);
8965 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8967 static struct type
*
8968 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8970 struct objfile
*objfile
= cu
->objfile
;
8971 struct type
*type
; /* Type that this function returns. */
8972 struct type
*ftype
; /* Function that returns above type. */
8973 struct attribute
*attr
;
8975 type
= die_type (die
, cu
);
8977 /* The die_type call above may have already set the type for this DIE. */
8978 ftype
= get_die_type (die
, cu
);
8982 ftype
= lookup_function_type (type
);
8984 /* All functions in C++, Pascal and Java have prototypes. */
8985 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8986 if ((attr
&& (DW_UNSND (attr
) != 0))
8987 || cu
->language
== language_cplus
8988 || cu
->language
== language_java
8989 || cu
->language
== language_pascal
)
8990 TYPE_PROTOTYPED (ftype
) = 1;
8991 else if (producer_is_realview (cu
->producer
))
8992 /* RealView does not emit DW_AT_prototyped. We can not
8993 distinguish prototyped and unprototyped functions; default to
8994 prototyped, since that is more common in modern code (and
8995 RealView warns about unprototyped functions). */
8996 TYPE_PROTOTYPED (ftype
) = 1;
8998 /* Store the calling convention in the type if it's available in
8999 the subroutine die. Otherwise set the calling convention to
9000 the default value DW_CC_normal. */
9001 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
9003 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
9004 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
9005 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
9007 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
9009 /* We need to add the subroutine type to the die immediately so
9010 we don't infinitely recurse when dealing with parameters
9011 declared as the same subroutine type. */
9012 set_die_type (die
, ftype
, cu
);
9014 if (die
->child
!= NULL
)
9016 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
9017 struct die_info
*child_die
;
9018 int nparams
, iparams
;
9020 /* Count the number of parameters.
9021 FIXME: GDB currently ignores vararg functions, but knows about
9022 vararg member functions. */
9024 child_die
= die
->child
;
9025 while (child_die
&& child_die
->tag
)
9027 if (child_die
->tag
== DW_TAG_formal_parameter
)
9029 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
9030 TYPE_VARARGS (ftype
) = 1;
9031 child_die
= sibling_die (child_die
);
9034 /* Allocate storage for parameters and fill them in. */
9035 TYPE_NFIELDS (ftype
) = nparams
;
9036 TYPE_FIELDS (ftype
) = (struct field
*)
9037 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
9039 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
9040 even if we error out during the parameters reading below. */
9041 for (iparams
= 0; iparams
< nparams
; iparams
++)
9042 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
9045 child_die
= die
->child
;
9046 while (child_die
&& child_die
->tag
)
9048 if (child_die
->tag
== DW_TAG_formal_parameter
)
9050 struct type
*arg_type
;
9052 /* DWARF version 2 has no clean way to discern C++
9053 static and non-static member functions. G++ helps
9054 GDB by marking the first parameter for non-static
9055 member functions (which is the this pointer) as
9056 artificial. We pass this information to
9057 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
9059 DWARF version 3 added DW_AT_object_pointer, which GCC
9060 4.5 does not yet generate. */
9061 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
9063 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
9066 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
9068 /* GCC/43521: In java, the formal parameter
9069 "this" is sometimes not marked with DW_AT_artificial. */
9070 if (cu
->language
== language_java
)
9072 const char *name
= dwarf2_name (child_die
, cu
);
9074 if (name
&& !strcmp (name
, "this"))
9075 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
9078 arg_type
= die_type (child_die
, cu
);
9080 /* RealView does not mark THIS as const, which the testsuite
9081 expects. GCC marks THIS as const in method definitions,
9082 but not in the class specifications (GCC PR 43053). */
9083 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
9084 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
9087 struct dwarf2_cu
*arg_cu
= cu
;
9088 const char *name
= dwarf2_name (child_die
, cu
);
9090 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
9093 /* If the compiler emits this, use it. */
9094 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
9097 else if (name
&& strcmp (name
, "this") == 0)
9098 /* Function definitions will have the argument names. */
9100 else if (name
== NULL
&& iparams
== 0)
9101 /* Declarations may not have the names, so like
9102 elsewhere in GDB, assume an artificial first
9103 argument is "this". */
9107 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
9111 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
9114 child_die
= sibling_die (child_die
);
9121 static struct type
*
9122 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
9124 struct objfile
*objfile
= cu
->objfile
;
9125 const char *name
= NULL
;
9126 struct type
*this_type
, *target_type
;
9128 name
= dwarf2_full_name (NULL
, die
, cu
);
9129 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
9130 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
9131 TYPE_NAME (this_type
) = (char *) name
;
9132 set_die_type (die
, this_type
, cu
);
9133 target_type
= die_type (die
, cu
);
9134 if (target_type
!= this_type
)
9135 TYPE_TARGET_TYPE (this_type
) = target_type
;
9138 /* Self-referential typedefs are, it seems, not allowed by the DWARF
9139 spec and cause infinite loops in GDB. */
9140 complaint (&symfile_complaints
,
9141 _("Self-referential DW_TAG_typedef "
9142 "- DIE at 0x%x [in module %s]"),
9143 die
->offset
.sect_off
, objfile
->name
);
9144 TYPE_TARGET_TYPE (this_type
) = NULL
;
9149 /* Find a representation of a given base type and install
9150 it in the TYPE field of the die. */
9152 static struct type
*
9153 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9155 struct objfile
*objfile
= cu
->objfile
;
9157 struct attribute
*attr
;
9158 int encoding
= 0, size
= 0;
9160 enum type_code code
= TYPE_CODE_INT
;
9162 struct type
*target_type
= NULL
;
9164 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
9167 encoding
= DW_UNSND (attr
);
9169 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9172 size
= DW_UNSND (attr
);
9174 name
= dwarf2_name (die
, cu
);
9177 complaint (&symfile_complaints
,
9178 _("DW_AT_name missing from DW_TAG_base_type"));
9183 case DW_ATE_address
:
9184 /* Turn DW_ATE_address into a void * pointer. */
9185 code
= TYPE_CODE_PTR
;
9186 type_flags
|= TYPE_FLAG_UNSIGNED
;
9187 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
9189 case DW_ATE_boolean
:
9190 code
= TYPE_CODE_BOOL
;
9191 type_flags
|= TYPE_FLAG_UNSIGNED
;
9193 case DW_ATE_complex_float
:
9194 code
= TYPE_CODE_COMPLEX
;
9195 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
9197 case DW_ATE_decimal_float
:
9198 code
= TYPE_CODE_DECFLOAT
;
9201 code
= TYPE_CODE_FLT
;
9205 case DW_ATE_unsigned
:
9206 type_flags
|= TYPE_FLAG_UNSIGNED
;
9207 if (cu
->language
== language_fortran
9209 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
9210 code
= TYPE_CODE_CHAR
;
9212 case DW_ATE_signed_char
:
9213 if (cu
->language
== language_ada
|| cu
->language
== language_m2
9214 || cu
->language
== language_pascal
9215 || cu
->language
== language_fortran
)
9216 code
= TYPE_CODE_CHAR
;
9218 case DW_ATE_unsigned_char
:
9219 if (cu
->language
== language_ada
|| cu
->language
== language_m2
9220 || cu
->language
== language_pascal
9221 || cu
->language
== language_fortran
)
9222 code
= TYPE_CODE_CHAR
;
9223 type_flags
|= TYPE_FLAG_UNSIGNED
;
9226 /* We just treat this as an integer and then recognize the
9227 type by name elsewhere. */
9231 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
9232 dwarf_type_encoding_name (encoding
));
9236 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
9237 TYPE_NAME (type
) = name
;
9238 TYPE_TARGET_TYPE (type
) = target_type
;
9240 if (name
&& strcmp (name
, "char") == 0)
9241 TYPE_NOSIGN (type
) = 1;
9243 return set_die_type (die
, type
, cu
);
9246 /* Read the given DW_AT_subrange DIE. */
9248 static struct type
*
9249 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9251 struct type
*base_type
;
9252 struct type
*range_type
;
9253 struct attribute
*attr
;
9255 int low_default_is_valid
;
9257 LONGEST negative_mask
;
9259 base_type
= die_type (die
, cu
);
9260 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
9261 check_typedef (base_type
);
9263 /* The die_type call above may have already set the type for this DIE. */
9264 range_type
= get_die_type (die
, cu
);
9268 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
9269 omitting DW_AT_lower_bound. */
9270 switch (cu
->language
)
9273 case language_cplus
:
9275 low_default_is_valid
= 1;
9277 case language_fortran
:
9279 low_default_is_valid
= 1;
9285 low_default_is_valid
= (cu
->header
.version
>= 4);
9289 case language_pascal
:
9291 low_default_is_valid
= (cu
->header
.version
>= 4);
9295 low_default_is_valid
= 0;
9299 /* FIXME: For variable sized arrays either of these could be
9300 a variable rather than a constant value. We'll allow it,
9301 but we don't know how to handle it. */
9302 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
9304 low
= dwarf2_get_attr_constant_value (attr
, low
);
9305 else if (!low_default_is_valid
)
9306 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
9307 "- DIE at 0x%x [in module %s]"),
9308 die
->offset
.sect_off
, cu
->objfile
->name
);
9310 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
9313 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
9315 /* GCC encodes arrays with unspecified or dynamic length
9316 with a DW_FORM_block1 attribute or a reference attribute.
9317 FIXME: GDB does not yet know how to handle dynamic
9318 arrays properly, treat them as arrays with unspecified
9321 FIXME: jimb/2003-09-22: GDB does not really know
9322 how to handle arrays of unspecified length
9323 either; we just represent them as zero-length
9324 arrays. Choose an appropriate upper bound given
9325 the lower bound we've computed above. */
9329 high
= dwarf2_get_attr_constant_value (attr
, 1);
9333 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
9336 int count
= dwarf2_get_attr_constant_value (attr
, 1);
9337 high
= low
+ count
- 1;
9341 /* Unspecified array length. */
9346 /* Dwarf-2 specifications explicitly allows to create subrange types
9347 without specifying a base type.
9348 In that case, the base type must be set to the type of
9349 the lower bound, upper bound or count, in that order, if any of these
9350 three attributes references an object that has a type.
9351 If no base type is found, the Dwarf-2 specifications say that
9352 a signed integer type of size equal to the size of an address should
9354 For the following C code: `extern char gdb_int [];'
9355 GCC produces an empty range DIE.
9356 FIXME: muller/2010-05-28: Possible references to object for low bound,
9357 high bound or count are not yet handled by this code. */
9358 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
9360 struct objfile
*objfile
= cu
->objfile
;
9361 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9362 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
9363 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
9365 /* Test "int", "long int", and "long long int" objfile types,
9366 and select the first one having a size above or equal to the
9367 architecture address size. */
9368 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9369 base_type
= int_type
;
9372 int_type
= objfile_type (objfile
)->builtin_long
;
9373 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9374 base_type
= int_type
;
9377 int_type
= objfile_type (objfile
)->builtin_long_long
;
9378 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9379 base_type
= int_type
;
9385 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
9386 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
9387 low
|= negative_mask
;
9388 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
9389 high
|= negative_mask
;
9391 range_type
= create_range_type (NULL
, base_type
, low
, high
);
9393 /* Mark arrays with dynamic length at least as an array of unspecified
9394 length. GDB could check the boundary but before it gets implemented at
9395 least allow accessing the array elements. */
9396 if (attr
&& attr_form_is_block (attr
))
9397 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9399 /* Ada expects an empty array on no boundary attributes. */
9400 if (attr
== NULL
&& cu
->language
!= language_ada
)
9401 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9403 name
= dwarf2_name (die
, cu
);
9405 TYPE_NAME (range_type
) = name
;
9407 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9409 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
9411 set_die_type (die
, range_type
, cu
);
9413 /* set_die_type should be already done. */
9414 set_descriptive_type (range_type
, die
, cu
);
9419 static struct type
*
9420 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9424 /* For now, we only support the C meaning of an unspecified type: void. */
9426 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
9427 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
9429 return set_die_type (die
, type
, cu
);
9432 /* Read a single die and all its descendents. Set the die's sibling
9433 field to NULL; set other fields in the die correctly, and set all
9434 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9435 location of the info_ptr after reading all of those dies. PARENT
9436 is the parent of the die in question. */
9438 static struct die_info
*
9439 read_die_and_children (const struct die_reader_specs
*reader
,
9441 gdb_byte
**new_info_ptr
,
9442 struct die_info
*parent
)
9444 struct die_info
*die
;
9448 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
9451 *new_info_ptr
= cur_ptr
;
9454 store_in_ref_table (die
, reader
->cu
);
9457 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
9461 *new_info_ptr
= cur_ptr
;
9464 die
->sibling
= NULL
;
9465 die
->parent
= parent
;
9469 /* Read a die, all of its descendents, and all of its siblings; set
9470 all of the fields of all of the dies correctly. Arguments are as
9471 in read_die_and_children. */
9473 static struct die_info
*
9474 read_die_and_siblings (const struct die_reader_specs
*reader
,
9476 gdb_byte
**new_info_ptr
,
9477 struct die_info
*parent
)
9479 struct die_info
*first_die
, *last_sibling
;
9483 first_die
= last_sibling
= NULL
;
9487 struct die_info
*die
9488 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
9492 *new_info_ptr
= cur_ptr
;
9499 last_sibling
->sibling
= die
;
9505 /* Read the die from the .debug_info section buffer. Set DIEP to
9506 point to a newly allocated die with its information, except for its
9507 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9508 whether the die has children or not. */
9511 read_full_die (const struct die_reader_specs
*reader
,
9512 struct die_info
**diep
, gdb_byte
*info_ptr
,
9515 unsigned int abbrev_number
, bytes_read
, i
;
9517 struct abbrev_info
*abbrev
;
9518 struct die_info
*die
;
9519 struct dwarf2_cu
*cu
= reader
->cu
;
9520 bfd
*abfd
= reader
->abfd
;
9522 offset
.sect_off
= info_ptr
- reader
->buffer
;
9523 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9524 info_ptr
+= bytes_read
;
9532 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
9534 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9536 bfd_get_filename (abfd
));
9538 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
9539 die
->offset
= offset
;
9540 die
->tag
= abbrev
->tag
;
9541 die
->abbrev
= abbrev_number
;
9543 die
->num_attrs
= abbrev
->num_attrs
;
9545 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9546 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
9550 *has_children
= abbrev
->has_children
;
9554 /* In DWARF version 2, the description of the debugging information is
9555 stored in a separate .debug_abbrev section. Before we read any
9556 dies from a section we read in all abbreviations and install them
9557 in a hash table. This function also sets flags in CU describing
9558 the data found in the abbrev table. */
9561 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
9562 struct dwarf2_section_info
*abbrev_section
)
9565 bfd
*abfd
= abbrev_section
->asection
->owner
;
9566 struct comp_unit_head
*cu_header
= &cu
->header
;
9567 gdb_byte
*abbrev_ptr
;
9568 struct abbrev_info
*cur_abbrev
;
9569 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9570 unsigned int abbrev_form
, hash_number
;
9571 struct attr_abbrev
*cur_attrs
;
9572 unsigned int allocated_attrs
;
9574 /* Initialize dwarf2 abbrevs. */
9575 obstack_init (&cu
->abbrev_obstack
);
9576 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9578 * sizeof (struct abbrev_info
*)));
9579 memset (cu
->dwarf2_abbrevs
, 0,
9580 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9582 dwarf2_read_section (cu
->objfile
, abbrev_section
);
9583 abbrev_ptr
= abbrev_section
->buffer
+ cu_header
->abbrev_offset
.sect_off
;
9584 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9585 abbrev_ptr
+= bytes_read
;
9587 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9588 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9590 /* Loop until we reach an abbrev number of 0. */
9591 while (abbrev_number
)
9593 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9595 /* read in abbrev header */
9596 cur_abbrev
->number
= abbrev_number
;
9597 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9598 abbrev_ptr
+= bytes_read
;
9599 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9602 /* now read in declarations */
9603 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9604 abbrev_ptr
+= bytes_read
;
9605 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9606 abbrev_ptr
+= bytes_read
;
9609 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9611 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9613 = xrealloc (cur_attrs
, (allocated_attrs
9614 * sizeof (struct attr_abbrev
)));
9617 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9618 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9619 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9620 abbrev_ptr
+= bytes_read
;
9621 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9622 abbrev_ptr
+= bytes_read
;
9625 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9626 (cur_abbrev
->num_attrs
9627 * sizeof (struct attr_abbrev
)));
9628 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9629 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9631 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9632 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9633 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9635 /* Get next abbreviation.
9636 Under Irix6 the abbreviations for a compilation unit are not
9637 always properly terminated with an abbrev number of 0.
9638 Exit loop if we encounter an abbreviation which we have
9639 already read (which means we are about to read the abbreviations
9640 for the next compile unit) or if the end of the abbreviation
9641 table is reached. */
9642 if ((unsigned int) (abbrev_ptr
- abbrev_section
->buffer
)
9643 >= abbrev_section
->size
)
9645 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9646 abbrev_ptr
+= bytes_read
;
9647 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9654 /* Release the memory used by the abbrev table for a compilation unit. */
9657 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9659 struct dwarf2_cu
*cu
= ptr_to_cu
;
9661 obstack_free (&cu
->abbrev_obstack
, NULL
);
9662 cu
->dwarf2_abbrevs
= NULL
;
9665 /* Lookup an abbrev_info structure in the abbrev hash table. */
9667 static struct abbrev_info
*
9668 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9670 unsigned int hash_number
;
9671 struct abbrev_info
*abbrev
;
9673 hash_number
= number
% ABBREV_HASH_SIZE
;
9674 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9678 if (abbrev
->number
== number
)
9681 abbrev
= abbrev
->next
;
9686 /* Returns nonzero if TAG represents a type that we might generate a partial
9690 is_type_tag_for_partial (int tag
)
9695 /* Some types that would be reasonable to generate partial symbols for,
9696 that we don't at present. */
9697 case DW_TAG_array_type
:
9698 case DW_TAG_file_type
:
9699 case DW_TAG_ptr_to_member_type
:
9700 case DW_TAG_set_type
:
9701 case DW_TAG_string_type
:
9702 case DW_TAG_subroutine_type
:
9704 case DW_TAG_base_type
:
9705 case DW_TAG_class_type
:
9706 case DW_TAG_interface_type
:
9707 case DW_TAG_enumeration_type
:
9708 case DW_TAG_structure_type
:
9709 case DW_TAG_subrange_type
:
9710 case DW_TAG_typedef
:
9711 case DW_TAG_union_type
:
9718 /* Load all DIEs that are interesting for partial symbols into memory. */
9720 static struct partial_die_info
*
9721 load_partial_dies (const struct die_reader_specs
*reader
,
9722 gdb_byte
*info_ptr
, int building_psymtab
)
9724 struct dwarf2_cu
*cu
= reader
->cu
;
9725 struct objfile
*objfile
= cu
->objfile
;
9726 struct partial_die_info
*part_die
;
9727 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9728 struct abbrev_info
*abbrev
;
9729 unsigned int bytes_read
;
9730 unsigned int load_all
= 0;
9731 int nesting_level
= 1;
9736 gdb_assert (cu
->per_cu
!= NULL
);
9737 if (cu
->per_cu
->load_all_dies
)
9741 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9745 &cu
->comp_unit_obstack
,
9746 hashtab_obstack_allocate
,
9747 dummy_obstack_deallocate
);
9749 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9750 sizeof (struct partial_die_info
));
9754 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9756 /* A NULL abbrev means the end of a series of children. */
9759 if (--nesting_level
== 0)
9761 /* PART_DIE was probably the last thing allocated on the
9762 comp_unit_obstack, so we could call obstack_free
9763 here. We don't do that because the waste is small,
9764 and will be cleaned up when we're done with this
9765 compilation unit. This way, we're also more robust
9766 against other users of the comp_unit_obstack. */
9769 info_ptr
+= bytes_read
;
9770 last_die
= parent_die
;
9771 parent_die
= parent_die
->die_parent
;
9775 /* Check for template arguments. We never save these; if
9776 they're seen, we just mark the parent, and go on our way. */
9777 if (parent_die
!= NULL
9778 && cu
->language
== language_cplus
9779 && (abbrev
->tag
== DW_TAG_template_type_param
9780 || abbrev
->tag
== DW_TAG_template_value_param
))
9782 parent_die
->has_template_arguments
= 1;
9786 /* We don't need a partial DIE for the template argument. */
9787 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9792 /* We only recurse into c++ subprograms looking for template arguments.
9793 Skip their other children. */
9795 && cu
->language
== language_cplus
9796 && parent_die
!= NULL
9797 && parent_die
->tag
== DW_TAG_subprogram
)
9799 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9803 /* Check whether this DIE is interesting enough to save. Normally
9804 we would not be interested in members here, but there may be
9805 later variables referencing them via DW_AT_specification (for
9808 && !is_type_tag_for_partial (abbrev
->tag
)
9809 && abbrev
->tag
!= DW_TAG_constant
9810 && abbrev
->tag
!= DW_TAG_enumerator
9811 && abbrev
->tag
!= DW_TAG_subprogram
9812 && abbrev
->tag
!= DW_TAG_lexical_block
9813 && abbrev
->tag
!= DW_TAG_variable
9814 && abbrev
->tag
!= DW_TAG_namespace
9815 && abbrev
->tag
!= DW_TAG_module
9816 && abbrev
->tag
!= DW_TAG_member
)
9818 /* Otherwise we skip to the next sibling, if any. */
9819 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9823 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
9826 /* This two-pass algorithm for processing partial symbols has a
9827 high cost in cache pressure. Thus, handle some simple cases
9828 here which cover the majority of C partial symbols. DIEs
9829 which neither have specification tags in them, nor could have
9830 specification tags elsewhere pointing at them, can simply be
9831 processed and discarded.
9833 This segment is also optional; scan_partial_symbols and
9834 add_partial_symbol will handle these DIEs if we chain
9835 them in normally. When compilers which do not emit large
9836 quantities of duplicate debug information are more common,
9837 this code can probably be removed. */
9839 /* Any complete simple types at the top level (pretty much all
9840 of them, for a language without namespaces), can be processed
9842 if (parent_die
== NULL
9843 && part_die
->has_specification
== 0
9844 && part_die
->is_declaration
== 0
9845 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9846 || part_die
->tag
== DW_TAG_base_type
9847 || part_die
->tag
== DW_TAG_subrange_type
))
9849 if (building_psymtab
&& part_die
->name
!= NULL
)
9850 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9851 VAR_DOMAIN
, LOC_TYPEDEF
,
9852 &objfile
->static_psymbols
,
9853 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9854 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
9858 /* The exception for DW_TAG_typedef with has_children above is
9859 a workaround of GCC PR debug/47510. In the case of this complaint
9860 type_name_no_tag_or_error will error on such types later.
9862 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9863 it could not find the child DIEs referenced later, this is checked
9864 above. In correct DWARF DW_TAG_typedef should have no children. */
9866 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9867 complaint (&symfile_complaints
,
9868 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9869 "- DIE at 0x%x [in module %s]"),
9870 part_die
->offset
.sect_off
, objfile
->name
);
9872 /* If we're at the second level, and we're an enumerator, and
9873 our parent has no specification (meaning possibly lives in a
9874 namespace elsewhere), then we can add the partial symbol now
9875 instead of queueing it. */
9876 if (part_die
->tag
== DW_TAG_enumerator
9877 && parent_die
!= NULL
9878 && parent_die
->die_parent
== NULL
9879 && parent_die
->tag
== DW_TAG_enumeration_type
9880 && parent_die
->has_specification
== 0)
9882 if (part_die
->name
== NULL
)
9883 complaint (&symfile_complaints
,
9884 _("malformed enumerator DIE ignored"));
9885 else if (building_psymtab
)
9886 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9887 VAR_DOMAIN
, LOC_CONST
,
9888 (cu
->language
== language_cplus
9889 || cu
->language
== language_java
)
9890 ? &objfile
->global_psymbols
9891 : &objfile
->static_psymbols
,
9892 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9894 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
9898 /* We'll save this DIE so link it in. */
9899 part_die
->die_parent
= parent_die
;
9900 part_die
->die_sibling
= NULL
;
9901 part_die
->die_child
= NULL
;
9903 if (last_die
&& last_die
== parent_die
)
9904 last_die
->die_child
= part_die
;
9906 last_die
->die_sibling
= part_die
;
9908 last_die
= part_die
;
9910 if (first_die
== NULL
)
9911 first_die
= part_die
;
9913 /* Maybe add the DIE to the hash table. Not all DIEs that we
9914 find interesting need to be in the hash table, because we
9915 also have the parent/sibling/child chains; only those that we
9916 might refer to by offset later during partial symbol reading.
9918 For now this means things that might have be the target of a
9919 DW_AT_specification, DW_AT_abstract_origin, or
9920 DW_AT_extension. DW_AT_extension will refer only to
9921 namespaces; DW_AT_abstract_origin refers to functions (and
9922 many things under the function DIE, but we do not recurse
9923 into function DIEs during partial symbol reading) and
9924 possibly variables as well; DW_AT_specification refers to
9925 declarations. Declarations ought to have the DW_AT_declaration
9926 flag. It happens that GCC forgets to put it in sometimes, but
9927 only for functions, not for types.
9929 Adding more things than necessary to the hash table is harmless
9930 except for the performance cost. Adding too few will result in
9931 wasted time in find_partial_die, when we reread the compilation
9932 unit with load_all_dies set. */
9935 || abbrev
->tag
== DW_TAG_constant
9936 || abbrev
->tag
== DW_TAG_subprogram
9937 || abbrev
->tag
== DW_TAG_variable
9938 || abbrev
->tag
== DW_TAG_namespace
9939 || part_die
->is_declaration
)
9943 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9944 part_die
->offset
.sect_off
, INSERT
);
9948 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9949 sizeof (struct partial_die_info
));
9951 /* For some DIEs we want to follow their children (if any). For C
9952 we have no reason to follow the children of structures; for other
9953 languages we have to, so that we can get at method physnames
9954 to infer fully qualified class names, for DW_AT_specification,
9955 and for C++ template arguments. For C++, we also look one level
9956 inside functions to find template arguments (if the name of the
9957 function does not already contain the template arguments).
9959 For Ada, we need to scan the children of subprograms and lexical
9960 blocks as well because Ada allows the definition of nested
9961 entities that could be interesting for the debugger, such as
9962 nested subprograms for instance. */
9963 if (last_die
->has_children
9965 || last_die
->tag
== DW_TAG_namespace
9966 || last_die
->tag
== DW_TAG_module
9967 || last_die
->tag
== DW_TAG_enumeration_type
9968 || (cu
->language
== language_cplus
9969 && last_die
->tag
== DW_TAG_subprogram
9970 && (last_die
->name
== NULL
9971 || strchr (last_die
->name
, '<') == NULL
))
9972 || (cu
->language
!= language_c
9973 && (last_die
->tag
== DW_TAG_class_type
9974 || last_die
->tag
== DW_TAG_interface_type
9975 || last_die
->tag
== DW_TAG_structure_type
9976 || last_die
->tag
== DW_TAG_union_type
))
9977 || (cu
->language
== language_ada
9978 && (last_die
->tag
== DW_TAG_subprogram
9979 || last_die
->tag
== DW_TAG_lexical_block
))))
9982 parent_die
= last_die
;
9986 /* Otherwise we skip to the next sibling, if any. */
9987 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
9989 /* Back to the top, do it again. */
9993 /* Read a minimal amount of information into the minimal die structure. */
9996 read_partial_die (const struct die_reader_specs
*reader
,
9997 struct partial_die_info
*part_die
,
9998 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
10001 struct dwarf2_cu
*cu
= reader
->cu
;
10002 struct objfile
*objfile
= cu
->objfile
;
10003 gdb_byte
*buffer
= reader
->buffer
;
10005 struct attribute attr
;
10006 int has_low_pc_attr
= 0;
10007 int has_high_pc_attr
= 0;
10008 int high_pc_relative
= 0;
10010 memset (part_die
, 0, sizeof (struct partial_die_info
));
10012 part_die
->offset
.sect_off
= info_ptr
- buffer
;
10014 info_ptr
+= abbrev_len
;
10016 if (abbrev
== NULL
)
10019 part_die
->tag
= abbrev
->tag
;
10020 part_die
->has_children
= abbrev
->has_children
;
10022 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
10024 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
10026 /* Store the data if it is of an attribute we want to keep in a
10027 partial symbol table. */
10031 switch (part_die
->tag
)
10033 case DW_TAG_compile_unit
:
10034 case DW_TAG_type_unit
:
10035 /* Compilation units have a DW_AT_name that is a filename, not
10036 a source language identifier. */
10037 case DW_TAG_enumeration_type
:
10038 case DW_TAG_enumerator
:
10039 /* These tags always have simple identifiers already; no need
10040 to canonicalize them. */
10041 part_die
->name
= DW_STRING (&attr
);
10045 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
10046 &objfile
->objfile_obstack
);
10050 case DW_AT_linkage_name
:
10051 case DW_AT_MIPS_linkage_name
:
10052 /* Note that both forms of linkage name might appear. We
10053 assume they will be the same, and we only store the last
10055 if (cu
->language
== language_ada
)
10056 part_die
->name
= DW_STRING (&attr
);
10057 part_die
->linkage_name
= DW_STRING (&attr
);
10060 has_low_pc_attr
= 1;
10061 part_die
->lowpc
= DW_ADDR (&attr
);
10063 case DW_AT_high_pc
:
10064 has_high_pc_attr
= 1;
10065 if (attr
.form
== DW_FORM_addr
)
10066 part_die
->highpc
= DW_ADDR (&attr
);
10069 high_pc_relative
= 1;
10070 part_die
->highpc
= DW_UNSND (&attr
);
10073 case DW_AT_location
:
10074 /* Support the .debug_loc offsets. */
10075 if (attr_form_is_block (&attr
))
10077 part_die
->locdesc
= DW_BLOCK (&attr
);
10079 else if (attr_form_is_section_offset (&attr
))
10081 dwarf2_complex_location_expr_complaint ();
10085 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
10086 "partial symbol information");
10089 case DW_AT_external
:
10090 part_die
->is_external
= DW_UNSND (&attr
);
10092 case DW_AT_declaration
:
10093 part_die
->is_declaration
= DW_UNSND (&attr
);
10096 part_die
->has_type
= 1;
10098 case DW_AT_abstract_origin
:
10099 case DW_AT_specification
:
10100 case DW_AT_extension
:
10101 part_die
->has_specification
= 1;
10102 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
10104 case DW_AT_sibling
:
10105 /* Ignore absolute siblings, they might point outside of
10106 the current compile unit. */
10107 if (attr
.form
== DW_FORM_ref_addr
)
10108 complaint (&symfile_complaints
,
10109 _("ignoring absolute DW_AT_sibling"));
10111 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
10113 case DW_AT_byte_size
:
10114 part_die
->has_byte_size
= 1;
10116 case DW_AT_calling_convention
:
10117 /* DWARF doesn't provide a way to identify a program's source-level
10118 entry point. DW_AT_calling_convention attributes are only meant
10119 to describe functions' calling conventions.
10121 However, because it's a necessary piece of information in
10122 Fortran, and because DW_CC_program is the only piece of debugging
10123 information whose definition refers to a 'main program' at all,
10124 several compilers have begun marking Fortran main programs with
10125 DW_CC_program --- even when those functions use the standard
10126 calling conventions.
10128 So until DWARF specifies a way to provide this information and
10129 compilers pick up the new representation, we'll support this
10131 if (DW_UNSND (&attr
) == DW_CC_program
10132 && cu
->language
== language_fortran
)
10134 set_main_name (part_die
->name
);
10136 /* As this DIE has a static linkage the name would be difficult
10137 to look up later. */
10138 language_of_main
= language_fortran
;
10142 if (DW_UNSND (&attr
) == DW_INL_inlined
10143 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
10144 part_die
->may_be_inlined
= 1;
10151 if (high_pc_relative
)
10152 part_die
->highpc
+= part_die
->lowpc
;
10154 if (has_low_pc_attr
&& has_high_pc_attr
)
10156 /* When using the GNU linker, .gnu.linkonce. sections are used to
10157 eliminate duplicate copies of functions and vtables and such.
10158 The linker will arbitrarily choose one and discard the others.
10159 The AT_*_pc values for such functions refer to local labels in
10160 these sections. If the section from that file was discarded, the
10161 labels are not in the output, so the relocs get a value of 0.
10162 If this is a discarded function, mark the pc bounds as invalid,
10163 so that GDB will ignore it. */
10164 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10166 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10168 complaint (&symfile_complaints
,
10169 _("DW_AT_low_pc %s is zero "
10170 "for DIE at 0x%x [in module %s]"),
10171 paddress (gdbarch
, part_die
->lowpc
),
10172 part_die
->offset
.sect_off
, objfile
->name
);
10174 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
10175 else if (part_die
->lowpc
>= part_die
->highpc
)
10177 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10179 complaint (&symfile_complaints
,
10180 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
10181 "for DIE at 0x%x [in module %s]"),
10182 paddress (gdbarch
, part_die
->lowpc
),
10183 paddress (gdbarch
, part_die
->highpc
),
10184 part_die
->offset
.sect_off
, objfile
->name
);
10187 part_die
->has_pc_info
= 1;
10193 /* Find a cached partial DIE at OFFSET in CU. */
10195 static struct partial_die_info
*
10196 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
10198 struct partial_die_info
*lookup_die
= NULL
;
10199 struct partial_die_info part_die
;
10201 part_die
.offset
= offset
;
10202 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
10208 /* Find a partial DIE at OFFSET, which may or may not be in CU,
10209 except in the case of .debug_types DIEs which do not reference
10210 outside their CU (they do however referencing other types via
10211 DW_FORM_ref_sig8). */
10213 static struct partial_die_info
*
10214 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
10216 struct objfile
*objfile
= cu
->objfile
;
10217 struct dwarf2_per_cu_data
*per_cu
= NULL
;
10218 struct partial_die_info
*pd
= NULL
;
10220 if (offset_in_cu_p (&cu
->header
, offset
))
10222 pd
= find_partial_die_in_comp_unit (offset
, cu
);
10225 /* We missed recording what we needed.
10226 Load all dies and try again. */
10227 per_cu
= cu
->per_cu
;
10231 /* TUs don't reference other CUs/TUs (except via type signatures). */
10232 if (cu
->per_cu
->debug_types_section
)
10234 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
10235 " external reference to offset 0x%lx [in module %s].\n"),
10236 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
10237 bfd_get_filename (objfile
->obfd
));
10239 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10241 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
10242 load_partial_comp_unit (per_cu
);
10244 per_cu
->cu
->last_used
= 0;
10245 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10248 /* If we didn't find it, and not all dies have been loaded,
10249 load them all and try again. */
10251 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
10253 /* FIXME: The testsuite doesn't trigger this code path.
10254 http://sourceware.org/bugzilla/show_bug.cgi?id=13961 */
10256 free_one_cached_comp_unit (per_cu
);
10257 per_cu
->load_all_dies
= 1;
10258 load_partial_comp_unit (per_cu
);
10260 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10264 internal_error (__FILE__
, __LINE__
,
10265 _("could not find partial DIE 0x%x "
10266 "in cache [from module %s]\n"),
10267 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
10271 /* See if we can figure out if the class lives in a namespace. We do
10272 this by looking for a member function; its demangled name will
10273 contain namespace info, if there is any. */
10276 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
10277 struct dwarf2_cu
*cu
)
10279 /* NOTE: carlton/2003-10-07: Getting the info this way changes
10280 what template types look like, because the demangler
10281 frequently doesn't give the same name as the debug info. We
10282 could fix this by only using the demangled name to get the
10283 prefix (but see comment in read_structure_type). */
10285 struct partial_die_info
*real_pdi
;
10286 struct partial_die_info
*child_pdi
;
10288 /* If this DIE (this DIE's specification, if any) has a parent, then
10289 we should not do this. We'll prepend the parent's fully qualified
10290 name when we create the partial symbol. */
10292 real_pdi
= struct_pdi
;
10293 while (real_pdi
->has_specification
)
10294 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
10296 if (real_pdi
->die_parent
!= NULL
)
10299 for (child_pdi
= struct_pdi
->die_child
;
10301 child_pdi
= child_pdi
->die_sibling
)
10303 if (child_pdi
->tag
== DW_TAG_subprogram
10304 && child_pdi
->linkage_name
!= NULL
)
10306 char *actual_class_name
10307 = language_class_name_from_physname (cu
->language_defn
,
10308 child_pdi
->linkage_name
);
10309 if (actual_class_name
!= NULL
)
10312 = obsavestring (actual_class_name
,
10313 strlen (actual_class_name
),
10314 &cu
->objfile
->objfile_obstack
);
10315 xfree (actual_class_name
);
10322 /* Adjust PART_DIE before generating a symbol for it. This function
10323 may set the is_external flag or change the DIE's name. */
10326 fixup_partial_die (struct partial_die_info
*part_die
,
10327 struct dwarf2_cu
*cu
)
10329 /* Once we've fixed up a die, there's no point in doing so again.
10330 This also avoids a memory leak if we were to call
10331 guess_partial_die_structure_name multiple times. */
10332 if (part_die
->fixup_called
)
10335 /* If we found a reference attribute and the DIE has no name, try
10336 to find a name in the referred to DIE. */
10338 if (part_die
->name
== NULL
&& part_die
->has_specification
)
10340 struct partial_die_info
*spec_die
;
10342 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
10344 fixup_partial_die (spec_die
, cu
);
10346 if (spec_die
->name
)
10348 part_die
->name
= spec_die
->name
;
10350 /* Copy DW_AT_external attribute if it is set. */
10351 if (spec_die
->is_external
)
10352 part_die
->is_external
= spec_die
->is_external
;
10356 /* Set default names for some unnamed DIEs. */
10358 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
10359 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
10361 /* If there is no parent die to provide a namespace, and there are
10362 children, see if we can determine the namespace from their linkage
10364 if (cu
->language
== language_cplus
10365 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
10366 && part_die
->die_parent
== NULL
10367 && part_die
->has_children
10368 && (part_die
->tag
== DW_TAG_class_type
10369 || part_die
->tag
== DW_TAG_structure_type
10370 || part_die
->tag
== DW_TAG_union_type
))
10371 guess_partial_die_structure_name (part_die
, cu
);
10373 /* GCC might emit a nameless struct or union that has a linkage
10374 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10375 if (part_die
->name
== NULL
10376 && (part_die
->tag
== DW_TAG_class_type
10377 || part_die
->tag
== DW_TAG_interface_type
10378 || part_die
->tag
== DW_TAG_structure_type
10379 || part_die
->tag
== DW_TAG_union_type
)
10380 && part_die
->linkage_name
!= NULL
)
10384 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
10389 /* Strip any leading namespaces/classes, keep only the base name.
10390 DW_AT_name for named DIEs does not contain the prefixes. */
10391 base
= strrchr (demangled
, ':');
10392 if (base
&& base
> demangled
&& base
[-1] == ':')
10397 part_die
->name
= obsavestring (base
, strlen (base
),
10398 &cu
->objfile
->objfile_obstack
);
10403 part_die
->fixup_called
= 1;
10406 /* Read an attribute value described by an attribute form. */
10409 read_attribute_value (const struct die_reader_specs
*reader
,
10410 struct attribute
*attr
, unsigned form
,
10411 gdb_byte
*info_ptr
)
10413 struct dwarf2_cu
*cu
= reader
->cu
;
10414 bfd
*abfd
= reader
->abfd
;
10415 struct comp_unit_head
*cu_header
= &cu
->header
;
10416 unsigned int bytes_read
;
10417 struct dwarf_block
*blk
;
10422 case DW_FORM_ref_addr
:
10423 if (cu
->header
.version
== 2)
10424 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10426 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
10427 &cu
->header
, &bytes_read
);
10428 info_ptr
+= bytes_read
;
10431 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10432 info_ptr
+= bytes_read
;
10434 case DW_FORM_block2
:
10435 blk
= dwarf_alloc_block (cu
);
10436 blk
->size
= read_2_bytes (abfd
, info_ptr
);
10438 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10439 info_ptr
+= blk
->size
;
10440 DW_BLOCK (attr
) = blk
;
10442 case DW_FORM_block4
:
10443 blk
= dwarf_alloc_block (cu
);
10444 blk
->size
= read_4_bytes (abfd
, info_ptr
);
10446 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10447 info_ptr
+= blk
->size
;
10448 DW_BLOCK (attr
) = blk
;
10450 case DW_FORM_data2
:
10451 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
10454 case DW_FORM_data4
:
10455 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
10458 case DW_FORM_data8
:
10459 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
10462 case DW_FORM_sec_offset
:
10463 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
10464 info_ptr
+= bytes_read
;
10466 case DW_FORM_string
:
10467 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
10468 DW_STRING_IS_CANONICAL (attr
) = 0;
10469 info_ptr
+= bytes_read
;
10472 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
10474 DW_STRING_IS_CANONICAL (attr
) = 0;
10475 info_ptr
+= bytes_read
;
10477 case DW_FORM_exprloc
:
10478 case DW_FORM_block
:
10479 blk
= dwarf_alloc_block (cu
);
10480 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10481 info_ptr
+= bytes_read
;
10482 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10483 info_ptr
+= blk
->size
;
10484 DW_BLOCK (attr
) = blk
;
10486 case DW_FORM_block1
:
10487 blk
= dwarf_alloc_block (cu
);
10488 blk
->size
= read_1_byte (abfd
, info_ptr
);
10490 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10491 info_ptr
+= blk
->size
;
10492 DW_BLOCK (attr
) = blk
;
10494 case DW_FORM_data1
:
10495 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10499 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10502 case DW_FORM_flag_present
:
10503 DW_UNSND (attr
) = 1;
10505 case DW_FORM_sdata
:
10506 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
10507 info_ptr
+= bytes_read
;
10509 case DW_FORM_udata
:
10510 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10511 info_ptr
+= bytes_read
;
10514 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10515 + read_1_byte (abfd
, info_ptr
));
10519 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10520 + read_2_bytes (abfd
, info_ptr
));
10524 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10525 + read_4_bytes (abfd
, info_ptr
));
10529 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10530 + read_8_bytes (abfd
, info_ptr
));
10533 case DW_FORM_ref_sig8
:
10534 /* Convert the signature to something we can record in DW_UNSND
10536 NOTE: This is NULL if the type wasn't found. */
10537 DW_SIGNATURED_TYPE (attr
) =
10538 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
10541 case DW_FORM_ref_udata
:
10542 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10543 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
10544 info_ptr
+= bytes_read
;
10546 case DW_FORM_indirect
:
10547 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10548 info_ptr
+= bytes_read
;
10549 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
10552 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10553 dwarf_form_name (form
),
10554 bfd_get_filename (abfd
));
10557 /* We have seen instances where the compiler tried to emit a byte
10558 size attribute of -1 which ended up being encoded as an unsigned
10559 0xffffffff. Although 0xffffffff is technically a valid size value,
10560 an object of this size seems pretty unlikely so we can relatively
10561 safely treat these cases as if the size attribute was invalid and
10562 treat them as zero by default. */
10563 if (attr
->name
== DW_AT_byte_size
10564 && form
== DW_FORM_data4
10565 && DW_UNSND (attr
) >= 0xffffffff)
10568 (&symfile_complaints
,
10569 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10570 hex_string (DW_UNSND (attr
)));
10571 DW_UNSND (attr
) = 0;
10577 /* Read an attribute described by an abbreviated attribute. */
10580 read_attribute (const struct die_reader_specs
*reader
,
10581 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10582 gdb_byte
*info_ptr
)
10584 attr
->name
= abbrev
->name
;
10585 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
10588 /* Read dwarf information from a buffer. */
10590 static unsigned int
10591 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10593 return bfd_get_8 (abfd
, buf
);
10597 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10599 return bfd_get_signed_8 (abfd
, buf
);
10602 static unsigned int
10603 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10605 return bfd_get_16 (abfd
, buf
);
10609 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10611 return bfd_get_signed_16 (abfd
, buf
);
10614 static unsigned int
10615 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10617 return bfd_get_32 (abfd
, buf
);
10621 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10623 return bfd_get_signed_32 (abfd
, buf
);
10627 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10629 return bfd_get_64 (abfd
, buf
);
10633 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10634 unsigned int *bytes_read
)
10636 struct comp_unit_head
*cu_header
= &cu
->header
;
10637 CORE_ADDR retval
= 0;
10639 if (cu_header
->signed_addr_p
)
10641 switch (cu_header
->addr_size
)
10644 retval
= bfd_get_signed_16 (abfd
, buf
);
10647 retval
= bfd_get_signed_32 (abfd
, buf
);
10650 retval
= bfd_get_signed_64 (abfd
, buf
);
10653 internal_error (__FILE__
, __LINE__
,
10654 _("read_address: bad switch, signed [in module %s]"),
10655 bfd_get_filename (abfd
));
10660 switch (cu_header
->addr_size
)
10663 retval
= bfd_get_16 (abfd
, buf
);
10666 retval
= bfd_get_32 (abfd
, buf
);
10669 retval
= bfd_get_64 (abfd
, buf
);
10672 internal_error (__FILE__
, __LINE__
,
10673 _("read_address: bad switch, "
10674 "unsigned [in module %s]"),
10675 bfd_get_filename (abfd
));
10679 *bytes_read
= cu_header
->addr_size
;
10683 /* Read the initial length from a section. The (draft) DWARF 3
10684 specification allows the initial length to take up either 4 bytes
10685 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10686 bytes describe the length and all offsets will be 8 bytes in length
10689 An older, non-standard 64-bit format is also handled by this
10690 function. The older format in question stores the initial length
10691 as an 8-byte quantity without an escape value. Lengths greater
10692 than 2^32 aren't very common which means that the initial 4 bytes
10693 is almost always zero. Since a length value of zero doesn't make
10694 sense for the 32-bit format, this initial zero can be considered to
10695 be an escape value which indicates the presence of the older 64-bit
10696 format. As written, the code can't detect (old format) lengths
10697 greater than 4GB. If it becomes necessary to handle lengths
10698 somewhat larger than 4GB, we could allow other small values (such
10699 as the non-sensical values of 1, 2, and 3) to also be used as
10700 escape values indicating the presence of the old format.
10702 The value returned via bytes_read should be used to increment the
10703 relevant pointer after calling read_initial_length().
10705 [ Note: read_initial_length() and read_offset() are based on the
10706 document entitled "DWARF Debugging Information Format", revision
10707 3, draft 8, dated November 19, 2001. This document was obtained
10710 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10712 This document is only a draft and is subject to change. (So beware.)
10714 Details regarding the older, non-standard 64-bit format were
10715 determined empirically by examining 64-bit ELF files produced by
10716 the SGI toolchain on an IRIX 6.5 machine.
10718 - Kevin, July 16, 2002
10722 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10724 LONGEST length
= bfd_get_32 (abfd
, buf
);
10726 if (length
== 0xffffffff)
10728 length
= bfd_get_64 (abfd
, buf
+ 4);
10731 else if (length
== 0)
10733 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10734 length
= bfd_get_64 (abfd
, buf
);
10745 /* Cover function for read_initial_length.
10746 Returns the length of the object at BUF, and stores the size of the
10747 initial length in *BYTES_READ and stores the size that offsets will be in
10749 If the initial length size is not equivalent to that specified in
10750 CU_HEADER then issue a complaint.
10751 This is useful when reading non-comp-unit headers. */
10754 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10755 const struct comp_unit_head
*cu_header
,
10756 unsigned int *bytes_read
,
10757 unsigned int *offset_size
)
10759 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10761 gdb_assert (cu_header
->initial_length_size
== 4
10762 || cu_header
->initial_length_size
== 8
10763 || cu_header
->initial_length_size
== 12);
10765 if (cu_header
->initial_length_size
!= *bytes_read
)
10766 complaint (&symfile_complaints
,
10767 _("intermixed 32-bit and 64-bit DWARF sections"));
10769 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10773 /* Read an offset from the data stream. The size of the offset is
10774 given by cu_header->offset_size. */
10777 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10778 unsigned int *bytes_read
)
10780 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10782 *bytes_read
= cu_header
->offset_size
;
10786 /* Read an offset from the data stream. */
10789 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10791 LONGEST retval
= 0;
10793 switch (offset_size
)
10796 retval
= bfd_get_32 (abfd
, buf
);
10799 retval
= bfd_get_64 (abfd
, buf
);
10802 internal_error (__FILE__
, __LINE__
,
10803 _("read_offset_1: bad switch [in module %s]"),
10804 bfd_get_filename (abfd
));
10811 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10813 /* If the size of a host char is 8 bits, we can return a pointer
10814 to the buffer, otherwise we have to copy the data to a buffer
10815 allocated on the temporary obstack. */
10816 gdb_assert (HOST_CHAR_BIT
== 8);
10821 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10823 /* If the size of a host char is 8 bits, we can return a pointer
10824 to the string, otherwise we have to copy the string to a buffer
10825 allocated on the temporary obstack. */
10826 gdb_assert (HOST_CHAR_BIT
== 8);
10829 *bytes_read_ptr
= 1;
10832 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10833 return (char *) buf
;
10837 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
10839 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10840 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10841 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10842 bfd_get_filename (abfd
));
10843 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10844 error (_("DW_FORM_strp pointing outside of "
10845 ".debug_str section [in module %s]"),
10846 bfd_get_filename (abfd
));
10847 gdb_assert (HOST_CHAR_BIT
== 8);
10848 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10850 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10854 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10855 const struct comp_unit_head
*cu_header
,
10856 unsigned int *bytes_read_ptr
)
10858 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10860 return read_indirect_string_at_offset (abfd
, str_offset
);
10864 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10867 unsigned int num_read
;
10869 unsigned char byte
;
10877 byte
= bfd_get_8 (abfd
, buf
);
10880 result
|= ((ULONGEST
) (byte
& 127) << shift
);
10881 if ((byte
& 128) == 0)
10887 *bytes_read_ptr
= num_read
;
10892 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10895 int i
, shift
, num_read
;
10896 unsigned char byte
;
10904 byte
= bfd_get_8 (abfd
, buf
);
10907 result
|= ((LONGEST
) (byte
& 127) << shift
);
10909 if ((byte
& 128) == 0)
10914 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10915 result
|= -(((LONGEST
) 1) << shift
);
10916 *bytes_read_ptr
= num_read
;
10920 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10923 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10929 byte
= bfd_get_8 (abfd
, buf
);
10931 if ((byte
& 128) == 0)
10937 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10944 cu
->language
= language_c
;
10946 case DW_LANG_C_plus_plus
:
10947 cu
->language
= language_cplus
;
10950 cu
->language
= language_d
;
10952 case DW_LANG_Fortran77
:
10953 case DW_LANG_Fortran90
:
10954 case DW_LANG_Fortran95
:
10955 cu
->language
= language_fortran
;
10958 cu
->language
= language_go
;
10960 case DW_LANG_Mips_Assembler
:
10961 cu
->language
= language_asm
;
10964 cu
->language
= language_java
;
10966 case DW_LANG_Ada83
:
10967 case DW_LANG_Ada95
:
10968 cu
->language
= language_ada
;
10970 case DW_LANG_Modula2
:
10971 cu
->language
= language_m2
;
10973 case DW_LANG_Pascal83
:
10974 cu
->language
= language_pascal
;
10977 cu
->language
= language_objc
;
10979 case DW_LANG_Cobol74
:
10980 case DW_LANG_Cobol85
:
10982 cu
->language
= language_minimal
;
10985 cu
->language_defn
= language_def (cu
->language
);
10988 /* Return the named attribute or NULL if not there. */
10990 static struct attribute
*
10991 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10996 struct attribute
*spec
= NULL
;
10998 for (i
= 0; i
< die
->num_attrs
; ++i
)
11000 if (die
->attrs
[i
].name
== name
)
11001 return &die
->attrs
[i
];
11002 if (die
->attrs
[i
].name
== DW_AT_specification
11003 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
11004 spec
= &die
->attrs
[i
];
11010 die
= follow_die_ref (die
, spec
, &cu
);
11016 /* Return the named attribute or NULL if not there,
11017 but do not follow DW_AT_specification, etc.
11018 This is for use in contexts where we're reading .debug_types dies.
11019 Following DW_AT_specification, DW_AT_abstract_origin will take us
11020 back up the chain, and we want to go down. */
11022 static struct attribute
*
11023 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
11024 struct dwarf2_cu
*cu
)
11028 for (i
= 0; i
< die
->num_attrs
; ++i
)
11029 if (die
->attrs
[i
].name
== name
)
11030 return &die
->attrs
[i
];
11035 /* Return non-zero iff the attribute NAME is defined for the given DIE,
11036 and holds a non-zero value. This function should only be used for
11037 DW_FORM_flag or DW_FORM_flag_present attributes. */
11040 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
11042 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
11044 return (attr
&& DW_UNSND (attr
));
11048 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
11050 /* A DIE is a declaration if it has a DW_AT_declaration attribute
11051 which value is non-zero. However, we have to be careful with
11052 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
11053 (via dwarf2_flag_true_p) follows this attribute. So we may
11054 end up accidently finding a declaration attribute that belongs
11055 to a different DIE referenced by the specification attribute,
11056 even though the given DIE does not have a declaration attribute. */
11057 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
11058 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
11061 /* Return the die giving the specification for DIE, if there is
11062 one. *SPEC_CU is the CU containing DIE on input, and the CU
11063 containing the return value on output. If there is no
11064 specification, but there is an abstract origin, that is
11067 static struct die_info
*
11068 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
11070 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
11073 if (spec_attr
== NULL
)
11074 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
11076 if (spec_attr
== NULL
)
11079 return follow_die_ref (die
, spec_attr
, spec_cu
);
11082 /* Free the line_header structure *LH, and any arrays and strings it
11084 NOTE: This is also used as a "cleanup" function. */
11087 free_line_header (struct line_header
*lh
)
11089 if (lh
->standard_opcode_lengths
)
11090 xfree (lh
->standard_opcode_lengths
);
11092 /* Remember that all the lh->file_names[i].name pointers are
11093 pointers into debug_line_buffer, and don't need to be freed. */
11094 if (lh
->file_names
)
11095 xfree (lh
->file_names
);
11097 /* Similarly for the include directory names. */
11098 if (lh
->include_dirs
)
11099 xfree (lh
->include_dirs
);
11104 /* Add an entry to LH's include directory table. */
11107 add_include_dir (struct line_header
*lh
, char *include_dir
)
11109 /* Grow the array if necessary. */
11110 if (lh
->include_dirs_size
== 0)
11112 lh
->include_dirs_size
= 1; /* for testing */
11113 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
11114 * sizeof (*lh
->include_dirs
));
11116 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
11118 lh
->include_dirs_size
*= 2;
11119 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
11120 (lh
->include_dirs_size
11121 * sizeof (*lh
->include_dirs
)));
11124 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
11127 /* Add an entry to LH's file name table. */
11130 add_file_name (struct line_header
*lh
,
11132 unsigned int dir_index
,
11133 unsigned int mod_time
,
11134 unsigned int length
)
11136 struct file_entry
*fe
;
11138 /* Grow the array if necessary. */
11139 if (lh
->file_names_size
== 0)
11141 lh
->file_names_size
= 1; /* for testing */
11142 lh
->file_names
= xmalloc (lh
->file_names_size
11143 * sizeof (*lh
->file_names
));
11145 else if (lh
->num_file_names
>= lh
->file_names_size
)
11147 lh
->file_names_size
*= 2;
11148 lh
->file_names
= xrealloc (lh
->file_names
,
11149 (lh
->file_names_size
11150 * sizeof (*lh
->file_names
)));
11153 fe
= &lh
->file_names
[lh
->num_file_names
++];
11155 fe
->dir_index
= dir_index
;
11156 fe
->mod_time
= mod_time
;
11157 fe
->length
= length
;
11158 fe
->included_p
= 0;
11162 /* Read the statement program header starting at OFFSET in
11163 .debug_line, according to the endianness of ABFD. Return a pointer
11164 to a struct line_header, allocated using xmalloc.
11166 NOTE: the strings in the include directory and file name tables of
11167 the returned object point into debug_line_buffer, and must not be
11170 static struct line_header
*
11171 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
11172 struct dwarf2_cu
*cu
)
11174 struct cleanup
*back_to
;
11175 struct line_header
*lh
;
11176 gdb_byte
*line_ptr
;
11177 unsigned int bytes_read
, offset_size
;
11179 char *cur_dir
, *cur_file
;
11181 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
11182 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
11184 complaint (&symfile_complaints
, _("missing .debug_line section"));
11188 /* Make sure that at least there's room for the total_length field.
11189 That could be 12 bytes long, but we're just going to fudge that. */
11190 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
11192 dwarf2_statement_list_fits_in_line_number_section_complaint ();
11196 lh
= xmalloc (sizeof (*lh
));
11197 memset (lh
, 0, sizeof (*lh
));
11198 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
11201 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
11203 /* Read in the header. */
11205 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
11206 &bytes_read
, &offset_size
);
11207 line_ptr
+= bytes_read
;
11208 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
11209 + dwarf2_per_objfile
->line
.size
))
11211 dwarf2_statement_list_fits_in_line_number_section_complaint ();
11214 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
11215 lh
->version
= read_2_bytes (abfd
, line_ptr
);
11217 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
11218 line_ptr
+= offset_size
;
11219 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
11221 if (lh
->version
>= 4)
11223 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
11227 lh
->maximum_ops_per_instruction
= 1;
11229 if (lh
->maximum_ops_per_instruction
== 0)
11231 lh
->maximum_ops_per_instruction
= 1;
11232 complaint (&symfile_complaints
,
11233 _("invalid maximum_ops_per_instruction "
11234 "in `.debug_line' section"));
11237 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
11239 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
11241 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
11243 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
11245 lh
->standard_opcode_lengths
11246 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
11248 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
11249 for (i
= 1; i
< lh
->opcode_base
; ++i
)
11251 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
11255 /* Read directory table. */
11256 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11258 line_ptr
+= bytes_read
;
11259 add_include_dir (lh
, cur_dir
);
11261 line_ptr
+= bytes_read
;
11263 /* Read file name table. */
11264 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11266 unsigned int dir_index
, mod_time
, length
;
11268 line_ptr
+= bytes_read
;
11269 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11270 line_ptr
+= bytes_read
;
11271 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11272 line_ptr
+= bytes_read
;
11273 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11274 line_ptr
+= bytes_read
;
11276 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11278 line_ptr
+= bytes_read
;
11279 lh
->statement_program_start
= line_ptr
;
11281 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
11282 + dwarf2_per_objfile
->line
.size
))
11283 complaint (&symfile_complaints
,
11284 _("line number info header doesn't "
11285 "fit in `.debug_line' section"));
11287 discard_cleanups (back_to
);
11291 /* Subroutine of dwarf_decode_lines to simplify it.
11292 Return the file name of the psymtab for included file FILE_INDEX
11293 in line header LH of PST.
11294 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11295 If space for the result is malloc'd, it will be freed by a cleanup.
11296 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
11299 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
11300 const struct partial_symtab
*pst
,
11301 const char *comp_dir
)
11303 const struct file_entry fe
= lh
->file_names
[file_index
];
11304 char *include_name
= fe
.name
;
11305 char *include_name_to_compare
= include_name
;
11306 char *dir_name
= NULL
;
11307 const char *pst_filename
;
11308 char *copied_name
= NULL
;
11312 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
11314 if (!IS_ABSOLUTE_PATH (include_name
)
11315 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
11317 /* Avoid creating a duplicate psymtab for PST.
11318 We do this by comparing INCLUDE_NAME and PST_FILENAME.
11319 Before we do the comparison, however, we need to account
11320 for DIR_NAME and COMP_DIR.
11321 First prepend dir_name (if non-NULL). If we still don't
11322 have an absolute path prepend comp_dir (if non-NULL).
11323 However, the directory we record in the include-file's
11324 psymtab does not contain COMP_DIR (to match the
11325 corresponding symtab(s)).
11330 bash$ gcc -g ./hello.c
11331 include_name = "hello.c"
11333 DW_AT_comp_dir = comp_dir = "/tmp"
11334 DW_AT_name = "./hello.c" */
11336 if (dir_name
!= NULL
)
11338 include_name
= concat (dir_name
, SLASH_STRING
,
11339 include_name
, (char *)NULL
);
11340 include_name_to_compare
= include_name
;
11341 make_cleanup (xfree
, include_name
);
11343 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
11345 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
11346 include_name
, (char *)NULL
);
11350 pst_filename
= pst
->filename
;
11351 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
11353 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
11354 pst_filename
, (char *)NULL
);
11355 pst_filename
= copied_name
;
11358 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
11360 if (include_name_to_compare
!= include_name
)
11361 xfree (include_name_to_compare
);
11362 if (copied_name
!= NULL
)
11363 xfree (copied_name
);
11367 return include_name
;
11370 /* Ignore this record_line request. */
11373 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11378 /* Subroutine of dwarf_decode_lines to simplify it.
11379 Process the line number information in LH. */
11382 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
11383 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
11385 gdb_byte
*line_ptr
, *extended_end
;
11386 gdb_byte
*line_end
;
11387 unsigned int bytes_read
, extended_len
;
11388 unsigned char op_code
, extended_op
, adj_opcode
;
11389 CORE_ADDR baseaddr
;
11390 struct objfile
*objfile
= cu
->objfile
;
11391 bfd
*abfd
= objfile
->obfd
;
11392 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11393 const int decode_for_pst_p
= (pst
!= NULL
);
11394 struct subfile
*last_subfile
= NULL
;
11395 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11398 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11400 line_ptr
= lh
->statement_program_start
;
11401 line_end
= lh
->statement_program_end
;
11403 /* Read the statement sequences until there's nothing left. */
11404 while (line_ptr
< line_end
)
11406 /* state machine registers */
11407 CORE_ADDR address
= 0;
11408 unsigned int file
= 1;
11409 unsigned int line
= 1;
11410 unsigned int column
= 0;
11411 int is_stmt
= lh
->default_is_stmt
;
11412 int basic_block
= 0;
11413 int end_sequence
= 0;
11415 unsigned char op_index
= 0;
11417 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
11419 /* Start a subfile for the current file of the state machine. */
11420 /* lh->include_dirs and lh->file_names are 0-based, but the
11421 directory and file name numbers in the statement program
11423 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11427 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11429 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11432 /* Decode the table. */
11433 while (!end_sequence
)
11435 op_code
= read_1_byte (abfd
, line_ptr
);
11437 if (line_ptr
> line_end
)
11439 dwarf2_debug_line_missing_end_sequence_complaint ();
11443 if (op_code
>= lh
->opcode_base
)
11445 /* Special operand. */
11446 adj_opcode
= op_code
- lh
->opcode_base
;
11447 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
11448 / lh
->maximum_ops_per_instruction
)
11449 * lh
->minimum_instruction_length
);
11450 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
11451 % lh
->maximum_ops_per_instruction
);
11452 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
11453 if (lh
->num_file_names
< file
|| file
== 0)
11454 dwarf2_debug_line_missing_file_complaint ();
11455 /* For now we ignore lines not starting on an
11456 instruction boundary. */
11457 else if (op_index
== 0)
11459 lh
->file_names
[file
- 1].included_p
= 1;
11460 if (!decode_for_pst_p
&& is_stmt
)
11462 if (last_subfile
!= current_subfile
)
11464 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11466 (*p_record_line
) (last_subfile
, 0, addr
);
11467 last_subfile
= current_subfile
;
11469 /* Append row to matrix using current values. */
11470 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11471 (*p_record_line
) (current_subfile
, line
, addr
);
11476 else switch (op_code
)
11478 case DW_LNS_extended_op
:
11479 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
11481 line_ptr
+= bytes_read
;
11482 extended_end
= line_ptr
+ extended_len
;
11483 extended_op
= read_1_byte (abfd
, line_ptr
);
11485 switch (extended_op
)
11487 case DW_LNE_end_sequence
:
11488 p_record_line
= record_line
;
11491 case DW_LNE_set_address
:
11492 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
11494 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11496 /* This line table is for a function which has been
11497 GCd by the linker. Ignore it. PR gdb/12528 */
11500 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
11502 complaint (&symfile_complaints
,
11503 _(".debug_line address at offset 0x%lx is 0 "
11505 line_offset
, objfile
->name
);
11506 p_record_line
= noop_record_line
;
11510 line_ptr
+= bytes_read
;
11511 address
+= baseaddr
;
11513 case DW_LNE_define_file
:
11516 unsigned int dir_index
, mod_time
, length
;
11518 cur_file
= read_direct_string (abfd
, line_ptr
,
11520 line_ptr
+= bytes_read
;
11522 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11523 line_ptr
+= bytes_read
;
11525 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11526 line_ptr
+= bytes_read
;
11528 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11529 line_ptr
+= bytes_read
;
11530 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11533 case DW_LNE_set_discriminator
:
11534 /* The discriminator is not interesting to the debugger;
11536 line_ptr
= extended_end
;
11539 complaint (&symfile_complaints
,
11540 _("mangled .debug_line section"));
11543 /* Make sure that we parsed the extended op correctly. If e.g.
11544 we expected a different address size than the producer used,
11545 we may have read the wrong number of bytes. */
11546 if (line_ptr
!= extended_end
)
11548 complaint (&symfile_complaints
,
11549 _("mangled .debug_line section"));
11554 if (lh
->num_file_names
< file
|| file
== 0)
11555 dwarf2_debug_line_missing_file_complaint ();
11558 lh
->file_names
[file
- 1].included_p
= 1;
11559 if (!decode_for_pst_p
&& is_stmt
)
11561 if (last_subfile
!= current_subfile
)
11563 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11565 (*p_record_line
) (last_subfile
, 0, addr
);
11566 last_subfile
= current_subfile
;
11568 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11569 (*p_record_line
) (current_subfile
, line
, addr
);
11574 case DW_LNS_advance_pc
:
11577 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11579 address
+= (((op_index
+ adjust
)
11580 / lh
->maximum_ops_per_instruction
)
11581 * lh
->minimum_instruction_length
);
11582 op_index
= ((op_index
+ adjust
)
11583 % lh
->maximum_ops_per_instruction
);
11584 line_ptr
+= bytes_read
;
11587 case DW_LNS_advance_line
:
11588 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11589 line_ptr
+= bytes_read
;
11591 case DW_LNS_set_file
:
11593 /* The arrays lh->include_dirs and lh->file_names are
11594 0-based, but the directory and file name numbers in
11595 the statement program are 1-based. */
11596 struct file_entry
*fe
;
11599 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11600 line_ptr
+= bytes_read
;
11601 if (lh
->num_file_names
< file
|| file
== 0)
11602 dwarf2_debug_line_missing_file_complaint ();
11605 fe
= &lh
->file_names
[file
- 1];
11607 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11608 if (!decode_for_pst_p
)
11610 last_subfile
= current_subfile
;
11611 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11616 case DW_LNS_set_column
:
11617 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11618 line_ptr
+= bytes_read
;
11620 case DW_LNS_negate_stmt
:
11621 is_stmt
= (!is_stmt
);
11623 case DW_LNS_set_basic_block
:
11626 /* Add to the address register of the state machine the
11627 address increment value corresponding to special opcode
11628 255. I.e., this value is scaled by the minimum
11629 instruction length since special opcode 255 would have
11630 scaled the increment. */
11631 case DW_LNS_const_add_pc
:
11633 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11635 address
+= (((op_index
+ adjust
)
11636 / lh
->maximum_ops_per_instruction
)
11637 * lh
->minimum_instruction_length
);
11638 op_index
= ((op_index
+ adjust
)
11639 % lh
->maximum_ops_per_instruction
);
11642 case DW_LNS_fixed_advance_pc
:
11643 address
+= read_2_bytes (abfd
, line_ptr
);
11649 /* Unknown standard opcode, ignore it. */
11652 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11654 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11655 line_ptr
+= bytes_read
;
11660 if (lh
->num_file_names
< file
|| file
== 0)
11661 dwarf2_debug_line_missing_file_complaint ();
11664 lh
->file_names
[file
- 1].included_p
= 1;
11665 if (!decode_for_pst_p
)
11667 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11668 (*p_record_line
) (current_subfile
, 0, addr
);
11674 /* Decode the Line Number Program (LNP) for the given line_header
11675 structure and CU. The actual information extracted and the type
11676 of structures created from the LNP depends on the value of PST.
11678 1. If PST is NULL, then this procedure uses the data from the program
11679 to create all necessary symbol tables, and their linetables.
11681 2. If PST is not NULL, this procedure reads the program to determine
11682 the list of files included by the unit represented by PST, and
11683 builds all the associated partial symbol tables.
11685 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11686 It is used for relative paths in the line table.
11687 NOTE: When processing partial symtabs (pst != NULL),
11688 comp_dir == pst->dirname.
11690 NOTE: It is important that psymtabs have the same file name (via strcmp)
11691 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11692 symtab we don't use it in the name of the psymtabs we create.
11693 E.g. expand_line_sal requires this when finding psymtabs to expand.
11694 A good testcase for this is mb-inline.exp. */
11697 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
11698 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
11699 int want_line_info
)
11701 struct objfile
*objfile
= cu
->objfile
;
11702 const int decode_for_pst_p
= (pst
!= NULL
);
11703 struct subfile
*first_subfile
= current_subfile
;
11705 if (want_line_info
)
11706 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
11708 if (decode_for_pst_p
)
11712 /* Now that we're done scanning the Line Header Program, we can
11713 create the psymtab of each included file. */
11714 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11715 if (lh
->file_names
[file_index
].included_p
== 1)
11717 char *include_name
=
11718 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11719 if (include_name
!= NULL
)
11720 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11725 /* Make sure a symtab is created for every file, even files
11726 which contain only variables (i.e. no code with associated
11730 for (i
= 0; i
< lh
->num_file_names
; i
++)
11733 struct file_entry
*fe
;
11735 fe
= &lh
->file_names
[i
];
11737 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11738 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11740 /* Skip the main file; we don't need it, and it must be
11741 allocated last, so that it will show up before the
11742 non-primary symtabs in the objfile's symtab list. */
11743 if (current_subfile
== first_subfile
)
11746 if (current_subfile
->symtab
== NULL
)
11747 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11749 fe
->symtab
= current_subfile
->symtab
;
11754 /* Start a subfile for DWARF. FILENAME is the name of the file and
11755 DIRNAME the name of the source directory which contains FILENAME
11756 or NULL if not known. COMP_DIR is the compilation directory for the
11757 linetable's compilation unit or NULL if not known.
11758 This routine tries to keep line numbers from identical absolute and
11759 relative file names in a common subfile.
11761 Using the `list' example from the GDB testsuite, which resides in
11762 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11763 of /srcdir/list0.c yields the following debugging information for list0.c:
11765 DW_AT_name: /srcdir/list0.c
11766 DW_AT_comp_dir: /compdir
11767 files.files[0].name: list0.h
11768 files.files[0].dir: /srcdir
11769 files.files[1].name: list0.c
11770 files.files[1].dir: /srcdir
11772 The line number information for list0.c has to end up in a single
11773 subfile, so that `break /srcdir/list0.c:1' works as expected.
11774 start_subfile will ensure that this happens provided that we pass the
11775 concatenation of files.files[1].dir and files.files[1].name as the
11779 dwarf2_start_subfile (char *filename
, const char *dirname
,
11780 const char *comp_dir
)
11784 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11785 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11786 second argument to start_subfile. To be consistent, we do the
11787 same here. In order not to lose the line information directory,
11788 we concatenate it to the filename when it makes sense.
11789 Note that the Dwarf3 standard says (speaking of filenames in line
11790 information): ``The directory index is ignored for file names
11791 that represent full path names''. Thus ignoring dirname in the
11792 `else' branch below isn't an issue. */
11794 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11795 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11797 fullname
= filename
;
11799 start_subfile (fullname
, comp_dir
);
11801 if (fullname
!= filename
)
11806 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11807 struct dwarf2_cu
*cu
)
11809 struct objfile
*objfile
= cu
->objfile
;
11810 struct comp_unit_head
*cu_header
= &cu
->header
;
11812 /* NOTE drow/2003-01-30: There used to be a comment and some special
11813 code here to turn a symbol with DW_AT_external and a
11814 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11815 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11816 with some versions of binutils) where shared libraries could have
11817 relocations against symbols in their debug information - the
11818 minimal symbol would have the right address, but the debug info
11819 would not. It's no longer necessary, because we will explicitly
11820 apply relocations when we read in the debug information now. */
11822 /* A DW_AT_location attribute with no contents indicates that a
11823 variable has been optimized away. */
11824 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11826 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11830 /* Handle one degenerate form of location expression specially, to
11831 preserve GDB's previous behavior when section offsets are
11832 specified. If this is just a DW_OP_addr then mark this symbol
11835 if (attr_form_is_block (attr
)
11836 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11837 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11839 unsigned int dummy
;
11841 SYMBOL_VALUE_ADDRESS (sym
) =
11842 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11843 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11844 fixup_symbol_section (sym
, objfile
);
11845 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11846 SYMBOL_SECTION (sym
));
11850 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11851 expression evaluator, and use LOC_COMPUTED only when necessary
11852 (i.e. when the value of a register or memory location is
11853 referenced, or a thread-local block, etc.). Then again, it might
11854 not be worthwhile. I'm assuming that it isn't unless performance
11855 or memory numbers show me otherwise. */
11857 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11858 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11860 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11861 cu
->has_loclist
= 1;
11864 /* Given a pointer to a DWARF information entry, figure out if we need
11865 to make a symbol table entry for it, and if so, create a new entry
11866 and return a pointer to it.
11867 If TYPE is NULL, determine symbol type from the die, otherwise
11868 used the passed type.
11869 If SPACE is not NULL, use it to hold the new symbol. If it is
11870 NULL, allocate a new symbol on the objfile's obstack. */
11872 static struct symbol
*
11873 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11874 struct symbol
*space
)
11876 struct objfile
*objfile
= cu
->objfile
;
11877 struct symbol
*sym
= NULL
;
11879 struct attribute
*attr
= NULL
;
11880 struct attribute
*attr2
= NULL
;
11881 CORE_ADDR baseaddr
;
11882 struct pending
**list_to_add
= NULL
;
11884 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11886 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11888 name
= dwarf2_name (die
, cu
);
11891 const char *linkagename
;
11892 int suppress_add
= 0;
11897 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11898 OBJSTAT (objfile
, n_syms
++);
11900 /* Cache this symbol's name and the name's demangled form (if any). */
11901 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11902 linkagename
= dwarf2_physname (name
, die
, cu
);
11903 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11905 /* Fortran does not have mangling standard and the mangling does differ
11906 between gfortran, iFort etc. */
11907 if (cu
->language
== language_fortran
11908 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11909 symbol_set_demangled_name (&(sym
->ginfo
),
11910 (char *) dwarf2_full_name (name
, die
, cu
),
11913 /* Default assumptions.
11914 Use the passed type or decode it from the die. */
11915 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11916 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11918 SYMBOL_TYPE (sym
) = type
;
11920 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11921 attr
= dwarf2_attr (die
,
11922 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11926 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11929 attr
= dwarf2_attr (die
,
11930 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11934 int file_index
= DW_UNSND (attr
);
11936 if (cu
->line_header
== NULL
11937 || file_index
> cu
->line_header
->num_file_names
)
11938 complaint (&symfile_complaints
,
11939 _("file index out of range"));
11940 else if (file_index
> 0)
11942 struct file_entry
*fe
;
11944 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11945 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11952 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11955 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11957 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11958 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11959 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11960 add_symbol_to_list (sym
, cu
->list_in_scope
);
11962 case DW_TAG_subprogram
:
11963 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11965 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11966 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11967 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11968 || cu
->language
== language_ada
)
11970 /* Subprograms marked external are stored as a global symbol.
11971 Ada subprograms, whether marked external or not, are always
11972 stored as a global symbol, because we want to be able to
11973 access them globally. For instance, we want to be able
11974 to break on a nested subprogram without having to
11975 specify the context. */
11976 list_to_add
= &global_symbols
;
11980 list_to_add
= cu
->list_in_scope
;
11983 case DW_TAG_inlined_subroutine
:
11984 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11986 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11987 SYMBOL_INLINED (sym
) = 1;
11988 list_to_add
= cu
->list_in_scope
;
11990 case DW_TAG_template_value_param
:
11992 /* Fall through. */
11993 case DW_TAG_constant
:
11994 case DW_TAG_variable
:
11995 case DW_TAG_member
:
11996 /* Compilation with minimal debug info may result in
11997 variables with missing type entries. Change the
11998 misleading `void' type to something sensible. */
11999 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
12001 = objfile_type (objfile
)->nodebug_data_symbol
;
12003 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12004 /* In the case of DW_TAG_member, we should only be called for
12005 static const members. */
12006 if (die
->tag
== DW_TAG_member
)
12008 /* dwarf2_add_field uses die_is_declaration,
12009 so we do the same. */
12010 gdb_assert (die_is_declaration (die
, cu
));
12015 dwarf2_const_value (attr
, sym
, cu
);
12016 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
12019 if (attr2
&& (DW_UNSND (attr2
) != 0))
12020 list_to_add
= &global_symbols
;
12022 list_to_add
= cu
->list_in_scope
;
12026 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
12029 var_decode_location (attr
, sym
, cu
);
12030 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
12031 if (SYMBOL_CLASS (sym
) == LOC_STATIC
12032 && SYMBOL_VALUE_ADDRESS (sym
) == 0
12033 && !dwarf2_per_objfile
->has_section_at_zero
)
12035 /* When a static variable is eliminated by the linker,
12036 the corresponding debug information is not stripped
12037 out, but the variable address is set to null;
12038 do not add such variables into symbol table. */
12040 else if (attr2
&& (DW_UNSND (attr2
) != 0))
12042 /* Workaround gfortran PR debug/40040 - it uses
12043 DW_AT_location for variables in -fPIC libraries which may
12044 get overriden by other libraries/executable and get
12045 a different address. Resolve it by the minimal symbol
12046 which may come from inferior's executable using copy
12047 relocation. Make this workaround only for gfortran as for
12048 other compilers GDB cannot guess the minimal symbol
12049 Fortran mangling kind. */
12050 if (cu
->language
== language_fortran
&& die
->parent
12051 && die
->parent
->tag
== DW_TAG_module
12053 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
12054 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
12056 /* A variable with DW_AT_external is never static,
12057 but it may be block-scoped. */
12058 list_to_add
= (cu
->list_in_scope
== &file_symbols
12059 ? &global_symbols
: cu
->list_in_scope
);
12062 list_to_add
= cu
->list_in_scope
;
12066 /* We do not know the address of this symbol.
12067 If it is an external symbol and we have type information
12068 for it, enter the symbol as a LOC_UNRESOLVED symbol.
12069 The address of the variable will then be determined from
12070 the minimal symbol table whenever the variable is
12072 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
12073 if (attr2
&& (DW_UNSND (attr2
) != 0)
12074 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
12076 /* A variable with DW_AT_external is never static, but it
12077 may be block-scoped. */
12078 list_to_add
= (cu
->list_in_scope
== &file_symbols
12079 ? &global_symbols
: cu
->list_in_scope
);
12081 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
12083 else if (!die_is_declaration (die
, cu
))
12085 /* Use the default LOC_OPTIMIZED_OUT class. */
12086 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
12088 list_to_add
= cu
->list_in_scope
;
12092 case DW_TAG_formal_parameter
:
12093 /* If we are inside a function, mark this as an argument. If
12094 not, we might be looking at an argument to an inlined function
12095 when we do not have enough information to show inlined frames;
12096 pretend it's a local variable in that case so that the user can
12098 if (context_stack_depth
> 0
12099 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
12100 SYMBOL_IS_ARGUMENT (sym
) = 1;
12101 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
12104 var_decode_location (attr
, sym
, cu
);
12106 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12109 dwarf2_const_value (attr
, sym
, cu
);
12112 list_to_add
= cu
->list_in_scope
;
12114 case DW_TAG_unspecified_parameters
:
12115 /* From varargs functions; gdb doesn't seem to have any
12116 interest in this information, so just ignore it for now.
12119 case DW_TAG_template_type_param
:
12121 /* Fall through. */
12122 case DW_TAG_class_type
:
12123 case DW_TAG_interface_type
:
12124 case DW_TAG_structure_type
:
12125 case DW_TAG_union_type
:
12126 case DW_TAG_set_type
:
12127 case DW_TAG_enumeration_type
:
12128 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
12129 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
12132 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
12133 really ever be static objects: otherwise, if you try
12134 to, say, break of a class's method and you're in a file
12135 which doesn't mention that class, it won't work unless
12136 the check for all static symbols in lookup_symbol_aux
12137 saves you. See the OtherFileClass tests in
12138 gdb.c++/namespace.exp. */
12142 list_to_add
= (cu
->list_in_scope
== &file_symbols
12143 && (cu
->language
== language_cplus
12144 || cu
->language
== language_java
)
12145 ? &global_symbols
: cu
->list_in_scope
);
12147 /* The semantics of C++ state that "struct foo {
12148 ... }" also defines a typedef for "foo". A Java
12149 class declaration also defines a typedef for the
12151 if (cu
->language
== language_cplus
12152 || cu
->language
== language_java
12153 || cu
->language
== language_ada
)
12155 /* The symbol's name is already allocated along
12156 with this objfile, so we don't need to
12157 duplicate it for the type. */
12158 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
12159 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
12164 case DW_TAG_typedef
:
12165 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
12166 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
12167 list_to_add
= cu
->list_in_scope
;
12169 case DW_TAG_base_type
:
12170 case DW_TAG_subrange_type
:
12171 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
12172 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
12173 list_to_add
= cu
->list_in_scope
;
12175 case DW_TAG_enumerator
:
12176 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12179 dwarf2_const_value (attr
, sym
, cu
);
12182 /* NOTE: carlton/2003-11-10: See comment above in the
12183 DW_TAG_class_type, etc. block. */
12185 list_to_add
= (cu
->list_in_scope
== &file_symbols
12186 && (cu
->language
== language_cplus
12187 || cu
->language
== language_java
)
12188 ? &global_symbols
: cu
->list_in_scope
);
12191 case DW_TAG_namespace
:
12192 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
12193 list_to_add
= &global_symbols
;
12196 /* Not a tag we recognize. Hopefully we aren't processing
12197 trash data, but since we must specifically ignore things
12198 we don't recognize, there is nothing else we should do at
12200 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
12201 dwarf_tag_name (die
->tag
));
12207 sym
->hash_next
= objfile
->template_symbols
;
12208 objfile
->template_symbols
= sym
;
12209 list_to_add
= NULL
;
12212 if (list_to_add
!= NULL
)
12213 add_symbol_to_list (sym
, list_to_add
);
12215 /* For the benefit of old versions of GCC, check for anonymous
12216 namespaces based on the demangled name. */
12217 if (!processing_has_namespace_info
12218 && cu
->language
== language_cplus
)
12219 cp_scan_for_anonymous_namespaces (sym
, objfile
);
12224 /* A wrapper for new_symbol_full that always allocates a new symbol. */
12226 static struct symbol
*
12227 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
12229 return new_symbol_full (die
, type
, cu
, NULL
);
12232 /* Given an attr with a DW_FORM_dataN value in host byte order,
12233 zero-extend it as appropriate for the symbol's type. The DWARF
12234 standard (v4) is not entirely clear about the meaning of using
12235 DW_FORM_dataN for a constant with a signed type, where the type is
12236 wider than the data. The conclusion of a discussion on the DWARF
12237 list was that this is unspecified. We choose to always zero-extend
12238 because that is the interpretation long in use by GCC. */
12241 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
12242 const char *name
, struct obstack
*obstack
,
12243 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
12245 struct objfile
*objfile
= cu
->objfile
;
12246 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
12247 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
12248 LONGEST l
= DW_UNSND (attr
);
12250 if (bits
< sizeof (*value
) * 8)
12252 l
&= ((LONGEST
) 1 << bits
) - 1;
12255 else if (bits
== sizeof (*value
) * 8)
12259 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
12260 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
12267 /* Read a constant value from an attribute. Either set *VALUE, or if
12268 the value does not fit in *VALUE, set *BYTES - either already
12269 allocated on the objfile obstack, or newly allocated on OBSTACK,
12270 or, set *BATON, if we translated the constant to a location
12274 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
12275 const char *name
, struct obstack
*obstack
,
12276 struct dwarf2_cu
*cu
,
12277 LONGEST
*value
, gdb_byte
**bytes
,
12278 struct dwarf2_locexpr_baton
**baton
)
12280 struct objfile
*objfile
= cu
->objfile
;
12281 struct comp_unit_head
*cu_header
= &cu
->header
;
12282 struct dwarf_block
*blk
;
12283 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
12284 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
12290 switch (attr
->form
)
12296 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
12297 dwarf2_const_value_length_mismatch_complaint (name
,
12298 cu_header
->addr_size
,
12299 TYPE_LENGTH (type
));
12300 /* Symbols of this form are reasonably rare, so we just
12301 piggyback on the existing location code rather than writing
12302 a new implementation of symbol_computed_ops. */
12303 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
12304 sizeof (struct dwarf2_locexpr_baton
));
12305 (*baton
)->per_cu
= cu
->per_cu
;
12306 gdb_assert ((*baton
)->per_cu
);
12308 (*baton
)->size
= 2 + cu_header
->addr_size
;
12309 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
12310 (*baton
)->data
= data
;
12312 data
[0] = DW_OP_addr
;
12313 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
12314 byte_order
, DW_ADDR (attr
));
12315 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
12318 case DW_FORM_string
:
12320 /* DW_STRING is already allocated on the objfile obstack, point
12322 *bytes
= (gdb_byte
*) DW_STRING (attr
);
12324 case DW_FORM_block1
:
12325 case DW_FORM_block2
:
12326 case DW_FORM_block4
:
12327 case DW_FORM_block
:
12328 case DW_FORM_exprloc
:
12329 blk
= DW_BLOCK (attr
);
12330 if (TYPE_LENGTH (type
) != blk
->size
)
12331 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
12332 TYPE_LENGTH (type
));
12333 *bytes
= blk
->data
;
12336 /* The DW_AT_const_value attributes are supposed to carry the
12337 symbol's value "represented as it would be on the target
12338 architecture." By the time we get here, it's already been
12339 converted to host endianness, so we just need to sign- or
12340 zero-extend it as appropriate. */
12341 case DW_FORM_data1
:
12342 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12343 obstack
, cu
, value
, 8);
12345 case DW_FORM_data2
:
12346 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12347 obstack
, cu
, value
, 16);
12349 case DW_FORM_data4
:
12350 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12351 obstack
, cu
, value
, 32);
12353 case DW_FORM_data8
:
12354 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12355 obstack
, cu
, value
, 64);
12358 case DW_FORM_sdata
:
12359 *value
= DW_SND (attr
);
12362 case DW_FORM_udata
:
12363 *value
= DW_UNSND (attr
);
12367 complaint (&symfile_complaints
,
12368 _("unsupported const value attribute form: '%s'"),
12369 dwarf_form_name (attr
->form
));
12376 /* Copy constant value from an attribute to a symbol. */
12379 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
12380 struct dwarf2_cu
*cu
)
12382 struct objfile
*objfile
= cu
->objfile
;
12383 struct comp_unit_head
*cu_header
= &cu
->header
;
12386 struct dwarf2_locexpr_baton
*baton
;
12388 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
12389 SYMBOL_PRINT_NAME (sym
),
12390 &objfile
->objfile_obstack
, cu
,
12391 &value
, &bytes
, &baton
);
12395 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
12396 SYMBOL_LOCATION_BATON (sym
) = baton
;
12397 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
12399 else if (bytes
!= NULL
)
12401 SYMBOL_VALUE_BYTES (sym
) = bytes
;
12402 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
12406 SYMBOL_VALUE (sym
) = value
;
12407 SYMBOL_CLASS (sym
) = LOC_CONST
;
12411 /* Return the type of the die in question using its DW_AT_type attribute. */
12413 static struct type
*
12414 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12416 struct attribute
*type_attr
;
12418 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
12421 /* A missing DW_AT_type represents a void type. */
12422 return objfile_type (cu
->objfile
)->builtin_void
;
12425 return lookup_die_type (die
, type_attr
, cu
);
12428 /* True iff CU's producer generates GNAT Ada auxiliary information
12429 that allows to find parallel types through that information instead
12430 of having to do expensive parallel lookups by type name. */
12433 need_gnat_info (struct dwarf2_cu
*cu
)
12435 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12436 of GNAT produces this auxiliary information, without any indication
12437 that it is produced. Part of enhancing the FSF version of GNAT
12438 to produce that information will be to put in place an indicator
12439 that we can use in order to determine whether the descriptive type
12440 info is available or not. One suggestion that has been made is
12441 to use a new attribute, attached to the CU die. For now, assume
12442 that the descriptive type info is not available. */
12446 /* Return the auxiliary type of the die in question using its
12447 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12448 attribute is not present. */
12450 static struct type
*
12451 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12453 struct attribute
*type_attr
;
12455 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
12459 return lookup_die_type (die
, type_attr
, cu
);
12462 /* If DIE has a descriptive_type attribute, then set the TYPE's
12463 descriptive type accordingly. */
12466 set_descriptive_type (struct type
*type
, struct die_info
*die
,
12467 struct dwarf2_cu
*cu
)
12469 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
12471 if (descriptive_type
)
12473 ALLOCATE_GNAT_AUX_TYPE (type
);
12474 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
12478 /* Return the containing type of the die in question using its
12479 DW_AT_containing_type attribute. */
12481 static struct type
*
12482 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12484 struct attribute
*type_attr
;
12486 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
12488 error (_("Dwarf Error: Problem turning containing type into gdb type "
12489 "[in module %s]"), cu
->objfile
->name
);
12491 return lookup_die_type (die
, type_attr
, cu
);
12494 /* Look up the type of DIE in CU using its type attribute ATTR.
12495 If there is no type substitute an error marker. */
12497 static struct type
*
12498 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
12499 struct dwarf2_cu
*cu
)
12501 struct objfile
*objfile
= cu
->objfile
;
12502 struct type
*this_type
;
12504 /* First see if we have it cached. */
12506 if (is_ref_attr (attr
))
12508 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
12510 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
12512 else if (attr
->form
== DW_FORM_ref_sig8
)
12514 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12515 sect_offset offset
;
12517 /* sig_type will be NULL if the signatured type is missing from
12519 if (sig_type
== NULL
)
12520 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12521 "at 0x%x [in module %s]"),
12522 die
->offset
.sect_off
, objfile
->name
);
12524 gdb_assert (sig_type
->per_cu
.debug_types_section
);
12525 offset
.sect_off
= (sig_type
->per_cu
.offset
.sect_off
12526 + sig_type
->type_offset
.cu_off
);
12527 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
12531 dump_die_for_error (die
);
12532 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12533 dwarf_attr_name (attr
->name
), objfile
->name
);
12536 /* If not cached we need to read it in. */
12538 if (this_type
== NULL
)
12540 struct die_info
*type_die
;
12541 struct dwarf2_cu
*type_cu
= cu
;
12543 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
12544 /* If the type is cached, we should have found it above. */
12545 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
12546 this_type
= read_type_die_1 (type_die
, type_cu
);
12549 /* If we still don't have a type use an error marker. */
12551 if (this_type
== NULL
)
12553 char *message
, *saved
;
12555 /* read_type_die already issued a complaint. */
12556 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12558 cu
->header
.offset
.sect_off
,
12559 die
->offset
.sect_off
);
12560 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
12561 message
, strlen (message
));
12564 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
12570 /* Return the type in DIE, CU.
12571 Returns NULL for invalid types.
12573 This first does a lookup in the appropriate type_hash table,
12574 and only reads the die in if necessary.
12576 NOTE: This can be called when reading in partial or full symbols. */
12578 static struct type
*
12579 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12581 struct type
*this_type
;
12583 this_type
= get_die_type (die
, cu
);
12587 return read_type_die_1 (die
, cu
);
12590 /* Read the type in DIE, CU.
12591 Returns NULL for invalid types. */
12593 static struct type
*
12594 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12596 struct type
*this_type
= NULL
;
12600 case DW_TAG_class_type
:
12601 case DW_TAG_interface_type
:
12602 case DW_TAG_structure_type
:
12603 case DW_TAG_union_type
:
12604 this_type
= read_structure_type (die
, cu
);
12606 case DW_TAG_enumeration_type
:
12607 this_type
= read_enumeration_type (die
, cu
);
12609 case DW_TAG_subprogram
:
12610 case DW_TAG_subroutine_type
:
12611 case DW_TAG_inlined_subroutine
:
12612 this_type
= read_subroutine_type (die
, cu
);
12614 case DW_TAG_array_type
:
12615 this_type
= read_array_type (die
, cu
);
12617 case DW_TAG_set_type
:
12618 this_type
= read_set_type (die
, cu
);
12620 case DW_TAG_pointer_type
:
12621 this_type
= read_tag_pointer_type (die
, cu
);
12623 case DW_TAG_ptr_to_member_type
:
12624 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12626 case DW_TAG_reference_type
:
12627 this_type
= read_tag_reference_type (die
, cu
);
12629 case DW_TAG_const_type
:
12630 this_type
= read_tag_const_type (die
, cu
);
12632 case DW_TAG_volatile_type
:
12633 this_type
= read_tag_volatile_type (die
, cu
);
12635 case DW_TAG_string_type
:
12636 this_type
= read_tag_string_type (die
, cu
);
12638 case DW_TAG_typedef
:
12639 this_type
= read_typedef (die
, cu
);
12641 case DW_TAG_subrange_type
:
12642 this_type
= read_subrange_type (die
, cu
);
12644 case DW_TAG_base_type
:
12645 this_type
= read_base_type (die
, cu
);
12647 case DW_TAG_unspecified_type
:
12648 this_type
= read_unspecified_type (die
, cu
);
12650 case DW_TAG_namespace
:
12651 this_type
= read_namespace_type (die
, cu
);
12653 case DW_TAG_module
:
12654 this_type
= read_module_type (die
, cu
);
12657 complaint (&symfile_complaints
,
12658 _("unexpected tag in read_type_die: '%s'"),
12659 dwarf_tag_name (die
->tag
));
12666 /* See if we can figure out if the class lives in a namespace. We do
12667 this by looking for a member function; its demangled name will
12668 contain namespace info, if there is any.
12669 Return the computed name or NULL.
12670 Space for the result is allocated on the objfile's obstack.
12671 This is the full-die version of guess_partial_die_structure_name.
12672 In this case we know DIE has no useful parent. */
12675 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12677 struct die_info
*spec_die
;
12678 struct dwarf2_cu
*spec_cu
;
12679 struct die_info
*child
;
12682 spec_die
= die_specification (die
, &spec_cu
);
12683 if (spec_die
!= NULL
)
12689 for (child
= die
->child
;
12691 child
= child
->sibling
)
12693 if (child
->tag
== DW_TAG_subprogram
)
12695 struct attribute
*attr
;
12697 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12699 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12703 = language_class_name_from_physname (cu
->language_defn
,
12707 if (actual_name
!= NULL
)
12709 char *die_name
= dwarf2_name (die
, cu
);
12711 if (die_name
!= NULL
12712 && strcmp (die_name
, actual_name
) != 0)
12714 /* Strip off the class name from the full name.
12715 We want the prefix. */
12716 int die_name_len
= strlen (die_name
);
12717 int actual_name_len
= strlen (actual_name
);
12719 /* Test for '::' as a sanity check. */
12720 if (actual_name_len
> die_name_len
+ 2
12721 && actual_name
[actual_name_len
12722 - die_name_len
- 1] == ':')
12724 obsavestring (actual_name
,
12725 actual_name_len
- die_name_len
- 2,
12726 &cu
->objfile
->objfile_obstack
);
12729 xfree (actual_name
);
12738 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12739 prefix part in such case. See
12740 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12743 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12745 struct attribute
*attr
;
12748 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
12749 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
12752 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12753 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
12756 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12758 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12759 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12762 /* dwarf2_name had to be already called. */
12763 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
12765 /* Strip the base name, keep any leading namespaces/classes. */
12766 base
= strrchr (DW_STRING (attr
), ':');
12767 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
12770 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
12771 &cu
->objfile
->objfile_obstack
);
12774 /* Return the name of the namespace/class that DIE is defined within,
12775 or "" if we can't tell. The caller should not xfree the result.
12777 For example, if we're within the method foo() in the following
12787 then determine_prefix on foo's die will return "N::C". */
12789 static const char *
12790 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12792 struct die_info
*parent
, *spec_die
;
12793 struct dwarf2_cu
*spec_cu
;
12794 struct type
*parent_type
;
12797 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12798 && cu
->language
!= language_fortran
)
12801 retval
= anonymous_struct_prefix (die
, cu
);
12805 /* We have to be careful in the presence of DW_AT_specification.
12806 For example, with GCC 3.4, given the code
12810 // Definition of N::foo.
12814 then we'll have a tree of DIEs like this:
12816 1: DW_TAG_compile_unit
12817 2: DW_TAG_namespace // N
12818 3: DW_TAG_subprogram // declaration of N::foo
12819 4: DW_TAG_subprogram // definition of N::foo
12820 DW_AT_specification // refers to die #3
12822 Thus, when processing die #4, we have to pretend that we're in
12823 the context of its DW_AT_specification, namely the contex of die
12826 spec_die
= die_specification (die
, &spec_cu
);
12827 if (spec_die
== NULL
)
12828 parent
= die
->parent
;
12831 parent
= spec_die
->parent
;
12835 if (parent
== NULL
)
12837 else if (parent
->building_fullname
)
12840 const char *parent_name
;
12842 /* It has been seen on RealView 2.2 built binaries,
12843 DW_TAG_template_type_param types actually _defined_ as
12844 children of the parent class:
12847 template class <class Enum> Class{};
12848 Class<enum E> class_e;
12850 1: DW_TAG_class_type (Class)
12851 2: DW_TAG_enumeration_type (E)
12852 3: DW_TAG_enumerator (enum1:0)
12853 3: DW_TAG_enumerator (enum2:1)
12855 2: DW_TAG_template_type_param
12856 DW_AT_type DW_FORM_ref_udata (E)
12858 Besides being broken debug info, it can put GDB into an
12859 infinite loop. Consider:
12861 When we're building the full name for Class<E>, we'll start
12862 at Class, and go look over its template type parameters,
12863 finding E. We'll then try to build the full name of E, and
12864 reach here. We're now trying to build the full name of E,
12865 and look over the parent DIE for containing scope. In the
12866 broken case, if we followed the parent DIE of E, we'd again
12867 find Class, and once again go look at its template type
12868 arguments, etc., etc. Simply don't consider such parent die
12869 as source-level parent of this die (it can't be, the language
12870 doesn't allow it), and break the loop here. */
12871 name
= dwarf2_name (die
, cu
);
12872 parent_name
= dwarf2_name (parent
, cu
);
12873 complaint (&symfile_complaints
,
12874 _("template param type '%s' defined within parent '%s'"),
12875 name
? name
: "<unknown>",
12876 parent_name
? parent_name
: "<unknown>");
12880 switch (parent
->tag
)
12882 case DW_TAG_namespace
:
12883 parent_type
= read_type_die (parent
, cu
);
12884 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12885 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12886 Work around this problem here. */
12887 if (cu
->language
== language_cplus
12888 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12890 /* We give a name to even anonymous namespaces. */
12891 return TYPE_TAG_NAME (parent_type
);
12892 case DW_TAG_class_type
:
12893 case DW_TAG_interface_type
:
12894 case DW_TAG_structure_type
:
12895 case DW_TAG_union_type
:
12896 case DW_TAG_module
:
12897 parent_type
= read_type_die (parent
, cu
);
12898 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12899 return TYPE_TAG_NAME (parent_type
);
12901 /* An anonymous structure is only allowed non-static data
12902 members; no typedefs, no member functions, et cetera.
12903 So it does not need a prefix. */
12905 case DW_TAG_compile_unit
:
12906 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12907 if (cu
->language
== language_cplus
12908 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12909 && die
->child
!= NULL
12910 && (die
->tag
== DW_TAG_class_type
12911 || die
->tag
== DW_TAG_structure_type
12912 || die
->tag
== DW_TAG_union_type
))
12914 char *name
= guess_full_die_structure_name (die
, cu
);
12920 return determine_prefix (parent
, cu
);
12924 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12925 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12926 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12927 an obconcat, otherwise allocate storage for the result. The CU argument is
12928 used to determine the language and hence, the appropriate separator. */
12930 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12933 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12934 int physname
, struct dwarf2_cu
*cu
)
12936 const char *lead
= "";
12939 if (suffix
== NULL
|| suffix
[0] == '\0'
12940 || prefix
== NULL
|| prefix
[0] == '\0')
12942 else if (cu
->language
== language_java
)
12944 else if (cu
->language
== language_fortran
&& physname
)
12946 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12947 DW_AT_MIPS_linkage_name is preferred and used instead. */
12955 if (prefix
== NULL
)
12957 if (suffix
== NULL
)
12963 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12965 strcpy (retval
, lead
);
12966 strcat (retval
, prefix
);
12967 strcat (retval
, sep
);
12968 strcat (retval
, suffix
);
12973 /* We have an obstack. */
12974 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12978 /* Return sibling of die, NULL if no sibling. */
12980 static struct die_info
*
12981 sibling_die (struct die_info
*die
)
12983 return die
->sibling
;
12986 /* Get name of a die, return NULL if not found. */
12989 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12990 struct obstack
*obstack
)
12992 if (name
&& cu
->language
== language_cplus
)
12994 char *canon_name
= cp_canonicalize_string (name
);
12996 if (canon_name
!= NULL
)
12998 if (strcmp (canon_name
, name
) != 0)
12999 name
= obsavestring (canon_name
, strlen (canon_name
),
13001 xfree (canon_name
);
13008 /* Get name of a die, return NULL if not found. */
13011 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
13013 struct attribute
*attr
;
13015 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
13016 if ((!attr
|| !DW_STRING (attr
))
13017 && die
->tag
!= DW_TAG_class_type
13018 && die
->tag
!= DW_TAG_interface_type
13019 && die
->tag
!= DW_TAG_structure_type
13020 && die
->tag
!= DW_TAG_union_type
)
13025 case DW_TAG_compile_unit
:
13026 /* Compilation units have a DW_AT_name that is a filename, not
13027 a source language identifier. */
13028 case DW_TAG_enumeration_type
:
13029 case DW_TAG_enumerator
:
13030 /* These tags always have simple identifiers already; no need
13031 to canonicalize them. */
13032 return DW_STRING (attr
);
13034 case DW_TAG_subprogram
:
13035 /* Java constructors will all be named "<init>", so return
13036 the class name when we see this special case. */
13037 if (cu
->language
== language_java
13038 && DW_STRING (attr
) != NULL
13039 && strcmp (DW_STRING (attr
), "<init>") == 0)
13041 struct dwarf2_cu
*spec_cu
= cu
;
13042 struct die_info
*spec_die
;
13044 /* GCJ will output '<init>' for Java constructor names.
13045 For this special case, return the name of the parent class. */
13047 /* GCJ may output suprogram DIEs with AT_specification set.
13048 If so, use the name of the specified DIE. */
13049 spec_die
= die_specification (die
, &spec_cu
);
13050 if (spec_die
!= NULL
)
13051 return dwarf2_name (spec_die
, spec_cu
);
13056 if (die
->tag
== DW_TAG_class_type
)
13057 return dwarf2_name (die
, cu
);
13059 while (die
->tag
!= DW_TAG_compile_unit
);
13063 case DW_TAG_class_type
:
13064 case DW_TAG_interface_type
:
13065 case DW_TAG_structure_type
:
13066 case DW_TAG_union_type
:
13067 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
13068 structures or unions. These were of the form "._%d" in GCC 4.1,
13069 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
13070 and GCC 4.4. We work around this problem by ignoring these. */
13071 if (attr
&& DW_STRING (attr
)
13072 && (strncmp (DW_STRING (attr
), "._", 2) == 0
13073 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
13076 /* GCC might emit a nameless typedef that has a linkage name. See
13077 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
13078 if (!attr
|| DW_STRING (attr
) == NULL
)
13080 char *demangled
= NULL
;
13082 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
13084 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
13086 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
13089 /* Avoid demangling DW_STRING (attr) the second time on a second
13090 call for the same DIE. */
13091 if (!DW_STRING_IS_CANONICAL (attr
))
13092 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
13098 /* FIXME: we already did this for the partial symbol... */
13099 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
13100 &cu
->objfile
->objfile_obstack
);
13101 DW_STRING_IS_CANONICAL (attr
) = 1;
13104 /* Strip any leading namespaces/classes, keep only the base name.
13105 DW_AT_name for named DIEs does not contain the prefixes. */
13106 base
= strrchr (DW_STRING (attr
), ':');
13107 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
13110 return DW_STRING (attr
);
13119 if (!DW_STRING_IS_CANONICAL (attr
))
13122 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
13123 &cu
->objfile
->objfile_obstack
);
13124 DW_STRING_IS_CANONICAL (attr
) = 1;
13126 return DW_STRING (attr
);
13129 /* Return the die that this die in an extension of, or NULL if there
13130 is none. *EXT_CU is the CU containing DIE on input, and the CU
13131 containing the return value on output. */
13133 static struct die_info
*
13134 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
13136 struct attribute
*attr
;
13138 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
13142 return follow_die_ref (die
, attr
, ext_cu
);
13145 /* Convert a DIE tag into its string name. */
13148 dwarf_tag_name (unsigned tag
)
13152 case DW_TAG_padding
:
13153 return "DW_TAG_padding";
13154 case DW_TAG_array_type
:
13155 return "DW_TAG_array_type";
13156 case DW_TAG_class_type
:
13157 return "DW_TAG_class_type";
13158 case DW_TAG_entry_point
:
13159 return "DW_TAG_entry_point";
13160 case DW_TAG_enumeration_type
:
13161 return "DW_TAG_enumeration_type";
13162 case DW_TAG_formal_parameter
:
13163 return "DW_TAG_formal_parameter";
13164 case DW_TAG_imported_declaration
:
13165 return "DW_TAG_imported_declaration";
13167 return "DW_TAG_label";
13168 case DW_TAG_lexical_block
:
13169 return "DW_TAG_lexical_block";
13170 case DW_TAG_member
:
13171 return "DW_TAG_member";
13172 case DW_TAG_pointer_type
:
13173 return "DW_TAG_pointer_type";
13174 case DW_TAG_reference_type
:
13175 return "DW_TAG_reference_type";
13176 case DW_TAG_compile_unit
:
13177 return "DW_TAG_compile_unit";
13178 case DW_TAG_string_type
:
13179 return "DW_TAG_string_type";
13180 case DW_TAG_structure_type
:
13181 return "DW_TAG_structure_type";
13182 case DW_TAG_subroutine_type
:
13183 return "DW_TAG_subroutine_type";
13184 case DW_TAG_typedef
:
13185 return "DW_TAG_typedef";
13186 case DW_TAG_union_type
:
13187 return "DW_TAG_union_type";
13188 case DW_TAG_unspecified_parameters
:
13189 return "DW_TAG_unspecified_parameters";
13190 case DW_TAG_variant
:
13191 return "DW_TAG_variant";
13192 case DW_TAG_common_block
:
13193 return "DW_TAG_common_block";
13194 case DW_TAG_common_inclusion
:
13195 return "DW_TAG_common_inclusion";
13196 case DW_TAG_inheritance
:
13197 return "DW_TAG_inheritance";
13198 case DW_TAG_inlined_subroutine
:
13199 return "DW_TAG_inlined_subroutine";
13200 case DW_TAG_module
:
13201 return "DW_TAG_module";
13202 case DW_TAG_ptr_to_member_type
:
13203 return "DW_TAG_ptr_to_member_type";
13204 case DW_TAG_set_type
:
13205 return "DW_TAG_set_type";
13206 case DW_TAG_subrange_type
:
13207 return "DW_TAG_subrange_type";
13208 case DW_TAG_with_stmt
:
13209 return "DW_TAG_with_stmt";
13210 case DW_TAG_access_declaration
:
13211 return "DW_TAG_access_declaration";
13212 case DW_TAG_base_type
:
13213 return "DW_TAG_base_type";
13214 case DW_TAG_catch_block
:
13215 return "DW_TAG_catch_block";
13216 case DW_TAG_const_type
:
13217 return "DW_TAG_const_type";
13218 case DW_TAG_constant
:
13219 return "DW_TAG_constant";
13220 case DW_TAG_enumerator
:
13221 return "DW_TAG_enumerator";
13222 case DW_TAG_file_type
:
13223 return "DW_TAG_file_type";
13224 case DW_TAG_friend
:
13225 return "DW_TAG_friend";
13226 case DW_TAG_namelist
:
13227 return "DW_TAG_namelist";
13228 case DW_TAG_namelist_item
:
13229 return "DW_TAG_namelist_item";
13230 case DW_TAG_packed_type
:
13231 return "DW_TAG_packed_type";
13232 case DW_TAG_subprogram
:
13233 return "DW_TAG_subprogram";
13234 case DW_TAG_template_type_param
:
13235 return "DW_TAG_template_type_param";
13236 case DW_TAG_template_value_param
:
13237 return "DW_TAG_template_value_param";
13238 case DW_TAG_thrown_type
:
13239 return "DW_TAG_thrown_type";
13240 case DW_TAG_try_block
:
13241 return "DW_TAG_try_block";
13242 case DW_TAG_variant_part
:
13243 return "DW_TAG_variant_part";
13244 case DW_TAG_variable
:
13245 return "DW_TAG_variable";
13246 case DW_TAG_volatile_type
:
13247 return "DW_TAG_volatile_type";
13248 case DW_TAG_dwarf_procedure
:
13249 return "DW_TAG_dwarf_procedure";
13250 case DW_TAG_restrict_type
:
13251 return "DW_TAG_restrict_type";
13252 case DW_TAG_interface_type
:
13253 return "DW_TAG_interface_type";
13254 case DW_TAG_namespace
:
13255 return "DW_TAG_namespace";
13256 case DW_TAG_imported_module
:
13257 return "DW_TAG_imported_module";
13258 case DW_TAG_unspecified_type
:
13259 return "DW_TAG_unspecified_type";
13260 case DW_TAG_partial_unit
:
13261 return "DW_TAG_partial_unit";
13262 case DW_TAG_imported_unit
:
13263 return "DW_TAG_imported_unit";
13264 case DW_TAG_condition
:
13265 return "DW_TAG_condition";
13266 case DW_TAG_shared_type
:
13267 return "DW_TAG_shared_type";
13268 case DW_TAG_type_unit
:
13269 return "DW_TAG_type_unit";
13270 case DW_TAG_MIPS_loop
:
13271 return "DW_TAG_MIPS_loop";
13272 case DW_TAG_HP_array_descriptor
:
13273 return "DW_TAG_HP_array_descriptor";
13274 case DW_TAG_format_label
:
13275 return "DW_TAG_format_label";
13276 case DW_TAG_function_template
:
13277 return "DW_TAG_function_template";
13278 case DW_TAG_class_template
:
13279 return "DW_TAG_class_template";
13280 case DW_TAG_GNU_BINCL
:
13281 return "DW_TAG_GNU_BINCL";
13282 case DW_TAG_GNU_EINCL
:
13283 return "DW_TAG_GNU_EINCL";
13284 case DW_TAG_upc_shared_type
:
13285 return "DW_TAG_upc_shared_type";
13286 case DW_TAG_upc_strict_type
:
13287 return "DW_TAG_upc_strict_type";
13288 case DW_TAG_upc_relaxed_type
:
13289 return "DW_TAG_upc_relaxed_type";
13290 case DW_TAG_PGI_kanji_type
:
13291 return "DW_TAG_PGI_kanji_type";
13292 case DW_TAG_PGI_interface_block
:
13293 return "DW_TAG_PGI_interface_block";
13294 case DW_TAG_GNU_call_site
:
13295 return "DW_TAG_GNU_call_site";
13297 return "DW_TAG_<unknown>";
13301 /* Convert a DWARF attribute code into its string name. */
13304 dwarf_attr_name (unsigned attr
)
13308 case DW_AT_sibling
:
13309 return "DW_AT_sibling";
13310 case DW_AT_location
:
13311 return "DW_AT_location";
13313 return "DW_AT_name";
13314 case DW_AT_ordering
:
13315 return "DW_AT_ordering";
13316 case DW_AT_subscr_data
:
13317 return "DW_AT_subscr_data";
13318 case DW_AT_byte_size
:
13319 return "DW_AT_byte_size";
13320 case DW_AT_bit_offset
:
13321 return "DW_AT_bit_offset";
13322 case DW_AT_bit_size
:
13323 return "DW_AT_bit_size";
13324 case DW_AT_element_list
:
13325 return "DW_AT_element_list";
13326 case DW_AT_stmt_list
:
13327 return "DW_AT_stmt_list";
13329 return "DW_AT_low_pc";
13330 case DW_AT_high_pc
:
13331 return "DW_AT_high_pc";
13332 case DW_AT_language
:
13333 return "DW_AT_language";
13335 return "DW_AT_member";
13337 return "DW_AT_discr";
13338 case DW_AT_discr_value
:
13339 return "DW_AT_discr_value";
13340 case DW_AT_visibility
:
13341 return "DW_AT_visibility";
13343 return "DW_AT_import";
13344 case DW_AT_string_length
:
13345 return "DW_AT_string_length";
13346 case DW_AT_common_reference
:
13347 return "DW_AT_common_reference";
13348 case DW_AT_comp_dir
:
13349 return "DW_AT_comp_dir";
13350 case DW_AT_const_value
:
13351 return "DW_AT_const_value";
13352 case DW_AT_containing_type
:
13353 return "DW_AT_containing_type";
13354 case DW_AT_default_value
:
13355 return "DW_AT_default_value";
13357 return "DW_AT_inline";
13358 case DW_AT_is_optional
:
13359 return "DW_AT_is_optional";
13360 case DW_AT_lower_bound
:
13361 return "DW_AT_lower_bound";
13362 case DW_AT_producer
:
13363 return "DW_AT_producer";
13364 case DW_AT_prototyped
:
13365 return "DW_AT_prototyped";
13366 case DW_AT_return_addr
:
13367 return "DW_AT_return_addr";
13368 case DW_AT_start_scope
:
13369 return "DW_AT_start_scope";
13370 case DW_AT_bit_stride
:
13371 return "DW_AT_bit_stride";
13372 case DW_AT_upper_bound
:
13373 return "DW_AT_upper_bound";
13374 case DW_AT_abstract_origin
:
13375 return "DW_AT_abstract_origin";
13376 case DW_AT_accessibility
:
13377 return "DW_AT_accessibility";
13378 case DW_AT_address_class
:
13379 return "DW_AT_address_class";
13380 case DW_AT_artificial
:
13381 return "DW_AT_artificial";
13382 case DW_AT_base_types
:
13383 return "DW_AT_base_types";
13384 case DW_AT_calling_convention
:
13385 return "DW_AT_calling_convention";
13387 return "DW_AT_count";
13388 case DW_AT_data_member_location
:
13389 return "DW_AT_data_member_location";
13390 case DW_AT_decl_column
:
13391 return "DW_AT_decl_column";
13392 case DW_AT_decl_file
:
13393 return "DW_AT_decl_file";
13394 case DW_AT_decl_line
:
13395 return "DW_AT_decl_line";
13396 case DW_AT_declaration
:
13397 return "DW_AT_declaration";
13398 case DW_AT_discr_list
:
13399 return "DW_AT_discr_list";
13400 case DW_AT_encoding
:
13401 return "DW_AT_encoding";
13402 case DW_AT_external
:
13403 return "DW_AT_external";
13404 case DW_AT_frame_base
:
13405 return "DW_AT_frame_base";
13407 return "DW_AT_friend";
13408 case DW_AT_identifier_case
:
13409 return "DW_AT_identifier_case";
13410 case DW_AT_macro_info
:
13411 return "DW_AT_macro_info";
13412 case DW_AT_namelist_items
:
13413 return "DW_AT_namelist_items";
13414 case DW_AT_priority
:
13415 return "DW_AT_priority";
13416 case DW_AT_segment
:
13417 return "DW_AT_segment";
13418 case DW_AT_specification
:
13419 return "DW_AT_specification";
13420 case DW_AT_static_link
:
13421 return "DW_AT_static_link";
13423 return "DW_AT_type";
13424 case DW_AT_use_location
:
13425 return "DW_AT_use_location";
13426 case DW_AT_variable_parameter
:
13427 return "DW_AT_variable_parameter";
13428 case DW_AT_virtuality
:
13429 return "DW_AT_virtuality";
13430 case DW_AT_vtable_elem_location
:
13431 return "DW_AT_vtable_elem_location";
13432 /* DWARF 3 values. */
13433 case DW_AT_allocated
:
13434 return "DW_AT_allocated";
13435 case DW_AT_associated
:
13436 return "DW_AT_associated";
13437 case DW_AT_data_location
:
13438 return "DW_AT_data_location";
13439 case DW_AT_byte_stride
:
13440 return "DW_AT_byte_stride";
13441 case DW_AT_entry_pc
:
13442 return "DW_AT_entry_pc";
13443 case DW_AT_use_UTF8
:
13444 return "DW_AT_use_UTF8";
13445 case DW_AT_extension
:
13446 return "DW_AT_extension";
13448 return "DW_AT_ranges";
13449 case DW_AT_trampoline
:
13450 return "DW_AT_trampoline";
13451 case DW_AT_call_column
:
13452 return "DW_AT_call_column";
13453 case DW_AT_call_file
:
13454 return "DW_AT_call_file";
13455 case DW_AT_call_line
:
13456 return "DW_AT_call_line";
13457 case DW_AT_description
:
13458 return "DW_AT_description";
13459 case DW_AT_binary_scale
:
13460 return "DW_AT_binary_scale";
13461 case DW_AT_decimal_scale
:
13462 return "DW_AT_decimal_scale";
13464 return "DW_AT_small";
13465 case DW_AT_decimal_sign
:
13466 return "DW_AT_decimal_sign";
13467 case DW_AT_digit_count
:
13468 return "DW_AT_digit_count";
13469 case DW_AT_picture_string
:
13470 return "DW_AT_picture_string";
13471 case DW_AT_mutable
:
13472 return "DW_AT_mutable";
13473 case DW_AT_threads_scaled
:
13474 return "DW_AT_threads_scaled";
13475 case DW_AT_explicit
:
13476 return "DW_AT_explicit";
13477 case DW_AT_object_pointer
:
13478 return "DW_AT_object_pointer";
13479 case DW_AT_endianity
:
13480 return "DW_AT_endianity";
13481 case DW_AT_elemental
:
13482 return "DW_AT_elemental";
13484 return "DW_AT_pure";
13485 case DW_AT_recursive
:
13486 return "DW_AT_recursive";
13487 /* DWARF 4 values. */
13488 case DW_AT_signature
:
13489 return "DW_AT_signature";
13490 case DW_AT_linkage_name
:
13491 return "DW_AT_linkage_name";
13492 /* SGI/MIPS extensions. */
13493 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13494 case DW_AT_MIPS_fde
:
13495 return "DW_AT_MIPS_fde";
13497 case DW_AT_MIPS_loop_begin
:
13498 return "DW_AT_MIPS_loop_begin";
13499 case DW_AT_MIPS_tail_loop_begin
:
13500 return "DW_AT_MIPS_tail_loop_begin";
13501 case DW_AT_MIPS_epilog_begin
:
13502 return "DW_AT_MIPS_epilog_begin";
13503 case DW_AT_MIPS_loop_unroll_factor
:
13504 return "DW_AT_MIPS_loop_unroll_factor";
13505 case DW_AT_MIPS_software_pipeline_depth
:
13506 return "DW_AT_MIPS_software_pipeline_depth";
13507 case DW_AT_MIPS_linkage_name
:
13508 return "DW_AT_MIPS_linkage_name";
13509 case DW_AT_MIPS_stride
:
13510 return "DW_AT_MIPS_stride";
13511 case DW_AT_MIPS_abstract_name
:
13512 return "DW_AT_MIPS_abstract_name";
13513 case DW_AT_MIPS_clone_origin
:
13514 return "DW_AT_MIPS_clone_origin";
13515 case DW_AT_MIPS_has_inlines
:
13516 return "DW_AT_MIPS_has_inlines";
13517 /* HP extensions. */
13518 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13519 case DW_AT_HP_block_index
:
13520 return "DW_AT_HP_block_index";
13522 case DW_AT_HP_unmodifiable
:
13523 return "DW_AT_HP_unmodifiable";
13524 case DW_AT_HP_actuals_stmt_list
:
13525 return "DW_AT_HP_actuals_stmt_list";
13526 case DW_AT_HP_proc_per_section
:
13527 return "DW_AT_HP_proc_per_section";
13528 case DW_AT_HP_raw_data_ptr
:
13529 return "DW_AT_HP_raw_data_ptr";
13530 case DW_AT_HP_pass_by_reference
:
13531 return "DW_AT_HP_pass_by_reference";
13532 case DW_AT_HP_opt_level
:
13533 return "DW_AT_HP_opt_level";
13534 case DW_AT_HP_prof_version_id
:
13535 return "DW_AT_HP_prof_version_id";
13536 case DW_AT_HP_opt_flags
:
13537 return "DW_AT_HP_opt_flags";
13538 case DW_AT_HP_cold_region_low_pc
:
13539 return "DW_AT_HP_cold_region_low_pc";
13540 case DW_AT_HP_cold_region_high_pc
:
13541 return "DW_AT_HP_cold_region_high_pc";
13542 case DW_AT_HP_all_variables_modifiable
:
13543 return "DW_AT_HP_all_variables_modifiable";
13544 case DW_AT_HP_linkage_name
:
13545 return "DW_AT_HP_linkage_name";
13546 case DW_AT_HP_prof_flags
:
13547 return "DW_AT_HP_prof_flags";
13548 /* GNU extensions. */
13549 case DW_AT_sf_names
:
13550 return "DW_AT_sf_names";
13551 case DW_AT_src_info
:
13552 return "DW_AT_src_info";
13553 case DW_AT_mac_info
:
13554 return "DW_AT_mac_info";
13555 case DW_AT_src_coords
:
13556 return "DW_AT_src_coords";
13557 case DW_AT_body_begin
:
13558 return "DW_AT_body_begin";
13559 case DW_AT_body_end
:
13560 return "DW_AT_body_end";
13561 case DW_AT_GNU_vector
:
13562 return "DW_AT_GNU_vector";
13563 case DW_AT_GNU_odr_signature
:
13564 return "DW_AT_GNU_odr_signature";
13565 /* VMS extensions. */
13566 case DW_AT_VMS_rtnbeg_pd_address
:
13567 return "DW_AT_VMS_rtnbeg_pd_address";
13568 /* UPC extension. */
13569 case DW_AT_upc_threads_scaled
:
13570 return "DW_AT_upc_threads_scaled";
13571 /* PGI (STMicroelectronics) extensions. */
13572 case DW_AT_PGI_lbase
:
13573 return "DW_AT_PGI_lbase";
13574 case DW_AT_PGI_soffset
:
13575 return "DW_AT_PGI_soffset";
13576 case DW_AT_PGI_lstride
:
13577 return "DW_AT_PGI_lstride";
13579 return "DW_AT_<unknown>";
13583 /* Convert a DWARF value form code into its string name. */
13586 dwarf_form_name (unsigned form
)
13591 return "DW_FORM_addr";
13592 case DW_FORM_block2
:
13593 return "DW_FORM_block2";
13594 case DW_FORM_block4
:
13595 return "DW_FORM_block4";
13596 case DW_FORM_data2
:
13597 return "DW_FORM_data2";
13598 case DW_FORM_data4
:
13599 return "DW_FORM_data4";
13600 case DW_FORM_data8
:
13601 return "DW_FORM_data8";
13602 case DW_FORM_string
:
13603 return "DW_FORM_string";
13604 case DW_FORM_block
:
13605 return "DW_FORM_block";
13606 case DW_FORM_block1
:
13607 return "DW_FORM_block1";
13608 case DW_FORM_data1
:
13609 return "DW_FORM_data1";
13611 return "DW_FORM_flag";
13612 case DW_FORM_sdata
:
13613 return "DW_FORM_sdata";
13615 return "DW_FORM_strp";
13616 case DW_FORM_udata
:
13617 return "DW_FORM_udata";
13618 case DW_FORM_ref_addr
:
13619 return "DW_FORM_ref_addr";
13621 return "DW_FORM_ref1";
13623 return "DW_FORM_ref2";
13625 return "DW_FORM_ref4";
13627 return "DW_FORM_ref8";
13628 case DW_FORM_ref_udata
:
13629 return "DW_FORM_ref_udata";
13630 case DW_FORM_indirect
:
13631 return "DW_FORM_indirect";
13632 case DW_FORM_sec_offset
:
13633 return "DW_FORM_sec_offset";
13634 case DW_FORM_exprloc
:
13635 return "DW_FORM_exprloc";
13636 case DW_FORM_flag_present
:
13637 return "DW_FORM_flag_present";
13638 case DW_FORM_ref_sig8
:
13639 return "DW_FORM_ref_sig8";
13641 return "DW_FORM_<unknown>";
13645 /* Convert a DWARF stack opcode into its string name. */
13648 dwarf_stack_op_name (unsigned op
)
13653 return "DW_OP_addr";
13655 return "DW_OP_deref";
13656 case DW_OP_const1u
:
13657 return "DW_OP_const1u";
13658 case DW_OP_const1s
:
13659 return "DW_OP_const1s";
13660 case DW_OP_const2u
:
13661 return "DW_OP_const2u";
13662 case DW_OP_const2s
:
13663 return "DW_OP_const2s";
13664 case DW_OP_const4u
:
13665 return "DW_OP_const4u";
13666 case DW_OP_const4s
:
13667 return "DW_OP_const4s";
13668 case DW_OP_const8u
:
13669 return "DW_OP_const8u";
13670 case DW_OP_const8s
:
13671 return "DW_OP_const8s";
13673 return "DW_OP_constu";
13675 return "DW_OP_consts";
13677 return "DW_OP_dup";
13679 return "DW_OP_drop";
13681 return "DW_OP_over";
13683 return "DW_OP_pick";
13685 return "DW_OP_swap";
13687 return "DW_OP_rot";
13689 return "DW_OP_xderef";
13691 return "DW_OP_abs";
13693 return "DW_OP_and";
13695 return "DW_OP_div";
13697 return "DW_OP_minus";
13699 return "DW_OP_mod";
13701 return "DW_OP_mul";
13703 return "DW_OP_neg";
13705 return "DW_OP_not";
13709 return "DW_OP_plus";
13710 case DW_OP_plus_uconst
:
13711 return "DW_OP_plus_uconst";
13713 return "DW_OP_shl";
13715 return "DW_OP_shr";
13717 return "DW_OP_shra";
13719 return "DW_OP_xor";
13721 return "DW_OP_bra";
13735 return "DW_OP_skip";
13737 return "DW_OP_lit0";
13739 return "DW_OP_lit1";
13741 return "DW_OP_lit2";
13743 return "DW_OP_lit3";
13745 return "DW_OP_lit4";
13747 return "DW_OP_lit5";
13749 return "DW_OP_lit6";
13751 return "DW_OP_lit7";
13753 return "DW_OP_lit8";
13755 return "DW_OP_lit9";
13757 return "DW_OP_lit10";
13759 return "DW_OP_lit11";
13761 return "DW_OP_lit12";
13763 return "DW_OP_lit13";
13765 return "DW_OP_lit14";
13767 return "DW_OP_lit15";
13769 return "DW_OP_lit16";
13771 return "DW_OP_lit17";
13773 return "DW_OP_lit18";
13775 return "DW_OP_lit19";
13777 return "DW_OP_lit20";
13779 return "DW_OP_lit21";
13781 return "DW_OP_lit22";
13783 return "DW_OP_lit23";
13785 return "DW_OP_lit24";
13787 return "DW_OP_lit25";
13789 return "DW_OP_lit26";
13791 return "DW_OP_lit27";
13793 return "DW_OP_lit28";
13795 return "DW_OP_lit29";
13797 return "DW_OP_lit30";
13799 return "DW_OP_lit31";
13801 return "DW_OP_reg0";
13803 return "DW_OP_reg1";
13805 return "DW_OP_reg2";
13807 return "DW_OP_reg3";
13809 return "DW_OP_reg4";
13811 return "DW_OP_reg5";
13813 return "DW_OP_reg6";
13815 return "DW_OP_reg7";
13817 return "DW_OP_reg8";
13819 return "DW_OP_reg9";
13821 return "DW_OP_reg10";
13823 return "DW_OP_reg11";
13825 return "DW_OP_reg12";
13827 return "DW_OP_reg13";
13829 return "DW_OP_reg14";
13831 return "DW_OP_reg15";
13833 return "DW_OP_reg16";
13835 return "DW_OP_reg17";
13837 return "DW_OP_reg18";
13839 return "DW_OP_reg19";
13841 return "DW_OP_reg20";
13843 return "DW_OP_reg21";
13845 return "DW_OP_reg22";
13847 return "DW_OP_reg23";
13849 return "DW_OP_reg24";
13851 return "DW_OP_reg25";
13853 return "DW_OP_reg26";
13855 return "DW_OP_reg27";
13857 return "DW_OP_reg28";
13859 return "DW_OP_reg29";
13861 return "DW_OP_reg30";
13863 return "DW_OP_reg31";
13865 return "DW_OP_breg0";
13867 return "DW_OP_breg1";
13869 return "DW_OP_breg2";
13871 return "DW_OP_breg3";
13873 return "DW_OP_breg4";
13875 return "DW_OP_breg5";
13877 return "DW_OP_breg6";
13879 return "DW_OP_breg7";
13881 return "DW_OP_breg8";
13883 return "DW_OP_breg9";
13885 return "DW_OP_breg10";
13887 return "DW_OP_breg11";
13889 return "DW_OP_breg12";
13891 return "DW_OP_breg13";
13893 return "DW_OP_breg14";
13895 return "DW_OP_breg15";
13897 return "DW_OP_breg16";
13899 return "DW_OP_breg17";
13901 return "DW_OP_breg18";
13903 return "DW_OP_breg19";
13905 return "DW_OP_breg20";
13907 return "DW_OP_breg21";
13909 return "DW_OP_breg22";
13911 return "DW_OP_breg23";
13913 return "DW_OP_breg24";
13915 return "DW_OP_breg25";
13917 return "DW_OP_breg26";
13919 return "DW_OP_breg27";
13921 return "DW_OP_breg28";
13923 return "DW_OP_breg29";
13925 return "DW_OP_breg30";
13927 return "DW_OP_breg31";
13929 return "DW_OP_regx";
13931 return "DW_OP_fbreg";
13933 return "DW_OP_bregx";
13935 return "DW_OP_piece";
13936 case DW_OP_deref_size
:
13937 return "DW_OP_deref_size";
13938 case DW_OP_xderef_size
:
13939 return "DW_OP_xderef_size";
13941 return "DW_OP_nop";
13942 /* DWARF 3 extensions. */
13943 case DW_OP_push_object_address
:
13944 return "DW_OP_push_object_address";
13946 return "DW_OP_call2";
13948 return "DW_OP_call4";
13949 case DW_OP_call_ref
:
13950 return "DW_OP_call_ref";
13951 case DW_OP_form_tls_address
:
13952 return "DW_OP_form_tls_address";
13953 case DW_OP_call_frame_cfa
:
13954 return "DW_OP_call_frame_cfa";
13955 case DW_OP_bit_piece
:
13956 return "DW_OP_bit_piece";
13957 /* DWARF 4 extensions. */
13958 case DW_OP_implicit_value
:
13959 return "DW_OP_implicit_value";
13960 case DW_OP_stack_value
:
13961 return "DW_OP_stack_value";
13962 /* GNU extensions. */
13963 case DW_OP_GNU_push_tls_address
:
13964 return "DW_OP_GNU_push_tls_address";
13965 case DW_OP_GNU_uninit
:
13966 return "DW_OP_GNU_uninit";
13967 case DW_OP_GNU_encoded_addr
:
13968 return "DW_OP_GNU_encoded_addr";
13969 case DW_OP_GNU_implicit_pointer
:
13970 return "DW_OP_GNU_implicit_pointer";
13971 case DW_OP_GNU_entry_value
:
13972 return "DW_OP_GNU_entry_value";
13973 case DW_OP_GNU_const_type
:
13974 return "DW_OP_GNU_const_type";
13975 case DW_OP_GNU_regval_type
:
13976 return "DW_OP_GNU_regval_type";
13977 case DW_OP_GNU_deref_type
:
13978 return "DW_OP_GNU_deref_type";
13979 case DW_OP_GNU_convert
:
13980 return "DW_OP_GNU_convert";
13981 case DW_OP_GNU_reinterpret
:
13982 return "DW_OP_GNU_reinterpret";
13983 case DW_OP_GNU_parameter_ref
:
13984 return "DW_OP_GNU_parameter_ref";
13991 dwarf_bool_name (unsigned mybool
)
13999 /* Convert a DWARF type code into its string name. */
14002 dwarf_type_encoding_name (unsigned enc
)
14007 return "DW_ATE_void";
14008 case DW_ATE_address
:
14009 return "DW_ATE_address";
14010 case DW_ATE_boolean
:
14011 return "DW_ATE_boolean";
14012 case DW_ATE_complex_float
:
14013 return "DW_ATE_complex_float";
14015 return "DW_ATE_float";
14016 case DW_ATE_signed
:
14017 return "DW_ATE_signed";
14018 case DW_ATE_signed_char
:
14019 return "DW_ATE_signed_char";
14020 case DW_ATE_unsigned
:
14021 return "DW_ATE_unsigned";
14022 case DW_ATE_unsigned_char
:
14023 return "DW_ATE_unsigned_char";
14025 case DW_ATE_imaginary_float
:
14026 return "DW_ATE_imaginary_float";
14027 case DW_ATE_packed_decimal
:
14028 return "DW_ATE_packed_decimal";
14029 case DW_ATE_numeric_string
:
14030 return "DW_ATE_numeric_string";
14031 case DW_ATE_edited
:
14032 return "DW_ATE_edited";
14033 case DW_ATE_signed_fixed
:
14034 return "DW_ATE_signed_fixed";
14035 case DW_ATE_unsigned_fixed
:
14036 return "DW_ATE_unsigned_fixed";
14037 case DW_ATE_decimal_float
:
14038 return "DW_ATE_decimal_float";
14041 return "DW_ATE_UTF";
14042 /* HP extensions. */
14043 case DW_ATE_HP_float80
:
14044 return "DW_ATE_HP_float80";
14045 case DW_ATE_HP_complex_float80
:
14046 return "DW_ATE_HP_complex_float80";
14047 case DW_ATE_HP_float128
:
14048 return "DW_ATE_HP_float128";
14049 case DW_ATE_HP_complex_float128
:
14050 return "DW_ATE_HP_complex_float128";
14051 case DW_ATE_HP_floathpintel
:
14052 return "DW_ATE_HP_floathpintel";
14053 case DW_ATE_HP_imaginary_float80
:
14054 return "DW_ATE_HP_imaginary_float80";
14055 case DW_ATE_HP_imaginary_float128
:
14056 return "DW_ATE_HP_imaginary_float128";
14058 return "DW_ATE_<unknown>";
14062 /* Convert a DWARF call frame info operation to its string name. */
14066 dwarf_cfi_name (unsigned cfi_opc
)
14070 case DW_CFA_advance_loc
:
14071 return "DW_CFA_advance_loc";
14072 case DW_CFA_offset
:
14073 return "DW_CFA_offset";
14074 case DW_CFA_restore
:
14075 return "DW_CFA_restore";
14077 return "DW_CFA_nop";
14078 case DW_CFA_set_loc
:
14079 return "DW_CFA_set_loc";
14080 case DW_CFA_advance_loc1
:
14081 return "DW_CFA_advance_loc1";
14082 case DW_CFA_advance_loc2
:
14083 return "DW_CFA_advance_loc2";
14084 case DW_CFA_advance_loc4
:
14085 return "DW_CFA_advance_loc4";
14086 case DW_CFA_offset_extended
:
14087 return "DW_CFA_offset_extended";
14088 case DW_CFA_restore_extended
:
14089 return "DW_CFA_restore_extended";
14090 case DW_CFA_undefined
:
14091 return "DW_CFA_undefined";
14092 case DW_CFA_same_value
:
14093 return "DW_CFA_same_value";
14094 case DW_CFA_register
:
14095 return "DW_CFA_register";
14096 case DW_CFA_remember_state
:
14097 return "DW_CFA_remember_state";
14098 case DW_CFA_restore_state
:
14099 return "DW_CFA_restore_state";
14100 case DW_CFA_def_cfa
:
14101 return "DW_CFA_def_cfa";
14102 case DW_CFA_def_cfa_register
:
14103 return "DW_CFA_def_cfa_register";
14104 case DW_CFA_def_cfa_offset
:
14105 return "DW_CFA_def_cfa_offset";
14107 case DW_CFA_def_cfa_expression
:
14108 return "DW_CFA_def_cfa_expression";
14109 case DW_CFA_expression
:
14110 return "DW_CFA_expression";
14111 case DW_CFA_offset_extended_sf
:
14112 return "DW_CFA_offset_extended_sf";
14113 case DW_CFA_def_cfa_sf
:
14114 return "DW_CFA_def_cfa_sf";
14115 case DW_CFA_def_cfa_offset_sf
:
14116 return "DW_CFA_def_cfa_offset_sf";
14117 case DW_CFA_val_offset
:
14118 return "DW_CFA_val_offset";
14119 case DW_CFA_val_offset_sf
:
14120 return "DW_CFA_val_offset_sf";
14121 case DW_CFA_val_expression
:
14122 return "DW_CFA_val_expression";
14123 /* SGI/MIPS specific. */
14124 case DW_CFA_MIPS_advance_loc8
:
14125 return "DW_CFA_MIPS_advance_loc8";
14126 /* GNU extensions. */
14127 case DW_CFA_GNU_window_save
:
14128 return "DW_CFA_GNU_window_save";
14129 case DW_CFA_GNU_args_size
:
14130 return "DW_CFA_GNU_args_size";
14131 case DW_CFA_GNU_negative_offset_extended
:
14132 return "DW_CFA_GNU_negative_offset_extended";
14134 return "DW_CFA_<unknown>";
14140 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
14144 print_spaces (indent
, f
);
14145 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
14146 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
14148 if (die
->parent
!= NULL
)
14150 print_spaces (indent
, f
);
14151 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
14152 die
->parent
->offset
.sect_off
);
14155 print_spaces (indent
, f
);
14156 fprintf_unfiltered (f
, " has children: %s\n",
14157 dwarf_bool_name (die
->child
!= NULL
));
14159 print_spaces (indent
, f
);
14160 fprintf_unfiltered (f
, " attributes:\n");
14162 for (i
= 0; i
< die
->num_attrs
; ++i
)
14164 print_spaces (indent
, f
);
14165 fprintf_unfiltered (f
, " %s (%s) ",
14166 dwarf_attr_name (die
->attrs
[i
].name
),
14167 dwarf_form_name (die
->attrs
[i
].form
));
14169 switch (die
->attrs
[i
].form
)
14172 fprintf_unfiltered (f
, "address: ");
14173 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
14175 case DW_FORM_block2
:
14176 case DW_FORM_block4
:
14177 case DW_FORM_block
:
14178 case DW_FORM_block1
:
14179 fprintf_unfiltered (f
, "block: size %d",
14180 DW_BLOCK (&die
->attrs
[i
])->size
);
14182 case DW_FORM_exprloc
:
14183 fprintf_unfiltered (f
, "expression: size %u",
14184 DW_BLOCK (&die
->attrs
[i
])->size
);
14186 case DW_FORM_ref_addr
:
14187 fprintf_unfiltered (f
, "ref address: ");
14188 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
14194 case DW_FORM_ref_udata
:
14195 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
14196 (long) (DW_UNSND (&die
->attrs
[i
])));
14198 case DW_FORM_data1
:
14199 case DW_FORM_data2
:
14200 case DW_FORM_data4
:
14201 case DW_FORM_data8
:
14202 case DW_FORM_udata
:
14203 case DW_FORM_sdata
:
14204 fprintf_unfiltered (f
, "constant: %s",
14205 pulongest (DW_UNSND (&die
->attrs
[i
])));
14207 case DW_FORM_sec_offset
:
14208 fprintf_unfiltered (f
, "section offset: %s",
14209 pulongest (DW_UNSND (&die
->attrs
[i
])));
14211 case DW_FORM_ref_sig8
:
14212 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
14213 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
14214 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
14216 fprintf_unfiltered (f
, "signatured type, offset: unknown");
14218 case DW_FORM_string
:
14220 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
14221 DW_STRING (&die
->attrs
[i
])
14222 ? DW_STRING (&die
->attrs
[i
]) : "",
14223 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
14226 if (DW_UNSND (&die
->attrs
[i
]))
14227 fprintf_unfiltered (f
, "flag: TRUE");
14229 fprintf_unfiltered (f
, "flag: FALSE");
14231 case DW_FORM_flag_present
:
14232 fprintf_unfiltered (f
, "flag: TRUE");
14234 case DW_FORM_indirect
:
14235 /* The reader will have reduced the indirect form to
14236 the "base form" so this form should not occur. */
14237 fprintf_unfiltered (f
,
14238 "unexpected attribute form: DW_FORM_indirect");
14241 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
14242 die
->attrs
[i
].form
);
14245 fprintf_unfiltered (f
, "\n");
14250 dump_die_for_error (struct die_info
*die
)
14252 dump_die_shallow (gdb_stderr
, 0, die
);
14256 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
14258 int indent
= level
* 4;
14260 gdb_assert (die
!= NULL
);
14262 if (level
>= max_level
)
14265 dump_die_shallow (f
, indent
, die
);
14267 if (die
->child
!= NULL
)
14269 print_spaces (indent
, f
);
14270 fprintf_unfiltered (f
, " Children:");
14271 if (level
+ 1 < max_level
)
14273 fprintf_unfiltered (f
, "\n");
14274 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
14278 fprintf_unfiltered (f
,
14279 " [not printed, max nesting level reached]\n");
14283 if (die
->sibling
!= NULL
&& level
> 0)
14285 dump_die_1 (f
, level
, max_level
, die
->sibling
);
14289 /* This is called from the pdie macro in gdbinit.in.
14290 It's not static so gcc will keep a copy callable from gdb. */
14293 dump_die (struct die_info
*die
, int max_level
)
14295 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
14299 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
14303 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
14309 /* DW_ADDR is always stored already as sect_offset; despite for the forms
14310 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
14313 is_ref_attr (struct attribute
*attr
)
14315 switch (attr
->form
)
14317 case DW_FORM_ref_addr
:
14322 case DW_FORM_ref_udata
:
14329 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
14333 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14335 sect_offset retval
= { DW_UNSND (attr
) };
14337 if (is_ref_attr (attr
))
14340 retval
.sect_off
= 0;
14341 complaint (&symfile_complaints
,
14342 _("unsupported die ref attribute form: '%s'"),
14343 dwarf_form_name (attr
->form
));
14347 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14348 * the value held by the attribute is not constant. */
14351 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
14353 if (attr
->form
== DW_FORM_sdata
)
14354 return DW_SND (attr
);
14355 else if (attr
->form
== DW_FORM_udata
14356 || attr
->form
== DW_FORM_data1
14357 || attr
->form
== DW_FORM_data2
14358 || attr
->form
== DW_FORM_data4
14359 || attr
->form
== DW_FORM_data8
)
14360 return DW_UNSND (attr
);
14363 complaint (&symfile_complaints
,
14364 _("Attribute value is not a constant (%s)"),
14365 dwarf_form_name (attr
->form
));
14366 return default_value
;
14370 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14371 unit and add it to our queue.
14372 The result is non-zero if PER_CU was queued, otherwise the result is zero
14373 meaning either PER_CU is already queued or it is already loaded. */
14376 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14377 struct dwarf2_per_cu_data
*per_cu
)
14379 /* We may arrive here during partial symbol reading, if we need full
14380 DIEs to process an unusual case (e.g. template arguments). Do
14381 not queue PER_CU, just tell our caller to load its DIEs. */
14382 if (dwarf2_per_objfile
->reading_partial_symbols
)
14384 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14389 /* Mark the dependence relation so that we don't flush PER_CU
14391 dwarf2_add_dependence (this_cu
, per_cu
);
14393 /* If it's already on the queue, we have nothing to do. */
14394 if (per_cu
->queued
)
14397 /* If the compilation unit is already loaded, just mark it as
14399 if (per_cu
->cu
!= NULL
)
14401 per_cu
->cu
->last_used
= 0;
14405 /* Add it to the queue. */
14406 queue_comp_unit (per_cu
);
14411 /* Follow reference or signature attribute ATTR of SRC_DIE.
14412 On entry *REF_CU is the CU of SRC_DIE.
14413 On exit *REF_CU is the CU of the result. */
14415 static struct die_info
*
14416 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14417 struct dwarf2_cu
**ref_cu
)
14419 struct die_info
*die
;
14421 if (is_ref_attr (attr
))
14422 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14423 else if (attr
->form
== DW_FORM_ref_sig8
)
14424 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14427 dump_die_for_error (src_die
);
14428 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14429 (*ref_cu
)->objfile
->name
);
14435 /* Follow reference OFFSET.
14436 On entry *REF_CU is the CU of the source die referencing OFFSET.
14437 On exit *REF_CU is the CU of the result.
14438 Returns NULL if OFFSET is invalid. */
14440 static struct die_info
*
14441 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
14443 struct die_info temp_die
;
14444 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14446 gdb_assert (cu
->per_cu
!= NULL
);
14450 if (cu
->per_cu
->debug_types_section
)
14452 /* .debug_types CUs cannot reference anything outside their CU.
14453 If they need to, they have to reference a signatured type via
14454 DW_FORM_ref_sig8. */
14455 if (! offset_in_cu_p (&cu
->header
, offset
))
14458 else if (! offset_in_cu_p (&cu
->header
, offset
))
14460 struct dwarf2_per_cu_data
*per_cu
;
14462 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14464 /* If necessary, add it to the queue and load its DIEs. */
14465 if (maybe_queue_comp_unit (cu
, per_cu
))
14466 load_full_comp_unit (per_cu
);
14468 target_cu
= per_cu
->cu
;
14470 else if (cu
->dies
== NULL
)
14472 /* We're loading full DIEs during partial symbol reading. */
14473 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14474 load_full_comp_unit (cu
->per_cu
);
14477 *ref_cu
= target_cu
;
14478 temp_die
.offset
= offset
;
14479 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
14482 /* Follow reference attribute ATTR of SRC_DIE.
14483 On entry *REF_CU is the CU of SRC_DIE.
14484 On exit *REF_CU is the CU of the result. */
14486 static struct die_info
*
14487 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14488 struct dwarf2_cu
**ref_cu
)
14490 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
14491 struct dwarf2_cu
*cu
= *ref_cu
;
14492 struct die_info
*die
;
14494 die
= follow_die_offset (offset
, ref_cu
);
14496 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14497 "at 0x%x [in module %s]"),
14498 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
14503 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14504 Returned value is intended for DW_OP_call*. Returned
14505 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14507 struct dwarf2_locexpr_baton
14508 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
14509 struct dwarf2_per_cu_data
*per_cu
,
14510 CORE_ADDR (*get_frame_pc
) (void *baton
),
14513 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
14514 struct dwarf2_cu
*cu
;
14515 struct die_info
*die
;
14516 struct attribute
*attr
;
14517 struct dwarf2_locexpr_baton retval
;
14519 dw2_setup (per_cu
->objfile
);
14521 if (per_cu
->cu
== NULL
)
14525 die
= follow_die_offset (offset
, &cu
);
14527 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14528 offset
.sect_off
, per_cu
->objfile
->name
);
14530 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14533 /* DWARF: "If there is no such attribute, then there is no effect.".
14534 DATA is ignored if SIZE is 0. */
14536 retval
.data
= NULL
;
14539 else if (attr_form_is_section_offset (attr
))
14541 struct dwarf2_loclist_baton loclist_baton
;
14542 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
14545 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
14547 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
14549 retval
.size
= size
;
14553 if (!attr_form_is_block (attr
))
14554 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14555 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14556 offset
.sect_off
, per_cu
->objfile
->name
);
14558 retval
.data
= DW_BLOCK (attr
)->data
;
14559 retval
.size
= DW_BLOCK (attr
)->size
;
14561 retval
.per_cu
= cu
->per_cu
;
14563 age_cached_comp_units ();
14568 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14572 dwarf2_get_die_type (cu_offset die_offset
,
14573 struct dwarf2_per_cu_data
*per_cu
)
14575 sect_offset die_offset_sect
;
14577 dw2_setup (per_cu
->objfile
);
14579 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
14580 return get_die_type_at_offset (die_offset_sect
, per_cu
);
14583 /* Follow the signature attribute ATTR in SRC_DIE.
14584 On entry *REF_CU is the CU of SRC_DIE.
14585 On exit *REF_CU is the CU of the result. */
14587 static struct die_info
*
14588 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
14589 struct dwarf2_cu
**ref_cu
)
14591 struct objfile
*objfile
= (*ref_cu
)->objfile
;
14592 struct die_info temp_die
;
14593 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14594 struct dwarf2_cu
*sig_cu
;
14595 struct die_info
*die
;
14597 /* sig_type will be NULL if the signatured type is missing from
14599 if (sig_type
== NULL
)
14600 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14601 "at 0x%x [in module %s]"),
14602 src_die
->offset
.sect_off
, objfile
->name
);
14604 /* If necessary, add it to the queue and load its DIEs. */
14606 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14607 read_signatured_type (sig_type
);
14609 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14611 sig_cu
= sig_type
->per_cu
.cu
;
14612 temp_die
.offset
.sect_off
= (sig_type
->per_cu
.offset
.sect_off
14613 + sig_type
->type_offset
.cu_off
);
14614 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
14615 temp_die
.offset
.sect_off
);
14622 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14623 "from DIE at 0x%x [in module %s]"),
14624 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
14627 /* Given an offset of a signatured type, return its signatured_type. */
14629 static struct signatured_type
*
14630 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14631 struct dwarf2_section_info
*section
,
14632 sect_offset offset
)
14634 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
14635 unsigned int length
, initial_length_size
;
14636 unsigned int sig_offset
;
14637 struct signatured_type find_entry
, *sig_type
;
14639 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14640 sig_offset
= (initial_length_size
14642 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14643 + 1 /*address_size*/);
14644 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14645 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14647 /* This is only used to lookup previously recorded types.
14648 If we didn't find it, it's our bug. */
14649 gdb_assert (sig_type
!= NULL
);
14650 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
14655 /* Load the DIEs associated with type unit PER_CU into memory. */
14658 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
14660 struct objfile
*objfile
= per_cu
->objfile
;
14661 struct dwarf2_section_info
*sect
= per_cu
->debug_types_section
;
14662 sect_offset offset
= per_cu
->offset
;
14663 struct signatured_type
*sig_type
;
14665 dwarf2_read_section (objfile
, sect
);
14667 /* We have the section offset, but we need the signature to do the
14668 hash table lookup. */
14669 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
14670 the signature to assert we found the right one.
14671 Ok, but it's a lot of work. We should simplify things so any needed
14672 assert doesn't require all this clumsiness. */
14673 sig_type
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14675 gdb_assert (&sig_type
->per_cu
== per_cu
);
14676 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
14678 read_signatured_type (sig_type
);
14680 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14683 /* die_reader_func for read_signatured_type.
14684 This is identical to load_full_comp_unit_reader,
14685 but is kept separate for now. */
14688 read_signatured_type_reader (const struct die_reader_specs
*reader
,
14689 gdb_byte
*info_ptr
,
14690 struct die_info
*comp_unit_die
,
14694 struct dwarf2_cu
*cu
= reader
->cu
;
14695 struct attribute
*attr
;
14697 gdb_assert (cu
->die_hash
== NULL
);
14699 htab_create_alloc_ex (cu
->header
.length
/ 12,
14703 &cu
->comp_unit_obstack
,
14704 hashtab_obstack_allocate
,
14705 dummy_obstack_deallocate
);
14708 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
14709 &info_ptr
, comp_unit_die
);
14710 cu
->dies
= comp_unit_die
;
14711 /* comp_unit_die is not stored in die_hash, no need. */
14713 /* We try not to read any attributes in this function, because not
14714 all CUs needed for references have been loaded yet, and symbol
14715 table processing isn't initialized. But we have to set the CU language,
14716 or we won't be able to build types correctly.
14717 Similarly, if we do not read the producer, we can not apply
14718 producer-specific interpretation. */
14719 prepare_one_comp_unit (cu
, cu
->dies
);
14722 /* Read in a signatured type and build its CU and DIEs. */
14725 read_signatured_type (struct signatured_type
*sig_type
)
14727 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
14729 gdb_assert (per_cu
->debug_types_section
);
14730 gdb_assert (per_cu
->cu
== NULL
);
14732 init_tu_and_read_dies (per_cu
, 1, read_signatured_type_reader
, NULL
);
14735 /* Decode simple location descriptions.
14736 Given a pointer to a dwarf block that defines a location, compute
14737 the location and return the value.
14739 NOTE drow/2003-11-18: This function is called in two situations
14740 now: for the address of static or global variables (partial symbols
14741 only) and for offsets into structures which are expected to be
14742 (more or less) constant. The partial symbol case should go away,
14743 and only the constant case should remain. That will let this
14744 function complain more accurately. A few special modes are allowed
14745 without complaint for global variables (for instance, global
14746 register values and thread-local values).
14748 A location description containing no operations indicates that the
14749 object is optimized out. The return value is 0 for that case.
14750 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14751 callers will only want a very basic result and this can become a
14754 Note that stack[0] is unused except as a default error return. */
14757 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14759 struct objfile
*objfile
= cu
->objfile
;
14761 int size
= blk
->size
;
14762 gdb_byte
*data
= blk
->data
;
14763 CORE_ADDR stack
[64];
14765 unsigned int bytes_read
, unsnd
;
14771 stack
[++stacki
] = 0;
14810 stack
[++stacki
] = op
- DW_OP_lit0
;
14845 stack
[++stacki
] = op
- DW_OP_reg0
;
14847 dwarf2_complex_location_expr_complaint ();
14851 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14853 stack
[++stacki
] = unsnd
;
14855 dwarf2_complex_location_expr_complaint ();
14859 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14864 case DW_OP_const1u
:
14865 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14869 case DW_OP_const1s
:
14870 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14874 case DW_OP_const2u
:
14875 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14879 case DW_OP_const2s
:
14880 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14884 case DW_OP_const4u
:
14885 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14889 case DW_OP_const4s
:
14890 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14894 case DW_OP_const8u
:
14895 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
14900 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14906 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14911 stack
[stacki
+ 1] = stack
[stacki
];
14916 stack
[stacki
- 1] += stack
[stacki
];
14920 case DW_OP_plus_uconst
:
14921 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14927 stack
[stacki
- 1] -= stack
[stacki
];
14932 /* If we're not the last op, then we definitely can't encode
14933 this using GDB's address_class enum. This is valid for partial
14934 global symbols, although the variable's address will be bogus
14937 dwarf2_complex_location_expr_complaint ();
14940 case DW_OP_GNU_push_tls_address
:
14941 /* The top of the stack has the offset from the beginning
14942 of the thread control block at which the variable is located. */
14943 /* Nothing should follow this operator, so the top of stack would
14945 /* This is valid for partial global symbols, but the variable's
14946 address will be bogus in the psymtab. Make it always at least
14947 non-zero to not look as a variable garbage collected by linker
14948 which have DW_OP_addr 0. */
14950 dwarf2_complex_location_expr_complaint ();
14954 case DW_OP_GNU_uninit
:
14959 const char *name
= dwarf_stack_op_name (op
);
14962 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14965 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14969 return (stack
[stacki
]);
14972 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14973 outside of the allocated space. Also enforce minimum>0. */
14974 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14976 complaint (&symfile_complaints
,
14977 _("location description stack overflow"));
14983 complaint (&symfile_complaints
,
14984 _("location description stack underflow"));
14988 return (stack
[stacki
]);
14991 /* memory allocation interface */
14993 static struct dwarf_block
*
14994 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14996 struct dwarf_block
*blk
;
14998 blk
= (struct dwarf_block
*)
14999 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
15003 static struct abbrev_info
*
15004 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
15006 struct abbrev_info
*abbrev
;
15008 abbrev
= (struct abbrev_info
*)
15009 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
15010 memset (abbrev
, 0, sizeof (struct abbrev_info
));
15014 static struct die_info
*
15015 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
15017 struct die_info
*die
;
15018 size_t size
= sizeof (struct die_info
);
15021 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
15023 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
15024 memset (die
, 0, sizeof (struct die_info
));
15029 /* Macro support. */
15031 /* Return the full name of file number I in *LH's file name table.
15032 Use COMP_DIR as the name of the current directory of the
15033 compilation. The result is allocated using xmalloc; the caller is
15034 responsible for freeing it. */
15036 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
15038 /* Is the file number a valid index into the line header's file name
15039 table? Remember that file numbers start with one, not zero. */
15040 if (1 <= file
&& file
<= lh
->num_file_names
)
15042 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15044 if (IS_ABSOLUTE_PATH (fe
->name
))
15045 return xstrdup (fe
->name
);
15053 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15059 dir_len
= strlen (dir
);
15060 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
15061 strcpy (full_name
, dir
);
15062 full_name
[dir_len
] = '/';
15063 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
15067 return xstrdup (fe
->name
);
15072 /* The compiler produced a bogus file number. We can at least
15073 record the macro definitions made in the file, even if we
15074 won't be able to find the file by name. */
15075 char fake_name
[80];
15077 sprintf (fake_name
, "<bad macro file number %d>", file
);
15079 complaint (&symfile_complaints
,
15080 _("bad file number in macro information (%d)"),
15083 return xstrdup (fake_name
);
15088 static struct macro_source_file
*
15089 macro_start_file (int file
, int line
,
15090 struct macro_source_file
*current_file
,
15091 const char *comp_dir
,
15092 struct line_header
*lh
, struct objfile
*objfile
)
15094 /* The full name of this source file. */
15095 char *full_name
= file_full_name (file
, lh
, comp_dir
);
15097 /* We don't create a macro table for this compilation unit
15098 at all until we actually get a filename. */
15099 if (! pending_macros
)
15100 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
15101 objfile
->macro_cache
);
15103 if (! current_file
)
15104 /* If we have no current file, then this must be the start_file
15105 directive for the compilation unit's main source file. */
15106 current_file
= macro_set_main (pending_macros
, full_name
);
15108 current_file
= macro_include (current_file
, line
, full_name
);
15112 return current_file
;
15116 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
15117 followed by a null byte. */
15119 copy_string (const char *buf
, int len
)
15121 char *s
= xmalloc (len
+ 1);
15123 memcpy (s
, buf
, len
);
15129 static const char *
15130 consume_improper_spaces (const char *p
, const char *body
)
15134 complaint (&symfile_complaints
,
15135 _("macro definition contains spaces "
15136 "in formal argument list:\n`%s'"),
15148 parse_macro_definition (struct macro_source_file
*file
, int line
,
15153 /* The body string takes one of two forms. For object-like macro
15154 definitions, it should be:
15156 <macro name> " " <definition>
15158 For function-like macro definitions, it should be:
15160 <macro name> "() " <definition>
15162 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
15164 Spaces may appear only where explicitly indicated, and in the
15167 The Dwarf 2 spec says that an object-like macro's name is always
15168 followed by a space, but versions of GCC around March 2002 omit
15169 the space when the macro's definition is the empty string.
15171 The Dwarf 2 spec says that there should be no spaces between the
15172 formal arguments in a function-like macro's formal argument list,
15173 but versions of GCC around March 2002 include spaces after the
15177 /* Find the extent of the macro name. The macro name is terminated
15178 by either a space or null character (for an object-like macro) or
15179 an opening paren (for a function-like macro). */
15180 for (p
= body
; *p
; p
++)
15181 if (*p
== ' ' || *p
== '(')
15184 if (*p
== ' ' || *p
== '\0')
15186 /* It's an object-like macro. */
15187 int name_len
= p
- body
;
15188 char *name
= copy_string (body
, name_len
);
15189 const char *replacement
;
15192 replacement
= body
+ name_len
+ 1;
15195 dwarf2_macro_malformed_definition_complaint (body
);
15196 replacement
= body
+ name_len
;
15199 macro_define_object (file
, line
, name
, replacement
);
15203 else if (*p
== '(')
15205 /* It's a function-like macro. */
15206 char *name
= copy_string (body
, p
- body
);
15209 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
15213 p
= consume_improper_spaces (p
, body
);
15215 /* Parse the formal argument list. */
15216 while (*p
&& *p
!= ')')
15218 /* Find the extent of the current argument name. */
15219 const char *arg_start
= p
;
15221 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
15224 if (! *p
|| p
== arg_start
)
15225 dwarf2_macro_malformed_definition_complaint (body
);
15228 /* Make sure argv has room for the new argument. */
15229 if (argc
>= argv_size
)
15232 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
15235 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
15238 p
= consume_improper_spaces (p
, body
);
15240 /* Consume the comma, if present. */
15245 p
= consume_improper_spaces (p
, body
);
15254 /* Perfectly formed definition, no complaints. */
15255 macro_define_function (file
, line
, name
,
15256 argc
, (const char **) argv
,
15258 else if (*p
== '\0')
15260 /* Complain, but do define it. */
15261 dwarf2_macro_malformed_definition_complaint (body
);
15262 macro_define_function (file
, line
, name
,
15263 argc
, (const char **) argv
,
15267 /* Just complain. */
15268 dwarf2_macro_malformed_definition_complaint (body
);
15271 /* Just complain. */
15272 dwarf2_macro_malformed_definition_complaint (body
);
15278 for (i
= 0; i
< argc
; i
++)
15284 dwarf2_macro_malformed_definition_complaint (body
);
15287 /* Skip some bytes from BYTES according to the form given in FORM.
15288 Returns the new pointer. */
15291 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
15292 enum dwarf_form form
,
15293 unsigned int offset_size
,
15294 struct dwarf2_section_info
*section
)
15296 unsigned int bytes_read
;
15300 case DW_FORM_data1
:
15305 case DW_FORM_data2
:
15309 case DW_FORM_data4
:
15313 case DW_FORM_data8
:
15317 case DW_FORM_string
:
15318 read_direct_string (abfd
, bytes
, &bytes_read
);
15319 bytes
+= bytes_read
;
15322 case DW_FORM_sec_offset
:
15324 bytes
+= offset_size
;
15327 case DW_FORM_block
:
15328 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
15329 bytes
+= bytes_read
;
15332 case DW_FORM_block1
:
15333 bytes
+= 1 + read_1_byte (abfd
, bytes
);
15335 case DW_FORM_block2
:
15336 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
15338 case DW_FORM_block4
:
15339 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
15342 case DW_FORM_sdata
:
15343 case DW_FORM_udata
:
15344 bytes
= skip_leb128 (abfd
, bytes
);
15350 complaint (&symfile_complaints
,
15351 _("invalid form 0x%x in `%s'"),
15353 section
->asection
->name
);
15361 /* A helper for dwarf_decode_macros that handles skipping an unknown
15362 opcode. Returns an updated pointer to the macro data buffer; or,
15363 on error, issues a complaint and returns NULL. */
15366 skip_unknown_opcode (unsigned int opcode
,
15367 gdb_byte
**opcode_definitions
,
15370 unsigned int offset_size
,
15371 struct dwarf2_section_info
*section
)
15373 unsigned int bytes_read
, i
;
15377 if (opcode_definitions
[opcode
] == NULL
)
15379 complaint (&symfile_complaints
,
15380 _("unrecognized DW_MACFINO opcode 0x%x"),
15385 defn
= opcode_definitions
[opcode
];
15386 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15387 defn
+= bytes_read
;
15389 for (i
= 0; i
< arg
; ++i
)
15391 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
15392 if (mac_ptr
== NULL
)
15394 /* skip_form_bytes already issued the complaint. */
15402 /* A helper function which parses the header of a macro section.
15403 If the macro section is the extended (for now called "GNU") type,
15404 then this updates *OFFSET_SIZE. Returns a pointer to just after
15405 the header, or issues a complaint and returns NULL on error. */
15408 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15411 unsigned int *offset_size
,
15412 int section_is_gnu
)
15414 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15416 if (section_is_gnu
)
15418 unsigned int version
, flags
;
15420 version
= read_2_bytes (abfd
, mac_ptr
);
15423 complaint (&symfile_complaints
,
15424 _("unrecognized version `%d' in .debug_macro section"),
15430 flags
= read_1_byte (abfd
, mac_ptr
);
15432 *offset_size
= (flags
& 1) ? 8 : 4;
15434 if ((flags
& 2) != 0)
15435 /* We don't need the line table offset. */
15436 mac_ptr
+= *offset_size
;
15438 /* Vendor opcode descriptions. */
15439 if ((flags
& 4) != 0)
15441 unsigned int i
, count
;
15443 count
= read_1_byte (abfd
, mac_ptr
);
15445 for (i
= 0; i
< count
; ++i
)
15447 unsigned int opcode
, bytes_read
;
15450 opcode
= read_1_byte (abfd
, mac_ptr
);
15452 opcode_definitions
[opcode
] = mac_ptr
;
15453 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15454 mac_ptr
+= bytes_read
;
15463 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15464 including DW_MACRO_GNU_transparent_include. */
15467 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15468 struct macro_source_file
*current_file
,
15469 struct line_header
*lh
, char *comp_dir
,
15470 struct dwarf2_section_info
*section
,
15471 int section_is_gnu
,
15472 unsigned int offset_size
,
15473 struct objfile
*objfile
,
15474 htab_t include_hash
)
15476 enum dwarf_macro_record_type macinfo_type
;
15477 int at_commandline
;
15478 gdb_byte
*opcode_definitions
[256];
15480 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15481 &offset_size
, section_is_gnu
);
15482 if (mac_ptr
== NULL
)
15484 /* We already issued a complaint. */
15488 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15489 GDB is still reading the definitions from command line. First
15490 DW_MACINFO_start_file will need to be ignored as it was already executed
15491 to create CURRENT_FILE for the main source holding also the command line
15492 definitions. On first met DW_MACINFO_start_file this flag is reset to
15493 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15495 at_commandline
= 1;
15499 /* Do we at least have room for a macinfo type byte? */
15500 if (mac_ptr
>= mac_end
)
15502 dwarf2_macros_too_long_complaint (section
);
15506 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15509 /* Note that we rely on the fact that the corresponding GNU and
15510 DWARF constants are the same. */
15511 switch (macinfo_type
)
15513 /* A zero macinfo type indicates the end of the macro
15518 case DW_MACRO_GNU_define
:
15519 case DW_MACRO_GNU_undef
:
15520 case DW_MACRO_GNU_define_indirect
:
15521 case DW_MACRO_GNU_undef_indirect
:
15523 unsigned int bytes_read
;
15528 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15529 mac_ptr
+= bytes_read
;
15531 if (macinfo_type
== DW_MACRO_GNU_define
15532 || macinfo_type
== DW_MACRO_GNU_undef
)
15534 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15535 mac_ptr
+= bytes_read
;
15539 LONGEST str_offset
;
15541 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15542 mac_ptr
+= offset_size
;
15544 body
= read_indirect_string_at_offset (abfd
, str_offset
);
15547 is_define
= (macinfo_type
== DW_MACRO_GNU_define
15548 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
15549 if (! current_file
)
15551 /* DWARF violation as no main source is present. */
15552 complaint (&symfile_complaints
,
15553 _("debug info with no main source gives macro %s "
15555 is_define
? _("definition") : _("undefinition"),
15559 if ((line
== 0 && !at_commandline
)
15560 || (line
!= 0 && at_commandline
))
15561 complaint (&symfile_complaints
,
15562 _("debug info gives %s macro %s with %s line %d: %s"),
15563 at_commandline
? _("command-line") : _("in-file"),
15564 is_define
? _("definition") : _("undefinition"),
15565 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
15568 parse_macro_definition (current_file
, line
, body
);
15571 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
15572 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
15573 macro_undef (current_file
, line
, body
);
15578 case DW_MACRO_GNU_start_file
:
15580 unsigned int bytes_read
;
15583 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15584 mac_ptr
+= bytes_read
;
15585 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15586 mac_ptr
+= bytes_read
;
15588 if ((line
== 0 && !at_commandline
)
15589 || (line
!= 0 && at_commandline
))
15590 complaint (&symfile_complaints
,
15591 _("debug info gives source %d included "
15592 "from %s at %s line %d"),
15593 file
, at_commandline
? _("command-line") : _("file"),
15594 line
== 0 ? _("zero") : _("non-zero"), line
);
15596 if (at_commandline
)
15598 /* This DW_MACRO_GNU_start_file was executed in the
15600 at_commandline
= 0;
15603 current_file
= macro_start_file (file
, line
,
15604 current_file
, comp_dir
,
15609 case DW_MACRO_GNU_end_file
:
15610 if (! current_file
)
15611 complaint (&symfile_complaints
,
15612 _("macro debug info has an unmatched "
15613 "`close_file' directive"));
15616 current_file
= current_file
->included_by
;
15617 if (! current_file
)
15619 enum dwarf_macro_record_type next_type
;
15621 /* GCC circa March 2002 doesn't produce the zero
15622 type byte marking the end of the compilation
15623 unit. Complain if it's not there, but exit no
15626 /* Do we at least have room for a macinfo type byte? */
15627 if (mac_ptr
>= mac_end
)
15629 dwarf2_macros_too_long_complaint (section
);
15633 /* We don't increment mac_ptr here, so this is just
15635 next_type
= read_1_byte (abfd
, mac_ptr
);
15636 if (next_type
!= 0)
15637 complaint (&symfile_complaints
,
15638 _("no terminating 0-type entry for "
15639 "macros in `.debug_macinfo' section"));
15646 case DW_MACRO_GNU_transparent_include
:
15651 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15652 mac_ptr
+= offset_size
;
15654 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
15657 /* This has actually happened; see
15658 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
15659 complaint (&symfile_complaints
,
15660 _("recursive DW_MACRO_GNU_transparent_include in "
15661 ".debug_macro section"));
15667 dwarf_decode_macro_bytes (abfd
,
15668 section
->buffer
+ offset
,
15669 mac_end
, current_file
,
15671 section
, section_is_gnu
,
15672 offset_size
, objfile
, include_hash
);
15674 htab_remove_elt (include_hash
, mac_ptr
);
15679 case DW_MACINFO_vendor_ext
:
15680 if (!section_is_gnu
)
15682 unsigned int bytes_read
;
15685 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15686 mac_ptr
+= bytes_read
;
15687 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15688 mac_ptr
+= bytes_read
;
15690 /* We don't recognize any vendor extensions. */
15696 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15697 mac_ptr
, abfd
, offset_size
,
15699 if (mac_ptr
== NULL
)
15703 } while (macinfo_type
!= 0);
15707 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
15708 char *comp_dir
, bfd
*abfd
,
15709 struct dwarf2_cu
*cu
,
15710 struct dwarf2_section_info
*section
,
15711 int section_is_gnu
)
15713 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15714 gdb_byte
*mac_ptr
, *mac_end
;
15715 struct macro_source_file
*current_file
= 0;
15716 enum dwarf_macro_record_type macinfo_type
;
15717 unsigned int offset_size
= cu
->header
.offset_size
;
15718 gdb_byte
*opcode_definitions
[256];
15719 struct cleanup
*cleanup
;
15720 htab_t include_hash
;
15723 dwarf2_read_section (objfile
, section
);
15724 if (section
->buffer
== NULL
)
15726 complaint (&symfile_complaints
, _("missing %s section"),
15727 section
->asection
->name
);
15731 /* First pass: Find the name of the base filename.
15732 This filename is needed in order to process all macros whose definition
15733 (or undefinition) comes from the command line. These macros are defined
15734 before the first DW_MACINFO_start_file entry, and yet still need to be
15735 associated to the base file.
15737 To determine the base file name, we scan the macro definitions until we
15738 reach the first DW_MACINFO_start_file entry. We then initialize
15739 CURRENT_FILE accordingly so that any macro definition found before the
15740 first DW_MACINFO_start_file can still be associated to the base file. */
15742 mac_ptr
= section
->buffer
+ offset
;
15743 mac_end
= section
->buffer
+ section
->size
;
15745 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15746 &offset_size
, section_is_gnu
);
15747 if (mac_ptr
== NULL
)
15749 /* We already issued a complaint. */
15755 /* Do we at least have room for a macinfo type byte? */
15756 if (mac_ptr
>= mac_end
)
15758 /* Complaint is printed during the second pass as GDB will probably
15759 stop the first pass earlier upon finding
15760 DW_MACINFO_start_file. */
15764 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15767 /* Note that we rely on the fact that the corresponding GNU and
15768 DWARF constants are the same. */
15769 switch (macinfo_type
)
15771 /* A zero macinfo type indicates the end of the macro
15776 case DW_MACRO_GNU_define
:
15777 case DW_MACRO_GNU_undef
:
15778 /* Only skip the data by MAC_PTR. */
15780 unsigned int bytes_read
;
15782 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15783 mac_ptr
+= bytes_read
;
15784 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15785 mac_ptr
+= bytes_read
;
15789 case DW_MACRO_GNU_start_file
:
15791 unsigned int bytes_read
;
15794 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15795 mac_ptr
+= bytes_read
;
15796 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15797 mac_ptr
+= bytes_read
;
15799 current_file
= macro_start_file (file
, line
, current_file
,
15800 comp_dir
, lh
, objfile
);
15804 case DW_MACRO_GNU_end_file
:
15805 /* No data to skip by MAC_PTR. */
15808 case DW_MACRO_GNU_define_indirect
:
15809 case DW_MACRO_GNU_undef_indirect
:
15811 unsigned int bytes_read
;
15813 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15814 mac_ptr
+= bytes_read
;
15815 mac_ptr
+= offset_size
;
15819 case DW_MACRO_GNU_transparent_include
:
15820 /* Note that, according to the spec, a transparent include
15821 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15822 skip this opcode. */
15823 mac_ptr
+= offset_size
;
15826 case DW_MACINFO_vendor_ext
:
15827 /* Only skip the data by MAC_PTR. */
15828 if (!section_is_gnu
)
15830 unsigned int bytes_read
;
15832 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15833 mac_ptr
+= bytes_read
;
15834 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15835 mac_ptr
+= bytes_read
;
15840 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15841 mac_ptr
, abfd
, offset_size
,
15843 if (mac_ptr
== NULL
)
15847 } while (macinfo_type
!= 0 && current_file
== NULL
);
15849 /* Second pass: Process all entries.
15851 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15852 command-line macro definitions/undefinitions. This flag is unset when we
15853 reach the first DW_MACINFO_start_file entry. */
15855 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
15856 NULL
, xcalloc
, xfree
);
15857 cleanup
= make_cleanup_htab_delete (include_hash
);
15858 mac_ptr
= section
->buffer
+ offset
;
15859 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
15861 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
15862 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
15863 offset_size
, objfile
, include_hash
);
15864 do_cleanups (cleanup
);
15867 /* Check if the attribute's form is a DW_FORM_block*
15868 if so return true else false. */
15871 attr_form_is_block (struct attribute
*attr
)
15873 return (attr
== NULL
? 0 :
15874 attr
->form
== DW_FORM_block1
15875 || attr
->form
== DW_FORM_block2
15876 || attr
->form
== DW_FORM_block4
15877 || attr
->form
== DW_FORM_block
15878 || attr
->form
== DW_FORM_exprloc
);
15881 /* Return non-zero if ATTR's value is a section offset --- classes
15882 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15883 You may use DW_UNSND (attr) to retrieve such offsets.
15885 Section 7.5.4, "Attribute Encodings", explains that no attribute
15886 may have a value that belongs to more than one of these classes; it
15887 would be ambiguous if we did, because we use the same forms for all
15891 attr_form_is_section_offset (struct attribute
*attr
)
15893 return (attr
->form
== DW_FORM_data4
15894 || attr
->form
== DW_FORM_data8
15895 || attr
->form
== DW_FORM_sec_offset
);
15898 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15899 zero otherwise. When this function returns true, you can apply
15900 dwarf2_get_attr_constant_value to it.
15902 However, note that for some attributes you must check
15903 attr_form_is_section_offset before using this test. DW_FORM_data4
15904 and DW_FORM_data8 are members of both the constant class, and of
15905 the classes that contain offsets into other debug sections
15906 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15907 that, if an attribute's can be either a constant or one of the
15908 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15909 taken as section offsets, not constants. */
15912 attr_form_is_constant (struct attribute
*attr
)
15914 switch (attr
->form
)
15916 case DW_FORM_sdata
:
15917 case DW_FORM_udata
:
15918 case DW_FORM_data1
:
15919 case DW_FORM_data2
:
15920 case DW_FORM_data4
:
15921 case DW_FORM_data8
:
15928 /* A helper function that fills in a dwarf2_loclist_baton. */
15931 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15932 struct dwarf2_loclist_baton
*baton
,
15933 struct attribute
*attr
)
15935 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15936 &dwarf2_per_objfile
->loc
);
15938 baton
->per_cu
= cu
->per_cu
;
15939 gdb_assert (baton
->per_cu
);
15940 /* We don't know how long the location list is, but make sure we
15941 don't run off the edge of the section. */
15942 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15943 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15944 baton
->base_address
= cu
->base_address
;
15948 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15949 struct dwarf2_cu
*cu
)
15951 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15953 if (attr_form_is_section_offset (attr
)
15954 /* ".debug_loc" may not exist at all, or the offset may be outside
15955 the section. If so, fall through to the complaint in the
15957 && DW_UNSND (attr
) < dwarf2_section_size (objfile
,
15958 &dwarf2_per_objfile
->loc
))
15960 struct dwarf2_loclist_baton
*baton
;
15962 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15963 sizeof (struct dwarf2_loclist_baton
));
15965 fill_in_loclist_baton (cu
, baton
, attr
);
15967 if (cu
->base_known
== 0)
15968 complaint (&symfile_complaints
,
15969 _("Location list used without "
15970 "specifying the CU base address."));
15972 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15973 SYMBOL_LOCATION_BATON (sym
) = baton
;
15977 struct dwarf2_locexpr_baton
*baton
;
15979 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15980 sizeof (struct dwarf2_locexpr_baton
));
15981 baton
->per_cu
= cu
->per_cu
;
15982 gdb_assert (baton
->per_cu
);
15984 if (attr_form_is_block (attr
))
15986 /* Note that we're just copying the block's data pointer
15987 here, not the actual data. We're still pointing into the
15988 info_buffer for SYM's objfile; right now we never release
15989 that buffer, but when we do clean up properly this may
15991 baton
->size
= DW_BLOCK (attr
)->size
;
15992 baton
->data
= DW_BLOCK (attr
)->data
;
15996 dwarf2_invalid_attrib_class_complaint ("location description",
15997 SYMBOL_NATURAL_NAME (sym
));
16001 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16002 SYMBOL_LOCATION_BATON (sym
) = baton
;
16006 /* Return the OBJFILE associated with the compilation unit CU. If CU
16007 came from a separate debuginfo file, then the master objfile is
16011 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
16013 struct objfile
*objfile
= per_cu
->objfile
;
16015 /* Return the master objfile, so that we can report and look up the
16016 correct file containing this variable. */
16017 if (objfile
->separate_debug_objfile_backlink
)
16018 objfile
= objfile
->separate_debug_objfile_backlink
;
16023 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
16024 (CU_HEADERP is unused in such case) or prepare a temporary copy at
16025 CU_HEADERP first. */
16027 static const struct comp_unit_head
*
16028 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
16029 struct dwarf2_per_cu_data
*per_cu
)
16031 struct objfile
*objfile
;
16032 struct dwarf2_per_objfile
*per_objfile
;
16033 gdb_byte
*info_ptr
;
16036 return &per_cu
->cu
->header
;
16038 objfile
= per_cu
->objfile
;
16039 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16040 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
.sect_off
;
16042 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
16043 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
16048 /* Return the address size given in the compilation unit header for CU. */
16051 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16053 struct comp_unit_head cu_header_local
;
16054 const struct comp_unit_head
*cu_headerp
;
16056 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16058 return cu_headerp
->addr_size
;
16061 /* Return the offset size given in the compilation unit header for CU. */
16064 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
16066 struct comp_unit_head cu_header_local
;
16067 const struct comp_unit_head
*cu_headerp
;
16069 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16071 return cu_headerp
->offset_size
;
16074 /* See its dwarf2loc.h declaration. */
16077 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16079 struct comp_unit_head cu_header_local
;
16080 const struct comp_unit_head
*cu_headerp
;
16082 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16084 if (cu_headerp
->version
== 2)
16085 return cu_headerp
->addr_size
;
16087 return cu_headerp
->offset_size
;
16090 /* Return the text offset of the CU. The returned offset comes from
16091 this CU's objfile. If this objfile came from a separate debuginfo
16092 file, then the offset may be different from the corresponding
16093 offset in the parent objfile. */
16096 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
16098 struct objfile
*objfile
= per_cu
->objfile
;
16100 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16103 /* Locate the .debug_info compilation unit from CU's objfile which contains
16104 the DIE at OFFSET. Raises an error on failure. */
16106 static struct dwarf2_per_cu_data
*
16107 dwarf2_find_containing_comp_unit (sect_offset offset
,
16108 struct objfile
*objfile
)
16110 struct dwarf2_per_cu_data
*this_cu
;
16114 high
= dwarf2_per_objfile
->n_comp_units
- 1;
16117 int mid
= low
+ (high
- low
) / 2;
16119 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
16120 >= offset
.sect_off
)
16125 gdb_assert (low
== high
);
16126 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
16130 error (_("Dwarf Error: could not find partial DIE containing "
16131 "offset 0x%lx [in module %s]"),
16132 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16134 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
16135 <= offset
.sect_off
);
16136 return dwarf2_per_objfile
->all_comp_units
[low
-1];
16140 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
16141 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
16142 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
16143 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
16144 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
16149 /* Initialize dwarf2_cu CU, owned by PER_CU. */
16152 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
16154 memset (cu
, 0, sizeof (*cu
));
16156 cu
->per_cu
= per_cu
;
16157 cu
->objfile
= per_cu
->objfile
;
16158 obstack_init (&cu
->comp_unit_obstack
);
16161 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
16164 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
16166 struct attribute
*attr
;
16168 /* Set the language we're debugging. */
16169 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
16171 set_cu_language (DW_UNSND (attr
), cu
);
16174 cu
->language
= language_minimal
;
16175 cu
->language_defn
= language_def (cu
->language
);
16178 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
16180 cu
->producer
= DW_STRING (attr
);
16183 /* Release one cached compilation unit, CU. We unlink it from the tree
16184 of compilation units, but we don't remove it from the read_in_chain;
16185 the caller is responsible for that.
16186 NOTE: DATA is a void * because this function is also used as a
16187 cleanup routine. */
16190 free_heap_comp_unit (void *data
)
16192 struct dwarf2_cu
*cu
= data
;
16194 gdb_assert (cu
->per_cu
!= NULL
);
16195 cu
->per_cu
->cu
= NULL
;
16198 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16203 /* This cleanup function is passed the address of a dwarf2_cu on the stack
16204 when we're finished with it. We can't free the pointer itself, but be
16205 sure to unlink it from the cache. Also release any associated storage. */
16208 free_stack_comp_unit (void *data
)
16210 struct dwarf2_cu
*cu
= data
;
16212 gdb_assert (cu
->per_cu
!= NULL
);
16213 cu
->per_cu
->cu
= NULL
;
16216 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16217 cu
->partial_dies
= NULL
;
16220 /* Free all cached compilation units. */
16223 free_cached_comp_units (void *data
)
16225 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16227 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16228 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16229 while (per_cu
!= NULL
)
16231 struct dwarf2_per_cu_data
*next_cu
;
16233 next_cu
= per_cu
->cu
->read_in_chain
;
16235 free_heap_comp_unit (per_cu
->cu
);
16236 *last_chain
= next_cu
;
16242 /* Increase the age counter on each cached compilation unit, and free
16243 any that are too old. */
16246 age_cached_comp_units (void)
16248 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16250 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
16251 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16252 while (per_cu
!= NULL
)
16254 per_cu
->cu
->last_used
++;
16255 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
16256 dwarf2_mark (per_cu
->cu
);
16257 per_cu
= per_cu
->cu
->read_in_chain
;
16260 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16261 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16262 while (per_cu
!= NULL
)
16264 struct dwarf2_per_cu_data
*next_cu
;
16266 next_cu
= per_cu
->cu
->read_in_chain
;
16268 if (!per_cu
->cu
->mark
)
16270 free_heap_comp_unit (per_cu
->cu
);
16271 *last_chain
= next_cu
;
16274 last_chain
= &per_cu
->cu
->read_in_chain
;
16280 /* Remove a single compilation unit from the cache. */
16283 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
16285 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16287 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16288 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16289 while (per_cu
!= NULL
)
16291 struct dwarf2_per_cu_data
*next_cu
;
16293 next_cu
= per_cu
->cu
->read_in_chain
;
16295 if (per_cu
== target_per_cu
)
16297 free_heap_comp_unit (per_cu
->cu
);
16299 *last_chain
= next_cu
;
16303 last_chain
= &per_cu
->cu
->read_in_chain
;
16309 /* Release all extra memory associated with OBJFILE. */
16312 dwarf2_free_objfile (struct objfile
*objfile
)
16314 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16316 if (dwarf2_per_objfile
== NULL
)
16319 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16320 free_cached_comp_units (NULL
);
16322 if (dwarf2_per_objfile
->quick_file_names_table
)
16323 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
16325 /* Everything else should be on the objfile obstack. */
16328 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
16329 We store these in a hash table separate from the DIEs, and preserve them
16330 when the DIEs are flushed out of cache.
16332 The CU "per_cu" pointer is needed because offset alone is not enough to
16333 uniquely identify the type. A file may have multiple .debug_types sections.
16334 We have to use something in dwarf2_per_cu_data (or the pointer to it)
16335 because we can enter the lookup routine, get_die_type_at_offset, from
16336 outside this file, and thus won't necessarily have PER_CU->cu.
16337 Fortunately, PER_CU is stable for the life of the objfile. */
16339 struct dwarf2_per_cu_offset_and_type
16341 const struct dwarf2_per_cu_data
*per_cu
;
16342 sect_offset offset
;
16346 /* Hash function for a dwarf2_per_cu_offset_and_type. */
16349 per_cu_offset_and_type_hash (const void *item
)
16351 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
16353 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
16356 /* Equality function for a dwarf2_per_cu_offset_and_type. */
16359 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
16361 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
16362 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
16364 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
16365 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
16368 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16369 table if necessary. For convenience, return TYPE.
16371 The DIEs reading must have careful ordering to:
16372 * Not cause infite loops trying to read in DIEs as a prerequisite for
16373 reading current DIE.
16374 * Not trying to dereference contents of still incompletely read in types
16375 while reading in other DIEs.
16376 * Enable referencing still incompletely read in types just by a pointer to
16377 the type without accessing its fields.
16379 Therefore caller should follow these rules:
16380 * Try to fetch any prerequisite types we may need to build this DIE type
16381 before building the type and calling set_die_type.
16382 * After building type call set_die_type for current DIE as soon as
16383 possible before fetching more types to complete the current type.
16384 * Make the type as complete as possible before fetching more types. */
16386 static struct type
*
16387 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16389 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
16390 struct objfile
*objfile
= cu
->objfile
;
16392 /* For Ada types, make sure that the gnat-specific data is always
16393 initialized (if not already set). There are a few types where
16394 we should not be doing so, because the type-specific area is
16395 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16396 where the type-specific area is used to store the floatformat).
16397 But this is not a problem, because the gnat-specific information
16398 is actually not needed for these types. */
16399 if (need_gnat_info (cu
)
16400 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16401 && TYPE_CODE (type
) != TYPE_CODE_FLT
16402 && !HAVE_GNAT_AUX_INFO (type
))
16403 INIT_GNAT_SPECIFIC (type
);
16405 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
16407 dwarf2_per_objfile
->die_type_hash
=
16408 htab_create_alloc_ex (127,
16409 per_cu_offset_and_type_hash
,
16410 per_cu_offset_and_type_eq
,
16412 &objfile
->objfile_obstack
,
16413 hashtab_obstack_allocate
,
16414 dummy_obstack_deallocate
);
16417 ofs
.per_cu
= cu
->per_cu
;
16418 ofs
.offset
= die
->offset
;
16420 slot
= (struct dwarf2_per_cu_offset_and_type
**)
16421 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
16423 complaint (&symfile_complaints
,
16424 _("A problem internal to GDB: DIE 0x%x has type already set"),
16425 die
->offset
.sect_off
);
16426 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16431 /* Look up the type for the die at OFFSET in the appropriate type_hash
16432 table, or return NULL if the die does not have a saved type. */
16434 static struct type
*
16435 get_die_type_at_offset (sect_offset offset
,
16436 struct dwarf2_per_cu_data
*per_cu
)
16438 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
16440 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
16443 ofs
.per_cu
= per_cu
;
16444 ofs
.offset
= offset
;
16445 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
16452 /* Look up the type for DIE in the appropriate type_hash table,
16453 or return NULL if DIE does not have a saved type. */
16455 static struct type
*
16456 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16458 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16461 /* Add a dependence relationship from CU to REF_PER_CU. */
16464 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16465 struct dwarf2_per_cu_data
*ref_per_cu
)
16469 if (cu
->dependencies
== NULL
)
16471 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16472 NULL
, &cu
->comp_unit_obstack
,
16473 hashtab_obstack_allocate
,
16474 dummy_obstack_deallocate
);
16476 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16478 *slot
= ref_per_cu
;
16481 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16482 Set the mark field in every compilation unit in the
16483 cache that we must keep because we are keeping CU. */
16486 dwarf2_mark_helper (void **slot
, void *data
)
16488 struct dwarf2_per_cu_data
*per_cu
;
16490 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
16492 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16493 reading of the chain. As such dependencies remain valid it is not much
16494 useful to track and undo them during QUIT cleanups. */
16495 if (per_cu
->cu
== NULL
)
16498 if (per_cu
->cu
->mark
)
16500 per_cu
->cu
->mark
= 1;
16502 if (per_cu
->cu
->dependencies
!= NULL
)
16503 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16508 /* Set the mark field in CU and in every other compilation unit in the
16509 cache that we must keep because we are keeping CU. */
16512 dwarf2_mark (struct dwarf2_cu
*cu
)
16517 if (cu
->dependencies
!= NULL
)
16518 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16522 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
16526 per_cu
->cu
->mark
= 0;
16527 per_cu
= per_cu
->cu
->read_in_chain
;
16531 /* Trivial hash function for partial_die_info: the hash value of a DIE
16532 is its offset in .debug_info for this objfile. */
16535 partial_die_hash (const void *item
)
16537 const struct partial_die_info
*part_die
= item
;
16539 return part_die
->offset
.sect_off
;
16542 /* Trivial comparison function for partial_die_info structures: two DIEs
16543 are equal if they have the same offset. */
16546 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
16548 const struct partial_die_info
*part_die_lhs
= item_lhs
;
16549 const struct partial_die_info
*part_die_rhs
= item_rhs
;
16551 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
16554 static struct cmd_list_element
*set_dwarf2_cmdlist
;
16555 static struct cmd_list_element
*show_dwarf2_cmdlist
;
16558 set_dwarf2_cmd (char *args
, int from_tty
)
16560 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
16564 show_dwarf2_cmd (char *args
, int from_tty
)
16566 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
16569 /* If section described by INFO was mmapped, munmap it now. */
16572 munmap_section_buffer (struct dwarf2_section_info
*info
)
16574 if (info
->map_addr
!= NULL
)
16579 res
= munmap (info
->map_addr
, info
->map_len
);
16580 gdb_assert (res
== 0);
16582 /* Without HAVE_MMAP, we should never be here to begin with. */
16583 gdb_assert_not_reached ("no mmap support");
16588 /* munmap debug sections for OBJFILE, if necessary. */
16591 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
16593 struct dwarf2_per_objfile
*data
= d
;
16595 struct dwarf2_section_info
*section
;
16597 /* This is sorted according to the order they're defined in to make it easier
16598 to keep in sync. */
16599 munmap_section_buffer (&data
->info
);
16600 munmap_section_buffer (&data
->abbrev
);
16601 munmap_section_buffer (&data
->line
);
16602 munmap_section_buffer (&data
->loc
);
16603 munmap_section_buffer (&data
->macinfo
);
16604 munmap_section_buffer (&data
->macro
);
16605 munmap_section_buffer (&data
->str
);
16606 munmap_section_buffer (&data
->ranges
);
16607 munmap_section_buffer (&data
->frame
);
16608 munmap_section_buffer (&data
->eh_frame
);
16609 munmap_section_buffer (&data
->gdb_index
);
16612 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
16614 munmap_section_buffer (section
);
16616 VEC_free (dwarf2_section_info_def
, data
->types
);
16620 /* The "save gdb-index" command. */
16622 /* The contents of the hash table we create when building the string
16624 struct strtab_entry
16626 offset_type offset
;
16630 /* Hash function for a strtab_entry.
16632 Function is used only during write_hash_table so no index format backward
16633 compatibility is needed. */
16636 hash_strtab_entry (const void *e
)
16638 const struct strtab_entry
*entry
= e
;
16639 return mapped_index_string_hash (INT_MAX
, entry
->str
);
16642 /* Equality function for a strtab_entry. */
16645 eq_strtab_entry (const void *a
, const void *b
)
16647 const struct strtab_entry
*ea
= a
;
16648 const struct strtab_entry
*eb
= b
;
16649 return !strcmp (ea
->str
, eb
->str
);
16652 /* Create a strtab_entry hash table. */
16655 create_strtab (void)
16657 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
16658 xfree
, xcalloc
, xfree
);
16661 /* Add a string to the constant pool. Return the string's offset in
16665 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
16668 struct strtab_entry entry
;
16669 struct strtab_entry
*result
;
16672 slot
= htab_find_slot (table
, &entry
, INSERT
);
16677 result
= XNEW (struct strtab_entry
);
16678 result
->offset
= obstack_object_size (cpool
);
16680 obstack_grow_str0 (cpool
, str
);
16683 return result
->offset
;
16686 /* An entry in the symbol table. */
16687 struct symtab_index_entry
16689 /* The name of the symbol. */
16691 /* The offset of the name in the constant pool. */
16692 offset_type index_offset
;
16693 /* A sorted vector of the indices of all the CUs that hold an object
16695 VEC (offset_type
) *cu_indices
;
16698 /* The symbol table. This is a power-of-2-sized hash table. */
16699 struct mapped_symtab
16701 offset_type n_elements
;
16703 struct symtab_index_entry
**data
;
16706 /* Hash function for a symtab_index_entry. */
16709 hash_symtab_entry (const void *e
)
16711 const struct symtab_index_entry
*entry
= e
;
16712 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
16713 sizeof (offset_type
) * VEC_length (offset_type
,
16714 entry
->cu_indices
),
16718 /* Equality function for a symtab_index_entry. */
16721 eq_symtab_entry (const void *a
, const void *b
)
16723 const struct symtab_index_entry
*ea
= a
;
16724 const struct symtab_index_entry
*eb
= b
;
16725 int len
= VEC_length (offset_type
, ea
->cu_indices
);
16726 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
16728 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
16729 VEC_address (offset_type
, eb
->cu_indices
),
16730 sizeof (offset_type
) * len
);
16733 /* Destroy a symtab_index_entry. */
16736 delete_symtab_entry (void *p
)
16738 struct symtab_index_entry
*entry
= p
;
16739 VEC_free (offset_type
, entry
->cu_indices
);
16743 /* Create a hash table holding symtab_index_entry objects. */
16746 create_symbol_hash_table (void)
16748 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
16749 delete_symtab_entry
, xcalloc
, xfree
);
16752 /* Create a new mapped symtab object. */
16754 static struct mapped_symtab
*
16755 create_mapped_symtab (void)
16757 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
16758 symtab
->n_elements
= 0;
16759 symtab
->size
= 1024;
16760 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16764 /* Destroy a mapped_symtab. */
16767 cleanup_mapped_symtab (void *p
)
16769 struct mapped_symtab
*symtab
= p
;
16770 /* The contents of the array are freed when the other hash table is
16772 xfree (symtab
->data
);
16776 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16779 Function is used only during write_hash_table so no index format backward
16780 compatibility is needed. */
16782 static struct symtab_index_entry
**
16783 find_slot (struct mapped_symtab
*symtab
, const char *name
)
16785 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
16787 index
= hash
& (symtab
->size
- 1);
16788 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
16792 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
16793 return &symtab
->data
[index
];
16794 index
= (index
+ step
) & (symtab
->size
- 1);
16798 /* Expand SYMTAB's hash table. */
16801 hash_expand (struct mapped_symtab
*symtab
)
16803 offset_type old_size
= symtab
->size
;
16805 struct symtab_index_entry
**old_entries
= symtab
->data
;
16808 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16810 for (i
= 0; i
< old_size
; ++i
)
16812 if (old_entries
[i
])
16814 struct symtab_index_entry
**slot
= find_slot (symtab
,
16815 old_entries
[i
]->name
);
16816 *slot
= old_entries
[i
];
16820 xfree (old_entries
);
16823 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16824 is the index of the CU in which the symbol appears. */
16827 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
16828 offset_type cu_index
)
16830 struct symtab_index_entry
**slot
;
16832 ++symtab
->n_elements
;
16833 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
16834 hash_expand (symtab
);
16836 slot
= find_slot (symtab
, name
);
16839 *slot
= XNEW (struct symtab_index_entry
);
16840 (*slot
)->name
= name
;
16841 (*slot
)->cu_indices
= NULL
;
16843 /* Don't push an index twice. Due to how we add entries we only
16844 have to check the last one. */
16845 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
16846 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
16847 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
16850 /* Add a vector of indices to the constant pool. */
16853 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
16854 struct symtab_index_entry
*entry
)
16858 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
16861 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
16862 offset_type val
= MAYBE_SWAP (len
);
16867 entry
->index_offset
= obstack_object_size (cpool
);
16869 obstack_grow (cpool
, &val
, sizeof (val
));
16871 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
16874 val
= MAYBE_SWAP (iter
);
16875 obstack_grow (cpool
, &val
, sizeof (val
));
16880 struct symtab_index_entry
*old_entry
= *slot
;
16881 entry
->index_offset
= old_entry
->index_offset
;
16884 return entry
->index_offset
;
16887 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16888 constant pool entries going into the obstack CPOOL. */
16891 write_hash_table (struct mapped_symtab
*symtab
,
16892 struct obstack
*output
, struct obstack
*cpool
)
16895 htab_t symbol_hash_table
;
16898 symbol_hash_table
= create_symbol_hash_table ();
16899 str_table
= create_strtab ();
16901 /* We add all the index vectors to the constant pool first, to
16902 ensure alignment is ok. */
16903 for (i
= 0; i
< symtab
->size
; ++i
)
16905 if (symtab
->data
[i
])
16906 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
16909 /* Now write out the hash table. */
16910 for (i
= 0; i
< symtab
->size
; ++i
)
16912 offset_type str_off
, vec_off
;
16914 if (symtab
->data
[i
])
16916 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
16917 vec_off
= symtab
->data
[i
]->index_offset
;
16921 /* While 0 is a valid constant pool index, it is not valid
16922 to have 0 for both offsets. */
16927 str_off
= MAYBE_SWAP (str_off
);
16928 vec_off
= MAYBE_SWAP (vec_off
);
16930 obstack_grow (output
, &str_off
, sizeof (str_off
));
16931 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
16934 htab_delete (str_table
);
16935 htab_delete (symbol_hash_table
);
16938 /* Struct to map psymtab to CU index in the index file. */
16939 struct psymtab_cu_index_map
16941 struct partial_symtab
*psymtab
;
16942 unsigned int cu_index
;
16946 hash_psymtab_cu_index (const void *item
)
16948 const struct psymtab_cu_index_map
*map
= item
;
16950 return htab_hash_pointer (map
->psymtab
);
16954 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16956 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16957 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16959 return lhs
->psymtab
== rhs
->psymtab
;
16962 /* Helper struct for building the address table. */
16963 struct addrmap_index_data
16965 struct objfile
*objfile
;
16966 struct obstack
*addr_obstack
;
16967 htab_t cu_index_htab
;
16969 /* Non-zero if the previous_* fields are valid.
16970 We can't write an entry until we see the next entry (since it is only then
16971 that we know the end of the entry). */
16972 int previous_valid
;
16973 /* Index of the CU in the table of all CUs in the index file. */
16974 unsigned int previous_cu_index
;
16975 /* Start address of the CU. */
16976 CORE_ADDR previous_cu_start
;
16979 /* Write an address entry to OBSTACK. */
16982 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16983 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16985 offset_type cu_index_to_write
;
16987 CORE_ADDR baseaddr
;
16989 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16991 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16992 obstack_grow (obstack
, addr
, 8);
16993 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16994 obstack_grow (obstack
, addr
, 8);
16995 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16996 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16999 /* Worker function for traversing an addrmap to build the address table. */
17002 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
17004 struct addrmap_index_data
*data
= datap
;
17005 struct partial_symtab
*pst
= obj
;
17006 offset_type cu_index
;
17009 if (data
->previous_valid
)
17010 add_address_entry (data
->objfile
, data
->addr_obstack
,
17011 data
->previous_cu_start
, start_addr
,
17012 data
->previous_cu_index
);
17014 data
->previous_cu_start
= start_addr
;
17017 struct psymtab_cu_index_map find_map
, *map
;
17018 find_map
.psymtab
= pst
;
17019 map
= htab_find (data
->cu_index_htab
, &find_map
);
17020 gdb_assert (map
!= NULL
);
17021 data
->previous_cu_index
= map
->cu_index
;
17022 data
->previous_valid
= 1;
17025 data
->previous_valid
= 0;
17030 /* Write OBJFILE's address map to OBSTACK.
17031 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
17032 in the index file. */
17035 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
17036 htab_t cu_index_htab
)
17038 struct addrmap_index_data addrmap_index_data
;
17040 /* When writing the address table, we have to cope with the fact that
17041 the addrmap iterator only provides the start of a region; we have to
17042 wait until the next invocation to get the start of the next region. */
17044 addrmap_index_data
.objfile
= objfile
;
17045 addrmap_index_data
.addr_obstack
= obstack
;
17046 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
17047 addrmap_index_data
.previous_valid
= 0;
17049 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
17050 &addrmap_index_data
);
17052 /* It's highly unlikely the last entry (end address = 0xff...ff)
17053 is valid, but we should still handle it.
17054 The end address is recorded as the start of the next region, but that
17055 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
17057 if (addrmap_index_data
.previous_valid
)
17058 add_address_entry (objfile
, obstack
,
17059 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
17060 addrmap_index_data
.previous_cu_index
);
17063 /* Add a list of partial symbols to SYMTAB. */
17066 write_psymbols (struct mapped_symtab
*symtab
,
17068 struct partial_symbol
**psymp
,
17070 offset_type cu_index
,
17073 for (; count
-- > 0; ++psymp
)
17075 void **slot
, *lookup
;
17077 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
17078 error (_("Ada is not currently supported by the index"));
17080 /* We only want to add a given psymbol once. However, we also
17081 want to account for whether it is global or static. So, we
17082 may add it twice, using slightly different values. */
17085 uintptr_t val
= 1 | (uintptr_t) *psymp
;
17087 lookup
= (void *) val
;
17092 /* Only add a given psymbol once. */
17093 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
17097 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (*psymp
), cu_index
);
17102 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
17103 exception if there is an error. */
17106 write_obstack (FILE *file
, struct obstack
*obstack
)
17108 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
17110 != obstack_object_size (obstack
))
17111 error (_("couldn't data write to file"));
17114 /* Unlink a file if the argument is not NULL. */
17117 unlink_if_set (void *p
)
17119 char **filename
= p
;
17121 unlink (*filename
);
17124 /* A helper struct used when iterating over debug_types. */
17125 struct signatured_type_index_data
17127 struct objfile
*objfile
;
17128 struct mapped_symtab
*symtab
;
17129 struct obstack
*types_list
;
17134 /* A helper function that writes a single signatured_type to an
17138 write_one_signatured_type (void **slot
, void *d
)
17140 struct signatured_type_index_data
*info
= d
;
17141 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
17142 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
17143 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17146 write_psymbols (info
->symtab
,
17148 info
->objfile
->global_psymbols
.list
17149 + psymtab
->globals_offset
,
17150 psymtab
->n_global_syms
, info
->cu_index
,
17152 write_psymbols (info
->symtab
,
17154 info
->objfile
->static_psymbols
.list
17155 + psymtab
->statics_offset
,
17156 psymtab
->n_static_syms
, info
->cu_index
,
17159 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17160 entry
->per_cu
.offset
.sect_off
);
17161 obstack_grow (info
->types_list
, val
, 8);
17162 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
.cu_off
);
17163 obstack_grow (info
->types_list
, val
, 8);
17164 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
17165 obstack_grow (info
->types_list
, val
, 8);
17172 /* Create an index file for OBJFILE in the directory DIR. */
17175 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
17177 struct cleanup
*cleanup
;
17178 char *filename
, *cleanup_filename
;
17179 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
17180 struct obstack cu_list
, types_cu_list
;
17183 struct mapped_symtab
*symtab
;
17184 offset_type val
, size_of_contents
, total_len
;
17188 htab_t cu_index_htab
;
17189 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
17191 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
17194 if (dwarf2_per_objfile
->using_index
)
17195 error (_("Cannot use an index to create the index"));
17197 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
17198 error (_("Cannot make an index when the file has multiple .debug_types sections"));
17200 if (stat (objfile
->name
, &st
) < 0)
17201 perror_with_name (objfile
->name
);
17203 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
17204 INDEX_SUFFIX
, (char *) NULL
);
17205 cleanup
= make_cleanup (xfree
, filename
);
17207 out_file
= fopen (filename
, "wb");
17209 error (_("Can't open `%s' for writing"), filename
);
17211 cleanup_filename
= filename
;
17212 make_cleanup (unlink_if_set
, &cleanup_filename
);
17214 symtab
= create_mapped_symtab ();
17215 make_cleanup (cleanup_mapped_symtab
, symtab
);
17217 obstack_init (&addr_obstack
);
17218 make_cleanup_obstack_free (&addr_obstack
);
17220 obstack_init (&cu_list
);
17221 make_cleanup_obstack_free (&cu_list
);
17223 obstack_init (&types_cu_list
);
17224 make_cleanup_obstack_free (&types_cu_list
);
17226 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
17227 NULL
, xcalloc
, xfree
);
17228 make_cleanup_htab_delete (psyms_seen
);
17230 /* While we're scanning CU's create a table that maps a psymtab pointer
17231 (which is what addrmap records) to its index (which is what is recorded
17232 in the index file). This will later be needed to write the address
17234 cu_index_htab
= htab_create_alloc (100,
17235 hash_psymtab_cu_index
,
17236 eq_psymtab_cu_index
,
17237 NULL
, xcalloc
, xfree
);
17238 make_cleanup_htab_delete (cu_index_htab
);
17239 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
17240 xmalloc (sizeof (struct psymtab_cu_index_map
)
17241 * dwarf2_per_objfile
->n_comp_units
);
17242 make_cleanup (xfree
, psymtab_cu_index_map
);
17244 /* The CU list is already sorted, so we don't need to do additional
17245 work here. Also, the debug_types entries do not appear in
17246 all_comp_units, but only in their own hash table. */
17247 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
17249 struct dwarf2_per_cu_data
*per_cu
17250 = dwarf2_per_objfile
->all_comp_units
[i
];
17251 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17253 struct psymtab_cu_index_map
*map
;
17256 write_psymbols (symtab
,
17258 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
17259 psymtab
->n_global_syms
, i
,
17261 write_psymbols (symtab
,
17263 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
17264 psymtab
->n_static_syms
, i
,
17267 map
= &psymtab_cu_index_map
[i
];
17268 map
->psymtab
= psymtab
;
17270 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
17271 gdb_assert (slot
!= NULL
);
17272 gdb_assert (*slot
== NULL
);
17275 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17276 per_cu
->offset
.sect_off
);
17277 obstack_grow (&cu_list
, val
, 8);
17278 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
17279 obstack_grow (&cu_list
, val
, 8);
17282 /* Dump the address map. */
17283 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
17285 /* Write out the .debug_type entries, if any. */
17286 if (dwarf2_per_objfile
->signatured_types
)
17288 struct signatured_type_index_data sig_data
;
17290 sig_data
.objfile
= objfile
;
17291 sig_data
.symtab
= symtab
;
17292 sig_data
.types_list
= &types_cu_list
;
17293 sig_data
.psyms_seen
= psyms_seen
;
17294 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
17295 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
17296 write_one_signatured_type
, &sig_data
);
17299 obstack_init (&constant_pool
);
17300 make_cleanup_obstack_free (&constant_pool
);
17301 obstack_init (&symtab_obstack
);
17302 make_cleanup_obstack_free (&symtab_obstack
);
17303 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
17305 obstack_init (&contents
);
17306 make_cleanup_obstack_free (&contents
);
17307 size_of_contents
= 6 * sizeof (offset_type
);
17308 total_len
= size_of_contents
;
17310 /* The version number. */
17311 val
= MAYBE_SWAP (6);
17312 obstack_grow (&contents
, &val
, sizeof (val
));
17314 /* The offset of the CU list from the start of the file. */
17315 val
= MAYBE_SWAP (total_len
);
17316 obstack_grow (&contents
, &val
, sizeof (val
));
17317 total_len
+= obstack_object_size (&cu_list
);
17319 /* The offset of the types CU list from the start of the file. */
17320 val
= MAYBE_SWAP (total_len
);
17321 obstack_grow (&contents
, &val
, sizeof (val
));
17322 total_len
+= obstack_object_size (&types_cu_list
);
17324 /* The offset of the address table from the start of the file. */
17325 val
= MAYBE_SWAP (total_len
);
17326 obstack_grow (&contents
, &val
, sizeof (val
));
17327 total_len
+= obstack_object_size (&addr_obstack
);
17329 /* The offset of the symbol table from the start of the file. */
17330 val
= MAYBE_SWAP (total_len
);
17331 obstack_grow (&contents
, &val
, sizeof (val
));
17332 total_len
+= obstack_object_size (&symtab_obstack
);
17334 /* The offset of the constant pool from the start of the file. */
17335 val
= MAYBE_SWAP (total_len
);
17336 obstack_grow (&contents
, &val
, sizeof (val
));
17337 total_len
+= obstack_object_size (&constant_pool
);
17339 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
17341 write_obstack (out_file
, &contents
);
17342 write_obstack (out_file
, &cu_list
);
17343 write_obstack (out_file
, &types_cu_list
);
17344 write_obstack (out_file
, &addr_obstack
);
17345 write_obstack (out_file
, &symtab_obstack
);
17346 write_obstack (out_file
, &constant_pool
);
17350 /* We want to keep the file, so we set cleanup_filename to NULL
17351 here. See unlink_if_set. */
17352 cleanup_filename
= NULL
;
17354 do_cleanups (cleanup
);
17357 /* Implementation of the `save gdb-index' command.
17359 Note that the file format used by this command is documented in the
17360 GDB manual. Any changes here must be documented there. */
17363 save_gdb_index_command (char *arg
, int from_tty
)
17365 struct objfile
*objfile
;
17368 error (_("usage: save gdb-index DIRECTORY"));
17370 ALL_OBJFILES (objfile
)
17374 /* If the objfile does not correspond to an actual file, skip it. */
17375 if (stat (objfile
->name
, &st
) < 0)
17378 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17379 if (dwarf2_per_objfile
)
17381 volatile struct gdb_exception except
;
17383 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17385 write_psymtabs_to_index (objfile
, arg
);
17387 if (except
.reason
< 0)
17388 exception_fprintf (gdb_stderr
, except
,
17389 _("Error while writing index for `%s': "),
17397 int dwarf2_always_disassemble
;
17400 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17401 struct cmd_list_element
*c
, const char *value
)
17403 fprintf_filtered (file
,
17404 _("Whether to always disassemble "
17405 "DWARF expressions is %s.\n"),
17410 show_check_physname (struct ui_file
*file
, int from_tty
,
17411 struct cmd_list_element
*c
, const char *value
)
17413 fprintf_filtered (file
,
17414 _("Whether to check \"physname\" is %s.\n"),
17418 void _initialize_dwarf2_read (void);
17421 _initialize_dwarf2_read (void)
17423 struct cmd_list_element
*c
;
17425 dwarf2_objfile_data_key
17426 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17428 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17429 Set DWARF 2 specific variables.\n\
17430 Configure DWARF 2 variables such as the cache size"),
17431 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17432 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17434 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17435 Show DWARF 2 specific variables\n\
17436 Show DWARF 2 variables such as the cache size"),
17437 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17438 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17440 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17441 &dwarf2_max_cache_age
, _("\
17442 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17443 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17444 A higher limit means that cached compilation units will be stored\n\
17445 in memory longer, and more total memory will be used. Zero disables\n\
17446 caching, which can slow down startup."),
17448 show_dwarf2_max_cache_age
,
17449 &set_dwarf2_cmdlist
,
17450 &show_dwarf2_cmdlist
);
17452 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17453 &dwarf2_always_disassemble
, _("\
17454 Set whether `info address' always disassembles DWARF expressions."), _("\
17455 Show whether `info address' always disassembles DWARF expressions."), _("\
17456 When enabled, DWARF expressions are always printed in an assembly-like\n\
17457 syntax. When disabled, expressions will be printed in a more\n\
17458 conversational style, when possible."),
17460 show_dwarf2_always_disassemble
,
17461 &set_dwarf2_cmdlist
,
17462 &show_dwarf2_cmdlist
);
17464 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
17465 Set debugging of the dwarf2 DIE reader."), _("\
17466 Show debugging of the dwarf2 DIE reader."), _("\
17467 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17468 The value is the maximum depth to print."),
17471 &setdebuglist
, &showdebuglist
);
17473 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
17474 Set cross-checking of \"physname\" code against demangler."), _("\
17475 Show cross-checking of \"physname\" code against demangler."), _("\
17476 When enabled, GDB's internal \"physname\" code is checked against\n\
17478 NULL
, show_check_physname
,
17479 &setdebuglist
, &showdebuglist
);
17481 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
17483 Save a gdb-index file.\n\
17484 Usage: save gdb-index DIRECTORY"),
17486 set_cmd_completer (c
, filename_completer
);