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"
66 #include "gdb_string.h"
67 #include "gdb_assert.h"
68 #include <sys/types.h>
75 #define MAP_FAILED ((void *) -1)
79 typedef struct symbol
*symbolp
;
82 /* When non-zero, dump DIEs after they are read in. */
83 static int dwarf2_die_debug
= 0;
85 /* When non-zero, cross-check physname against demangler. */
86 static int check_physname
= 0;
90 /* When set, the file that we're processing is known to have debugging
91 info for C++ namespaces. GCC 3.3.x did not produce this information,
92 but later versions do. */
94 static int processing_has_namespace_info
;
96 static const struct objfile_data
*dwarf2_objfile_data_key
;
98 struct dwarf2_section_info
103 /* Not NULL if the section was actually mmapped. */
105 /* Page aligned size of mmapped area. */
106 bfd_size_type map_len
;
107 /* True if we have tried to read this section. */
111 typedef struct dwarf2_section_info dwarf2_section_info_def
;
112 DEF_VEC_O (dwarf2_section_info_def
);
114 /* All offsets in the index are of this type. It must be
115 architecture-independent. */
116 typedef uint32_t offset_type
;
118 DEF_VEC_I (offset_type
);
120 /* A description of the mapped index. The file format is described in
121 a comment by the code that writes the index. */
124 /* Index data format version. */
127 /* The total length of the buffer. */
130 /* A pointer to the address table data. */
131 const gdb_byte
*address_table
;
133 /* Size of the address table data in bytes. */
134 offset_type address_table_size
;
136 /* The symbol table, implemented as a hash table. */
137 const offset_type
*symbol_table
;
139 /* Size in slots, each slot is 2 offset_types. */
140 offset_type symbol_table_slots
;
142 /* A pointer to the constant pool. */
143 const char *constant_pool
;
146 /* Collection of data recorded per objfile.
147 This hangs off of dwarf2_objfile_data_key. */
149 struct dwarf2_per_objfile
151 struct dwarf2_section_info info
;
152 struct dwarf2_section_info abbrev
;
153 struct dwarf2_section_info line
;
154 struct dwarf2_section_info loc
;
155 struct dwarf2_section_info macinfo
;
156 struct dwarf2_section_info macro
;
157 struct dwarf2_section_info str
;
158 struct dwarf2_section_info ranges
;
159 struct dwarf2_section_info frame
;
160 struct dwarf2_section_info eh_frame
;
161 struct dwarf2_section_info gdb_index
;
163 VEC (dwarf2_section_info_def
) *types
;
166 struct objfile
*objfile
;
168 /* A list of all the compilation units. This is used to locate
169 the target compilation unit of a particular reference. */
170 struct dwarf2_per_cu_data
**all_comp_units
;
172 /* The number of compilation units in ALL_COMP_UNITS. */
175 /* The number of .debug_types-related CUs. */
176 int n_type_comp_units
;
178 /* The .debug_types-related CUs. */
179 struct dwarf2_per_cu_data
**type_comp_units
;
181 /* A chain of compilation units that are currently read in, so that
182 they can be freed later. */
183 struct dwarf2_per_cu_data
*read_in_chain
;
185 /* A table mapping .debug_types signatures to its signatured_type entry.
186 This is NULL if the .debug_types section hasn't been read in yet. */
187 htab_t signatured_types
;
189 /* A flag indicating wether this objfile has a section loaded at a
191 int has_section_at_zero
;
193 /* True if we are using the mapped index,
194 or we are faking it for OBJF_READNOW's sake. */
195 unsigned char using_index
;
197 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
198 struct mapped_index
*index_table
;
200 /* When using index_table, this keeps track of all quick_file_names entries.
201 TUs can share line table entries with CUs or other TUs, and there can be
202 a lot more TUs than unique line tables, so we maintain a separate table
203 of all line table entries to support the sharing. */
204 htab_t quick_file_names_table
;
206 /* Set during partial symbol reading, to prevent queueing of full
208 int reading_partial_symbols
;
210 /* Table mapping type .debug_info DIE offsets to types.
211 This is NULL if not allocated yet.
212 It (currently) makes sense to allocate debug_types_type_hash lazily.
213 To keep things simple we allocate both lazily. */
214 htab_t debug_info_type_hash
;
216 /* Table mapping type .debug_types DIE offsets to types.
217 This is NULL if not allocated yet. */
218 htab_t debug_types_type_hash
;
221 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
223 /* Default names of the debugging sections. */
225 /* Note that if the debugging section has been compressed, it might
226 have a name like .zdebug_info. */
228 static const struct dwarf2_debug_sections dwarf2_elf_names
=
230 { ".debug_info", ".zdebug_info" },
231 { ".debug_abbrev", ".zdebug_abbrev" },
232 { ".debug_line", ".zdebug_line" },
233 { ".debug_loc", ".zdebug_loc" },
234 { ".debug_macinfo", ".zdebug_macinfo" },
235 { ".debug_macro", ".zdebug_macro" },
236 { ".debug_str", ".zdebug_str" },
237 { ".debug_ranges", ".zdebug_ranges" },
238 { ".debug_types", ".zdebug_types" },
239 { ".debug_frame", ".zdebug_frame" },
240 { ".eh_frame", NULL
},
241 { ".gdb_index", ".zgdb_index" },
245 /* local data types */
247 /* We hold several abbreviation tables in memory at the same time. */
248 #ifndef ABBREV_HASH_SIZE
249 #define ABBREV_HASH_SIZE 121
252 /* The data in a compilation unit header, after target2host
253 translation, looks like this. */
254 struct comp_unit_head
258 unsigned char addr_size
;
259 unsigned char signed_addr_p
;
260 unsigned int abbrev_offset
;
262 /* Size of file offsets; either 4 or 8. */
263 unsigned int offset_size
;
265 /* Size of the length field; either 4 or 12. */
266 unsigned int initial_length_size
;
268 /* Offset to the first byte of this compilation unit header in the
269 .debug_info section, for resolving relative reference dies. */
272 /* Offset to first die in this cu from the start of the cu.
273 This will be the first byte following the compilation unit header. */
274 unsigned int first_die_offset
;
277 /* Type used for delaying computation of method physnames.
278 See comments for compute_delayed_physnames. */
279 struct delayed_method_info
281 /* The type to which the method is attached, i.e., its parent class. */
284 /* The index of the method in the type's function fieldlists. */
287 /* The index of the method in the fieldlist. */
290 /* The name of the DIE. */
293 /* The DIE associated with this method. */
294 struct die_info
*die
;
297 typedef struct delayed_method_info delayed_method_info
;
298 DEF_VEC_O (delayed_method_info
);
300 /* Internal state when decoding a particular compilation unit. */
303 /* The objfile containing this compilation unit. */
304 struct objfile
*objfile
;
306 /* The header of the compilation unit. */
307 struct comp_unit_head header
;
309 /* Base address of this compilation unit. */
310 CORE_ADDR base_address
;
312 /* Non-zero if base_address has been set. */
315 /* The language we are debugging. */
316 enum language language
;
317 const struct language_defn
*language_defn
;
319 const char *producer
;
321 /* The generic symbol table building routines have separate lists for
322 file scope symbols and all all other scopes (local scopes). So
323 we need to select the right one to pass to add_symbol_to_list().
324 We do it by keeping a pointer to the correct list in list_in_scope.
326 FIXME: The original dwarf code just treated the file scope as the
327 first local scope, and all other local scopes as nested local
328 scopes, and worked fine. Check to see if we really need to
329 distinguish these in buildsym.c. */
330 struct pending
**list_in_scope
;
332 /* DWARF abbreviation table associated with this compilation unit. */
333 struct abbrev_info
**dwarf2_abbrevs
;
335 /* Storage for the abbrev table. */
336 struct obstack abbrev_obstack
;
338 /* Hash table holding all the loaded partial DIEs. */
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 offsets for following references. */
360 /* Full DIEs if read in. */
361 struct die_info
*dies
;
363 /* A set of pointers to dwarf2_per_cu_data objects for compilation
364 units referenced by this one. Only set during full symbol processing;
365 partial symbol tables do not have dependencies. */
368 /* Header data from the line table, during full symbol processing. */
369 struct line_header
*line_header
;
371 /* A list of methods which need to have physnames computed
372 after all type information has been read. */
373 VEC (delayed_method_info
) *method_list
;
375 /* To be copied to symtab->call_site_htab. */
376 htab_t call_site_htab
;
378 /* Mark used when releasing cached dies. */
379 unsigned int mark
: 1;
381 /* This flag will be set if this compilation unit might include
382 inter-compilation-unit references. */
383 unsigned int has_form_ref_addr
: 1;
385 /* This flag will be set if this compilation unit includes any
386 DW_TAG_namespace DIEs. If we know that there are explicit
387 DIEs for namespaces, we don't need to try to infer them
388 from mangled names. */
389 unsigned int has_namespace_info
: 1;
391 /* This CU references .debug_loc. See the symtab->locations_valid field.
392 This test is imperfect as there may exist optimized debug code not using
393 any location list and still facing inlining issues if handled as
394 unoptimized code. For a future better test see GCC PR other/32998. */
395 unsigned int has_loclist
: 1;
398 /* Persistent data held for a compilation unit, even when not
399 processing it. We put a pointer to this structure in the
400 read_symtab_private field of the psymtab. */
402 struct dwarf2_per_cu_data
404 /* The start offset and length of this compilation unit. 2**29-1
405 bytes should suffice to store the length of any compilation unit
406 - if it doesn't, GDB will fall over anyway.
407 NOTE: Unlike comp_unit_head.length, this length includes
408 initial_length_size. */
410 unsigned int length
: 29;
412 /* Flag indicating this compilation unit will be read in before
413 any of the current compilation units are processed. */
414 unsigned int queued
: 1;
416 /* This flag will be set if we need to load absolutely all DIEs
417 for this compilation unit, instead of just the ones we think
418 are interesting. It gets set if we look for a DIE in the
419 hash table and don't find it. */
420 unsigned int load_all_dies
: 1;
422 /* Non-null if this CU is from .debug_types; in which case it points
423 to the section. Otherwise it's from .debug_info. */
424 struct dwarf2_section_info
*debug_types_section
;
426 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
427 of the CU cache it gets reset to NULL again. */
428 struct dwarf2_cu
*cu
;
430 /* The corresponding objfile.
431 Normally we can get the objfile from dwarf2_per_objfile.
432 However we can enter this file with just a "per_cu" handle. */
433 struct objfile
*objfile
;
435 /* When using partial symbol tables, the 'psymtab' field is active.
436 Otherwise the 'quick' field is active. */
439 /* The partial symbol table associated with this compilation unit,
440 or NULL for partial units (which do not have an associated
442 struct partial_symtab
*psymtab
;
444 /* Data needed by the "quick" functions. */
445 struct dwarf2_per_cu_quick_data
*quick
;
449 /* Entry in the signatured_types hash table. */
451 struct signatured_type
455 /* Offset in .debug_types of the type defined by this TU. */
456 unsigned int type_offset
;
458 /* The CU(/TU) of this type. */
459 struct dwarf2_per_cu_data per_cu
;
462 /* Struct used to pass misc. parameters to read_die_and_children, et
463 al. which are used for both .debug_info and .debug_types dies.
464 All parameters here are unchanging for the life of the call. This
465 struct exists to abstract away the constant parameters of die
468 struct die_reader_specs
470 /* The bfd of this objfile. */
473 /* The CU of the DIE we are parsing. */
474 struct dwarf2_cu
*cu
;
476 /* Pointer to start of section buffer.
477 This is either the start of .debug_info or .debug_types. */
478 const gdb_byte
*buffer
;
481 /* The line number information for a compilation unit (found in the
482 .debug_line section) begins with a "statement program header",
483 which contains the following information. */
486 unsigned int total_length
;
487 unsigned short version
;
488 unsigned int header_length
;
489 unsigned char minimum_instruction_length
;
490 unsigned char maximum_ops_per_instruction
;
491 unsigned char default_is_stmt
;
493 unsigned char line_range
;
494 unsigned char opcode_base
;
496 /* standard_opcode_lengths[i] is the number of operands for the
497 standard opcode whose value is i. This means that
498 standard_opcode_lengths[0] is unused, and the last meaningful
499 element is standard_opcode_lengths[opcode_base - 1]. */
500 unsigned char *standard_opcode_lengths
;
502 /* The include_directories table. NOTE! These strings are not
503 allocated with xmalloc; instead, they are pointers into
504 debug_line_buffer. If you try to free them, `free' will get
506 unsigned int num_include_dirs
, include_dirs_size
;
509 /* The file_names table. NOTE! These strings are not allocated
510 with xmalloc; instead, they are pointers into debug_line_buffer.
511 Don't try to free them directly. */
512 unsigned int num_file_names
, file_names_size
;
516 unsigned int dir_index
;
517 unsigned int mod_time
;
519 int included_p
; /* Non-zero if referenced by the Line Number Program. */
520 struct symtab
*symtab
; /* The associated symbol table, if any. */
523 /* The start and end of the statement program following this
524 header. These point into dwarf2_per_objfile->line_buffer. */
525 gdb_byte
*statement_program_start
, *statement_program_end
;
528 /* When we construct a partial symbol table entry we only
529 need this much information. */
530 struct partial_die_info
532 /* Offset of this DIE. */
535 /* DWARF-2 tag for this DIE. */
536 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
538 /* Assorted flags describing the data found in this DIE. */
539 unsigned int has_children
: 1;
540 unsigned int is_external
: 1;
541 unsigned int is_declaration
: 1;
542 unsigned int has_type
: 1;
543 unsigned int has_specification
: 1;
544 unsigned int has_pc_info
: 1;
546 /* Flag set if the SCOPE field of this structure has been
548 unsigned int scope_set
: 1;
550 /* Flag set if the DIE has a byte_size attribute. */
551 unsigned int has_byte_size
: 1;
553 /* Flag set if any of the DIE's children are template arguments. */
554 unsigned int has_template_arguments
: 1;
556 /* Flag set if fixup_partial_die has been called on this die. */
557 unsigned int fixup_called
: 1;
559 /* The name of this DIE. Normally the value of DW_AT_name, but
560 sometimes a default name for unnamed DIEs. */
563 /* The linkage name, if present. */
564 const char *linkage_name
;
566 /* The scope to prepend to our children. This is generally
567 allocated on the comp_unit_obstack, so will disappear
568 when this compilation unit leaves the cache. */
571 /* The location description associated with this DIE, if any. */
572 struct dwarf_block
*locdesc
;
574 /* If HAS_PC_INFO, the PC range associated with this DIE. */
578 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
579 DW_AT_sibling, if any. */
580 /* NOTE: This member isn't strictly necessary, read_partial_die could
581 return DW_AT_sibling values to its caller load_partial_dies. */
584 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
585 DW_AT_specification (or DW_AT_abstract_origin or
587 unsigned int spec_offset
;
589 /* Pointers to this DIE's parent, first child, and next sibling,
591 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
594 /* This data structure holds the information of an abbrev. */
597 unsigned int number
; /* number identifying abbrev */
598 enum dwarf_tag tag
; /* dwarf tag */
599 unsigned short has_children
; /* boolean */
600 unsigned short num_attrs
; /* number of attributes */
601 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
602 struct abbrev_info
*next
; /* next in chain */
607 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
608 ENUM_BITFIELD(dwarf_form
) form
: 16;
611 /* Attributes have a name and a value. */
614 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
615 ENUM_BITFIELD(dwarf_form
) form
: 15;
617 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
618 field should be in u.str (existing only for DW_STRING) but it is kept
619 here for better struct attribute alignment. */
620 unsigned int string_is_canonical
: 1;
625 struct dwarf_block
*blk
;
629 struct signatured_type
*signatured_type
;
634 /* This data structure holds a complete die structure. */
637 /* DWARF-2 tag for this DIE. */
638 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
640 /* Number of attributes */
641 unsigned char num_attrs
;
643 /* True if we're presently building the full type name for the
644 type derived from this DIE. */
645 unsigned char building_fullname
: 1;
650 /* Offset in .debug_info or .debug_types section. */
653 /* The dies in a compilation unit form an n-ary tree. PARENT
654 points to this die's parent; CHILD points to the first child of
655 this node; and all the children of a given node are chained
656 together via their SIBLING fields. */
657 struct die_info
*child
; /* Its first child, if any. */
658 struct die_info
*sibling
; /* Its next sibling, if any. */
659 struct die_info
*parent
; /* Its parent, if any. */
661 /* An array of attributes, with NUM_ATTRS elements. There may be
662 zero, but it's not common and zero-sized arrays are not
663 sufficiently portable C. */
664 struct attribute attrs
[1];
667 /* Get at parts of an attribute structure. */
669 #define DW_STRING(attr) ((attr)->u.str)
670 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
671 #define DW_UNSND(attr) ((attr)->u.unsnd)
672 #define DW_BLOCK(attr) ((attr)->u.blk)
673 #define DW_SND(attr) ((attr)->u.snd)
674 #define DW_ADDR(attr) ((attr)->u.addr)
675 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
677 /* Blocks are a bunch of untyped bytes. */
682 /* Valid only if SIZE is not zero. */
686 #ifndef ATTR_ALLOC_CHUNK
687 #define ATTR_ALLOC_CHUNK 4
690 /* Allocate fields for structs, unions and enums in this size. */
691 #ifndef DW_FIELD_ALLOC_CHUNK
692 #define DW_FIELD_ALLOC_CHUNK 4
695 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
696 but this would require a corresponding change in unpack_field_as_long
698 static int bits_per_byte
= 8;
700 /* The routines that read and process dies for a C struct or C++ class
701 pass lists of data member fields and lists of member function fields
702 in an instance of a field_info structure, as defined below. */
705 /* List of data member and baseclasses fields. */
708 struct nextfield
*next
;
713 *fields
, *baseclasses
;
715 /* Number of fields (including baseclasses). */
718 /* Number of baseclasses. */
721 /* Set if the accesibility of one of the fields is not public. */
722 int non_public_fields
;
724 /* Member function fields array, entries are allocated in the order they
725 are encountered in the object file. */
728 struct nextfnfield
*next
;
729 struct fn_field fnfield
;
733 /* Member function fieldlist array, contains name of possibly overloaded
734 member function, number of overloaded member functions and a pointer
735 to the head of the member function field chain. */
740 struct nextfnfield
*head
;
744 /* Number of entries in the fnfieldlists array. */
747 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
748 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
749 struct typedef_field_list
751 struct typedef_field field
;
752 struct typedef_field_list
*next
;
755 unsigned typedef_field_list_count
;
758 /* One item on the queue of compilation units to read in full symbols
760 struct dwarf2_queue_item
762 struct dwarf2_per_cu_data
*per_cu
;
763 struct dwarf2_queue_item
*next
;
766 /* The current queue. */
767 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
769 /* Loaded secondary compilation units are kept in memory until they
770 have not been referenced for the processing of this many
771 compilation units. Set this to zero to disable caching. Cache
772 sizes of up to at least twenty will improve startup time for
773 typical inter-CU-reference binaries, at an obvious memory cost. */
774 static int dwarf2_max_cache_age
= 5;
776 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
777 struct cmd_list_element
*c
, const char *value
)
779 fprintf_filtered (file
, _("The upper bound on the age of cached "
780 "dwarf2 compilation units is %s.\n"),
785 /* Various complaints about symbol reading that don't abort the process. */
788 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
790 complaint (&symfile_complaints
,
791 _("statement list doesn't fit in .debug_line section"));
795 dwarf2_debug_line_missing_file_complaint (void)
797 complaint (&symfile_complaints
,
798 _(".debug_line section has line data without a file"));
802 dwarf2_debug_line_missing_end_sequence_complaint (void)
804 complaint (&symfile_complaints
,
805 _(".debug_line section has line "
806 "program sequence without an end"));
810 dwarf2_complex_location_expr_complaint (void)
812 complaint (&symfile_complaints
, _("location expression too complex"));
816 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
819 complaint (&symfile_complaints
,
820 _("const value length mismatch for '%s', got %d, expected %d"),
825 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
827 complaint (&symfile_complaints
,
828 _("macro info runs off end of `%s' section"),
829 section
->asection
->name
);
833 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
835 complaint (&symfile_complaints
,
836 _("macro debug info contains a "
837 "malformed macro definition:\n`%s'"),
842 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
844 complaint (&symfile_complaints
,
845 _("invalid attribute class or form for '%s' in '%s'"),
849 /* local function prototypes */
851 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
853 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
856 static void dwarf2_find_base_address (struct die_info
*die
,
857 struct dwarf2_cu
*cu
);
859 static void dwarf2_build_psymtabs_hard (struct objfile
*);
861 static void scan_partial_symbols (struct partial_die_info
*,
862 CORE_ADDR
*, CORE_ADDR
*,
863 int, struct dwarf2_cu
*);
865 static void add_partial_symbol (struct partial_die_info
*,
868 static void add_partial_namespace (struct partial_die_info
*pdi
,
869 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
870 int need_pc
, struct dwarf2_cu
*cu
);
872 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
873 CORE_ADDR
*highpc
, int need_pc
,
874 struct dwarf2_cu
*cu
);
876 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
877 struct dwarf2_cu
*cu
);
879 static void add_partial_subprogram (struct partial_die_info
*pdi
,
880 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
881 int need_pc
, struct dwarf2_cu
*cu
);
883 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
884 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
885 bfd
*abfd
, struct dwarf2_cu
*cu
);
887 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
889 static void psymtab_to_symtab_1 (struct partial_symtab
*);
891 static void dwarf2_read_abbrevs (struct dwarf2_cu
*cu
);
893 static void dwarf2_free_abbrev_table (void *);
895 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
897 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
900 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
903 static struct partial_die_info
*load_partial_dies (bfd
*,
904 gdb_byte
*, gdb_byte
*,
905 int, struct dwarf2_cu
*);
907 static gdb_byte
*read_partial_die (struct partial_die_info
*,
908 struct abbrev_info
*abbrev
,
910 gdb_byte
*, gdb_byte
*,
913 static struct partial_die_info
*find_partial_die (unsigned int,
916 static void fixup_partial_die (struct partial_die_info
*,
919 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
920 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
922 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
923 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
925 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
927 static int read_1_signed_byte (bfd
*, gdb_byte
*);
929 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
931 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
933 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
935 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
938 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
940 static LONGEST read_checked_initial_length_and_offset
941 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
942 unsigned int *, unsigned int *);
944 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
947 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
949 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
951 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
953 static char *read_indirect_string (bfd
*, gdb_byte
*,
954 const struct comp_unit_head
*,
957 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
959 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
961 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
963 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
965 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
968 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
972 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
973 struct dwarf2_cu
*cu
);
975 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
977 static struct die_info
*die_specification (struct die_info
*die
,
978 struct dwarf2_cu
**);
980 static void free_line_header (struct line_header
*lh
);
982 static void add_file_name (struct line_header
*, char *, unsigned int,
983 unsigned int, unsigned int);
985 static struct line_header
*(dwarf_decode_line_header
986 (unsigned int offset
,
987 bfd
*abfd
, struct dwarf2_cu
*cu
));
989 static void dwarf_decode_lines (struct line_header
*, const char *, bfd
*,
990 struct dwarf2_cu
*, struct partial_symtab
*);
992 static void dwarf2_start_subfile (char *, const char *, const char *);
994 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
997 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
998 struct dwarf2_cu
*, struct symbol
*);
1000 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1001 struct dwarf2_cu
*);
1003 static void dwarf2_const_value_attr (struct attribute
*attr
,
1006 struct obstack
*obstack
,
1007 struct dwarf2_cu
*cu
, long *value
,
1009 struct dwarf2_locexpr_baton
**baton
);
1011 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1013 static int need_gnat_info (struct dwarf2_cu
*);
1015 static struct type
*die_descriptive_type (struct die_info
*,
1016 struct dwarf2_cu
*);
1018 static void set_descriptive_type (struct type
*, struct die_info
*,
1019 struct dwarf2_cu
*);
1021 static struct type
*die_containing_type (struct die_info
*,
1022 struct dwarf2_cu
*);
1024 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1025 struct dwarf2_cu
*);
1027 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1029 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1031 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1033 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1034 const char *suffix
, int physname
,
1035 struct dwarf2_cu
*cu
);
1037 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1039 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1041 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1043 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1045 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1047 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1048 struct dwarf2_cu
*, struct partial_symtab
*);
1050 static int dwarf2_get_pc_bounds (struct die_info
*,
1051 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1052 struct partial_symtab
*);
1054 static void get_scope_pc_bounds (struct die_info
*,
1055 CORE_ADDR
*, CORE_ADDR
*,
1056 struct dwarf2_cu
*);
1058 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1059 CORE_ADDR
, struct dwarf2_cu
*);
1061 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1062 struct dwarf2_cu
*);
1064 static void dwarf2_attach_fields_to_type (struct field_info
*,
1065 struct type
*, struct dwarf2_cu
*);
1067 static void dwarf2_add_member_fn (struct field_info
*,
1068 struct die_info
*, struct type
*,
1069 struct dwarf2_cu
*);
1071 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1073 struct dwarf2_cu
*);
1075 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1077 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1079 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1081 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1083 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1085 static struct type
*read_module_type (struct die_info
*die
,
1086 struct dwarf2_cu
*cu
);
1088 static const char *namespace_name (struct die_info
*die
,
1089 int *is_anonymous
, struct dwarf2_cu
*);
1091 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1093 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1095 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1096 struct dwarf2_cu
*);
1098 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1100 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1102 gdb_byte
**new_info_ptr
,
1103 struct die_info
*parent
);
1105 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1107 gdb_byte
**new_info_ptr
,
1108 struct die_info
*parent
);
1110 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1112 gdb_byte
**new_info_ptr
,
1113 struct die_info
*parent
);
1115 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1116 struct die_info
**, gdb_byte
*,
1119 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1121 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1124 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1126 static const char *dwarf2_full_name (char *name
,
1127 struct die_info
*die
,
1128 struct dwarf2_cu
*cu
);
1130 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1131 struct dwarf2_cu
**);
1133 static char *dwarf_tag_name (unsigned int);
1135 static char *dwarf_attr_name (unsigned int);
1137 static char *dwarf_form_name (unsigned int);
1139 static char *dwarf_bool_name (unsigned int);
1141 static char *dwarf_type_encoding_name (unsigned int);
1144 static char *dwarf_cfi_name (unsigned int);
1147 static struct die_info
*sibling_die (struct die_info
*);
1149 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1151 static void dump_die_for_error (struct die_info
*);
1153 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1156 /*static*/ void dump_die (struct die_info
*, int max_level
);
1158 static void store_in_ref_table (struct die_info
*,
1159 struct dwarf2_cu
*);
1161 static int is_ref_attr (struct attribute
*);
1163 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1165 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1167 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1169 struct dwarf2_cu
**);
1171 static struct die_info
*follow_die_ref (struct die_info
*,
1173 struct dwarf2_cu
**);
1175 static struct die_info
*follow_die_sig (struct die_info
*,
1177 struct dwarf2_cu
**);
1179 static struct signatured_type
*lookup_signatured_type_at_offset
1180 (struct objfile
*objfile
,
1181 struct dwarf2_section_info
*section
,
1182 unsigned int offset
);
1184 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1186 static void read_signatured_type (struct signatured_type
*type_sig
);
1188 /* memory allocation interface */
1190 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1192 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1194 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1196 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1197 char *, bfd
*, struct dwarf2_cu
*,
1198 struct dwarf2_section_info
*,
1201 static int attr_form_is_block (struct attribute
*);
1203 static int attr_form_is_section_offset (struct attribute
*);
1205 static int attr_form_is_constant (struct attribute
*);
1207 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1208 struct dwarf2_loclist_baton
*baton
,
1209 struct attribute
*attr
);
1211 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1213 struct dwarf2_cu
*cu
);
1215 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1216 struct abbrev_info
*abbrev
,
1217 struct dwarf2_cu
*cu
);
1219 static void free_stack_comp_unit (void *);
1221 static hashval_t
partial_die_hash (const void *item
);
1223 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1225 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1226 (unsigned int offset
, struct objfile
*objfile
);
1228 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1229 struct dwarf2_per_cu_data
*per_cu
);
1231 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1232 struct die_info
*comp_unit_die
);
1234 static void free_heap_comp_unit (void *);
1236 static void free_cached_comp_units (void *);
1238 static void age_cached_comp_units (void);
1240 static void free_one_cached_comp_unit (void *);
1242 static struct type
*set_die_type (struct die_info
*, struct type
*,
1243 struct dwarf2_cu
*);
1245 static void create_all_comp_units (struct objfile
*);
1247 static int create_debug_types_hash_table (struct objfile
*objfile
);
1249 static void load_full_comp_unit (struct dwarf2_per_cu_data
*);
1251 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1253 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1254 struct dwarf2_per_cu_data
*);
1256 static void dwarf2_mark (struct dwarf2_cu
*);
1258 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1260 static struct type
*get_die_type_at_offset (unsigned int,
1261 struct dwarf2_per_cu_data
*per_cu
);
1263 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1265 static void dwarf2_release_queue (void *dummy
);
1267 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
);
1269 static void process_queue (void);
1271 static void find_file_and_directory (struct die_info
*die
,
1272 struct dwarf2_cu
*cu
,
1273 char **name
, char **comp_dir
);
1275 static char *file_full_name (int file
, struct line_header
*lh
,
1276 const char *comp_dir
);
1278 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1281 unsigned int buffer_size
,
1283 int is_debug_types_section
);
1285 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1286 struct dwarf2_cu
*cu
);
1288 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1292 /* Convert VALUE between big- and little-endian. */
1294 byte_swap (offset_type value
)
1298 result
= (value
& 0xff) << 24;
1299 result
|= (value
& 0xff00) << 8;
1300 result
|= (value
& 0xff0000) >> 8;
1301 result
|= (value
& 0xff000000) >> 24;
1305 #define MAYBE_SWAP(V) byte_swap (V)
1308 #define MAYBE_SWAP(V) (V)
1309 #endif /* WORDS_BIGENDIAN */
1311 /* The suffix for an index file. */
1312 #define INDEX_SUFFIX ".gdb-index"
1314 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1315 struct dwarf2_cu
*cu
);
1317 /* Try to locate the sections we need for DWARF 2 debugging
1318 information and return true if we have enough to do something.
1319 NAMES points to the dwarf2 section names, or is NULL if the standard
1320 ELF names are used. */
1323 dwarf2_has_info (struct objfile
*objfile
,
1324 const struct dwarf2_debug_sections
*names
)
1326 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1327 if (!dwarf2_per_objfile
)
1329 /* Initialize per-objfile state. */
1330 struct dwarf2_per_objfile
*data
1331 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1333 memset (data
, 0, sizeof (*data
));
1334 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1335 dwarf2_per_objfile
= data
;
1337 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1339 dwarf2_per_objfile
->objfile
= objfile
;
1341 return (dwarf2_per_objfile
->info
.asection
!= NULL
1342 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1345 /* When loading sections, we look either for uncompressed section or for
1346 compressed section names. */
1349 section_is_p (const char *section_name
,
1350 const struct dwarf2_section_names
*names
)
1352 if (names
->normal
!= NULL
1353 && strcmp (section_name
, names
->normal
) == 0)
1355 if (names
->compressed
!= NULL
1356 && strcmp (section_name
, names
->compressed
) == 0)
1361 /* This function is mapped across the sections and remembers the
1362 offset and size of each of the debugging sections we are interested
1366 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1368 const struct dwarf2_debug_sections
*names
;
1371 names
= &dwarf2_elf_names
;
1373 names
= (const struct dwarf2_debug_sections
*) vnames
;
1375 if (section_is_p (sectp
->name
, &names
->info
))
1377 dwarf2_per_objfile
->info
.asection
= sectp
;
1378 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1380 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1382 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1383 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1385 else if (section_is_p (sectp
->name
, &names
->line
))
1387 dwarf2_per_objfile
->line
.asection
= sectp
;
1388 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1390 else if (section_is_p (sectp
->name
, &names
->loc
))
1392 dwarf2_per_objfile
->loc
.asection
= sectp
;
1393 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1395 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1397 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1398 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1400 else if (section_is_p (sectp
->name
, &names
->macro
))
1402 dwarf2_per_objfile
->macro
.asection
= sectp
;
1403 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1405 else if (section_is_p (sectp
->name
, &names
->str
))
1407 dwarf2_per_objfile
->str
.asection
= sectp
;
1408 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1410 else if (section_is_p (sectp
->name
, &names
->frame
))
1412 dwarf2_per_objfile
->frame
.asection
= sectp
;
1413 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1415 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1417 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1419 if (aflag
& SEC_HAS_CONTENTS
)
1421 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1422 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1425 else if (section_is_p (sectp
->name
, &names
->ranges
))
1427 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1428 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1430 else if (section_is_p (sectp
->name
, &names
->types
))
1432 struct dwarf2_section_info type_section
;
1434 memset (&type_section
, 0, sizeof (type_section
));
1435 type_section
.asection
= sectp
;
1436 type_section
.size
= bfd_get_section_size (sectp
);
1438 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1441 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1443 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1444 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1447 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1448 && bfd_section_vma (abfd
, sectp
) == 0)
1449 dwarf2_per_objfile
->has_section_at_zero
= 1;
1452 /* Decompress a section that was compressed using zlib. Store the
1453 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1456 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1457 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1459 bfd
*abfd
= objfile
->obfd
;
1461 error (_("Support for zlib-compressed DWARF data (from '%s') "
1462 "is disabled in this copy of GDB"),
1463 bfd_get_filename (abfd
));
1465 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1466 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1467 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1468 bfd_size_type uncompressed_size
;
1469 gdb_byte
*uncompressed_buffer
;
1472 int header_size
= 12;
1474 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1475 || bfd_bread (compressed_buffer
,
1476 compressed_size
, abfd
) != compressed_size
)
1477 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1478 bfd_get_filename (abfd
));
1480 /* Read the zlib header. In this case, it should be "ZLIB" followed
1481 by the uncompressed section size, 8 bytes in big-endian order. */
1482 if (compressed_size
< header_size
1483 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1484 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1485 bfd_get_filename (abfd
));
1486 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1487 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1488 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1489 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1490 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1491 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1492 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1493 uncompressed_size
+= compressed_buffer
[11];
1495 /* It is possible the section consists of several compressed
1496 buffers concatenated together, so we uncompress in a loop. */
1500 strm
.avail_in
= compressed_size
- header_size
;
1501 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1502 strm
.avail_out
= uncompressed_size
;
1503 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1505 rc
= inflateInit (&strm
);
1506 while (strm
.avail_in
> 0)
1509 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1510 bfd_get_filename (abfd
), rc
);
1511 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1512 + (uncompressed_size
- strm
.avail_out
));
1513 rc
= inflate (&strm
, Z_FINISH
);
1514 if (rc
!= Z_STREAM_END
)
1515 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1516 bfd_get_filename (abfd
), rc
);
1517 rc
= inflateReset (&strm
);
1519 rc
= inflateEnd (&strm
);
1521 || strm
.avail_out
!= 0)
1522 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1523 bfd_get_filename (abfd
), rc
);
1525 do_cleanups (cleanup
);
1526 *outbuf
= uncompressed_buffer
;
1527 *outsize
= uncompressed_size
;
1531 /* A helper function that decides whether a section is empty. */
1534 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1536 return info
->asection
== NULL
|| info
->size
== 0;
1539 /* Read the contents of the section INFO from object file specified by
1540 OBJFILE, store info about the section into INFO.
1541 If the section is compressed, uncompress it before returning. */
1544 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1546 bfd
*abfd
= objfile
->obfd
;
1547 asection
*sectp
= info
->asection
;
1548 gdb_byte
*buf
, *retbuf
;
1549 unsigned char header
[4];
1553 info
->buffer
= NULL
;
1554 info
->map_addr
= NULL
;
1557 if (dwarf2_section_empty_p (info
))
1560 /* Check if the file has a 4-byte header indicating compression. */
1561 if (info
->size
> sizeof (header
)
1562 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1563 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1565 /* Upon decompression, update the buffer and its size. */
1566 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1568 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1576 pagesize
= getpagesize ();
1578 /* Only try to mmap sections which are large enough: we don't want to
1579 waste space due to fragmentation. Also, only try mmap for sections
1580 without relocations. */
1582 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1584 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1585 MAP_PRIVATE
, sectp
->filepos
,
1586 &info
->map_addr
, &info
->map_len
);
1588 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1590 #if HAVE_POSIX_MADVISE
1591 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1598 /* If we get here, we are a normal, not-compressed section. */
1600 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1602 /* When debugging .o files, we may need to apply relocations; see
1603 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1604 We never compress sections in .o files, so we only need to
1605 try this when the section is not compressed. */
1606 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1609 info
->buffer
= retbuf
;
1613 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1614 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1615 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1616 bfd_get_filename (abfd
));
1619 /* A helper function that returns the size of a section in a safe way.
1620 If you are positive that the section has been read before using the
1621 size, then it is safe to refer to the dwarf2_section_info object's
1622 "size" field directly. In other cases, you must call this
1623 function, because for compressed sections the size field is not set
1624 correctly until the section has been read. */
1626 static bfd_size_type
1627 dwarf2_section_size (struct objfile
*objfile
,
1628 struct dwarf2_section_info
*info
)
1631 dwarf2_read_section (objfile
, info
);
1635 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1639 dwarf2_get_section_info (struct objfile
*objfile
,
1640 enum dwarf2_section_enum sect
,
1641 asection
**sectp
, gdb_byte
**bufp
,
1642 bfd_size_type
*sizep
)
1644 struct dwarf2_per_objfile
*data
1645 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1646 struct dwarf2_section_info
*info
;
1648 /* We may see an objfile without any DWARF, in which case we just
1659 case DWARF2_DEBUG_FRAME
:
1660 info
= &data
->frame
;
1662 case DWARF2_EH_FRAME
:
1663 info
= &data
->eh_frame
;
1666 gdb_assert_not_reached ("unexpected section");
1669 dwarf2_read_section (objfile
, info
);
1671 *sectp
= info
->asection
;
1672 *bufp
= info
->buffer
;
1673 *sizep
= info
->size
;
1677 /* DWARF quick_symbols_functions support. */
1679 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1680 unique line tables, so we maintain a separate table of all .debug_line
1681 derived entries to support the sharing.
1682 All the quick functions need is the list of file names. We discard the
1683 line_header when we're done and don't need to record it here. */
1684 struct quick_file_names
1686 /* The offset in .debug_line of the line table. We hash on this. */
1687 unsigned int offset
;
1689 /* The number of entries in file_names, real_names. */
1690 unsigned int num_file_names
;
1692 /* The file names from the line table, after being run through
1694 const char **file_names
;
1696 /* The file names from the line table after being run through
1697 gdb_realpath. These are computed lazily. */
1698 const char **real_names
;
1701 /* When using the index (and thus not using psymtabs), each CU has an
1702 object of this type. This is used to hold information needed by
1703 the various "quick" methods. */
1704 struct dwarf2_per_cu_quick_data
1706 /* The file table. This can be NULL if there was no file table
1707 or it's currently not read in.
1708 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1709 struct quick_file_names
*file_names
;
1711 /* The corresponding symbol table. This is NULL if symbols for this
1712 CU have not yet been read. */
1713 struct symtab
*symtab
;
1715 /* A temporary mark bit used when iterating over all CUs in
1716 expand_symtabs_matching. */
1717 unsigned int mark
: 1;
1719 /* True if we've tried to read the file table and found there isn't one.
1720 There will be no point in trying to read it again next time. */
1721 unsigned int no_file_data
: 1;
1724 /* Hash function for a quick_file_names. */
1727 hash_file_name_entry (const void *e
)
1729 const struct quick_file_names
*file_data
= e
;
1731 return file_data
->offset
;
1734 /* Equality function for a quick_file_names. */
1737 eq_file_name_entry (const void *a
, const void *b
)
1739 const struct quick_file_names
*ea
= a
;
1740 const struct quick_file_names
*eb
= b
;
1742 return ea
->offset
== eb
->offset
;
1745 /* Delete function for a quick_file_names. */
1748 delete_file_name_entry (void *e
)
1750 struct quick_file_names
*file_data
= e
;
1753 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1755 xfree ((void*) file_data
->file_names
[i
]);
1756 if (file_data
->real_names
)
1757 xfree ((void*) file_data
->real_names
[i
]);
1760 /* The space for the struct itself lives on objfile_obstack,
1761 so we don't free it here. */
1764 /* Create a quick_file_names hash table. */
1767 create_quick_file_names_table (unsigned int nr_initial_entries
)
1769 return htab_create_alloc (nr_initial_entries
,
1770 hash_file_name_entry
, eq_file_name_entry
,
1771 delete_file_name_entry
, xcalloc
, xfree
);
1774 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1775 have to be created afterwards. You should call age_cached_comp_units after
1776 processing PER_CU->CU. dw2_setup must have been already called. */
1779 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1781 if (per_cu
->debug_types_section
)
1782 load_full_type_unit (per_cu
);
1784 load_full_comp_unit (per_cu
);
1786 gdb_assert (per_cu
->cu
!= NULL
);
1788 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1791 /* Read in the symbols for PER_CU. */
1794 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1796 struct cleanup
*back_to
;
1798 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1800 queue_comp_unit (per_cu
);
1806 /* Age the cache, releasing compilation units that have not
1807 been used recently. */
1808 age_cached_comp_units ();
1810 do_cleanups (back_to
);
1813 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1814 the objfile from which this CU came. Returns the resulting symbol
1817 static struct symtab
*
1818 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1820 if (!per_cu
->v
.quick
->symtab
)
1822 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1823 increment_reading_symtab ();
1824 dw2_do_instantiate_symtab (per_cu
);
1825 do_cleanups (back_to
);
1827 return per_cu
->v
.quick
->symtab
;
1830 /* Return the CU given its index. */
1832 static struct dwarf2_per_cu_data
*
1833 dw2_get_cu (int index
)
1835 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1837 index
-= dwarf2_per_objfile
->n_comp_units
;
1838 return dwarf2_per_objfile
->type_comp_units
[index
];
1840 return dwarf2_per_objfile
->all_comp_units
[index
];
1843 /* A helper function that knows how to read a 64-bit value in a way
1844 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1848 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1850 if (sizeof (ULONGEST
) < 8)
1854 /* Ignore the upper 4 bytes if they are all zero. */
1855 for (i
= 0; i
< 4; ++i
)
1856 if (bytes
[i
+ 4] != 0)
1859 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1862 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1866 /* Read the CU list from the mapped index, and use it to create all
1867 the CU objects for this objfile. Return 0 if something went wrong,
1868 1 if everything went ok. */
1871 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1872 offset_type cu_list_elements
)
1876 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1877 dwarf2_per_objfile
->all_comp_units
1878 = obstack_alloc (&objfile
->objfile_obstack
,
1879 dwarf2_per_objfile
->n_comp_units
1880 * sizeof (struct dwarf2_per_cu_data
*));
1882 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1884 struct dwarf2_per_cu_data
*the_cu
;
1885 ULONGEST offset
, length
;
1887 if (!extract_cu_value (cu_list
, &offset
)
1888 || !extract_cu_value (cu_list
+ 8, &length
))
1892 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1893 struct dwarf2_per_cu_data
);
1894 the_cu
->offset
= offset
;
1895 the_cu
->length
= length
;
1896 the_cu
->objfile
= objfile
;
1897 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1898 struct dwarf2_per_cu_quick_data
);
1899 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1905 /* Create the signatured type hash table from the index. */
1908 create_signatured_type_table_from_index (struct objfile
*objfile
,
1909 struct dwarf2_section_info
*section
,
1910 const gdb_byte
*bytes
,
1911 offset_type elements
)
1914 htab_t sig_types_hash
;
1916 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1917 dwarf2_per_objfile
->type_comp_units
1918 = obstack_alloc (&objfile
->objfile_obstack
,
1919 dwarf2_per_objfile
->n_type_comp_units
1920 * sizeof (struct dwarf2_per_cu_data
*));
1922 sig_types_hash
= allocate_signatured_type_table (objfile
);
1924 for (i
= 0; i
< elements
; i
+= 3)
1926 struct signatured_type
*type_sig
;
1927 ULONGEST offset
, type_offset
, signature
;
1930 if (!extract_cu_value (bytes
, &offset
)
1931 || !extract_cu_value (bytes
+ 8, &type_offset
))
1933 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1936 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1937 struct signatured_type
);
1938 type_sig
->signature
= signature
;
1939 type_sig
->type_offset
= type_offset
;
1940 type_sig
->per_cu
.debug_types_section
= section
;
1941 type_sig
->per_cu
.offset
= offset
;
1942 type_sig
->per_cu
.objfile
= objfile
;
1943 type_sig
->per_cu
.v
.quick
1944 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1945 struct dwarf2_per_cu_quick_data
);
1947 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1950 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1953 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1958 /* Read the address map data from the mapped index, and use it to
1959 populate the objfile's psymtabs_addrmap. */
1962 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1964 const gdb_byte
*iter
, *end
;
1965 struct obstack temp_obstack
;
1966 struct addrmap
*mutable_map
;
1967 struct cleanup
*cleanup
;
1970 obstack_init (&temp_obstack
);
1971 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1972 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1974 iter
= index
->address_table
;
1975 end
= iter
+ index
->address_table_size
;
1977 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1981 ULONGEST hi
, lo
, cu_index
;
1982 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1984 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1986 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1989 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1990 dw2_get_cu (cu_index
));
1993 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1994 &objfile
->objfile_obstack
);
1995 do_cleanups (cleanup
);
1998 /* The hash function for strings in the mapped index. This is the same as
1999 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2000 implementation. This is necessary because the hash function is tied to the
2001 format of the mapped index file. The hash values do not have to match with
2004 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2007 mapped_index_string_hash (int index_version
, const void *p
)
2009 const unsigned char *str
= (const unsigned char *) p
;
2013 while ((c
= *str
++) != 0)
2015 if (index_version
>= 5)
2017 r
= r
* 67 + c
- 113;
2023 /* Find a slot in the mapped index INDEX for the object named NAME.
2024 If NAME is found, set *VEC_OUT to point to the CU vector in the
2025 constant pool and return 1. If NAME cannot be found, return 0. */
2028 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2029 offset_type
**vec_out
)
2031 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2033 offset_type slot
, step
;
2034 int (*cmp
) (const char *, const char *);
2036 if (current_language
->la_language
== language_cplus
2037 || current_language
->la_language
== language_java
2038 || current_language
->la_language
== language_fortran
)
2040 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2042 const char *paren
= strchr (name
, '(');
2048 dup
= xmalloc (paren
- name
+ 1);
2049 memcpy (dup
, name
, paren
- name
);
2050 dup
[paren
- name
] = 0;
2052 make_cleanup (xfree
, dup
);
2057 /* Index version 4 did not support case insensitive searches. But the
2058 indexes for case insensitive languages are built in lowercase, therefore
2059 simulate our NAME being searched is also lowercased. */
2060 hash
= mapped_index_string_hash ((index
->version
== 4
2061 && case_sensitivity
== case_sensitive_off
2062 ? 5 : index
->version
),
2065 slot
= hash
& (index
->symbol_table_slots
- 1);
2066 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2067 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2071 /* Convert a slot number to an offset into the table. */
2072 offset_type i
= 2 * slot
;
2074 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2076 do_cleanups (back_to
);
2080 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2081 if (!cmp (name
, str
))
2083 *vec_out
= (offset_type
*) (index
->constant_pool
2084 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2085 do_cleanups (back_to
);
2089 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2093 /* Read the index file. If everything went ok, initialize the "quick"
2094 elements of all the CUs and return 1. Otherwise, return 0. */
2097 dwarf2_read_index (struct objfile
*objfile
)
2100 struct mapped_index
*map
;
2101 offset_type
*metadata
;
2102 const gdb_byte
*cu_list
;
2103 const gdb_byte
*types_list
= NULL
;
2104 offset_type version
, cu_list_elements
;
2105 offset_type types_list_elements
= 0;
2108 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2111 /* Older elfutils strip versions could keep the section in the main
2112 executable while splitting it for the separate debug info file. */
2113 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2114 & SEC_HAS_CONTENTS
) == 0)
2117 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2119 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2120 /* Version check. */
2121 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2122 /* Versions earlier than 3 emitted every copy of a psymbol. This
2123 causes the index to behave very poorly for certain requests. Version 3
2124 contained incomplete addrmap. So, it seems better to just ignore such
2125 indices. Index version 4 uses a different hash function than index
2126 version 5 and later. */
2129 /* Indexes with higher version than the one supported by GDB may be no
2130 longer backward compatible. */
2134 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2135 map
->version
= version
;
2136 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2138 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2141 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2142 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2146 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2147 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2148 - MAYBE_SWAP (metadata
[i
]))
2152 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2153 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2154 - MAYBE_SWAP (metadata
[i
]));
2157 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2158 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2159 - MAYBE_SWAP (metadata
[i
]))
2160 / (2 * sizeof (offset_type
)));
2163 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2165 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2168 if (types_list_elements
)
2170 struct dwarf2_section_info
*section
;
2172 /* We can only handle a single .debug_types when we have an
2174 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2177 section
= VEC_index (dwarf2_section_info_def
,
2178 dwarf2_per_objfile
->types
, 0);
2180 if (!create_signatured_type_table_from_index (objfile
, section
,
2182 types_list_elements
))
2186 create_addrmap_from_index (objfile
, map
);
2188 dwarf2_per_objfile
->index_table
= map
;
2189 dwarf2_per_objfile
->using_index
= 1;
2190 dwarf2_per_objfile
->quick_file_names_table
=
2191 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2196 /* A helper for the "quick" functions which sets the global
2197 dwarf2_per_objfile according to OBJFILE. */
2200 dw2_setup (struct objfile
*objfile
)
2202 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2203 gdb_assert (dwarf2_per_objfile
);
2206 /* A helper for the "quick" functions which attempts to read the line
2207 table for THIS_CU. */
2209 static struct quick_file_names
*
2210 dw2_get_file_names (struct objfile
*objfile
,
2211 struct dwarf2_per_cu_data
*this_cu
)
2213 bfd
*abfd
= objfile
->obfd
;
2214 struct line_header
*lh
;
2215 struct attribute
*attr
;
2216 struct cleanup
*cleanups
;
2217 struct die_info
*comp_unit_die
;
2218 struct dwarf2_section_info
* sec
;
2219 gdb_byte
*info_ptr
, *buffer
;
2220 int has_children
, i
;
2221 struct dwarf2_cu cu
;
2222 unsigned int bytes_read
, buffer_size
;
2223 struct die_reader_specs reader_specs
;
2224 char *name
, *comp_dir
;
2226 struct quick_file_names
*qfn
;
2227 unsigned int line_offset
;
2229 if (this_cu
->v
.quick
->file_names
!= NULL
)
2230 return this_cu
->v
.quick
->file_names
;
2231 /* If we know there is no line data, no point in looking again. */
2232 if (this_cu
->v
.quick
->no_file_data
)
2235 init_one_comp_unit (&cu
, this_cu
);
2236 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2238 if (this_cu
->debug_types_section
)
2239 sec
= this_cu
->debug_types_section
;
2241 sec
= &dwarf2_per_objfile
->info
;
2242 dwarf2_read_section (objfile
, sec
);
2243 buffer_size
= sec
->size
;
2244 buffer
= sec
->buffer
;
2245 info_ptr
= buffer
+ this_cu
->offset
;
2247 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2248 buffer
, buffer_size
,
2250 this_cu
->debug_types_section
!= NULL
);
2252 /* Skip dummy compilation units. */
2253 if (info_ptr
>= buffer
+ buffer_size
2254 || peek_abbrev_code (abfd
, info_ptr
) == 0)
2256 do_cleanups (cleanups
);
2260 dwarf2_read_abbrevs (&cu
);
2261 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2263 init_cu_die_reader (&reader_specs
, &cu
);
2264 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2270 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2273 struct quick_file_names find_entry
;
2275 line_offset
= DW_UNSND (attr
);
2277 /* We may have already read in this line header (TU line header sharing).
2278 If we have we're done. */
2279 find_entry
.offset
= line_offset
;
2280 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2281 &find_entry
, INSERT
);
2284 do_cleanups (cleanups
);
2285 this_cu
->v
.quick
->file_names
= *slot
;
2289 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2293 do_cleanups (cleanups
);
2294 this_cu
->v
.quick
->no_file_data
= 1;
2298 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2299 qfn
->offset
= line_offset
;
2300 gdb_assert (slot
!= NULL
);
2303 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2305 qfn
->num_file_names
= lh
->num_file_names
;
2306 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2307 lh
->num_file_names
* sizeof (char *));
2308 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2309 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2310 qfn
->real_names
= NULL
;
2312 free_line_header (lh
);
2313 do_cleanups (cleanups
);
2315 this_cu
->v
.quick
->file_names
= qfn
;
2319 /* A helper for the "quick" functions which computes and caches the
2320 real path for a given file name from the line table. */
2323 dw2_get_real_path (struct objfile
*objfile
,
2324 struct quick_file_names
*qfn
, int index
)
2326 if (qfn
->real_names
== NULL
)
2327 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2328 qfn
->num_file_names
, sizeof (char *));
2330 if (qfn
->real_names
[index
] == NULL
)
2331 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2333 return qfn
->real_names
[index
];
2336 static struct symtab
*
2337 dw2_find_last_source_symtab (struct objfile
*objfile
)
2341 dw2_setup (objfile
);
2342 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2343 return dw2_instantiate_symtab (dw2_get_cu (index
));
2346 /* Traversal function for dw2_forget_cached_source_info. */
2349 dw2_free_cached_file_names (void **slot
, void *info
)
2351 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2353 if (file_data
->real_names
)
2357 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2359 xfree ((void*) file_data
->real_names
[i
]);
2360 file_data
->real_names
[i
] = NULL
;
2368 dw2_forget_cached_source_info (struct objfile
*objfile
)
2370 dw2_setup (objfile
);
2372 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2373 dw2_free_cached_file_names
, NULL
);
2376 /* Helper function for dw2_map_symtabs_matching_filename that expands
2377 the symtabs and calls the iterator. */
2380 dw2_map_expand_apply (struct objfile
*objfile
,
2381 struct dwarf2_per_cu_data
*per_cu
,
2383 const char *full_path
, const char *real_path
,
2384 int (*callback
) (struct symtab
*, void *),
2387 struct symtab
*last_made
= objfile
->symtabs
;
2389 /* Don't visit already-expanded CUs. */
2390 if (per_cu
->v
.quick
->symtab
)
2393 /* This may expand more than one symtab, and we want to iterate over
2395 dw2_instantiate_symtab (per_cu
);
2397 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2398 objfile
->symtabs
, last_made
);
2401 /* Implementation of the map_symtabs_matching_filename method. */
2404 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2405 const char *full_path
, const char *real_path
,
2406 int (*callback
) (struct symtab
*, void *),
2410 const char *name_basename
= lbasename (name
);
2411 int check_basename
= name_basename
== name
;
2412 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2414 dw2_setup (objfile
);
2416 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2417 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2420 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2421 struct quick_file_names
*file_data
;
2423 /* We only need to look at symtabs not already expanded. */
2424 if (per_cu
->v
.quick
->symtab
)
2427 file_data
= dw2_get_file_names (objfile
, per_cu
);
2428 if (file_data
== NULL
)
2431 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2433 const char *this_name
= file_data
->file_names
[j
];
2435 if (FILENAME_CMP (name
, this_name
) == 0)
2437 if (dw2_map_expand_apply (objfile
, per_cu
,
2438 name
, full_path
, real_path
,
2443 if (check_basename
&& ! base_cu
2444 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2447 /* Before we invoke realpath, which can get expensive when many
2448 files are involved, do a quick comparison of the basenames. */
2449 if (! basenames_may_differ
2450 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2453 if (full_path
!= NULL
)
2455 const char *this_real_name
= dw2_get_real_path (objfile
,
2458 if (this_real_name
!= NULL
2459 && FILENAME_CMP (full_path
, this_real_name
) == 0)
2461 if (dw2_map_expand_apply (objfile
, per_cu
,
2462 name
, full_path
, real_path
,
2468 if (real_path
!= NULL
)
2470 const char *this_real_name
= dw2_get_real_path (objfile
,
2473 if (this_real_name
!= NULL
2474 && FILENAME_CMP (real_path
, this_real_name
) == 0)
2476 if (dw2_map_expand_apply (objfile
, per_cu
,
2477 name
, full_path
, real_path
,
2487 if (dw2_map_expand_apply (objfile
, base_cu
,
2488 name
, full_path
, real_path
,
2496 static struct symtab
*
2497 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2498 const char *name
, domain_enum domain
)
2500 /* We do all the work in the pre_expand_symtabs_matching hook
2505 /* A helper function that expands all symtabs that hold an object
2509 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2511 dw2_setup (objfile
);
2513 /* index_table is NULL if OBJF_READNOW. */
2514 if (dwarf2_per_objfile
->index_table
)
2518 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2521 offset_type i
, len
= MAYBE_SWAP (*vec
);
2522 for (i
= 0; i
< len
; ++i
)
2524 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2525 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2527 dw2_instantiate_symtab (per_cu
);
2534 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2535 enum block_enum block_kind
, const char *name
,
2538 dw2_do_expand_symtabs_matching (objfile
, name
);
2542 dw2_print_stats (struct objfile
*objfile
)
2546 dw2_setup (objfile
);
2548 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2549 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2551 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2553 if (!per_cu
->v
.quick
->symtab
)
2556 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2560 dw2_dump (struct objfile
*objfile
)
2562 /* Nothing worth printing. */
2566 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2567 struct section_offsets
*delta
)
2569 /* There's nothing to relocate here. */
2573 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2574 const char *func_name
)
2576 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2580 dw2_expand_all_symtabs (struct objfile
*objfile
)
2584 dw2_setup (objfile
);
2586 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2587 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2589 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2591 dw2_instantiate_symtab (per_cu
);
2596 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2597 const char *filename
)
2601 dw2_setup (objfile
);
2603 /* We don't need to consider type units here.
2604 This is only called for examining code, e.g. expand_line_sal.
2605 There can be an order of magnitude (or more) more type units
2606 than comp units, and we avoid them if we can. */
2608 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2611 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2612 struct quick_file_names
*file_data
;
2614 /* We only need to look at symtabs not already expanded. */
2615 if (per_cu
->v
.quick
->symtab
)
2618 file_data
= dw2_get_file_names (objfile
, per_cu
);
2619 if (file_data
== NULL
)
2622 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2624 const char *this_name
= file_data
->file_names
[j
];
2625 if (FILENAME_CMP (this_name
, filename
) == 0)
2627 dw2_instantiate_symtab (per_cu
);
2635 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2637 struct dwarf2_per_cu_data
*per_cu
;
2639 struct quick_file_names
*file_data
;
2641 dw2_setup (objfile
);
2643 /* index_table is NULL if OBJF_READNOW. */
2644 if (!dwarf2_per_objfile
->index_table
)
2648 ALL_OBJFILE_SYMTABS (objfile
, s
)
2651 struct blockvector
*bv
= BLOCKVECTOR (s
);
2652 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2653 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2656 return sym
->symtab
->filename
;
2661 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2665 /* Note that this just looks at the very first one named NAME -- but
2666 actually we are looking for a function. find_main_filename
2667 should be rewritten so that it doesn't require a custom hook. It
2668 could just use the ordinary symbol tables. */
2669 /* vec[0] is the length, which must always be >0. */
2670 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2672 file_data
= dw2_get_file_names (objfile
, per_cu
);
2673 if (file_data
== NULL
)
2676 return file_data
->file_names
[file_data
->num_file_names
- 1];
2680 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2681 struct objfile
*objfile
, int global
,
2682 int (*callback
) (struct block
*,
2683 struct symbol
*, void *),
2684 void *data
, symbol_compare_ftype
*match
,
2685 symbol_compare_ftype
*ordered_compare
)
2687 /* Currently unimplemented; used for Ada. The function can be called if the
2688 current language is Ada for a non-Ada objfile using GNU index. As Ada
2689 does not look for non-Ada symbols this function should just return. */
2693 dw2_expand_symtabs_matching
2694 (struct objfile
*objfile
,
2695 int (*file_matcher
) (const char *, void *),
2696 int (*name_matcher
) (const struct language_defn
*, const char *, void *),
2697 enum search_domain kind
,
2702 struct mapped_index
*index
;
2704 dw2_setup (objfile
);
2706 /* index_table is NULL if OBJF_READNOW. */
2707 if (!dwarf2_per_objfile
->index_table
)
2709 index
= dwarf2_per_objfile
->index_table
;
2711 if (file_matcher
!= NULL
)
2712 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2713 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2716 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2717 struct quick_file_names
*file_data
;
2719 per_cu
->v
.quick
->mark
= 0;
2721 /* We only need to look at symtabs not already expanded. */
2722 if (per_cu
->v
.quick
->symtab
)
2725 file_data
= dw2_get_file_names (objfile
, per_cu
);
2726 if (file_data
== NULL
)
2729 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2731 if (file_matcher (file_data
->file_names
[j
], data
))
2733 per_cu
->v
.quick
->mark
= 1;
2739 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2741 offset_type idx
= 2 * iter
;
2743 offset_type
*vec
, vec_len
, vec_idx
;
2745 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2748 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2750 if (! (*name_matcher
) (current_language
, name
, data
))
2753 /* The name was matched, now expand corresponding CUs that were
2755 vec
= (offset_type
*) (index
->constant_pool
2756 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2757 vec_len
= MAYBE_SWAP (vec
[0]);
2758 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2760 struct dwarf2_per_cu_data
*per_cu
;
2762 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2763 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2764 dw2_instantiate_symtab (per_cu
);
2769 static struct symtab
*
2770 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2771 struct minimal_symbol
*msymbol
,
2773 struct obj_section
*section
,
2776 struct dwarf2_per_cu_data
*data
;
2778 dw2_setup (objfile
);
2780 if (!objfile
->psymtabs_addrmap
)
2783 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2787 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2788 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2789 paddress (get_objfile_arch (objfile
), pc
));
2791 return dw2_instantiate_symtab (data
);
2795 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2796 void *data
, int need_fullname
)
2800 dw2_setup (objfile
);
2802 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2803 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2806 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2807 struct quick_file_names
*file_data
;
2809 /* We only need to look at symtabs not already expanded. */
2810 if (per_cu
->v
.quick
->symtab
)
2813 file_data
= dw2_get_file_names (objfile
, per_cu
);
2814 if (file_data
== NULL
)
2817 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2819 const char *this_real_name
;
2822 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
2824 this_real_name
= NULL
;
2825 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2831 dw2_has_symbols (struct objfile
*objfile
)
2836 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2839 dw2_find_last_source_symtab
,
2840 dw2_forget_cached_source_info
,
2841 dw2_map_symtabs_matching_filename
,
2843 dw2_pre_expand_symtabs_matching
,
2847 dw2_expand_symtabs_for_function
,
2848 dw2_expand_all_symtabs
,
2849 dw2_expand_symtabs_with_filename
,
2850 dw2_find_symbol_file
,
2851 dw2_map_matching_symbols
,
2852 dw2_expand_symtabs_matching
,
2853 dw2_find_pc_sect_symtab
,
2854 dw2_map_symbol_filenames
2857 /* Initialize for reading DWARF for this objfile. Return 0 if this
2858 file will use psymtabs, or 1 if using the GNU index. */
2861 dwarf2_initialize_objfile (struct objfile
*objfile
)
2863 /* If we're about to read full symbols, don't bother with the
2864 indices. In this case we also don't care if some other debug
2865 format is making psymtabs, because they are all about to be
2867 if ((objfile
->flags
& OBJF_READNOW
))
2871 dwarf2_per_objfile
->using_index
= 1;
2872 create_all_comp_units (objfile
);
2873 create_debug_types_hash_table (objfile
);
2874 dwarf2_per_objfile
->quick_file_names_table
=
2875 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2877 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2878 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2880 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2882 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2883 struct dwarf2_per_cu_quick_data
);
2886 /* Return 1 so that gdb sees the "quick" functions. However,
2887 these functions will be no-ops because we will have expanded
2892 if (dwarf2_read_index (objfile
))
2900 /* Build a partial symbol table. */
2903 dwarf2_build_psymtabs (struct objfile
*objfile
)
2905 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2907 init_psymbol_list (objfile
, 1024);
2910 dwarf2_build_psymtabs_hard (objfile
);
2913 /* Return TRUE if OFFSET is within CU_HEADER. */
2916 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2918 unsigned int bottom
= cu_header
->offset
;
2919 unsigned int top
= (cu_header
->offset
2921 + cu_header
->initial_length_size
);
2923 return (offset
>= bottom
&& offset
< top
);
2926 /* Read in the comp unit header information from the debug_info at info_ptr.
2927 NOTE: This leaves members offset, first_die_offset to be filled in
2931 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2932 gdb_byte
*info_ptr
, bfd
*abfd
)
2935 unsigned int bytes_read
;
2937 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2938 cu_header
->initial_length_size
= bytes_read
;
2939 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2940 info_ptr
+= bytes_read
;
2941 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2943 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2945 info_ptr
+= bytes_read
;
2946 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2948 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2949 if (signed_addr
< 0)
2950 internal_error (__FILE__
, __LINE__
,
2951 _("read_comp_unit_head: dwarf from non elf file"));
2952 cu_header
->signed_addr_p
= signed_addr
;
2957 /* Read in a CU header and perform some basic error checking. */
2960 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2961 gdb_byte
*buffer
, unsigned int buffer_size
,
2962 bfd
*abfd
, int is_debug_types_section
)
2964 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2966 header
->offset
= beg_of_comp_unit
- buffer
;
2968 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2970 /* If we're reading a type unit, skip over the signature and
2971 type_offset fields. */
2972 if (is_debug_types_section
)
2973 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
2975 header
->first_die_offset
= info_ptr
- beg_of_comp_unit
;
2977 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2978 error (_("Dwarf Error: wrong version in compilation unit header "
2979 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2980 bfd_get_filename (abfd
));
2982 if (header
->abbrev_offset
2983 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
2984 &dwarf2_per_objfile
->abbrev
))
2985 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2986 "(offset 0x%lx + 6) [in module %s]"),
2987 (long) header
->abbrev_offset
,
2988 (long) (beg_of_comp_unit
- buffer
),
2989 bfd_get_filename (abfd
));
2991 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2992 > buffer
+ buffer_size
)
2993 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2994 "(offset 0x%lx + 0) [in module %s]"),
2995 (long) header
->length
,
2996 (long) (beg_of_comp_unit
- buffer
),
2997 bfd_get_filename (abfd
));
3002 /* Read in the types comp unit header information from .debug_types entry at
3003 types_ptr. The result is a pointer to one past the end of the header. */
3006 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
3007 struct dwarf2_section_info
*section
,
3008 ULONGEST
*signature
,
3009 gdb_byte
*types_ptr
, bfd
*abfd
)
3011 gdb_byte
*initial_types_ptr
= types_ptr
;
3013 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
3014 cu_header
->offset
= types_ptr
- section
->buffer
;
3016 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
3018 *signature
= read_8_bytes (abfd
, types_ptr
);
3020 types_ptr
+= cu_header
->offset_size
;
3021 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
3026 /* Allocate a new partial symtab for file named NAME and mark this new
3027 partial symtab as being an include of PST. */
3030 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3031 struct objfile
*objfile
)
3033 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3035 subpst
->section_offsets
= pst
->section_offsets
;
3036 subpst
->textlow
= 0;
3037 subpst
->texthigh
= 0;
3039 subpst
->dependencies
= (struct partial_symtab
**)
3040 obstack_alloc (&objfile
->objfile_obstack
,
3041 sizeof (struct partial_symtab
*));
3042 subpst
->dependencies
[0] = pst
;
3043 subpst
->number_of_dependencies
= 1;
3045 subpst
->globals_offset
= 0;
3046 subpst
->n_global_syms
= 0;
3047 subpst
->statics_offset
= 0;
3048 subpst
->n_static_syms
= 0;
3049 subpst
->symtab
= NULL
;
3050 subpst
->read_symtab
= pst
->read_symtab
;
3053 /* No private part is necessary for include psymtabs. This property
3054 can be used to differentiate between such include psymtabs and
3055 the regular ones. */
3056 subpst
->read_symtab_private
= NULL
;
3059 /* Read the Line Number Program data and extract the list of files
3060 included by the source file represented by PST. Build an include
3061 partial symtab for each of these included files. */
3064 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3065 struct die_info
*die
,
3066 struct partial_symtab
*pst
)
3068 struct objfile
*objfile
= cu
->objfile
;
3069 bfd
*abfd
= objfile
->obfd
;
3070 struct line_header
*lh
= NULL
;
3071 struct attribute
*attr
;
3073 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3076 unsigned int line_offset
= DW_UNSND (attr
);
3078 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3081 return; /* No linetable, so no includes. */
3083 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3084 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
3086 free_line_header (lh
);
3090 hash_type_signature (const void *item
)
3092 const struct signatured_type
*type_sig
= item
;
3094 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3095 return type_sig
->signature
;
3099 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
3101 const struct signatured_type
*lhs
= item_lhs
;
3102 const struct signatured_type
*rhs
= item_rhs
;
3104 return lhs
->signature
== rhs
->signature
;
3107 /* Allocate a hash table for signatured types. */
3110 allocate_signatured_type_table (struct objfile
*objfile
)
3112 return htab_create_alloc_ex (41,
3113 hash_type_signature
,
3116 &objfile
->objfile_obstack
,
3117 hashtab_obstack_allocate
,
3118 dummy_obstack_deallocate
);
3121 /* A helper function to add a signatured type CU to a list. */
3124 add_signatured_type_cu_to_list (void **slot
, void *datum
)
3126 struct signatured_type
*sigt
= *slot
;
3127 struct dwarf2_per_cu_data
***datap
= datum
;
3129 **datap
= &sigt
->per_cu
;
3135 /* Create the hash table of all entries in the .debug_types section.
3136 The result is zero if there is an error (e.g. missing .debug_types section),
3137 otherwise non-zero. */
3140 create_debug_types_hash_table (struct objfile
*objfile
)
3142 htab_t types_htab
= NULL
;
3143 struct dwarf2_per_cu_data
**iter
;
3145 struct dwarf2_section_info
*section
;
3147 if (VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
))
3149 dwarf2_per_objfile
->signatured_types
= NULL
;
3154 VEC_iterate (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
3158 gdb_byte
*info_ptr
, *end_ptr
;
3160 dwarf2_read_section (objfile
, section
);
3161 info_ptr
= section
->buffer
;
3163 if (info_ptr
== NULL
)
3166 if (types_htab
== NULL
)
3167 types_htab
= allocate_signatured_type_table (objfile
);
3169 if (dwarf2_die_debug
)
3170 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3172 end_ptr
= info_ptr
+ section
->size
;
3173 while (info_ptr
< end_ptr
)
3175 unsigned int offset
;
3176 unsigned int offset_size
;
3177 unsigned int type_offset
;
3178 unsigned int length
, initial_length_size
;
3179 unsigned short version
;
3181 struct signatured_type
*type_sig
;
3183 gdb_byte
*ptr
= info_ptr
;
3185 offset
= ptr
- section
->buffer
;
3187 /* We need to read the type's signature in order to build the hash
3188 table, but we don't need to read anything else just yet. */
3190 /* Sanity check to ensure entire cu is present. */
3191 length
= read_initial_length (objfile
->obfd
, ptr
,
3192 &initial_length_size
);
3193 if (ptr
+ length
+ initial_length_size
> end_ptr
)
3195 complaint (&symfile_complaints
,
3196 _("debug type entry runs off end "
3197 "of `.debug_types' section, ignored"));
3201 offset_size
= initial_length_size
== 4 ? 4 : 8;
3202 ptr
+= initial_length_size
;
3203 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3205 ptr
+= offset_size
; /* abbrev offset */
3206 ptr
+= 1; /* address size */
3207 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3209 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3212 /* Skip dummy type units. */
3213 if (ptr
>= end_ptr
|| peek_abbrev_code (objfile
->obfd
, ptr
) == 0)
3215 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3219 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3220 memset (type_sig
, 0, sizeof (*type_sig
));
3221 type_sig
->signature
= signature
;
3222 type_sig
->type_offset
= type_offset
;
3223 type_sig
->per_cu
.objfile
= objfile
;
3224 type_sig
->per_cu
.debug_types_section
= section
;
3225 type_sig
->per_cu
.offset
= offset
;
3227 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3228 gdb_assert (slot
!= NULL
);
3231 const struct signatured_type
*dup_sig
= *slot
;
3233 complaint (&symfile_complaints
,
3234 _("debug type entry at offset 0x%x is duplicate to the "
3235 "entry at offset 0x%x, signature 0x%s"),
3236 offset
, dup_sig
->per_cu
.offset
,
3237 phex (signature
, sizeof (signature
)));
3238 gdb_assert (signature
== dup_sig
->signature
);
3242 if (dwarf2_die_debug
)
3243 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3244 offset
, phex (signature
, sizeof (signature
)));
3246 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3250 dwarf2_per_objfile
->signatured_types
= types_htab
;
3252 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3253 dwarf2_per_objfile
->type_comp_units
3254 = obstack_alloc (&objfile
->objfile_obstack
,
3255 dwarf2_per_objfile
->n_type_comp_units
3256 * sizeof (struct dwarf2_per_cu_data
*));
3257 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3258 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3259 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3260 == dwarf2_per_objfile
->n_type_comp_units
);
3265 /* Lookup a signature based type.
3266 Returns NULL if SIG is not present in the table. */
3268 static struct signatured_type
*
3269 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3271 struct signatured_type find_entry
, *entry
;
3273 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3275 complaint (&symfile_complaints
,
3276 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3280 find_entry
.signature
= sig
;
3281 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3285 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3288 init_cu_die_reader (struct die_reader_specs
*reader
,
3289 struct dwarf2_cu
*cu
)
3291 reader
->abfd
= cu
->objfile
->obfd
;
3293 if (cu
->per_cu
->debug_types_section
)
3295 gdb_assert (cu
->per_cu
->debug_types_section
->readin
);
3296 reader
->buffer
= cu
->per_cu
->debug_types_section
->buffer
;
3300 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3301 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3305 /* Find the base address of the compilation unit for range lists and
3306 location lists. It will normally be specified by DW_AT_low_pc.
3307 In DWARF-3 draft 4, the base address could be overridden by
3308 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3309 compilation units with discontinuous ranges. */
3312 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3314 struct attribute
*attr
;
3317 cu
->base_address
= 0;
3319 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3322 cu
->base_address
= DW_ADDR (attr
);
3327 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3330 cu
->base_address
= DW_ADDR (attr
);
3336 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3337 to combine the common parts.
3338 Process compilation unit THIS_CU for a psymtab.
3339 SECTION is the section the CU/TU comes from,
3340 either .debug_info or .debug_types. */
3343 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3344 struct dwarf2_section_info
*section
,
3345 int is_debug_types_section
)
3347 struct objfile
*objfile
= this_cu
->objfile
;
3348 bfd
*abfd
= objfile
->obfd
;
3349 gdb_byte
*buffer
= section
->buffer
;
3350 gdb_byte
*info_ptr
= buffer
+ this_cu
->offset
;
3351 unsigned int buffer_size
= section
->size
;
3352 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3353 struct die_info
*comp_unit_die
;
3354 struct partial_symtab
*pst
;
3356 struct cleanup
*back_to_inner
;
3357 struct dwarf2_cu cu
;
3358 int has_children
, has_pc_info
;
3359 struct attribute
*attr
;
3360 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3361 struct die_reader_specs reader_specs
;
3362 const char *filename
;
3364 /* If this compilation unit was already read in, free the
3365 cached copy in order to read it in again. This is
3366 necessary because we skipped some symbols when we first
3367 read in the compilation unit (see load_partial_dies).
3368 This problem could be avoided, but the benefit is
3370 if (this_cu
->cu
!= NULL
)
3371 free_one_cached_comp_unit (this_cu
->cu
);
3373 /* Note that this is a pointer to our stack frame, being
3374 added to a global data structure. It will be cleaned up
3375 in free_stack_comp_unit when we finish with this
3376 compilation unit. */
3377 init_one_comp_unit (&cu
, this_cu
);
3378 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3380 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3381 buffer
, buffer_size
,
3383 is_debug_types_section
);
3385 /* Skip dummy compilation units. */
3386 if (info_ptr
>= buffer
+ buffer_size
3387 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3389 do_cleanups (back_to_inner
);
3393 cu
.list_in_scope
= &file_symbols
;
3395 /* Read the abbrevs for this compilation unit into a table. */
3396 dwarf2_read_abbrevs (&cu
);
3397 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3399 /* Read the compilation unit die. */
3400 init_cu_die_reader (&reader_specs
, &cu
);
3401 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3404 if (is_debug_types_section
)
3406 /* LENGTH has not been set yet for type units. */
3407 gdb_assert (this_cu
->offset
== cu
.header
.offset
);
3408 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3410 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3412 do_cleanups (back_to_inner
);
3416 prepare_one_comp_unit (&cu
, comp_unit_die
);
3418 /* Allocate a new partial symbol table structure. */
3419 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3420 if (attr
== NULL
|| !DW_STRING (attr
))
3423 filename
= DW_STRING (attr
);
3424 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3426 /* TEXTLOW and TEXTHIGH are set below. */
3428 objfile
->global_psymbols
.next
,
3429 objfile
->static_psymbols
.next
);
3430 pst
->psymtabs_addrmap_supported
= 1;
3432 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3434 pst
->dirname
= DW_STRING (attr
);
3436 pst
->read_symtab_private
= this_cu
;
3438 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3440 /* Store the function that reads in the rest of the symbol table. */
3441 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3443 this_cu
->v
.psymtab
= pst
;
3445 dwarf2_find_base_address (comp_unit_die
, &cu
);
3447 /* Possibly set the default values of LOWPC and HIGHPC from
3449 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3450 &best_highpc
, &cu
, pst
);
3451 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3452 /* Store the contiguous range if it is not empty; it can be empty for
3453 CUs with no code. */
3454 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3455 best_lowpc
+ baseaddr
,
3456 best_highpc
+ baseaddr
- 1, pst
);
3458 /* Check if comp unit has_children.
3459 If so, read the rest of the partial symbols from this comp unit.
3460 If not, there's no more debug_info for this comp unit. */
3463 struct partial_die_info
*first_die
;
3464 CORE_ADDR lowpc
, highpc
;
3466 lowpc
= ((CORE_ADDR
) -1);
3467 highpc
= ((CORE_ADDR
) 0);
3469 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3471 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3472 ! has_pc_info
, &cu
);
3474 /* If we didn't find a lowpc, set it to highpc to avoid
3475 complaints from `maint check'. */
3476 if (lowpc
== ((CORE_ADDR
) -1))
3479 /* If the compilation unit didn't have an explicit address range,
3480 then use the information extracted from its child dies. */
3484 best_highpc
= highpc
;
3487 pst
->textlow
= best_lowpc
+ baseaddr
;
3488 pst
->texthigh
= best_highpc
+ baseaddr
;
3490 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3491 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3492 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3493 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3494 sort_pst_symbols (pst
);
3496 if (is_debug_types_section
)
3498 /* It's not clear we want to do anything with stmt lists here.
3499 Waiting to see what gcc ultimately does. */
3503 /* Get the list of files included in the current compilation unit,
3504 and build a psymtab for each of them. */
3505 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3508 do_cleanups (back_to_inner
);
3511 /* Traversal function for htab_traverse_noresize.
3512 Process one .debug_types comp-unit. */
3515 process_type_comp_unit (void **slot
, void *info
)
3517 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3518 struct dwarf2_per_cu_data
*this_cu
;
3520 gdb_assert (info
== NULL
);
3521 this_cu
= &entry
->per_cu
;
3523 gdb_assert (this_cu
->debug_types_section
->readin
);
3524 process_psymtab_comp_unit (this_cu
, this_cu
->debug_types_section
, 1);
3529 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3530 Build partial symbol tables for the .debug_types comp-units. */
3533 build_type_psymtabs (struct objfile
*objfile
)
3535 if (! create_debug_types_hash_table (objfile
))
3538 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3539 process_type_comp_unit
, NULL
);
3542 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3545 psymtabs_addrmap_cleanup (void *o
)
3547 struct objfile
*objfile
= o
;
3549 objfile
->psymtabs_addrmap
= NULL
;
3552 /* Build the partial symbol table by doing a quick pass through the
3553 .debug_info and .debug_abbrev sections. */
3556 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3558 struct cleanup
*back_to
, *addrmap_cleanup
;
3559 struct obstack temp_obstack
;
3562 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3564 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3566 /* Any cached compilation units will be linked by the per-objfile
3567 read_in_chain. Make sure to free them when we're done. */
3568 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3570 build_type_psymtabs (objfile
);
3572 create_all_comp_units (objfile
);
3574 /* Create a temporary address map on a temporary obstack. We later
3575 copy this to the final obstack. */
3576 obstack_init (&temp_obstack
);
3577 make_cleanup_obstack_free (&temp_obstack
);
3578 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3579 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3581 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3583 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3585 process_psymtab_comp_unit (per_cu
, &dwarf2_per_objfile
->info
, 0);
3588 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3589 &objfile
->objfile_obstack
);
3590 discard_cleanups (addrmap_cleanup
);
3592 do_cleanups (back_to
);
3595 /* Load the partial DIEs for a secondary CU into memory. */
3598 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
3600 struct objfile
*objfile
= this_cu
->objfile
;
3601 bfd
*abfd
= objfile
->obfd
;
3603 struct die_info
*comp_unit_die
;
3604 struct dwarf2_cu
*cu
;
3605 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3607 struct die_reader_specs reader_specs
;
3610 gdb_assert (! this_cu
->debug_types_section
);
3612 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3613 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3615 if (this_cu
->cu
== NULL
)
3617 cu
= xmalloc (sizeof (*cu
));
3618 init_one_comp_unit (cu
, this_cu
);
3622 /* If an error occurs while loading, release our storage. */
3623 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3625 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3626 dwarf2_per_objfile
->info
.buffer
,
3627 dwarf2_per_objfile
->info
.size
,
3630 /* Skip dummy compilation units. */
3631 if (info_ptr
>= (dwarf2_per_objfile
->info
.buffer
3632 + dwarf2_per_objfile
->info
.size
)
3633 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3635 do_cleanups (free_cu_cleanup
);
3639 /* Link this CU into read_in_chain. */
3640 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3641 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3646 info_ptr
+= cu
->header
.first_die_offset
;
3649 /* Read the abbrevs for this compilation unit into a table. */
3650 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3651 dwarf2_read_abbrevs (cu
);
3652 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3654 /* Read the compilation unit die. */
3655 init_cu_die_reader (&reader_specs
, cu
);
3656 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3659 prepare_one_comp_unit (cu
, comp_unit_die
);
3661 /* Check if comp unit has_children.
3662 If so, read the rest of the partial symbols from this comp unit.
3663 If not, there's no more debug_info for this comp unit. */
3665 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3667 do_cleanups (free_abbrevs_cleanup
);
3671 /* We've successfully allocated this compilation unit. Let our
3672 caller clean it up when finished with it. */
3673 discard_cleanups (free_cu_cleanup
);
3677 /* Create a list of all compilation units in OBJFILE.
3678 This is only done for -readnow and building partial symtabs. */
3681 create_all_comp_units (struct objfile
*objfile
)
3685 struct dwarf2_per_cu_data
**all_comp_units
;
3688 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3689 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3693 all_comp_units
= xmalloc (n_allocated
3694 * sizeof (struct dwarf2_per_cu_data
*));
3696 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3697 + dwarf2_per_objfile
->info
.size
)
3699 unsigned int length
, initial_length_size
;
3700 struct dwarf2_per_cu_data
*this_cu
;
3701 unsigned int offset
;
3703 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3705 /* Read just enough information to find out where the next
3706 compilation unit is. */
3707 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3708 &initial_length_size
);
3710 /* Save the compilation unit for later lookup. */
3711 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3712 sizeof (struct dwarf2_per_cu_data
));
3713 memset (this_cu
, 0, sizeof (*this_cu
));
3714 this_cu
->offset
= offset
;
3715 this_cu
->length
= length
+ initial_length_size
;
3716 this_cu
->objfile
= objfile
;
3718 if (n_comp_units
== n_allocated
)
3721 all_comp_units
= xrealloc (all_comp_units
,
3723 * sizeof (struct dwarf2_per_cu_data
*));
3725 all_comp_units
[n_comp_units
++] = this_cu
;
3727 info_ptr
= info_ptr
+ this_cu
->length
;
3730 dwarf2_per_objfile
->all_comp_units
3731 = obstack_alloc (&objfile
->objfile_obstack
,
3732 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3733 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3734 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3735 xfree (all_comp_units
);
3736 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3739 /* Process all loaded DIEs for compilation unit CU, starting at
3740 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3741 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3742 DW_AT_ranges). If NEED_PC is set, then this function will set
3743 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3744 and record the covered ranges in the addrmap. */
3747 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3748 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3750 struct partial_die_info
*pdi
;
3752 /* Now, march along the PDI's, descending into ones which have
3753 interesting children but skipping the children of the other ones,
3754 until we reach the end of the compilation unit. */
3760 fixup_partial_die (pdi
, cu
);
3762 /* Anonymous namespaces or modules have no name but have interesting
3763 children, so we need to look at them. Ditto for anonymous
3766 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3767 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3771 case DW_TAG_subprogram
:
3772 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3774 case DW_TAG_constant
:
3775 case DW_TAG_variable
:
3776 case DW_TAG_typedef
:
3777 case DW_TAG_union_type
:
3778 if (!pdi
->is_declaration
)
3780 add_partial_symbol (pdi
, cu
);
3783 case DW_TAG_class_type
:
3784 case DW_TAG_interface_type
:
3785 case DW_TAG_structure_type
:
3786 if (!pdi
->is_declaration
)
3788 add_partial_symbol (pdi
, cu
);
3791 case DW_TAG_enumeration_type
:
3792 if (!pdi
->is_declaration
)
3793 add_partial_enumeration (pdi
, cu
);
3795 case DW_TAG_base_type
:
3796 case DW_TAG_subrange_type
:
3797 /* File scope base type definitions are added to the partial
3799 add_partial_symbol (pdi
, cu
);
3801 case DW_TAG_namespace
:
3802 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3805 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3812 /* If the die has a sibling, skip to the sibling. */
3814 pdi
= pdi
->die_sibling
;
3818 /* Functions used to compute the fully scoped name of a partial DIE.
3820 Normally, this is simple. For C++, the parent DIE's fully scoped
3821 name is concatenated with "::" and the partial DIE's name. For
3822 Java, the same thing occurs except that "." is used instead of "::".
3823 Enumerators are an exception; they use the scope of their parent
3824 enumeration type, i.e. the name of the enumeration type is not
3825 prepended to the enumerator.
3827 There are two complexities. One is DW_AT_specification; in this
3828 case "parent" means the parent of the target of the specification,
3829 instead of the direct parent of the DIE. The other is compilers
3830 which do not emit DW_TAG_namespace; in this case we try to guess
3831 the fully qualified name of structure types from their members'
3832 linkage names. This must be done using the DIE's children rather
3833 than the children of any DW_AT_specification target. We only need
3834 to do this for structures at the top level, i.e. if the target of
3835 any DW_AT_specification (if any; otherwise the DIE itself) does not
3838 /* Compute the scope prefix associated with PDI's parent, in
3839 compilation unit CU. The result will be allocated on CU's
3840 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3841 field. NULL is returned if no prefix is necessary. */
3843 partial_die_parent_scope (struct partial_die_info
*pdi
,
3844 struct dwarf2_cu
*cu
)
3846 char *grandparent_scope
;
3847 struct partial_die_info
*parent
, *real_pdi
;
3849 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3850 then this means the parent of the specification DIE. */
3853 while (real_pdi
->has_specification
)
3854 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3856 parent
= real_pdi
->die_parent
;
3860 if (parent
->scope_set
)
3861 return parent
->scope
;
3863 fixup_partial_die (parent
, cu
);
3865 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3867 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3868 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3869 Work around this problem here. */
3870 if (cu
->language
== language_cplus
3871 && parent
->tag
== DW_TAG_namespace
3872 && strcmp (parent
->name
, "::") == 0
3873 && grandparent_scope
== NULL
)
3875 parent
->scope
= NULL
;
3876 parent
->scope_set
= 1;
3880 if (pdi
->tag
== DW_TAG_enumerator
)
3881 /* Enumerators should not get the name of the enumeration as a prefix. */
3882 parent
->scope
= grandparent_scope
;
3883 else if (parent
->tag
== DW_TAG_namespace
3884 || parent
->tag
== DW_TAG_module
3885 || parent
->tag
== DW_TAG_structure_type
3886 || parent
->tag
== DW_TAG_class_type
3887 || parent
->tag
== DW_TAG_interface_type
3888 || parent
->tag
== DW_TAG_union_type
3889 || parent
->tag
== DW_TAG_enumeration_type
)
3891 if (grandparent_scope
== NULL
)
3892 parent
->scope
= parent
->name
;
3894 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3896 parent
->name
, 0, cu
);
3900 /* FIXME drow/2004-04-01: What should we be doing with
3901 function-local names? For partial symbols, we should probably be
3903 complaint (&symfile_complaints
,
3904 _("unhandled containing DIE tag %d for DIE at %d"),
3905 parent
->tag
, pdi
->offset
);
3906 parent
->scope
= grandparent_scope
;
3909 parent
->scope_set
= 1;
3910 return parent
->scope
;
3913 /* Return the fully scoped name associated with PDI, from compilation unit
3914 CU. The result will be allocated with malloc. */
3916 partial_die_full_name (struct partial_die_info
*pdi
,
3917 struct dwarf2_cu
*cu
)
3921 /* If this is a template instantiation, we can not work out the
3922 template arguments from partial DIEs. So, unfortunately, we have
3923 to go through the full DIEs. At least any work we do building
3924 types here will be reused if full symbols are loaded later. */
3925 if (pdi
->has_template_arguments
)
3927 fixup_partial_die (pdi
, cu
);
3929 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3931 struct die_info
*die
;
3932 struct attribute attr
;
3933 struct dwarf2_cu
*ref_cu
= cu
;
3936 attr
.form
= DW_FORM_ref_addr
;
3937 attr
.u
.addr
= pdi
->offset
;
3938 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3940 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3944 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3945 if (parent_scope
== NULL
)
3948 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3952 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3954 struct objfile
*objfile
= cu
->objfile
;
3956 char *actual_name
= NULL
;
3957 const struct partial_symbol
*psym
= NULL
;
3959 int built_actual_name
= 0;
3961 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3963 actual_name
= partial_die_full_name (pdi
, cu
);
3965 built_actual_name
= 1;
3967 if (actual_name
== NULL
)
3968 actual_name
= pdi
->name
;
3972 case DW_TAG_subprogram
:
3973 if (pdi
->is_external
|| cu
->language
== language_ada
)
3975 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3976 of the global scope. But in Ada, we want to be able to access
3977 nested procedures globally. So all Ada subprograms are stored
3978 in the global scope. */
3979 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3980 mst_text, objfile); */
3981 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3983 VAR_DOMAIN
, LOC_BLOCK
,
3984 &objfile
->global_psymbols
,
3985 0, pdi
->lowpc
+ baseaddr
,
3986 cu
->language
, objfile
);
3990 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3991 mst_file_text, objfile); */
3992 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3994 VAR_DOMAIN
, LOC_BLOCK
,
3995 &objfile
->static_psymbols
,
3996 0, pdi
->lowpc
+ baseaddr
,
3997 cu
->language
, objfile
);
4000 case DW_TAG_constant
:
4002 struct psymbol_allocation_list
*list
;
4004 if (pdi
->is_external
)
4005 list
= &objfile
->global_psymbols
;
4007 list
= &objfile
->static_psymbols
;
4008 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4009 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4010 list
, 0, 0, cu
->language
, objfile
);
4013 case DW_TAG_variable
:
4015 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4019 && !dwarf2_per_objfile
->has_section_at_zero
)
4021 /* A global or static variable may also have been stripped
4022 out by the linker if unused, in which case its address
4023 will be nullified; do not add such variables into partial
4024 symbol table then. */
4026 else if (pdi
->is_external
)
4029 Don't enter into the minimal symbol tables as there is
4030 a minimal symbol table entry from the ELF symbols already.
4031 Enter into partial symbol table if it has a location
4032 descriptor or a type.
4033 If the location descriptor is missing, new_symbol will create
4034 a LOC_UNRESOLVED symbol, the address of the variable will then
4035 be determined from the minimal symbol table whenever the variable
4037 The address for the partial symbol table entry is not
4038 used by GDB, but it comes in handy for debugging partial symbol
4041 if (pdi
->locdesc
|| pdi
->has_type
)
4042 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4044 VAR_DOMAIN
, LOC_STATIC
,
4045 &objfile
->global_psymbols
,
4047 cu
->language
, objfile
);
4051 /* Static Variable. Skip symbols without location descriptors. */
4052 if (pdi
->locdesc
== NULL
)
4054 if (built_actual_name
)
4055 xfree (actual_name
);
4058 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4059 mst_file_data, objfile); */
4060 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4062 VAR_DOMAIN
, LOC_STATIC
,
4063 &objfile
->static_psymbols
,
4065 cu
->language
, objfile
);
4068 case DW_TAG_typedef
:
4069 case DW_TAG_base_type
:
4070 case DW_TAG_subrange_type
:
4071 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4073 VAR_DOMAIN
, LOC_TYPEDEF
,
4074 &objfile
->static_psymbols
,
4075 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4077 case DW_TAG_namespace
:
4078 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4080 VAR_DOMAIN
, LOC_TYPEDEF
,
4081 &objfile
->global_psymbols
,
4082 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4084 case DW_TAG_class_type
:
4085 case DW_TAG_interface_type
:
4086 case DW_TAG_structure_type
:
4087 case DW_TAG_union_type
:
4088 case DW_TAG_enumeration_type
:
4089 /* Skip external references. The DWARF standard says in the section
4090 about "Structure, Union, and Class Type Entries": "An incomplete
4091 structure, union or class type is represented by a structure,
4092 union or class entry that does not have a byte size attribute
4093 and that has a DW_AT_declaration attribute." */
4094 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4096 if (built_actual_name
)
4097 xfree (actual_name
);
4101 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4102 static vs. global. */
4103 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4105 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4106 (cu
->language
== language_cplus
4107 || cu
->language
== language_java
)
4108 ? &objfile
->global_psymbols
4109 : &objfile
->static_psymbols
,
4110 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4113 case DW_TAG_enumerator
:
4114 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4116 VAR_DOMAIN
, LOC_CONST
,
4117 (cu
->language
== language_cplus
4118 || cu
->language
== language_java
)
4119 ? &objfile
->global_psymbols
4120 : &objfile
->static_psymbols
,
4121 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4127 if (built_actual_name
)
4128 xfree (actual_name
);
4131 /* Read a partial die corresponding to a namespace; also, add a symbol
4132 corresponding to that namespace to the symbol table. NAMESPACE is
4133 the name of the enclosing namespace. */
4136 add_partial_namespace (struct partial_die_info
*pdi
,
4137 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4138 int need_pc
, struct dwarf2_cu
*cu
)
4140 /* Add a symbol for the namespace. */
4142 add_partial_symbol (pdi
, cu
);
4144 /* Now scan partial symbols in that namespace. */
4146 if (pdi
->has_children
)
4147 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4150 /* Read a partial die corresponding to a Fortran module. */
4153 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4154 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4156 /* Now scan partial symbols in that module. */
4158 if (pdi
->has_children
)
4159 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4162 /* Read a partial die corresponding to a subprogram and create a partial
4163 symbol for that subprogram. When the CU language allows it, this
4164 routine also defines a partial symbol for each nested subprogram
4165 that this subprogram contains.
4167 DIE my also be a lexical block, in which case we simply search
4168 recursively for suprograms defined inside that lexical block.
4169 Again, this is only performed when the CU language allows this
4170 type of definitions. */
4173 add_partial_subprogram (struct partial_die_info
*pdi
,
4174 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4175 int need_pc
, struct dwarf2_cu
*cu
)
4177 if (pdi
->tag
== DW_TAG_subprogram
)
4179 if (pdi
->has_pc_info
)
4181 if (pdi
->lowpc
< *lowpc
)
4182 *lowpc
= pdi
->lowpc
;
4183 if (pdi
->highpc
> *highpc
)
4184 *highpc
= pdi
->highpc
;
4188 struct objfile
*objfile
= cu
->objfile
;
4190 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4191 SECT_OFF_TEXT (objfile
));
4192 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4193 pdi
->lowpc
+ baseaddr
,
4194 pdi
->highpc
- 1 + baseaddr
,
4195 cu
->per_cu
->v
.psymtab
);
4197 if (!pdi
->is_declaration
)
4198 /* Ignore subprogram DIEs that do not have a name, they are
4199 illegal. Do not emit a complaint at this point, we will
4200 do so when we convert this psymtab into a symtab. */
4202 add_partial_symbol (pdi
, cu
);
4206 if (! pdi
->has_children
)
4209 if (cu
->language
== language_ada
)
4211 pdi
= pdi
->die_child
;
4214 fixup_partial_die (pdi
, cu
);
4215 if (pdi
->tag
== DW_TAG_subprogram
4216 || pdi
->tag
== DW_TAG_lexical_block
)
4217 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4218 pdi
= pdi
->die_sibling
;
4223 /* Read a partial die corresponding to an enumeration type. */
4226 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4227 struct dwarf2_cu
*cu
)
4229 struct partial_die_info
*pdi
;
4231 if (enum_pdi
->name
!= NULL
)
4232 add_partial_symbol (enum_pdi
, cu
);
4234 pdi
= enum_pdi
->die_child
;
4237 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4238 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4240 add_partial_symbol (pdi
, cu
);
4241 pdi
= pdi
->die_sibling
;
4245 /* Return the initial uleb128 in the die at INFO_PTR. */
4248 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4250 unsigned int bytes_read
;
4252 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4255 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4256 Return the corresponding abbrev, or NULL if the number is zero (indicating
4257 an empty DIE). In either case *BYTES_READ will be set to the length of
4258 the initial number. */
4260 static struct abbrev_info
*
4261 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4262 struct dwarf2_cu
*cu
)
4264 bfd
*abfd
= cu
->objfile
->obfd
;
4265 unsigned int abbrev_number
;
4266 struct abbrev_info
*abbrev
;
4268 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4270 if (abbrev_number
== 0)
4273 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4276 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4277 abbrev_number
, bfd_get_filename (abfd
));
4283 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4284 Returns a pointer to the end of a series of DIEs, terminated by an empty
4285 DIE. Any children of the skipped DIEs will also be skipped. */
4288 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4290 struct abbrev_info
*abbrev
;
4291 unsigned int bytes_read
;
4295 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4297 return info_ptr
+ bytes_read
;
4299 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4303 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4304 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4305 abbrev corresponding to that skipped uleb128 should be passed in
4306 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4310 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4311 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4313 unsigned int bytes_read
;
4314 struct attribute attr
;
4315 bfd
*abfd
= cu
->objfile
->obfd
;
4316 unsigned int form
, i
;
4318 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4320 /* The only abbrev we care about is DW_AT_sibling. */
4321 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4323 read_attribute (&attr
, &abbrev
->attrs
[i
],
4324 abfd
, info_ptr
, cu
);
4325 if (attr
.form
== DW_FORM_ref_addr
)
4326 complaint (&symfile_complaints
,
4327 _("ignoring absolute DW_AT_sibling"));
4329 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4332 /* If it isn't DW_AT_sibling, skip this attribute. */
4333 form
= abbrev
->attrs
[i
].form
;
4337 case DW_FORM_ref_addr
:
4338 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4339 and later it is offset sized. */
4340 if (cu
->header
.version
== 2)
4341 info_ptr
+= cu
->header
.addr_size
;
4343 info_ptr
+= cu
->header
.offset_size
;
4346 info_ptr
+= cu
->header
.addr_size
;
4353 case DW_FORM_flag_present
:
4365 case DW_FORM_ref_sig8
:
4368 case DW_FORM_string
:
4369 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4370 info_ptr
+= bytes_read
;
4372 case DW_FORM_sec_offset
:
4374 info_ptr
+= cu
->header
.offset_size
;
4376 case DW_FORM_exprloc
:
4378 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4379 info_ptr
+= bytes_read
;
4381 case DW_FORM_block1
:
4382 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4384 case DW_FORM_block2
:
4385 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4387 case DW_FORM_block4
:
4388 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4392 case DW_FORM_ref_udata
:
4393 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4395 case DW_FORM_indirect
:
4396 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4397 info_ptr
+= bytes_read
;
4398 /* We need to continue parsing from here, so just go back to
4400 goto skip_attribute
;
4403 error (_("Dwarf Error: Cannot handle %s "
4404 "in DWARF reader [in module %s]"),
4405 dwarf_form_name (form
),
4406 bfd_get_filename (abfd
));
4410 if (abbrev
->has_children
)
4411 return skip_children (buffer
, info_ptr
, cu
);
4416 /* Locate ORIG_PDI's sibling.
4417 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4421 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4422 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4423 bfd
*abfd
, struct dwarf2_cu
*cu
)
4425 /* Do we know the sibling already? */
4427 if (orig_pdi
->sibling
)
4428 return orig_pdi
->sibling
;
4430 /* Are there any children to deal with? */
4432 if (!orig_pdi
->has_children
)
4435 /* Skip the children the long way. */
4437 return skip_children (buffer
, info_ptr
, cu
);
4440 /* Expand this partial symbol table into a full symbol table. */
4443 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4449 warning (_("bug: psymtab for %s is already read in."),
4456 printf_filtered (_("Reading in symbols for %s..."),
4458 gdb_flush (gdb_stdout
);
4461 /* Restore our global data. */
4462 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4463 dwarf2_objfile_data_key
);
4465 /* If this psymtab is constructed from a debug-only objfile, the
4466 has_section_at_zero flag will not necessarily be correct. We
4467 can get the correct value for this flag by looking at the data
4468 associated with the (presumably stripped) associated objfile. */
4469 if (pst
->objfile
->separate_debug_objfile_backlink
)
4471 struct dwarf2_per_objfile
*dpo_backlink
4472 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4473 dwarf2_objfile_data_key
);
4475 dwarf2_per_objfile
->has_section_at_zero
4476 = dpo_backlink
->has_section_at_zero
;
4479 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4481 psymtab_to_symtab_1 (pst
);
4483 /* Finish up the debug error message. */
4485 printf_filtered (_("done.\n"));
4490 /* Reading in full CUs. */
4492 /* Add PER_CU to the queue. */
4495 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4497 struct dwarf2_queue_item
*item
;
4500 item
= xmalloc (sizeof (*item
));
4501 item
->per_cu
= per_cu
;
4504 if (dwarf2_queue
== NULL
)
4505 dwarf2_queue
= item
;
4507 dwarf2_queue_tail
->next
= item
;
4509 dwarf2_queue_tail
= item
;
4512 /* Process the queue. */
4515 process_queue (void)
4517 struct dwarf2_queue_item
*item
, *next_item
;
4519 /* The queue starts out with one item, but following a DIE reference
4520 may load a new CU, adding it to the end of the queue. */
4521 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4523 if (dwarf2_per_objfile
->using_index
4524 ? !item
->per_cu
->v
.quick
->symtab
4525 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4526 process_full_comp_unit (item
->per_cu
);
4528 item
->per_cu
->queued
= 0;
4529 next_item
= item
->next
;
4533 dwarf2_queue_tail
= NULL
;
4536 /* Free all allocated queue entries. This function only releases anything if
4537 an error was thrown; if the queue was processed then it would have been
4538 freed as we went along. */
4541 dwarf2_release_queue (void *dummy
)
4543 struct dwarf2_queue_item
*item
, *last
;
4545 item
= dwarf2_queue
;
4548 /* Anything still marked queued is likely to be in an
4549 inconsistent state, so discard it. */
4550 if (item
->per_cu
->queued
)
4552 if (item
->per_cu
->cu
!= NULL
)
4553 free_one_cached_comp_unit (item
->per_cu
->cu
);
4554 item
->per_cu
->queued
= 0;
4562 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4565 /* Read in full symbols for PST, and anything it depends on. */
4568 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4570 struct dwarf2_per_cu_data
*per_cu
;
4571 struct cleanup
*back_to
;
4574 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4575 if (!pst
->dependencies
[i
]->readin
)
4577 /* Inform about additional files that need to be read in. */
4580 /* FIXME: i18n: Need to make this a single string. */
4581 fputs_filtered (" ", gdb_stdout
);
4583 fputs_filtered ("and ", gdb_stdout
);
4585 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4586 wrap_here (""); /* Flush output. */
4587 gdb_flush (gdb_stdout
);
4589 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4592 per_cu
= pst
->read_symtab_private
;
4596 /* It's an include file, no symbols to read for it.
4597 Everything is in the parent symtab. */
4602 dw2_do_instantiate_symtab (per_cu
);
4605 /* Load the DIEs associated with PER_CU into memory. */
4608 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4610 struct objfile
*objfile
= per_cu
->objfile
;
4611 bfd
*abfd
= objfile
->obfd
;
4612 struct dwarf2_cu
*cu
;
4613 unsigned int offset
;
4614 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4615 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4616 struct attribute
*attr
;
4619 gdb_assert (! per_cu
->debug_types_section
);
4621 /* Set local variables from the partial symbol table info. */
4622 offset
= per_cu
->offset
;
4624 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4625 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4626 beg_of_comp_unit
= info_ptr
;
4628 if (per_cu
->cu
== NULL
)
4630 cu
= xmalloc (sizeof (*cu
));
4631 init_one_comp_unit (cu
, per_cu
);
4635 /* If an error occurs while loading, release our storage. */
4636 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4638 /* Read in the comp_unit header. */
4639 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4641 /* Skip dummy compilation units. */
4642 if (info_ptr
>= (dwarf2_per_objfile
->info
.buffer
4643 + dwarf2_per_objfile
->info
.size
)
4644 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4646 do_cleanups (free_cu_cleanup
);
4650 /* Complete the cu_header. */
4651 cu
->header
.offset
= offset
;
4652 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4654 /* Read the abbrevs for this compilation unit. */
4655 dwarf2_read_abbrevs (cu
);
4656 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4658 /* Link this CU into read_in_chain. */
4659 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4660 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4665 info_ptr
+= cu
->header
.first_die_offset
;
4668 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4670 /* We try not to read any attributes in this function, because not
4671 all CUs needed for references have been loaded yet, and symbol
4672 table processing isn't initialized. But we have to set the CU language,
4673 or we won't be able to build types correctly. */
4674 prepare_one_comp_unit (cu
, cu
->dies
);
4676 /* Similarly, if we do not read the producer, we can not apply
4677 producer-specific interpretation. */
4678 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4680 cu
->producer
= DW_STRING (attr
);
4684 do_cleanups (free_abbrevs_cleanup
);
4686 /* We've successfully allocated this compilation unit. Let our
4687 caller clean it up when finished with it. */
4688 discard_cleanups (free_cu_cleanup
);
4692 /* Add a DIE to the delayed physname list. */
4695 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4696 const char *name
, struct die_info
*die
,
4697 struct dwarf2_cu
*cu
)
4699 struct delayed_method_info mi
;
4701 mi
.fnfield_index
= fnfield_index
;
4705 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4708 /* A cleanup for freeing the delayed method list. */
4711 free_delayed_list (void *ptr
)
4713 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4714 if (cu
->method_list
!= NULL
)
4716 VEC_free (delayed_method_info
, cu
->method_list
);
4717 cu
->method_list
= NULL
;
4721 /* Compute the physnames of any methods on the CU's method list.
4723 The computation of method physnames is delayed in order to avoid the
4724 (bad) condition that one of the method's formal parameters is of an as yet
4728 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4731 struct delayed_method_info
*mi
;
4732 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4734 const char *physname
;
4735 struct fn_fieldlist
*fn_flp
4736 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4737 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4738 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4742 /* Generate full symbol information for PER_CU, whose DIEs have
4743 already been loaded into memory. */
4746 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4748 struct dwarf2_cu
*cu
= per_cu
->cu
;
4749 struct objfile
*objfile
= per_cu
->objfile
;
4750 CORE_ADDR lowpc
, highpc
;
4751 struct symtab
*symtab
;
4752 struct cleanup
*back_to
, *delayed_list_cleanup
;
4755 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4758 back_to
= make_cleanup (really_free_pendings
, NULL
);
4759 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4761 cu
->list_in_scope
= &file_symbols
;
4763 /* Do line number decoding in read_file_scope () */
4764 process_die (cu
->dies
, cu
);
4766 /* Now that we have processed all the DIEs in the CU, all the types
4767 should be complete, and it should now be safe to compute all of the
4769 compute_delayed_physnames (cu
);
4770 do_cleanups (delayed_list_cleanup
);
4772 /* Some compilers don't define a DW_AT_high_pc attribute for the
4773 compilation unit. If the DW_AT_high_pc is missing, synthesize
4774 it, by scanning the DIE's below the compilation unit. */
4775 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4777 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4781 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
4783 /* Set symtab language to language from DW_AT_language. If the
4784 compilation is from a C file generated by language preprocessors, do
4785 not set the language if it was already deduced by start_subfile. */
4786 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4787 symtab
->language
= cu
->language
;
4789 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4790 produce DW_AT_location with location lists but it can be possibly
4791 invalid without -fvar-tracking.
4793 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4794 needed, it would be wrong due to missing DW_AT_producer there.
4796 Still one can confuse GDB by using non-standard GCC compilation
4797 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4799 if (cu
->has_loclist
&& gcc_4_minor
>= 0)
4800 symtab
->locations_valid
= 1;
4802 if (gcc_4_minor
>= 5)
4803 symtab
->epilogue_unwind_valid
= 1;
4805 symtab
->call_site_htab
= cu
->call_site_htab
;
4808 if (dwarf2_per_objfile
->using_index
)
4809 per_cu
->v
.quick
->symtab
= symtab
;
4812 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4813 pst
->symtab
= symtab
;
4817 do_cleanups (back_to
);
4820 /* Process a die and its children. */
4823 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4827 case DW_TAG_padding
:
4829 case DW_TAG_compile_unit
:
4830 read_file_scope (die
, cu
);
4832 case DW_TAG_type_unit
:
4833 read_type_unit_scope (die
, cu
);
4835 case DW_TAG_subprogram
:
4836 case DW_TAG_inlined_subroutine
:
4837 read_func_scope (die
, cu
);
4839 case DW_TAG_lexical_block
:
4840 case DW_TAG_try_block
:
4841 case DW_TAG_catch_block
:
4842 read_lexical_block_scope (die
, cu
);
4844 case DW_TAG_GNU_call_site
:
4845 read_call_site_scope (die
, cu
);
4847 case DW_TAG_class_type
:
4848 case DW_TAG_interface_type
:
4849 case DW_TAG_structure_type
:
4850 case DW_TAG_union_type
:
4851 process_structure_scope (die
, cu
);
4853 case DW_TAG_enumeration_type
:
4854 process_enumeration_scope (die
, cu
);
4857 /* These dies have a type, but processing them does not create
4858 a symbol or recurse to process the children. Therefore we can
4859 read them on-demand through read_type_die. */
4860 case DW_TAG_subroutine_type
:
4861 case DW_TAG_set_type
:
4862 case DW_TAG_array_type
:
4863 case DW_TAG_pointer_type
:
4864 case DW_TAG_ptr_to_member_type
:
4865 case DW_TAG_reference_type
:
4866 case DW_TAG_string_type
:
4869 case DW_TAG_base_type
:
4870 case DW_TAG_subrange_type
:
4871 case DW_TAG_typedef
:
4872 /* Add a typedef symbol for the type definition, if it has a
4874 new_symbol (die
, read_type_die (die
, cu
), cu
);
4876 case DW_TAG_common_block
:
4877 read_common_block (die
, cu
);
4879 case DW_TAG_common_inclusion
:
4881 case DW_TAG_namespace
:
4882 processing_has_namespace_info
= 1;
4883 read_namespace (die
, cu
);
4886 processing_has_namespace_info
= 1;
4887 read_module (die
, cu
);
4889 case DW_TAG_imported_declaration
:
4890 case DW_TAG_imported_module
:
4891 processing_has_namespace_info
= 1;
4892 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4893 || cu
->language
!= language_fortran
))
4894 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4895 dwarf_tag_name (die
->tag
));
4896 read_import_statement (die
, cu
);
4899 new_symbol (die
, NULL
, cu
);
4904 /* A helper function for dwarf2_compute_name which determines whether DIE
4905 needs to have the name of the scope prepended to the name listed in the
4909 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4911 struct attribute
*attr
;
4915 case DW_TAG_namespace
:
4916 case DW_TAG_typedef
:
4917 case DW_TAG_class_type
:
4918 case DW_TAG_interface_type
:
4919 case DW_TAG_structure_type
:
4920 case DW_TAG_union_type
:
4921 case DW_TAG_enumeration_type
:
4922 case DW_TAG_enumerator
:
4923 case DW_TAG_subprogram
:
4927 case DW_TAG_variable
:
4928 case DW_TAG_constant
:
4929 /* We only need to prefix "globally" visible variables. These include
4930 any variable marked with DW_AT_external or any variable that
4931 lives in a namespace. [Variables in anonymous namespaces
4932 require prefixing, but they are not DW_AT_external.] */
4934 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4936 struct dwarf2_cu
*spec_cu
= cu
;
4938 return die_needs_namespace (die_specification (die
, &spec_cu
),
4942 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4943 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4944 && die
->parent
->tag
!= DW_TAG_module
)
4946 /* A variable in a lexical block of some kind does not need a
4947 namespace, even though in C++ such variables may be external
4948 and have a mangled name. */
4949 if (die
->parent
->tag
== DW_TAG_lexical_block
4950 || die
->parent
->tag
== DW_TAG_try_block
4951 || die
->parent
->tag
== DW_TAG_catch_block
4952 || die
->parent
->tag
== DW_TAG_subprogram
)
4961 /* Retrieve the last character from a mem_file. */
4964 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4966 char *last_char_p
= (char *) object
;
4969 *last_char_p
= buffer
[length
- 1];
4972 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4973 compute the physname for the object, which include a method's
4974 formal parameters (C++/Java) and return type (Java).
4976 For Ada, return the DIE's linkage name rather than the fully qualified
4977 name. PHYSNAME is ignored..
4979 The result is allocated on the objfile_obstack and canonicalized. */
4982 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4985 struct objfile
*objfile
= cu
->objfile
;
4988 name
= dwarf2_name (die
, cu
);
4990 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4991 compute it by typename_concat inside GDB. */
4992 if (cu
->language
== language_ada
4993 || (cu
->language
== language_fortran
&& physname
))
4995 /* For Ada unit, we prefer the linkage name over the name, as
4996 the former contains the exported name, which the user expects
4997 to be able to reference. Ideally, we want the user to be able
4998 to reference this entity using either natural or linkage name,
4999 but we haven't started looking at this enhancement yet. */
5000 struct attribute
*attr
;
5002 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5004 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5005 if (attr
&& DW_STRING (attr
))
5006 return DW_STRING (attr
);
5009 /* These are the only languages we know how to qualify names in. */
5011 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5012 || cu
->language
== language_fortran
))
5014 if (die_needs_namespace (die
, cu
))
5018 struct ui_file
*buf
;
5020 prefix
= determine_prefix (die
, cu
);
5021 buf
= mem_fileopen ();
5022 if (*prefix
!= '\0')
5024 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5027 fputs_unfiltered (prefixed_name
, buf
);
5028 xfree (prefixed_name
);
5031 fputs_unfiltered (name
, buf
);
5033 /* Template parameters may be specified in the DIE's DW_AT_name, or
5034 as children with DW_TAG_template_type_param or
5035 DW_TAG_value_type_param. If the latter, add them to the name
5036 here. If the name already has template parameters, then
5037 skip this step; some versions of GCC emit both, and
5038 it is more efficient to use the pre-computed name.
5040 Something to keep in mind about this process: it is very
5041 unlikely, or in some cases downright impossible, to produce
5042 something that will match the mangled name of a function.
5043 If the definition of the function has the same debug info,
5044 we should be able to match up with it anyway. But fallbacks
5045 using the minimal symbol, for instance to find a method
5046 implemented in a stripped copy of libstdc++, will not work.
5047 If we do not have debug info for the definition, we will have to
5048 match them up some other way.
5050 When we do name matching there is a related problem with function
5051 templates; two instantiated function templates are allowed to
5052 differ only by their return types, which we do not add here. */
5054 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5056 struct attribute
*attr
;
5057 struct die_info
*child
;
5060 die
->building_fullname
= 1;
5062 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5067 struct dwarf2_locexpr_baton
*baton
;
5070 if (child
->tag
!= DW_TAG_template_type_param
5071 && child
->tag
!= DW_TAG_template_value_param
)
5076 fputs_unfiltered ("<", buf
);
5080 fputs_unfiltered (", ", buf
);
5082 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5085 complaint (&symfile_complaints
,
5086 _("template parameter missing DW_AT_type"));
5087 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5090 type
= die_type (child
, cu
);
5092 if (child
->tag
== DW_TAG_template_type_param
)
5094 c_print_type (type
, "", buf
, -1, 0);
5098 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5101 complaint (&symfile_complaints
,
5102 _("template parameter missing "
5103 "DW_AT_const_value"));
5104 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5108 dwarf2_const_value_attr (attr
, type
, name
,
5109 &cu
->comp_unit_obstack
, cu
,
5110 &value
, &bytes
, &baton
);
5112 if (TYPE_NOSIGN (type
))
5113 /* GDB prints characters as NUMBER 'CHAR'. If that's
5114 changed, this can use value_print instead. */
5115 c_printchar (value
, type
, buf
);
5118 struct value_print_options opts
;
5121 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5125 else if (bytes
!= NULL
)
5127 v
= allocate_value (type
);
5128 memcpy (value_contents_writeable (v
), bytes
,
5129 TYPE_LENGTH (type
));
5132 v
= value_from_longest (type
, value
);
5134 /* Specify decimal so that we do not depend on
5136 get_formatted_print_options (&opts
, 'd');
5138 value_print (v
, buf
, &opts
);
5144 die
->building_fullname
= 0;
5148 /* Close the argument list, with a space if necessary
5149 (nested templates). */
5150 char last_char
= '\0';
5151 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5152 if (last_char
== '>')
5153 fputs_unfiltered (" >", buf
);
5155 fputs_unfiltered (">", buf
);
5159 /* For Java and C++ methods, append formal parameter type
5160 information, if PHYSNAME. */
5162 if (physname
&& die
->tag
== DW_TAG_subprogram
5163 && (cu
->language
== language_cplus
5164 || cu
->language
== language_java
))
5166 struct type
*type
= read_type_die (die
, cu
);
5168 c_type_print_args (type
, buf
, 1, cu
->language
);
5170 if (cu
->language
== language_java
)
5172 /* For java, we must append the return type to method
5174 if (die
->tag
== DW_TAG_subprogram
)
5175 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5178 else if (cu
->language
== language_cplus
)
5180 /* Assume that an artificial first parameter is
5181 "this", but do not crash if it is not. RealView
5182 marks unnamed (and thus unused) parameters as
5183 artificial; there is no way to differentiate
5185 if (TYPE_NFIELDS (type
) > 0
5186 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5187 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5188 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5190 fputs_unfiltered (" const", buf
);
5194 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
5196 ui_file_delete (buf
);
5198 if (cu
->language
== language_cplus
)
5201 = dwarf2_canonicalize_name (name
, cu
,
5202 &objfile
->objfile_obstack
);
5213 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5214 If scope qualifiers are appropriate they will be added. The result
5215 will be allocated on the objfile_obstack, or NULL if the DIE does
5216 not have a name. NAME may either be from a previous call to
5217 dwarf2_name or NULL.
5219 The output string will be canonicalized (if C++/Java). */
5222 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5224 return dwarf2_compute_name (name
, die
, cu
, 0);
5227 /* Construct a physname for the given DIE in CU. NAME may either be
5228 from a previous call to dwarf2_name or NULL. The result will be
5229 allocated on the objfile_objstack or NULL if the DIE does not have a
5232 The output string will be canonicalized (if C++/Java). */
5235 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5237 struct objfile
*objfile
= cu
->objfile
;
5238 struct attribute
*attr
;
5239 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5240 struct cleanup
*back_to
;
5243 /* In this case dwarf2_compute_name is just a shortcut not building anything
5245 if (!die_needs_namespace (die
, cu
))
5246 return dwarf2_compute_name (name
, die
, cu
, 1);
5248 back_to
= make_cleanup (null_cleanup
, NULL
);
5250 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5252 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5254 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5256 if (attr
&& DW_STRING (attr
))
5260 mangled
= DW_STRING (attr
);
5262 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5263 type. It is easier for GDB users to search for such functions as
5264 `name(params)' than `long name(params)'. In such case the minimal
5265 symbol names do not match the full symbol names but for template
5266 functions there is never a need to look up their definition from their
5267 declaration so the only disadvantage remains the minimal symbol
5268 variant `long name(params)' does not have the proper inferior type.
5271 demangled
= cplus_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
5272 | (cu
->language
== language_java
5273 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5277 make_cleanup (xfree
, demangled
);
5287 if (canon
== NULL
|| check_physname
)
5289 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5291 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5293 /* It may not mean a bug in GDB. The compiler could also
5294 compute DW_AT_linkage_name incorrectly. But in such case
5295 GDB would need to be bug-to-bug compatible. */
5297 complaint (&symfile_complaints
,
5298 _("Computed physname <%s> does not match demangled <%s> "
5299 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5300 physname
, canon
, mangled
, die
->offset
, objfile
->name
);
5302 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5303 is available here - over computed PHYSNAME. It is safer
5304 against both buggy GDB and buggy compilers. */
5318 retval
= obsavestring (retval
, strlen (retval
),
5319 &objfile
->objfile_obstack
);
5321 do_cleanups (back_to
);
5325 /* Read the import statement specified by the given die and record it. */
5328 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5330 struct objfile
*objfile
= cu
->objfile
;
5331 struct attribute
*import_attr
;
5332 struct die_info
*imported_die
, *child_die
;
5333 struct dwarf2_cu
*imported_cu
;
5334 const char *imported_name
;
5335 const char *imported_name_prefix
;
5336 const char *canonical_name
;
5337 const char *import_alias
;
5338 const char *imported_declaration
= NULL
;
5339 const char *import_prefix
;
5340 VEC (const_char_ptr
) *excludes
= NULL
;
5341 struct cleanup
*cleanups
;
5345 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5346 if (import_attr
== NULL
)
5348 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5349 dwarf_tag_name (die
->tag
));
5354 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5355 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5356 if (imported_name
== NULL
)
5358 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5360 The import in the following code:
5374 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5375 <52> DW_AT_decl_file : 1
5376 <53> DW_AT_decl_line : 6
5377 <54> DW_AT_import : <0x75>
5378 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5380 <5b> DW_AT_decl_file : 1
5381 <5c> DW_AT_decl_line : 2
5382 <5d> DW_AT_type : <0x6e>
5384 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5385 <76> DW_AT_byte_size : 4
5386 <77> DW_AT_encoding : 5 (signed)
5388 imports the wrong die ( 0x75 instead of 0x58 ).
5389 This case will be ignored until the gcc bug is fixed. */
5393 /* Figure out the local name after import. */
5394 import_alias
= dwarf2_name (die
, cu
);
5396 /* Figure out where the statement is being imported to. */
5397 import_prefix
= determine_prefix (die
, cu
);
5399 /* Figure out what the scope of the imported die is and prepend it
5400 to the name of the imported die. */
5401 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5403 if (imported_die
->tag
!= DW_TAG_namespace
5404 && imported_die
->tag
!= DW_TAG_module
)
5406 imported_declaration
= imported_name
;
5407 canonical_name
= imported_name_prefix
;
5409 else if (strlen (imported_name_prefix
) > 0)
5411 temp
= alloca (strlen (imported_name_prefix
)
5412 + 2 + strlen (imported_name
) + 1);
5413 strcpy (temp
, imported_name_prefix
);
5414 strcat (temp
, "::");
5415 strcat (temp
, imported_name
);
5416 canonical_name
= temp
;
5419 canonical_name
= imported_name
;
5421 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5423 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5424 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5425 child_die
= sibling_die (child_die
))
5427 /* DWARF-4: A Fortran use statement with a “rename list” may be
5428 represented by an imported module entry with an import attribute
5429 referring to the module and owned entries corresponding to those
5430 entities that are renamed as part of being imported. */
5432 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5434 complaint (&symfile_complaints
,
5435 _("child DW_TAG_imported_declaration expected "
5436 "- DIE at 0x%x [in module %s]"),
5437 child_die
->offset
, objfile
->name
);
5441 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5442 if (import_attr
== NULL
)
5444 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5445 dwarf_tag_name (child_die
->tag
));
5450 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5452 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5453 if (imported_name
== NULL
)
5455 complaint (&symfile_complaints
,
5456 _("child DW_TAG_imported_declaration has unknown "
5457 "imported name - DIE at 0x%x [in module %s]"),
5458 child_die
->offset
, objfile
->name
);
5462 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5464 process_die (child_die
, cu
);
5467 cp_add_using_directive (import_prefix
,
5470 imported_declaration
,
5472 &objfile
->objfile_obstack
);
5474 do_cleanups (cleanups
);
5477 /* Cleanup function for read_file_scope. */
5480 free_cu_line_header (void *arg
)
5482 struct dwarf2_cu
*cu
= arg
;
5484 free_line_header (cu
->line_header
);
5485 cu
->line_header
= NULL
;
5489 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5490 char **name
, char **comp_dir
)
5492 struct attribute
*attr
;
5497 /* Find the filename. Do not use dwarf2_name here, since the filename
5498 is not a source language identifier. */
5499 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5502 *name
= DW_STRING (attr
);
5505 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5507 *comp_dir
= DW_STRING (attr
);
5508 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5510 *comp_dir
= ldirname (*name
);
5511 if (*comp_dir
!= NULL
)
5512 make_cleanup (xfree
, *comp_dir
);
5514 if (*comp_dir
!= NULL
)
5516 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5517 directory, get rid of it. */
5518 char *cp
= strchr (*comp_dir
, ':');
5520 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5525 *name
= "<unknown>";
5528 /* Handle DW_AT_stmt_list for a compilation unit. */
5531 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
5532 const char *comp_dir
)
5534 struct attribute
*attr
;
5535 struct objfile
*objfile
= cu
->objfile
;
5536 bfd
*abfd
= objfile
->obfd
;
5538 /* Decode line number information if present. We do this before
5539 processing child DIEs, so that the line header table is available
5540 for DW_AT_decl_file. */
5541 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5544 unsigned int line_offset
= DW_UNSND (attr
);
5545 struct line_header
*line_header
5546 = dwarf_decode_line_header (line_offset
, abfd
, cu
);
5550 cu
->line_header
= line_header
;
5551 make_cleanup (free_cu_line_header
, cu
);
5552 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5557 /* Process DW_TAG_compile_unit. */
5560 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5562 struct objfile
*objfile
= cu
->objfile
;
5563 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5564 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5565 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5566 struct attribute
*attr
;
5568 char *comp_dir
= NULL
;
5569 struct die_info
*child_die
;
5570 bfd
*abfd
= objfile
->obfd
;
5573 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5575 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5577 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5578 from finish_block. */
5579 if (lowpc
== ((CORE_ADDR
) -1))
5584 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5586 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5589 set_cu_language (DW_UNSND (attr
), cu
);
5592 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5594 cu
->producer
= DW_STRING (attr
);
5596 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5597 standardised yet. As a workaround for the language detection we fall
5598 back to the DW_AT_producer string. */
5599 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5600 cu
->language
= language_opencl
;
5602 /* We assume that we're processing GCC output. */
5603 processing_gcc_compilation
= 2;
5605 processing_has_namespace_info
= 0;
5607 start_symtab (name
, comp_dir
, lowpc
);
5608 record_debugformat ("DWARF 2");
5609 record_producer (cu
->producer
);
5611 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5613 /* Process all dies in compilation unit. */
5614 if (die
->child
!= NULL
)
5616 child_die
= die
->child
;
5617 while (child_die
&& child_die
->tag
)
5619 process_die (child_die
, cu
);
5620 child_die
= sibling_die (child_die
);
5624 /* Decode macro information, if present. Dwarf 2 macro information
5625 refers to information in the line number info statement program
5626 header, so we can only read it if we've read the header
5628 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
5629 if (attr
&& cu
->line_header
)
5631 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
5632 complaint (&symfile_complaints
,
5633 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5635 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
5637 &dwarf2_per_objfile
->macro
, 1);
5641 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5642 if (attr
&& cu
->line_header
)
5644 unsigned int macro_offset
= DW_UNSND (attr
);
5646 dwarf_decode_macros (cu
->line_header
, macro_offset
,
5648 &dwarf2_per_objfile
->macinfo
, 0);
5652 do_cleanups (back_to
);
5655 /* Process DW_TAG_type_unit.
5656 For TUs we want to skip the first top level sibling if it's not the
5657 actual type being defined by this TU. In this case the first top
5658 level sibling is there to provide context only. */
5661 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5663 struct objfile
*objfile
= cu
->objfile
;
5664 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5666 struct attribute
*attr
;
5668 char *comp_dir
= NULL
;
5669 struct die_info
*child_die
;
5670 bfd
*abfd
= objfile
->obfd
;
5672 /* start_symtab needs a low pc, but we don't really have one.
5673 Do what read_file_scope would do in the absence of such info. */
5674 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5676 /* Find the filename. Do not use dwarf2_name here, since the filename
5677 is not a source language identifier. */
5678 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5680 name
= DW_STRING (attr
);
5682 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5684 comp_dir
= DW_STRING (attr
);
5685 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5687 comp_dir
= ldirname (name
);
5688 if (comp_dir
!= NULL
)
5689 make_cleanup (xfree
, comp_dir
);
5695 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5697 set_cu_language (DW_UNSND (attr
), cu
);
5699 /* This isn't technically needed today. It is done for symmetry
5700 with read_file_scope. */
5701 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5703 cu
->producer
= DW_STRING (attr
);
5705 /* We assume that we're processing GCC output. */
5706 processing_gcc_compilation
= 2;
5708 processing_has_namespace_info
= 0;
5710 start_symtab (name
, comp_dir
, lowpc
);
5711 record_debugformat ("DWARF 2");
5712 record_producer (cu
->producer
);
5714 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5716 /* Process the dies in the type unit. */
5717 if (die
->child
== NULL
)
5719 dump_die_for_error (die
);
5720 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5721 bfd_get_filename (abfd
));
5724 child_die
= die
->child
;
5726 while (child_die
&& child_die
->tag
)
5728 process_die (child_die
, cu
);
5730 child_die
= sibling_die (child_die
);
5733 do_cleanups (back_to
);
5736 /* qsort helper for inherit_abstract_dies. */
5739 unsigned_int_compar (const void *ap
, const void *bp
)
5741 unsigned int a
= *(unsigned int *) ap
;
5742 unsigned int b
= *(unsigned int *) bp
;
5744 return (a
> b
) - (b
> a
);
5747 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5748 Inherit only the children of the DW_AT_abstract_origin DIE not being
5749 already referenced by DW_AT_abstract_origin from the children of the
5753 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5755 struct die_info
*child_die
;
5756 unsigned die_children_count
;
5757 /* CU offsets which were referenced by children of the current DIE. */
5759 unsigned *offsets_end
, *offsetp
;
5760 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5761 struct die_info
*origin_die
;
5762 /* Iterator of the ORIGIN_DIE children. */
5763 struct die_info
*origin_child_die
;
5764 struct cleanup
*cleanups
;
5765 struct attribute
*attr
;
5766 struct dwarf2_cu
*origin_cu
;
5767 struct pending
**origin_previous_list_in_scope
;
5769 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5773 /* Note that following die references may follow to a die in a
5777 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5779 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5781 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5782 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5784 if (die
->tag
!= origin_die
->tag
5785 && !(die
->tag
== DW_TAG_inlined_subroutine
5786 && origin_die
->tag
== DW_TAG_subprogram
))
5787 complaint (&symfile_complaints
,
5788 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5789 die
->offset
, origin_die
->offset
);
5791 child_die
= die
->child
;
5792 die_children_count
= 0;
5793 while (child_die
&& child_die
->tag
)
5795 child_die
= sibling_die (child_die
);
5796 die_children_count
++;
5798 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5799 cleanups
= make_cleanup (xfree
, offsets
);
5801 offsets_end
= offsets
;
5802 child_die
= die
->child
;
5803 while (child_die
&& child_die
->tag
)
5805 /* For each CHILD_DIE, find the corresponding child of
5806 ORIGIN_DIE. If there is more than one layer of
5807 DW_AT_abstract_origin, follow them all; there shouldn't be,
5808 but GCC versions at least through 4.4 generate this (GCC PR
5810 struct die_info
*child_origin_die
= child_die
;
5811 struct dwarf2_cu
*child_origin_cu
= cu
;
5815 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5819 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5823 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5824 counterpart may exist. */
5825 if (child_origin_die
!= child_die
)
5827 if (child_die
->tag
!= child_origin_die
->tag
5828 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5829 && child_origin_die
->tag
== DW_TAG_subprogram
))
5830 complaint (&symfile_complaints
,
5831 _("Child DIE 0x%x and its abstract origin 0x%x have "
5832 "different tags"), child_die
->offset
,
5833 child_origin_die
->offset
);
5834 if (child_origin_die
->parent
!= origin_die
)
5835 complaint (&symfile_complaints
,
5836 _("Child DIE 0x%x and its abstract origin 0x%x have "
5837 "different parents"), child_die
->offset
,
5838 child_origin_die
->offset
);
5840 *offsets_end
++ = child_origin_die
->offset
;
5842 child_die
= sibling_die (child_die
);
5844 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5845 unsigned_int_compar
);
5846 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5847 if (offsetp
[-1] == *offsetp
)
5848 complaint (&symfile_complaints
,
5849 _("Multiple children of DIE 0x%x refer "
5850 "to DIE 0x%x as their abstract origin"),
5851 die
->offset
, *offsetp
);
5854 origin_child_die
= origin_die
->child
;
5855 while (origin_child_die
&& origin_child_die
->tag
)
5857 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5858 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5860 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5862 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5863 process_die (origin_child_die
, origin_cu
);
5865 origin_child_die
= sibling_die (origin_child_die
);
5867 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5869 do_cleanups (cleanups
);
5873 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5875 struct objfile
*objfile
= cu
->objfile
;
5876 struct context_stack
*new;
5879 struct die_info
*child_die
;
5880 struct attribute
*attr
, *call_line
, *call_file
;
5883 struct block
*block
;
5884 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5885 VEC (symbolp
) *template_args
= NULL
;
5886 struct template_symbol
*templ_func
= NULL
;
5890 /* If we do not have call site information, we can't show the
5891 caller of this inlined function. That's too confusing, so
5892 only use the scope for local variables. */
5893 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5894 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5895 if (call_line
== NULL
|| call_file
== NULL
)
5897 read_lexical_block_scope (die
, cu
);
5902 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5904 name
= dwarf2_name (die
, cu
);
5906 /* Ignore functions with missing or empty names. These are actually
5907 illegal according to the DWARF standard. */
5910 complaint (&symfile_complaints
,
5911 _("missing name for subprogram DIE at %d"), die
->offset
);
5915 /* Ignore functions with missing or invalid low and high pc attributes. */
5916 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5918 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5919 if (!attr
|| !DW_UNSND (attr
))
5920 complaint (&symfile_complaints
,
5921 _("cannot get low and high bounds "
5922 "for subprogram DIE at %d"),
5930 /* If we have any template arguments, then we must allocate a
5931 different sort of symbol. */
5932 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5934 if (child_die
->tag
== DW_TAG_template_type_param
5935 || child_die
->tag
== DW_TAG_template_value_param
)
5937 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5938 struct template_symbol
);
5939 templ_func
->base
.is_cplus_template_function
= 1;
5944 new = push_context (0, lowpc
);
5945 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5946 (struct symbol
*) templ_func
);
5948 /* If there is a location expression for DW_AT_frame_base, record
5950 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5952 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5953 expression is being recorded directly in the function's symbol
5954 and not in a separate frame-base object. I guess this hack is
5955 to avoid adding some sort of frame-base adjunct/annex to the
5956 function's symbol :-(. The problem with doing this is that it
5957 results in a function symbol with a location expression that
5958 has nothing to do with the location of the function, ouch! The
5959 relationship should be: a function's symbol has-a frame base; a
5960 frame-base has-a location expression. */
5961 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5963 cu
->list_in_scope
= &local_symbols
;
5965 if (die
->child
!= NULL
)
5967 child_die
= die
->child
;
5968 while (child_die
&& child_die
->tag
)
5970 if (child_die
->tag
== DW_TAG_template_type_param
5971 || child_die
->tag
== DW_TAG_template_value_param
)
5973 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5976 VEC_safe_push (symbolp
, template_args
, arg
);
5979 process_die (child_die
, cu
);
5980 child_die
= sibling_die (child_die
);
5984 inherit_abstract_dies (die
, cu
);
5986 /* If we have a DW_AT_specification, we might need to import using
5987 directives from the context of the specification DIE. See the
5988 comment in determine_prefix. */
5989 if (cu
->language
== language_cplus
5990 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5992 struct dwarf2_cu
*spec_cu
= cu
;
5993 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5997 child_die
= spec_die
->child
;
5998 while (child_die
&& child_die
->tag
)
6000 if (child_die
->tag
== DW_TAG_imported_module
)
6001 process_die (child_die
, spec_cu
);
6002 child_die
= sibling_die (child_die
);
6005 /* In some cases, GCC generates specification DIEs that
6006 themselves contain DW_AT_specification attributes. */
6007 spec_die
= die_specification (spec_die
, &spec_cu
);
6011 new = pop_context ();
6012 /* Make a block for the local symbols within. */
6013 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
6014 lowpc
, highpc
, objfile
);
6016 /* For C++, set the block's scope. */
6017 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
6018 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
6019 determine_prefix (die
, cu
),
6020 processing_has_namespace_info
);
6022 /* If we have address ranges, record them. */
6023 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6025 /* Attach template arguments to function. */
6026 if (! VEC_empty (symbolp
, template_args
))
6028 gdb_assert (templ_func
!= NULL
);
6030 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
6031 templ_func
->template_arguments
6032 = obstack_alloc (&objfile
->objfile_obstack
,
6033 (templ_func
->n_template_arguments
6034 * sizeof (struct symbol
*)));
6035 memcpy (templ_func
->template_arguments
,
6036 VEC_address (symbolp
, template_args
),
6037 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
6038 VEC_free (symbolp
, template_args
);
6041 /* In C++, we can have functions nested inside functions (e.g., when
6042 a function declares a class that has methods). This means that
6043 when we finish processing a function scope, we may need to go
6044 back to building a containing block's symbol lists. */
6045 local_symbols
= new->locals
;
6046 param_symbols
= new->params
;
6047 using_directives
= new->using_directives
;
6049 /* If we've finished processing a top-level function, subsequent
6050 symbols go in the file symbol list. */
6051 if (outermost_context_p ())
6052 cu
->list_in_scope
= &file_symbols
;
6055 /* Process all the DIES contained within a lexical block scope. Start
6056 a new scope, process the dies, and then close the scope. */
6059 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6061 struct objfile
*objfile
= cu
->objfile
;
6062 struct context_stack
*new;
6063 CORE_ADDR lowpc
, highpc
;
6064 struct die_info
*child_die
;
6067 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6069 /* Ignore blocks with missing or invalid low and high pc attributes. */
6070 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6071 as multiple lexical blocks? Handling children in a sane way would
6072 be nasty. Might be easier to properly extend generic blocks to
6074 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6079 push_context (0, lowpc
);
6080 if (die
->child
!= NULL
)
6082 child_die
= die
->child
;
6083 while (child_die
&& child_die
->tag
)
6085 process_die (child_die
, cu
);
6086 child_die
= sibling_die (child_die
);
6089 new = pop_context ();
6091 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6094 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6097 /* Note that recording ranges after traversing children, as we
6098 do here, means that recording a parent's ranges entails
6099 walking across all its children's ranges as they appear in
6100 the address map, which is quadratic behavior.
6102 It would be nicer to record the parent's ranges before
6103 traversing its children, simply overriding whatever you find
6104 there. But since we don't even decide whether to create a
6105 block until after we've traversed its children, that's hard
6107 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6109 local_symbols
= new->locals
;
6110 using_directives
= new->using_directives
;
6113 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6116 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6118 struct objfile
*objfile
= cu
->objfile
;
6119 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6120 CORE_ADDR pc
, baseaddr
;
6121 struct attribute
*attr
;
6122 struct call_site
*call_site
, call_site_local
;
6125 struct die_info
*child_die
;
6127 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6129 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6132 complaint (&symfile_complaints
,
6133 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6134 "DIE 0x%x [in module %s]"),
6135 die
->offset
, objfile
->name
);
6138 pc
= DW_ADDR (attr
) + baseaddr
;
6140 if (cu
->call_site_htab
== NULL
)
6141 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
6142 NULL
, &objfile
->objfile_obstack
,
6143 hashtab_obstack_allocate
, NULL
);
6144 call_site_local
.pc
= pc
;
6145 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
6148 complaint (&symfile_complaints
,
6149 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6150 "DIE 0x%x [in module %s]"),
6151 paddress (gdbarch
, pc
), die
->offset
, objfile
->name
);
6155 /* Count parameters at the caller. */
6158 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6159 child_die
= sibling_die (child_die
))
6161 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6163 complaint (&symfile_complaints
,
6164 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6165 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6166 child_die
->tag
, child_die
->offset
, objfile
->name
);
6173 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
6174 (sizeof (*call_site
)
6175 + (sizeof (*call_site
->parameter
)
6178 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
6181 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
6183 struct die_info
*func_die
;
6185 /* Skip also over DW_TAG_inlined_subroutine. */
6186 for (func_die
= die
->parent
;
6187 func_die
&& func_die
->tag
!= DW_TAG_subprogram
6188 && func_die
->tag
!= DW_TAG_subroutine_type
;
6189 func_die
= func_die
->parent
);
6191 /* DW_AT_GNU_all_call_sites is a superset
6192 of DW_AT_GNU_all_tail_call_sites. */
6194 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
6195 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
6197 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6198 not complete. But keep CALL_SITE for look ups via call_site_htab,
6199 both the initial caller containing the real return address PC and
6200 the final callee containing the current PC of a chain of tail
6201 calls do not need to have the tail call list complete. But any
6202 function candidate for a virtual tail call frame searched via
6203 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6204 determined unambiguously. */
6208 struct type
*func_type
= NULL
;
6211 func_type
= get_die_type (func_die
, cu
);
6212 if (func_type
!= NULL
)
6214 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
6216 /* Enlist this call site to the function. */
6217 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
6218 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
6221 complaint (&symfile_complaints
,
6222 _("Cannot find function owning DW_TAG_GNU_call_site "
6223 "DIE 0x%x [in module %s]"),
6224 die
->offset
, objfile
->name
);
6228 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
6230 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
6231 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
6232 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
6233 /* Keep NULL DWARF_BLOCK. */;
6234 else if (attr_form_is_block (attr
))
6236 struct dwarf2_locexpr_baton
*dlbaton
;
6238 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
6239 dlbaton
->data
= DW_BLOCK (attr
)->data
;
6240 dlbaton
->size
= DW_BLOCK (attr
)->size
;
6241 dlbaton
->per_cu
= cu
->per_cu
;
6243 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
6245 else if (is_ref_attr (attr
))
6247 struct dwarf2_cu
*target_cu
= cu
;
6248 struct die_info
*target_die
;
6250 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
6251 gdb_assert (target_cu
->objfile
== objfile
);
6252 if (die_is_declaration (target_die
, target_cu
))
6254 const char *target_physname
;
6256 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
6257 if (target_physname
== NULL
)
6258 complaint (&symfile_complaints
,
6259 _("DW_AT_GNU_call_site_target target DIE has invalid "
6260 "physname, for referencing DIE 0x%x [in module %s]"),
6261 die
->offset
, objfile
->name
);
6263 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
6269 /* DW_AT_entry_pc should be preferred. */
6270 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
6271 complaint (&symfile_complaints
,
6272 _("DW_AT_GNU_call_site_target target DIE has invalid "
6273 "low pc, for referencing DIE 0x%x [in module %s]"),
6274 die
->offset
, objfile
->name
);
6276 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
6280 complaint (&symfile_complaints
,
6281 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6282 "block nor reference, for DIE 0x%x [in module %s]"),
6283 die
->offset
, objfile
->name
);
6285 call_site
->per_cu
= cu
->per_cu
;
6287 for (child_die
= die
->child
;
6288 child_die
&& child_die
->tag
;
6289 child_die
= sibling_die (child_die
))
6291 struct dwarf2_locexpr_baton
*dlbaton
;
6292 struct call_site_parameter
*parameter
;
6294 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6296 /* Already printed the complaint above. */
6300 gdb_assert (call_site
->parameter_count
< nparams
);
6301 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
6303 /* DW_AT_location specifies the register number. Value of the data
6304 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6306 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
6307 if (!attr
|| !attr_form_is_block (attr
))
6309 complaint (&symfile_complaints
,
6310 _("No DW_FORM_block* DW_AT_location for "
6311 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6312 child_die
->offset
, objfile
->name
);
6315 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
6316 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
6317 if (parameter
->dwarf_reg
== -1
6318 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
6319 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
6320 ¶meter
->fb_offset
))
6322 complaint (&symfile_complaints
,
6323 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6324 "for DW_FORM_block* DW_AT_location for "
6325 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6326 child_die
->offset
, objfile
->name
);
6330 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
6331 if (!attr_form_is_block (attr
))
6333 complaint (&symfile_complaints
,
6334 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6335 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6336 child_die
->offset
, objfile
->name
);
6339 parameter
->value
= DW_BLOCK (attr
)->data
;
6340 parameter
->value_size
= DW_BLOCK (attr
)->size
;
6342 /* Parameters are not pre-cleared by memset above. */
6343 parameter
->data_value
= NULL
;
6344 parameter
->data_value_size
= 0;
6345 call_site
->parameter_count
++;
6347 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
6350 if (!attr_form_is_block (attr
))
6351 complaint (&symfile_complaints
,
6352 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6353 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6354 child_die
->offset
, objfile
->name
);
6357 parameter
->data_value
= DW_BLOCK (attr
)->data
;
6358 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
6364 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6365 Return 1 if the attributes are present and valid, otherwise, return 0.
6366 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6369 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6370 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6371 struct partial_symtab
*ranges_pst
)
6373 struct objfile
*objfile
= cu
->objfile
;
6374 struct comp_unit_head
*cu_header
= &cu
->header
;
6375 bfd
*obfd
= objfile
->obfd
;
6376 unsigned int addr_size
= cu_header
->addr_size
;
6377 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6378 /* Base address selection entry. */
6389 found_base
= cu
->base_known
;
6390 base
= cu
->base_address
;
6392 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6393 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6395 complaint (&symfile_complaints
,
6396 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6400 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6402 /* Read in the largest possible address. */
6403 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6404 if ((marker
& mask
) == mask
)
6406 /* If we found the largest possible address, then
6407 read the base address. */
6408 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6409 buffer
+= 2 * addr_size
;
6410 offset
+= 2 * addr_size
;
6416 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6420 CORE_ADDR range_beginning
, range_end
;
6422 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6423 buffer
+= addr_size
;
6424 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6425 buffer
+= addr_size
;
6426 offset
+= 2 * addr_size
;
6428 /* An end of list marker is a pair of zero addresses. */
6429 if (range_beginning
== 0 && range_end
== 0)
6430 /* Found the end of list entry. */
6433 /* Each base address selection entry is a pair of 2 values.
6434 The first is the largest possible address, the second is
6435 the base address. Check for a base address here. */
6436 if ((range_beginning
& mask
) == mask
)
6438 /* If we found the largest possible address, then
6439 read the base address. */
6440 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6447 /* We have no valid base address for the ranges
6449 complaint (&symfile_complaints
,
6450 _("Invalid .debug_ranges data (no base address)"));
6454 if (range_beginning
> range_end
)
6456 /* Inverted range entries are invalid. */
6457 complaint (&symfile_complaints
,
6458 _("Invalid .debug_ranges data (inverted range)"));
6462 /* Empty range entries have no effect. */
6463 if (range_beginning
== range_end
)
6466 range_beginning
+= base
;
6469 if (ranges_pst
!= NULL
)
6470 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6471 range_beginning
+ baseaddr
,
6472 range_end
- 1 + baseaddr
,
6475 /* FIXME: This is recording everything as a low-high
6476 segment of consecutive addresses. We should have a
6477 data structure for discontiguous block ranges
6481 low
= range_beginning
;
6487 if (range_beginning
< low
)
6488 low
= range_beginning
;
6489 if (range_end
> high
)
6495 /* If the first entry is an end-of-list marker, the range
6496 describes an empty scope, i.e. no instructions. */
6502 *high_return
= high
;
6506 /* Get low and high pc attributes from a die. Return 1 if the attributes
6507 are present and valid, otherwise, return 0. Return -1 if the range is
6508 discontinuous, i.e. derived from DW_AT_ranges information. */
6510 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6511 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6512 struct partial_symtab
*pst
)
6514 struct attribute
*attr
;
6519 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6522 high
= DW_ADDR (attr
);
6523 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6525 low
= DW_ADDR (attr
);
6527 /* Found high w/o low attribute. */
6530 /* Found consecutive range of addresses. */
6535 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6538 /* Value of the DW_AT_ranges attribute is the offset in the
6539 .debug_ranges section. */
6540 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6542 /* Found discontinuous range of addresses. */
6547 /* read_partial_die has also the strict LOW < HIGH requirement. */
6551 /* When using the GNU linker, .gnu.linkonce. sections are used to
6552 eliminate duplicate copies of functions and vtables and such.
6553 The linker will arbitrarily choose one and discard the others.
6554 The AT_*_pc values for such functions refer to local labels in
6555 these sections. If the section from that file was discarded, the
6556 labels are not in the output, so the relocs get a value of 0.
6557 If this is a discarded function, mark the pc bounds as invalid,
6558 so that GDB will ignore it. */
6559 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6568 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6569 its low and high PC addresses. Do nothing if these addresses could not
6570 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6571 and HIGHPC to the high address if greater than HIGHPC. */
6574 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6575 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6576 struct dwarf2_cu
*cu
)
6578 CORE_ADDR low
, high
;
6579 struct die_info
*child
= die
->child
;
6581 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6583 *lowpc
= min (*lowpc
, low
);
6584 *highpc
= max (*highpc
, high
);
6587 /* If the language does not allow nested subprograms (either inside
6588 subprograms or lexical blocks), we're done. */
6589 if (cu
->language
!= language_ada
)
6592 /* Check all the children of the given DIE. If it contains nested
6593 subprograms, then check their pc bounds. Likewise, we need to
6594 check lexical blocks as well, as they may also contain subprogram
6596 while (child
&& child
->tag
)
6598 if (child
->tag
== DW_TAG_subprogram
6599 || child
->tag
== DW_TAG_lexical_block
)
6600 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6601 child
= sibling_die (child
);
6605 /* Get the low and high pc's represented by the scope DIE, and store
6606 them in *LOWPC and *HIGHPC. If the correct values can't be
6607 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6610 get_scope_pc_bounds (struct die_info
*die
,
6611 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6612 struct dwarf2_cu
*cu
)
6614 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6615 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6616 CORE_ADDR current_low
, current_high
;
6618 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6620 best_low
= current_low
;
6621 best_high
= current_high
;
6625 struct die_info
*child
= die
->child
;
6627 while (child
&& child
->tag
)
6629 switch (child
->tag
) {
6630 case DW_TAG_subprogram
:
6631 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6633 case DW_TAG_namespace
:
6635 /* FIXME: carlton/2004-01-16: Should we do this for
6636 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6637 that current GCC's always emit the DIEs corresponding
6638 to definitions of methods of classes as children of a
6639 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6640 the DIEs giving the declarations, which could be
6641 anywhere). But I don't see any reason why the
6642 standards says that they have to be there. */
6643 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6645 if (current_low
!= ((CORE_ADDR
) -1))
6647 best_low
= min (best_low
, current_low
);
6648 best_high
= max (best_high
, current_high
);
6656 child
= sibling_die (child
);
6661 *highpc
= best_high
;
6664 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6667 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6668 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6670 struct objfile
*objfile
= cu
->objfile
;
6671 struct attribute
*attr
;
6673 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6676 CORE_ADDR high
= DW_ADDR (attr
);
6678 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6681 CORE_ADDR low
= DW_ADDR (attr
);
6683 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6687 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6690 bfd
*obfd
= objfile
->obfd
;
6692 /* The value of the DW_AT_ranges attribute is the offset of the
6693 address range list in the .debug_ranges section. */
6694 unsigned long offset
= DW_UNSND (attr
);
6695 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6697 /* For some target architectures, but not others, the
6698 read_address function sign-extends the addresses it returns.
6699 To recognize base address selection entries, we need a
6701 unsigned int addr_size
= cu
->header
.addr_size
;
6702 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6704 /* The base address, to which the next pair is relative. Note
6705 that this 'base' is a DWARF concept: most entries in a range
6706 list are relative, to reduce the number of relocs against the
6707 debugging information. This is separate from this function's
6708 'baseaddr' argument, which GDB uses to relocate debugging
6709 information from a shared library based on the address at
6710 which the library was loaded. */
6711 CORE_ADDR base
= cu
->base_address
;
6712 int base_known
= cu
->base_known
;
6714 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6715 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6717 complaint (&symfile_complaints
,
6718 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6725 unsigned int bytes_read
;
6726 CORE_ADDR start
, end
;
6728 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6729 buffer
+= bytes_read
;
6730 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6731 buffer
+= bytes_read
;
6733 /* Did we find the end of the range list? */
6734 if (start
== 0 && end
== 0)
6737 /* Did we find a base address selection entry? */
6738 else if ((start
& base_select_mask
) == base_select_mask
)
6744 /* We found an ordinary address range. */
6749 complaint (&symfile_complaints
,
6750 _("Invalid .debug_ranges data "
6751 "(no base address)"));
6757 /* Inverted range entries are invalid. */
6758 complaint (&symfile_complaints
,
6759 _("Invalid .debug_ranges data "
6760 "(inverted range)"));
6764 /* Empty range entries have no effect. */
6768 record_block_range (block
,
6769 baseaddr
+ base
+ start
,
6770 baseaddr
+ base
+ end
- 1);
6776 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6777 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6778 during 4.6.0 experimental. */
6781 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6784 int major
, minor
, release
;
6786 if (cu
->producer
== NULL
)
6788 /* For unknown compilers expect their behavior is DWARF version
6791 GCC started to support .debug_types sections by -gdwarf-4 since
6792 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6793 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6794 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6795 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6800 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6802 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6804 /* For non-GCC compilers expect their behavior is DWARF version
6809 cs
= &cu
->producer
[strlen ("GNU ")];
6810 while (*cs
&& !isdigit (*cs
))
6812 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6814 /* Not recognized as GCC. */
6819 return major
< 4 || (major
== 4 && minor
< 6);
6822 /* Return the default accessibility type if it is not overriden by
6823 DW_AT_accessibility. */
6825 static enum dwarf_access_attribute
6826 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6828 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6830 /* The default DWARF 2 accessibility for members is public, the default
6831 accessibility for inheritance is private. */
6833 if (die
->tag
!= DW_TAG_inheritance
)
6834 return DW_ACCESS_public
;
6836 return DW_ACCESS_private
;
6840 /* DWARF 3+ defines the default accessibility a different way. The same
6841 rules apply now for DW_TAG_inheritance as for the members and it only
6842 depends on the container kind. */
6844 if (die
->parent
->tag
== DW_TAG_class_type
)
6845 return DW_ACCESS_private
;
6847 return DW_ACCESS_public
;
6851 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6852 offset. If the attribute was not found return 0, otherwise return
6853 1. If it was found but could not properly be handled, set *OFFSET
6857 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
6860 struct attribute
*attr
;
6862 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6867 /* Note that we do not check for a section offset first here.
6868 This is because DW_AT_data_member_location is new in DWARF 4,
6869 so if we see it, we can assume that a constant form is really
6870 a constant and not a section offset. */
6871 if (attr_form_is_constant (attr
))
6872 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
6873 else if (attr_form_is_section_offset (attr
))
6874 dwarf2_complex_location_expr_complaint ();
6875 else if (attr_form_is_block (attr
))
6876 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6878 dwarf2_complex_location_expr_complaint ();
6886 /* Add an aggregate field to the field list. */
6889 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6890 struct dwarf2_cu
*cu
)
6892 struct objfile
*objfile
= cu
->objfile
;
6893 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6894 struct nextfield
*new_field
;
6895 struct attribute
*attr
;
6897 char *fieldname
= "";
6899 /* Allocate a new field list entry and link it in. */
6900 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6901 make_cleanup (xfree
, new_field
);
6902 memset (new_field
, 0, sizeof (struct nextfield
));
6904 if (die
->tag
== DW_TAG_inheritance
)
6906 new_field
->next
= fip
->baseclasses
;
6907 fip
->baseclasses
= new_field
;
6911 new_field
->next
= fip
->fields
;
6912 fip
->fields
= new_field
;
6916 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6918 new_field
->accessibility
= DW_UNSND (attr
);
6920 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
6921 if (new_field
->accessibility
!= DW_ACCESS_public
)
6922 fip
->non_public_fields
= 1;
6924 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6926 new_field
->virtuality
= DW_UNSND (attr
);
6928 new_field
->virtuality
= DW_VIRTUALITY_none
;
6930 fp
= &new_field
->field
;
6932 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6936 /* Data member other than a C++ static data member. */
6938 /* Get type of field. */
6939 fp
->type
= die_type (die
, cu
);
6941 SET_FIELD_BITPOS (*fp
, 0);
6943 /* Get bit size of field (zero if none). */
6944 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6947 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6951 FIELD_BITSIZE (*fp
) = 0;
6954 /* Get bit offset of field. */
6955 if (handle_data_member_location (die
, cu
, &offset
))
6956 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
6957 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6960 if (gdbarch_bits_big_endian (gdbarch
))
6962 /* For big endian bits, the DW_AT_bit_offset gives the
6963 additional bit offset from the MSB of the containing
6964 anonymous object to the MSB of the field. We don't
6965 have to do anything special since we don't need to
6966 know the size of the anonymous object. */
6967 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6971 /* For little endian bits, compute the bit offset to the
6972 MSB of the anonymous object, subtract off the number of
6973 bits from the MSB of the field to the MSB of the
6974 object, and then subtract off the number of bits of
6975 the field itself. The result is the bit offset of
6976 the LSB of the field. */
6978 int bit_offset
= DW_UNSND (attr
);
6980 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6983 /* The size of the anonymous object containing
6984 the bit field is explicit, so use the
6985 indicated size (in bytes). */
6986 anonymous_size
= DW_UNSND (attr
);
6990 /* The size of the anonymous object containing
6991 the bit field must be inferred from the type
6992 attribute of the data member containing the
6994 anonymous_size
= TYPE_LENGTH (fp
->type
);
6996 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6997 - bit_offset
- FIELD_BITSIZE (*fp
);
7001 /* Get name of field. */
7002 fieldname
= dwarf2_name (die
, cu
);
7003 if (fieldname
== NULL
)
7006 /* The name is already allocated along with this objfile, so we don't
7007 need to duplicate it for the type. */
7008 fp
->name
= fieldname
;
7010 /* Change accessibility for artificial fields (e.g. virtual table
7011 pointer or virtual base class pointer) to private. */
7012 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
7014 FIELD_ARTIFICIAL (*fp
) = 1;
7015 new_field
->accessibility
= DW_ACCESS_private
;
7016 fip
->non_public_fields
= 1;
7019 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
7021 /* C++ static member. */
7023 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7024 is a declaration, but all versions of G++ as of this writing
7025 (so through at least 3.2.1) incorrectly generate
7026 DW_TAG_variable tags. */
7028 const char *physname
;
7030 /* Get name of field. */
7031 fieldname
= dwarf2_name (die
, cu
);
7032 if (fieldname
== NULL
)
7035 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7037 /* Only create a symbol if this is an external value.
7038 new_symbol checks this and puts the value in the global symbol
7039 table, which we want. If it is not external, new_symbol
7040 will try to put the value in cu->list_in_scope which is wrong. */
7041 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
7043 /* A static const member, not much different than an enum as far as
7044 we're concerned, except that we can support more types. */
7045 new_symbol (die
, NULL
, cu
);
7048 /* Get physical name. */
7049 physname
= dwarf2_physname (fieldname
, die
, cu
);
7051 /* The name is already allocated along with this objfile, so we don't
7052 need to duplicate it for the type. */
7053 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
7054 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7055 FIELD_NAME (*fp
) = fieldname
;
7057 else if (die
->tag
== DW_TAG_inheritance
)
7061 /* C++ base class field. */
7062 if (handle_data_member_location (die
, cu
, &offset
))
7063 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7064 FIELD_BITSIZE (*fp
) = 0;
7065 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7066 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
7067 fip
->nbaseclasses
++;
7071 /* Add a typedef defined in the scope of the FIP's class. */
7074 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
7075 struct dwarf2_cu
*cu
)
7077 struct objfile
*objfile
= cu
->objfile
;
7078 struct typedef_field_list
*new_field
;
7079 struct attribute
*attr
;
7080 struct typedef_field
*fp
;
7081 char *fieldname
= "";
7083 /* Allocate a new field list entry and link it in. */
7084 new_field
= xzalloc (sizeof (*new_field
));
7085 make_cleanup (xfree
, new_field
);
7087 gdb_assert (die
->tag
== DW_TAG_typedef
);
7089 fp
= &new_field
->field
;
7091 /* Get name of field. */
7092 fp
->name
= dwarf2_name (die
, cu
);
7093 if (fp
->name
== NULL
)
7096 fp
->type
= read_type_die (die
, cu
);
7098 new_field
->next
= fip
->typedef_field_list
;
7099 fip
->typedef_field_list
= new_field
;
7100 fip
->typedef_field_list_count
++;
7103 /* Create the vector of fields, and attach it to the type. */
7106 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
7107 struct dwarf2_cu
*cu
)
7109 int nfields
= fip
->nfields
;
7111 /* Record the field count, allocate space for the array of fields,
7112 and create blank accessibility bitfields if necessary. */
7113 TYPE_NFIELDS (type
) = nfields
;
7114 TYPE_FIELDS (type
) = (struct field
*)
7115 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
7116 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
7118 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
7120 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7122 TYPE_FIELD_PRIVATE_BITS (type
) =
7123 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7124 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
7126 TYPE_FIELD_PROTECTED_BITS (type
) =
7127 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7128 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
7130 TYPE_FIELD_IGNORE_BITS (type
) =
7131 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7132 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
7135 /* If the type has baseclasses, allocate and clear a bit vector for
7136 TYPE_FIELD_VIRTUAL_BITS. */
7137 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
7139 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
7140 unsigned char *pointer
;
7142 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7143 pointer
= TYPE_ALLOC (type
, num_bytes
);
7144 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
7145 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
7146 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
7149 /* Copy the saved-up fields into the field vector. Start from the head of
7150 the list, adding to the tail of the field array, so that they end up in
7151 the same order in the array in which they were added to the list. */
7152 while (nfields
-- > 0)
7154 struct nextfield
*fieldp
;
7158 fieldp
= fip
->fields
;
7159 fip
->fields
= fieldp
->next
;
7163 fieldp
= fip
->baseclasses
;
7164 fip
->baseclasses
= fieldp
->next
;
7167 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
7168 switch (fieldp
->accessibility
)
7170 case DW_ACCESS_private
:
7171 if (cu
->language
!= language_ada
)
7172 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
7175 case DW_ACCESS_protected
:
7176 if (cu
->language
!= language_ada
)
7177 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
7180 case DW_ACCESS_public
:
7184 /* Unknown accessibility. Complain and treat it as public. */
7186 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
7187 fieldp
->accessibility
);
7191 if (nfields
< fip
->nbaseclasses
)
7193 switch (fieldp
->virtuality
)
7195 case DW_VIRTUALITY_virtual
:
7196 case DW_VIRTUALITY_pure_virtual
:
7197 if (cu
->language
== language_ada
)
7198 error (_("unexpected virtuality in component of Ada type"));
7199 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
7206 /* Add a member function to the proper fieldlist. */
7209 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
7210 struct type
*type
, struct dwarf2_cu
*cu
)
7212 struct objfile
*objfile
= cu
->objfile
;
7213 struct attribute
*attr
;
7214 struct fnfieldlist
*flp
;
7216 struct fn_field
*fnp
;
7218 struct nextfnfield
*new_fnfield
;
7219 struct type
*this_type
;
7220 enum dwarf_access_attribute accessibility
;
7222 if (cu
->language
== language_ada
)
7223 error (_("unexpected member function in Ada type"));
7225 /* Get name of member function. */
7226 fieldname
= dwarf2_name (die
, cu
);
7227 if (fieldname
== NULL
)
7230 /* Look up member function name in fieldlist. */
7231 for (i
= 0; i
< fip
->nfnfields
; i
++)
7233 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7237 /* Create new list element if necessary. */
7238 if (i
< fip
->nfnfields
)
7239 flp
= &fip
->fnfieldlists
[i
];
7242 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7244 fip
->fnfieldlists
= (struct fnfieldlist
*)
7245 xrealloc (fip
->fnfieldlists
,
7246 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7247 * sizeof (struct fnfieldlist
));
7248 if (fip
->nfnfields
== 0)
7249 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7251 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7252 flp
->name
= fieldname
;
7255 i
= fip
->nfnfields
++;
7258 /* Create a new member function field and chain it to the field list
7260 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7261 make_cleanup (xfree
, new_fnfield
);
7262 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7263 new_fnfield
->next
= flp
->head
;
7264 flp
->head
= new_fnfield
;
7267 /* Fill in the member function field info. */
7268 fnp
= &new_fnfield
->fnfield
;
7270 /* Delay processing of the physname until later. */
7271 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7273 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7278 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7279 fnp
->physname
= physname
? physname
: "";
7282 fnp
->type
= alloc_type (objfile
);
7283 this_type
= read_type_die (die
, cu
);
7284 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7286 int nparams
= TYPE_NFIELDS (this_type
);
7288 /* TYPE is the domain of this method, and THIS_TYPE is the type
7289 of the method itself (TYPE_CODE_METHOD). */
7290 smash_to_method_type (fnp
->type
, type
,
7291 TYPE_TARGET_TYPE (this_type
),
7292 TYPE_FIELDS (this_type
),
7293 TYPE_NFIELDS (this_type
),
7294 TYPE_VARARGS (this_type
));
7296 /* Handle static member functions.
7297 Dwarf2 has no clean way to discern C++ static and non-static
7298 member functions. G++ helps GDB by marking the first
7299 parameter for non-static member functions (which is the this
7300 pointer) as artificial. We obtain this information from
7301 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7302 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7303 fnp
->voffset
= VOFFSET_STATIC
;
7306 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7307 dwarf2_full_name (fieldname
, die
, cu
));
7309 /* Get fcontext from DW_AT_containing_type if present. */
7310 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7311 fnp
->fcontext
= die_containing_type (die
, cu
);
7313 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7314 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7316 /* Get accessibility. */
7317 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7319 accessibility
= DW_UNSND (attr
);
7321 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7322 switch (accessibility
)
7324 case DW_ACCESS_private
:
7325 fnp
->is_private
= 1;
7327 case DW_ACCESS_protected
:
7328 fnp
->is_protected
= 1;
7332 /* Check for artificial methods. */
7333 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7334 if (attr
&& DW_UNSND (attr
) != 0)
7335 fnp
->is_artificial
= 1;
7337 /* Get index in virtual function table if it is a virtual member
7338 function. For older versions of GCC, this is an offset in the
7339 appropriate virtual table, as specified by DW_AT_containing_type.
7340 For everyone else, it is an expression to be evaluated relative
7341 to the object address. */
7343 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7346 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7348 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7350 /* Old-style GCC. */
7351 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7353 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7354 || (DW_BLOCK (attr
)->size
> 1
7355 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7356 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7358 struct dwarf_block blk
;
7361 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7363 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7364 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7365 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7366 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7367 dwarf2_complex_location_expr_complaint ();
7369 fnp
->voffset
/= cu
->header
.addr_size
;
7373 dwarf2_complex_location_expr_complaint ();
7376 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7378 else if (attr_form_is_section_offset (attr
))
7380 dwarf2_complex_location_expr_complaint ();
7384 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7390 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7391 if (attr
&& DW_UNSND (attr
))
7393 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7394 complaint (&symfile_complaints
,
7395 _("Member function \"%s\" (offset %d) is virtual "
7396 "but the vtable offset is not specified"),
7397 fieldname
, die
->offset
);
7398 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7399 TYPE_CPLUS_DYNAMIC (type
) = 1;
7404 /* Create the vector of member function fields, and attach it to the type. */
7407 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7408 struct dwarf2_cu
*cu
)
7410 struct fnfieldlist
*flp
;
7411 int total_length
= 0;
7414 if (cu
->language
== language_ada
)
7415 error (_("unexpected member functions in Ada type"));
7417 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7418 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7419 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7421 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7423 struct nextfnfield
*nfp
= flp
->head
;
7424 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7427 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7428 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7429 fn_flp
->fn_fields
= (struct fn_field
*)
7430 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7431 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7432 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7434 total_length
+= flp
->length
;
7437 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7438 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
7441 /* Returns non-zero if NAME is the name of a vtable member in CU's
7442 language, zero otherwise. */
7444 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7446 static const char vptr
[] = "_vptr";
7447 static const char vtable
[] = "vtable";
7449 /* Look for the C++ and Java forms of the vtable. */
7450 if ((cu
->language
== language_java
7451 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7452 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7453 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7459 /* GCC outputs unnamed structures that are really pointers to member
7460 functions, with the ABI-specified layout. If TYPE describes
7461 such a structure, smash it into a member function type.
7463 GCC shouldn't do this; it should just output pointer to member DIEs.
7464 This is GCC PR debug/28767. */
7467 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7469 struct type
*pfn_type
, *domain_type
, *new_type
;
7471 /* Check for a structure with no name and two children. */
7472 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7475 /* Check for __pfn and __delta members. */
7476 if (TYPE_FIELD_NAME (type
, 0) == NULL
7477 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7478 || TYPE_FIELD_NAME (type
, 1) == NULL
7479 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7482 /* Find the type of the method. */
7483 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7484 if (pfn_type
== NULL
7485 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7486 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7489 /* Look for the "this" argument. */
7490 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7491 if (TYPE_NFIELDS (pfn_type
) == 0
7492 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7493 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7496 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7497 new_type
= alloc_type (objfile
);
7498 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7499 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7500 TYPE_VARARGS (pfn_type
));
7501 smash_to_methodptr_type (type
, new_type
);
7504 /* Called when we find the DIE that starts a structure or union scope
7505 (definition) to create a type for the structure or union. Fill in
7506 the type's name and general properties; the members will not be
7507 processed until process_structure_type.
7509 NOTE: we need to call these functions regardless of whether or not the
7510 DIE has a DW_AT_name attribute, since it might be an anonymous
7511 structure or union. This gets the type entered into our set of
7514 However, if the structure is incomplete (an opaque struct/union)
7515 then suppress creating a symbol table entry for it since gdb only
7516 wants to find the one with the complete definition. Note that if
7517 it is complete, we just call new_symbol, which does it's own
7518 checking about whether the struct/union is anonymous or not (and
7519 suppresses creating a symbol table entry itself). */
7521 static struct type
*
7522 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7524 struct objfile
*objfile
= cu
->objfile
;
7526 struct attribute
*attr
;
7529 /* If the definition of this type lives in .debug_types, read that type.
7530 Don't follow DW_AT_specification though, that will take us back up
7531 the chain and we want to go down. */
7532 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7535 struct dwarf2_cu
*type_cu
= cu
;
7536 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7538 /* We could just recurse on read_structure_type, but we need to call
7539 get_die_type to ensure only one type for this DIE is created.
7540 This is important, for example, because for c++ classes we need
7541 TYPE_NAME set which is only done by new_symbol. Blech. */
7542 type
= read_type_die (type_die
, type_cu
);
7544 /* TYPE_CU may not be the same as CU.
7545 Ensure TYPE is recorded in CU's type_hash table. */
7546 return set_die_type (die
, type
, cu
);
7549 type
= alloc_type (objfile
);
7550 INIT_CPLUS_SPECIFIC (type
);
7552 name
= dwarf2_name (die
, cu
);
7555 if (cu
->language
== language_cplus
7556 || cu
->language
== language_java
)
7558 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7560 /* dwarf2_full_name might have already finished building the DIE's
7561 type. If so, there is no need to continue. */
7562 if (get_die_type (die
, cu
) != NULL
)
7563 return get_die_type (die
, cu
);
7565 TYPE_TAG_NAME (type
) = full_name
;
7566 if (die
->tag
== DW_TAG_structure_type
7567 || die
->tag
== DW_TAG_class_type
)
7568 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7572 /* The name is already allocated along with this objfile, so
7573 we don't need to duplicate it for the type. */
7574 TYPE_TAG_NAME (type
) = (char *) name
;
7575 if (die
->tag
== DW_TAG_class_type
)
7576 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7580 if (die
->tag
== DW_TAG_structure_type
)
7582 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7584 else if (die
->tag
== DW_TAG_union_type
)
7586 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7590 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7593 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7594 TYPE_DECLARED_CLASS (type
) = 1;
7596 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7599 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7603 TYPE_LENGTH (type
) = 0;
7606 TYPE_STUB_SUPPORTED (type
) = 1;
7607 if (die_is_declaration (die
, cu
))
7608 TYPE_STUB (type
) = 1;
7609 else if (attr
== NULL
&& die
->child
== NULL
7610 && producer_is_realview (cu
->producer
))
7611 /* RealView does not output the required DW_AT_declaration
7612 on incomplete types. */
7613 TYPE_STUB (type
) = 1;
7615 /* We need to add the type field to the die immediately so we don't
7616 infinitely recurse when dealing with pointers to the structure
7617 type within the structure itself. */
7618 set_die_type (die
, type
, cu
);
7620 /* set_die_type should be already done. */
7621 set_descriptive_type (type
, die
, cu
);
7626 /* Finish creating a structure or union type, including filling in
7627 its members and creating a symbol for it. */
7630 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7632 struct objfile
*objfile
= cu
->objfile
;
7633 struct die_info
*child_die
= die
->child
;
7636 type
= get_die_type (die
, cu
);
7638 type
= read_structure_type (die
, cu
);
7640 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7642 struct field_info fi
;
7643 struct die_info
*child_die
;
7644 VEC (symbolp
) *template_args
= NULL
;
7645 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7647 memset (&fi
, 0, sizeof (struct field_info
));
7649 child_die
= die
->child
;
7651 while (child_die
&& child_die
->tag
)
7653 if (child_die
->tag
== DW_TAG_member
7654 || child_die
->tag
== DW_TAG_variable
)
7656 /* NOTE: carlton/2002-11-05: A C++ static data member
7657 should be a DW_TAG_member that is a declaration, but
7658 all versions of G++ as of this writing (so through at
7659 least 3.2.1) incorrectly generate DW_TAG_variable
7660 tags for them instead. */
7661 dwarf2_add_field (&fi
, child_die
, cu
);
7663 else if (child_die
->tag
== DW_TAG_subprogram
)
7665 /* C++ member function. */
7666 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7668 else if (child_die
->tag
== DW_TAG_inheritance
)
7670 /* C++ base class field. */
7671 dwarf2_add_field (&fi
, child_die
, cu
);
7673 else if (child_die
->tag
== DW_TAG_typedef
)
7674 dwarf2_add_typedef (&fi
, child_die
, cu
);
7675 else if (child_die
->tag
== DW_TAG_template_type_param
7676 || child_die
->tag
== DW_TAG_template_value_param
)
7678 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7681 VEC_safe_push (symbolp
, template_args
, arg
);
7684 child_die
= sibling_die (child_die
);
7687 /* Attach template arguments to type. */
7688 if (! VEC_empty (symbolp
, template_args
))
7690 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7691 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7692 = VEC_length (symbolp
, template_args
);
7693 TYPE_TEMPLATE_ARGUMENTS (type
)
7694 = obstack_alloc (&objfile
->objfile_obstack
,
7695 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7696 * sizeof (struct symbol
*)));
7697 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7698 VEC_address (symbolp
, template_args
),
7699 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7700 * sizeof (struct symbol
*)));
7701 VEC_free (symbolp
, template_args
);
7704 /* Attach fields and member functions to the type. */
7706 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7709 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7711 /* Get the type which refers to the base class (possibly this
7712 class itself) which contains the vtable pointer for the current
7713 class from the DW_AT_containing_type attribute. This use of
7714 DW_AT_containing_type is a GNU extension. */
7716 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7718 struct type
*t
= die_containing_type (die
, cu
);
7720 TYPE_VPTR_BASETYPE (type
) = t
;
7725 /* Our own class provides vtbl ptr. */
7726 for (i
= TYPE_NFIELDS (t
) - 1;
7727 i
>= TYPE_N_BASECLASSES (t
);
7730 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7732 if (is_vtable_name (fieldname
, cu
))
7734 TYPE_VPTR_FIELDNO (type
) = i
;
7739 /* Complain if virtual function table field not found. */
7740 if (i
< TYPE_N_BASECLASSES (t
))
7741 complaint (&symfile_complaints
,
7742 _("virtual function table pointer "
7743 "not found when defining class '%s'"),
7744 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7749 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7752 else if (cu
->producer
7753 && strncmp (cu
->producer
,
7754 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7756 /* The IBM XLC compiler does not provide direct indication
7757 of the containing type, but the vtable pointer is
7758 always named __vfp. */
7762 for (i
= TYPE_NFIELDS (type
) - 1;
7763 i
>= TYPE_N_BASECLASSES (type
);
7766 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7768 TYPE_VPTR_FIELDNO (type
) = i
;
7769 TYPE_VPTR_BASETYPE (type
) = type
;
7776 /* Copy fi.typedef_field_list linked list elements content into the
7777 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7778 if (fi
.typedef_field_list
)
7780 int i
= fi
.typedef_field_list_count
;
7782 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7783 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7784 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7785 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7787 /* Reverse the list order to keep the debug info elements order. */
7790 struct typedef_field
*dest
, *src
;
7792 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7793 src
= &fi
.typedef_field_list
->field
;
7794 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7799 do_cleanups (back_to
);
7801 if (HAVE_CPLUS_STRUCT (type
))
7802 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
7805 quirk_gcc_member_function_pointer (type
, objfile
);
7807 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7808 snapshots) has been known to create a die giving a declaration
7809 for a class that has, as a child, a die giving a definition for a
7810 nested class. So we have to process our children even if the
7811 current die is a declaration. Normally, of course, a declaration
7812 won't have any children at all. */
7814 while (child_die
!= NULL
&& child_die
->tag
)
7816 if (child_die
->tag
== DW_TAG_member
7817 || child_die
->tag
== DW_TAG_variable
7818 || child_die
->tag
== DW_TAG_inheritance
7819 || child_die
->tag
== DW_TAG_template_value_param
7820 || child_die
->tag
== DW_TAG_template_type_param
)
7825 process_die (child_die
, cu
);
7827 child_die
= sibling_die (child_die
);
7830 /* Do not consider external references. According to the DWARF standard,
7831 these DIEs are identified by the fact that they have no byte_size
7832 attribute, and a declaration attribute. */
7833 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7834 || !die_is_declaration (die
, cu
))
7835 new_symbol (die
, type
, cu
);
7838 /* Given a DW_AT_enumeration_type die, set its type. We do not
7839 complete the type's fields yet, or create any symbols. */
7841 static struct type
*
7842 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7844 struct objfile
*objfile
= cu
->objfile
;
7846 struct attribute
*attr
;
7849 /* If the definition of this type lives in .debug_types, read that type.
7850 Don't follow DW_AT_specification though, that will take us back up
7851 the chain and we want to go down. */
7852 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7855 struct dwarf2_cu
*type_cu
= cu
;
7856 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7858 type
= read_type_die (type_die
, type_cu
);
7860 /* TYPE_CU may not be the same as CU.
7861 Ensure TYPE is recorded in CU's type_hash table. */
7862 return set_die_type (die
, type
, cu
);
7865 type
= alloc_type (objfile
);
7867 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7868 name
= dwarf2_full_name (NULL
, die
, cu
);
7870 TYPE_TAG_NAME (type
) = (char *) name
;
7872 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7875 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7879 TYPE_LENGTH (type
) = 0;
7882 /* The enumeration DIE can be incomplete. In Ada, any type can be
7883 declared as private in the package spec, and then defined only
7884 inside the package body. Such types are known as Taft Amendment
7885 Types. When another package uses such a type, an incomplete DIE
7886 may be generated by the compiler. */
7887 if (die_is_declaration (die
, cu
))
7888 TYPE_STUB (type
) = 1;
7890 return set_die_type (die
, type
, cu
);
7893 /* Given a pointer to a die which begins an enumeration, process all
7894 the dies that define the members of the enumeration, and create the
7895 symbol for the enumeration type.
7897 NOTE: We reverse the order of the element list. */
7900 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7902 struct type
*this_type
;
7904 this_type
= get_die_type (die
, cu
);
7905 if (this_type
== NULL
)
7906 this_type
= read_enumeration_type (die
, cu
);
7908 if (die
->child
!= NULL
)
7910 struct die_info
*child_die
;
7912 struct field
*fields
= NULL
;
7914 int unsigned_enum
= 1;
7917 child_die
= die
->child
;
7918 while (child_die
&& child_die
->tag
)
7920 if (child_die
->tag
!= DW_TAG_enumerator
)
7922 process_die (child_die
, cu
);
7926 name
= dwarf2_name (child_die
, cu
);
7929 sym
= new_symbol (child_die
, this_type
, cu
);
7930 if (SYMBOL_VALUE (sym
) < 0)
7933 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7935 fields
= (struct field
*)
7937 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7938 * sizeof (struct field
));
7941 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7942 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7943 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7944 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7950 child_die
= sibling_die (child_die
);
7955 TYPE_NFIELDS (this_type
) = num_fields
;
7956 TYPE_FIELDS (this_type
) = (struct field
*)
7957 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7958 memcpy (TYPE_FIELDS (this_type
), fields
,
7959 sizeof (struct field
) * num_fields
);
7963 TYPE_UNSIGNED (this_type
) = 1;
7966 /* If we are reading an enum from a .debug_types unit, and the enum
7967 is a declaration, and the enum is not the signatured type in the
7968 unit, then we do not want to add a symbol for it. Adding a
7969 symbol would in some cases obscure the true definition of the
7970 enum, giving users an incomplete type when the definition is
7971 actually available. Note that we do not want to do this for all
7972 enums which are just declarations, because C++0x allows forward
7973 enum declarations. */
7974 if (cu
->per_cu
->debug_types_section
7975 && die_is_declaration (die
, cu
))
7977 struct signatured_type
*type_sig
;
7980 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
7981 cu
->per_cu
->debug_types_section
,
7982 cu
->per_cu
->offset
);
7983 if (type_sig
->type_offset
!= die
->offset
)
7987 new_symbol (die
, this_type
, cu
);
7990 /* Extract all information from a DW_TAG_array_type DIE and put it in
7991 the DIE's type field. For now, this only handles one dimensional
7994 static struct type
*
7995 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7997 struct objfile
*objfile
= cu
->objfile
;
7998 struct die_info
*child_die
;
8000 struct type
*element_type
, *range_type
, *index_type
;
8001 struct type
**range_types
= NULL
;
8002 struct attribute
*attr
;
8004 struct cleanup
*back_to
;
8007 element_type
= die_type (die
, cu
);
8009 /* The die_type call above may have already set the type for this DIE. */
8010 type
= get_die_type (die
, cu
);
8014 /* Irix 6.2 native cc creates array types without children for
8015 arrays with unspecified length. */
8016 if (die
->child
== NULL
)
8018 index_type
= objfile_type (objfile
)->builtin_int
;
8019 range_type
= create_range_type (NULL
, index_type
, 0, -1);
8020 type
= create_array_type (NULL
, element_type
, range_type
);
8021 return set_die_type (die
, type
, cu
);
8024 back_to
= make_cleanup (null_cleanup
, NULL
);
8025 child_die
= die
->child
;
8026 while (child_die
&& child_die
->tag
)
8028 if (child_die
->tag
== DW_TAG_subrange_type
)
8030 struct type
*child_type
= read_type_die (child_die
, cu
);
8032 if (child_type
!= NULL
)
8034 /* The range type was succesfully read. Save it for the
8035 array type creation. */
8036 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
8038 range_types
= (struct type
**)
8039 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
8040 * sizeof (struct type
*));
8042 make_cleanup (free_current_contents
, &range_types
);
8044 range_types
[ndim
++] = child_type
;
8047 child_die
= sibling_die (child_die
);
8050 /* Dwarf2 dimensions are output from left to right, create the
8051 necessary array types in backwards order. */
8053 type
= element_type
;
8055 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
8060 type
= create_array_type (NULL
, type
, range_types
[i
++]);
8065 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
8068 /* Understand Dwarf2 support for vector types (like they occur on
8069 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8070 array type. This is not part of the Dwarf2/3 standard yet, but a
8071 custom vendor extension. The main difference between a regular
8072 array and the vector variant is that vectors are passed by value
8074 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
8076 make_vector_type (type
);
8078 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8079 implementation may choose to implement triple vectors using this
8081 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8084 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
8085 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8087 complaint (&symfile_complaints
,
8088 _("DW_AT_byte_size for array type smaller "
8089 "than the total size of elements"));
8092 name
= dwarf2_name (die
, cu
);
8094 TYPE_NAME (type
) = name
;
8096 /* Install the type in the die. */
8097 set_die_type (die
, type
, cu
);
8099 /* set_die_type should be already done. */
8100 set_descriptive_type (type
, die
, cu
);
8102 do_cleanups (back_to
);
8107 static enum dwarf_array_dim_ordering
8108 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
8110 struct attribute
*attr
;
8112 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
8114 if (attr
) return DW_SND (attr
);
8116 /* GNU F77 is a special case, as at 08/2004 array type info is the
8117 opposite order to the dwarf2 specification, but data is still
8118 laid out as per normal fortran.
8120 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8121 version checking. */
8123 if (cu
->language
== language_fortran
8124 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
8126 return DW_ORD_row_major
;
8129 switch (cu
->language_defn
->la_array_ordering
)
8131 case array_column_major
:
8132 return DW_ORD_col_major
;
8133 case array_row_major
:
8135 return DW_ORD_row_major
;
8139 /* Extract all information from a DW_TAG_set_type DIE and put it in
8140 the DIE's type field. */
8142 static struct type
*
8143 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8145 struct type
*domain_type
, *set_type
;
8146 struct attribute
*attr
;
8148 domain_type
= die_type (die
, cu
);
8150 /* The die_type call above may have already set the type for this DIE. */
8151 set_type
= get_die_type (die
, cu
);
8155 set_type
= create_set_type (NULL
, domain_type
);
8157 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8159 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
8161 return set_die_type (die
, set_type
, cu
);
8164 /* First cut: install each common block member as a global variable. */
8167 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
8169 struct die_info
*child_die
;
8170 struct attribute
*attr
;
8172 CORE_ADDR base
= (CORE_ADDR
) 0;
8174 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8177 /* Support the .debug_loc offsets. */
8178 if (attr_form_is_block (attr
))
8180 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
8182 else if (attr_form_is_section_offset (attr
))
8184 dwarf2_complex_location_expr_complaint ();
8188 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8189 "common block member");
8192 if (die
->child
!= NULL
)
8194 child_die
= die
->child
;
8195 while (child_die
&& child_die
->tag
)
8199 sym
= new_symbol (child_die
, NULL
, cu
);
8201 && handle_data_member_location (child_die
, cu
, &offset
))
8203 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
8204 add_symbol_to_list (sym
, &global_symbols
);
8206 child_die
= sibling_die (child_die
);
8211 /* Create a type for a C++ namespace. */
8213 static struct type
*
8214 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8216 struct objfile
*objfile
= cu
->objfile
;
8217 const char *previous_prefix
, *name
;
8221 /* For extensions, reuse the type of the original namespace. */
8222 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
8224 struct die_info
*ext_die
;
8225 struct dwarf2_cu
*ext_cu
= cu
;
8227 ext_die
= dwarf2_extension (die
, &ext_cu
);
8228 type
= read_type_die (ext_die
, ext_cu
);
8230 /* EXT_CU may not be the same as CU.
8231 Ensure TYPE is recorded in CU's type_hash table. */
8232 return set_die_type (die
, type
, cu
);
8235 name
= namespace_name (die
, &is_anonymous
, cu
);
8237 /* Now build the name of the current namespace. */
8239 previous_prefix
= determine_prefix (die
, cu
);
8240 if (previous_prefix
[0] != '\0')
8241 name
= typename_concat (&objfile
->objfile_obstack
,
8242 previous_prefix
, name
, 0, cu
);
8244 /* Create the type. */
8245 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8247 TYPE_NAME (type
) = (char *) name
;
8248 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8250 return set_die_type (die
, type
, cu
);
8253 /* Read a C++ namespace. */
8256 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8258 struct objfile
*objfile
= cu
->objfile
;
8261 /* Add a symbol associated to this if we haven't seen the namespace
8262 before. Also, add a using directive if it's an anonymous
8265 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8269 type
= read_type_die (die
, cu
);
8270 new_symbol (die
, type
, cu
);
8272 namespace_name (die
, &is_anonymous
, cu
);
8275 const char *previous_prefix
= determine_prefix (die
, cu
);
8277 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8278 NULL
, NULL
, &objfile
->objfile_obstack
);
8282 if (die
->child
!= NULL
)
8284 struct die_info
*child_die
= die
->child
;
8286 while (child_die
&& child_die
->tag
)
8288 process_die (child_die
, cu
);
8289 child_die
= sibling_die (child_die
);
8294 /* Read a Fortran module as type. This DIE can be only a declaration used for
8295 imported module. Still we need that type as local Fortran "use ... only"
8296 declaration imports depend on the created type in determine_prefix. */
8298 static struct type
*
8299 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8301 struct objfile
*objfile
= cu
->objfile
;
8305 module_name
= dwarf2_name (die
, cu
);
8307 complaint (&symfile_complaints
,
8308 _("DW_TAG_module has no name, offset 0x%x"),
8310 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8312 /* determine_prefix uses TYPE_TAG_NAME. */
8313 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8315 return set_die_type (die
, type
, cu
);
8318 /* Read a Fortran module. */
8321 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8323 struct die_info
*child_die
= die
->child
;
8325 while (child_die
&& child_die
->tag
)
8327 process_die (child_die
, cu
);
8328 child_die
= sibling_die (child_die
);
8332 /* Return the name of the namespace represented by DIE. Set
8333 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8337 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8339 struct die_info
*current_die
;
8340 const char *name
= NULL
;
8342 /* Loop through the extensions until we find a name. */
8344 for (current_die
= die
;
8345 current_die
!= NULL
;
8346 current_die
= dwarf2_extension (die
, &cu
))
8348 name
= dwarf2_name (current_die
, cu
);
8353 /* Is it an anonymous namespace? */
8355 *is_anonymous
= (name
== NULL
);
8357 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8362 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8363 the user defined type vector. */
8365 static struct type
*
8366 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8368 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8369 struct comp_unit_head
*cu_header
= &cu
->header
;
8371 struct attribute
*attr_byte_size
;
8372 struct attribute
*attr_address_class
;
8373 int byte_size
, addr_class
;
8374 struct type
*target_type
;
8376 target_type
= die_type (die
, cu
);
8378 /* The die_type call above may have already set the type for this DIE. */
8379 type
= get_die_type (die
, cu
);
8383 type
= lookup_pointer_type (target_type
);
8385 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8387 byte_size
= DW_UNSND (attr_byte_size
);
8389 byte_size
= cu_header
->addr_size
;
8391 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8392 if (attr_address_class
)
8393 addr_class
= DW_UNSND (attr_address_class
);
8395 addr_class
= DW_ADDR_none
;
8397 /* If the pointer size or address class is different than the
8398 default, create a type variant marked as such and set the
8399 length accordingly. */
8400 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8402 if (gdbarch_address_class_type_flags_p (gdbarch
))
8406 type_flags
= gdbarch_address_class_type_flags
8407 (gdbarch
, byte_size
, addr_class
);
8408 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8410 type
= make_type_with_address_space (type
, type_flags
);
8412 else if (TYPE_LENGTH (type
) != byte_size
)
8414 complaint (&symfile_complaints
,
8415 _("invalid pointer size %d"), byte_size
);
8419 /* Should we also complain about unhandled address classes? */
8423 TYPE_LENGTH (type
) = byte_size
;
8424 return set_die_type (die
, type
, cu
);
8427 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8428 the user defined type vector. */
8430 static struct type
*
8431 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8434 struct type
*to_type
;
8435 struct type
*domain
;
8437 to_type
= die_type (die
, cu
);
8438 domain
= die_containing_type (die
, cu
);
8440 /* The calls above may have already set the type for this DIE. */
8441 type
= get_die_type (die
, cu
);
8445 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8446 type
= lookup_methodptr_type (to_type
);
8448 type
= lookup_memberptr_type (to_type
, domain
);
8450 return set_die_type (die
, type
, cu
);
8453 /* Extract all information from a DW_TAG_reference_type DIE and add to
8454 the user defined type vector. */
8456 static struct type
*
8457 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8459 struct comp_unit_head
*cu_header
= &cu
->header
;
8460 struct type
*type
, *target_type
;
8461 struct attribute
*attr
;
8463 target_type
= die_type (die
, cu
);
8465 /* The die_type call above may have already set the type for this DIE. */
8466 type
= get_die_type (die
, cu
);
8470 type
= lookup_reference_type (target_type
);
8471 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8474 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8478 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8480 return set_die_type (die
, type
, cu
);
8483 static struct type
*
8484 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8486 struct type
*base_type
, *cv_type
;
8488 base_type
= die_type (die
, cu
);
8490 /* The die_type call above may have already set the type for this DIE. */
8491 cv_type
= get_die_type (die
, cu
);
8495 /* In case the const qualifier is applied to an array type, the element type
8496 is so qualified, not the array type (section 6.7.3 of C99). */
8497 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8499 struct type
*el_type
, *inner_array
;
8501 base_type
= copy_type (base_type
);
8502 inner_array
= base_type
;
8504 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8506 TYPE_TARGET_TYPE (inner_array
) =
8507 copy_type (TYPE_TARGET_TYPE (inner_array
));
8508 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8511 el_type
= TYPE_TARGET_TYPE (inner_array
);
8512 TYPE_TARGET_TYPE (inner_array
) =
8513 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8515 return set_die_type (die
, base_type
, cu
);
8518 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8519 return set_die_type (die
, cv_type
, cu
);
8522 static struct type
*
8523 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8525 struct type
*base_type
, *cv_type
;
8527 base_type
= die_type (die
, cu
);
8529 /* The die_type call above may have already set the type for this DIE. */
8530 cv_type
= get_die_type (die
, cu
);
8534 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8535 return set_die_type (die
, cv_type
, cu
);
8538 /* Extract all information from a DW_TAG_string_type DIE and add to
8539 the user defined type vector. It isn't really a user defined type,
8540 but it behaves like one, with other DIE's using an AT_user_def_type
8541 attribute to reference it. */
8543 static struct type
*
8544 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8546 struct objfile
*objfile
= cu
->objfile
;
8547 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8548 struct type
*type
, *range_type
, *index_type
, *char_type
;
8549 struct attribute
*attr
;
8550 unsigned int length
;
8552 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8555 length
= DW_UNSND (attr
);
8559 /* Check for the DW_AT_byte_size attribute. */
8560 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8563 length
= DW_UNSND (attr
);
8571 index_type
= objfile_type (objfile
)->builtin_int
;
8572 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8573 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8574 type
= create_string_type (NULL
, char_type
, range_type
);
8576 return set_die_type (die
, type
, cu
);
8579 /* Handle DIES due to C code like:
8583 int (*funcp)(int a, long l);
8587 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8589 static struct type
*
8590 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8592 struct objfile
*objfile
= cu
->objfile
;
8593 struct type
*type
; /* Type that this function returns. */
8594 struct type
*ftype
; /* Function that returns above type. */
8595 struct attribute
*attr
;
8597 type
= die_type (die
, cu
);
8599 /* The die_type call above may have already set the type for this DIE. */
8600 ftype
= get_die_type (die
, cu
);
8604 ftype
= lookup_function_type (type
);
8606 /* All functions in C++, Pascal and Java have prototypes. */
8607 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8608 if ((attr
&& (DW_UNSND (attr
) != 0))
8609 || cu
->language
== language_cplus
8610 || cu
->language
== language_java
8611 || cu
->language
== language_pascal
)
8612 TYPE_PROTOTYPED (ftype
) = 1;
8613 else if (producer_is_realview (cu
->producer
))
8614 /* RealView does not emit DW_AT_prototyped. We can not
8615 distinguish prototyped and unprototyped functions; default to
8616 prototyped, since that is more common in modern code (and
8617 RealView warns about unprototyped functions). */
8618 TYPE_PROTOTYPED (ftype
) = 1;
8620 /* Store the calling convention in the type if it's available in
8621 the subroutine die. Otherwise set the calling convention to
8622 the default value DW_CC_normal. */
8623 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8625 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8626 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8627 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8629 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8631 /* We need to add the subroutine type to the die immediately so
8632 we don't infinitely recurse when dealing with parameters
8633 declared as the same subroutine type. */
8634 set_die_type (die
, ftype
, cu
);
8636 if (die
->child
!= NULL
)
8638 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
8639 struct die_info
*child_die
;
8640 int nparams
, iparams
;
8642 /* Count the number of parameters.
8643 FIXME: GDB currently ignores vararg functions, but knows about
8644 vararg member functions. */
8646 child_die
= die
->child
;
8647 while (child_die
&& child_die
->tag
)
8649 if (child_die
->tag
== DW_TAG_formal_parameter
)
8651 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8652 TYPE_VARARGS (ftype
) = 1;
8653 child_die
= sibling_die (child_die
);
8656 /* Allocate storage for parameters and fill them in. */
8657 TYPE_NFIELDS (ftype
) = nparams
;
8658 TYPE_FIELDS (ftype
) = (struct field
*)
8659 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8661 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8662 even if we error out during the parameters reading below. */
8663 for (iparams
= 0; iparams
< nparams
; iparams
++)
8664 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8667 child_die
= die
->child
;
8668 while (child_die
&& child_die
->tag
)
8670 if (child_die
->tag
== DW_TAG_formal_parameter
)
8672 struct type
*arg_type
;
8674 /* DWARF version 2 has no clean way to discern C++
8675 static and non-static member functions. G++ helps
8676 GDB by marking the first parameter for non-static
8677 member functions (which is the this pointer) as
8678 artificial. We pass this information to
8679 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8681 DWARF version 3 added DW_AT_object_pointer, which GCC
8682 4.5 does not yet generate. */
8683 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8685 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8688 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8690 /* GCC/43521: In java, the formal parameter
8691 "this" is sometimes not marked with DW_AT_artificial. */
8692 if (cu
->language
== language_java
)
8694 const char *name
= dwarf2_name (child_die
, cu
);
8696 if (name
&& !strcmp (name
, "this"))
8697 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8700 arg_type
= die_type (child_die
, cu
);
8702 /* RealView does not mark THIS as const, which the testsuite
8703 expects. GCC marks THIS as const in method definitions,
8704 but not in the class specifications (GCC PR 43053). */
8705 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8706 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8709 struct dwarf2_cu
*arg_cu
= cu
;
8710 const char *name
= dwarf2_name (child_die
, cu
);
8712 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8715 /* If the compiler emits this, use it. */
8716 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8719 else if (name
&& strcmp (name
, "this") == 0)
8720 /* Function definitions will have the argument names. */
8722 else if (name
== NULL
&& iparams
== 0)
8723 /* Declarations may not have the names, so like
8724 elsewhere in GDB, assume an artificial first
8725 argument is "this". */
8729 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8733 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8736 child_die
= sibling_die (child_die
);
8743 static struct type
*
8744 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8746 struct objfile
*objfile
= cu
->objfile
;
8747 const char *name
= NULL
;
8748 struct type
*this_type
, *target_type
;
8750 name
= dwarf2_full_name (NULL
, die
, cu
);
8751 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8752 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8753 TYPE_NAME (this_type
) = (char *) name
;
8754 set_die_type (die
, this_type
, cu
);
8755 target_type
= die_type (die
, cu
);
8756 if (target_type
!= this_type
)
8757 TYPE_TARGET_TYPE (this_type
) = target_type
;
8760 /* Self-referential typedefs are, it seems, not allowed by the DWARF
8761 spec and cause infinite loops in GDB. */
8762 complaint (&symfile_complaints
,
8763 _("Self-referential DW_TAG_typedef "
8764 "- DIE at 0x%x [in module %s]"),
8765 die
->offset
, objfile
->name
);
8766 TYPE_TARGET_TYPE (this_type
) = NULL
;
8771 /* Find a representation of a given base type and install
8772 it in the TYPE field of the die. */
8774 static struct type
*
8775 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8777 struct objfile
*objfile
= cu
->objfile
;
8779 struct attribute
*attr
;
8780 int encoding
= 0, size
= 0;
8782 enum type_code code
= TYPE_CODE_INT
;
8784 struct type
*target_type
= NULL
;
8786 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8789 encoding
= DW_UNSND (attr
);
8791 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8794 size
= DW_UNSND (attr
);
8796 name
= dwarf2_name (die
, cu
);
8799 complaint (&symfile_complaints
,
8800 _("DW_AT_name missing from DW_TAG_base_type"));
8805 case DW_ATE_address
:
8806 /* Turn DW_ATE_address into a void * pointer. */
8807 code
= TYPE_CODE_PTR
;
8808 type_flags
|= TYPE_FLAG_UNSIGNED
;
8809 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8811 case DW_ATE_boolean
:
8812 code
= TYPE_CODE_BOOL
;
8813 type_flags
|= TYPE_FLAG_UNSIGNED
;
8815 case DW_ATE_complex_float
:
8816 code
= TYPE_CODE_COMPLEX
;
8817 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8819 case DW_ATE_decimal_float
:
8820 code
= TYPE_CODE_DECFLOAT
;
8823 code
= TYPE_CODE_FLT
;
8827 case DW_ATE_unsigned
:
8828 type_flags
|= TYPE_FLAG_UNSIGNED
;
8829 if (cu
->language
== language_fortran
8831 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
8832 code
= TYPE_CODE_CHAR
;
8834 case DW_ATE_signed_char
:
8835 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8836 || cu
->language
== language_pascal
8837 || cu
->language
== language_fortran
)
8838 code
= TYPE_CODE_CHAR
;
8840 case DW_ATE_unsigned_char
:
8841 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8842 || cu
->language
== language_pascal
8843 || cu
->language
== language_fortran
)
8844 code
= TYPE_CODE_CHAR
;
8845 type_flags
|= TYPE_FLAG_UNSIGNED
;
8848 /* We just treat this as an integer and then recognize the
8849 type by name elsewhere. */
8853 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8854 dwarf_type_encoding_name (encoding
));
8858 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8859 TYPE_NAME (type
) = name
;
8860 TYPE_TARGET_TYPE (type
) = target_type
;
8862 if (name
&& strcmp (name
, "char") == 0)
8863 TYPE_NOSIGN (type
) = 1;
8865 return set_die_type (die
, type
, cu
);
8868 /* Read the given DW_AT_subrange DIE. */
8870 static struct type
*
8871 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8873 struct type
*base_type
;
8874 struct type
*range_type
;
8875 struct attribute
*attr
;
8879 LONGEST negative_mask
;
8881 base_type
= die_type (die
, cu
);
8882 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8883 check_typedef (base_type
);
8885 /* The die_type call above may have already set the type for this DIE. */
8886 range_type
= get_die_type (die
, cu
);
8890 if (cu
->language
== language_fortran
)
8892 /* FORTRAN implies a lower bound of 1, if not given. */
8896 /* FIXME: For variable sized arrays either of these could be
8897 a variable rather than a constant value. We'll allow it,
8898 but we don't know how to handle it. */
8899 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8901 low
= dwarf2_get_attr_constant_value (attr
, 0);
8903 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8906 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
8908 /* GCC encodes arrays with unspecified or dynamic length
8909 with a DW_FORM_block1 attribute or a reference attribute.
8910 FIXME: GDB does not yet know how to handle dynamic
8911 arrays properly, treat them as arrays with unspecified
8914 FIXME: jimb/2003-09-22: GDB does not really know
8915 how to handle arrays of unspecified length
8916 either; we just represent them as zero-length
8917 arrays. Choose an appropriate upper bound given
8918 the lower bound we've computed above. */
8922 high
= dwarf2_get_attr_constant_value (attr
, 1);
8926 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8929 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8930 high
= low
+ count
- 1;
8934 /* Unspecified array length. */
8939 /* Dwarf-2 specifications explicitly allows to create subrange types
8940 without specifying a base type.
8941 In that case, the base type must be set to the type of
8942 the lower bound, upper bound or count, in that order, if any of these
8943 three attributes references an object that has a type.
8944 If no base type is found, the Dwarf-2 specifications say that
8945 a signed integer type of size equal to the size of an address should
8947 For the following C code: `extern char gdb_int [];'
8948 GCC produces an empty range DIE.
8949 FIXME: muller/2010-05-28: Possible references to object for low bound,
8950 high bound or count are not yet handled by this code. */
8951 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8953 struct objfile
*objfile
= cu
->objfile
;
8954 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8955 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8956 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8958 /* Test "int", "long int", and "long long int" objfile types,
8959 and select the first one having a size above or equal to the
8960 architecture address size. */
8961 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8962 base_type
= int_type
;
8965 int_type
= objfile_type (objfile
)->builtin_long
;
8966 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8967 base_type
= int_type
;
8970 int_type
= objfile_type (objfile
)->builtin_long_long
;
8971 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8972 base_type
= int_type
;
8978 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8979 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8980 low
|= negative_mask
;
8981 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8982 high
|= negative_mask
;
8984 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8986 /* Mark arrays with dynamic length at least as an array of unspecified
8987 length. GDB could check the boundary but before it gets implemented at
8988 least allow accessing the array elements. */
8989 if (attr
&& attr_form_is_block (attr
))
8990 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8992 /* Ada expects an empty array on no boundary attributes. */
8993 if (attr
== NULL
&& cu
->language
!= language_ada
)
8994 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8996 name
= dwarf2_name (die
, cu
);
8998 TYPE_NAME (range_type
) = name
;
9000 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9002 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
9004 set_die_type (die
, range_type
, cu
);
9006 /* set_die_type should be already done. */
9007 set_descriptive_type (range_type
, die
, cu
);
9012 static struct type
*
9013 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9017 /* For now, we only support the C meaning of an unspecified type: void. */
9019 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
9020 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
9022 return set_die_type (die
, type
, cu
);
9025 /* Trivial hash function for die_info: the hash value of a DIE
9026 is its offset in .debug_info for this objfile. */
9029 die_hash (const void *item
)
9031 const struct die_info
*die
= item
;
9036 /* Trivial comparison function for die_info structures: two DIEs
9037 are equal if they have the same offset. */
9040 die_eq (const void *item_lhs
, const void *item_rhs
)
9042 const struct die_info
*die_lhs
= item_lhs
;
9043 const struct die_info
*die_rhs
= item_rhs
;
9045 return die_lhs
->offset
== die_rhs
->offset
;
9048 /* Read a whole compilation unit into a linked list of dies. */
9050 static struct die_info
*
9051 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9053 struct die_reader_specs reader_specs
;
9054 int read_abbrevs
= 0;
9055 struct cleanup
*back_to
= NULL
;
9056 struct die_info
*die
;
9058 if (cu
->dwarf2_abbrevs
== NULL
)
9060 dwarf2_read_abbrevs (cu
);
9061 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
9065 gdb_assert (cu
->die_hash
== NULL
);
9067 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9071 &cu
->comp_unit_obstack
,
9072 hashtab_obstack_allocate
,
9073 dummy_obstack_deallocate
);
9075 init_cu_die_reader (&reader_specs
, cu
);
9077 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
9080 do_cleanups (back_to
);
9085 /* Main entry point for reading a DIE and all children.
9086 Read the DIE and dump it if requested. */
9088 static struct die_info
*
9089 read_die_and_children (const struct die_reader_specs
*reader
,
9091 gdb_byte
**new_info_ptr
,
9092 struct die_info
*parent
)
9094 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
9095 new_info_ptr
, parent
);
9097 if (dwarf2_die_debug
)
9099 fprintf_unfiltered (gdb_stdlog
,
9100 "\nRead die from %s of %s:\n",
9101 (reader
->cu
->per_cu
->debug_types_section
9104 reader
->abfd
->filename
);
9105 dump_die (result
, dwarf2_die_debug
);
9111 /* Read a single die and all its descendents. Set the die's sibling
9112 field to NULL; set other fields in the die correctly, and set all
9113 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9114 location of the info_ptr after reading all of those dies. PARENT
9115 is the parent of the die in question. */
9117 static struct die_info
*
9118 read_die_and_children_1 (const struct die_reader_specs
*reader
,
9120 gdb_byte
**new_info_ptr
,
9121 struct die_info
*parent
)
9123 struct die_info
*die
;
9127 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
9130 *new_info_ptr
= cur_ptr
;
9133 store_in_ref_table (die
, reader
->cu
);
9136 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
9140 *new_info_ptr
= cur_ptr
;
9143 die
->sibling
= NULL
;
9144 die
->parent
= parent
;
9148 /* Read a die, all of its descendents, and all of its siblings; set
9149 all of the fields of all of the dies correctly. Arguments are as
9150 in read_die_and_children. */
9152 static struct die_info
*
9153 read_die_and_siblings (const struct die_reader_specs
*reader
,
9155 gdb_byte
**new_info_ptr
,
9156 struct die_info
*parent
)
9158 struct die_info
*first_die
, *last_sibling
;
9162 first_die
= last_sibling
= NULL
;
9166 struct die_info
*die
9167 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
9171 *new_info_ptr
= cur_ptr
;
9178 last_sibling
->sibling
= die
;
9184 /* Read the die from the .debug_info section buffer. Set DIEP to
9185 point to a newly allocated die with its information, except for its
9186 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9187 whether the die has children or not. */
9190 read_full_die (const struct die_reader_specs
*reader
,
9191 struct die_info
**diep
, gdb_byte
*info_ptr
,
9194 unsigned int abbrev_number
, bytes_read
, i
, offset
;
9195 struct abbrev_info
*abbrev
;
9196 struct die_info
*die
;
9197 struct dwarf2_cu
*cu
= reader
->cu
;
9198 bfd
*abfd
= reader
->abfd
;
9200 offset
= info_ptr
- reader
->buffer
;
9201 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9202 info_ptr
+= bytes_read
;
9210 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
9212 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9214 bfd_get_filename (abfd
));
9216 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
9217 die
->offset
= offset
;
9218 die
->tag
= abbrev
->tag
;
9219 die
->abbrev
= abbrev_number
;
9221 die
->num_attrs
= abbrev
->num_attrs
;
9223 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9224 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
9225 abfd
, info_ptr
, cu
);
9228 *has_children
= abbrev
->has_children
;
9232 /* In DWARF version 2, the description of the debugging information is
9233 stored in a separate .debug_abbrev section. Before we read any
9234 dies from a section we read in all abbreviations and install them
9235 in a hash table. This function also sets flags in CU describing
9236 the data found in the abbrev table. */
9239 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
)
9241 bfd
*abfd
= cu
->objfile
->obfd
;
9242 struct comp_unit_head
*cu_header
= &cu
->header
;
9243 gdb_byte
*abbrev_ptr
;
9244 struct abbrev_info
*cur_abbrev
;
9245 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9246 unsigned int abbrev_form
, hash_number
;
9247 struct attr_abbrev
*cur_attrs
;
9248 unsigned int allocated_attrs
;
9250 /* Initialize dwarf2 abbrevs. */
9251 obstack_init (&cu
->abbrev_obstack
);
9252 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9254 * sizeof (struct abbrev_info
*)));
9255 memset (cu
->dwarf2_abbrevs
, 0,
9256 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9258 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
9259 &dwarf2_per_objfile
->abbrev
);
9260 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
9261 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9262 abbrev_ptr
+= bytes_read
;
9264 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9265 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9267 /* Loop until we reach an abbrev number of 0. */
9268 while (abbrev_number
)
9270 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9272 /* read in abbrev header */
9273 cur_abbrev
->number
= abbrev_number
;
9274 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9275 abbrev_ptr
+= bytes_read
;
9276 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9279 if (cur_abbrev
->tag
== DW_TAG_namespace
)
9280 cu
->has_namespace_info
= 1;
9282 /* now read in declarations */
9283 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9284 abbrev_ptr
+= bytes_read
;
9285 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9286 abbrev_ptr
+= bytes_read
;
9289 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9291 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9293 = xrealloc (cur_attrs
, (allocated_attrs
9294 * sizeof (struct attr_abbrev
)));
9297 /* Record whether this compilation unit might have
9298 inter-compilation-unit references. If we don't know what form
9299 this attribute will have, then it might potentially be a
9300 DW_FORM_ref_addr, so we conservatively expect inter-CU
9303 if (abbrev_form
== DW_FORM_ref_addr
9304 || abbrev_form
== DW_FORM_indirect
)
9305 cu
->has_form_ref_addr
= 1;
9307 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9308 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9309 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9310 abbrev_ptr
+= bytes_read
;
9311 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9312 abbrev_ptr
+= bytes_read
;
9315 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9316 (cur_abbrev
->num_attrs
9317 * sizeof (struct attr_abbrev
)));
9318 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9319 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9321 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9322 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9323 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9325 /* Get next abbreviation.
9326 Under Irix6 the abbreviations for a compilation unit are not
9327 always properly terminated with an abbrev number of 0.
9328 Exit loop if we encounter an abbreviation which we have
9329 already read (which means we are about to read the abbreviations
9330 for the next compile unit) or if the end of the abbreviation
9331 table is reached. */
9332 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
9333 >= dwarf2_per_objfile
->abbrev
.size
)
9335 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9336 abbrev_ptr
+= bytes_read
;
9337 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9344 /* Release the memory used by the abbrev table for a compilation unit. */
9347 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9349 struct dwarf2_cu
*cu
= ptr_to_cu
;
9351 obstack_free (&cu
->abbrev_obstack
, NULL
);
9352 cu
->dwarf2_abbrevs
= NULL
;
9355 /* Lookup an abbrev_info structure in the abbrev hash table. */
9357 static struct abbrev_info
*
9358 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9360 unsigned int hash_number
;
9361 struct abbrev_info
*abbrev
;
9363 hash_number
= number
% ABBREV_HASH_SIZE
;
9364 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9368 if (abbrev
->number
== number
)
9371 abbrev
= abbrev
->next
;
9376 /* Returns nonzero if TAG represents a type that we might generate a partial
9380 is_type_tag_for_partial (int tag
)
9385 /* Some types that would be reasonable to generate partial symbols for,
9386 that we don't at present. */
9387 case DW_TAG_array_type
:
9388 case DW_TAG_file_type
:
9389 case DW_TAG_ptr_to_member_type
:
9390 case DW_TAG_set_type
:
9391 case DW_TAG_string_type
:
9392 case DW_TAG_subroutine_type
:
9394 case DW_TAG_base_type
:
9395 case DW_TAG_class_type
:
9396 case DW_TAG_interface_type
:
9397 case DW_TAG_enumeration_type
:
9398 case DW_TAG_structure_type
:
9399 case DW_TAG_subrange_type
:
9400 case DW_TAG_typedef
:
9401 case DW_TAG_union_type
:
9408 /* Load all DIEs that are interesting for partial symbols into memory. */
9410 static struct partial_die_info
*
9411 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9412 int building_psymtab
, struct dwarf2_cu
*cu
)
9414 struct objfile
*objfile
= cu
->objfile
;
9415 struct partial_die_info
*part_die
;
9416 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9417 struct abbrev_info
*abbrev
;
9418 unsigned int bytes_read
;
9419 unsigned int load_all
= 0;
9421 int nesting_level
= 1;
9426 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
9430 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9434 &cu
->comp_unit_obstack
,
9435 hashtab_obstack_allocate
,
9436 dummy_obstack_deallocate
);
9438 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9439 sizeof (struct partial_die_info
));
9443 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9445 /* A NULL abbrev means the end of a series of children. */
9448 if (--nesting_level
== 0)
9450 /* PART_DIE was probably the last thing allocated on the
9451 comp_unit_obstack, so we could call obstack_free
9452 here. We don't do that because the waste is small,
9453 and will be cleaned up when we're done with this
9454 compilation unit. This way, we're also more robust
9455 against other users of the comp_unit_obstack. */
9458 info_ptr
+= bytes_read
;
9459 last_die
= parent_die
;
9460 parent_die
= parent_die
->die_parent
;
9464 /* Check for template arguments. We never save these; if
9465 they're seen, we just mark the parent, and go on our way. */
9466 if (parent_die
!= NULL
9467 && cu
->language
== language_cplus
9468 && (abbrev
->tag
== DW_TAG_template_type_param
9469 || abbrev
->tag
== DW_TAG_template_value_param
))
9471 parent_die
->has_template_arguments
= 1;
9475 /* We don't need a partial DIE for the template argument. */
9476 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9482 /* We only recurse into subprograms looking for template arguments.
9483 Skip their other children. */
9485 && cu
->language
== language_cplus
9486 && parent_die
!= NULL
9487 && parent_die
->tag
== DW_TAG_subprogram
)
9489 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9493 /* Check whether this DIE is interesting enough to save. Normally
9494 we would not be interested in members here, but there may be
9495 later variables referencing them via DW_AT_specification (for
9498 && !is_type_tag_for_partial (abbrev
->tag
)
9499 && abbrev
->tag
!= DW_TAG_constant
9500 && abbrev
->tag
!= DW_TAG_enumerator
9501 && abbrev
->tag
!= DW_TAG_subprogram
9502 && abbrev
->tag
!= DW_TAG_lexical_block
9503 && abbrev
->tag
!= DW_TAG_variable
9504 && abbrev
->tag
!= DW_TAG_namespace
9505 && abbrev
->tag
!= DW_TAG_module
9506 && abbrev
->tag
!= DW_TAG_member
)
9508 /* Otherwise we skip to the next sibling, if any. */
9509 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9513 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9514 buffer
, info_ptr
, cu
);
9516 /* This two-pass algorithm for processing partial symbols has a
9517 high cost in cache pressure. Thus, handle some simple cases
9518 here which cover the majority of C partial symbols. DIEs
9519 which neither have specification tags in them, nor could have
9520 specification tags elsewhere pointing at them, can simply be
9521 processed and discarded.
9523 This segment is also optional; scan_partial_symbols and
9524 add_partial_symbol will handle these DIEs if we chain
9525 them in normally. When compilers which do not emit large
9526 quantities of duplicate debug information are more common,
9527 this code can probably be removed. */
9529 /* Any complete simple types at the top level (pretty much all
9530 of them, for a language without namespaces), can be processed
9532 if (parent_die
== NULL
9533 && part_die
->has_specification
== 0
9534 && part_die
->is_declaration
== 0
9535 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9536 || part_die
->tag
== DW_TAG_base_type
9537 || part_die
->tag
== DW_TAG_subrange_type
))
9539 if (building_psymtab
&& part_die
->name
!= NULL
)
9540 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9541 VAR_DOMAIN
, LOC_TYPEDEF
,
9542 &objfile
->static_psymbols
,
9543 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9544 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9548 /* The exception for DW_TAG_typedef with has_children above is
9549 a workaround of GCC PR debug/47510. In the case of this complaint
9550 type_name_no_tag_or_error will error on such types later.
9552 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9553 it could not find the child DIEs referenced later, this is checked
9554 above. In correct DWARF DW_TAG_typedef should have no children. */
9556 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9557 complaint (&symfile_complaints
,
9558 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9559 "- DIE at 0x%x [in module %s]"),
9560 part_die
->offset
, objfile
->name
);
9562 /* If we're at the second level, and we're an enumerator, and
9563 our parent has no specification (meaning possibly lives in a
9564 namespace elsewhere), then we can add the partial symbol now
9565 instead of queueing it. */
9566 if (part_die
->tag
== DW_TAG_enumerator
9567 && parent_die
!= NULL
9568 && parent_die
->die_parent
== NULL
9569 && parent_die
->tag
== DW_TAG_enumeration_type
9570 && parent_die
->has_specification
== 0)
9572 if (part_die
->name
== NULL
)
9573 complaint (&symfile_complaints
,
9574 _("malformed enumerator DIE ignored"));
9575 else if (building_psymtab
)
9576 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9577 VAR_DOMAIN
, LOC_CONST
,
9578 (cu
->language
== language_cplus
9579 || cu
->language
== language_java
)
9580 ? &objfile
->global_psymbols
9581 : &objfile
->static_psymbols
,
9582 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9584 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9588 /* We'll save this DIE so link it in. */
9589 part_die
->die_parent
= parent_die
;
9590 part_die
->die_sibling
= NULL
;
9591 part_die
->die_child
= NULL
;
9593 if (last_die
&& last_die
== parent_die
)
9594 last_die
->die_child
= part_die
;
9596 last_die
->die_sibling
= part_die
;
9598 last_die
= part_die
;
9600 if (first_die
== NULL
)
9601 first_die
= part_die
;
9603 /* Maybe add the DIE to the hash table. Not all DIEs that we
9604 find interesting need to be in the hash table, because we
9605 also have the parent/sibling/child chains; only those that we
9606 might refer to by offset later during partial symbol reading.
9608 For now this means things that might have be the target of a
9609 DW_AT_specification, DW_AT_abstract_origin, or
9610 DW_AT_extension. DW_AT_extension will refer only to
9611 namespaces; DW_AT_abstract_origin refers to functions (and
9612 many things under the function DIE, but we do not recurse
9613 into function DIEs during partial symbol reading) and
9614 possibly variables as well; DW_AT_specification refers to
9615 declarations. Declarations ought to have the DW_AT_declaration
9616 flag. It happens that GCC forgets to put it in sometimes, but
9617 only for functions, not for types.
9619 Adding more things than necessary to the hash table is harmless
9620 except for the performance cost. Adding too few will result in
9621 wasted time in find_partial_die, when we reread the compilation
9622 unit with load_all_dies set. */
9625 || abbrev
->tag
== DW_TAG_constant
9626 || abbrev
->tag
== DW_TAG_subprogram
9627 || abbrev
->tag
== DW_TAG_variable
9628 || abbrev
->tag
== DW_TAG_namespace
9629 || part_die
->is_declaration
)
9633 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9634 part_die
->offset
, INSERT
);
9638 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9639 sizeof (struct partial_die_info
));
9641 /* For some DIEs we want to follow their children (if any). For C
9642 we have no reason to follow the children of structures; for other
9643 languages we have to, so that we can get at method physnames
9644 to infer fully qualified class names, for DW_AT_specification,
9645 and for C++ template arguments. For C++, we also look one level
9646 inside functions to find template arguments (if the name of the
9647 function does not already contain the template arguments).
9649 For Ada, we need to scan the children of subprograms and lexical
9650 blocks as well because Ada allows the definition of nested
9651 entities that could be interesting for the debugger, such as
9652 nested subprograms for instance. */
9653 if (last_die
->has_children
9655 || last_die
->tag
== DW_TAG_namespace
9656 || last_die
->tag
== DW_TAG_module
9657 || last_die
->tag
== DW_TAG_enumeration_type
9658 || (cu
->language
== language_cplus
9659 && last_die
->tag
== DW_TAG_subprogram
9660 && (last_die
->name
== NULL
9661 || strchr (last_die
->name
, '<') == NULL
))
9662 || (cu
->language
!= language_c
9663 && (last_die
->tag
== DW_TAG_class_type
9664 || last_die
->tag
== DW_TAG_interface_type
9665 || last_die
->tag
== DW_TAG_structure_type
9666 || last_die
->tag
== DW_TAG_union_type
))
9667 || (cu
->language
== language_ada
9668 && (last_die
->tag
== DW_TAG_subprogram
9669 || last_die
->tag
== DW_TAG_lexical_block
))))
9672 parent_die
= last_die
;
9676 /* Otherwise we skip to the next sibling, if any. */
9677 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9679 /* Back to the top, do it again. */
9683 /* Read a minimal amount of information into the minimal die structure. */
9686 read_partial_die (struct partial_die_info
*part_die
,
9687 struct abbrev_info
*abbrev
,
9688 unsigned int abbrev_len
, bfd
*abfd
,
9689 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9690 struct dwarf2_cu
*cu
)
9692 struct objfile
*objfile
= cu
->objfile
;
9694 struct attribute attr
;
9695 int has_low_pc_attr
= 0;
9696 int has_high_pc_attr
= 0;
9698 memset (part_die
, 0, sizeof (struct partial_die_info
));
9700 part_die
->offset
= info_ptr
- buffer
;
9702 info_ptr
+= abbrev_len
;
9707 part_die
->tag
= abbrev
->tag
;
9708 part_die
->has_children
= abbrev
->has_children
;
9710 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9712 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9714 /* Store the data if it is of an attribute we want to keep in a
9715 partial symbol table. */
9719 switch (part_die
->tag
)
9721 case DW_TAG_compile_unit
:
9722 case DW_TAG_type_unit
:
9723 /* Compilation units have a DW_AT_name that is a filename, not
9724 a source language identifier. */
9725 case DW_TAG_enumeration_type
:
9726 case DW_TAG_enumerator
:
9727 /* These tags always have simple identifiers already; no need
9728 to canonicalize them. */
9729 part_die
->name
= DW_STRING (&attr
);
9733 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9734 &objfile
->objfile_obstack
);
9738 case DW_AT_linkage_name
:
9739 case DW_AT_MIPS_linkage_name
:
9740 /* Note that both forms of linkage name might appear. We
9741 assume they will be the same, and we only store the last
9743 if (cu
->language
== language_ada
)
9744 part_die
->name
= DW_STRING (&attr
);
9745 part_die
->linkage_name
= DW_STRING (&attr
);
9748 has_low_pc_attr
= 1;
9749 part_die
->lowpc
= DW_ADDR (&attr
);
9752 has_high_pc_attr
= 1;
9753 part_die
->highpc
= DW_ADDR (&attr
);
9755 case DW_AT_location
:
9756 /* Support the .debug_loc offsets. */
9757 if (attr_form_is_block (&attr
))
9759 part_die
->locdesc
= DW_BLOCK (&attr
);
9761 else if (attr_form_is_section_offset (&attr
))
9763 dwarf2_complex_location_expr_complaint ();
9767 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9768 "partial symbol information");
9771 case DW_AT_external
:
9772 part_die
->is_external
= DW_UNSND (&attr
);
9774 case DW_AT_declaration
:
9775 part_die
->is_declaration
= DW_UNSND (&attr
);
9778 part_die
->has_type
= 1;
9780 case DW_AT_abstract_origin
:
9781 case DW_AT_specification
:
9782 case DW_AT_extension
:
9783 part_die
->has_specification
= 1;
9784 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9787 /* Ignore absolute siblings, they might point outside of
9788 the current compile unit. */
9789 if (attr
.form
== DW_FORM_ref_addr
)
9790 complaint (&symfile_complaints
,
9791 _("ignoring absolute DW_AT_sibling"));
9793 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9795 case DW_AT_byte_size
:
9796 part_die
->has_byte_size
= 1;
9798 case DW_AT_calling_convention
:
9799 /* DWARF doesn't provide a way to identify a program's source-level
9800 entry point. DW_AT_calling_convention attributes are only meant
9801 to describe functions' calling conventions.
9803 However, because it's a necessary piece of information in
9804 Fortran, and because DW_CC_program is the only piece of debugging
9805 information whose definition refers to a 'main program' at all,
9806 several compilers have begun marking Fortran main programs with
9807 DW_CC_program --- even when those functions use the standard
9808 calling conventions.
9810 So until DWARF specifies a way to provide this information and
9811 compilers pick up the new representation, we'll support this
9813 if (DW_UNSND (&attr
) == DW_CC_program
9814 && cu
->language
== language_fortran
)
9816 set_main_name (part_die
->name
);
9818 /* As this DIE has a static linkage the name would be difficult
9819 to look up later. */
9820 language_of_main
= language_fortran
;
9828 if (has_low_pc_attr
&& has_high_pc_attr
)
9830 /* When using the GNU linker, .gnu.linkonce. sections are used to
9831 eliminate duplicate copies of functions and vtables and such.
9832 The linker will arbitrarily choose one and discard the others.
9833 The AT_*_pc values for such functions refer to local labels in
9834 these sections. If the section from that file was discarded, the
9835 labels are not in the output, so the relocs get a value of 0.
9836 If this is a discarded function, mark the pc bounds as invalid,
9837 so that GDB will ignore it. */
9838 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9840 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9842 complaint (&symfile_complaints
,
9843 _("DW_AT_low_pc %s is zero "
9844 "for DIE at 0x%x [in module %s]"),
9845 paddress (gdbarch
, part_die
->lowpc
),
9846 part_die
->offset
, objfile
->name
);
9848 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9849 else if (part_die
->lowpc
>= part_die
->highpc
)
9851 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9853 complaint (&symfile_complaints
,
9854 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9855 "for DIE at 0x%x [in module %s]"),
9856 paddress (gdbarch
, part_die
->lowpc
),
9857 paddress (gdbarch
, part_die
->highpc
),
9858 part_die
->offset
, objfile
->name
);
9861 part_die
->has_pc_info
= 1;
9867 /* Find a cached partial DIE at OFFSET in CU. */
9869 static struct partial_die_info
*
9870 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9872 struct partial_die_info
*lookup_die
= NULL
;
9873 struct partial_die_info part_die
;
9875 part_die
.offset
= offset
;
9876 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9881 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9882 except in the case of .debug_types DIEs which do not reference
9883 outside their CU (they do however referencing other types via
9884 DW_FORM_ref_sig8). */
9886 static struct partial_die_info
*
9887 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9889 struct objfile
*objfile
= cu
->objfile
;
9890 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9891 struct partial_die_info
*pd
= NULL
;
9893 if (cu
->per_cu
->debug_types_section
)
9895 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9901 if (offset_in_cu_p (&cu
->header
, offset
))
9903 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9908 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
9910 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9911 load_partial_comp_unit (per_cu
);
9913 per_cu
->cu
->last_used
= 0;
9914 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9916 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9918 struct cleanup
*back_to
;
9919 struct partial_die_info comp_unit_die
;
9920 struct abbrev_info
*abbrev
;
9921 unsigned int bytes_read
;
9924 per_cu
->load_all_dies
= 1;
9926 /* Re-read the DIEs. */
9927 back_to
= make_cleanup (null_cleanup
, 0);
9928 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9930 dwarf2_read_abbrevs (per_cu
->cu
);
9931 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9933 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9934 + per_cu
->cu
->header
.offset
9935 + per_cu
->cu
->header
.first_die_offset
);
9936 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9937 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9939 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9941 if (comp_unit_die
.has_children
)
9942 load_partial_dies (objfile
->obfd
,
9943 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9945 do_cleanups (back_to
);
9947 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9953 internal_error (__FILE__
, __LINE__
,
9954 _("could not find partial DIE 0x%x "
9955 "in cache [from module %s]\n"),
9956 offset
, bfd_get_filename (objfile
->obfd
));
9960 /* See if we can figure out if the class lives in a namespace. We do
9961 this by looking for a member function; its demangled name will
9962 contain namespace info, if there is any. */
9965 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9966 struct dwarf2_cu
*cu
)
9968 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9969 what template types look like, because the demangler
9970 frequently doesn't give the same name as the debug info. We
9971 could fix this by only using the demangled name to get the
9972 prefix (but see comment in read_structure_type). */
9974 struct partial_die_info
*real_pdi
;
9975 struct partial_die_info
*child_pdi
;
9977 /* If this DIE (this DIE's specification, if any) has a parent, then
9978 we should not do this. We'll prepend the parent's fully qualified
9979 name when we create the partial symbol. */
9981 real_pdi
= struct_pdi
;
9982 while (real_pdi
->has_specification
)
9983 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9985 if (real_pdi
->die_parent
!= NULL
)
9988 for (child_pdi
= struct_pdi
->die_child
;
9990 child_pdi
= child_pdi
->die_sibling
)
9992 if (child_pdi
->tag
== DW_TAG_subprogram
9993 && child_pdi
->linkage_name
!= NULL
)
9995 char *actual_class_name
9996 = language_class_name_from_physname (cu
->language_defn
,
9997 child_pdi
->linkage_name
);
9998 if (actual_class_name
!= NULL
)
10001 = obsavestring (actual_class_name
,
10002 strlen (actual_class_name
),
10003 &cu
->objfile
->objfile_obstack
);
10004 xfree (actual_class_name
);
10011 /* Adjust PART_DIE before generating a symbol for it. This function
10012 may set the is_external flag or change the DIE's name. */
10015 fixup_partial_die (struct partial_die_info
*part_die
,
10016 struct dwarf2_cu
*cu
)
10018 /* Once we've fixed up a die, there's no point in doing so again.
10019 This also avoids a memory leak if we were to call
10020 guess_partial_die_structure_name multiple times. */
10021 if (part_die
->fixup_called
)
10024 /* If we found a reference attribute and the DIE has no name, try
10025 to find a name in the referred to DIE. */
10027 if (part_die
->name
== NULL
&& part_die
->has_specification
)
10029 struct partial_die_info
*spec_die
;
10031 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
10033 fixup_partial_die (spec_die
, cu
);
10035 if (spec_die
->name
)
10037 part_die
->name
= spec_die
->name
;
10039 /* Copy DW_AT_external attribute if it is set. */
10040 if (spec_die
->is_external
)
10041 part_die
->is_external
= spec_die
->is_external
;
10045 /* Set default names for some unnamed DIEs. */
10047 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
10048 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
10050 /* If there is no parent die to provide a namespace, and there are
10051 children, see if we can determine the namespace from their linkage
10053 NOTE: We need to do this even if cu->has_namespace_info != 0.
10054 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
10055 if (cu
->language
== language_cplus
10056 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
10057 && part_die
->die_parent
== NULL
10058 && part_die
->has_children
10059 && (part_die
->tag
== DW_TAG_class_type
10060 || part_die
->tag
== DW_TAG_structure_type
10061 || part_die
->tag
== DW_TAG_union_type
))
10062 guess_partial_die_structure_name (part_die
, cu
);
10064 /* GCC might emit a nameless struct or union that has a linkage
10065 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10066 if (part_die
->name
== NULL
10067 && (part_die
->tag
== DW_TAG_class_type
10068 || part_die
->tag
== DW_TAG_interface_type
10069 || part_die
->tag
== DW_TAG_structure_type
10070 || part_die
->tag
== DW_TAG_union_type
)
10071 && part_die
->linkage_name
!= NULL
)
10075 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
10080 /* Strip any leading namespaces/classes, keep only the base name.
10081 DW_AT_name for named DIEs does not contain the prefixes. */
10082 base
= strrchr (demangled
, ':');
10083 if (base
&& base
> demangled
&& base
[-1] == ':')
10088 part_die
->name
= obsavestring (base
, strlen (base
),
10089 &cu
->objfile
->objfile_obstack
);
10094 part_die
->fixup_called
= 1;
10097 /* Read an attribute value described by an attribute form. */
10100 read_attribute_value (struct attribute
*attr
, unsigned form
,
10101 bfd
*abfd
, gdb_byte
*info_ptr
,
10102 struct dwarf2_cu
*cu
)
10104 struct comp_unit_head
*cu_header
= &cu
->header
;
10105 unsigned int bytes_read
;
10106 struct dwarf_block
*blk
;
10111 case DW_FORM_ref_addr
:
10112 if (cu
->header
.version
== 2)
10113 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10115 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
10116 &cu
->header
, &bytes_read
);
10117 info_ptr
+= bytes_read
;
10120 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10121 info_ptr
+= bytes_read
;
10123 case DW_FORM_block2
:
10124 blk
= dwarf_alloc_block (cu
);
10125 blk
->size
= read_2_bytes (abfd
, info_ptr
);
10127 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10128 info_ptr
+= blk
->size
;
10129 DW_BLOCK (attr
) = blk
;
10131 case DW_FORM_block4
:
10132 blk
= dwarf_alloc_block (cu
);
10133 blk
->size
= read_4_bytes (abfd
, info_ptr
);
10135 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10136 info_ptr
+= blk
->size
;
10137 DW_BLOCK (attr
) = blk
;
10139 case DW_FORM_data2
:
10140 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
10143 case DW_FORM_data4
:
10144 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
10147 case DW_FORM_data8
:
10148 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
10151 case DW_FORM_sec_offset
:
10152 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
10153 info_ptr
+= bytes_read
;
10155 case DW_FORM_string
:
10156 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
10157 DW_STRING_IS_CANONICAL (attr
) = 0;
10158 info_ptr
+= bytes_read
;
10161 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
10163 DW_STRING_IS_CANONICAL (attr
) = 0;
10164 info_ptr
+= bytes_read
;
10166 case DW_FORM_exprloc
:
10167 case DW_FORM_block
:
10168 blk
= dwarf_alloc_block (cu
);
10169 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10170 info_ptr
+= bytes_read
;
10171 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10172 info_ptr
+= blk
->size
;
10173 DW_BLOCK (attr
) = blk
;
10175 case DW_FORM_block1
:
10176 blk
= dwarf_alloc_block (cu
);
10177 blk
->size
= read_1_byte (abfd
, info_ptr
);
10179 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10180 info_ptr
+= blk
->size
;
10181 DW_BLOCK (attr
) = blk
;
10183 case DW_FORM_data1
:
10184 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10188 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10191 case DW_FORM_flag_present
:
10192 DW_UNSND (attr
) = 1;
10194 case DW_FORM_sdata
:
10195 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
10196 info_ptr
+= bytes_read
;
10198 case DW_FORM_udata
:
10199 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10200 info_ptr
+= bytes_read
;
10203 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
10207 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
10211 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
10215 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
10218 case DW_FORM_ref_sig8
:
10219 /* Convert the signature to something we can record in DW_UNSND
10221 NOTE: This is NULL if the type wasn't found. */
10222 DW_SIGNATURED_TYPE (attr
) =
10223 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
10226 case DW_FORM_ref_udata
:
10227 DW_ADDR (attr
) = (cu
->header
.offset
10228 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
10229 info_ptr
+= bytes_read
;
10231 case DW_FORM_indirect
:
10232 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10233 info_ptr
+= bytes_read
;
10234 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
10237 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10238 dwarf_form_name (form
),
10239 bfd_get_filename (abfd
));
10242 /* We have seen instances where the compiler tried to emit a byte
10243 size attribute of -1 which ended up being encoded as an unsigned
10244 0xffffffff. Although 0xffffffff is technically a valid size value,
10245 an object of this size seems pretty unlikely so we can relatively
10246 safely treat these cases as if the size attribute was invalid and
10247 treat them as zero by default. */
10248 if (attr
->name
== DW_AT_byte_size
10249 && form
== DW_FORM_data4
10250 && DW_UNSND (attr
) >= 0xffffffff)
10253 (&symfile_complaints
,
10254 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10255 hex_string (DW_UNSND (attr
)));
10256 DW_UNSND (attr
) = 0;
10262 /* Read an attribute described by an abbreviated attribute. */
10265 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10266 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
10268 attr
->name
= abbrev
->name
;
10269 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
10272 /* Read dwarf information from a buffer. */
10274 static unsigned int
10275 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10277 return bfd_get_8 (abfd
, buf
);
10281 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10283 return bfd_get_signed_8 (abfd
, buf
);
10286 static unsigned int
10287 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10289 return bfd_get_16 (abfd
, buf
);
10293 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10295 return bfd_get_signed_16 (abfd
, buf
);
10298 static unsigned int
10299 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10301 return bfd_get_32 (abfd
, buf
);
10305 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10307 return bfd_get_signed_32 (abfd
, buf
);
10311 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10313 return bfd_get_64 (abfd
, buf
);
10317 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10318 unsigned int *bytes_read
)
10320 struct comp_unit_head
*cu_header
= &cu
->header
;
10321 CORE_ADDR retval
= 0;
10323 if (cu_header
->signed_addr_p
)
10325 switch (cu_header
->addr_size
)
10328 retval
= bfd_get_signed_16 (abfd
, buf
);
10331 retval
= bfd_get_signed_32 (abfd
, buf
);
10334 retval
= bfd_get_signed_64 (abfd
, buf
);
10337 internal_error (__FILE__
, __LINE__
,
10338 _("read_address: bad switch, signed [in module %s]"),
10339 bfd_get_filename (abfd
));
10344 switch (cu_header
->addr_size
)
10347 retval
= bfd_get_16 (abfd
, buf
);
10350 retval
= bfd_get_32 (abfd
, buf
);
10353 retval
= bfd_get_64 (abfd
, buf
);
10356 internal_error (__FILE__
, __LINE__
,
10357 _("read_address: bad switch, "
10358 "unsigned [in module %s]"),
10359 bfd_get_filename (abfd
));
10363 *bytes_read
= cu_header
->addr_size
;
10367 /* Read the initial length from a section. The (draft) DWARF 3
10368 specification allows the initial length to take up either 4 bytes
10369 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10370 bytes describe the length and all offsets will be 8 bytes in length
10373 An older, non-standard 64-bit format is also handled by this
10374 function. The older format in question stores the initial length
10375 as an 8-byte quantity without an escape value. Lengths greater
10376 than 2^32 aren't very common which means that the initial 4 bytes
10377 is almost always zero. Since a length value of zero doesn't make
10378 sense for the 32-bit format, this initial zero can be considered to
10379 be an escape value which indicates the presence of the older 64-bit
10380 format. As written, the code can't detect (old format) lengths
10381 greater than 4GB. If it becomes necessary to handle lengths
10382 somewhat larger than 4GB, we could allow other small values (such
10383 as the non-sensical values of 1, 2, and 3) to also be used as
10384 escape values indicating the presence of the old format.
10386 The value returned via bytes_read should be used to increment the
10387 relevant pointer after calling read_initial_length().
10389 [ Note: read_initial_length() and read_offset() are based on the
10390 document entitled "DWARF Debugging Information Format", revision
10391 3, draft 8, dated November 19, 2001. This document was obtained
10394 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10396 This document is only a draft and is subject to change. (So beware.)
10398 Details regarding the older, non-standard 64-bit format were
10399 determined empirically by examining 64-bit ELF files produced by
10400 the SGI toolchain on an IRIX 6.5 machine.
10402 - Kevin, July 16, 2002
10406 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10408 LONGEST length
= bfd_get_32 (abfd
, buf
);
10410 if (length
== 0xffffffff)
10412 length
= bfd_get_64 (abfd
, buf
+ 4);
10415 else if (length
== 0)
10417 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10418 length
= bfd_get_64 (abfd
, buf
);
10429 /* Cover function for read_initial_length.
10430 Returns the length of the object at BUF, and stores the size of the
10431 initial length in *BYTES_READ and stores the size that offsets will be in
10433 If the initial length size is not equivalent to that specified in
10434 CU_HEADER then issue a complaint.
10435 This is useful when reading non-comp-unit headers. */
10438 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10439 const struct comp_unit_head
*cu_header
,
10440 unsigned int *bytes_read
,
10441 unsigned int *offset_size
)
10443 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10445 gdb_assert (cu_header
->initial_length_size
== 4
10446 || cu_header
->initial_length_size
== 8
10447 || cu_header
->initial_length_size
== 12);
10449 if (cu_header
->initial_length_size
!= *bytes_read
)
10450 complaint (&symfile_complaints
,
10451 _("intermixed 32-bit and 64-bit DWARF sections"));
10453 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10457 /* Read an offset from the data stream. The size of the offset is
10458 given by cu_header->offset_size. */
10461 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10462 unsigned int *bytes_read
)
10464 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10466 *bytes_read
= cu_header
->offset_size
;
10470 /* Read an offset from the data stream. */
10473 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10475 LONGEST retval
= 0;
10477 switch (offset_size
)
10480 retval
= bfd_get_32 (abfd
, buf
);
10483 retval
= bfd_get_64 (abfd
, buf
);
10486 internal_error (__FILE__
, __LINE__
,
10487 _("read_offset_1: bad switch [in module %s]"),
10488 bfd_get_filename (abfd
));
10495 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10497 /* If the size of a host char is 8 bits, we can return a pointer
10498 to the buffer, otherwise we have to copy the data to a buffer
10499 allocated on the temporary obstack. */
10500 gdb_assert (HOST_CHAR_BIT
== 8);
10505 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10507 /* If the size of a host char is 8 bits, we can return a pointer
10508 to the string, otherwise we have to copy the string to a buffer
10509 allocated on the temporary obstack. */
10510 gdb_assert (HOST_CHAR_BIT
== 8);
10513 *bytes_read_ptr
= 1;
10516 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10517 return (char *) buf
;
10521 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
10523 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10524 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10525 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10526 bfd_get_filename (abfd
));
10527 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10528 error (_("DW_FORM_strp pointing outside of "
10529 ".debug_str section [in module %s]"),
10530 bfd_get_filename (abfd
));
10531 gdb_assert (HOST_CHAR_BIT
== 8);
10532 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10534 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10538 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10539 const struct comp_unit_head
*cu_header
,
10540 unsigned int *bytes_read_ptr
)
10542 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10544 return read_indirect_string_at_offset (abfd
, str_offset
);
10547 static unsigned long
10548 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10550 unsigned long result
;
10551 unsigned int num_read
;
10553 unsigned char byte
;
10561 byte
= bfd_get_8 (abfd
, buf
);
10564 result
|= ((unsigned long)(byte
& 127) << shift
);
10565 if ((byte
& 128) == 0)
10571 *bytes_read_ptr
= num_read
;
10576 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10579 int i
, shift
, num_read
;
10580 unsigned char byte
;
10588 byte
= bfd_get_8 (abfd
, buf
);
10591 result
|= ((long)(byte
& 127) << shift
);
10593 if ((byte
& 128) == 0)
10598 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10599 result
|= -(((long)1) << shift
);
10600 *bytes_read_ptr
= num_read
;
10604 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10607 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10613 byte
= bfd_get_8 (abfd
, buf
);
10615 if ((byte
& 128) == 0)
10621 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10628 cu
->language
= language_c
;
10630 case DW_LANG_C_plus_plus
:
10631 cu
->language
= language_cplus
;
10634 cu
->language
= language_d
;
10636 case DW_LANG_Fortran77
:
10637 case DW_LANG_Fortran90
:
10638 case DW_LANG_Fortran95
:
10639 cu
->language
= language_fortran
;
10641 case DW_LANG_Mips_Assembler
:
10642 cu
->language
= language_asm
;
10645 cu
->language
= language_java
;
10647 case DW_LANG_Ada83
:
10648 case DW_LANG_Ada95
:
10649 cu
->language
= language_ada
;
10651 case DW_LANG_Modula2
:
10652 cu
->language
= language_m2
;
10654 case DW_LANG_Pascal83
:
10655 cu
->language
= language_pascal
;
10658 cu
->language
= language_objc
;
10660 case DW_LANG_Cobol74
:
10661 case DW_LANG_Cobol85
:
10663 cu
->language
= language_minimal
;
10666 cu
->language_defn
= language_def (cu
->language
);
10669 /* Return the named attribute or NULL if not there. */
10671 static struct attribute
*
10672 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10675 struct attribute
*spec
= NULL
;
10677 for (i
= 0; i
< die
->num_attrs
; ++i
)
10679 if (die
->attrs
[i
].name
== name
)
10680 return &die
->attrs
[i
];
10681 if (die
->attrs
[i
].name
== DW_AT_specification
10682 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10683 spec
= &die
->attrs
[i
];
10688 die
= follow_die_ref (die
, spec
, &cu
);
10689 return dwarf2_attr (die
, name
, cu
);
10695 /* Return the named attribute or NULL if not there,
10696 but do not follow DW_AT_specification, etc.
10697 This is for use in contexts where we're reading .debug_types dies.
10698 Following DW_AT_specification, DW_AT_abstract_origin will take us
10699 back up the chain, and we want to go down. */
10701 static struct attribute
*
10702 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10703 struct dwarf2_cu
*cu
)
10707 for (i
= 0; i
< die
->num_attrs
; ++i
)
10708 if (die
->attrs
[i
].name
== name
)
10709 return &die
->attrs
[i
];
10714 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10715 and holds a non-zero value. This function should only be used for
10716 DW_FORM_flag or DW_FORM_flag_present attributes. */
10719 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10721 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10723 return (attr
&& DW_UNSND (attr
));
10727 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10729 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10730 which value is non-zero. However, we have to be careful with
10731 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10732 (via dwarf2_flag_true_p) follows this attribute. So we may
10733 end up accidently finding a declaration attribute that belongs
10734 to a different DIE referenced by the specification attribute,
10735 even though the given DIE does not have a declaration attribute. */
10736 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10737 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10740 /* Return the die giving the specification for DIE, if there is
10741 one. *SPEC_CU is the CU containing DIE on input, and the CU
10742 containing the return value on output. If there is no
10743 specification, but there is an abstract origin, that is
10746 static struct die_info
*
10747 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10749 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10752 if (spec_attr
== NULL
)
10753 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10755 if (spec_attr
== NULL
)
10758 return follow_die_ref (die
, spec_attr
, spec_cu
);
10761 /* Free the line_header structure *LH, and any arrays and strings it
10763 NOTE: This is also used as a "cleanup" function. */
10766 free_line_header (struct line_header
*lh
)
10768 if (lh
->standard_opcode_lengths
)
10769 xfree (lh
->standard_opcode_lengths
);
10771 /* Remember that all the lh->file_names[i].name pointers are
10772 pointers into debug_line_buffer, and don't need to be freed. */
10773 if (lh
->file_names
)
10774 xfree (lh
->file_names
);
10776 /* Similarly for the include directory names. */
10777 if (lh
->include_dirs
)
10778 xfree (lh
->include_dirs
);
10783 /* Add an entry to LH's include directory table. */
10786 add_include_dir (struct line_header
*lh
, char *include_dir
)
10788 /* Grow the array if necessary. */
10789 if (lh
->include_dirs_size
== 0)
10791 lh
->include_dirs_size
= 1; /* for testing */
10792 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10793 * sizeof (*lh
->include_dirs
));
10795 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10797 lh
->include_dirs_size
*= 2;
10798 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10799 (lh
->include_dirs_size
10800 * sizeof (*lh
->include_dirs
)));
10803 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10806 /* Add an entry to LH's file name table. */
10809 add_file_name (struct line_header
*lh
,
10811 unsigned int dir_index
,
10812 unsigned int mod_time
,
10813 unsigned int length
)
10815 struct file_entry
*fe
;
10817 /* Grow the array if necessary. */
10818 if (lh
->file_names_size
== 0)
10820 lh
->file_names_size
= 1; /* for testing */
10821 lh
->file_names
= xmalloc (lh
->file_names_size
10822 * sizeof (*lh
->file_names
));
10824 else if (lh
->num_file_names
>= lh
->file_names_size
)
10826 lh
->file_names_size
*= 2;
10827 lh
->file_names
= xrealloc (lh
->file_names
,
10828 (lh
->file_names_size
10829 * sizeof (*lh
->file_names
)));
10832 fe
= &lh
->file_names
[lh
->num_file_names
++];
10834 fe
->dir_index
= dir_index
;
10835 fe
->mod_time
= mod_time
;
10836 fe
->length
= length
;
10837 fe
->included_p
= 0;
10841 /* Read the statement program header starting at OFFSET in
10842 .debug_line, according to the endianness of ABFD. Return a pointer
10843 to a struct line_header, allocated using xmalloc.
10845 NOTE: the strings in the include directory and file name tables of
10846 the returned object point into debug_line_buffer, and must not be
10849 static struct line_header
*
10850 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10851 struct dwarf2_cu
*cu
)
10853 struct cleanup
*back_to
;
10854 struct line_header
*lh
;
10855 gdb_byte
*line_ptr
;
10856 unsigned int bytes_read
, offset_size
;
10858 char *cur_dir
, *cur_file
;
10860 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10861 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10863 complaint (&symfile_complaints
, _("missing .debug_line section"));
10867 /* Make sure that at least there's room for the total_length field.
10868 That could be 12 bytes long, but we're just going to fudge that. */
10869 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10871 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10875 lh
= xmalloc (sizeof (*lh
));
10876 memset (lh
, 0, sizeof (*lh
));
10877 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10880 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10882 /* Read in the header. */
10884 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10885 &bytes_read
, &offset_size
);
10886 line_ptr
+= bytes_read
;
10887 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10888 + dwarf2_per_objfile
->line
.size
))
10890 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10893 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10894 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10896 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10897 line_ptr
+= offset_size
;
10898 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10900 if (lh
->version
>= 4)
10902 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10906 lh
->maximum_ops_per_instruction
= 1;
10908 if (lh
->maximum_ops_per_instruction
== 0)
10910 lh
->maximum_ops_per_instruction
= 1;
10911 complaint (&symfile_complaints
,
10912 _("invalid maximum_ops_per_instruction "
10913 "in `.debug_line' section"));
10916 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10918 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10920 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10922 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10924 lh
->standard_opcode_lengths
10925 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10927 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10928 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10930 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10934 /* Read directory table. */
10935 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10937 line_ptr
+= bytes_read
;
10938 add_include_dir (lh
, cur_dir
);
10940 line_ptr
+= bytes_read
;
10942 /* Read file name table. */
10943 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10945 unsigned int dir_index
, mod_time
, length
;
10947 line_ptr
+= bytes_read
;
10948 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10949 line_ptr
+= bytes_read
;
10950 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10951 line_ptr
+= bytes_read
;
10952 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10953 line_ptr
+= bytes_read
;
10955 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10957 line_ptr
+= bytes_read
;
10958 lh
->statement_program_start
= line_ptr
;
10960 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
10961 + dwarf2_per_objfile
->line
.size
))
10962 complaint (&symfile_complaints
,
10963 _("line number info header doesn't "
10964 "fit in `.debug_line' section"));
10966 discard_cleanups (back_to
);
10970 /* Subroutine of dwarf_decode_lines to simplify it.
10971 Return the file name of the psymtab for included file FILE_INDEX
10972 in line header LH of PST.
10973 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10974 If space for the result is malloc'd, it will be freed by a cleanup.
10975 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10978 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10979 const struct partial_symtab
*pst
,
10980 const char *comp_dir
)
10982 const struct file_entry fe
= lh
->file_names
[file_index
];
10983 char *include_name
= fe
.name
;
10984 char *include_name_to_compare
= include_name
;
10985 char *dir_name
= NULL
;
10986 const char *pst_filename
;
10987 char *copied_name
= NULL
;
10991 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10993 if (!IS_ABSOLUTE_PATH (include_name
)
10994 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10996 /* Avoid creating a duplicate psymtab for PST.
10997 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10998 Before we do the comparison, however, we need to account
10999 for DIR_NAME and COMP_DIR.
11000 First prepend dir_name (if non-NULL). If we still don't
11001 have an absolute path prepend comp_dir (if non-NULL).
11002 However, the directory we record in the include-file's
11003 psymtab does not contain COMP_DIR (to match the
11004 corresponding symtab(s)).
11009 bash$ gcc -g ./hello.c
11010 include_name = "hello.c"
11012 DW_AT_comp_dir = comp_dir = "/tmp"
11013 DW_AT_name = "./hello.c" */
11015 if (dir_name
!= NULL
)
11017 include_name
= concat (dir_name
, SLASH_STRING
,
11018 include_name
, (char *)NULL
);
11019 include_name_to_compare
= include_name
;
11020 make_cleanup (xfree
, include_name
);
11022 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
11024 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
11025 include_name
, (char *)NULL
);
11029 pst_filename
= pst
->filename
;
11030 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
11032 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
11033 pst_filename
, (char *)NULL
);
11034 pst_filename
= copied_name
;
11037 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
11039 if (include_name_to_compare
!= include_name
)
11040 xfree (include_name_to_compare
);
11041 if (copied_name
!= NULL
)
11042 xfree (copied_name
);
11046 return include_name
;
11049 /* Ignore this record_line request. */
11052 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11057 /* Decode the Line Number Program (LNP) for the given line_header
11058 structure and CU. The actual information extracted and the type
11059 of structures created from the LNP depends on the value of PST.
11061 1. If PST is NULL, then this procedure uses the data from the program
11062 to create all necessary symbol tables, and their linetables.
11064 2. If PST is not NULL, this procedure reads the program to determine
11065 the list of files included by the unit represented by PST, and
11066 builds all the associated partial symbol tables.
11068 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11069 It is used for relative paths in the line table.
11070 NOTE: When processing partial symtabs (pst != NULL),
11071 comp_dir == pst->dirname.
11073 NOTE: It is important that psymtabs have the same file name (via strcmp)
11074 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11075 symtab we don't use it in the name of the psymtabs we create.
11076 E.g. expand_line_sal requires this when finding psymtabs to expand.
11077 A good testcase for this is mb-inline.exp. */
11080 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
11081 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
11083 gdb_byte
*line_ptr
, *extended_end
;
11084 gdb_byte
*line_end
;
11085 unsigned int bytes_read
, extended_len
;
11086 unsigned char op_code
, extended_op
, adj_opcode
;
11087 CORE_ADDR baseaddr
;
11088 struct objfile
*objfile
= cu
->objfile
;
11089 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11090 const int decode_for_pst_p
= (pst
!= NULL
);
11091 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
11092 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11095 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11097 line_ptr
= lh
->statement_program_start
;
11098 line_end
= lh
->statement_program_end
;
11100 /* Read the statement sequences until there's nothing left. */
11101 while (line_ptr
< line_end
)
11103 /* state machine registers */
11104 CORE_ADDR address
= 0;
11105 unsigned int file
= 1;
11106 unsigned int line
= 1;
11107 unsigned int column
= 0;
11108 int is_stmt
= lh
->default_is_stmt
;
11109 int basic_block
= 0;
11110 int end_sequence
= 0;
11112 unsigned char op_index
= 0;
11114 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
11116 /* Start a subfile for the current file of the state machine. */
11117 /* lh->include_dirs and lh->file_names are 0-based, but the
11118 directory and file name numbers in the statement program
11120 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11124 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11126 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11129 /* Decode the table. */
11130 while (!end_sequence
)
11132 op_code
= read_1_byte (abfd
, line_ptr
);
11134 if (line_ptr
> line_end
)
11136 dwarf2_debug_line_missing_end_sequence_complaint ();
11140 if (op_code
>= lh
->opcode_base
)
11142 /* Special operand. */
11143 adj_opcode
= op_code
- lh
->opcode_base
;
11144 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
11145 / lh
->maximum_ops_per_instruction
)
11146 * lh
->minimum_instruction_length
);
11147 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
11148 % lh
->maximum_ops_per_instruction
);
11149 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
11150 if (lh
->num_file_names
< file
|| file
== 0)
11151 dwarf2_debug_line_missing_file_complaint ();
11152 /* For now we ignore lines not starting on an
11153 instruction boundary. */
11154 else if (op_index
== 0)
11156 lh
->file_names
[file
- 1].included_p
= 1;
11157 if (!decode_for_pst_p
&& is_stmt
)
11159 if (last_subfile
!= current_subfile
)
11161 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11163 (*p_record_line
) (last_subfile
, 0, addr
);
11164 last_subfile
= current_subfile
;
11166 /* Append row to matrix using current values. */
11167 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11168 (*p_record_line
) (current_subfile
, line
, addr
);
11173 else switch (op_code
)
11175 case DW_LNS_extended_op
:
11176 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
11178 line_ptr
+= bytes_read
;
11179 extended_end
= line_ptr
+ extended_len
;
11180 extended_op
= read_1_byte (abfd
, line_ptr
);
11182 switch (extended_op
)
11184 case DW_LNE_end_sequence
:
11185 p_record_line
= record_line
;
11188 case DW_LNE_set_address
:
11189 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
11191 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11193 /* This line table is for a function which has been
11194 GCd by the linker. Ignore it. PR gdb/12528 */
11197 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
11199 complaint (&symfile_complaints
,
11200 _(".debug_line address at offset 0x%lx is 0 "
11202 line_offset
, objfile
->name
);
11203 p_record_line
= noop_record_line
;
11207 line_ptr
+= bytes_read
;
11208 address
+= baseaddr
;
11210 case DW_LNE_define_file
:
11213 unsigned int dir_index
, mod_time
, length
;
11215 cur_file
= read_direct_string (abfd
, line_ptr
,
11217 line_ptr
+= bytes_read
;
11219 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11220 line_ptr
+= bytes_read
;
11222 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11223 line_ptr
+= bytes_read
;
11225 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11226 line_ptr
+= bytes_read
;
11227 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11230 case DW_LNE_set_discriminator
:
11231 /* The discriminator is not interesting to the debugger;
11233 line_ptr
= extended_end
;
11236 complaint (&symfile_complaints
,
11237 _("mangled .debug_line section"));
11240 /* Make sure that we parsed the extended op correctly. If e.g.
11241 we expected a different address size than the producer used,
11242 we may have read the wrong number of bytes. */
11243 if (line_ptr
!= extended_end
)
11245 complaint (&symfile_complaints
,
11246 _("mangled .debug_line section"));
11251 if (lh
->num_file_names
< file
|| file
== 0)
11252 dwarf2_debug_line_missing_file_complaint ();
11255 lh
->file_names
[file
- 1].included_p
= 1;
11256 if (!decode_for_pst_p
&& is_stmt
)
11258 if (last_subfile
!= current_subfile
)
11260 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11262 (*p_record_line
) (last_subfile
, 0, addr
);
11263 last_subfile
= current_subfile
;
11265 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11266 (*p_record_line
) (current_subfile
, line
, addr
);
11271 case DW_LNS_advance_pc
:
11274 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11276 address
+= (((op_index
+ adjust
)
11277 / lh
->maximum_ops_per_instruction
)
11278 * lh
->minimum_instruction_length
);
11279 op_index
= ((op_index
+ adjust
)
11280 % lh
->maximum_ops_per_instruction
);
11281 line_ptr
+= bytes_read
;
11284 case DW_LNS_advance_line
:
11285 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11286 line_ptr
+= bytes_read
;
11288 case DW_LNS_set_file
:
11290 /* The arrays lh->include_dirs and lh->file_names are
11291 0-based, but the directory and file name numbers in
11292 the statement program are 1-based. */
11293 struct file_entry
*fe
;
11296 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11297 line_ptr
+= bytes_read
;
11298 if (lh
->num_file_names
< file
|| file
== 0)
11299 dwarf2_debug_line_missing_file_complaint ();
11302 fe
= &lh
->file_names
[file
- 1];
11304 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11305 if (!decode_for_pst_p
)
11307 last_subfile
= current_subfile
;
11308 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11313 case DW_LNS_set_column
:
11314 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11315 line_ptr
+= bytes_read
;
11317 case DW_LNS_negate_stmt
:
11318 is_stmt
= (!is_stmt
);
11320 case DW_LNS_set_basic_block
:
11323 /* Add to the address register of the state machine the
11324 address increment value corresponding to special opcode
11325 255. I.e., this value is scaled by the minimum
11326 instruction length since special opcode 255 would have
11327 scaled the increment. */
11328 case DW_LNS_const_add_pc
:
11330 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11332 address
+= (((op_index
+ adjust
)
11333 / lh
->maximum_ops_per_instruction
)
11334 * lh
->minimum_instruction_length
);
11335 op_index
= ((op_index
+ adjust
)
11336 % lh
->maximum_ops_per_instruction
);
11339 case DW_LNS_fixed_advance_pc
:
11340 address
+= read_2_bytes (abfd
, line_ptr
);
11346 /* Unknown standard opcode, ignore it. */
11349 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11351 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11352 line_ptr
+= bytes_read
;
11357 if (lh
->num_file_names
< file
|| file
== 0)
11358 dwarf2_debug_line_missing_file_complaint ();
11361 lh
->file_names
[file
- 1].included_p
= 1;
11362 if (!decode_for_pst_p
)
11364 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11365 (*p_record_line
) (current_subfile
, 0, addr
);
11370 if (decode_for_pst_p
)
11374 /* Now that we're done scanning the Line Header Program, we can
11375 create the psymtab of each included file. */
11376 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11377 if (lh
->file_names
[file_index
].included_p
== 1)
11379 char *include_name
=
11380 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11381 if (include_name
!= NULL
)
11382 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11387 /* Make sure a symtab is created for every file, even files
11388 which contain only variables (i.e. no code with associated
11392 struct file_entry
*fe
;
11394 for (i
= 0; i
< lh
->num_file_names
; i
++)
11398 fe
= &lh
->file_names
[i
];
11400 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11401 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11403 /* Skip the main file; we don't need it, and it must be
11404 allocated last, so that it will show up before the
11405 non-primary symtabs in the objfile's symtab list. */
11406 if (current_subfile
== first_subfile
)
11409 if (current_subfile
->symtab
== NULL
)
11410 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11412 fe
->symtab
= current_subfile
->symtab
;
11417 /* Start a subfile for DWARF. FILENAME is the name of the file and
11418 DIRNAME the name of the source directory which contains FILENAME
11419 or NULL if not known. COMP_DIR is the compilation directory for the
11420 linetable's compilation unit or NULL if not known.
11421 This routine tries to keep line numbers from identical absolute and
11422 relative file names in a common subfile.
11424 Using the `list' example from the GDB testsuite, which resides in
11425 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11426 of /srcdir/list0.c yields the following debugging information for list0.c:
11428 DW_AT_name: /srcdir/list0.c
11429 DW_AT_comp_dir: /compdir
11430 files.files[0].name: list0.h
11431 files.files[0].dir: /srcdir
11432 files.files[1].name: list0.c
11433 files.files[1].dir: /srcdir
11435 The line number information for list0.c has to end up in a single
11436 subfile, so that `break /srcdir/list0.c:1' works as expected.
11437 start_subfile will ensure that this happens provided that we pass the
11438 concatenation of files.files[1].dir and files.files[1].name as the
11442 dwarf2_start_subfile (char *filename
, const char *dirname
,
11443 const char *comp_dir
)
11447 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11448 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11449 second argument to start_subfile. To be consistent, we do the
11450 same here. In order not to lose the line information directory,
11451 we concatenate it to the filename when it makes sense.
11452 Note that the Dwarf3 standard says (speaking of filenames in line
11453 information): ``The directory index is ignored for file names
11454 that represent full path names''. Thus ignoring dirname in the
11455 `else' branch below isn't an issue. */
11457 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11458 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11460 fullname
= filename
;
11462 start_subfile (fullname
, comp_dir
);
11464 if (fullname
!= filename
)
11469 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11470 struct dwarf2_cu
*cu
)
11472 struct objfile
*objfile
= cu
->objfile
;
11473 struct comp_unit_head
*cu_header
= &cu
->header
;
11475 /* NOTE drow/2003-01-30: There used to be a comment and some special
11476 code here to turn a symbol with DW_AT_external and a
11477 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11478 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11479 with some versions of binutils) where shared libraries could have
11480 relocations against symbols in their debug information - the
11481 minimal symbol would have the right address, but the debug info
11482 would not. It's no longer necessary, because we will explicitly
11483 apply relocations when we read in the debug information now. */
11485 /* A DW_AT_location attribute with no contents indicates that a
11486 variable has been optimized away. */
11487 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11489 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11493 /* Handle one degenerate form of location expression specially, to
11494 preserve GDB's previous behavior when section offsets are
11495 specified. If this is just a DW_OP_addr then mark this symbol
11498 if (attr_form_is_block (attr
)
11499 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11500 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11502 unsigned int dummy
;
11504 SYMBOL_VALUE_ADDRESS (sym
) =
11505 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11506 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11507 fixup_symbol_section (sym
, objfile
);
11508 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11509 SYMBOL_SECTION (sym
));
11513 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11514 expression evaluator, and use LOC_COMPUTED only when necessary
11515 (i.e. when the value of a register or memory location is
11516 referenced, or a thread-local block, etc.). Then again, it might
11517 not be worthwhile. I'm assuming that it isn't unless performance
11518 or memory numbers show me otherwise. */
11520 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11521 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11523 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11524 cu
->has_loclist
= 1;
11527 /* Given a pointer to a DWARF information entry, figure out if we need
11528 to make a symbol table entry for it, and if so, create a new entry
11529 and return a pointer to it.
11530 If TYPE is NULL, determine symbol type from the die, otherwise
11531 used the passed type.
11532 If SPACE is not NULL, use it to hold the new symbol. If it is
11533 NULL, allocate a new symbol on the objfile's obstack. */
11535 static struct symbol
*
11536 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11537 struct symbol
*space
)
11539 struct objfile
*objfile
= cu
->objfile
;
11540 struct symbol
*sym
= NULL
;
11542 struct attribute
*attr
= NULL
;
11543 struct attribute
*attr2
= NULL
;
11544 CORE_ADDR baseaddr
;
11545 struct pending
**list_to_add
= NULL
;
11547 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11549 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11551 name
= dwarf2_name (die
, cu
);
11554 const char *linkagename
;
11555 int suppress_add
= 0;
11560 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11561 OBJSTAT (objfile
, n_syms
++);
11563 /* Cache this symbol's name and the name's demangled form (if any). */
11564 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11565 linkagename
= dwarf2_physname (name
, die
, cu
);
11566 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11568 /* Fortran does not have mangling standard and the mangling does differ
11569 between gfortran, iFort etc. */
11570 if (cu
->language
== language_fortran
11571 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11572 symbol_set_demangled_name (&(sym
->ginfo
),
11573 (char *) dwarf2_full_name (name
, die
, cu
),
11576 /* Default assumptions.
11577 Use the passed type or decode it from the die. */
11578 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11579 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11581 SYMBOL_TYPE (sym
) = type
;
11583 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11584 attr
= dwarf2_attr (die
,
11585 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11589 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11592 attr
= dwarf2_attr (die
,
11593 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11597 int file_index
= DW_UNSND (attr
);
11599 if (cu
->line_header
== NULL
11600 || file_index
> cu
->line_header
->num_file_names
)
11601 complaint (&symfile_complaints
,
11602 _("file index out of range"));
11603 else if (file_index
> 0)
11605 struct file_entry
*fe
;
11607 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11608 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11615 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11618 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11620 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11621 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11622 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11623 add_symbol_to_list (sym
, cu
->list_in_scope
);
11625 case DW_TAG_subprogram
:
11626 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11628 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11629 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11630 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11631 || cu
->language
== language_ada
)
11633 /* Subprograms marked external are stored as a global symbol.
11634 Ada subprograms, whether marked external or not, are always
11635 stored as a global symbol, because we want to be able to
11636 access them globally. For instance, we want to be able
11637 to break on a nested subprogram without having to
11638 specify the context. */
11639 list_to_add
= &global_symbols
;
11643 list_to_add
= cu
->list_in_scope
;
11646 case DW_TAG_inlined_subroutine
:
11647 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11649 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11650 SYMBOL_INLINED (sym
) = 1;
11651 /* Do not add the symbol to any lists. It will be found via
11652 BLOCK_FUNCTION from the blockvector. */
11654 case DW_TAG_template_value_param
:
11656 /* Fall through. */
11657 case DW_TAG_constant
:
11658 case DW_TAG_variable
:
11659 case DW_TAG_member
:
11660 /* Compilation with minimal debug info may result in
11661 variables with missing type entries. Change the
11662 misleading `void' type to something sensible. */
11663 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11665 = objfile_type (objfile
)->nodebug_data_symbol
;
11667 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11668 /* In the case of DW_TAG_member, we should only be called for
11669 static const members. */
11670 if (die
->tag
== DW_TAG_member
)
11672 /* dwarf2_add_field uses die_is_declaration,
11673 so we do the same. */
11674 gdb_assert (die_is_declaration (die
, cu
));
11679 dwarf2_const_value (attr
, sym
, cu
);
11680 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11683 if (attr2
&& (DW_UNSND (attr2
) != 0))
11684 list_to_add
= &global_symbols
;
11686 list_to_add
= cu
->list_in_scope
;
11690 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11693 var_decode_location (attr
, sym
, cu
);
11694 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11695 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11696 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11697 && !dwarf2_per_objfile
->has_section_at_zero
)
11699 /* When a static variable is eliminated by the linker,
11700 the corresponding debug information is not stripped
11701 out, but the variable address is set to null;
11702 do not add such variables into symbol table. */
11704 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11706 /* Workaround gfortran PR debug/40040 - it uses
11707 DW_AT_location for variables in -fPIC libraries which may
11708 get overriden by other libraries/executable and get
11709 a different address. Resolve it by the minimal symbol
11710 which may come from inferior's executable using copy
11711 relocation. Make this workaround only for gfortran as for
11712 other compilers GDB cannot guess the minimal symbol
11713 Fortran mangling kind. */
11714 if (cu
->language
== language_fortran
&& die
->parent
11715 && die
->parent
->tag
== DW_TAG_module
11717 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11718 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11720 /* A variable with DW_AT_external is never static,
11721 but it may be block-scoped. */
11722 list_to_add
= (cu
->list_in_scope
== &file_symbols
11723 ? &global_symbols
: cu
->list_in_scope
);
11726 list_to_add
= cu
->list_in_scope
;
11730 /* We do not know the address of this symbol.
11731 If it is an external symbol and we have type information
11732 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11733 The address of the variable will then be determined from
11734 the minimal symbol table whenever the variable is
11736 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11737 if (attr2
&& (DW_UNSND (attr2
) != 0)
11738 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11740 /* A variable with DW_AT_external is never static, but it
11741 may be block-scoped. */
11742 list_to_add
= (cu
->list_in_scope
== &file_symbols
11743 ? &global_symbols
: cu
->list_in_scope
);
11745 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11747 else if (!die_is_declaration (die
, cu
))
11749 /* Use the default LOC_OPTIMIZED_OUT class. */
11750 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11752 list_to_add
= cu
->list_in_scope
;
11756 case DW_TAG_formal_parameter
:
11757 /* If we are inside a function, mark this as an argument. If
11758 not, we might be looking at an argument to an inlined function
11759 when we do not have enough information to show inlined frames;
11760 pretend it's a local variable in that case so that the user can
11762 if (context_stack_depth
> 0
11763 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11764 SYMBOL_IS_ARGUMENT (sym
) = 1;
11765 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11768 var_decode_location (attr
, sym
, cu
);
11770 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11773 dwarf2_const_value (attr
, sym
, cu
);
11776 list_to_add
= cu
->list_in_scope
;
11778 case DW_TAG_unspecified_parameters
:
11779 /* From varargs functions; gdb doesn't seem to have any
11780 interest in this information, so just ignore it for now.
11783 case DW_TAG_template_type_param
:
11785 /* Fall through. */
11786 case DW_TAG_class_type
:
11787 case DW_TAG_interface_type
:
11788 case DW_TAG_structure_type
:
11789 case DW_TAG_union_type
:
11790 case DW_TAG_set_type
:
11791 case DW_TAG_enumeration_type
:
11792 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11793 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11796 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11797 really ever be static objects: otherwise, if you try
11798 to, say, break of a class's method and you're in a file
11799 which doesn't mention that class, it won't work unless
11800 the check for all static symbols in lookup_symbol_aux
11801 saves you. See the OtherFileClass tests in
11802 gdb.c++/namespace.exp. */
11806 list_to_add
= (cu
->list_in_scope
== &file_symbols
11807 && (cu
->language
== language_cplus
11808 || cu
->language
== language_java
)
11809 ? &global_symbols
: cu
->list_in_scope
);
11811 /* The semantics of C++ state that "struct foo {
11812 ... }" also defines a typedef for "foo". A Java
11813 class declaration also defines a typedef for the
11815 if (cu
->language
== language_cplus
11816 || cu
->language
== language_java
11817 || cu
->language
== language_ada
)
11819 /* The symbol's name is already allocated along
11820 with this objfile, so we don't need to
11821 duplicate it for the type. */
11822 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11823 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11828 case DW_TAG_typedef
:
11829 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11830 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11831 list_to_add
= cu
->list_in_scope
;
11833 case DW_TAG_base_type
:
11834 case DW_TAG_subrange_type
:
11835 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11836 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11837 list_to_add
= cu
->list_in_scope
;
11839 case DW_TAG_enumerator
:
11840 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11843 dwarf2_const_value (attr
, sym
, cu
);
11846 /* NOTE: carlton/2003-11-10: See comment above in the
11847 DW_TAG_class_type, etc. block. */
11849 list_to_add
= (cu
->list_in_scope
== &file_symbols
11850 && (cu
->language
== language_cplus
11851 || cu
->language
== language_java
)
11852 ? &global_symbols
: cu
->list_in_scope
);
11855 case DW_TAG_namespace
:
11856 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11857 list_to_add
= &global_symbols
;
11860 /* Not a tag we recognize. Hopefully we aren't processing
11861 trash data, but since we must specifically ignore things
11862 we don't recognize, there is nothing else we should do at
11864 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11865 dwarf_tag_name (die
->tag
));
11871 sym
->hash_next
= objfile
->template_symbols
;
11872 objfile
->template_symbols
= sym
;
11873 list_to_add
= NULL
;
11876 if (list_to_add
!= NULL
)
11877 add_symbol_to_list (sym
, list_to_add
);
11879 /* For the benefit of old versions of GCC, check for anonymous
11880 namespaces based on the demangled name. */
11881 if (!processing_has_namespace_info
11882 && cu
->language
== language_cplus
)
11883 cp_scan_for_anonymous_namespaces (sym
, objfile
);
11888 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11890 static struct symbol
*
11891 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11893 return new_symbol_full (die
, type
, cu
, NULL
);
11896 /* Given an attr with a DW_FORM_dataN value in host byte order,
11897 zero-extend it as appropriate for the symbol's type. The DWARF
11898 standard (v4) is not entirely clear about the meaning of using
11899 DW_FORM_dataN for a constant with a signed type, where the type is
11900 wider than the data. The conclusion of a discussion on the DWARF
11901 list was that this is unspecified. We choose to always zero-extend
11902 because that is the interpretation long in use by GCC. */
11905 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11906 const char *name
, struct obstack
*obstack
,
11907 struct dwarf2_cu
*cu
, long *value
, int bits
)
11909 struct objfile
*objfile
= cu
->objfile
;
11910 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11911 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11912 LONGEST l
= DW_UNSND (attr
);
11914 if (bits
< sizeof (*value
) * 8)
11916 l
&= ((LONGEST
) 1 << bits
) - 1;
11919 else if (bits
== sizeof (*value
) * 8)
11923 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11924 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11931 /* Read a constant value from an attribute. Either set *VALUE, or if
11932 the value does not fit in *VALUE, set *BYTES - either already
11933 allocated on the objfile obstack, or newly allocated on OBSTACK,
11934 or, set *BATON, if we translated the constant to a location
11938 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11939 const char *name
, struct obstack
*obstack
,
11940 struct dwarf2_cu
*cu
,
11941 long *value
, gdb_byte
**bytes
,
11942 struct dwarf2_locexpr_baton
**baton
)
11944 struct objfile
*objfile
= cu
->objfile
;
11945 struct comp_unit_head
*cu_header
= &cu
->header
;
11946 struct dwarf_block
*blk
;
11947 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
11948 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
11954 switch (attr
->form
)
11960 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
11961 dwarf2_const_value_length_mismatch_complaint (name
,
11962 cu_header
->addr_size
,
11963 TYPE_LENGTH (type
));
11964 /* Symbols of this form are reasonably rare, so we just
11965 piggyback on the existing location code rather than writing
11966 a new implementation of symbol_computed_ops. */
11967 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11968 sizeof (struct dwarf2_locexpr_baton
));
11969 (*baton
)->per_cu
= cu
->per_cu
;
11970 gdb_assert ((*baton
)->per_cu
);
11972 (*baton
)->size
= 2 + cu_header
->addr_size
;
11973 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11974 (*baton
)->data
= data
;
11976 data
[0] = DW_OP_addr
;
11977 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11978 byte_order
, DW_ADDR (attr
));
11979 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11982 case DW_FORM_string
:
11984 /* DW_STRING is already allocated on the objfile obstack, point
11986 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11988 case DW_FORM_block1
:
11989 case DW_FORM_block2
:
11990 case DW_FORM_block4
:
11991 case DW_FORM_block
:
11992 case DW_FORM_exprloc
:
11993 blk
= DW_BLOCK (attr
);
11994 if (TYPE_LENGTH (type
) != blk
->size
)
11995 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11996 TYPE_LENGTH (type
));
11997 *bytes
= blk
->data
;
12000 /* The DW_AT_const_value attributes are supposed to carry the
12001 symbol's value "represented as it would be on the target
12002 architecture." By the time we get here, it's already been
12003 converted to host endianness, so we just need to sign- or
12004 zero-extend it as appropriate. */
12005 case DW_FORM_data1
:
12006 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12007 obstack
, cu
, value
, 8);
12009 case DW_FORM_data2
:
12010 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12011 obstack
, cu
, value
, 16);
12013 case DW_FORM_data4
:
12014 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12015 obstack
, cu
, value
, 32);
12017 case DW_FORM_data8
:
12018 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12019 obstack
, cu
, value
, 64);
12022 case DW_FORM_sdata
:
12023 *value
= DW_SND (attr
);
12026 case DW_FORM_udata
:
12027 *value
= DW_UNSND (attr
);
12031 complaint (&symfile_complaints
,
12032 _("unsupported const value attribute form: '%s'"),
12033 dwarf_form_name (attr
->form
));
12040 /* Copy constant value from an attribute to a symbol. */
12043 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
12044 struct dwarf2_cu
*cu
)
12046 struct objfile
*objfile
= cu
->objfile
;
12047 struct comp_unit_head
*cu_header
= &cu
->header
;
12050 struct dwarf2_locexpr_baton
*baton
;
12052 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
12053 SYMBOL_PRINT_NAME (sym
),
12054 &objfile
->objfile_obstack
, cu
,
12055 &value
, &bytes
, &baton
);
12059 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
12060 SYMBOL_LOCATION_BATON (sym
) = baton
;
12061 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
12063 else if (bytes
!= NULL
)
12065 SYMBOL_VALUE_BYTES (sym
) = bytes
;
12066 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
12070 SYMBOL_VALUE (sym
) = value
;
12071 SYMBOL_CLASS (sym
) = LOC_CONST
;
12075 /* Return the type of the die in question using its DW_AT_type attribute. */
12077 static struct type
*
12078 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12080 struct attribute
*type_attr
;
12082 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
12085 /* A missing DW_AT_type represents a void type. */
12086 return objfile_type (cu
->objfile
)->builtin_void
;
12089 return lookup_die_type (die
, type_attr
, cu
);
12092 /* True iff CU's producer generates GNAT Ada auxiliary information
12093 that allows to find parallel types through that information instead
12094 of having to do expensive parallel lookups by type name. */
12097 need_gnat_info (struct dwarf2_cu
*cu
)
12099 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12100 of GNAT produces this auxiliary information, without any indication
12101 that it is produced. Part of enhancing the FSF version of GNAT
12102 to produce that information will be to put in place an indicator
12103 that we can use in order to determine whether the descriptive type
12104 info is available or not. One suggestion that has been made is
12105 to use a new attribute, attached to the CU die. For now, assume
12106 that the descriptive type info is not available. */
12110 /* Return the auxiliary type of the die in question using its
12111 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12112 attribute is not present. */
12114 static struct type
*
12115 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12117 struct attribute
*type_attr
;
12119 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
12123 return lookup_die_type (die
, type_attr
, cu
);
12126 /* If DIE has a descriptive_type attribute, then set the TYPE's
12127 descriptive type accordingly. */
12130 set_descriptive_type (struct type
*type
, struct die_info
*die
,
12131 struct dwarf2_cu
*cu
)
12133 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
12135 if (descriptive_type
)
12137 ALLOCATE_GNAT_AUX_TYPE (type
);
12138 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
12142 /* Return the containing type of the die in question using its
12143 DW_AT_containing_type attribute. */
12145 static struct type
*
12146 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12148 struct attribute
*type_attr
;
12150 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
12152 error (_("Dwarf Error: Problem turning containing type into gdb type "
12153 "[in module %s]"), cu
->objfile
->name
);
12155 return lookup_die_type (die
, type_attr
, cu
);
12158 /* Look up the type of DIE in CU using its type attribute ATTR.
12159 If there is no type substitute an error marker. */
12161 static struct type
*
12162 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
12163 struct dwarf2_cu
*cu
)
12165 struct objfile
*objfile
= cu
->objfile
;
12166 struct type
*this_type
;
12168 /* First see if we have it cached. */
12170 if (is_ref_attr (attr
))
12172 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
12174 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
12176 else if (attr
->form
== DW_FORM_ref_sig8
)
12178 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12179 struct dwarf2_cu
*sig_cu
;
12180 unsigned int offset
;
12182 /* sig_type will be NULL if the signatured type is missing from
12184 if (sig_type
== NULL
)
12185 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12186 "at 0x%x [in module %s]"),
12187 die
->offset
, objfile
->name
);
12189 gdb_assert (sig_type
->per_cu
.debug_types_section
);
12190 offset
= sig_type
->per_cu
.offset
+ sig_type
->type_offset
;
12191 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
12195 dump_die_for_error (die
);
12196 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12197 dwarf_attr_name (attr
->name
), objfile
->name
);
12200 /* If not cached we need to read it in. */
12202 if (this_type
== NULL
)
12204 struct die_info
*type_die
;
12205 struct dwarf2_cu
*type_cu
= cu
;
12207 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
12208 /* If the type is cached, we should have found it above. */
12209 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
12210 this_type
= read_type_die_1 (type_die
, type_cu
);
12213 /* If we still don't have a type use an error marker. */
12215 if (this_type
== NULL
)
12217 char *message
, *saved
;
12219 /* read_type_die already issued a complaint. */
12220 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12224 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
12225 message
, strlen (message
));
12228 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
12234 /* Return the type in DIE, CU.
12235 Returns NULL for invalid types.
12237 This first does a lookup in the appropriate type_hash table,
12238 and only reads the die in if necessary.
12240 NOTE: This can be called when reading in partial or full symbols. */
12242 static struct type
*
12243 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12245 struct type
*this_type
;
12247 this_type
= get_die_type (die
, cu
);
12251 return read_type_die_1 (die
, cu
);
12254 /* Read the type in DIE, CU.
12255 Returns NULL for invalid types. */
12257 static struct type
*
12258 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12260 struct type
*this_type
= NULL
;
12264 case DW_TAG_class_type
:
12265 case DW_TAG_interface_type
:
12266 case DW_TAG_structure_type
:
12267 case DW_TAG_union_type
:
12268 this_type
= read_structure_type (die
, cu
);
12270 case DW_TAG_enumeration_type
:
12271 this_type
= read_enumeration_type (die
, cu
);
12273 case DW_TAG_subprogram
:
12274 case DW_TAG_subroutine_type
:
12275 case DW_TAG_inlined_subroutine
:
12276 this_type
= read_subroutine_type (die
, cu
);
12278 case DW_TAG_array_type
:
12279 this_type
= read_array_type (die
, cu
);
12281 case DW_TAG_set_type
:
12282 this_type
= read_set_type (die
, cu
);
12284 case DW_TAG_pointer_type
:
12285 this_type
= read_tag_pointer_type (die
, cu
);
12287 case DW_TAG_ptr_to_member_type
:
12288 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12290 case DW_TAG_reference_type
:
12291 this_type
= read_tag_reference_type (die
, cu
);
12293 case DW_TAG_const_type
:
12294 this_type
= read_tag_const_type (die
, cu
);
12296 case DW_TAG_volatile_type
:
12297 this_type
= read_tag_volatile_type (die
, cu
);
12299 case DW_TAG_string_type
:
12300 this_type
= read_tag_string_type (die
, cu
);
12302 case DW_TAG_typedef
:
12303 this_type
= read_typedef (die
, cu
);
12305 case DW_TAG_subrange_type
:
12306 this_type
= read_subrange_type (die
, cu
);
12308 case DW_TAG_base_type
:
12309 this_type
= read_base_type (die
, cu
);
12311 case DW_TAG_unspecified_type
:
12312 this_type
= read_unspecified_type (die
, cu
);
12314 case DW_TAG_namespace
:
12315 this_type
= read_namespace_type (die
, cu
);
12317 case DW_TAG_module
:
12318 this_type
= read_module_type (die
, cu
);
12321 complaint (&symfile_complaints
,
12322 _("unexpected tag in read_type_die: '%s'"),
12323 dwarf_tag_name (die
->tag
));
12330 /* See if we can figure out if the class lives in a namespace. We do
12331 this by looking for a member function; its demangled name will
12332 contain namespace info, if there is any.
12333 Return the computed name or NULL.
12334 Space for the result is allocated on the objfile's obstack.
12335 This is the full-die version of guess_partial_die_structure_name.
12336 In this case we know DIE has no useful parent. */
12339 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12341 struct die_info
*spec_die
;
12342 struct dwarf2_cu
*spec_cu
;
12343 struct die_info
*child
;
12346 spec_die
= die_specification (die
, &spec_cu
);
12347 if (spec_die
!= NULL
)
12353 for (child
= die
->child
;
12355 child
= child
->sibling
)
12357 if (child
->tag
== DW_TAG_subprogram
)
12359 struct attribute
*attr
;
12361 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12363 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12367 = language_class_name_from_physname (cu
->language_defn
,
12371 if (actual_name
!= NULL
)
12373 char *die_name
= dwarf2_name (die
, cu
);
12375 if (die_name
!= NULL
12376 && strcmp (die_name
, actual_name
) != 0)
12378 /* Strip off the class name from the full name.
12379 We want the prefix. */
12380 int die_name_len
= strlen (die_name
);
12381 int actual_name_len
= strlen (actual_name
);
12383 /* Test for '::' as a sanity check. */
12384 if (actual_name_len
> die_name_len
+ 2
12385 && actual_name
[actual_name_len
12386 - die_name_len
- 1] == ':')
12388 obsavestring (actual_name
,
12389 actual_name_len
- die_name_len
- 2,
12390 &cu
->objfile
->objfile_obstack
);
12393 xfree (actual_name
);
12402 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12403 prefix part in such case. See
12404 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12407 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12409 struct attribute
*attr
;
12412 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
12413 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
12416 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12417 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
12420 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12422 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12423 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12426 /* dwarf2_name had to be already called. */
12427 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
12429 /* Strip the base name, keep any leading namespaces/classes. */
12430 base
= strrchr (DW_STRING (attr
), ':');
12431 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
12434 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
12435 &cu
->objfile
->objfile_obstack
);
12438 /* Return the name of the namespace/class that DIE is defined within,
12439 or "" if we can't tell. The caller should not xfree the result.
12441 For example, if we're within the method foo() in the following
12451 then determine_prefix on foo's die will return "N::C". */
12454 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12456 struct die_info
*parent
, *spec_die
;
12457 struct dwarf2_cu
*spec_cu
;
12458 struct type
*parent_type
;
12461 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12462 && cu
->language
!= language_fortran
)
12465 retval
= anonymous_struct_prefix (die
, cu
);
12469 /* We have to be careful in the presence of DW_AT_specification.
12470 For example, with GCC 3.4, given the code
12474 // Definition of N::foo.
12478 then we'll have a tree of DIEs like this:
12480 1: DW_TAG_compile_unit
12481 2: DW_TAG_namespace // N
12482 3: DW_TAG_subprogram // declaration of N::foo
12483 4: DW_TAG_subprogram // definition of N::foo
12484 DW_AT_specification // refers to die #3
12486 Thus, when processing die #4, we have to pretend that we're in
12487 the context of its DW_AT_specification, namely the contex of die
12490 spec_die
= die_specification (die
, &spec_cu
);
12491 if (spec_die
== NULL
)
12492 parent
= die
->parent
;
12495 parent
= spec_die
->parent
;
12499 if (parent
== NULL
)
12501 else if (parent
->building_fullname
)
12504 const char *parent_name
;
12506 /* It has been seen on RealView 2.2 built binaries,
12507 DW_TAG_template_type_param types actually _defined_ as
12508 children of the parent class:
12511 template class <class Enum> Class{};
12512 Class<enum E> class_e;
12514 1: DW_TAG_class_type (Class)
12515 2: DW_TAG_enumeration_type (E)
12516 3: DW_TAG_enumerator (enum1:0)
12517 3: DW_TAG_enumerator (enum2:1)
12519 2: DW_TAG_template_type_param
12520 DW_AT_type DW_FORM_ref_udata (E)
12522 Besides being broken debug info, it can put GDB into an
12523 infinite loop. Consider:
12525 When we're building the full name for Class<E>, we'll start
12526 at Class, and go look over its template type parameters,
12527 finding E. We'll then try to build the full name of E, and
12528 reach here. We're now trying to build the full name of E,
12529 and look over the parent DIE for containing scope. In the
12530 broken case, if we followed the parent DIE of E, we'd again
12531 find Class, and once again go look at its template type
12532 arguments, etc., etc. Simply don't consider such parent die
12533 as source-level parent of this die (it can't be, the language
12534 doesn't allow it), and break the loop here. */
12535 name
= dwarf2_name (die
, cu
);
12536 parent_name
= dwarf2_name (parent
, cu
);
12537 complaint (&symfile_complaints
,
12538 _("template param type '%s' defined within parent '%s'"),
12539 name
? name
: "<unknown>",
12540 parent_name
? parent_name
: "<unknown>");
12544 switch (parent
->tag
)
12546 case DW_TAG_namespace
:
12547 parent_type
= read_type_die (parent
, cu
);
12548 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12549 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12550 Work around this problem here. */
12551 if (cu
->language
== language_cplus
12552 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12554 /* We give a name to even anonymous namespaces. */
12555 return TYPE_TAG_NAME (parent_type
);
12556 case DW_TAG_class_type
:
12557 case DW_TAG_interface_type
:
12558 case DW_TAG_structure_type
:
12559 case DW_TAG_union_type
:
12560 case DW_TAG_module
:
12561 parent_type
= read_type_die (parent
, cu
);
12562 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12563 return TYPE_TAG_NAME (parent_type
);
12565 /* An anonymous structure is only allowed non-static data
12566 members; no typedefs, no member functions, et cetera.
12567 So it does not need a prefix. */
12569 case DW_TAG_compile_unit
:
12570 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12571 if (cu
->language
== language_cplus
12572 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12573 && die
->child
!= NULL
12574 && (die
->tag
== DW_TAG_class_type
12575 || die
->tag
== DW_TAG_structure_type
12576 || die
->tag
== DW_TAG_union_type
))
12578 char *name
= guess_full_die_structure_name (die
, cu
);
12584 return determine_prefix (parent
, cu
);
12588 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12589 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12590 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12591 an obconcat, otherwise allocate storage for the result. The CU argument is
12592 used to determine the language and hence, the appropriate separator. */
12594 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12597 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12598 int physname
, struct dwarf2_cu
*cu
)
12600 const char *lead
= "";
12603 if (suffix
== NULL
|| suffix
[0] == '\0'
12604 || prefix
== NULL
|| prefix
[0] == '\0')
12606 else if (cu
->language
== language_java
)
12608 else if (cu
->language
== language_fortran
&& physname
)
12610 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12611 DW_AT_MIPS_linkage_name is preferred and used instead. */
12619 if (prefix
== NULL
)
12621 if (suffix
== NULL
)
12627 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12629 strcpy (retval
, lead
);
12630 strcat (retval
, prefix
);
12631 strcat (retval
, sep
);
12632 strcat (retval
, suffix
);
12637 /* We have an obstack. */
12638 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12642 /* Return sibling of die, NULL if no sibling. */
12644 static struct die_info
*
12645 sibling_die (struct die_info
*die
)
12647 return die
->sibling
;
12650 /* Get name of a die, return NULL if not found. */
12653 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12654 struct obstack
*obstack
)
12656 if (name
&& cu
->language
== language_cplus
)
12658 char *canon_name
= cp_canonicalize_string (name
);
12660 if (canon_name
!= NULL
)
12662 if (strcmp (canon_name
, name
) != 0)
12663 name
= obsavestring (canon_name
, strlen (canon_name
),
12665 xfree (canon_name
);
12672 /* Get name of a die, return NULL if not found. */
12675 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12677 struct attribute
*attr
;
12679 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12680 if ((!attr
|| !DW_STRING (attr
))
12681 && die
->tag
!= DW_TAG_class_type
12682 && die
->tag
!= DW_TAG_interface_type
12683 && die
->tag
!= DW_TAG_structure_type
12684 && die
->tag
!= DW_TAG_union_type
)
12689 case DW_TAG_compile_unit
:
12690 /* Compilation units have a DW_AT_name that is a filename, not
12691 a source language identifier. */
12692 case DW_TAG_enumeration_type
:
12693 case DW_TAG_enumerator
:
12694 /* These tags always have simple identifiers already; no need
12695 to canonicalize them. */
12696 return DW_STRING (attr
);
12698 case DW_TAG_subprogram
:
12699 /* Java constructors will all be named "<init>", so return
12700 the class name when we see this special case. */
12701 if (cu
->language
== language_java
12702 && DW_STRING (attr
) != NULL
12703 && strcmp (DW_STRING (attr
), "<init>") == 0)
12705 struct dwarf2_cu
*spec_cu
= cu
;
12706 struct die_info
*spec_die
;
12708 /* GCJ will output '<init>' for Java constructor names.
12709 For this special case, return the name of the parent class. */
12711 /* GCJ may output suprogram DIEs with AT_specification set.
12712 If so, use the name of the specified DIE. */
12713 spec_die
= die_specification (die
, &spec_cu
);
12714 if (spec_die
!= NULL
)
12715 return dwarf2_name (spec_die
, spec_cu
);
12720 if (die
->tag
== DW_TAG_class_type
)
12721 return dwarf2_name (die
, cu
);
12723 while (die
->tag
!= DW_TAG_compile_unit
);
12727 case DW_TAG_class_type
:
12728 case DW_TAG_interface_type
:
12729 case DW_TAG_structure_type
:
12730 case DW_TAG_union_type
:
12731 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12732 structures or unions. These were of the form "._%d" in GCC 4.1,
12733 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12734 and GCC 4.4. We work around this problem by ignoring these. */
12735 if (attr
&& DW_STRING (attr
)
12736 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12737 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12740 /* GCC might emit a nameless typedef that has a linkage name. See
12741 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12742 if (!attr
|| DW_STRING (attr
) == NULL
)
12744 char *demangled
= NULL
;
12746 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12748 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12750 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12753 /* Avoid demangling DW_STRING (attr) the second time on a second
12754 call for the same DIE. */
12755 if (!DW_STRING_IS_CANONICAL (attr
))
12756 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12762 /* FIXME: we already did this for the partial symbol... */
12763 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
12764 &cu
->objfile
->objfile_obstack
);
12765 DW_STRING_IS_CANONICAL (attr
) = 1;
12768 /* Strip any leading namespaces/classes, keep only the base name.
12769 DW_AT_name for named DIEs does not contain the prefixes. */
12770 base
= strrchr (DW_STRING (attr
), ':');
12771 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
12774 return DW_STRING (attr
);
12783 if (!DW_STRING_IS_CANONICAL (attr
))
12786 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12787 &cu
->objfile
->objfile_obstack
);
12788 DW_STRING_IS_CANONICAL (attr
) = 1;
12790 return DW_STRING (attr
);
12793 /* Return the die that this die in an extension of, or NULL if there
12794 is none. *EXT_CU is the CU containing DIE on input, and the CU
12795 containing the return value on output. */
12797 static struct die_info
*
12798 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12800 struct attribute
*attr
;
12802 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12806 return follow_die_ref (die
, attr
, ext_cu
);
12809 /* Convert a DIE tag into its string name. */
12812 dwarf_tag_name (unsigned tag
)
12816 case DW_TAG_padding
:
12817 return "DW_TAG_padding";
12818 case DW_TAG_array_type
:
12819 return "DW_TAG_array_type";
12820 case DW_TAG_class_type
:
12821 return "DW_TAG_class_type";
12822 case DW_TAG_entry_point
:
12823 return "DW_TAG_entry_point";
12824 case DW_TAG_enumeration_type
:
12825 return "DW_TAG_enumeration_type";
12826 case DW_TAG_formal_parameter
:
12827 return "DW_TAG_formal_parameter";
12828 case DW_TAG_imported_declaration
:
12829 return "DW_TAG_imported_declaration";
12831 return "DW_TAG_label";
12832 case DW_TAG_lexical_block
:
12833 return "DW_TAG_lexical_block";
12834 case DW_TAG_member
:
12835 return "DW_TAG_member";
12836 case DW_TAG_pointer_type
:
12837 return "DW_TAG_pointer_type";
12838 case DW_TAG_reference_type
:
12839 return "DW_TAG_reference_type";
12840 case DW_TAG_compile_unit
:
12841 return "DW_TAG_compile_unit";
12842 case DW_TAG_string_type
:
12843 return "DW_TAG_string_type";
12844 case DW_TAG_structure_type
:
12845 return "DW_TAG_structure_type";
12846 case DW_TAG_subroutine_type
:
12847 return "DW_TAG_subroutine_type";
12848 case DW_TAG_typedef
:
12849 return "DW_TAG_typedef";
12850 case DW_TAG_union_type
:
12851 return "DW_TAG_union_type";
12852 case DW_TAG_unspecified_parameters
:
12853 return "DW_TAG_unspecified_parameters";
12854 case DW_TAG_variant
:
12855 return "DW_TAG_variant";
12856 case DW_TAG_common_block
:
12857 return "DW_TAG_common_block";
12858 case DW_TAG_common_inclusion
:
12859 return "DW_TAG_common_inclusion";
12860 case DW_TAG_inheritance
:
12861 return "DW_TAG_inheritance";
12862 case DW_TAG_inlined_subroutine
:
12863 return "DW_TAG_inlined_subroutine";
12864 case DW_TAG_module
:
12865 return "DW_TAG_module";
12866 case DW_TAG_ptr_to_member_type
:
12867 return "DW_TAG_ptr_to_member_type";
12868 case DW_TAG_set_type
:
12869 return "DW_TAG_set_type";
12870 case DW_TAG_subrange_type
:
12871 return "DW_TAG_subrange_type";
12872 case DW_TAG_with_stmt
:
12873 return "DW_TAG_with_stmt";
12874 case DW_TAG_access_declaration
:
12875 return "DW_TAG_access_declaration";
12876 case DW_TAG_base_type
:
12877 return "DW_TAG_base_type";
12878 case DW_TAG_catch_block
:
12879 return "DW_TAG_catch_block";
12880 case DW_TAG_const_type
:
12881 return "DW_TAG_const_type";
12882 case DW_TAG_constant
:
12883 return "DW_TAG_constant";
12884 case DW_TAG_enumerator
:
12885 return "DW_TAG_enumerator";
12886 case DW_TAG_file_type
:
12887 return "DW_TAG_file_type";
12888 case DW_TAG_friend
:
12889 return "DW_TAG_friend";
12890 case DW_TAG_namelist
:
12891 return "DW_TAG_namelist";
12892 case DW_TAG_namelist_item
:
12893 return "DW_TAG_namelist_item";
12894 case DW_TAG_packed_type
:
12895 return "DW_TAG_packed_type";
12896 case DW_TAG_subprogram
:
12897 return "DW_TAG_subprogram";
12898 case DW_TAG_template_type_param
:
12899 return "DW_TAG_template_type_param";
12900 case DW_TAG_template_value_param
:
12901 return "DW_TAG_template_value_param";
12902 case DW_TAG_thrown_type
:
12903 return "DW_TAG_thrown_type";
12904 case DW_TAG_try_block
:
12905 return "DW_TAG_try_block";
12906 case DW_TAG_variant_part
:
12907 return "DW_TAG_variant_part";
12908 case DW_TAG_variable
:
12909 return "DW_TAG_variable";
12910 case DW_TAG_volatile_type
:
12911 return "DW_TAG_volatile_type";
12912 case DW_TAG_dwarf_procedure
:
12913 return "DW_TAG_dwarf_procedure";
12914 case DW_TAG_restrict_type
:
12915 return "DW_TAG_restrict_type";
12916 case DW_TAG_interface_type
:
12917 return "DW_TAG_interface_type";
12918 case DW_TAG_namespace
:
12919 return "DW_TAG_namespace";
12920 case DW_TAG_imported_module
:
12921 return "DW_TAG_imported_module";
12922 case DW_TAG_unspecified_type
:
12923 return "DW_TAG_unspecified_type";
12924 case DW_TAG_partial_unit
:
12925 return "DW_TAG_partial_unit";
12926 case DW_TAG_imported_unit
:
12927 return "DW_TAG_imported_unit";
12928 case DW_TAG_condition
:
12929 return "DW_TAG_condition";
12930 case DW_TAG_shared_type
:
12931 return "DW_TAG_shared_type";
12932 case DW_TAG_type_unit
:
12933 return "DW_TAG_type_unit";
12934 case DW_TAG_MIPS_loop
:
12935 return "DW_TAG_MIPS_loop";
12936 case DW_TAG_HP_array_descriptor
:
12937 return "DW_TAG_HP_array_descriptor";
12938 case DW_TAG_format_label
:
12939 return "DW_TAG_format_label";
12940 case DW_TAG_function_template
:
12941 return "DW_TAG_function_template";
12942 case DW_TAG_class_template
:
12943 return "DW_TAG_class_template";
12944 case DW_TAG_GNU_BINCL
:
12945 return "DW_TAG_GNU_BINCL";
12946 case DW_TAG_GNU_EINCL
:
12947 return "DW_TAG_GNU_EINCL";
12948 case DW_TAG_upc_shared_type
:
12949 return "DW_TAG_upc_shared_type";
12950 case DW_TAG_upc_strict_type
:
12951 return "DW_TAG_upc_strict_type";
12952 case DW_TAG_upc_relaxed_type
:
12953 return "DW_TAG_upc_relaxed_type";
12954 case DW_TAG_PGI_kanji_type
:
12955 return "DW_TAG_PGI_kanji_type";
12956 case DW_TAG_PGI_interface_block
:
12957 return "DW_TAG_PGI_interface_block";
12958 case DW_TAG_GNU_call_site
:
12959 return "DW_TAG_GNU_call_site";
12961 return "DW_TAG_<unknown>";
12965 /* Convert a DWARF attribute code into its string name. */
12968 dwarf_attr_name (unsigned attr
)
12972 case DW_AT_sibling
:
12973 return "DW_AT_sibling";
12974 case DW_AT_location
:
12975 return "DW_AT_location";
12977 return "DW_AT_name";
12978 case DW_AT_ordering
:
12979 return "DW_AT_ordering";
12980 case DW_AT_subscr_data
:
12981 return "DW_AT_subscr_data";
12982 case DW_AT_byte_size
:
12983 return "DW_AT_byte_size";
12984 case DW_AT_bit_offset
:
12985 return "DW_AT_bit_offset";
12986 case DW_AT_bit_size
:
12987 return "DW_AT_bit_size";
12988 case DW_AT_element_list
:
12989 return "DW_AT_element_list";
12990 case DW_AT_stmt_list
:
12991 return "DW_AT_stmt_list";
12993 return "DW_AT_low_pc";
12994 case DW_AT_high_pc
:
12995 return "DW_AT_high_pc";
12996 case DW_AT_language
:
12997 return "DW_AT_language";
12999 return "DW_AT_member";
13001 return "DW_AT_discr";
13002 case DW_AT_discr_value
:
13003 return "DW_AT_discr_value";
13004 case DW_AT_visibility
:
13005 return "DW_AT_visibility";
13007 return "DW_AT_import";
13008 case DW_AT_string_length
:
13009 return "DW_AT_string_length";
13010 case DW_AT_common_reference
:
13011 return "DW_AT_common_reference";
13012 case DW_AT_comp_dir
:
13013 return "DW_AT_comp_dir";
13014 case DW_AT_const_value
:
13015 return "DW_AT_const_value";
13016 case DW_AT_containing_type
:
13017 return "DW_AT_containing_type";
13018 case DW_AT_default_value
:
13019 return "DW_AT_default_value";
13021 return "DW_AT_inline";
13022 case DW_AT_is_optional
:
13023 return "DW_AT_is_optional";
13024 case DW_AT_lower_bound
:
13025 return "DW_AT_lower_bound";
13026 case DW_AT_producer
:
13027 return "DW_AT_producer";
13028 case DW_AT_prototyped
:
13029 return "DW_AT_prototyped";
13030 case DW_AT_return_addr
:
13031 return "DW_AT_return_addr";
13032 case DW_AT_start_scope
:
13033 return "DW_AT_start_scope";
13034 case DW_AT_bit_stride
:
13035 return "DW_AT_bit_stride";
13036 case DW_AT_upper_bound
:
13037 return "DW_AT_upper_bound";
13038 case DW_AT_abstract_origin
:
13039 return "DW_AT_abstract_origin";
13040 case DW_AT_accessibility
:
13041 return "DW_AT_accessibility";
13042 case DW_AT_address_class
:
13043 return "DW_AT_address_class";
13044 case DW_AT_artificial
:
13045 return "DW_AT_artificial";
13046 case DW_AT_base_types
:
13047 return "DW_AT_base_types";
13048 case DW_AT_calling_convention
:
13049 return "DW_AT_calling_convention";
13051 return "DW_AT_count";
13052 case DW_AT_data_member_location
:
13053 return "DW_AT_data_member_location";
13054 case DW_AT_decl_column
:
13055 return "DW_AT_decl_column";
13056 case DW_AT_decl_file
:
13057 return "DW_AT_decl_file";
13058 case DW_AT_decl_line
:
13059 return "DW_AT_decl_line";
13060 case DW_AT_declaration
:
13061 return "DW_AT_declaration";
13062 case DW_AT_discr_list
:
13063 return "DW_AT_discr_list";
13064 case DW_AT_encoding
:
13065 return "DW_AT_encoding";
13066 case DW_AT_external
:
13067 return "DW_AT_external";
13068 case DW_AT_frame_base
:
13069 return "DW_AT_frame_base";
13071 return "DW_AT_friend";
13072 case DW_AT_identifier_case
:
13073 return "DW_AT_identifier_case";
13074 case DW_AT_macro_info
:
13075 return "DW_AT_macro_info";
13076 case DW_AT_namelist_items
:
13077 return "DW_AT_namelist_items";
13078 case DW_AT_priority
:
13079 return "DW_AT_priority";
13080 case DW_AT_segment
:
13081 return "DW_AT_segment";
13082 case DW_AT_specification
:
13083 return "DW_AT_specification";
13084 case DW_AT_static_link
:
13085 return "DW_AT_static_link";
13087 return "DW_AT_type";
13088 case DW_AT_use_location
:
13089 return "DW_AT_use_location";
13090 case DW_AT_variable_parameter
:
13091 return "DW_AT_variable_parameter";
13092 case DW_AT_virtuality
:
13093 return "DW_AT_virtuality";
13094 case DW_AT_vtable_elem_location
:
13095 return "DW_AT_vtable_elem_location";
13096 /* DWARF 3 values. */
13097 case DW_AT_allocated
:
13098 return "DW_AT_allocated";
13099 case DW_AT_associated
:
13100 return "DW_AT_associated";
13101 case DW_AT_data_location
:
13102 return "DW_AT_data_location";
13103 case DW_AT_byte_stride
:
13104 return "DW_AT_byte_stride";
13105 case DW_AT_entry_pc
:
13106 return "DW_AT_entry_pc";
13107 case DW_AT_use_UTF8
:
13108 return "DW_AT_use_UTF8";
13109 case DW_AT_extension
:
13110 return "DW_AT_extension";
13112 return "DW_AT_ranges";
13113 case DW_AT_trampoline
:
13114 return "DW_AT_trampoline";
13115 case DW_AT_call_column
:
13116 return "DW_AT_call_column";
13117 case DW_AT_call_file
:
13118 return "DW_AT_call_file";
13119 case DW_AT_call_line
:
13120 return "DW_AT_call_line";
13121 case DW_AT_description
:
13122 return "DW_AT_description";
13123 case DW_AT_binary_scale
:
13124 return "DW_AT_binary_scale";
13125 case DW_AT_decimal_scale
:
13126 return "DW_AT_decimal_scale";
13128 return "DW_AT_small";
13129 case DW_AT_decimal_sign
:
13130 return "DW_AT_decimal_sign";
13131 case DW_AT_digit_count
:
13132 return "DW_AT_digit_count";
13133 case DW_AT_picture_string
:
13134 return "DW_AT_picture_string";
13135 case DW_AT_mutable
:
13136 return "DW_AT_mutable";
13137 case DW_AT_threads_scaled
:
13138 return "DW_AT_threads_scaled";
13139 case DW_AT_explicit
:
13140 return "DW_AT_explicit";
13141 case DW_AT_object_pointer
:
13142 return "DW_AT_object_pointer";
13143 case DW_AT_endianity
:
13144 return "DW_AT_endianity";
13145 case DW_AT_elemental
:
13146 return "DW_AT_elemental";
13148 return "DW_AT_pure";
13149 case DW_AT_recursive
:
13150 return "DW_AT_recursive";
13151 /* DWARF 4 values. */
13152 case DW_AT_signature
:
13153 return "DW_AT_signature";
13154 case DW_AT_linkage_name
:
13155 return "DW_AT_linkage_name";
13156 /* SGI/MIPS extensions. */
13157 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13158 case DW_AT_MIPS_fde
:
13159 return "DW_AT_MIPS_fde";
13161 case DW_AT_MIPS_loop_begin
:
13162 return "DW_AT_MIPS_loop_begin";
13163 case DW_AT_MIPS_tail_loop_begin
:
13164 return "DW_AT_MIPS_tail_loop_begin";
13165 case DW_AT_MIPS_epilog_begin
:
13166 return "DW_AT_MIPS_epilog_begin";
13167 case DW_AT_MIPS_loop_unroll_factor
:
13168 return "DW_AT_MIPS_loop_unroll_factor";
13169 case DW_AT_MIPS_software_pipeline_depth
:
13170 return "DW_AT_MIPS_software_pipeline_depth";
13171 case DW_AT_MIPS_linkage_name
:
13172 return "DW_AT_MIPS_linkage_name";
13173 case DW_AT_MIPS_stride
:
13174 return "DW_AT_MIPS_stride";
13175 case DW_AT_MIPS_abstract_name
:
13176 return "DW_AT_MIPS_abstract_name";
13177 case DW_AT_MIPS_clone_origin
:
13178 return "DW_AT_MIPS_clone_origin";
13179 case DW_AT_MIPS_has_inlines
:
13180 return "DW_AT_MIPS_has_inlines";
13181 /* HP extensions. */
13182 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13183 case DW_AT_HP_block_index
:
13184 return "DW_AT_HP_block_index";
13186 case DW_AT_HP_unmodifiable
:
13187 return "DW_AT_HP_unmodifiable";
13188 case DW_AT_HP_actuals_stmt_list
:
13189 return "DW_AT_HP_actuals_stmt_list";
13190 case DW_AT_HP_proc_per_section
:
13191 return "DW_AT_HP_proc_per_section";
13192 case DW_AT_HP_raw_data_ptr
:
13193 return "DW_AT_HP_raw_data_ptr";
13194 case DW_AT_HP_pass_by_reference
:
13195 return "DW_AT_HP_pass_by_reference";
13196 case DW_AT_HP_opt_level
:
13197 return "DW_AT_HP_opt_level";
13198 case DW_AT_HP_prof_version_id
:
13199 return "DW_AT_HP_prof_version_id";
13200 case DW_AT_HP_opt_flags
:
13201 return "DW_AT_HP_opt_flags";
13202 case DW_AT_HP_cold_region_low_pc
:
13203 return "DW_AT_HP_cold_region_low_pc";
13204 case DW_AT_HP_cold_region_high_pc
:
13205 return "DW_AT_HP_cold_region_high_pc";
13206 case DW_AT_HP_all_variables_modifiable
:
13207 return "DW_AT_HP_all_variables_modifiable";
13208 case DW_AT_HP_linkage_name
:
13209 return "DW_AT_HP_linkage_name";
13210 case DW_AT_HP_prof_flags
:
13211 return "DW_AT_HP_prof_flags";
13212 /* GNU extensions. */
13213 case DW_AT_sf_names
:
13214 return "DW_AT_sf_names";
13215 case DW_AT_src_info
:
13216 return "DW_AT_src_info";
13217 case DW_AT_mac_info
:
13218 return "DW_AT_mac_info";
13219 case DW_AT_src_coords
:
13220 return "DW_AT_src_coords";
13221 case DW_AT_body_begin
:
13222 return "DW_AT_body_begin";
13223 case DW_AT_body_end
:
13224 return "DW_AT_body_end";
13225 case DW_AT_GNU_vector
:
13226 return "DW_AT_GNU_vector";
13227 case DW_AT_GNU_odr_signature
:
13228 return "DW_AT_GNU_odr_signature";
13229 /* VMS extensions. */
13230 case DW_AT_VMS_rtnbeg_pd_address
:
13231 return "DW_AT_VMS_rtnbeg_pd_address";
13232 /* UPC extension. */
13233 case DW_AT_upc_threads_scaled
:
13234 return "DW_AT_upc_threads_scaled";
13235 /* PGI (STMicroelectronics) extensions. */
13236 case DW_AT_PGI_lbase
:
13237 return "DW_AT_PGI_lbase";
13238 case DW_AT_PGI_soffset
:
13239 return "DW_AT_PGI_soffset";
13240 case DW_AT_PGI_lstride
:
13241 return "DW_AT_PGI_lstride";
13243 return "DW_AT_<unknown>";
13247 /* Convert a DWARF value form code into its string name. */
13250 dwarf_form_name (unsigned form
)
13255 return "DW_FORM_addr";
13256 case DW_FORM_block2
:
13257 return "DW_FORM_block2";
13258 case DW_FORM_block4
:
13259 return "DW_FORM_block4";
13260 case DW_FORM_data2
:
13261 return "DW_FORM_data2";
13262 case DW_FORM_data4
:
13263 return "DW_FORM_data4";
13264 case DW_FORM_data8
:
13265 return "DW_FORM_data8";
13266 case DW_FORM_string
:
13267 return "DW_FORM_string";
13268 case DW_FORM_block
:
13269 return "DW_FORM_block";
13270 case DW_FORM_block1
:
13271 return "DW_FORM_block1";
13272 case DW_FORM_data1
:
13273 return "DW_FORM_data1";
13275 return "DW_FORM_flag";
13276 case DW_FORM_sdata
:
13277 return "DW_FORM_sdata";
13279 return "DW_FORM_strp";
13280 case DW_FORM_udata
:
13281 return "DW_FORM_udata";
13282 case DW_FORM_ref_addr
:
13283 return "DW_FORM_ref_addr";
13285 return "DW_FORM_ref1";
13287 return "DW_FORM_ref2";
13289 return "DW_FORM_ref4";
13291 return "DW_FORM_ref8";
13292 case DW_FORM_ref_udata
:
13293 return "DW_FORM_ref_udata";
13294 case DW_FORM_indirect
:
13295 return "DW_FORM_indirect";
13296 case DW_FORM_sec_offset
:
13297 return "DW_FORM_sec_offset";
13298 case DW_FORM_exprloc
:
13299 return "DW_FORM_exprloc";
13300 case DW_FORM_flag_present
:
13301 return "DW_FORM_flag_present";
13302 case DW_FORM_ref_sig8
:
13303 return "DW_FORM_ref_sig8";
13305 return "DW_FORM_<unknown>";
13309 /* Convert a DWARF stack opcode into its string name. */
13312 dwarf_stack_op_name (unsigned op
)
13317 return "DW_OP_addr";
13319 return "DW_OP_deref";
13320 case DW_OP_const1u
:
13321 return "DW_OP_const1u";
13322 case DW_OP_const1s
:
13323 return "DW_OP_const1s";
13324 case DW_OP_const2u
:
13325 return "DW_OP_const2u";
13326 case DW_OP_const2s
:
13327 return "DW_OP_const2s";
13328 case DW_OP_const4u
:
13329 return "DW_OP_const4u";
13330 case DW_OP_const4s
:
13331 return "DW_OP_const4s";
13332 case DW_OP_const8u
:
13333 return "DW_OP_const8u";
13334 case DW_OP_const8s
:
13335 return "DW_OP_const8s";
13337 return "DW_OP_constu";
13339 return "DW_OP_consts";
13341 return "DW_OP_dup";
13343 return "DW_OP_drop";
13345 return "DW_OP_over";
13347 return "DW_OP_pick";
13349 return "DW_OP_swap";
13351 return "DW_OP_rot";
13353 return "DW_OP_xderef";
13355 return "DW_OP_abs";
13357 return "DW_OP_and";
13359 return "DW_OP_div";
13361 return "DW_OP_minus";
13363 return "DW_OP_mod";
13365 return "DW_OP_mul";
13367 return "DW_OP_neg";
13369 return "DW_OP_not";
13373 return "DW_OP_plus";
13374 case DW_OP_plus_uconst
:
13375 return "DW_OP_plus_uconst";
13377 return "DW_OP_shl";
13379 return "DW_OP_shr";
13381 return "DW_OP_shra";
13383 return "DW_OP_xor";
13385 return "DW_OP_bra";
13399 return "DW_OP_skip";
13401 return "DW_OP_lit0";
13403 return "DW_OP_lit1";
13405 return "DW_OP_lit2";
13407 return "DW_OP_lit3";
13409 return "DW_OP_lit4";
13411 return "DW_OP_lit5";
13413 return "DW_OP_lit6";
13415 return "DW_OP_lit7";
13417 return "DW_OP_lit8";
13419 return "DW_OP_lit9";
13421 return "DW_OP_lit10";
13423 return "DW_OP_lit11";
13425 return "DW_OP_lit12";
13427 return "DW_OP_lit13";
13429 return "DW_OP_lit14";
13431 return "DW_OP_lit15";
13433 return "DW_OP_lit16";
13435 return "DW_OP_lit17";
13437 return "DW_OP_lit18";
13439 return "DW_OP_lit19";
13441 return "DW_OP_lit20";
13443 return "DW_OP_lit21";
13445 return "DW_OP_lit22";
13447 return "DW_OP_lit23";
13449 return "DW_OP_lit24";
13451 return "DW_OP_lit25";
13453 return "DW_OP_lit26";
13455 return "DW_OP_lit27";
13457 return "DW_OP_lit28";
13459 return "DW_OP_lit29";
13461 return "DW_OP_lit30";
13463 return "DW_OP_lit31";
13465 return "DW_OP_reg0";
13467 return "DW_OP_reg1";
13469 return "DW_OP_reg2";
13471 return "DW_OP_reg3";
13473 return "DW_OP_reg4";
13475 return "DW_OP_reg5";
13477 return "DW_OP_reg6";
13479 return "DW_OP_reg7";
13481 return "DW_OP_reg8";
13483 return "DW_OP_reg9";
13485 return "DW_OP_reg10";
13487 return "DW_OP_reg11";
13489 return "DW_OP_reg12";
13491 return "DW_OP_reg13";
13493 return "DW_OP_reg14";
13495 return "DW_OP_reg15";
13497 return "DW_OP_reg16";
13499 return "DW_OP_reg17";
13501 return "DW_OP_reg18";
13503 return "DW_OP_reg19";
13505 return "DW_OP_reg20";
13507 return "DW_OP_reg21";
13509 return "DW_OP_reg22";
13511 return "DW_OP_reg23";
13513 return "DW_OP_reg24";
13515 return "DW_OP_reg25";
13517 return "DW_OP_reg26";
13519 return "DW_OP_reg27";
13521 return "DW_OP_reg28";
13523 return "DW_OP_reg29";
13525 return "DW_OP_reg30";
13527 return "DW_OP_reg31";
13529 return "DW_OP_breg0";
13531 return "DW_OP_breg1";
13533 return "DW_OP_breg2";
13535 return "DW_OP_breg3";
13537 return "DW_OP_breg4";
13539 return "DW_OP_breg5";
13541 return "DW_OP_breg6";
13543 return "DW_OP_breg7";
13545 return "DW_OP_breg8";
13547 return "DW_OP_breg9";
13549 return "DW_OP_breg10";
13551 return "DW_OP_breg11";
13553 return "DW_OP_breg12";
13555 return "DW_OP_breg13";
13557 return "DW_OP_breg14";
13559 return "DW_OP_breg15";
13561 return "DW_OP_breg16";
13563 return "DW_OP_breg17";
13565 return "DW_OP_breg18";
13567 return "DW_OP_breg19";
13569 return "DW_OP_breg20";
13571 return "DW_OP_breg21";
13573 return "DW_OP_breg22";
13575 return "DW_OP_breg23";
13577 return "DW_OP_breg24";
13579 return "DW_OP_breg25";
13581 return "DW_OP_breg26";
13583 return "DW_OP_breg27";
13585 return "DW_OP_breg28";
13587 return "DW_OP_breg29";
13589 return "DW_OP_breg30";
13591 return "DW_OP_breg31";
13593 return "DW_OP_regx";
13595 return "DW_OP_fbreg";
13597 return "DW_OP_bregx";
13599 return "DW_OP_piece";
13600 case DW_OP_deref_size
:
13601 return "DW_OP_deref_size";
13602 case DW_OP_xderef_size
:
13603 return "DW_OP_xderef_size";
13605 return "DW_OP_nop";
13606 /* DWARF 3 extensions. */
13607 case DW_OP_push_object_address
:
13608 return "DW_OP_push_object_address";
13610 return "DW_OP_call2";
13612 return "DW_OP_call4";
13613 case DW_OP_call_ref
:
13614 return "DW_OP_call_ref";
13615 case DW_OP_form_tls_address
:
13616 return "DW_OP_form_tls_address";
13617 case DW_OP_call_frame_cfa
:
13618 return "DW_OP_call_frame_cfa";
13619 case DW_OP_bit_piece
:
13620 return "DW_OP_bit_piece";
13621 /* DWARF 4 extensions. */
13622 case DW_OP_implicit_value
:
13623 return "DW_OP_implicit_value";
13624 case DW_OP_stack_value
:
13625 return "DW_OP_stack_value";
13626 /* GNU extensions. */
13627 case DW_OP_GNU_push_tls_address
:
13628 return "DW_OP_GNU_push_tls_address";
13629 case DW_OP_GNU_uninit
:
13630 return "DW_OP_GNU_uninit";
13631 case DW_OP_GNU_implicit_pointer
:
13632 return "DW_OP_GNU_implicit_pointer";
13633 case DW_OP_GNU_entry_value
:
13634 return "DW_OP_GNU_entry_value";
13635 case DW_OP_GNU_const_type
:
13636 return "DW_OP_GNU_const_type";
13637 case DW_OP_GNU_regval_type
:
13638 return "DW_OP_GNU_regval_type";
13639 case DW_OP_GNU_deref_type
:
13640 return "DW_OP_GNU_deref_type";
13641 case DW_OP_GNU_convert
:
13642 return "DW_OP_GNU_convert";
13643 case DW_OP_GNU_reinterpret
:
13644 return "DW_OP_GNU_reinterpret";
13651 dwarf_bool_name (unsigned mybool
)
13659 /* Convert a DWARF type code into its string name. */
13662 dwarf_type_encoding_name (unsigned enc
)
13667 return "DW_ATE_void";
13668 case DW_ATE_address
:
13669 return "DW_ATE_address";
13670 case DW_ATE_boolean
:
13671 return "DW_ATE_boolean";
13672 case DW_ATE_complex_float
:
13673 return "DW_ATE_complex_float";
13675 return "DW_ATE_float";
13676 case DW_ATE_signed
:
13677 return "DW_ATE_signed";
13678 case DW_ATE_signed_char
:
13679 return "DW_ATE_signed_char";
13680 case DW_ATE_unsigned
:
13681 return "DW_ATE_unsigned";
13682 case DW_ATE_unsigned_char
:
13683 return "DW_ATE_unsigned_char";
13685 case DW_ATE_imaginary_float
:
13686 return "DW_ATE_imaginary_float";
13687 case DW_ATE_packed_decimal
:
13688 return "DW_ATE_packed_decimal";
13689 case DW_ATE_numeric_string
:
13690 return "DW_ATE_numeric_string";
13691 case DW_ATE_edited
:
13692 return "DW_ATE_edited";
13693 case DW_ATE_signed_fixed
:
13694 return "DW_ATE_signed_fixed";
13695 case DW_ATE_unsigned_fixed
:
13696 return "DW_ATE_unsigned_fixed";
13697 case DW_ATE_decimal_float
:
13698 return "DW_ATE_decimal_float";
13701 return "DW_ATE_UTF";
13702 /* HP extensions. */
13703 case DW_ATE_HP_float80
:
13704 return "DW_ATE_HP_float80";
13705 case DW_ATE_HP_complex_float80
:
13706 return "DW_ATE_HP_complex_float80";
13707 case DW_ATE_HP_float128
:
13708 return "DW_ATE_HP_float128";
13709 case DW_ATE_HP_complex_float128
:
13710 return "DW_ATE_HP_complex_float128";
13711 case DW_ATE_HP_floathpintel
:
13712 return "DW_ATE_HP_floathpintel";
13713 case DW_ATE_HP_imaginary_float80
:
13714 return "DW_ATE_HP_imaginary_float80";
13715 case DW_ATE_HP_imaginary_float128
:
13716 return "DW_ATE_HP_imaginary_float128";
13718 return "DW_ATE_<unknown>";
13722 /* Convert a DWARF call frame info operation to its string name. */
13726 dwarf_cfi_name (unsigned cfi_opc
)
13730 case DW_CFA_advance_loc
:
13731 return "DW_CFA_advance_loc";
13732 case DW_CFA_offset
:
13733 return "DW_CFA_offset";
13734 case DW_CFA_restore
:
13735 return "DW_CFA_restore";
13737 return "DW_CFA_nop";
13738 case DW_CFA_set_loc
:
13739 return "DW_CFA_set_loc";
13740 case DW_CFA_advance_loc1
:
13741 return "DW_CFA_advance_loc1";
13742 case DW_CFA_advance_loc2
:
13743 return "DW_CFA_advance_loc2";
13744 case DW_CFA_advance_loc4
:
13745 return "DW_CFA_advance_loc4";
13746 case DW_CFA_offset_extended
:
13747 return "DW_CFA_offset_extended";
13748 case DW_CFA_restore_extended
:
13749 return "DW_CFA_restore_extended";
13750 case DW_CFA_undefined
:
13751 return "DW_CFA_undefined";
13752 case DW_CFA_same_value
:
13753 return "DW_CFA_same_value";
13754 case DW_CFA_register
:
13755 return "DW_CFA_register";
13756 case DW_CFA_remember_state
:
13757 return "DW_CFA_remember_state";
13758 case DW_CFA_restore_state
:
13759 return "DW_CFA_restore_state";
13760 case DW_CFA_def_cfa
:
13761 return "DW_CFA_def_cfa";
13762 case DW_CFA_def_cfa_register
:
13763 return "DW_CFA_def_cfa_register";
13764 case DW_CFA_def_cfa_offset
:
13765 return "DW_CFA_def_cfa_offset";
13767 case DW_CFA_def_cfa_expression
:
13768 return "DW_CFA_def_cfa_expression";
13769 case DW_CFA_expression
:
13770 return "DW_CFA_expression";
13771 case DW_CFA_offset_extended_sf
:
13772 return "DW_CFA_offset_extended_sf";
13773 case DW_CFA_def_cfa_sf
:
13774 return "DW_CFA_def_cfa_sf";
13775 case DW_CFA_def_cfa_offset_sf
:
13776 return "DW_CFA_def_cfa_offset_sf";
13777 case DW_CFA_val_offset
:
13778 return "DW_CFA_val_offset";
13779 case DW_CFA_val_offset_sf
:
13780 return "DW_CFA_val_offset_sf";
13781 case DW_CFA_val_expression
:
13782 return "DW_CFA_val_expression";
13783 /* SGI/MIPS specific. */
13784 case DW_CFA_MIPS_advance_loc8
:
13785 return "DW_CFA_MIPS_advance_loc8";
13786 /* GNU extensions. */
13787 case DW_CFA_GNU_window_save
:
13788 return "DW_CFA_GNU_window_save";
13789 case DW_CFA_GNU_args_size
:
13790 return "DW_CFA_GNU_args_size";
13791 case DW_CFA_GNU_negative_offset_extended
:
13792 return "DW_CFA_GNU_negative_offset_extended";
13794 return "DW_CFA_<unknown>";
13800 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13804 print_spaces (indent
, f
);
13805 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13806 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13808 if (die
->parent
!= NULL
)
13810 print_spaces (indent
, f
);
13811 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13812 die
->parent
->offset
);
13815 print_spaces (indent
, f
);
13816 fprintf_unfiltered (f
, " has children: %s\n",
13817 dwarf_bool_name (die
->child
!= NULL
));
13819 print_spaces (indent
, f
);
13820 fprintf_unfiltered (f
, " attributes:\n");
13822 for (i
= 0; i
< die
->num_attrs
; ++i
)
13824 print_spaces (indent
, f
);
13825 fprintf_unfiltered (f
, " %s (%s) ",
13826 dwarf_attr_name (die
->attrs
[i
].name
),
13827 dwarf_form_name (die
->attrs
[i
].form
));
13829 switch (die
->attrs
[i
].form
)
13831 case DW_FORM_ref_addr
:
13833 fprintf_unfiltered (f
, "address: ");
13834 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13836 case DW_FORM_block2
:
13837 case DW_FORM_block4
:
13838 case DW_FORM_block
:
13839 case DW_FORM_block1
:
13840 fprintf_unfiltered (f
, "block: size %d",
13841 DW_BLOCK (&die
->attrs
[i
])->size
);
13843 case DW_FORM_exprloc
:
13844 fprintf_unfiltered (f
, "expression: size %u",
13845 DW_BLOCK (&die
->attrs
[i
])->size
);
13850 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13851 (long) (DW_ADDR (&die
->attrs
[i
])));
13853 case DW_FORM_data1
:
13854 case DW_FORM_data2
:
13855 case DW_FORM_data4
:
13856 case DW_FORM_data8
:
13857 case DW_FORM_udata
:
13858 case DW_FORM_sdata
:
13859 fprintf_unfiltered (f
, "constant: %s",
13860 pulongest (DW_UNSND (&die
->attrs
[i
])));
13862 case DW_FORM_sec_offset
:
13863 fprintf_unfiltered (f
, "section offset: %s",
13864 pulongest (DW_UNSND (&die
->attrs
[i
])));
13866 case DW_FORM_ref_sig8
:
13867 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13868 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13869 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
);
13871 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13873 case DW_FORM_string
:
13875 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13876 DW_STRING (&die
->attrs
[i
])
13877 ? DW_STRING (&die
->attrs
[i
]) : "",
13878 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13881 if (DW_UNSND (&die
->attrs
[i
]))
13882 fprintf_unfiltered (f
, "flag: TRUE");
13884 fprintf_unfiltered (f
, "flag: FALSE");
13886 case DW_FORM_flag_present
:
13887 fprintf_unfiltered (f
, "flag: TRUE");
13889 case DW_FORM_indirect
:
13890 /* The reader will have reduced the indirect form to
13891 the "base form" so this form should not occur. */
13892 fprintf_unfiltered (f
,
13893 "unexpected attribute form: DW_FORM_indirect");
13896 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13897 die
->attrs
[i
].form
);
13900 fprintf_unfiltered (f
, "\n");
13905 dump_die_for_error (struct die_info
*die
)
13907 dump_die_shallow (gdb_stderr
, 0, die
);
13911 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13913 int indent
= level
* 4;
13915 gdb_assert (die
!= NULL
);
13917 if (level
>= max_level
)
13920 dump_die_shallow (f
, indent
, die
);
13922 if (die
->child
!= NULL
)
13924 print_spaces (indent
, f
);
13925 fprintf_unfiltered (f
, " Children:");
13926 if (level
+ 1 < max_level
)
13928 fprintf_unfiltered (f
, "\n");
13929 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13933 fprintf_unfiltered (f
,
13934 " [not printed, max nesting level reached]\n");
13938 if (die
->sibling
!= NULL
&& level
> 0)
13940 dump_die_1 (f
, level
, max_level
, die
->sibling
);
13944 /* This is called from the pdie macro in gdbinit.in.
13945 It's not static so gcc will keep a copy callable from gdb. */
13948 dump_die (struct die_info
*die
, int max_level
)
13950 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
13954 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
13958 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
13964 is_ref_attr (struct attribute
*attr
)
13966 switch (attr
->form
)
13968 case DW_FORM_ref_addr
:
13973 case DW_FORM_ref_udata
:
13980 static unsigned int
13981 dwarf2_get_ref_die_offset (struct attribute
*attr
)
13983 if (is_ref_attr (attr
))
13984 return DW_ADDR (attr
);
13986 complaint (&symfile_complaints
,
13987 _("unsupported die ref attribute form: '%s'"),
13988 dwarf_form_name (attr
->form
));
13992 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13993 * the value held by the attribute is not constant. */
13996 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
13998 if (attr
->form
== DW_FORM_sdata
)
13999 return DW_SND (attr
);
14000 else if (attr
->form
== DW_FORM_udata
14001 || attr
->form
== DW_FORM_data1
14002 || attr
->form
== DW_FORM_data2
14003 || attr
->form
== DW_FORM_data4
14004 || attr
->form
== DW_FORM_data8
)
14005 return DW_UNSND (attr
);
14008 complaint (&symfile_complaints
,
14009 _("Attribute value is not a constant (%s)"),
14010 dwarf_form_name (attr
->form
));
14011 return default_value
;
14015 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14016 unit and add it to our queue.
14017 The result is non-zero if PER_CU was queued, otherwise the result is zero
14018 meaning either PER_CU is already queued or it is already loaded. */
14021 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14022 struct dwarf2_per_cu_data
*per_cu
)
14024 /* We may arrive here during partial symbol reading, if we need full
14025 DIEs to process an unusual case (e.g. template arguments). Do
14026 not queue PER_CU, just tell our caller to load its DIEs. */
14027 if (dwarf2_per_objfile
->reading_partial_symbols
)
14029 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14034 /* Mark the dependence relation so that we don't flush PER_CU
14036 dwarf2_add_dependence (this_cu
, per_cu
);
14038 /* If it's already on the queue, we have nothing to do. */
14039 if (per_cu
->queued
)
14042 /* If the compilation unit is already loaded, just mark it as
14044 if (per_cu
->cu
!= NULL
)
14046 per_cu
->cu
->last_used
= 0;
14050 /* Add it to the queue. */
14051 queue_comp_unit (per_cu
);
14056 /* Follow reference or signature attribute ATTR of SRC_DIE.
14057 On entry *REF_CU is the CU of SRC_DIE.
14058 On exit *REF_CU is the CU of the result. */
14060 static struct die_info
*
14061 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14062 struct dwarf2_cu
**ref_cu
)
14064 struct die_info
*die
;
14066 if (is_ref_attr (attr
))
14067 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14068 else if (attr
->form
== DW_FORM_ref_sig8
)
14069 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14072 dump_die_for_error (src_die
);
14073 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14074 (*ref_cu
)->objfile
->name
);
14080 /* Follow reference OFFSET.
14081 On entry *REF_CU is the CU of the source die referencing OFFSET.
14082 On exit *REF_CU is the CU of the result.
14083 Returns NULL if OFFSET is invalid. */
14085 static struct die_info
*
14086 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
14088 struct die_info temp_die
;
14089 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14091 gdb_assert (cu
->per_cu
!= NULL
);
14095 if (cu
->per_cu
->debug_types_section
)
14097 /* .debug_types CUs cannot reference anything outside their CU.
14098 If they need to, they have to reference a signatured type via
14099 DW_FORM_ref_sig8. */
14100 if (! offset_in_cu_p (&cu
->header
, offset
))
14103 else if (! offset_in_cu_p (&cu
->header
, offset
))
14105 struct dwarf2_per_cu_data
*per_cu
;
14107 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14109 /* If necessary, add it to the queue and load its DIEs. */
14110 if (maybe_queue_comp_unit (cu
, per_cu
))
14111 load_full_comp_unit (per_cu
);
14113 target_cu
= per_cu
->cu
;
14115 else if (cu
->dies
== NULL
)
14117 /* We're loading full DIEs during partial symbol reading. */
14118 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14119 load_full_comp_unit (cu
->per_cu
);
14122 *ref_cu
= target_cu
;
14123 temp_die
.offset
= offset
;
14124 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
14127 /* Follow reference attribute ATTR of SRC_DIE.
14128 On entry *REF_CU is the CU of SRC_DIE.
14129 On exit *REF_CU is the CU of the result. */
14131 static struct die_info
*
14132 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14133 struct dwarf2_cu
**ref_cu
)
14135 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
14136 struct dwarf2_cu
*cu
= *ref_cu
;
14137 struct die_info
*die
;
14139 die
= follow_die_offset (offset
, ref_cu
);
14141 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14142 "at 0x%x [in module %s]"),
14143 offset
, src_die
->offset
, cu
->objfile
->name
);
14148 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14149 Returned value is intended for DW_OP_call*. Returned
14150 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14152 struct dwarf2_locexpr_baton
14153 dwarf2_fetch_die_location_block (unsigned int offset
,
14154 struct dwarf2_per_cu_data
*per_cu
,
14155 CORE_ADDR (*get_frame_pc
) (void *baton
),
14158 struct dwarf2_cu
*cu
;
14159 struct die_info
*die
;
14160 struct attribute
*attr
;
14161 struct dwarf2_locexpr_baton retval
;
14163 dw2_setup (per_cu
->objfile
);
14165 if (per_cu
->cu
== NULL
)
14169 die
= follow_die_offset (offset
, &cu
);
14171 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14172 offset
, per_cu
->objfile
->name
);
14174 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14177 /* DWARF: "If there is no such attribute, then there is no effect.".
14178 DATA is ignored if SIZE is 0. */
14180 retval
.data
= NULL
;
14183 else if (attr_form_is_section_offset (attr
))
14185 struct dwarf2_loclist_baton loclist_baton
;
14186 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
14189 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
14191 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
14193 retval
.size
= size
;
14197 if (!attr_form_is_block (attr
))
14198 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14199 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14200 offset
, per_cu
->objfile
->name
);
14202 retval
.data
= DW_BLOCK (attr
)->data
;
14203 retval
.size
= DW_BLOCK (attr
)->size
;
14205 retval
.per_cu
= cu
->per_cu
;
14207 age_cached_comp_units ();
14212 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14216 dwarf2_get_die_type (unsigned int die_offset
,
14217 struct dwarf2_per_cu_data
*per_cu
)
14219 dw2_setup (per_cu
->objfile
);
14220 return get_die_type_at_offset (die_offset
, per_cu
);
14223 /* Follow the signature attribute ATTR in SRC_DIE.
14224 On entry *REF_CU is the CU of SRC_DIE.
14225 On exit *REF_CU is the CU of the result. */
14227 static struct die_info
*
14228 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
14229 struct dwarf2_cu
**ref_cu
)
14231 struct objfile
*objfile
= (*ref_cu
)->objfile
;
14232 struct die_info temp_die
;
14233 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14234 struct dwarf2_cu
*sig_cu
;
14235 struct die_info
*die
;
14237 /* sig_type will be NULL if the signatured type is missing from
14239 if (sig_type
== NULL
)
14240 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14241 "at 0x%x [in module %s]"),
14242 src_die
->offset
, objfile
->name
);
14244 /* If necessary, add it to the queue and load its DIEs. */
14246 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14247 read_signatured_type (sig_type
);
14249 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14251 sig_cu
= sig_type
->per_cu
.cu
;
14252 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
14253 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
14260 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14261 "from DIE at 0x%x [in module %s]"),
14262 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
14265 /* Given an offset of a signatured type, return its signatured_type. */
14267 static struct signatured_type
*
14268 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14269 struct dwarf2_section_info
*section
,
14270 unsigned int offset
)
14272 gdb_byte
*info_ptr
= section
->buffer
+ offset
;
14273 unsigned int length
, initial_length_size
;
14274 unsigned int sig_offset
;
14275 struct signatured_type find_entry
, *type_sig
;
14277 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14278 sig_offset
= (initial_length_size
14280 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14281 + 1 /*address_size*/);
14282 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14283 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14285 /* This is only used to lookup previously recorded types.
14286 If we didn't find it, it's our bug. */
14287 gdb_assert (type_sig
!= NULL
);
14288 gdb_assert (offset
== type_sig
->per_cu
.offset
);
14293 /* Load the DIEs associated with type unit PER_CU into memory. */
14296 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
14298 struct objfile
*objfile
= per_cu
->objfile
;
14299 struct dwarf2_section_info
*sect
= per_cu
->debug_types_section
;
14300 unsigned int offset
= per_cu
->offset
;
14301 struct signatured_type
*type_sig
;
14303 dwarf2_read_section (objfile
, sect
);
14305 /* We have the section offset, but we need the signature to do the
14306 hash table lookup. */
14307 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
14308 the signature to assert we found the right one.
14309 Ok, but it's a lot of work. We should simplify things so any needed
14310 assert doesn't require all this clumsiness. */
14311 type_sig
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14313 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14315 read_signatured_type (type_sig
);
14317 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
14320 /* Read in a signatured type and build its CU and DIEs. */
14323 read_signatured_type (struct signatured_type
*type_sig
)
14325 struct objfile
*objfile
= type_sig
->per_cu
.objfile
;
14326 gdb_byte
*types_ptr
;
14327 struct die_reader_specs reader_specs
;
14328 struct dwarf2_cu
*cu
;
14329 ULONGEST signature
;
14330 struct cleanup
*back_to
, *free_cu_cleanup
;
14331 struct dwarf2_section_info
*section
= type_sig
->per_cu
.debug_types_section
;
14333 dwarf2_read_section (objfile
, section
);
14334 types_ptr
= section
->buffer
+ type_sig
->per_cu
.offset
;
14336 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14338 cu
= xmalloc (sizeof (*cu
));
14339 init_one_comp_unit (cu
, &type_sig
->per_cu
);
14341 /* If an error occurs while loading, release our storage. */
14342 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
14344 types_ptr
= read_type_comp_unit_head (&cu
->header
, section
, &signature
,
14345 types_ptr
, objfile
->obfd
);
14346 gdb_assert (signature
== type_sig
->signature
);
14349 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14353 &cu
->comp_unit_obstack
,
14354 hashtab_obstack_allocate
,
14355 dummy_obstack_deallocate
);
14357 dwarf2_read_abbrevs (cu
);
14358 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
14360 init_cu_die_reader (&reader_specs
, cu
);
14362 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14365 /* We try not to read any attributes in this function, because not
14366 all CUs needed for references have been loaded yet, and symbol
14367 table processing isn't initialized. But we have to set the CU language,
14368 or we won't be able to build types correctly. */
14369 prepare_one_comp_unit (cu
, cu
->dies
);
14371 do_cleanups (back_to
);
14373 /* We've successfully allocated this compilation unit. Let our caller
14374 clean it up when finished with it. */
14375 discard_cleanups (free_cu_cleanup
);
14377 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14378 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
14381 /* Decode simple location descriptions.
14382 Given a pointer to a dwarf block that defines a location, compute
14383 the location and return the value.
14385 NOTE drow/2003-11-18: This function is called in two situations
14386 now: for the address of static or global variables (partial symbols
14387 only) and for offsets into structures which are expected to be
14388 (more or less) constant. The partial symbol case should go away,
14389 and only the constant case should remain. That will let this
14390 function complain more accurately. A few special modes are allowed
14391 without complaint for global variables (for instance, global
14392 register values and thread-local values).
14394 A location description containing no operations indicates that the
14395 object is optimized out. The return value is 0 for that case.
14396 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14397 callers will only want a very basic result and this can become a
14400 Note that stack[0] is unused except as a default error return. */
14403 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14405 struct objfile
*objfile
= cu
->objfile
;
14407 int size
= blk
->size
;
14408 gdb_byte
*data
= blk
->data
;
14409 CORE_ADDR stack
[64];
14411 unsigned int bytes_read
, unsnd
;
14417 stack
[++stacki
] = 0;
14456 stack
[++stacki
] = op
- DW_OP_lit0
;
14491 stack
[++stacki
] = op
- DW_OP_reg0
;
14493 dwarf2_complex_location_expr_complaint ();
14497 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14499 stack
[++stacki
] = unsnd
;
14501 dwarf2_complex_location_expr_complaint ();
14505 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14510 case DW_OP_const1u
:
14511 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14515 case DW_OP_const1s
:
14516 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14520 case DW_OP_const2u
:
14521 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14525 case DW_OP_const2s
:
14526 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14530 case DW_OP_const4u
:
14531 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14535 case DW_OP_const4s
:
14536 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14540 case DW_OP_const8u
:
14541 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
14546 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14552 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14557 stack
[stacki
+ 1] = stack
[stacki
];
14562 stack
[stacki
- 1] += stack
[stacki
];
14566 case DW_OP_plus_uconst
:
14567 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14573 stack
[stacki
- 1] -= stack
[stacki
];
14578 /* If we're not the last op, then we definitely can't encode
14579 this using GDB's address_class enum. This is valid for partial
14580 global symbols, although the variable's address will be bogus
14583 dwarf2_complex_location_expr_complaint ();
14586 case DW_OP_GNU_push_tls_address
:
14587 /* The top of the stack has the offset from the beginning
14588 of the thread control block at which the variable is located. */
14589 /* Nothing should follow this operator, so the top of stack would
14591 /* This is valid for partial global symbols, but the variable's
14592 address will be bogus in the psymtab. Make it always at least
14593 non-zero to not look as a variable garbage collected by linker
14594 which have DW_OP_addr 0. */
14596 dwarf2_complex_location_expr_complaint ();
14600 case DW_OP_GNU_uninit
:
14605 const char *name
= dwarf_stack_op_name (op
);
14608 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14611 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14615 return (stack
[stacki
]);
14618 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14619 outside of the allocated space. Also enforce minimum>0. */
14620 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14622 complaint (&symfile_complaints
,
14623 _("location description stack overflow"));
14629 complaint (&symfile_complaints
,
14630 _("location description stack underflow"));
14634 return (stack
[stacki
]);
14637 /* memory allocation interface */
14639 static struct dwarf_block
*
14640 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14642 struct dwarf_block
*blk
;
14644 blk
= (struct dwarf_block
*)
14645 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14649 static struct abbrev_info
*
14650 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14652 struct abbrev_info
*abbrev
;
14654 abbrev
= (struct abbrev_info
*)
14655 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14656 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14660 static struct die_info
*
14661 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14663 struct die_info
*die
;
14664 size_t size
= sizeof (struct die_info
);
14667 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14669 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14670 memset (die
, 0, sizeof (struct die_info
));
14675 /* Macro support. */
14677 /* Return the full name of file number I in *LH's file name table.
14678 Use COMP_DIR as the name of the current directory of the
14679 compilation. The result is allocated using xmalloc; the caller is
14680 responsible for freeing it. */
14682 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14684 /* Is the file number a valid index into the line header's file name
14685 table? Remember that file numbers start with one, not zero. */
14686 if (1 <= file
&& file
<= lh
->num_file_names
)
14688 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14690 if (IS_ABSOLUTE_PATH (fe
->name
))
14691 return xstrdup (fe
->name
);
14699 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14705 dir_len
= strlen (dir
);
14706 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14707 strcpy (full_name
, dir
);
14708 full_name
[dir_len
] = '/';
14709 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14713 return xstrdup (fe
->name
);
14718 /* The compiler produced a bogus file number. We can at least
14719 record the macro definitions made in the file, even if we
14720 won't be able to find the file by name. */
14721 char fake_name
[80];
14723 sprintf (fake_name
, "<bad macro file number %d>", file
);
14725 complaint (&symfile_complaints
,
14726 _("bad file number in macro information (%d)"),
14729 return xstrdup (fake_name
);
14734 static struct macro_source_file
*
14735 macro_start_file (int file
, int line
,
14736 struct macro_source_file
*current_file
,
14737 const char *comp_dir
,
14738 struct line_header
*lh
, struct objfile
*objfile
)
14740 /* The full name of this source file. */
14741 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14743 /* We don't create a macro table for this compilation unit
14744 at all until we actually get a filename. */
14745 if (! pending_macros
)
14746 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14747 objfile
->macro_cache
);
14749 if (! current_file
)
14750 /* If we have no current file, then this must be the start_file
14751 directive for the compilation unit's main source file. */
14752 current_file
= macro_set_main (pending_macros
, full_name
);
14754 current_file
= macro_include (current_file
, line
, full_name
);
14758 return current_file
;
14762 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14763 followed by a null byte. */
14765 copy_string (const char *buf
, int len
)
14767 char *s
= xmalloc (len
+ 1);
14769 memcpy (s
, buf
, len
);
14775 static const char *
14776 consume_improper_spaces (const char *p
, const char *body
)
14780 complaint (&symfile_complaints
,
14781 _("macro definition contains spaces "
14782 "in formal argument list:\n`%s'"),
14794 parse_macro_definition (struct macro_source_file
*file
, int line
,
14799 /* The body string takes one of two forms. For object-like macro
14800 definitions, it should be:
14802 <macro name> " " <definition>
14804 For function-like macro definitions, it should be:
14806 <macro name> "() " <definition>
14808 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14810 Spaces may appear only where explicitly indicated, and in the
14813 The Dwarf 2 spec says that an object-like macro's name is always
14814 followed by a space, but versions of GCC around March 2002 omit
14815 the space when the macro's definition is the empty string.
14817 The Dwarf 2 spec says that there should be no spaces between the
14818 formal arguments in a function-like macro's formal argument list,
14819 but versions of GCC around March 2002 include spaces after the
14823 /* Find the extent of the macro name. The macro name is terminated
14824 by either a space or null character (for an object-like macro) or
14825 an opening paren (for a function-like macro). */
14826 for (p
= body
; *p
; p
++)
14827 if (*p
== ' ' || *p
== '(')
14830 if (*p
== ' ' || *p
== '\0')
14832 /* It's an object-like macro. */
14833 int name_len
= p
- body
;
14834 char *name
= copy_string (body
, name_len
);
14835 const char *replacement
;
14838 replacement
= body
+ name_len
+ 1;
14841 dwarf2_macro_malformed_definition_complaint (body
);
14842 replacement
= body
+ name_len
;
14845 macro_define_object (file
, line
, name
, replacement
);
14849 else if (*p
== '(')
14851 /* It's a function-like macro. */
14852 char *name
= copy_string (body
, p
- body
);
14855 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14859 p
= consume_improper_spaces (p
, body
);
14861 /* Parse the formal argument list. */
14862 while (*p
&& *p
!= ')')
14864 /* Find the extent of the current argument name. */
14865 const char *arg_start
= p
;
14867 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14870 if (! *p
|| p
== arg_start
)
14871 dwarf2_macro_malformed_definition_complaint (body
);
14874 /* Make sure argv has room for the new argument. */
14875 if (argc
>= argv_size
)
14878 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14881 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14884 p
= consume_improper_spaces (p
, body
);
14886 /* Consume the comma, if present. */
14891 p
= consume_improper_spaces (p
, body
);
14900 /* Perfectly formed definition, no complaints. */
14901 macro_define_function (file
, line
, name
,
14902 argc
, (const char **) argv
,
14904 else if (*p
== '\0')
14906 /* Complain, but do define it. */
14907 dwarf2_macro_malformed_definition_complaint (body
);
14908 macro_define_function (file
, line
, name
,
14909 argc
, (const char **) argv
,
14913 /* Just complain. */
14914 dwarf2_macro_malformed_definition_complaint (body
);
14917 /* Just complain. */
14918 dwarf2_macro_malformed_definition_complaint (body
);
14924 for (i
= 0; i
< argc
; i
++)
14930 dwarf2_macro_malformed_definition_complaint (body
);
14933 /* Skip some bytes from BYTES according to the form given in FORM.
14934 Returns the new pointer. */
14937 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
14938 enum dwarf_form form
,
14939 unsigned int offset_size
,
14940 struct dwarf2_section_info
*section
)
14942 unsigned int bytes_read
;
14946 case DW_FORM_data1
:
14951 case DW_FORM_data2
:
14955 case DW_FORM_data4
:
14959 case DW_FORM_data8
:
14963 case DW_FORM_string
:
14964 read_direct_string (abfd
, bytes
, &bytes_read
);
14965 bytes
+= bytes_read
;
14968 case DW_FORM_sec_offset
:
14970 bytes
+= offset_size
;
14973 case DW_FORM_block
:
14974 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
14975 bytes
+= bytes_read
;
14978 case DW_FORM_block1
:
14979 bytes
+= 1 + read_1_byte (abfd
, bytes
);
14981 case DW_FORM_block2
:
14982 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
14984 case DW_FORM_block4
:
14985 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
14988 case DW_FORM_sdata
:
14989 case DW_FORM_udata
:
14990 bytes
= skip_leb128 (abfd
, bytes
);
14996 complaint (&symfile_complaints
,
14997 _("invalid form 0x%x in `%s'"),
14999 section
->asection
->name
);
15007 /* A helper for dwarf_decode_macros that handles skipping an unknown
15008 opcode. Returns an updated pointer to the macro data buffer; or,
15009 on error, issues a complaint and returns NULL. */
15012 skip_unknown_opcode (unsigned int opcode
,
15013 gdb_byte
**opcode_definitions
,
15016 unsigned int offset_size
,
15017 struct dwarf2_section_info
*section
)
15019 unsigned int bytes_read
, i
;
15023 if (opcode_definitions
[opcode
] == NULL
)
15025 complaint (&symfile_complaints
,
15026 _("unrecognized DW_MACFINO opcode 0x%x"),
15031 defn
= opcode_definitions
[opcode
];
15032 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15033 defn
+= bytes_read
;
15035 for (i
= 0; i
< arg
; ++i
)
15037 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
15038 if (mac_ptr
== NULL
)
15040 /* skip_form_bytes already issued the complaint. */
15048 /* A helper function which parses the header of a macro section.
15049 If the macro section is the extended (for now called "GNU") type,
15050 then this updates *OFFSET_SIZE. Returns a pointer to just after
15051 the header, or issues a complaint and returns NULL on error. */
15054 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15057 unsigned int *offset_size
,
15058 int section_is_gnu
)
15060 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15062 if (section_is_gnu
)
15064 unsigned int version
, flags
;
15066 version
= read_2_bytes (abfd
, mac_ptr
);
15069 complaint (&symfile_complaints
,
15070 _("unrecognized version `%d' in .debug_macro section"),
15076 flags
= read_1_byte (abfd
, mac_ptr
);
15078 *offset_size
= (flags
& 1) ? 8 : 4;
15080 if ((flags
& 2) != 0)
15081 /* We don't need the line table offset. */
15082 mac_ptr
+= *offset_size
;
15084 /* Vendor opcode descriptions. */
15085 if ((flags
& 4) != 0)
15087 unsigned int i
, count
;
15089 count
= read_1_byte (abfd
, mac_ptr
);
15091 for (i
= 0; i
< count
; ++i
)
15093 unsigned int opcode
, bytes_read
;
15096 opcode
= read_1_byte (abfd
, mac_ptr
);
15098 opcode_definitions
[opcode
] = mac_ptr
;
15099 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15100 mac_ptr
+= bytes_read
;
15109 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15110 including DW_GNU_MACINFO_transparent_include. */
15113 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15114 struct macro_source_file
*current_file
,
15115 struct line_header
*lh
, char *comp_dir
,
15116 struct dwarf2_section_info
*section
,
15117 int section_is_gnu
,
15118 unsigned int offset_size
,
15119 struct objfile
*objfile
)
15121 enum dwarf_macro_record_type macinfo_type
;
15122 int at_commandline
;
15123 gdb_byte
*opcode_definitions
[256];
15125 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15126 &offset_size
, section_is_gnu
);
15127 if (mac_ptr
== NULL
)
15129 /* We already issued a complaint. */
15133 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15134 GDB is still reading the definitions from command line. First
15135 DW_MACINFO_start_file will need to be ignored as it was already executed
15136 to create CURRENT_FILE for the main source holding also the command line
15137 definitions. On first met DW_MACINFO_start_file this flag is reset to
15138 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15140 at_commandline
= 1;
15144 /* Do we at least have room for a macinfo type byte? */
15145 if (mac_ptr
>= mac_end
)
15147 dwarf2_macros_too_long_complaint (section
);
15151 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15154 /* Note that we rely on the fact that the corresponding GNU and
15155 DWARF constants are the same. */
15156 switch (macinfo_type
)
15158 /* A zero macinfo type indicates the end of the macro
15163 case DW_MACRO_GNU_define
:
15164 case DW_MACRO_GNU_undef
:
15165 case DW_MACRO_GNU_define_indirect
:
15166 case DW_MACRO_GNU_undef_indirect
:
15168 unsigned int bytes_read
;
15173 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15174 mac_ptr
+= bytes_read
;
15176 if (macinfo_type
== DW_MACRO_GNU_define
15177 || macinfo_type
== DW_MACRO_GNU_undef
)
15179 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15180 mac_ptr
+= bytes_read
;
15184 LONGEST str_offset
;
15186 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15187 mac_ptr
+= offset_size
;
15189 body
= read_indirect_string_at_offset (abfd
, str_offset
);
15192 is_define
= (macinfo_type
== DW_MACRO_GNU_define
15193 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
15194 if (! current_file
)
15196 /* DWARF violation as no main source is present. */
15197 complaint (&symfile_complaints
,
15198 _("debug info with no main source gives macro %s "
15200 is_define
? _("definition") : _("undefinition"),
15204 if ((line
== 0 && !at_commandline
)
15205 || (line
!= 0 && at_commandline
))
15206 complaint (&symfile_complaints
,
15207 _("debug info gives %s macro %s with %s line %d: %s"),
15208 at_commandline
? _("command-line") : _("in-file"),
15209 is_define
? _("definition") : _("undefinition"),
15210 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
15213 parse_macro_definition (current_file
, line
, body
);
15216 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
15217 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
15218 macro_undef (current_file
, line
, body
);
15223 case DW_MACRO_GNU_start_file
:
15225 unsigned int bytes_read
;
15228 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15229 mac_ptr
+= bytes_read
;
15230 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15231 mac_ptr
+= bytes_read
;
15233 if ((line
== 0 && !at_commandline
)
15234 || (line
!= 0 && at_commandline
))
15235 complaint (&symfile_complaints
,
15236 _("debug info gives source %d included "
15237 "from %s at %s line %d"),
15238 file
, at_commandline
? _("command-line") : _("file"),
15239 line
== 0 ? _("zero") : _("non-zero"), line
);
15241 if (at_commandline
)
15243 /* This DW_MACRO_GNU_start_file was executed in the
15245 at_commandline
= 0;
15248 current_file
= macro_start_file (file
, line
,
15249 current_file
, comp_dir
,
15254 case DW_MACRO_GNU_end_file
:
15255 if (! current_file
)
15256 complaint (&symfile_complaints
,
15257 _("macro debug info has an unmatched "
15258 "`close_file' directive"));
15261 current_file
= current_file
->included_by
;
15262 if (! current_file
)
15264 enum dwarf_macro_record_type next_type
;
15266 /* GCC circa March 2002 doesn't produce the zero
15267 type byte marking the end of the compilation
15268 unit. Complain if it's not there, but exit no
15271 /* Do we at least have room for a macinfo type byte? */
15272 if (mac_ptr
>= mac_end
)
15274 dwarf2_macros_too_long_complaint (section
);
15278 /* We don't increment mac_ptr here, so this is just
15280 next_type
= read_1_byte (abfd
, mac_ptr
);
15281 if (next_type
!= 0)
15282 complaint (&symfile_complaints
,
15283 _("no terminating 0-type entry for "
15284 "macros in `.debug_macinfo' section"));
15291 case DW_MACRO_GNU_transparent_include
:
15295 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15296 mac_ptr
+= offset_size
;
15298 dwarf_decode_macro_bytes (abfd
,
15299 section
->buffer
+ offset
,
15300 mac_end
, current_file
,
15302 section
, section_is_gnu
,
15303 offset_size
, objfile
);
15307 case DW_MACINFO_vendor_ext
:
15308 if (!section_is_gnu
)
15310 unsigned int bytes_read
;
15313 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15314 mac_ptr
+= bytes_read
;
15315 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15316 mac_ptr
+= bytes_read
;
15318 /* We don't recognize any vendor extensions. */
15324 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15325 mac_ptr
, abfd
, offset_size
,
15327 if (mac_ptr
== NULL
)
15331 } while (macinfo_type
!= 0);
15335 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
15336 char *comp_dir
, bfd
*abfd
,
15337 struct dwarf2_cu
*cu
,
15338 struct dwarf2_section_info
*section
,
15339 int section_is_gnu
)
15341 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15342 gdb_byte
*mac_ptr
, *mac_end
;
15343 struct macro_source_file
*current_file
= 0;
15344 enum dwarf_macro_record_type macinfo_type
;
15345 unsigned int offset_size
= cu
->header
.offset_size
;
15346 gdb_byte
*opcode_definitions
[256];
15348 dwarf2_read_section (objfile
, section
);
15349 if (section
->buffer
== NULL
)
15351 complaint (&symfile_complaints
, _("missing %s section"),
15352 section
->asection
->name
);
15356 /* First pass: Find the name of the base filename.
15357 This filename is needed in order to process all macros whose definition
15358 (or undefinition) comes from the command line. These macros are defined
15359 before the first DW_MACINFO_start_file entry, and yet still need to be
15360 associated to the base file.
15362 To determine the base file name, we scan the macro definitions until we
15363 reach the first DW_MACINFO_start_file entry. We then initialize
15364 CURRENT_FILE accordingly so that any macro definition found before the
15365 first DW_MACINFO_start_file can still be associated to the base file. */
15367 mac_ptr
= section
->buffer
+ offset
;
15368 mac_end
= section
->buffer
+ section
->size
;
15370 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15371 &offset_size
, section_is_gnu
);
15372 if (mac_ptr
== NULL
)
15374 /* We already issued a complaint. */
15380 /* Do we at least have room for a macinfo type byte? */
15381 if (mac_ptr
>= mac_end
)
15383 /* Complaint is printed during the second pass as GDB will probably
15384 stop the first pass earlier upon finding
15385 DW_MACINFO_start_file. */
15389 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15392 /* Note that we rely on the fact that the corresponding GNU and
15393 DWARF constants are the same. */
15394 switch (macinfo_type
)
15396 /* A zero macinfo type indicates the end of the macro
15401 case DW_MACRO_GNU_define
:
15402 case DW_MACRO_GNU_undef
:
15403 /* Only skip the data by MAC_PTR. */
15405 unsigned int bytes_read
;
15407 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15408 mac_ptr
+= bytes_read
;
15409 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15410 mac_ptr
+= bytes_read
;
15414 case DW_MACRO_GNU_start_file
:
15416 unsigned int bytes_read
;
15419 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15420 mac_ptr
+= bytes_read
;
15421 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15422 mac_ptr
+= bytes_read
;
15424 current_file
= macro_start_file (file
, line
, current_file
,
15425 comp_dir
, lh
, objfile
);
15429 case DW_MACRO_GNU_end_file
:
15430 /* No data to skip by MAC_PTR. */
15433 case DW_MACRO_GNU_define_indirect
:
15434 case DW_MACRO_GNU_undef_indirect
:
15436 unsigned int bytes_read
;
15438 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15439 mac_ptr
+= bytes_read
;
15440 mac_ptr
+= offset_size
;
15444 case DW_MACRO_GNU_transparent_include
:
15445 /* Note that, according to the spec, a transparent include
15446 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15447 skip this opcode. */
15448 mac_ptr
+= offset_size
;
15451 case DW_MACINFO_vendor_ext
:
15452 /* Only skip the data by MAC_PTR. */
15453 if (!section_is_gnu
)
15455 unsigned int bytes_read
;
15457 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15458 mac_ptr
+= bytes_read
;
15459 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15460 mac_ptr
+= bytes_read
;
15465 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15466 mac_ptr
, abfd
, offset_size
,
15468 if (mac_ptr
== NULL
)
15472 } while (macinfo_type
!= 0 && current_file
== NULL
);
15474 /* Second pass: Process all entries.
15476 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15477 command-line macro definitions/undefinitions. This flag is unset when we
15478 reach the first DW_MACINFO_start_file entry. */
15480 dwarf_decode_macro_bytes (abfd
, section
->buffer
+ offset
, mac_end
,
15481 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
15482 offset_size
, objfile
);
15485 /* Check if the attribute's form is a DW_FORM_block*
15486 if so return true else false. */
15488 attr_form_is_block (struct attribute
*attr
)
15490 return (attr
== NULL
? 0 :
15491 attr
->form
== DW_FORM_block1
15492 || attr
->form
== DW_FORM_block2
15493 || attr
->form
== DW_FORM_block4
15494 || attr
->form
== DW_FORM_block
15495 || attr
->form
== DW_FORM_exprloc
);
15498 /* Return non-zero if ATTR's value is a section offset --- classes
15499 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15500 You may use DW_UNSND (attr) to retrieve such offsets.
15502 Section 7.5.4, "Attribute Encodings", explains that no attribute
15503 may have a value that belongs to more than one of these classes; it
15504 would be ambiguous if we did, because we use the same forms for all
15507 attr_form_is_section_offset (struct attribute
*attr
)
15509 return (attr
->form
== DW_FORM_data4
15510 || attr
->form
== DW_FORM_data8
15511 || attr
->form
== DW_FORM_sec_offset
);
15515 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15516 zero otherwise. When this function returns true, you can apply
15517 dwarf2_get_attr_constant_value to it.
15519 However, note that for some attributes you must check
15520 attr_form_is_section_offset before using this test. DW_FORM_data4
15521 and DW_FORM_data8 are members of both the constant class, and of
15522 the classes that contain offsets into other debug sections
15523 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15524 that, if an attribute's can be either a constant or one of the
15525 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15526 taken as section offsets, not constants. */
15528 attr_form_is_constant (struct attribute
*attr
)
15530 switch (attr
->form
)
15532 case DW_FORM_sdata
:
15533 case DW_FORM_udata
:
15534 case DW_FORM_data1
:
15535 case DW_FORM_data2
:
15536 case DW_FORM_data4
:
15537 case DW_FORM_data8
:
15544 /* A helper function that fills in a dwarf2_loclist_baton. */
15547 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15548 struct dwarf2_loclist_baton
*baton
,
15549 struct attribute
*attr
)
15551 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15552 &dwarf2_per_objfile
->loc
);
15554 baton
->per_cu
= cu
->per_cu
;
15555 gdb_assert (baton
->per_cu
);
15556 /* We don't know how long the location list is, but make sure we
15557 don't run off the edge of the section. */
15558 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15559 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15560 baton
->base_address
= cu
->base_address
;
15564 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15565 struct dwarf2_cu
*cu
)
15567 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15569 if (attr_form_is_section_offset (attr
)
15570 /* ".debug_loc" may not exist at all, or the offset may be outside
15571 the section. If so, fall through to the complaint in the
15573 && DW_UNSND (attr
) < dwarf2_section_size (objfile
,
15574 &dwarf2_per_objfile
->loc
))
15576 struct dwarf2_loclist_baton
*baton
;
15578 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15579 sizeof (struct dwarf2_loclist_baton
));
15581 fill_in_loclist_baton (cu
, baton
, attr
);
15583 if (cu
->base_known
== 0)
15584 complaint (&symfile_complaints
,
15585 _("Location list used without "
15586 "specifying the CU base address."));
15588 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15589 SYMBOL_LOCATION_BATON (sym
) = baton
;
15593 struct dwarf2_locexpr_baton
*baton
;
15595 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15596 sizeof (struct dwarf2_locexpr_baton
));
15597 baton
->per_cu
= cu
->per_cu
;
15598 gdb_assert (baton
->per_cu
);
15600 if (attr_form_is_block (attr
))
15602 /* Note that we're just copying the block's data pointer
15603 here, not the actual data. We're still pointing into the
15604 info_buffer for SYM's objfile; right now we never release
15605 that buffer, but when we do clean up properly this may
15607 baton
->size
= DW_BLOCK (attr
)->size
;
15608 baton
->data
= DW_BLOCK (attr
)->data
;
15612 dwarf2_invalid_attrib_class_complaint ("location description",
15613 SYMBOL_NATURAL_NAME (sym
));
15617 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15618 SYMBOL_LOCATION_BATON (sym
) = baton
;
15622 /* Return the OBJFILE associated with the compilation unit CU. If CU
15623 came from a separate debuginfo file, then the master objfile is
15627 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
15629 struct objfile
*objfile
= per_cu
->objfile
;
15631 /* Return the master objfile, so that we can report and look up the
15632 correct file containing this variable. */
15633 if (objfile
->separate_debug_objfile_backlink
)
15634 objfile
= objfile
->separate_debug_objfile_backlink
;
15639 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15640 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15641 CU_HEADERP first. */
15643 static const struct comp_unit_head
*
15644 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
15645 struct dwarf2_per_cu_data
*per_cu
)
15647 struct objfile
*objfile
;
15648 struct dwarf2_per_objfile
*per_objfile
;
15649 gdb_byte
*info_ptr
;
15652 return &per_cu
->cu
->header
;
15654 objfile
= per_cu
->objfile
;
15655 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15656 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
15658 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
15659 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
15664 /* Return the address size given in the compilation unit header for CU. */
15667 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15669 struct comp_unit_head cu_header_local
;
15670 const struct comp_unit_head
*cu_headerp
;
15672 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15674 return cu_headerp
->addr_size
;
15677 /* Return the offset size given in the compilation unit header for CU. */
15680 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
15682 struct comp_unit_head cu_header_local
;
15683 const struct comp_unit_head
*cu_headerp
;
15685 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15687 return cu_headerp
->offset_size
;
15690 /* See its dwarf2loc.h declaration. */
15693 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15695 struct comp_unit_head cu_header_local
;
15696 const struct comp_unit_head
*cu_headerp
;
15698 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15700 if (cu_headerp
->version
== 2)
15701 return cu_headerp
->addr_size
;
15703 return cu_headerp
->offset_size
;
15706 /* Return the text offset of the CU. The returned offset comes from
15707 this CU's objfile. If this objfile came from a separate debuginfo
15708 file, then the offset may be different from the corresponding
15709 offset in the parent objfile. */
15712 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
15714 struct objfile
*objfile
= per_cu
->objfile
;
15716 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15719 /* Locate the .debug_info compilation unit from CU's objfile which contains
15720 the DIE at OFFSET. Raises an error on failure. */
15722 static struct dwarf2_per_cu_data
*
15723 dwarf2_find_containing_comp_unit (unsigned int offset
,
15724 struct objfile
*objfile
)
15726 struct dwarf2_per_cu_data
*this_cu
;
15730 high
= dwarf2_per_objfile
->n_comp_units
- 1;
15733 int mid
= low
+ (high
- low
) / 2;
15735 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
15740 gdb_assert (low
== high
);
15741 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
15744 error (_("Dwarf Error: could not find partial DIE containing "
15745 "offset 0x%lx [in module %s]"),
15746 (long) offset
, bfd_get_filename (objfile
->obfd
));
15748 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
15749 return dwarf2_per_objfile
->all_comp_units
[low
-1];
15753 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
15754 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
15755 && offset
>= this_cu
->offset
+ this_cu
->length
)
15756 error (_("invalid dwarf2 offset %u"), offset
);
15757 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
15762 /* Initialize dwarf2_cu CU, owned by PER_CU. */
15765 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
15767 memset (cu
, 0, sizeof (*cu
));
15769 cu
->per_cu
= per_cu
;
15770 cu
->objfile
= per_cu
->objfile
;
15771 obstack_init (&cu
->comp_unit_obstack
);
15774 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15777 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
15779 struct attribute
*attr
;
15781 /* Set the language we're debugging. */
15782 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
15784 set_cu_language (DW_UNSND (attr
), cu
);
15787 cu
->language
= language_minimal
;
15788 cu
->language_defn
= language_def (cu
->language
);
15792 /* Release one cached compilation unit, CU. We unlink it from the tree
15793 of compilation units, but we don't remove it from the read_in_chain;
15794 the caller is responsible for that.
15795 NOTE: DATA is a void * because this function is also used as a
15796 cleanup routine. */
15799 free_heap_comp_unit (void *data
)
15801 struct dwarf2_cu
*cu
= data
;
15803 gdb_assert (cu
->per_cu
!= NULL
);
15804 cu
->per_cu
->cu
= NULL
;
15807 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15812 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15813 when we're finished with it. We can't free the pointer itself, but be
15814 sure to unlink it from the cache. Also release any associated storage
15815 and perform cache maintenance.
15817 Only used during partial symbol parsing. */
15820 free_stack_comp_unit (void *data
)
15822 struct dwarf2_cu
*cu
= data
;
15824 gdb_assert (cu
->per_cu
!= NULL
);
15825 cu
->per_cu
->cu
= NULL
;
15828 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15829 cu
->partial_dies
= NULL
;
15831 /* The previous code only did this if per_cu != NULL.
15832 But that would always succeed, so now we just unconditionally do
15833 the aging. This seems like the wrong place to do such aging,
15834 but cleaning that up is left for later. */
15835 age_cached_comp_units ();
15838 /* Free all cached compilation units. */
15841 free_cached_comp_units (void *data
)
15843 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15845 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15846 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15847 while (per_cu
!= NULL
)
15849 struct dwarf2_per_cu_data
*next_cu
;
15851 next_cu
= per_cu
->cu
->read_in_chain
;
15853 free_heap_comp_unit (per_cu
->cu
);
15854 *last_chain
= next_cu
;
15860 /* Increase the age counter on each cached compilation unit, and free
15861 any that are too old. */
15864 age_cached_comp_units (void)
15866 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15868 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
15869 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15870 while (per_cu
!= NULL
)
15872 per_cu
->cu
->last_used
++;
15873 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
15874 dwarf2_mark (per_cu
->cu
);
15875 per_cu
= per_cu
->cu
->read_in_chain
;
15878 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15879 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15880 while (per_cu
!= NULL
)
15882 struct dwarf2_per_cu_data
*next_cu
;
15884 next_cu
= per_cu
->cu
->read_in_chain
;
15886 if (!per_cu
->cu
->mark
)
15888 free_heap_comp_unit (per_cu
->cu
);
15889 *last_chain
= next_cu
;
15892 last_chain
= &per_cu
->cu
->read_in_chain
;
15898 /* Remove a single compilation unit from the cache. */
15901 free_one_cached_comp_unit (void *target_cu
)
15903 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15905 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15906 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15907 while (per_cu
!= NULL
)
15909 struct dwarf2_per_cu_data
*next_cu
;
15911 next_cu
= per_cu
->cu
->read_in_chain
;
15913 if (per_cu
->cu
== target_cu
)
15915 free_heap_comp_unit (per_cu
->cu
);
15916 *last_chain
= next_cu
;
15920 last_chain
= &per_cu
->cu
->read_in_chain
;
15926 /* Release all extra memory associated with OBJFILE. */
15929 dwarf2_free_objfile (struct objfile
*objfile
)
15931 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15933 if (dwarf2_per_objfile
== NULL
)
15936 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
15937 free_cached_comp_units (NULL
);
15939 if (dwarf2_per_objfile
->quick_file_names_table
)
15940 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
15942 /* Everything else should be on the objfile obstack. */
15945 /* A pair of DIE offset and GDB type pointer. We store these
15946 in a hash table separate from the DIEs, and preserve them
15947 when the DIEs are flushed out of cache. */
15949 struct dwarf2_offset_and_type
15951 unsigned int offset
;
15955 /* Hash function for a dwarf2_offset_and_type. */
15958 offset_and_type_hash (const void *item
)
15960 const struct dwarf2_offset_and_type
*ofs
= item
;
15962 return ofs
->offset
;
15965 /* Equality function for a dwarf2_offset_and_type. */
15968 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
15970 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
15971 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
15973 return ofs_lhs
->offset
== ofs_rhs
->offset
;
15976 /* Set the type associated with DIE to TYPE. Save it in CU's hash
15977 table if necessary. For convenience, return TYPE.
15979 The DIEs reading must have careful ordering to:
15980 * Not cause infite loops trying to read in DIEs as a prerequisite for
15981 reading current DIE.
15982 * Not trying to dereference contents of still incompletely read in types
15983 while reading in other DIEs.
15984 * Enable referencing still incompletely read in types just by a pointer to
15985 the type without accessing its fields.
15987 Therefore caller should follow these rules:
15988 * Try to fetch any prerequisite types we may need to build this DIE type
15989 before building the type and calling set_die_type.
15990 * After building type call set_die_type for current DIE as soon as
15991 possible before fetching more types to complete the current type.
15992 * Make the type as complete as possible before fetching more types. */
15994 static struct type
*
15995 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
15997 struct dwarf2_offset_and_type
**slot
, ofs
;
15998 struct objfile
*objfile
= cu
->objfile
;
15999 htab_t
*type_hash_ptr
;
16001 /* For Ada types, make sure that the gnat-specific data is always
16002 initialized (if not already set). There are a few types where
16003 we should not be doing so, because the type-specific area is
16004 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16005 where the type-specific area is used to store the floatformat).
16006 But this is not a problem, because the gnat-specific information
16007 is actually not needed for these types. */
16008 if (need_gnat_info (cu
)
16009 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16010 && TYPE_CODE (type
) != TYPE_CODE_FLT
16011 && !HAVE_GNAT_AUX_INFO (type
))
16012 INIT_GNAT_SPECIFIC (type
);
16014 if (cu
->per_cu
->debug_types_section
)
16015 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
16017 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
16019 if (*type_hash_ptr
== NULL
)
16022 = htab_create_alloc_ex (127,
16023 offset_and_type_hash
,
16024 offset_and_type_eq
,
16026 &objfile
->objfile_obstack
,
16027 hashtab_obstack_allocate
,
16028 dummy_obstack_deallocate
);
16031 ofs
.offset
= die
->offset
;
16033 slot
= (struct dwarf2_offset_and_type
**)
16034 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
16036 complaint (&symfile_complaints
,
16037 _("A problem internal to GDB: DIE 0x%x has type already set"),
16039 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16044 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
16045 table, or return NULL if the die does not have a saved type. */
16047 static struct type
*
16048 get_die_type_at_offset (unsigned int offset
,
16049 struct dwarf2_per_cu_data
*per_cu
)
16051 struct dwarf2_offset_and_type
*slot
, ofs
;
16054 if (per_cu
->debug_types_section
)
16055 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
16057 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
16058 if (type_hash
== NULL
)
16061 ofs
.offset
= offset
;
16062 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
16069 /* Look up the type for DIE in the appropriate type_hash table,
16070 or return NULL if DIE does not have a saved type. */
16072 static struct type
*
16073 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16075 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16078 /* Add a dependence relationship from CU to REF_PER_CU. */
16081 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16082 struct dwarf2_per_cu_data
*ref_per_cu
)
16086 if (cu
->dependencies
== NULL
)
16088 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16089 NULL
, &cu
->comp_unit_obstack
,
16090 hashtab_obstack_allocate
,
16091 dummy_obstack_deallocate
);
16093 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16095 *slot
= ref_per_cu
;
16098 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16099 Set the mark field in every compilation unit in the
16100 cache that we must keep because we are keeping CU. */
16103 dwarf2_mark_helper (void **slot
, void *data
)
16105 struct dwarf2_per_cu_data
*per_cu
;
16107 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
16109 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16110 reading of the chain. As such dependencies remain valid it is not much
16111 useful to track and undo them during QUIT cleanups. */
16112 if (per_cu
->cu
== NULL
)
16115 if (per_cu
->cu
->mark
)
16117 per_cu
->cu
->mark
= 1;
16119 if (per_cu
->cu
->dependencies
!= NULL
)
16120 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16125 /* Set the mark field in CU and in every other compilation unit in the
16126 cache that we must keep because we are keeping CU. */
16129 dwarf2_mark (struct dwarf2_cu
*cu
)
16134 if (cu
->dependencies
!= NULL
)
16135 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16139 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
16143 per_cu
->cu
->mark
= 0;
16144 per_cu
= per_cu
->cu
->read_in_chain
;
16148 /* Trivial hash function for partial_die_info: the hash value of a DIE
16149 is its offset in .debug_info for this objfile. */
16152 partial_die_hash (const void *item
)
16154 const struct partial_die_info
*part_die
= item
;
16156 return part_die
->offset
;
16159 /* Trivial comparison function for partial_die_info structures: two DIEs
16160 are equal if they have the same offset. */
16163 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
16165 const struct partial_die_info
*part_die_lhs
= item_lhs
;
16166 const struct partial_die_info
*part_die_rhs
= item_rhs
;
16168 return part_die_lhs
->offset
== part_die_rhs
->offset
;
16171 static struct cmd_list_element
*set_dwarf2_cmdlist
;
16172 static struct cmd_list_element
*show_dwarf2_cmdlist
;
16175 set_dwarf2_cmd (char *args
, int from_tty
)
16177 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
16181 show_dwarf2_cmd (char *args
, int from_tty
)
16183 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
16186 /* If section described by INFO was mmapped, munmap it now. */
16189 munmap_section_buffer (struct dwarf2_section_info
*info
)
16191 if (info
->map_addr
!= NULL
)
16196 res
= munmap (info
->map_addr
, info
->map_len
);
16197 gdb_assert (res
== 0);
16199 /* Without HAVE_MMAP, we should never be here to begin with. */
16200 gdb_assert_not_reached ("no mmap support");
16205 /* munmap debug sections for OBJFILE, if necessary. */
16208 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
16210 struct dwarf2_per_objfile
*data
= d
;
16212 struct dwarf2_section_info
*section
;
16214 /* This is sorted according to the order they're defined in to make it easier
16215 to keep in sync. */
16216 munmap_section_buffer (&data
->info
);
16217 munmap_section_buffer (&data
->abbrev
);
16218 munmap_section_buffer (&data
->line
);
16219 munmap_section_buffer (&data
->loc
);
16220 munmap_section_buffer (&data
->macinfo
);
16221 munmap_section_buffer (&data
->macro
);
16222 munmap_section_buffer (&data
->str
);
16223 munmap_section_buffer (&data
->ranges
);
16224 munmap_section_buffer (&data
->frame
);
16225 munmap_section_buffer (&data
->eh_frame
);
16226 munmap_section_buffer (&data
->gdb_index
);
16229 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
16231 munmap_section_buffer (section
);
16233 VEC_free (dwarf2_section_info_def
, data
->types
);
16237 /* The "save gdb-index" command. */
16239 /* The contents of the hash table we create when building the string
16241 struct strtab_entry
16243 offset_type offset
;
16247 /* Hash function for a strtab_entry.
16249 Function is used only during write_hash_table so no index format backward
16250 compatibility is needed. */
16253 hash_strtab_entry (const void *e
)
16255 const struct strtab_entry
*entry
= e
;
16256 return mapped_index_string_hash (INT_MAX
, entry
->str
);
16259 /* Equality function for a strtab_entry. */
16262 eq_strtab_entry (const void *a
, const void *b
)
16264 const struct strtab_entry
*ea
= a
;
16265 const struct strtab_entry
*eb
= b
;
16266 return !strcmp (ea
->str
, eb
->str
);
16269 /* Create a strtab_entry hash table. */
16272 create_strtab (void)
16274 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
16275 xfree
, xcalloc
, xfree
);
16278 /* Add a string to the constant pool. Return the string's offset in
16282 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
16285 struct strtab_entry entry
;
16286 struct strtab_entry
*result
;
16289 slot
= htab_find_slot (table
, &entry
, INSERT
);
16294 result
= XNEW (struct strtab_entry
);
16295 result
->offset
= obstack_object_size (cpool
);
16297 obstack_grow_str0 (cpool
, str
);
16300 return result
->offset
;
16303 /* An entry in the symbol table. */
16304 struct symtab_index_entry
16306 /* The name of the symbol. */
16308 /* The offset of the name in the constant pool. */
16309 offset_type index_offset
;
16310 /* A sorted vector of the indices of all the CUs that hold an object
16312 VEC (offset_type
) *cu_indices
;
16315 /* The symbol table. This is a power-of-2-sized hash table. */
16316 struct mapped_symtab
16318 offset_type n_elements
;
16320 struct symtab_index_entry
**data
;
16323 /* Hash function for a symtab_index_entry. */
16326 hash_symtab_entry (const void *e
)
16328 const struct symtab_index_entry
*entry
= e
;
16329 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
16330 sizeof (offset_type
) * VEC_length (offset_type
,
16331 entry
->cu_indices
),
16335 /* Equality function for a symtab_index_entry. */
16338 eq_symtab_entry (const void *a
, const void *b
)
16340 const struct symtab_index_entry
*ea
= a
;
16341 const struct symtab_index_entry
*eb
= b
;
16342 int len
= VEC_length (offset_type
, ea
->cu_indices
);
16343 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
16345 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
16346 VEC_address (offset_type
, eb
->cu_indices
),
16347 sizeof (offset_type
) * len
);
16350 /* Destroy a symtab_index_entry. */
16353 delete_symtab_entry (void *p
)
16355 struct symtab_index_entry
*entry
= p
;
16356 VEC_free (offset_type
, entry
->cu_indices
);
16360 /* Create a hash table holding symtab_index_entry objects. */
16363 create_symbol_hash_table (void)
16365 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
16366 delete_symtab_entry
, xcalloc
, xfree
);
16369 /* Create a new mapped symtab object. */
16371 static struct mapped_symtab
*
16372 create_mapped_symtab (void)
16374 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
16375 symtab
->n_elements
= 0;
16376 symtab
->size
= 1024;
16377 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16381 /* Destroy a mapped_symtab. */
16384 cleanup_mapped_symtab (void *p
)
16386 struct mapped_symtab
*symtab
= p
;
16387 /* The contents of the array are freed when the other hash table is
16389 xfree (symtab
->data
);
16393 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16396 Function is used only during write_hash_table so no index format backward
16397 compatibility is needed. */
16399 static struct symtab_index_entry
**
16400 find_slot (struct mapped_symtab
*symtab
, const char *name
)
16402 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
16404 index
= hash
& (symtab
->size
- 1);
16405 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
16409 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
16410 return &symtab
->data
[index
];
16411 index
= (index
+ step
) & (symtab
->size
- 1);
16415 /* Expand SYMTAB's hash table. */
16418 hash_expand (struct mapped_symtab
*symtab
)
16420 offset_type old_size
= symtab
->size
;
16422 struct symtab_index_entry
**old_entries
= symtab
->data
;
16425 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16427 for (i
= 0; i
< old_size
; ++i
)
16429 if (old_entries
[i
])
16431 struct symtab_index_entry
**slot
= find_slot (symtab
,
16432 old_entries
[i
]->name
);
16433 *slot
= old_entries
[i
];
16437 xfree (old_entries
);
16440 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16441 is the index of the CU in which the symbol appears. */
16444 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
16445 offset_type cu_index
)
16447 struct symtab_index_entry
**slot
;
16449 ++symtab
->n_elements
;
16450 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
16451 hash_expand (symtab
);
16453 slot
= find_slot (symtab
, name
);
16456 *slot
= XNEW (struct symtab_index_entry
);
16457 (*slot
)->name
= name
;
16458 (*slot
)->cu_indices
= NULL
;
16460 /* Don't push an index twice. Due to how we add entries we only
16461 have to check the last one. */
16462 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
16463 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
16464 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
16467 /* Add a vector of indices to the constant pool. */
16470 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
16471 struct symtab_index_entry
*entry
)
16475 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
16478 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
16479 offset_type val
= MAYBE_SWAP (len
);
16484 entry
->index_offset
= obstack_object_size (cpool
);
16486 obstack_grow (cpool
, &val
, sizeof (val
));
16488 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
16491 val
= MAYBE_SWAP (iter
);
16492 obstack_grow (cpool
, &val
, sizeof (val
));
16497 struct symtab_index_entry
*old_entry
= *slot
;
16498 entry
->index_offset
= old_entry
->index_offset
;
16501 return entry
->index_offset
;
16504 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16505 constant pool entries going into the obstack CPOOL. */
16508 write_hash_table (struct mapped_symtab
*symtab
,
16509 struct obstack
*output
, struct obstack
*cpool
)
16512 htab_t symbol_hash_table
;
16515 symbol_hash_table
= create_symbol_hash_table ();
16516 str_table
= create_strtab ();
16518 /* We add all the index vectors to the constant pool first, to
16519 ensure alignment is ok. */
16520 for (i
= 0; i
< symtab
->size
; ++i
)
16522 if (symtab
->data
[i
])
16523 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
16526 /* Now write out the hash table. */
16527 for (i
= 0; i
< symtab
->size
; ++i
)
16529 offset_type str_off
, vec_off
;
16531 if (symtab
->data
[i
])
16533 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
16534 vec_off
= symtab
->data
[i
]->index_offset
;
16538 /* While 0 is a valid constant pool index, it is not valid
16539 to have 0 for both offsets. */
16544 str_off
= MAYBE_SWAP (str_off
);
16545 vec_off
= MAYBE_SWAP (vec_off
);
16547 obstack_grow (output
, &str_off
, sizeof (str_off
));
16548 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
16551 htab_delete (str_table
);
16552 htab_delete (symbol_hash_table
);
16555 /* Struct to map psymtab to CU index in the index file. */
16556 struct psymtab_cu_index_map
16558 struct partial_symtab
*psymtab
;
16559 unsigned int cu_index
;
16563 hash_psymtab_cu_index (const void *item
)
16565 const struct psymtab_cu_index_map
*map
= item
;
16567 return htab_hash_pointer (map
->psymtab
);
16571 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16573 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16574 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16576 return lhs
->psymtab
== rhs
->psymtab
;
16579 /* Helper struct for building the address table. */
16580 struct addrmap_index_data
16582 struct objfile
*objfile
;
16583 struct obstack
*addr_obstack
;
16584 htab_t cu_index_htab
;
16586 /* Non-zero if the previous_* fields are valid.
16587 We can't write an entry until we see the next entry (since it is only then
16588 that we know the end of the entry). */
16589 int previous_valid
;
16590 /* Index of the CU in the table of all CUs in the index file. */
16591 unsigned int previous_cu_index
;
16592 /* Start address of the CU. */
16593 CORE_ADDR previous_cu_start
;
16596 /* Write an address entry to OBSTACK. */
16599 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16600 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16602 offset_type cu_index_to_write
;
16604 CORE_ADDR baseaddr
;
16606 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16608 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16609 obstack_grow (obstack
, addr
, 8);
16610 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16611 obstack_grow (obstack
, addr
, 8);
16612 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16613 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16616 /* Worker function for traversing an addrmap to build the address table. */
16619 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
16621 struct addrmap_index_data
*data
= datap
;
16622 struct partial_symtab
*pst
= obj
;
16623 offset_type cu_index
;
16626 if (data
->previous_valid
)
16627 add_address_entry (data
->objfile
, data
->addr_obstack
,
16628 data
->previous_cu_start
, start_addr
,
16629 data
->previous_cu_index
);
16631 data
->previous_cu_start
= start_addr
;
16634 struct psymtab_cu_index_map find_map
, *map
;
16635 find_map
.psymtab
= pst
;
16636 map
= htab_find (data
->cu_index_htab
, &find_map
);
16637 gdb_assert (map
!= NULL
);
16638 data
->previous_cu_index
= map
->cu_index
;
16639 data
->previous_valid
= 1;
16642 data
->previous_valid
= 0;
16647 /* Write OBJFILE's address map to OBSTACK.
16648 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16649 in the index file. */
16652 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
16653 htab_t cu_index_htab
)
16655 struct addrmap_index_data addrmap_index_data
;
16657 /* When writing the address table, we have to cope with the fact that
16658 the addrmap iterator only provides the start of a region; we have to
16659 wait until the next invocation to get the start of the next region. */
16661 addrmap_index_data
.objfile
= objfile
;
16662 addrmap_index_data
.addr_obstack
= obstack
;
16663 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
16664 addrmap_index_data
.previous_valid
= 0;
16666 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
16667 &addrmap_index_data
);
16669 /* It's highly unlikely the last entry (end address = 0xff...ff)
16670 is valid, but we should still handle it.
16671 The end address is recorded as the start of the next region, but that
16672 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16674 if (addrmap_index_data
.previous_valid
)
16675 add_address_entry (objfile
, obstack
,
16676 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
16677 addrmap_index_data
.previous_cu_index
);
16680 /* Add a list of partial symbols to SYMTAB. */
16683 write_psymbols (struct mapped_symtab
*symtab
,
16685 struct partial_symbol
**psymp
,
16687 offset_type cu_index
,
16690 for (; count
-- > 0; ++psymp
)
16692 void **slot
, *lookup
;
16694 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
16695 error (_("Ada is not currently supported by the index"));
16697 /* We only want to add a given psymbol once. However, we also
16698 want to account for whether it is global or static. So, we
16699 may add it twice, using slightly different values. */
16702 uintptr_t val
= 1 | (uintptr_t) *psymp
;
16704 lookup
= (void *) val
;
16709 /* Only add a given psymbol once. */
16710 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
16714 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (*psymp
), cu_index
);
16719 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16720 exception if there is an error. */
16723 write_obstack (FILE *file
, struct obstack
*obstack
)
16725 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
16727 != obstack_object_size (obstack
))
16728 error (_("couldn't data write to file"));
16731 /* Unlink a file if the argument is not NULL. */
16734 unlink_if_set (void *p
)
16736 char **filename
= p
;
16738 unlink (*filename
);
16741 /* A helper struct used when iterating over debug_types. */
16742 struct signatured_type_index_data
16744 struct objfile
*objfile
;
16745 struct mapped_symtab
*symtab
;
16746 struct obstack
*types_list
;
16751 /* A helper function that writes a single signatured_type to an
16755 write_one_signatured_type (void **slot
, void *d
)
16757 struct signatured_type_index_data
*info
= d
;
16758 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
16759 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
16760 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16763 write_psymbols (info
->symtab
,
16765 info
->objfile
->global_psymbols
.list
16766 + psymtab
->globals_offset
,
16767 psymtab
->n_global_syms
, info
->cu_index
,
16769 write_psymbols (info
->symtab
,
16771 info
->objfile
->static_psymbols
.list
16772 + psymtab
->statics_offset
,
16773 psymtab
->n_static_syms
, info
->cu_index
,
16776 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->per_cu
.offset
);
16777 obstack_grow (info
->types_list
, val
, 8);
16778 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
16779 obstack_grow (info
->types_list
, val
, 8);
16780 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
16781 obstack_grow (info
->types_list
, val
, 8);
16788 /* Create an index file for OBJFILE in the directory DIR. */
16791 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
16793 struct cleanup
*cleanup
;
16794 char *filename
, *cleanup_filename
;
16795 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
16796 struct obstack cu_list
, types_cu_list
;
16799 struct mapped_symtab
*symtab
;
16800 offset_type val
, size_of_contents
, total_len
;
16804 htab_t cu_index_htab
;
16805 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
16807 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
16810 if (dwarf2_per_objfile
->using_index
)
16811 error (_("Cannot use an index to create the index"));
16813 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
16814 error (_("Cannot make an index when the file has multiple .debug_types sections"));
16816 if (stat (objfile
->name
, &st
) < 0)
16817 perror_with_name (objfile
->name
);
16819 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
16820 INDEX_SUFFIX
, (char *) NULL
);
16821 cleanup
= make_cleanup (xfree
, filename
);
16823 out_file
= fopen (filename
, "wb");
16825 error (_("Can't open `%s' for writing"), filename
);
16827 cleanup_filename
= filename
;
16828 make_cleanup (unlink_if_set
, &cleanup_filename
);
16830 symtab
= create_mapped_symtab ();
16831 make_cleanup (cleanup_mapped_symtab
, symtab
);
16833 obstack_init (&addr_obstack
);
16834 make_cleanup_obstack_free (&addr_obstack
);
16836 obstack_init (&cu_list
);
16837 make_cleanup_obstack_free (&cu_list
);
16839 obstack_init (&types_cu_list
);
16840 make_cleanup_obstack_free (&types_cu_list
);
16842 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
16843 NULL
, xcalloc
, xfree
);
16844 make_cleanup_htab_delete (psyms_seen
);
16846 /* While we're scanning CU's create a table that maps a psymtab pointer
16847 (which is what addrmap records) to its index (which is what is recorded
16848 in the index file). This will later be needed to write the address
16850 cu_index_htab
= htab_create_alloc (100,
16851 hash_psymtab_cu_index
,
16852 eq_psymtab_cu_index
,
16853 NULL
, xcalloc
, xfree
);
16854 make_cleanup_htab_delete (cu_index_htab
);
16855 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
16856 xmalloc (sizeof (struct psymtab_cu_index_map
)
16857 * dwarf2_per_objfile
->n_comp_units
);
16858 make_cleanup (xfree
, psymtab_cu_index_map
);
16860 /* The CU list is already sorted, so we don't need to do additional
16861 work here. Also, the debug_types entries do not appear in
16862 all_comp_units, but only in their own hash table. */
16863 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
16865 struct dwarf2_per_cu_data
*per_cu
16866 = dwarf2_per_objfile
->all_comp_units
[i
];
16867 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16869 struct psymtab_cu_index_map
*map
;
16872 write_psymbols (symtab
,
16874 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
16875 psymtab
->n_global_syms
, i
,
16877 write_psymbols (symtab
,
16879 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
16880 psymtab
->n_static_syms
, i
,
16883 map
= &psymtab_cu_index_map
[i
];
16884 map
->psymtab
= psymtab
;
16886 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
16887 gdb_assert (slot
!= NULL
);
16888 gdb_assert (*slot
== NULL
);
16891 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
16892 obstack_grow (&cu_list
, val
, 8);
16893 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
16894 obstack_grow (&cu_list
, val
, 8);
16897 /* Dump the address map. */
16898 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
16900 /* Write out the .debug_type entries, if any. */
16901 if (dwarf2_per_objfile
->signatured_types
)
16903 struct signatured_type_index_data sig_data
;
16905 sig_data
.objfile
= objfile
;
16906 sig_data
.symtab
= symtab
;
16907 sig_data
.types_list
= &types_cu_list
;
16908 sig_data
.psyms_seen
= psyms_seen
;
16909 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
16910 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
16911 write_one_signatured_type
, &sig_data
);
16914 obstack_init (&constant_pool
);
16915 make_cleanup_obstack_free (&constant_pool
);
16916 obstack_init (&symtab_obstack
);
16917 make_cleanup_obstack_free (&symtab_obstack
);
16918 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
16920 obstack_init (&contents
);
16921 make_cleanup_obstack_free (&contents
);
16922 size_of_contents
= 6 * sizeof (offset_type
);
16923 total_len
= size_of_contents
;
16925 /* The version number. */
16926 val
= MAYBE_SWAP (5);
16927 obstack_grow (&contents
, &val
, sizeof (val
));
16929 /* The offset of the CU list from the start of the file. */
16930 val
= MAYBE_SWAP (total_len
);
16931 obstack_grow (&contents
, &val
, sizeof (val
));
16932 total_len
+= obstack_object_size (&cu_list
);
16934 /* The offset of the types CU list from the start of the file. */
16935 val
= MAYBE_SWAP (total_len
);
16936 obstack_grow (&contents
, &val
, sizeof (val
));
16937 total_len
+= obstack_object_size (&types_cu_list
);
16939 /* The offset of the address table from the start of the file. */
16940 val
= MAYBE_SWAP (total_len
);
16941 obstack_grow (&contents
, &val
, sizeof (val
));
16942 total_len
+= obstack_object_size (&addr_obstack
);
16944 /* The offset of the symbol table from the start of the file. */
16945 val
= MAYBE_SWAP (total_len
);
16946 obstack_grow (&contents
, &val
, sizeof (val
));
16947 total_len
+= obstack_object_size (&symtab_obstack
);
16949 /* The offset of the constant pool from the start of the file. */
16950 val
= MAYBE_SWAP (total_len
);
16951 obstack_grow (&contents
, &val
, sizeof (val
));
16952 total_len
+= obstack_object_size (&constant_pool
);
16954 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
16956 write_obstack (out_file
, &contents
);
16957 write_obstack (out_file
, &cu_list
);
16958 write_obstack (out_file
, &types_cu_list
);
16959 write_obstack (out_file
, &addr_obstack
);
16960 write_obstack (out_file
, &symtab_obstack
);
16961 write_obstack (out_file
, &constant_pool
);
16965 /* We want to keep the file, so we set cleanup_filename to NULL
16966 here. See unlink_if_set. */
16967 cleanup_filename
= NULL
;
16969 do_cleanups (cleanup
);
16972 /* Implementation of the `save gdb-index' command.
16974 Note that the file format used by this command is documented in the
16975 GDB manual. Any changes here must be documented there. */
16978 save_gdb_index_command (char *arg
, int from_tty
)
16980 struct objfile
*objfile
;
16983 error (_("usage: save gdb-index DIRECTORY"));
16985 ALL_OBJFILES (objfile
)
16989 /* If the objfile does not correspond to an actual file, skip it. */
16990 if (stat (objfile
->name
, &st
) < 0)
16993 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16994 if (dwarf2_per_objfile
)
16996 volatile struct gdb_exception except
;
16998 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17000 write_psymtabs_to_index (objfile
, arg
);
17002 if (except
.reason
< 0)
17003 exception_fprintf (gdb_stderr
, except
,
17004 _("Error while writing index for `%s': "),
17012 int dwarf2_always_disassemble
;
17015 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17016 struct cmd_list_element
*c
, const char *value
)
17018 fprintf_filtered (file
,
17019 _("Whether to always disassemble "
17020 "DWARF expressions is %s.\n"),
17025 show_check_physname (struct ui_file
*file
, int from_tty
,
17026 struct cmd_list_element
*c
, const char *value
)
17028 fprintf_filtered (file
,
17029 _("Whether to check \"physname\" is %s.\n"),
17033 void _initialize_dwarf2_read (void);
17036 _initialize_dwarf2_read (void)
17038 struct cmd_list_element
*c
;
17040 dwarf2_objfile_data_key
17041 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17043 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17044 Set DWARF 2 specific variables.\n\
17045 Configure DWARF 2 variables such as the cache size"),
17046 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17047 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17049 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17050 Show DWARF 2 specific variables\n\
17051 Show DWARF 2 variables such as the cache size"),
17052 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17053 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17055 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17056 &dwarf2_max_cache_age
, _("\
17057 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17058 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17059 A higher limit means that cached compilation units will be stored\n\
17060 in memory longer, and more total memory will be used. Zero disables\n\
17061 caching, which can slow down startup."),
17063 show_dwarf2_max_cache_age
,
17064 &set_dwarf2_cmdlist
,
17065 &show_dwarf2_cmdlist
);
17067 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17068 &dwarf2_always_disassemble
, _("\
17069 Set whether `info address' always disassembles DWARF expressions."), _("\
17070 Show whether `info address' always disassembles DWARF expressions."), _("\
17071 When enabled, DWARF expressions are always printed in an assembly-like\n\
17072 syntax. When disabled, expressions will be printed in a more\n\
17073 conversational style, when possible."),
17075 show_dwarf2_always_disassemble
,
17076 &set_dwarf2_cmdlist
,
17077 &show_dwarf2_cmdlist
);
17079 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
17080 Set debugging of the dwarf2 DIE reader."), _("\
17081 Show debugging of the dwarf2 DIE reader."), _("\
17082 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17083 The value is the maximum depth to print."),
17086 &setdebuglist
, &showdebuglist
);
17088 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
17089 Set cross-checking of \"physname\" code against demangler."), _("\
17090 Show cross-checking of \"physname\" code against demangler."), _("\
17091 When enabled, GDB's internal \"physname\" code is checked against\n\
17093 NULL
, show_check_physname
,
17094 &setdebuglist
, &showdebuglist
);
17096 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
17098 Save a gdb-index file.\n\
17099 Usage: save gdb-index DIRECTORY"),
17101 set_cmd_completer (c
, filename_completer
);