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/>. */
35 #include "gdb-demangle.h"
36 #include "expression.h"
37 #include "filenames.h" /* for DOSish file names */
40 #include "complaints.h"
42 #include "dwarf2expr.h"
43 #include "dwarf2loc.h"
44 #include "cp-support.h"
50 #include "typeprint.h"
53 #include "exceptions.h"
55 #include "completer.h"
62 #include "gdb_string.h"
63 #include "gdb_assert.h"
64 #include <sys/types.h>
71 #define MAP_FAILED ((void *) -1)
75 typedef struct symbol
*symbolp
;
79 /* .debug_info header for a compilation unit
80 Because of alignment constraints, this structure has padding and cannot
81 be mapped directly onto the beginning of the .debug_info section. */
82 typedef struct comp_unit_header
84 unsigned int length
; /* length of the .debug_info
86 unsigned short version
; /* version number -- 2 for DWARF
88 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
89 unsigned char addr_size
; /* byte size of an address -- 4 */
92 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
95 /* .debug_line statement program prologue
96 Because of alignment constraints, this structure has padding and cannot
97 be mapped directly onto the beginning of the .debug_info section. */
98 typedef struct statement_prologue
100 unsigned int total_length
; /* byte length of the statement
102 unsigned short version
; /* version number -- 2 for DWARF
104 unsigned int prologue_length
; /* # bytes between prologue &
106 unsigned char minimum_instruction_length
; /* byte size of
108 unsigned char default_is_stmt
; /* initial value of is_stmt
111 unsigned char line_range
;
112 unsigned char opcode_base
; /* number assigned to first special
114 unsigned char *standard_opcode_lengths
;
118 /* When non-zero, dump DIEs after they are read in. */
119 static int dwarf2_die_debug
= 0;
121 /* When non-zero, cross-check physname against demangler. */
122 static int check_physname
= 0;
126 /* When set, the file that we're processing is known to have debugging
127 info for C++ namespaces. GCC 3.3.x did not produce this information,
128 but later versions do. */
130 static int processing_has_namespace_info
;
132 static const struct objfile_data
*dwarf2_objfile_data_key
;
134 struct dwarf2_section_info
139 /* Not NULL if the section was actually mmapped. */
141 /* Page aligned size of mmapped area. */
142 bfd_size_type map_len
;
143 /* True if we have tried to read this section. */
147 typedef struct dwarf2_section_info dwarf2_section_info_def
;
148 DEF_VEC_O (dwarf2_section_info_def
);
150 /* All offsets in the index are of this type. It must be
151 architecture-independent. */
152 typedef uint32_t offset_type
;
154 DEF_VEC_I (offset_type
);
156 /* A description of the mapped index. The file format is described in
157 a comment by the code that writes the index. */
160 /* Index data format version. */
163 /* The total length of the buffer. */
166 /* A pointer to the address table data. */
167 const gdb_byte
*address_table
;
169 /* Size of the address table data in bytes. */
170 offset_type address_table_size
;
172 /* The symbol table, implemented as a hash table. */
173 const offset_type
*symbol_table
;
175 /* Size in slots, each slot is 2 offset_types. */
176 offset_type symbol_table_slots
;
178 /* A pointer to the constant pool. */
179 const char *constant_pool
;
182 /* Collection of data recorded per objfile.
183 This hangs off of dwarf2_objfile_data_key. */
185 struct dwarf2_per_objfile
187 struct dwarf2_section_info info
;
188 struct dwarf2_section_info abbrev
;
189 struct dwarf2_section_info line
;
190 struct dwarf2_section_info loc
;
191 struct dwarf2_section_info macinfo
;
192 struct dwarf2_section_info macro
;
193 struct dwarf2_section_info str
;
194 struct dwarf2_section_info ranges
;
195 struct dwarf2_section_info frame
;
196 struct dwarf2_section_info eh_frame
;
197 struct dwarf2_section_info gdb_index
;
199 VEC (dwarf2_section_info_def
) *types
;
202 struct objfile
*objfile
;
204 /* A list of all the compilation units. This is used to locate
205 the target compilation unit of a particular reference. */
206 struct dwarf2_per_cu_data
**all_comp_units
;
208 /* The number of compilation units in ALL_COMP_UNITS. */
211 /* The number of .debug_types-related CUs. */
212 int n_type_comp_units
;
214 /* The .debug_types-related CUs. */
215 struct dwarf2_per_cu_data
**type_comp_units
;
217 /* A chain of compilation units that are currently read in, so that
218 they can be freed later. */
219 struct dwarf2_per_cu_data
*read_in_chain
;
221 /* A table mapping .debug_types signatures to its signatured_type entry.
222 This is NULL if the .debug_types section hasn't been read in yet. */
223 htab_t signatured_types
;
225 /* A flag indicating wether this objfile has a section loaded at a
227 int has_section_at_zero
;
229 /* True if we are using the mapped index,
230 or we are faking it for OBJF_READNOW's sake. */
231 unsigned char using_index
;
233 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
234 struct mapped_index
*index_table
;
236 /* When using index_table, this keeps track of all quick_file_names entries.
237 TUs can share line table entries with CUs or other TUs, and there can be
238 a lot more TUs than unique line tables, so we maintain a separate table
239 of all line table entries to support the sharing. */
240 htab_t quick_file_names_table
;
242 /* Set during partial symbol reading, to prevent queueing of full
244 int reading_partial_symbols
;
246 /* Table mapping type .debug_info DIE offsets to types.
247 This is NULL if not allocated yet.
248 It (currently) makes sense to allocate debug_types_type_hash lazily.
249 To keep things simple we allocate both lazily. */
250 htab_t debug_info_type_hash
;
252 /* Table mapping type .debug_types DIE offsets to types.
253 This is NULL if not allocated yet. */
254 htab_t debug_types_type_hash
;
257 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
259 /* Default names of the debugging sections. */
261 /* Note that if the debugging section has been compressed, it might
262 have a name like .zdebug_info. */
264 static const struct dwarf2_debug_sections dwarf2_elf_names
=
266 { ".debug_info", ".zdebug_info" },
267 { ".debug_abbrev", ".zdebug_abbrev" },
268 { ".debug_line", ".zdebug_line" },
269 { ".debug_loc", ".zdebug_loc" },
270 { ".debug_macinfo", ".zdebug_macinfo" },
271 { ".debug_macro", ".zdebug_macro" },
272 { ".debug_str", ".zdebug_str" },
273 { ".debug_ranges", ".zdebug_ranges" },
274 { ".debug_types", ".zdebug_types" },
275 { ".debug_frame", ".zdebug_frame" },
276 { ".eh_frame", NULL
},
277 { ".gdb_index", ".zgdb_index" },
281 /* local data types */
283 /* We hold several abbreviation tables in memory at the same time. */
284 #ifndef ABBREV_HASH_SIZE
285 #define ABBREV_HASH_SIZE 121
288 /* The data in a compilation unit header, after target2host
289 translation, looks like this. */
290 struct comp_unit_head
294 unsigned char addr_size
;
295 unsigned char signed_addr_p
;
296 unsigned int abbrev_offset
;
298 /* Size of file offsets; either 4 or 8. */
299 unsigned int offset_size
;
301 /* Size of the length field; either 4 or 12. */
302 unsigned int initial_length_size
;
304 /* Offset to the first byte of this compilation unit header in the
305 .debug_info section, for resolving relative reference dies. */
308 /* Offset to first die in this cu from the start of the cu.
309 This will be the first byte following the compilation unit header. */
310 unsigned int first_die_offset
;
313 /* Type used for delaying computation of method physnames.
314 See comments for compute_delayed_physnames. */
315 struct delayed_method_info
317 /* The type to which the method is attached, i.e., its parent class. */
320 /* The index of the method in the type's function fieldlists. */
323 /* The index of the method in the fieldlist. */
326 /* The name of the DIE. */
329 /* The DIE associated with this method. */
330 struct die_info
*die
;
333 typedef struct delayed_method_info delayed_method_info
;
334 DEF_VEC_O (delayed_method_info
);
336 /* Internal state when decoding a particular compilation unit. */
339 /* The objfile containing this compilation unit. */
340 struct objfile
*objfile
;
342 /* The header of the compilation unit. */
343 struct comp_unit_head header
;
345 /* Base address of this compilation unit. */
346 CORE_ADDR base_address
;
348 /* Non-zero if base_address has been set. */
351 /* The language we are debugging. */
352 enum language language
;
353 const struct language_defn
*language_defn
;
355 const char *producer
;
357 /* The generic symbol table building routines have separate lists for
358 file scope symbols and all all other scopes (local scopes). So
359 we need to select the right one to pass to add_symbol_to_list().
360 We do it by keeping a pointer to the correct list in list_in_scope.
362 FIXME: The original dwarf code just treated the file scope as the
363 first local scope, and all other local scopes as nested local
364 scopes, and worked fine. Check to see if we really need to
365 distinguish these in buildsym.c. */
366 struct pending
**list_in_scope
;
368 /* DWARF abbreviation table associated with this compilation unit. */
369 struct abbrev_info
**dwarf2_abbrevs
;
371 /* Storage for the abbrev table. */
372 struct obstack abbrev_obstack
;
374 /* Hash table holding all the loaded partial DIEs. */
377 /* Storage for things with the same lifetime as this read-in compilation
378 unit, including partial DIEs. */
379 struct obstack comp_unit_obstack
;
381 /* When multiple dwarf2_cu structures are living in memory, this field
382 chains them all together, so that they can be released efficiently.
383 We will probably also want a generation counter so that most-recently-used
384 compilation units are cached... */
385 struct dwarf2_per_cu_data
*read_in_chain
;
387 /* Backchain to our per_cu entry if the tree has been built. */
388 struct dwarf2_per_cu_data
*per_cu
;
390 /* How many compilation units ago was this CU last referenced? */
393 /* A hash table of die offsets for following references. */
396 /* Full DIEs if read in. */
397 struct die_info
*dies
;
399 /* A set of pointers to dwarf2_per_cu_data objects for compilation
400 units referenced by this one. Only set during full symbol processing;
401 partial symbol tables do not have dependencies. */
404 /* Header data from the line table, during full symbol processing. */
405 struct line_header
*line_header
;
407 /* A list of methods which need to have physnames computed
408 after all type information has been read. */
409 VEC (delayed_method_info
) *method_list
;
411 /* To be copied to symtab->call_site_htab. */
412 htab_t call_site_htab
;
414 /* Mark used when releasing cached dies. */
415 unsigned int mark
: 1;
417 /* This flag will be set if this compilation unit might include
418 inter-compilation-unit references. */
419 unsigned int has_form_ref_addr
: 1;
421 /* This flag will be set if this compilation unit includes any
422 DW_TAG_namespace DIEs. If we know that there are explicit
423 DIEs for namespaces, we don't need to try to infer them
424 from mangled names. */
425 unsigned int has_namespace_info
: 1;
427 /* This CU references .debug_loc. See the symtab->locations_valid field.
428 This test is imperfect as there may exist optimized debug code not using
429 any location list and still facing inlining issues if handled as
430 unoptimized code. For a future better test see GCC PR other/32998. */
431 unsigned int has_loclist
: 1;
434 /* Persistent data held for a compilation unit, even when not
435 processing it. We put a pointer to this structure in the
436 read_symtab_private field of the psymtab. */
438 struct dwarf2_per_cu_data
440 /* The start offset and length of this compilation unit. 2**29-1
441 bytes should suffice to store the length of any compilation unit
442 - if it doesn't, GDB will fall over anyway.
443 NOTE: Unlike comp_unit_head.length, this length includes
444 initial_length_size. */
446 unsigned int length
: 29;
448 /* Flag indicating this compilation unit will be read in before
449 any of the current compilation units are processed. */
450 unsigned int queued
: 1;
452 /* This flag will be set if we need to load absolutely all DIEs
453 for this compilation unit, instead of just the ones we think
454 are interesting. It gets set if we look for a DIE in the
455 hash table and don't find it. */
456 unsigned int load_all_dies
: 1;
458 /* Non-null if this CU is from .debug_types; in which case it points
459 to the section. Otherwise it's from .debug_info. */
460 struct dwarf2_section_info
*debug_types_section
;
462 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
463 of the CU cache it gets reset to NULL again. */
464 struct dwarf2_cu
*cu
;
466 /* The corresponding objfile.
467 Normally we can get the objfile from dwarf2_per_objfile.
468 However we can enter this file with just a "per_cu" handle. */
469 struct objfile
*objfile
;
471 /* When using partial symbol tables, the 'psymtab' field is active.
472 Otherwise the 'quick' field is active. */
475 /* The partial symbol table associated with this compilation unit,
476 or NULL for partial units (which do not have an associated
478 struct partial_symtab
*psymtab
;
480 /* Data needed by the "quick" functions. */
481 struct dwarf2_per_cu_quick_data
*quick
;
485 /* Entry in the signatured_types hash table. */
487 struct signatured_type
491 /* Offset in .debug_types of the type defined by this TU. */
492 unsigned int type_offset
;
494 /* The CU(/TU) of this type. */
495 struct dwarf2_per_cu_data per_cu
;
498 /* Struct used to pass misc. parameters to read_die_and_children, et
499 al. which are used for both .debug_info and .debug_types dies.
500 All parameters here are unchanging for the life of the call. This
501 struct exists to abstract away the constant parameters of die
504 struct die_reader_specs
506 /* The bfd of this objfile. */
509 /* The CU of the DIE we are parsing. */
510 struct dwarf2_cu
*cu
;
512 /* Pointer to start of section buffer.
513 This is either the start of .debug_info or .debug_types. */
514 const gdb_byte
*buffer
;
517 /* The line number information for a compilation unit (found in the
518 .debug_line section) begins with a "statement program header",
519 which contains the following information. */
522 unsigned int total_length
;
523 unsigned short version
;
524 unsigned int header_length
;
525 unsigned char minimum_instruction_length
;
526 unsigned char maximum_ops_per_instruction
;
527 unsigned char default_is_stmt
;
529 unsigned char line_range
;
530 unsigned char opcode_base
;
532 /* standard_opcode_lengths[i] is the number of operands for the
533 standard opcode whose value is i. This means that
534 standard_opcode_lengths[0] is unused, and the last meaningful
535 element is standard_opcode_lengths[opcode_base - 1]. */
536 unsigned char *standard_opcode_lengths
;
538 /* The include_directories table. NOTE! These strings are not
539 allocated with xmalloc; instead, they are pointers into
540 debug_line_buffer. If you try to free them, `free' will get
542 unsigned int num_include_dirs
, include_dirs_size
;
545 /* The file_names table. NOTE! These strings are not allocated
546 with xmalloc; instead, they are pointers into debug_line_buffer.
547 Don't try to free them directly. */
548 unsigned int num_file_names
, file_names_size
;
552 unsigned int dir_index
;
553 unsigned int mod_time
;
555 int included_p
; /* Non-zero if referenced by the Line Number Program. */
556 struct symtab
*symtab
; /* The associated symbol table, if any. */
559 /* The start and end of the statement program following this
560 header. These point into dwarf2_per_objfile->line_buffer. */
561 gdb_byte
*statement_program_start
, *statement_program_end
;
564 /* When we construct a partial symbol table entry we only
565 need this much information. */
566 struct partial_die_info
568 /* Offset of this DIE. */
571 /* DWARF-2 tag for this DIE. */
572 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
574 /* Assorted flags describing the data found in this DIE. */
575 unsigned int has_children
: 1;
576 unsigned int is_external
: 1;
577 unsigned int is_declaration
: 1;
578 unsigned int has_type
: 1;
579 unsigned int has_specification
: 1;
580 unsigned int has_pc_info
: 1;
582 /* Flag set if the SCOPE field of this structure has been
584 unsigned int scope_set
: 1;
586 /* Flag set if the DIE has a byte_size attribute. */
587 unsigned int has_byte_size
: 1;
589 /* Flag set if any of the DIE's children are template arguments. */
590 unsigned int has_template_arguments
: 1;
592 /* Flag set if fixup_partial_die has been called on this die. */
593 unsigned int fixup_called
: 1;
595 /* The name of this DIE. Normally the value of DW_AT_name, but
596 sometimes a default name for unnamed DIEs. */
599 /* The linkage name, if present. */
600 const char *linkage_name
;
602 /* The scope to prepend to our children. This is generally
603 allocated on the comp_unit_obstack, so will disappear
604 when this compilation unit leaves the cache. */
607 /* The location description associated with this DIE, if any. */
608 struct dwarf_block
*locdesc
;
610 /* If HAS_PC_INFO, the PC range associated with this DIE. */
614 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
615 DW_AT_sibling, if any. */
616 /* NOTE: This member isn't strictly necessary, read_partial_die could
617 return DW_AT_sibling values to its caller load_partial_dies. */
620 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
621 DW_AT_specification (or DW_AT_abstract_origin or
623 unsigned int spec_offset
;
625 /* Pointers to this DIE's parent, first child, and next sibling,
627 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
630 /* This data structure holds the information of an abbrev. */
633 unsigned int number
; /* number identifying abbrev */
634 enum dwarf_tag tag
; /* dwarf tag */
635 unsigned short has_children
; /* boolean */
636 unsigned short num_attrs
; /* number of attributes */
637 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
638 struct abbrev_info
*next
; /* next in chain */
643 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
644 ENUM_BITFIELD(dwarf_form
) form
: 16;
647 /* Attributes have a name and a value. */
650 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
651 ENUM_BITFIELD(dwarf_form
) form
: 15;
653 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
654 field should be in u.str (existing only for DW_STRING) but it is kept
655 here for better struct attribute alignment. */
656 unsigned int string_is_canonical
: 1;
661 struct dwarf_block
*blk
;
665 struct signatured_type
*signatured_type
;
670 /* This data structure holds a complete die structure. */
673 /* DWARF-2 tag for this DIE. */
674 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
676 /* Number of attributes */
677 unsigned char num_attrs
;
679 /* True if we're presently building the full type name for the
680 type derived from this DIE. */
681 unsigned char building_fullname
: 1;
686 /* Offset in .debug_info or .debug_types section. */
689 /* The dies in a compilation unit form an n-ary tree. PARENT
690 points to this die's parent; CHILD points to the first child of
691 this node; and all the children of a given node are chained
692 together via their SIBLING fields. */
693 struct die_info
*child
; /* Its first child, if any. */
694 struct die_info
*sibling
; /* Its next sibling, if any. */
695 struct die_info
*parent
; /* Its parent, if any. */
697 /* An array of attributes, with NUM_ATTRS elements. There may be
698 zero, but it's not common and zero-sized arrays are not
699 sufficiently portable C. */
700 struct attribute attrs
[1];
703 /* Get at parts of an attribute structure. */
705 #define DW_STRING(attr) ((attr)->u.str)
706 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
707 #define DW_UNSND(attr) ((attr)->u.unsnd)
708 #define DW_BLOCK(attr) ((attr)->u.blk)
709 #define DW_SND(attr) ((attr)->u.snd)
710 #define DW_ADDR(attr) ((attr)->u.addr)
711 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
713 /* Blocks are a bunch of untyped bytes. */
718 /* Valid only if SIZE is not zero. */
722 #ifndef ATTR_ALLOC_CHUNK
723 #define ATTR_ALLOC_CHUNK 4
726 /* Allocate fields for structs, unions and enums in this size. */
727 #ifndef DW_FIELD_ALLOC_CHUNK
728 #define DW_FIELD_ALLOC_CHUNK 4
731 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
732 but this would require a corresponding change in unpack_field_as_long
734 static int bits_per_byte
= 8;
736 /* The routines that read and process dies for a C struct or C++ class
737 pass lists of data member fields and lists of member function fields
738 in an instance of a field_info structure, as defined below. */
741 /* List of data member and baseclasses fields. */
744 struct nextfield
*next
;
749 *fields
, *baseclasses
;
751 /* Number of fields (including baseclasses). */
754 /* Number of baseclasses. */
757 /* Set if the accesibility of one of the fields is not public. */
758 int non_public_fields
;
760 /* Member function fields array, entries are allocated in the order they
761 are encountered in the object file. */
764 struct nextfnfield
*next
;
765 struct fn_field fnfield
;
769 /* Member function fieldlist array, contains name of possibly overloaded
770 member function, number of overloaded member functions and a pointer
771 to the head of the member function field chain. */
776 struct nextfnfield
*head
;
780 /* Number of entries in the fnfieldlists array. */
783 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
784 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
785 struct typedef_field_list
787 struct typedef_field field
;
788 struct typedef_field_list
*next
;
791 unsigned typedef_field_list_count
;
794 /* One item on the queue of compilation units to read in full symbols
796 struct dwarf2_queue_item
798 struct dwarf2_per_cu_data
*per_cu
;
799 struct dwarf2_queue_item
*next
;
802 /* The current queue. */
803 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
805 /* Loaded secondary compilation units are kept in memory until they
806 have not been referenced for the processing of this many
807 compilation units. Set this to zero to disable caching. Cache
808 sizes of up to at least twenty will improve startup time for
809 typical inter-CU-reference binaries, at an obvious memory cost. */
810 static int dwarf2_max_cache_age
= 5;
812 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
813 struct cmd_list_element
*c
, const char *value
)
815 fprintf_filtered (file
, _("The upper bound on the age of cached "
816 "dwarf2 compilation units is %s.\n"),
821 /* Various complaints about symbol reading that don't abort the process. */
824 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
826 complaint (&symfile_complaints
,
827 _("statement list doesn't fit in .debug_line section"));
831 dwarf2_debug_line_missing_file_complaint (void)
833 complaint (&symfile_complaints
,
834 _(".debug_line section has line data without a file"));
838 dwarf2_debug_line_missing_end_sequence_complaint (void)
840 complaint (&symfile_complaints
,
841 _(".debug_line section has line "
842 "program sequence without an end"));
846 dwarf2_complex_location_expr_complaint (void)
848 complaint (&symfile_complaints
, _("location expression too complex"));
852 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
855 complaint (&symfile_complaints
,
856 _("const value length mismatch for '%s', got %d, expected %d"),
861 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
863 complaint (&symfile_complaints
,
864 _("macro info runs off end of `%s' section"),
865 section
->asection
->name
);
869 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
871 complaint (&symfile_complaints
,
872 _("macro debug info contains a "
873 "malformed macro definition:\n`%s'"),
878 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
880 complaint (&symfile_complaints
,
881 _("invalid attribute class or form for '%s' in '%s'"),
885 /* local function prototypes */
887 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
889 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
892 static void dwarf2_find_base_address (struct die_info
*die
,
893 struct dwarf2_cu
*cu
);
895 static void dwarf2_build_psymtabs_hard (struct objfile
*);
897 static void scan_partial_symbols (struct partial_die_info
*,
898 CORE_ADDR
*, CORE_ADDR
*,
899 int, struct dwarf2_cu
*);
901 static void add_partial_symbol (struct partial_die_info
*,
904 static void add_partial_namespace (struct partial_die_info
*pdi
,
905 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
906 int need_pc
, struct dwarf2_cu
*cu
);
908 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
909 CORE_ADDR
*highpc
, int need_pc
,
910 struct dwarf2_cu
*cu
);
912 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
913 struct dwarf2_cu
*cu
);
915 static void add_partial_subprogram (struct partial_die_info
*pdi
,
916 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
917 int need_pc
, struct dwarf2_cu
*cu
);
919 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
920 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
921 bfd
*abfd
, struct dwarf2_cu
*cu
);
923 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
925 static void psymtab_to_symtab_1 (struct partial_symtab
*);
927 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
929 static void dwarf2_free_abbrev_table (void *);
931 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
933 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
936 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
939 static struct partial_die_info
*load_partial_dies (bfd
*,
940 gdb_byte
*, gdb_byte
*,
941 int, struct dwarf2_cu
*);
943 static gdb_byte
*read_partial_die (struct partial_die_info
*,
944 struct abbrev_info
*abbrev
,
946 gdb_byte
*, gdb_byte
*,
949 static struct partial_die_info
*find_partial_die (unsigned int,
952 static void fixup_partial_die (struct partial_die_info
*,
955 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
956 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
958 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
959 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
961 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
963 static int read_1_signed_byte (bfd
*, gdb_byte
*);
965 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
967 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
969 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
971 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
974 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
976 static LONGEST read_checked_initial_length_and_offset
977 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
978 unsigned int *, unsigned int *);
980 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
983 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
985 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
987 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
989 static char *read_indirect_string (bfd
*, gdb_byte
*,
990 const struct comp_unit_head
*,
993 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
995 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
997 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
999 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1001 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1002 struct dwarf2_cu
*);
1004 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1006 struct dwarf2_cu
*);
1008 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1009 struct dwarf2_cu
*cu
);
1011 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1013 static struct die_info
*die_specification (struct die_info
*die
,
1014 struct dwarf2_cu
**);
1016 static void free_line_header (struct line_header
*lh
);
1018 static void add_file_name (struct line_header
*, char *, unsigned int,
1019 unsigned int, unsigned int);
1021 static struct line_header
*(dwarf_decode_line_header
1022 (unsigned int offset
,
1023 bfd
*abfd
, struct dwarf2_cu
*cu
));
1025 static void dwarf_decode_lines (struct line_header
*, const char *, bfd
*,
1026 struct dwarf2_cu
*, struct partial_symtab
*);
1028 static void dwarf2_start_subfile (char *, const char *, const char *);
1030 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1031 struct dwarf2_cu
*);
1033 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1034 struct dwarf2_cu
*, struct symbol
*);
1036 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1037 struct dwarf2_cu
*);
1039 static void dwarf2_const_value_attr (struct attribute
*attr
,
1042 struct obstack
*obstack
,
1043 struct dwarf2_cu
*cu
, long *value
,
1045 struct dwarf2_locexpr_baton
**baton
);
1047 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1049 static int need_gnat_info (struct dwarf2_cu
*);
1051 static struct type
*die_descriptive_type (struct die_info
*,
1052 struct dwarf2_cu
*);
1054 static void set_descriptive_type (struct type
*, struct die_info
*,
1055 struct dwarf2_cu
*);
1057 static struct type
*die_containing_type (struct die_info
*,
1058 struct dwarf2_cu
*);
1060 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1061 struct dwarf2_cu
*);
1063 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1065 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1067 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1069 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1070 const char *suffix
, int physname
,
1071 struct dwarf2_cu
*cu
);
1073 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1075 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1077 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1079 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1081 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1083 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1084 struct dwarf2_cu
*, struct partial_symtab
*);
1086 static int dwarf2_get_pc_bounds (struct die_info
*,
1087 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1088 struct partial_symtab
*);
1090 static void get_scope_pc_bounds (struct die_info
*,
1091 CORE_ADDR
*, CORE_ADDR
*,
1092 struct dwarf2_cu
*);
1094 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1095 CORE_ADDR
, struct dwarf2_cu
*);
1097 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1098 struct dwarf2_cu
*);
1100 static void dwarf2_attach_fields_to_type (struct field_info
*,
1101 struct type
*, struct dwarf2_cu
*);
1103 static void dwarf2_add_member_fn (struct field_info
*,
1104 struct die_info
*, struct type
*,
1105 struct dwarf2_cu
*);
1107 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1109 struct dwarf2_cu
*);
1111 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1113 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1115 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1117 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1119 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1121 static struct type
*read_module_type (struct die_info
*die
,
1122 struct dwarf2_cu
*cu
);
1124 static const char *namespace_name (struct die_info
*die
,
1125 int *is_anonymous
, struct dwarf2_cu
*);
1127 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1129 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1131 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1132 struct dwarf2_cu
*);
1134 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1136 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1138 gdb_byte
**new_info_ptr
,
1139 struct die_info
*parent
);
1141 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1143 gdb_byte
**new_info_ptr
,
1144 struct die_info
*parent
);
1146 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1148 gdb_byte
**new_info_ptr
,
1149 struct die_info
*parent
);
1151 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1152 struct die_info
**, gdb_byte
*,
1155 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1157 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1160 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1162 static const char *dwarf2_full_name (char *name
,
1163 struct die_info
*die
,
1164 struct dwarf2_cu
*cu
);
1166 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1167 struct dwarf2_cu
**);
1169 static char *dwarf_tag_name (unsigned int);
1171 static char *dwarf_attr_name (unsigned int);
1173 static char *dwarf_form_name (unsigned int);
1175 static char *dwarf_bool_name (unsigned int);
1177 static char *dwarf_type_encoding_name (unsigned int);
1180 static char *dwarf_cfi_name (unsigned int);
1183 static struct die_info
*sibling_die (struct die_info
*);
1185 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1187 static void dump_die_for_error (struct die_info
*);
1189 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1192 /*static*/ void dump_die (struct die_info
*, int max_level
);
1194 static void store_in_ref_table (struct die_info
*,
1195 struct dwarf2_cu
*);
1197 static int is_ref_attr (struct attribute
*);
1199 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1201 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1203 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1205 struct dwarf2_cu
**);
1207 static struct die_info
*follow_die_ref (struct die_info
*,
1209 struct dwarf2_cu
**);
1211 static struct die_info
*follow_die_sig (struct die_info
*,
1213 struct dwarf2_cu
**);
1215 static struct signatured_type
*lookup_signatured_type_at_offset
1216 (struct objfile
*objfile
,
1217 struct dwarf2_section_info
*section
,
1218 unsigned int offset
);
1220 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1221 struct dwarf2_section_info
*sect
,
1222 unsigned int offset
);
1224 static void read_signatured_type (struct signatured_type
*type_sig
);
1226 /* memory allocation interface */
1228 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1230 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1232 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1234 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1235 char *, bfd
*, struct dwarf2_cu
*,
1236 struct dwarf2_section_info
*,
1239 static int attr_form_is_block (struct attribute
*);
1241 static int attr_form_is_section_offset (struct attribute
*);
1243 static int attr_form_is_constant (struct attribute
*);
1245 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1246 struct dwarf2_loclist_baton
*baton
,
1247 struct attribute
*attr
);
1249 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1251 struct dwarf2_cu
*cu
);
1253 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1254 struct abbrev_info
*abbrev
,
1255 struct dwarf2_cu
*cu
);
1257 static void free_stack_comp_unit (void *);
1259 static hashval_t
partial_die_hash (const void *item
);
1261 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1263 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1264 (unsigned int offset
, struct objfile
*objfile
);
1266 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1267 (unsigned int offset
, struct objfile
*objfile
);
1269 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1270 struct dwarf2_per_cu_data
*per_cu
);
1272 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1273 struct die_info
*comp_unit_die
);
1275 static void free_heap_comp_unit (void *);
1277 static void free_cached_comp_units (void *);
1279 static void age_cached_comp_units (void);
1281 static void free_one_cached_comp_unit (void *);
1283 static struct type
*set_die_type (struct die_info
*, struct type
*,
1284 struct dwarf2_cu
*);
1286 static void create_all_comp_units (struct objfile
*);
1288 static int create_debug_types_hash_table (struct objfile
*objfile
);
1290 static void load_full_comp_unit (struct dwarf2_per_cu_data
*);
1292 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1294 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1295 struct dwarf2_per_cu_data
*);
1297 static void dwarf2_mark (struct dwarf2_cu
*);
1299 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1301 static struct type
*get_die_type_at_offset (unsigned int,
1302 struct dwarf2_per_cu_data
*per_cu
);
1304 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1306 static void dwarf2_release_queue (void *dummy
);
1308 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
);
1310 static void process_queue (void);
1312 static void find_file_and_directory (struct die_info
*die
,
1313 struct dwarf2_cu
*cu
,
1314 char **name
, char **comp_dir
);
1316 static char *file_full_name (int file
, struct line_header
*lh
,
1317 const char *comp_dir
);
1319 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1322 unsigned int buffer_size
,
1324 int is_debug_types_section
);
1326 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1327 struct dwarf2_cu
*cu
);
1329 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1333 /* Convert VALUE between big- and little-endian. */
1335 byte_swap (offset_type value
)
1339 result
= (value
& 0xff) << 24;
1340 result
|= (value
& 0xff00) << 8;
1341 result
|= (value
& 0xff0000) >> 8;
1342 result
|= (value
& 0xff000000) >> 24;
1346 #define MAYBE_SWAP(V) byte_swap (V)
1349 #define MAYBE_SWAP(V) (V)
1350 #endif /* WORDS_BIGENDIAN */
1352 /* The suffix for an index file. */
1353 #define INDEX_SUFFIX ".gdb-index"
1355 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1356 struct dwarf2_cu
*cu
);
1358 /* Try to locate the sections we need for DWARF 2 debugging
1359 information and return true if we have enough to do something.
1360 NAMES points to the dwarf2 section names, or is NULL if the standard
1361 ELF names are used. */
1364 dwarf2_has_info (struct objfile
*objfile
,
1365 const struct dwarf2_debug_sections
*names
)
1367 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1368 if (!dwarf2_per_objfile
)
1370 /* Initialize per-objfile state. */
1371 struct dwarf2_per_objfile
*data
1372 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1374 memset (data
, 0, sizeof (*data
));
1375 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1376 dwarf2_per_objfile
= data
;
1378 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1380 dwarf2_per_objfile
->objfile
= objfile
;
1382 return (dwarf2_per_objfile
->info
.asection
!= NULL
1383 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1386 /* When loading sections, we look either for uncompressed section or for
1387 compressed section names. */
1390 section_is_p (const char *section_name
,
1391 const struct dwarf2_section_names
*names
)
1393 if (names
->normal
!= NULL
1394 && strcmp (section_name
, names
->normal
) == 0)
1396 if (names
->compressed
!= NULL
1397 && strcmp (section_name
, names
->compressed
) == 0)
1402 /* This function is mapped across the sections and remembers the
1403 offset and size of each of the debugging sections we are interested
1407 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1409 const struct dwarf2_debug_sections
*names
;
1412 names
= &dwarf2_elf_names
;
1414 names
= (const struct dwarf2_debug_sections
*) vnames
;
1416 if (section_is_p (sectp
->name
, &names
->info
))
1418 dwarf2_per_objfile
->info
.asection
= sectp
;
1419 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1421 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1423 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1424 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1426 else if (section_is_p (sectp
->name
, &names
->line
))
1428 dwarf2_per_objfile
->line
.asection
= sectp
;
1429 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1431 else if (section_is_p (sectp
->name
, &names
->loc
))
1433 dwarf2_per_objfile
->loc
.asection
= sectp
;
1434 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1436 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1438 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1439 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1441 else if (section_is_p (sectp
->name
, &names
->macro
))
1443 dwarf2_per_objfile
->macro
.asection
= sectp
;
1444 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1446 else if (section_is_p (sectp
->name
, &names
->str
))
1448 dwarf2_per_objfile
->str
.asection
= sectp
;
1449 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1451 else if (section_is_p (sectp
->name
, &names
->frame
))
1453 dwarf2_per_objfile
->frame
.asection
= sectp
;
1454 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1456 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1458 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1460 if (aflag
& SEC_HAS_CONTENTS
)
1462 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1463 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1466 else if (section_is_p (sectp
->name
, &names
->ranges
))
1468 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1469 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1471 else if (section_is_p (sectp
->name
, &names
->types
))
1473 struct dwarf2_section_info type_section
;
1475 memset (&type_section
, 0, sizeof (type_section
));
1476 type_section
.asection
= sectp
;
1477 type_section
.size
= bfd_get_section_size (sectp
);
1479 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1482 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1484 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1485 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1488 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1489 && bfd_section_vma (abfd
, sectp
) == 0)
1490 dwarf2_per_objfile
->has_section_at_zero
= 1;
1493 /* Decompress a section that was compressed using zlib. Store the
1494 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1497 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1498 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1500 bfd
*abfd
= objfile
->obfd
;
1502 error (_("Support for zlib-compressed DWARF data (from '%s') "
1503 "is disabled in this copy of GDB"),
1504 bfd_get_filename (abfd
));
1506 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1507 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1508 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1509 bfd_size_type uncompressed_size
;
1510 gdb_byte
*uncompressed_buffer
;
1513 int header_size
= 12;
1515 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1516 || bfd_bread (compressed_buffer
,
1517 compressed_size
, abfd
) != compressed_size
)
1518 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1519 bfd_get_filename (abfd
));
1521 /* Read the zlib header. In this case, it should be "ZLIB" followed
1522 by the uncompressed section size, 8 bytes in big-endian order. */
1523 if (compressed_size
< header_size
1524 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1525 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1526 bfd_get_filename (abfd
));
1527 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1528 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1529 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1530 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1531 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1532 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1533 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1534 uncompressed_size
+= compressed_buffer
[11];
1536 /* It is possible the section consists of several compressed
1537 buffers concatenated together, so we uncompress in a loop. */
1541 strm
.avail_in
= compressed_size
- header_size
;
1542 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1543 strm
.avail_out
= uncompressed_size
;
1544 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1546 rc
= inflateInit (&strm
);
1547 while (strm
.avail_in
> 0)
1550 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1551 bfd_get_filename (abfd
), rc
);
1552 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1553 + (uncompressed_size
- strm
.avail_out
));
1554 rc
= inflate (&strm
, Z_FINISH
);
1555 if (rc
!= Z_STREAM_END
)
1556 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1557 bfd_get_filename (abfd
), rc
);
1558 rc
= inflateReset (&strm
);
1560 rc
= inflateEnd (&strm
);
1562 || strm
.avail_out
!= 0)
1563 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1564 bfd_get_filename (abfd
), rc
);
1566 do_cleanups (cleanup
);
1567 *outbuf
= uncompressed_buffer
;
1568 *outsize
= uncompressed_size
;
1572 /* A helper function that decides whether a section is empty. */
1575 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1577 return info
->asection
== NULL
|| info
->size
== 0;
1580 /* Read the contents of the section INFO from object file specified by
1581 OBJFILE, store info about the section into INFO.
1582 If the section is compressed, uncompress it before returning. */
1585 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1587 bfd
*abfd
= objfile
->obfd
;
1588 asection
*sectp
= info
->asection
;
1589 gdb_byte
*buf
, *retbuf
;
1590 unsigned char header
[4];
1594 info
->buffer
= NULL
;
1595 info
->map_addr
= NULL
;
1598 if (dwarf2_section_empty_p (info
))
1601 /* Check if the file has a 4-byte header indicating compression. */
1602 if (info
->size
> sizeof (header
)
1603 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1604 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1606 /* Upon decompression, update the buffer and its size. */
1607 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1609 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1617 pagesize
= getpagesize ();
1619 /* Only try to mmap sections which are large enough: we don't want to
1620 waste space due to fragmentation. Also, only try mmap for sections
1621 without relocations. */
1623 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1625 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1626 MAP_PRIVATE
, sectp
->filepos
,
1627 &info
->map_addr
, &info
->map_len
);
1629 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1631 #if HAVE_POSIX_MADVISE
1632 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1639 /* If we get here, we are a normal, not-compressed section. */
1641 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1643 /* When debugging .o files, we may need to apply relocations; see
1644 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1645 We never compress sections in .o files, so we only need to
1646 try this when the section is not compressed. */
1647 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1650 info
->buffer
= retbuf
;
1654 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1655 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1656 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1657 bfd_get_filename (abfd
));
1660 /* A helper function that returns the size of a section in a safe way.
1661 If you are positive that the section has been read before using the
1662 size, then it is safe to refer to the dwarf2_section_info object's
1663 "size" field directly. In other cases, you must call this
1664 function, because for compressed sections the size field is not set
1665 correctly until the section has been read. */
1667 static bfd_size_type
1668 dwarf2_section_size (struct objfile
*objfile
,
1669 struct dwarf2_section_info
*info
)
1672 dwarf2_read_section (objfile
, info
);
1676 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1680 dwarf2_get_section_info (struct objfile
*objfile
,
1681 enum dwarf2_section_enum sect
,
1682 asection
**sectp
, gdb_byte
**bufp
,
1683 bfd_size_type
*sizep
)
1685 struct dwarf2_per_objfile
*data
1686 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1687 struct dwarf2_section_info
*info
;
1689 /* We may see an objfile without any DWARF, in which case we just
1700 case DWARF2_DEBUG_FRAME
:
1701 info
= &data
->frame
;
1703 case DWARF2_EH_FRAME
:
1704 info
= &data
->eh_frame
;
1707 gdb_assert_not_reached ("unexpected section");
1710 dwarf2_read_section (objfile
, info
);
1712 *sectp
= info
->asection
;
1713 *bufp
= info
->buffer
;
1714 *sizep
= info
->size
;
1718 /* DWARF quick_symbols_functions support. */
1720 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1721 unique line tables, so we maintain a separate table of all .debug_line
1722 derived entries to support the sharing.
1723 All the quick functions need is the list of file names. We discard the
1724 line_header when we're done and don't need to record it here. */
1725 struct quick_file_names
1727 /* The offset in .debug_line of the line table. We hash on this. */
1728 unsigned int offset
;
1730 /* The number of entries in file_names, real_names. */
1731 unsigned int num_file_names
;
1733 /* The file names from the line table, after being run through
1735 const char **file_names
;
1737 /* The file names from the line table after being run through
1738 gdb_realpath. These are computed lazily. */
1739 const char **real_names
;
1742 /* When using the index (and thus not using psymtabs), each CU has an
1743 object of this type. This is used to hold information needed by
1744 the various "quick" methods. */
1745 struct dwarf2_per_cu_quick_data
1747 /* The file table. This can be NULL if there was no file table
1748 or it's currently not read in.
1749 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1750 struct quick_file_names
*file_names
;
1752 /* The corresponding symbol table. This is NULL if symbols for this
1753 CU have not yet been read. */
1754 struct symtab
*symtab
;
1756 /* A temporary mark bit used when iterating over all CUs in
1757 expand_symtabs_matching. */
1758 unsigned int mark
: 1;
1760 /* True if we've tried to read the file table and found there isn't one.
1761 There will be no point in trying to read it again next time. */
1762 unsigned int no_file_data
: 1;
1765 /* Hash function for a quick_file_names. */
1768 hash_file_name_entry (const void *e
)
1770 const struct quick_file_names
*file_data
= e
;
1772 return file_data
->offset
;
1775 /* Equality function for a quick_file_names. */
1778 eq_file_name_entry (const void *a
, const void *b
)
1780 const struct quick_file_names
*ea
= a
;
1781 const struct quick_file_names
*eb
= b
;
1783 return ea
->offset
== eb
->offset
;
1786 /* Delete function for a quick_file_names. */
1789 delete_file_name_entry (void *e
)
1791 struct quick_file_names
*file_data
= e
;
1794 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1796 xfree ((void*) file_data
->file_names
[i
]);
1797 if (file_data
->real_names
)
1798 xfree ((void*) file_data
->real_names
[i
]);
1801 /* The space for the struct itself lives on objfile_obstack,
1802 so we don't free it here. */
1805 /* Create a quick_file_names hash table. */
1808 create_quick_file_names_table (unsigned int nr_initial_entries
)
1810 return htab_create_alloc (nr_initial_entries
,
1811 hash_file_name_entry
, eq_file_name_entry
,
1812 delete_file_name_entry
, xcalloc
, xfree
);
1815 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1816 have to be created afterwards. You should call age_cached_comp_units after
1817 processing PER_CU->CU. dw2_setup must have been already called. */
1820 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1822 if (per_cu
->debug_types_section
)
1823 read_signatured_type_at_offset (per_cu
->objfile
,
1824 per_cu
->debug_types_section
,
1827 load_full_comp_unit (per_cu
);
1829 gdb_assert (per_cu
->cu
!= NULL
);
1831 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1834 /* Read in the symbols for PER_CU. */
1837 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1839 struct cleanup
*back_to
;
1841 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1843 queue_comp_unit (per_cu
);
1849 /* Age the cache, releasing compilation units that have not
1850 been used recently. */
1851 age_cached_comp_units ();
1853 do_cleanups (back_to
);
1856 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1857 the objfile from which this CU came. Returns the resulting symbol
1860 static struct symtab
*
1861 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1863 if (!per_cu
->v
.quick
->symtab
)
1865 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1866 increment_reading_symtab ();
1867 dw2_do_instantiate_symtab (per_cu
);
1868 do_cleanups (back_to
);
1870 return per_cu
->v
.quick
->symtab
;
1873 /* Return the CU given its index. */
1875 static struct dwarf2_per_cu_data
*
1876 dw2_get_cu (int index
)
1878 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1880 index
-= dwarf2_per_objfile
->n_comp_units
;
1881 return dwarf2_per_objfile
->type_comp_units
[index
];
1883 return dwarf2_per_objfile
->all_comp_units
[index
];
1886 /* A helper function that knows how to read a 64-bit value in a way
1887 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1891 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1893 if (sizeof (ULONGEST
) < 8)
1897 /* Ignore the upper 4 bytes if they are all zero. */
1898 for (i
= 0; i
< 4; ++i
)
1899 if (bytes
[i
+ 4] != 0)
1902 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1905 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1909 /* Read the CU list from the mapped index, and use it to create all
1910 the CU objects for this objfile. Return 0 if something went wrong,
1911 1 if everything went ok. */
1914 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1915 offset_type cu_list_elements
)
1919 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1920 dwarf2_per_objfile
->all_comp_units
1921 = obstack_alloc (&objfile
->objfile_obstack
,
1922 dwarf2_per_objfile
->n_comp_units
1923 * sizeof (struct dwarf2_per_cu_data
*));
1925 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1927 struct dwarf2_per_cu_data
*the_cu
;
1928 ULONGEST offset
, length
;
1930 if (!extract_cu_value (cu_list
, &offset
)
1931 || !extract_cu_value (cu_list
+ 8, &length
))
1935 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1936 struct dwarf2_per_cu_data
);
1937 the_cu
->offset
= offset
;
1938 the_cu
->length
= length
;
1939 the_cu
->objfile
= objfile
;
1940 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1941 struct dwarf2_per_cu_quick_data
);
1942 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1948 /* Create the signatured type hash table from the index. */
1951 create_signatured_type_table_from_index (struct objfile
*objfile
,
1952 struct dwarf2_section_info
*section
,
1953 const gdb_byte
*bytes
,
1954 offset_type elements
)
1957 htab_t sig_types_hash
;
1959 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1960 dwarf2_per_objfile
->type_comp_units
1961 = obstack_alloc (&objfile
->objfile_obstack
,
1962 dwarf2_per_objfile
->n_type_comp_units
1963 * sizeof (struct dwarf2_per_cu_data
*));
1965 sig_types_hash
= allocate_signatured_type_table (objfile
);
1967 for (i
= 0; i
< elements
; i
+= 3)
1969 struct signatured_type
*type_sig
;
1970 ULONGEST offset
, type_offset
, signature
;
1973 if (!extract_cu_value (bytes
, &offset
)
1974 || !extract_cu_value (bytes
+ 8, &type_offset
))
1976 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1979 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1980 struct signatured_type
);
1981 type_sig
->signature
= signature
;
1982 type_sig
->type_offset
= type_offset
;
1983 type_sig
->per_cu
.debug_types_section
= section
;
1984 type_sig
->per_cu
.offset
= offset
;
1985 type_sig
->per_cu
.objfile
= objfile
;
1986 type_sig
->per_cu
.v
.quick
1987 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1988 struct dwarf2_per_cu_quick_data
);
1990 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1993 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1996 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2001 /* Read the address map data from the mapped index, and use it to
2002 populate the objfile's psymtabs_addrmap. */
2005 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2007 const gdb_byte
*iter
, *end
;
2008 struct obstack temp_obstack
;
2009 struct addrmap
*mutable_map
;
2010 struct cleanup
*cleanup
;
2013 obstack_init (&temp_obstack
);
2014 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2015 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2017 iter
= index
->address_table
;
2018 end
= iter
+ index
->address_table_size
;
2020 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2024 ULONGEST hi
, lo
, cu_index
;
2025 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2027 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2029 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2032 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2033 dw2_get_cu (cu_index
));
2036 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2037 &objfile
->objfile_obstack
);
2038 do_cleanups (cleanup
);
2041 /* The hash function for strings in the mapped index. This is the same as
2042 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2043 implementation. This is necessary because the hash function is tied to the
2044 format of the mapped index file. The hash values do not have to match with
2047 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2050 mapped_index_string_hash (int index_version
, const void *p
)
2052 const unsigned char *str
= (const unsigned char *) p
;
2056 while ((c
= *str
++) != 0)
2058 if (index_version
>= 5)
2060 r
= r
* 67 + c
- 113;
2066 /* Find a slot in the mapped index INDEX for the object named NAME.
2067 If NAME is found, set *VEC_OUT to point to the CU vector in the
2068 constant pool and return 1. If NAME cannot be found, return 0. */
2071 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2072 offset_type
**vec_out
)
2074 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2076 offset_type slot
, step
;
2077 int (*cmp
) (const char *, const char *);
2079 if (current_language
->la_language
== language_cplus
2080 || current_language
->la_language
== language_java
2081 || current_language
->la_language
== language_fortran
)
2083 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2085 const char *paren
= strchr (name
, '(');
2091 dup
= xmalloc (paren
- name
+ 1);
2092 memcpy (dup
, name
, paren
- name
);
2093 dup
[paren
- name
] = 0;
2095 make_cleanup (xfree
, dup
);
2100 /* Index version 4 did not support case insensitive searches. But the
2101 indexes for case insensitive languages are built in lowercase, therefore
2102 simulate our NAME being searched is also lowercased. */
2103 hash
= mapped_index_string_hash ((index
->version
== 4
2104 && case_sensitivity
== case_sensitive_off
2105 ? 5 : index
->version
),
2108 slot
= hash
& (index
->symbol_table_slots
- 1);
2109 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2110 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2114 /* Convert a slot number to an offset into the table. */
2115 offset_type i
= 2 * slot
;
2117 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2119 do_cleanups (back_to
);
2123 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2124 if (!cmp (name
, str
))
2126 *vec_out
= (offset_type
*) (index
->constant_pool
2127 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2128 do_cleanups (back_to
);
2132 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2136 /* Read the index file. If everything went ok, initialize the "quick"
2137 elements of all the CUs and return 1. Otherwise, return 0. */
2140 dwarf2_read_index (struct objfile
*objfile
)
2143 struct mapped_index
*map
;
2144 offset_type
*metadata
;
2145 const gdb_byte
*cu_list
;
2146 const gdb_byte
*types_list
= NULL
;
2147 offset_type version
, cu_list_elements
;
2148 offset_type types_list_elements
= 0;
2151 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2154 /* Older elfutils strip versions could keep the section in the main
2155 executable while splitting it for the separate debug info file. */
2156 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2157 & SEC_HAS_CONTENTS
) == 0)
2160 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2162 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2163 /* Version check. */
2164 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2165 /* Versions earlier than 3 emitted every copy of a psymbol. This
2166 causes the index to behave very poorly for certain requests. Version 3
2167 contained incomplete addrmap. So, it seems better to just ignore such
2168 indices. Index version 4 uses a different hash function than index
2169 version 5 and later. */
2172 /* Indexes with higher version than the one supported by GDB may be no
2173 longer backward compatible. */
2177 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2178 map
->version
= version
;
2179 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2181 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2184 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2185 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2189 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2190 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2191 - MAYBE_SWAP (metadata
[i
]))
2195 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2196 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2197 - MAYBE_SWAP (metadata
[i
]));
2200 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2201 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2202 - MAYBE_SWAP (metadata
[i
]))
2203 / (2 * sizeof (offset_type
)));
2206 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2208 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2211 if (types_list_elements
)
2213 struct dwarf2_section_info
*section
;
2215 /* We can only handle a single .debug_types when we have an
2217 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2220 section
= VEC_index (dwarf2_section_info_def
,
2221 dwarf2_per_objfile
->types
, 0);
2223 if (!create_signatured_type_table_from_index (objfile
, section
,
2225 types_list_elements
))
2229 create_addrmap_from_index (objfile
, map
);
2231 dwarf2_per_objfile
->index_table
= map
;
2232 dwarf2_per_objfile
->using_index
= 1;
2233 dwarf2_per_objfile
->quick_file_names_table
=
2234 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2239 /* A helper for the "quick" functions which sets the global
2240 dwarf2_per_objfile according to OBJFILE. */
2243 dw2_setup (struct objfile
*objfile
)
2245 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2246 gdb_assert (dwarf2_per_objfile
);
2249 /* A helper for the "quick" functions which attempts to read the line
2250 table for THIS_CU. */
2252 static struct quick_file_names
*
2253 dw2_get_file_names (struct objfile
*objfile
,
2254 struct dwarf2_per_cu_data
*this_cu
)
2256 bfd
*abfd
= objfile
->obfd
;
2257 struct line_header
*lh
;
2258 struct attribute
*attr
;
2259 struct cleanup
*cleanups
;
2260 struct die_info
*comp_unit_die
;
2261 struct dwarf2_section_info
* sec
;
2262 gdb_byte
*info_ptr
, *buffer
;
2263 int has_children
, i
;
2264 struct dwarf2_cu cu
;
2265 unsigned int bytes_read
, buffer_size
;
2266 struct die_reader_specs reader_specs
;
2267 char *name
, *comp_dir
;
2269 struct quick_file_names
*qfn
;
2270 unsigned int line_offset
;
2272 if (this_cu
->v
.quick
->file_names
!= NULL
)
2273 return this_cu
->v
.quick
->file_names
;
2274 /* If we know there is no line data, no point in looking again. */
2275 if (this_cu
->v
.quick
->no_file_data
)
2278 init_one_comp_unit (&cu
, this_cu
);
2279 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2281 if (this_cu
->debug_types_section
)
2282 sec
= this_cu
->debug_types_section
;
2284 sec
= &dwarf2_per_objfile
->info
;
2285 dwarf2_read_section (objfile
, sec
);
2286 buffer_size
= sec
->size
;
2287 buffer
= sec
->buffer
;
2288 info_ptr
= buffer
+ this_cu
->offset
;
2290 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2291 buffer
, buffer_size
,
2293 this_cu
->debug_types_section
!= NULL
);
2295 /* Skip dummy compilation units. */
2296 if (info_ptr
>= buffer
+ buffer_size
2297 || peek_abbrev_code (abfd
, info_ptr
) == 0)
2299 do_cleanups (cleanups
);
2303 dwarf2_read_abbrevs (abfd
, &cu
);
2304 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2306 init_cu_die_reader (&reader_specs
, &cu
);
2307 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2313 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2316 struct quick_file_names find_entry
;
2318 line_offset
= DW_UNSND (attr
);
2320 /* We may have already read in this line header (TU line header sharing).
2321 If we have we're done. */
2322 find_entry
.offset
= line_offset
;
2323 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2324 &find_entry
, INSERT
);
2327 do_cleanups (cleanups
);
2328 this_cu
->v
.quick
->file_names
= *slot
;
2332 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2336 do_cleanups (cleanups
);
2337 this_cu
->v
.quick
->no_file_data
= 1;
2341 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2342 qfn
->offset
= line_offset
;
2343 gdb_assert (slot
!= NULL
);
2346 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2348 qfn
->num_file_names
= lh
->num_file_names
;
2349 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2350 lh
->num_file_names
* sizeof (char *));
2351 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2352 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2353 qfn
->real_names
= NULL
;
2355 free_line_header (lh
);
2356 do_cleanups (cleanups
);
2358 this_cu
->v
.quick
->file_names
= qfn
;
2362 /* A helper for the "quick" functions which computes and caches the
2363 real path for a given file name from the line table. */
2366 dw2_get_real_path (struct objfile
*objfile
,
2367 struct quick_file_names
*qfn
, int index
)
2369 if (qfn
->real_names
== NULL
)
2370 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2371 qfn
->num_file_names
, sizeof (char *));
2373 if (qfn
->real_names
[index
] == NULL
)
2374 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2376 return qfn
->real_names
[index
];
2379 static struct symtab
*
2380 dw2_find_last_source_symtab (struct objfile
*objfile
)
2384 dw2_setup (objfile
);
2385 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2386 return dw2_instantiate_symtab (dw2_get_cu (index
));
2389 /* Traversal function for dw2_forget_cached_source_info. */
2392 dw2_free_cached_file_names (void **slot
, void *info
)
2394 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2396 if (file_data
->real_names
)
2400 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2402 xfree ((void*) file_data
->real_names
[i
]);
2403 file_data
->real_names
[i
] = NULL
;
2411 dw2_forget_cached_source_info (struct objfile
*objfile
)
2413 dw2_setup (objfile
);
2415 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2416 dw2_free_cached_file_names
, NULL
);
2419 /* Helper function for dw2_map_symtabs_matching_filename that expands
2420 the symtabs and calls the iterator. */
2423 dw2_map_expand_apply (struct objfile
*objfile
,
2424 struct dwarf2_per_cu_data
*per_cu
,
2426 const char *full_path
, const char *real_path
,
2427 int (*callback
) (struct symtab
*, void *),
2430 struct symtab
*last_made
= objfile
->symtabs
;
2432 /* Don't visit already-expanded CUs. */
2433 if (per_cu
->v
.quick
->symtab
)
2436 /* This may expand more than one symtab, and we want to iterate over
2438 dw2_instantiate_symtab (per_cu
);
2440 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2441 objfile
->symtabs
, last_made
);
2444 /* Implementation of the map_symtabs_matching_filename method. */
2447 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2448 const char *full_path
, const char *real_path
,
2449 int (*callback
) (struct symtab
*, void *),
2453 const char *name_basename
= lbasename (name
);
2454 int check_basename
= name_basename
== name
;
2455 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2457 dw2_setup (objfile
);
2459 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2460 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2463 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2464 struct quick_file_names
*file_data
;
2466 /* We only need to look at symtabs not already expanded. */
2467 if (per_cu
->v
.quick
->symtab
)
2470 file_data
= dw2_get_file_names (objfile
, per_cu
);
2471 if (file_data
== NULL
)
2474 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2476 const char *this_name
= file_data
->file_names
[j
];
2478 if (FILENAME_CMP (name
, this_name
) == 0)
2480 if (dw2_map_expand_apply (objfile
, per_cu
,
2481 name
, full_path
, real_path
,
2486 if (check_basename
&& ! base_cu
2487 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2490 /* Before we invoke realpath, which can get expensive when many
2491 files are involved, do a quick comparison of the basenames. */
2492 if (! basenames_may_differ
2493 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2496 if (full_path
!= NULL
)
2498 const char *this_real_name
= dw2_get_real_path (objfile
,
2501 if (this_real_name
!= NULL
2502 && FILENAME_CMP (full_path
, this_real_name
) == 0)
2504 if (dw2_map_expand_apply (objfile
, per_cu
,
2505 name
, full_path
, real_path
,
2511 if (real_path
!= NULL
)
2513 const char *this_real_name
= dw2_get_real_path (objfile
,
2516 if (this_real_name
!= NULL
2517 && FILENAME_CMP (real_path
, this_real_name
) == 0)
2519 if (dw2_map_expand_apply (objfile
, per_cu
,
2520 name
, full_path
, real_path
,
2530 if (dw2_map_expand_apply (objfile
, base_cu
,
2531 name
, full_path
, real_path
,
2539 static struct symtab
*
2540 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2541 const char *name
, domain_enum domain
)
2543 /* We do all the work in the pre_expand_symtabs_matching hook
2548 /* A helper function that expands all symtabs that hold an object
2552 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2554 dw2_setup (objfile
);
2556 /* index_table is NULL if OBJF_READNOW. */
2557 if (dwarf2_per_objfile
->index_table
)
2561 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2564 offset_type i
, len
= MAYBE_SWAP (*vec
);
2565 for (i
= 0; i
< len
; ++i
)
2567 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2568 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2570 dw2_instantiate_symtab (per_cu
);
2577 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2578 enum block_enum block_kind
, const char *name
,
2581 dw2_do_expand_symtabs_matching (objfile
, name
);
2585 dw2_print_stats (struct objfile
*objfile
)
2589 dw2_setup (objfile
);
2591 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2592 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2594 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2596 if (!per_cu
->v
.quick
->symtab
)
2599 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2603 dw2_dump (struct objfile
*objfile
)
2605 /* Nothing worth printing. */
2609 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2610 struct section_offsets
*delta
)
2612 /* There's nothing to relocate here. */
2616 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2617 const char *func_name
)
2619 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2623 dw2_expand_all_symtabs (struct objfile
*objfile
)
2627 dw2_setup (objfile
);
2629 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2630 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2632 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2634 dw2_instantiate_symtab (per_cu
);
2639 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2640 const char *filename
)
2644 dw2_setup (objfile
);
2646 /* We don't need to consider type units here.
2647 This is only called for examining code, e.g. expand_line_sal.
2648 There can be an order of magnitude (or more) more type units
2649 than comp units, and we avoid them if we can. */
2651 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2654 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2655 struct quick_file_names
*file_data
;
2657 /* We only need to look at symtabs not already expanded. */
2658 if (per_cu
->v
.quick
->symtab
)
2661 file_data
= dw2_get_file_names (objfile
, per_cu
);
2662 if (file_data
== NULL
)
2665 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2667 const char *this_name
= file_data
->file_names
[j
];
2668 if (FILENAME_CMP (this_name
, filename
) == 0)
2670 dw2_instantiate_symtab (per_cu
);
2678 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2680 struct dwarf2_per_cu_data
*per_cu
;
2682 struct quick_file_names
*file_data
;
2684 dw2_setup (objfile
);
2686 /* index_table is NULL if OBJF_READNOW. */
2687 if (!dwarf2_per_objfile
->index_table
)
2691 ALL_OBJFILE_SYMTABS (objfile
, s
)
2694 struct blockvector
*bv
= BLOCKVECTOR (s
);
2695 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2696 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2699 return sym
->symtab
->filename
;
2704 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2708 /* Note that this just looks at the very first one named NAME -- but
2709 actually we are looking for a function. find_main_filename
2710 should be rewritten so that it doesn't require a custom hook. It
2711 could just use the ordinary symbol tables. */
2712 /* vec[0] is the length, which must always be >0. */
2713 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2715 file_data
= dw2_get_file_names (objfile
, per_cu
);
2716 if (file_data
== NULL
)
2719 return file_data
->file_names
[file_data
->num_file_names
- 1];
2723 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2724 struct objfile
*objfile
, int global
,
2725 int (*callback
) (struct block
*,
2726 struct symbol
*, void *),
2727 void *data
, symbol_compare_ftype
*match
,
2728 symbol_compare_ftype
*ordered_compare
)
2730 /* Currently unimplemented; used for Ada. The function can be called if the
2731 current language is Ada for a non-Ada objfile using GNU index. As Ada
2732 does not look for non-Ada symbols this function should just return. */
2736 dw2_expand_symtabs_matching
2737 (struct objfile
*objfile
,
2738 int (*file_matcher
) (const char *, void *),
2739 int (*name_matcher
) (const struct language_defn
*, const char *, void *),
2740 enum search_domain kind
,
2745 struct mapped_index
*index
;
2747 dw2_setup (objfile
);
2749 /* index_table is NULL if OBJF_READNOW. */
2750 if (!dwarf2_per_objfile
->index_table
)
2752 index
= dwarf2_per_objfile
->index_table
;
2754 if (file_matcher
!= NULL
)
2755 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2756 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2759 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2760 struct quick_file_names
*file_data
;
2762 per_cu
->v
.quick
->mark
= 0;
2764 /* We only need to look at symtabs not already expanded. */
2765 if (per_cu
->v
.quick
->symtab
)
2768 file_data
= dw2_get_file_names (objfile
, per_cu
);
2769 if (file_data
== NULL
)
2772 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2774 if (file_matcher (file_data
->file_names
[j
], data
))
2776 per_cu
->v
.quick
->mark
= 1;
2782 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2784 offset_type idx
= 2 * iter
;
2786 offset_type
*vec
, vec_len
, vec_idx
;
2788 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2791 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2793 if (! (*name_matcher
) (current_language
, name
, data
))
2796 /* The name was matched, now expand corresponding CUs that were
2798 vec
= (offset_type
*) (index
->constant_pool
2799 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2800 vec_len
= MAYBE_SWAP (vec
[0]);
2801 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2803 struct dwarf2_per_cu_data
*per_cu
;
2805 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2806 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2807 dw2_instantiate_symtab (per_cu
);
2812 static struct symtab
*
2813 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2814 struct minimal_symbol
*msymbol
,
2816 struct obj_section
*section
,
2819 struct dwarf2_per_cu_data
*data
;
2821 dw2_setup (objfile
);
2823 if (!objfile
->psymtabs_addrmap
)
2826 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2830 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2831 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2832 paddress (get_objfile_arch (objfile
), pc
));
2834 return dw2_instantiate_symtab (data
);
2838 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2839 void *data
, int need_fullname
)
2843 dw2_setup (objfile
);
2845 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2846 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2849 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2850 struct quick_file_names
*file_data
;
2852 /* We only need to look at symtabs not already expanded. */
2853 if (per_cu
->v
.quick
->symtab
)
2856 file_data
= dw2_get_file_names (objfile
, per_cu
);
2857 if (file_data
== NULL
)
2860 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2862 const char *this_real_name
;
2865 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
2867 this_real_name
= NULL
;
2868 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2874 dw2_has_symbols (struct objfile
*objfile
)
2879 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2882 dw2_find_last_source_symtab
,
2883 dw2_forget_cached_source_info
,
2884 dw2_map_symtabs_matching_filename
,
2886 dw2_pre_expand_symtabs_matching
,
2890 dw2_expand_symtabs_for_function
,
2891 dw2_expand_all_symtabs
,
2892 dw2_expand_symtabs_with_filename
,
2893 dw2_find_symbol_file
,
2894 dw2_map_matching_symbols
,
2895 dw2_expand_symtabs_matching
,
2896 dw2_find_pc_sect_symtab
,
2897 dw2_map_symbol_filenames
2900 /* Initialize for reading DWARF for this objfile. Return 0 if this
2901 file will use psymtabs, or 1 if using the GNU index. */
2904 dwarf2_initialize_objfile (struct objfile
*objfile
)
2906 /* If we're about to read full symbols, don't bother with the
2907 indices. In this case we also don't care if some other debug
2908 format is making psymtabs, because they are all about to be
2910 if ((objfile
->flags
& OBJF_READNOW
))
2914 dwarf2_per_objfile
->using_index
= 1;
2915 create_all_comp_units (objfile
);
2916 create_debug_types_hash_table (objfile
);
2917 dwarf2_per_objfile
->quick_file_names_table
=
2918 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2920 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2921 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2923 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2925 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2926 struct dwarf2_per_cu_quick_data
);
2929 /* Return 1 so that gdb sees the "quick" functions. However,
2930 these functions will be no-ops because we will have expanded
2935 if (dwarf2_read_index (objfile
))
2943 /* Build a partial symbol table. */
2946 dwarf2_build_psymtabs (struct objfile
*objfile
)
2948 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2950 init_psymbol_list (objfile
, 1024);
2953 dwarf2_build_psymtabs_hard (objfile
);
2956 /* Return TRUE if OFFSET is within CU_HEADER. */
2959 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2961 unsigned int bottom
= cu_header
->offset
;
2962 unsigned int top
= (cu_header
->offset
2964 + cu_header
->initial_length_size
);
2966 return (offset
>= bottom
&& offset
< top
);
2969 /* Read in the comp unit header information from the debug_info at info_ptr.
2970 NOTE: This leaves members offset, first_die_offset to be filled in
2974 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2975 gdb_byte
*info_ptr
, bfd
*abfd
)
2978 unsigned int bytes_read
;
2980 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2981 cu_header
->initial_length_size
= bytes_read
;
2982 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2983 info_ptr
+= bytes_read
;
2984 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2986 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2988 info_ptr
+= bytes_read
;
2989 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2991 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2992 if (signed_addr
< 0)
2993 internal_error (__FILE__
, __LINE__
,
2994 _("read_comp_unit_head: dwarf from non elf file"));
2995 cu_header
->signed_addr_p
= signed_addr
;
3000 /* Read in a CU header and perform some basic error checking. */
3003 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
3004 gdb_byte
*buffer
, unsigned int buffer_size
,
3005 bfd
*abfd
, int is_debug_types_section
)
3007 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3009 header
->offset
= beg_of_comp_unit
- buffer
;
3011 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3013 /* If we're reading a type unit, skip over the signature and
3014 type_offset fields. */
3015 if (is_debug_types_section
)
3016 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3018 header
->first_die_offset
= info_ptr
- beg_of_comp_unit
;
3020 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3021 error (_("Dwarf Error: wrong version in compilation unit header "
3022 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3023 bfd_get_filename (abfd
));
3025 if (header
->abbrev_offset
3026 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3027 &dwarf2_per_objfile
->abbrev
))
3028 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3029 "(offset 0x%lx + 6) [in module %s]"),
3030 (long) header
->abbrev_offset
,
3031 (long) (beg_of_comp_unit
- buffer
),
3032 bfd_get_filename (abfd
));
3034 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
3035 > buffer
+ buffer_size
)
3036 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3037 "(offset 0x%lx + 0) [in module %s]"),
3038 (long) header
->length
,
3039 (long) (beg_of_comp_unit
- buffer
),
3040 bfd_get_filename (abfd
));
3045 /* Read in the types comp unit header information from .debug_types entry at
3046 types_ptr. The result is a pointer to one past the end of the header. */
3049 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
3050 struct dwarf2_section_info
*section
,
3051 ULONGEST
*signature
,
3052 gdb_byte
*types_ptr
, bfd
*abfd
)
3054 gdb_byte
*initial_types_ptr
= types_ptr
;
3056 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
3057 cu_header
->offset
= types_ptr
- section
->buffer
;
3059 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
3061 *signature
= read_8_bytes (abfd
, types_ptr
);
3063 types_ptr
+= cu_header
->offset_size
;
3064 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
3069 /* Allocate a new partial symtab for file named NAME and mark this new
3070 partial symtab as being an include of PST. */
3073 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3074 struct objfile
*objfile
)
3076 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3078 subpst
->section_offsets
= pst
->section_offsets
;
3079 subpst
->textlow
= 0;
3080 subpst
->texthigh
= 0;
3082 subpst
->dependencies
= (struct partial_symtab
**)
3083 obstack_alloc (&objfile
->objfile_obstack
,
3084 sizeof (struct partial_symtab
*));
3085 subpst
->dependencies
[0] = pst
;
3086 subpst
->number_of_dependencies
= 1;
3088 subpst
->globals_offset
= 0;
3089 subpst
->n_global_syms
= 0;
3090 subpst
->statics_offset
= 0;
3091 subpst
->n_static_syms
= 0;
3092 subpst
->symtab
= NULL
;
3093 subpst
->read_symtab
= pst
->read_symtab
;
3096 /* No private part is necessary for include psymtabs. This property
3097 can be used to differentiate between such include psymtabs and
3098 the regular ones. */
3099 subpst
->read_symtab_private
= NULL
;
3102 /* Read the Line Number Program data and extract the list of files
3103 included by the source file represented by PST. Build an include
3104 partial symtab for each of these included files. */
3107 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3108 struct die_info
*die
,
3109 struct partial_symtab
*pst
)
3111 struct objfile
*objfile
= cu
->objfile
;
3112 bfd
*abfd
= objfile
->obfd
;
3113 struct line_header
*lh
= NULL
;
3114 struct attribute
*attr
;
3116 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3119 unsigned int line_offset
= DW_UNSND (attr
);
3121 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3124 return; /* No linetable, so no includes. */
3126 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3127 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
3129 free_line_header (lh
);
3133 hash_type_signature (const void *item
)
3135 const struct signatured_type
*type_sig
= item
;
3137 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3138 return type_sig
->signature
;
3142 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
3144 const struct signatured_type
*lhs
= item_lhs
;
3145 const struct signatured_type
*rhs
= item_rhs
;
3147 return lhs
->signature
== rhs
->signature
;
3150 /* Allocate a hash table for signatured types. */
3153 allocate_signatured_type_table (struct objfile
*objfile
)
3155 return htab_create_alloc_ex (41,
3156 hash_type_signature
,
3159 &objfile
->objfile_obstack
,
3160 hashtab_obstack_allocate
,
3161 dummy_obstack_deallocate
);
3164 /* A helper function to add a signatured type CU to a list. */
3167 add_signatured_type_cu_to_list (void **slot
, void *datum
)
3169 struct signatured_type
*sigt
= *slot
;
3170 struct dwarf2_per_cu_data
***datap
= datum
;
3172 **datap
= &sigt
->per_cu
;
3178 /* Create the hash table of all entries in the .debug_types section.
3179 The result is zero if there is an error (e.g. missing .debug_types section),
3180 otherwise non-zero. */
3183 create_debug_types_hash_table (struct objfile
*objfile
)
3185 htab_t types_htab
= NULL
;
3186 struct dwarf2_per_cu_data
**iter
;
3188 struct dwarf2_section_info
*section
;
3190 if (VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
))
3192 dwarf2_per_objfile
->signatured_types
= NULL
;
3197 VEC_iterate (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
3201 gdb_byte
*info_ptr
, *end_ptr
;
3203 dwarf2_read_section (objfile
, section
);
3204 info_ptr
= section
->buffer
;
3206 if (info_ptr
== NULL
)
3209 if (types_htab
== NULL
)
3210 types_htab
= allocate_signatured_type_table (objfile
);
3212 if (dwarf2_die_debug
)
3213 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3215 end_ptr
= info_ptr
+ section
->size
;
3216 while (info_ptr
< end_ptr
)
3218 unsigned int offset
;
3219 unsigned int offset_size
;
3220 unsigned int type_offset
;
3221 unsigned int length
, initial_length_size
;
3222 unsigned short version
;
3224 struct signatured_type
*type_sig
;
3226 gdb_byte
*ptr
= info_ptr
;
3228 offset
= ptr
- section
->buffer
;
3230 /* We need to read the type's signature in order to build the hash
3231 table, but we don't need to read anything else just yet. */
3233 /* Sanity check to ensure entire cu is present. */
3234 length
= read_initial_length (objfile
->obfd
, ptr
,
3235 &initial_length_size
);
3236 if (ptr
+ length
+ initial_length_size
> end_ptr
)
3238 complaint (&symfile_complaints
,
3239 _("debug type entry runs off end "
3240 "of `.debug_types' section, ignored"));
3244 offset_size
= initial_length_size
== 4 ? 4 : 8;
3245 ptr
+= initial_length_size
;
3246 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3248 ptr
+= offset_size
; /* abbrev offset */
3249 ptr
+= 1; /* address size */
3250 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3252 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3255 /* Skip dummy type units. */
3256 if (ptr
>= end_ptr
|| peek_abbrev_code (objfile
->obfd
, ptr
) == 0)
3258 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3262 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3263 memset (type_sig
, 0, sizeof (*type_sig
));
3264 type_sig
->signature
= signature
;
3265 type_sig
->type_offset
= type_offset
;
3266 type_sig
->per_cu
.objfile
= objfile
;
3267 type_sig
->per_cu
.debug_types_section
= section
;
3268 type_sig
->per_cu
.offset
= offset
;
3270 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3271 gdb_assert (slot
!= NULL
);
3274 const struct signatured_type
*dup_sig
= *slot
;
3276 complaint (&symfile_complaints
,
3277 _("debug type entry at offset 0x%x is duplicate to the "
3278 "entry at offset 0x%x, signature 0x%s"),
3279 offset
, dup_sig
->per_cu
.offset
,
3280 phex (signature
, sizeof (signature
)));
3281 gdb_assert (signature
== dup_sig
->signature
);
3285 if (dwarf2_die_debug
)
3286 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3287 offset
, phex (signature
, sizeof (signature
)));
3289 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3293 dwarf2_per_objfile
->signatured_types
= types_htab
;
3295 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3296 dwarf2_per_objfile
->type_comp_units
3297 = obstack_alloc (&objfile
->objfile_obstack
,
3298 dwarf2_per_objfile
->n_type_comp_units
3299 * sizeof (struct dwarf2_per_cu_data
*));
3300 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3301 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3302 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3303 == dwarf2_per_objfile
->n_type_comp_units
);
3308 /* Lookup a signature based type.
3309 Returns NULL if SIG is not present in the table. */
3311 static struct signatured_type
*
3312 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3314 struct signatured_type find_entry
, *entry
;
3316 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3318 complaint (&symfile_complaints
,
3319 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3323 find_entry
.signature
= sig
;
3324 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3328 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3331 init_cu_die_reader (struct die_reader_specs
*reader
,
3332 struct dwarf2_cu
*cu
)
3334 reader
->abfd
= cu
->objfile
->obfd
;
3336 if (cu
->per_cu
->debug_types_section
)
3338 gdb_assert (cu
->per_cu
->debug_types_section
->readin
);
3339 reader
->buffer
= cu
->per_cu
->debug_types_section
->buffer
;
3343 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3344 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3348 /* Find the base address of the compilation unit for range lists and
3349 location lists. It will normally be specified by DW_AT_low_pc.
3350 In DWARF-3 draft 4, the base address could be overridden by
3351 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3352 compilation units with discontinuous ranges. */
3355 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3357 struct attribute
*attr
;
3360 cu
->base_address
= 0;
3362 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3365 cu
->base_address
= DW_ADDR (attr
);
3370 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3373 cu
->base_address
= DW_ADDR (attr
);
3379 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3380 to combine the common parts.
3381 Process a compilation unit for a psymtab.
3382 BUFFER is a pointer to the beginning of the dwarf section buffer,
3383 either .debug_info or debug_types.
3384 INFO_PTR is a pointer to the start of the CU.
3385 Returns a pointer to the next CU. */
3388 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3389 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3390 unsigned int buffer_size
)
3392 struct objfile
*objfile
= this_cu
->objfile
;
3393 bfd
*abfd
= objfile
->obfd
;
3394 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3395 struct die_info
*comp_unit_die
;
3396 struct partial_symtab
*pst
;
3398 struct cleanup
*back_to_inner
;
3399 struct dwarf2_cu cu
;
3400 int has_children
, has_pc_info
;
3401 struct attribute
*attr
;
3402 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3403 struct die_reader_specs reader_specs
;
3404 const char *filename
;
3406 /* If this compilation unit was already read in, free the
3407 cached copy in order to read it in again. This is
3408 necessary because we skipped some symbols when we first
3409 read in the compilation unit (see load_partial_dies).
3410 This problem could be avoided, but the benefit is
3412 if (this_cu
->cu
!= NULL
)
3413 free_one_cached_comp_unit (this_cu
->cu
);
3415 /* Note that this is a pointer to our stack frame, being
3416 added to a global data structure. It will be cleaned up
3417 in free_stack_comp_unit when we finish with this
3418 compilation unit. */
3419 init_one_comp_unit (&cu
, this_cu
);
3420 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3422 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3423 buffer
, buffer_size
,
3425 this_cu
->debug_types_section
!= NULL
);
3427 /* Skip dummy compilation units. */
3428 if (info_ptr
>= buffer
+ buffer_size
3429 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3431 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3432 + cu
.header
.initial_length_size
);
3433 do_cleanups (back_to_inner
);
3437 cu
.list_in_scope
= &file_symbols
;
3439 /* Read the abbrevs for this compilation unit into a table. */
3440 dwarf2_read_abbrevs (abfd
, &cu
);
3441 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3443 /* Read the compilation unit die. */
3444 init_cu_die_reader (&reader_specs
, &cu
);
3445 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3448 if (this_cu
->debug_types_section
)
3450 /* LENGTH has not been set yet for type units. */
3451 gdb_assert (this_cu
->offset
== cu
.header
.offset
);
3452 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3454 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3456 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3457 + cu
.header
.initial_length_size
);
3458 do_cleanups (back_to_inner
);
3462 prepare_one_comp_unit (&cu
, comp_unit_die
);
3464 /* Allocate a new partial symbol table structure. */
3465 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3466 if (attr
== NULL
|| !DW_STRING (attr
))
3469 filename
= DW_STRING (attr
);
3470 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3472 /* TEXTLOW and TEXTHIGH are set below. */
3474 objfile
->global_psymbols
.next
,
3475 objfile
->static_psymbols
.next
);
3476 pst
->psymtabs_addrmap_supported
= 1;
3478 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3480 pst
->dirname
= DW_STRING (attr
);
3482 pst
->read_symtab_private
= this_cu
;
3484 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3486 /* Store the function that reads in the rest of the symbol table. */
3487 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3489 this_cu
->v
.psymtab
= pst
;
3491 dwarf2_find_base_address (comp_unit_die
, &cu
);
3493 /* Possibly set the default values of LOWPC and HIGHPC from
3495 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3496 &best_highpc
, &cu
, pst
);
3497 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3498 /* Store the contiguous range if it is not empty; it can be empty for
3499 CUs with no code. */
3500 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3501 best_lowpc
+ baseaddr
,
3502 best_highpc
+ baseaddr
- 1, pst
);
3504 /* Check if comp unit has_children.
3505 If so, read the rest of the partial symbols from this comp unit.
3506 If not, there's no more debug_info for this comp unit. */
3509 struct partial_die_info
*first_die
;
3510 CORE_ADDR lowpc
, highpc
;
3512 lowpc
= ((CORE_ADDR
) -1);
3513 highpc
= ((CORE_ADDR
) 0);
3515 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3517 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3518 ! has_pc_info
, &cu
);
3520 /* If we didn't find a lowpc, set it to highpc to avoid
3521 complaints from `maint check'. */
3522 if (lowpc
== ((CORE_ADDR
) -1))
3525 /* If the compilation unit didn't have an explicit address range,
3526 then use the information extracted from its child dies. */
3530 best_highpc
= highpc
;
3533 pst
->textlow
= best_lowpc
+ baseaddr
;
3534 pst
->texthigh
= best_highpc
+ baseaddr
;
3536 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3537 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3538 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3539 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3540 sort_pst_symbols (pst
);
3542 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3543 + cu
.header
.initial_length_size
);
3545 if (this_cu
->debug_types_section
)
3547 /* It's not clear we want to do anything with stmt lists here.
3548 Waiting to see what gcc ultimately does. */
3552 /* Get the list of files included in the current compilation unit,
3553 and build a psymtab for each of them. */
3554 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3557 do_cleanups (back_to_inner
);
3562 /* Traversal function for htab_traverse_noresize.
3563 Process one .debug_types comp-unit. */
3566 process_type_comp_unit (void **slot
, void *info
)
3568 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3569 struct dwarf2_per_cu_data
*this_cu
;
3571 gdb_assert (info
== NULL
);
3572 this_cu
= &entry
->per_cu
;
3574 gdb_assert (this_cu
->debug_types_section
->readin
);
3575 process_psymtab_comp_unit (this_cu
,
3576 this_cu
->debug_types_section
->buffer
,
3577 (this_cu
->debug_types_section
->buffer
3579 this_cu
->debug_types_section
->size
);
3584 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3585 Build partial symbol tables for the .debug_types comp-units. */
3588 build_type_psymtabs (struct objfile
*objfile
)
3590 if (! create_debug_types_hash_table (objfile
))
3593 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3594 process_type_comp_unit
, NULL
);
3597 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3600 psymtabs_addrmap_cleanup (void *o
)
3602 struct objfile
*objfile
= o
;
3604 objfile
->psymtabs_addrmap
= NULL
;
3607 /* Build the partial symbol table by doing a quick pass through the
3608 .debug_info and .debug_abbrev sections. */
3611 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3614 struct cleanup
*back_to
, *addrmap_cleanup
;
3615 struct obstack temp_obstack
;
3617 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3619 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3620 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3622 /* Any cached compilation units will be linked by the per-objfile
3623 read_in_chain. Make sure to free them when we're done. */
3624 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3626 build_type_psymtabs (objfile
);
3628 create_all_comp_units (objfile
);
3630 /* Create a temporary address map on a temporary obstack. We later
3631 copy this to the final obstack. */
3632 obstack_init (&temp_obstack
);
3633 make_cleanup_obstack_free (&temp_obstack
);
3634 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3635 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3637 /* Since the objects we're extracting from .debug_info vary in
3638 length, only the individual functions to extract them (like
3639 read_comp_unit_head and load_partial_die) can really know whether
3640 the buffer is large enough to hold another complete object.
3642 At the moment, they don't actually check that. If .debug_info
3643 holds just one extra byte after the last compilation unit's dies,
3644 then read_comp_unit_head will happily read off the end of the
3645 buffer. read_partial_die is similarly casual. Those functions
3648 For this loop condition, simply checking whether there's any data
3649 left at all should be sufficient. */
3651 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3652 + dwarf2_per_objfile
->info
.size
))
3654 struct dwarf2_per_cu_data
*this_cu
;
3656 this_cu
= dwarf2_find_comp_unit (info_ptr
3657 - dwarf2_per_objfile
->info
.buffer
,
3660 info_ptr
= process_psymtab_comp_unit (this_cu
,
3661 dwarf2_per_objfile
->info
.buffer
,
3663 dwarf2_per_objfile
->info
.size
);
3666 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3667 &objfile
->objfile_obstack
);
3668 discard_cleanups (addrmap_cleanup
);
3670 do_cleanups (back_to
);
3673 /* Load the partial DIEs for a secondary CU into memory. */
3676 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
3678 struct objfile
*objfile
= this_cu
->objfile
;
3679 bfd
*abfd
= objfile
->obfd
;
3681 struct die_info
*comp_unit_die
;
3682 struct dwarf2_cu
*cu
;
3683 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3685 struct die_reader_specs reader_specs
;
3688 gdb_assert (! this_cu
->debug_types_section
);
3690 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3691 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3693 if (this_cu
->cu
== NULL
)
3695 cu
= xmalloc (sizeof (*cu
));
3696 init_one_comp_unit (cu
, this_cu
);
3700 /* If an error occurs while loading, release our storage. */
3701 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3703 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3704 dwarf2_per_objfile
->info
.buffer
,
3705 dwarf2_per_objfile
->info
.size
,
3708 /* Skip dummy compilation units. */
3709 if (info_ptr
>= (dwarf2_per_objfile
->info
.buffer
3710 + dwarf2_per_objfile
->info
.size
)
3711 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3713 do_cleanups (free_cu_cleanup
);
3717 /* Link this CU into read_in_chain. */
3718 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3719 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3724 info_ptr
+= cu
->header
.first_die_offset
;
3727 /* Read the abbrevs for this compilation unit into a table. */
3728 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3729 dwarf2_read_abbrevs (abfd
, cu
);
3730 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3732 /* Read the compilation unit die. */
3733 init_cu_die_reader (&reader_specs
, cu
);
3734 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3737 prepare_one_comp_unit (cu
, comp_unit_die
);
3739 /* Check if comp unit has_children.
3740 If so, read the rest of the partial symbols from this comp unit.
3741 If not, there's no more debug_info for this comp unit. */
3743 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3745 do_cleanups (free_abbrevs_cleanup
);
3749 /* We've successfully allocated this compilation unit. Let our
3750 caller clean it up when finished with it. */
3751 discard_cleanups (free_cu_cleanup
);
3755 /* Create a list of all compilation units in OBJFILE.
3756 This is only done for -readnow and building partial symtabs. */
3759 create_all_comp_units (struct objfile
*objfile
)
3763 struct dwarf2_per_cu_data
**all_comp_units
;
3766 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3767 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3771 all_comp_units
= xmalloc (n_allocated
3772 * sizeof (struct dwarf2_per_cu_data
*));
3774 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3775 + dwarf2_per_objfile
->info
.size
)
3777 unsigned int length
, initial_length_size
;
3778 struct dwarf2_per_cu_data
*this_cu
;
3779 unsigned int offset
;
3781 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3783 /* Read just enough information to find out where the next
3784 compilation unit is. */
3785 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3786 &initial_length_size
);
3788 /* Save the compilation unit for later lookup. */
3789 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3790 sizeof (struct dwarf2_per_cu_data
));
3791 memset (this_cu
, 0, sizeof (*this_cu
));
3792 this_cu
->offset
= offset
;
3793 this_cu
->length
= length
+ initial_length_size
;
3794 this_cu
->objfile
= objfile
;
3796 if (n_comp_units
== n_allocated
)
3799 all_comp_units
= xrealloc (all_comp_units
,
3801 * sizeof (struct dwarf2_per_cu_data
*));
3803 all_comp_units
[n_comp_units
++] = this_cu
;
3805 info_ptr
= info_ptr
+ this_cu
->length
;
3808 dwarf2_per_objfile
->all_comp_units
3809 = obstack_alloc (&objfile
->objfile_obstack
,
3810 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3811 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3812 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3813 xfree (all_comp_units
);
3814 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3817 /* Process all loaded DIEs for compilation unit CU, starting at
3818 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3819 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3820 DW_AT_ranges). If NEED_PC is set, then this function will set
3821 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3822 and record the covered ranges in the addrmap. */
3825 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3826 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3828 struct partial_die_info
*pdi
;
3830 /* Now, march along the PDI's, descending into ones which have
3831 interesting children but skipping the children of the other ones,
3832 until we reach the end of the compilation unit. */
3838 fixup_partial_die (pdi
, cu
);
3840 /* Anonymous namespaces or modules have no name but have interesting
3841 children, so we need to look at them. Ditto for anonymous
3844 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3845 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3849 case DW_TAG_subprogram
:
3850 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3852 case DW_TAG_constant
:
3853 case DW_TAG_variable
:
3854 case DW_TAG_typedef
:
3855 case DW_TAG_union_type
:
3856 if (!pdi
->is_declaration
)
3858 add_partial_symbol (pdi
, cu
);
3861 case DW_TAG_class_type
:
3862 case DW_TAG_interface_type
:
3863 case DW_TAG_structure_type
:
3864 if (!pdi
->is_declaration
)
3866 add_partial_symbol (pdi
, cu
);
3869 case DW_TAG_enumeration_type
:
3870 if (!pdi
->is_declaration
)
3871 add_partial_enumeration (pdi
, cu
);
3873 case DW_TAG_base_type
:
3874 case DW_TAG_subrange_type
:
3875 /* File scope base type definitions are added to the partial
3877 add_partial_symbol (pdi
, cu
);
3879 case DW_TAG_namespace
:
3880 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3883 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3890 /* If the die has a sibling, skip to the sibling. */
3892 pdi
= pdi
->die_sibling
;
3896 /* Functions used to compute the fully scoped name of a partial DIE.
3898 Normally, this is simple. For C++, the parent DIE's fully scoped
3899 name is concatenated with "::" and the partial DIE's name. For
3900 Java, the same thing occurs except that "." is used instead of "::".
3901 Enumerators are an exception; they use the scope of their parent
3902 enumeration type, i.e. the name of the enumeration type is not
3903 prepended to the enumerator.
3905 There are two complexities. One is DW_AT_specification; in this
3906 case "parent" means the parent of the target of the specification,
3907 instead of the direct parent of the DIE. The other is compilers
3908 which do not emit DW_TAG_namespace; in this case we try to guess
3909 the fully qualified name of structure types from their members'
3910 linkage names. This must be done using the DIE's children rather
3911 than the children of any DW_AT_specification target. We only need
3912 to do this for structures at the top level, i.e. if the target of
3913 any DW_AT_specification (if any; otherwise the DIE itself) does not
3916 /* Compute the scope prefix associated with PDI's parent, in
3917 compilation unit CU. The result will be allocated on CU's
3918 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3919 field. NULL is returned if no prefix is necessary. */
3921 partial_die_parent_scope (struct partial_die_info
*pdi
,
3922 struct dwarf2_cu
*cu
)
3924 char *grandparent_scope
;
3925 struct partial_die_info
*parent
, *real_pdi
;
3927 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3928 then this means the parent of the specification DIE. */
3931 while (real_pdi
->has_specification
)
3932 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3934 parent
= real_pdi
->die_parent
;
3938 if (parent
->scope_set
)
3939 return parent
->scope
;
3941 fixup_partial_die (parent
, cu
);
3943 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3945 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3946 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3947 Work around this problem here. */
3948 if (cu
->language
== language_cplus
3949 && parent
->tag
== DW_TAG_namespace
3950 && strcmp (parent
->name
, "::") == 0
3951 && grandparent_scope
== NULL
)
3953 parent
->scope
= NULL
;
3954 parent
->scope_set
= 1;
3958 if (pdi
->tag
== DW_TAG_enumerator
)
3959 /* Enumerators should not get the name of the enumeration as a prefix. */
3960 parent
->scope
= grandparent_scope
;
3961 else if (parent
->tag
== DW_TAG_namespace
3962 || parent
->tag
== DW_TAG_module
3963 || parent
->tag
== DW_TAG_structure_type
3964 || parent
->tag
== DW_TAG_class_type
3965 || parent
->tag
== DW_TAG_interface_type
3966 || parent
->tag
== DW_TAG_union_type
3967 || parent
->tag
== DW_TAG_enumeration_type
)
3969 if (grandparent_scope
== NULL
)
3970 parent
->scope
= parent
->name
;
3972 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3974 parent
->name
, 0, cu
);
3978 /* FIXME drow/2004-04-01: What should we be doing with
3979 function-local names? For partial symbols, we should probably be
3981 complaint (&symfile_complaints
,
3982 _("unhandled containing DIE tag %d for DIE at %d"),
3983 parent
->tag
, pdi
->offset
);
3984 parent
->scope
= grandparent_scope
;
3987 parent
->scope_set
= 1;
3988 return parent
->scope
;
3991 /* Return the fully scoped name associated with PDI, from compilation unit
3992 CU. The result will be allocated with malloc. */
3994 partial_die_full_name (struct partial_die_info
*pdi
,
3995 struct dwarf2_cu
*cu
)
3999 /* If this is a template instantiation, we can not work out the
4000 template arguments from partial DIEs. So, unfortunately, we have
4001 to go through the full DIEs. At least any work we do building
4002 types here will be reused if full symbols are loaded later. */
4003 if (pdi
->has_template_arguments
)
4005 fixup_partial_die (pdi
, cu
);
4007 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4009 struct die_info
*die
;
4010 struct attribute attr
;
4011 struct dwarf2_cu
*ref_cu
= cu
;
4014 attr
.form
= DW_FORM_ref_addr
;
4015 attr
.u
.addr
= pdi
->offset
;
4016 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4018 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4022 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4023 if (parent_scope
== NULL
)
4026 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4030 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4032 struct objfile
*objfile
= cu
->objfile
;
4034 char *actual_name
= NULL
;
4035 const struct partial_symbol
*psym
= NULL
;
4037 int built_actual_name
= 0;
4039 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4041 actual_name
= partial_die_full_name (pdi
, cu
);
4043 built_actual_name
= 1;
4045 if (actual_name
== NULL
)
4046 actual_name
= pdi
->name
;
4050 case DW_TAG_subprogram
:
4051 if (pdi
->is_external
|| cu
->language
== language_ada
)
4053 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4054 of the global scope. But in Ada, we want to be able to access
4055 nested procedures globally. So all Ada subprograms are stored
4056 in the global scope. */
4057 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4058 mst_text, objfile); */
4059 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4061 VAR_DOMAIN
, LOC_BLOCK
,
4062 &objfile
->global_psymbols
,
4063 0, pdi
->lowpc
+ baseaddr
,
4064 cu
->language
, objfile
);
4068 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4069 mst_file_text, objfile); */
4070 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4072 VAR_DOMAIN
, LOC_BLOCK
,
4073 &objfile
->static_psymbols
,
4074 0, pdi
->lowpc
+ baseaddr
,
4075 cu
->language
, objfile
);
4078 case DW_TAG_constant
:
4080 struct psymbol_allocation_list
*list
;
4082 if (pdi
->is_external
)
4083 list
= &objfile
->global_psymbols
;
4085 list
= &objfile
->static_psymbols
;
4086 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4087 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4088 list
, 0, 0, cu
->language
, objfile
);
4091 case DW_TAG_variable
:
4093 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4097 && !dwarf2_per_objfile
->has_section_at_zero
)
4099 /* A global or static variable may also have been stripped
4100 out by the linker if unused, in which case its address
4101 will be nullified; do not add such variables into partial
4102 symbol table then. */
4104 else if (pdi
->is_external
)
4107 Don't enter into the minimal symbol tables as there is
4108 a minimal symbol table entry from the ELF symbols already.
4109 Enter into partial symbol table if it has a location
4110 descriptor or a type.
4111 If the location descriptor is missing, new_symbol will create
4112 a LOC_UNRESOLVED symbol, the address of the variable will then
4113 be determined from the minimal symbol table whenever the variable
4115 The address for the partial symbol table entry is not
4116 used by GDB, but it comes in handy for debugging partial symbol
4119 if (pdi
->locdesc
|| pdi
->has_type
)
4120 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4122 VAR_DOMAIN
, LOC_STATIC
,
4123 &objfile
->global_psymbols
,
4125 cu
->language
, objfile
);
4129 /* Static Variable. Skip symbols without location descriptors. */
4130 if (pdi
->locdesc
== NULL
)
4132 if (built_actual_name
)
4133 xfree (actual_name
);
4136 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4137 mst_file_data, objfile); */
4138 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4140 VAR_DOMAIN
, LOC_STATIC
,
4141 &objfile
->static_psymbols
,
4143 cu
->language
, objfile
);
4146 case DW_TAG_typedef
:
4147 case DW_TAG_base_type
:
4148 case DW_TAG_subrange_type
:
4149 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4151 VAR_DOMAIN
, LOC_TYPEDEF
,
4152 &objfile
->static_psymbols
,
4153 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4155 case DW_TAG_namespace
:
4156 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4158 VAR_DOMAIN
, LOC_TYPEDEF
,
4159 &objfile
->global_psymbols
,
4160 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4162 case DW_TAG_class_type
:
4163 case DW_TAG_interface_type
:
4164 case DW_TAG_structure_type
:
4165 case DW_TAG_union_type
:
4166 case DW_TAG_enumeration_type
:
4167 /* Skip external references. The DWARF standard says in the section
4168 about "Structure, Union, and Class Type Entries": "An incomplete
4169 structure, union or class type is represented by a structure,
4170 union or class entry that does not have a byte size attribute
4171 and that has a DW_AT_declaration attribute." */
4172 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4174 if (built_actual_name
)
4175 xfree (actual_name
);
4179 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4180 static vs. global. */
4181 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4183 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4184 (cu
->language
== language_cplus
4185 || cu
->language
== language_java
)
4186 ? &objfile
->global_psymbols
4187 : &objfile
->static_psymbols
,
4188 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4191 case DW_TAG_enumerator
:
4192 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4194 VAR_DOMAIN
, LOC_CONST
,
4195 (cu
->language
== language_cplus
4196 || cu
->language
== language_java
)
4197 ? &objfile
->global_psymbols
4198 : &objfile
->static_psymbols
,
4199 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4205 if (built_actual_name
)
4206 xfree (actual_name
);
4209 /* Read a partial die corresponding to a namespace; also, add a symbol
4210 corresponding to that namespace to the symbol table. NAMESPACE is
4211 the name of the enclosing namespace. */
4214 add_partial_namespace (struct partial_die_info
*pdi
,
4215 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4216 int need_pc
, struct dwarf2_cu
*cu
)
4218 /* Add a symbol for the namespace. */
4220 add_partial_symbol (pdi
, cu
);
4222 /* Now scan partial symbols in that namespace. */
4224 if (pdi
->has_children
)
4225 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4228 /* Read a partial die corresponding to a Fortran module. */
4231 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4232 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4234 /* Now scan partial symbols in that module. */
4236 if (pdi
->has_children
)
4237 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4240 /* Read a partial die corresponding to a subprogram and create a partial
4241 symbol for that subprogram. When the CU language allows it, this
4242 routine also defines a partial symbol for each nested subprogram
4243 that this subprogram contains.
4245 DIE my also be a lexical block, in which case we simply search
4246 recursively for suprograms defined inside that lexical block.
4247 Again, this is only performed when the CU language allows this
4248 type of definitions. */
4251 add_partial_subprogram (struct partial_die_info
*pdi
,
4252 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4253 int need_pc
, struct dwarf2_cu
*cu
)
4255 if (pdi
->tag
== DW_TAG_subprogram
)
4257 if (pdi
->has_pc_info
)
4259 if (pdi
->lowpc
< *lowpc
)
4260 *lowpc
= pdi
->lowpc
;
4261 if (pdi
->highpc
> *highpc
)
4262 *highpc
= pdi
->highpc
;
4266 struct objfile
*objfile
= cu
->objfile
;
4268 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4269 SECT_OFF_TEXT (objfile
));
4270 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4271 pdi
->lowpc
+ baseaddr
,
4272 pdi
->highpc
- 1 + baseaddr
,
4273 cu
->per_cu
->v
.psymtab
);
4275 if (!pdi
->is_declaration
)
4276 /* Ignore subprogram DIEs that do not have a name, they are
4277 illegal. Do not emit a complaint at this point, we will
4278 do so when we convert this psymtab into a symtab. */
4280 add_partial_symbol (pdi
, cu
);
4284 if (! pdi
->has_children
)
4287 if (cu
->language
== language_ada
)
4289 pdi
= pdi
->die_child
;
4292 fixup_partial_die (pdi
, cu
);
4293 if (pdi
->tag
== DW_TAG_subprogram
4294 || pdi
->tag
== DW_TAG_lexical_block
)
4295 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4296 pdi
= pdi
->die_sibling
;
4301 /* Read a partial die corresponding to an enumeration type. */
4304 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4305 struct dwarf2_cu
*cu
)
4307 struct partial_die_info
*pdi
;
4309 if (enum_pdi
->name
!= NULL
)
4310 add_partial_symbol (enum_pdi
, cu
);
4312 pdi
= enum_pdi
->die_child
;
4315 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4316 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4318 add_partial_symbol (pdi
, cu
);
4319 pdi
= pdi
->die_sibling
;
4323 /* Return the initial uleb128 in the die at INFO_PTR. */
4326 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4328 unsigned int bytes_read
;
4330 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4333 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4334 Return the corresponding abbrev, or NULL if the number is zero (indicating
4335 an empty DIE). In either case *BYTES_READ will be set to the length of
4336 the initial number. */
4338 static struct abbrev_info
*
4339 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4340 struct dwarf2_cu
*cu
)
4342 bfd
*abfd
= cu
->objfile
->obfd
;
4343 unsigned int abbrev_number
;
4344 struct abbrev_info
*abbrev
;
4346 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4348 if (abbrev_number
== 0)
4351 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4354 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4355 abbrev_number
, bfd_get_filename (abfd
));
4361 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4362 Returns a pointer to the end of a series of DIEs, terminated by an empty
4363 DIE. Any children of the skipped DIEs will also be skipped. */
4366 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4368 struct abbrev_info
*abbrev
;
4369 unsigned int bytes_read
;
4373 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4375 return info_ptr
+ bytes_read
;
4377 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4381 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4382 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4383 abbrev corresponding to that skipped uleb128 should be passed in
4384 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4388 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4389 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4391 unsigned int bytes_read
;
4392 struct attribute attr
;
4393 bfd
*abfd
= cu
->objfile
->obfd
;
4394 unsigned int form
, i
;
4396 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4398 /* The only abbrev we care about is DW_AT_sibling. */
4399 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4401 read_attribute (&attr
, &abbrev
->attrs
[i
],
4402 abfd
, info_ptr
, cu
);
4403 if (attr
.form
== DW_FORM_ref_addr
)
4404 complaint (&symfile_complaints
,
4405 _("ignoring absolute DW_AT_sibling"));
4407 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4410 /* If it isn't DW_AT_sibling, skip this attribute. */
4411 form
= abbrev
->attrs
[i
].form
;
4415 case DW_FORM_ref_addr
:
4416 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4417 and later it is offset sized. */
4418 if (cu
->header
.version
== 2)
4419 info_ptr
+= cu
->header
.addr_size
;
4421 info_ptr
+= cu
->header
.offset_size
;
4424 info_ptr
+= cu
->header
.addr_size
;
4431 case DW_FORM_flag_present
:
4443 case DW_FORM_ref_sig8
:
4446 case DW_FORM_string
:
4447 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4448 info_ptr
+= bytes_read
;
4450 case DW_FORM_sec_offset
:
4452 info_ptr
+= cu
->header
.offset_size
;
4454 case DW_FORM_exprloc
:
4456 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4457 info_ptr
+= bytes_read
;
4459 case DW_FORM_block1
:
4460 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4462 case DW_FORM_block2
:
4463 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4465 case DW_FORM_block4
:
4466 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4470 case DW_FORM_ref_udata
:
4471 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4473 case DW_FORM_indirect
:
4474 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4475 info_ptr
+= bytes_read
;
4476 /* We need to continue parsing from here, so just go back to
4478 goto skip_attribute
;
4481 error (_("Dwarf Error: Cannot handle %s "
4482 "in DWARF reader [in module %s]"),
4483 dwarf_form_name (form
),
4484 bfd_get_filename (abfd
));
4488 if (abbrev
->has_children
)
4489 return skip_children (buffer
, info_ptr
, cu
);
4494 /* Locate ORIG_PDI's sibling.
4495 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4499 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4500 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4501 bfd
*abfd
, struct dwarf2_cu
*cu
)
4503 /* Do we know the sibling already? */
4505 if (orig_pdi
->sibling
)
4506 return orig_pdi
->sibling
;
4508 /* Are there any children to deal with? */
4510 if (!orig_pdi
->has_children
)
4513 /* Skip the children the long way. */
4515 return skip_children (buffer
, info_ptr
, cu
);
4518 /* Expand this partial symbol table into a full symbol table. */
4521 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4527 warning (_("bug: psymtab for %s is already read in."),
4534 printf_filtered (_("Reading in symbols for %s..."),
4536 gdb_flush (gdb_stdout
);
4539 /* Restore our global data. */
4540 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4541 dwarf2_objfile_data_key
);
4543 /* If this psymtab is constructed from a debug-only objfile, the
4544 has_section_at_zero flag will not necessarily be correct. We
4545 can get the correct value for this flag by looking at the data
4546 associated with the (presumably stripped) associated objfile. */
4547 if (pst
->objfile
->separate_debug_objfile_backlink
)
4549 struct dwarf2_per_objfile
*dpo_backlink
4550 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4551 dwarf2_objfile_data_key
);
4553 dwarf2_per_objfile
->has_section_at_zero
4554 = dpo_backlink
->has_section_at_zero
;
4557 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4559 psymtab_to_symtab_1 (pst
);
4561 /* Finish up the debug error message. */
4563 printf_filtered (_("done.\n"));
4568 /* Reading in full CUs. */
4570 /* Add PER_CU to the queue. */
4573 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4575 struct dwarf2_queue_item
*item
;
4578 item
= xmalloc (sizeof (*item
));
4579 item
->per_cu
= per_cu
;
4582 if (dwarf2_queue
== NULL
)
4583 dwarf2_queue
= item
;
4585 dwarf2_queue_tail
->next
= item
;
4587 dwarf2_queue_tail
= item
;
4590 /* Process the queue. */
4593 process_queue (void)
4595 struct dwarf2_queue_item
*item
, *next_item
;
4597 /* The queue starts out with one item, but following a DIE reference
4598 may load a new CU, adding it to the end of the queue. */
4599 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4601 if (dwarf2_per_objfile
->using_index
4602 ? !item
->per_cu
->v
.quick
->symtab
4603 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4604 process_full_comp_unit (item
->per_cu
);
4606 item
->per_cu
->queued
= 0;
4607 next_item
= item
->next
;
4611 dwarf2_queue_tail
= NULL
;
4614 /* Free all allocated queue entries. This function only releases anything if
4615 an error was thrown; if the queue was processed then it would have been
4616 freed as we went along. */
4619 dwarf2_release_queue (void *dummy
)
4621 struct dwarf2_queue_item
*item
, *last
;
4623 item
= dwarf2_queue
;
4626 /* Anything still marked queued is likely to be in an
4627 inconsistent state, so discard it. */
4628 if (item
->per_cu
->queued
)
4630 if (item
->per_cu
->cu
!= NULL
)
4631 free_one_cached_comp_unit (item
->per_cu
->cu
);
4632 item
->per_cu
->queued
= 0;
4640 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4643 /* Read in full symbols for PST, and anything it depends on. */
4646 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4648 struct dwarf2_per_cu_data
*per_cu
;
4649 struct cleanup
*back_to
;
4652 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4653 if (!pst
->dependencies
[i
]->readin
)
4655 /* Inform about additional files that need to be read in. */
4658 /* FIXME: i18n: Need to make this a single string. */
4659 fputs_filtered (" ", gdb_stdout
);
4661 fputs_filtered ("and ", gdb_stdout
);
4663 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4664 wrap_here (""); /* Flush output. */
4665 gdb_flush (gdb_stdout
);
4667 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4670 per_cu
= pst
->read_symtab_private
;
4674 /* It's an include file, no symbols to read for it.
4675 Everything is in the parent symtab. */
4680 dw2_do_instantiate_symtab (per_cu
);
4683 /* Load the DIEs associated with PER_CU into memory. */
4686 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4688 struct objfile
*objfile
= per_cu
->objfile
;
4689 bfd
*abfd
= objfile
->obfd
;
4690 struct dwarf2_cu
*cu
;
4691 unsigned int offset
;
4692 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4693 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4694 struct attribute
*attr
;
4697 gdb_assert (! per_cu
->debug_types_section
);
4699 /* Set local variables from the partial symbol table info. */
4700 offset
= per_cu
->offset
;
4702 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4703 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4704 beg_of_comp_unit
= info_ptr
;
4706 if (per_cu
->cu
== NULL
)
4708 cu
= xmalloc (sizeof (*cu
));
4709 init_one_comp_unit (cu
, per_cu
);
4713 /* If an error occurs while loading, release our storage. */
4714 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4716 /* Read in the comp_unit header. */
4717 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4719 /* Skip dummy compilation units. */
4720 if (info_ptr
>= (dwarf2_per_objfile
->info
.buffer
4721 + dwarf2_per_objfile
->info
.size
)
4722 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4724 do_cleanups (free_cu_cleanup
);
4728 /* Complete the cu_header. */
4729 cu
->header
.offset
= offset
;
4730 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4732 /* Read the abbrevs for this compilation unit. */
4733 dwarf2_read_abbrevs (abfd
, cu
);
4734 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4736 /* Link this CU into read_in_chain. */
4737 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4738 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4743 info_ptr
+= cu
->header
.first_die_offset
;
4746 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4748 /* We try not to read any attributes in this function, because not
4749 all CUs needed for references have been loaded yet, and symbol
4750 table processing isn't initialized. But we have to set the CU language,
4751 or we won't be able to build types correctly. */
4752 prepare_one_comp_unit (cu
, cu
->dies
);
4754 /* Similarly, if we do not read the producer, we can not apply
4755 producer-specific interpretation. */
4756 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4758 cu
->producer
= DW_STRING (attr
);
4762 do_cleanups (free_abbrevs_cleanup
);
4764 /* We've successfully allocated this compilation unit. Let our
4765 caller clean it up when finished with it. */
4766 discard_cleanups (free_cu_cleanup
);
4770 /* Add a DIE to the delayed physname list. */
4773 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4774 const char *name
, struct die_info
*die
,
4775 struct dwarf2_cu
*cu
)
4777 struct delayed_method_info mi
;
4779 mi
.fnfield_index
= fnfield_index
;
4783 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4786 /* A cleanup for freeing the delayed method list. */
4789 free_delayed_list (void *ptr
)
4791 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4792 if (cu
->method_list
!= NULL
)
4794 VEC_free (delayed_method_info
, cu
->method_list
);
4795 cu
->method_list
= NULL
;
4799 /* Compute the physnames of any methods on the CU's method list.
4801 The computation of method physnames is delayed in order to avoid the
4802 (bad) condition that one of the method's formal parameters is of an as yet
4806 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4809 struct delayed_method_info
*mi
;
4810 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4812 const char *physname
;
4813 struct fn_fieldlist
*fn_flp
4814 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4815 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4816 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4820 /* Generate full symbol information for PER_CU, whose DIEs have
4821 already been loaded into memory. */
4824 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4826 struct dwarf2_cu
*cu
= per_cu
->cu
;
4827 struct objfile
*objfile
= per_cu
->objfile
;
4828 CORE_ADDR lowpc
, highpc
;
4829 struct symtab
*symtab
;
4830 struct cleanup
*back_to
, *delayed_list_cleanup
;
4833 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4836 back_to
= make_cleanup (really_free_pendings
, NULL
);
4837 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4839 cu
->list_in_scope
= &file_symbols
;
4841 /* Do line number decoding in read_file_scope () */
4842 process_die (cu
->dies
, cu
);
4844 /* Now that we have processed all the DIEs in the CU, all the types
4845 should be complete, and it should now be safe to compute all of the
4847 compute_delayed_physnames (cu
);
4848 do_cleanups (delayed_list_cleanup
);
4850 /* Some compilers don't define a DW_AT_high_pc attribute for the
4851 compilation unit. If the DW_AT_high_pc is missing, synthesize
4852 it, by scanning the DIE's below the compilation unit. */
4853 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4855 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4859 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
4861 /* Set symtab language to language from DW_AT_language. If the
4862 compilation is from a C file generated by language preprocessors, do
4863 not set the language if it was already deduced by start_subfile. */
4864 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4865 symtab
->language
= cu
->language
;
4867 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4868 produce DW_AT_location with location lists but it can be possibly
4869 invalid without -fvar-tracking.
4871 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4872 needed, it would be wrong due to missing DW_AT_producer there.
4874 Still one can confuse GDB by using non-standard GCC compilation
4875 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4877 if (cu
->has_loclist
&& gcc_4_minor
>= 0)
4878 symtab
->locations_valid
= 1;
4880 if (gcc_4_minor
>= 5)
4881 symtab
->epilogue_unwind_valid
= 1;
4883 symtab
->call_site_htab
= cu
->call_site_htab
;
4886 if (dwarf2_per_objfile
->using_index
)
4887 per_cu
->v
.quick
->symtab
= symtab
;
4890 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4891 pst
->symtab
= symtab
;
4895 do_cleanups (back_to
);
4898 /* Process a die and its children. */
4901 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4905 case DW_TAG_padding
:
4907 case DW_TAG_compile_unit
:
4908 read_file_scope (die
, cu
);
4910 case DW_TAG_type_unit
:
4911 read_type_unit_scope (die
, cu
);
4913 case DW_TAG_subprogram
:
4914 case DW_TAG_inlined_subroutine
:
4915 read_func_scope (die
, cu
);
4917 case DW_TAG_lexical_block
:
4918 case DW_TAG_try_block
:
4919 case DW_TAG_catch_block
:
4920 read_lexical_block_scope (die
, cu
);
4922 case DW_TAG_GNU_call_site
:
4923 read_call_site_scope (die
, cu
);
4925 case DW_TAG_class_type
:
4926 case DW_TAG_interface_type
:
4927 case DW_TAG_structure_type
:
4928 case DW_TAG_union_type
:
4929 process_structure_scope (die
, cu
);
4931 case DW_TAG_enumeration_type
:
4932 process_enumeration_scope (die
, cu
);
4935 /* These dies have a type, but processing them does not create
4936 a symbol or recurse to process the children. Therefore we can
4937 read them on-demand through read_type_die. */
4938 case DW_TAG_subroutine_type
:
4939 case DW_TAG_set_type
:
4940 case DW_TAG_array_type
:
4941 case DW_TAG_pointer_type
:
4942 case DW_TAG_ptr_to_member_type
:
4943 case DW_TAG_reference_type
:
4944 case DW_TAG_string_type
:
4947 case DW_TAG_base_type
:
4948 case DW_TAG_subrange_type
:
4949 case DW_TAG_typedef
:
4950 /* Add a typedef symbol for the type definition, if it has a
4952 new_symbol (die
, read_type_die (die
, cu
), cu
);
4954 case DW_TAG_common_block
:
4955 read_common_block (die
, cu
);
4957 case DW_TAG_common_inclusion
:
4959 case DW_TAG_namespace
:
4960 processing_has_namespace_info
= 1;
4961 read_namespace (die
, cu
);
4964 processing_has_namespace_info
= 1;
4965 read_module (die
, cu
);
4967 case DW_TAG_imported_declaration
:
4968 case DW_TAG_imported_module
:
4969 processing_has_namespace_info
= 1;
4970 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4971 || cu
->language
!= language_fortran
))
4972 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4973 dwarf_tag_name (die
->tag
));
4974 read_import_statement (die
, cu
);
4977 new_symbol (die
, NULL
, cu
);
4982 /* A helper function for dwarf2_compute_name which determines whether DIE
4983 needs to have the name of the scope prepended to the name listed in the
4987 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4989 struct attribute
*attr
;
4993 case DW_TAG_namespace
:
4994 case DW_TAG_typedef
:
4995 case DW_TAG_class_type
:
4996 case DW_TAG_interface_type
:
4997 case DW_TAG_structure_type
:
4998 case DW_TAG_union_type
:
4999 case DW_TAG_enumeration_type
:
5000 case DW_TAG_enumerator
:
5001 case DW_TAG_subprogram
:
5005 case DW_TAG_variable
:
5006 case DW_TAG_constant
:
5007 /* We only need to prefix "globally" visible variables. These include
5008 any variable marked with DW_AT_external or any variable that
5009 lives in a namespace. [Variables in anonymous namespaces
5010 require prefixing, but they are not DW_AT_external.] */
5012 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
5014 struct dwarf2_cu
*spec_cu
= cu
;
5016 return die_needs_namespace (die_specification (die
, &spec_cu
),
5020 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5021 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
5022 && die
->parent
->tag
!= DW_TAG_module
)
5024 /* A variable in a lexical block of some kind does not need a
5025 namespace, even though in C++ such variables may be external
5026 and have a mangled name. */
5027 if (die
->parent
->tag
== DW_TAG_lexical_block
5028 || die
->parent
->tag
== DW_TAG_try_block
5029 || die
->parent
->tag
== DW_TAG_catch_block
5030 || die
->parent
->tag
== DW_TAG_subprogram
)
5039 /* Retrieve the last character from a mem_file. */
5042 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
5044 char *last_char_p
= (char *) object
;
5047 *last_char_p
= buffer
[length
- 1];
5050 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5051 compute the physname for the object, which include a method's
5052 formal parameters (C++/Java) and return type (Java).
5054 For Ada, return the DIE's linkage name rather than the fully qualified
5055 name. PHYSNAME is ignored..
5057 The result is allocated on the objfile_obstack and canonicalized. */
5060 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5063 struct objfile
*objfile
= cu
->objfile
;
5066 name
= dwarf2_name (die
, cu
);
5068 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5069 compute it by typename_concat inside GDB. */
5070 if (cu
->language
== language_ada
5071 || (cu
->language
== language_fortran
&& physname
))
5073 /* For Ada unit, we prefer the linkage name over the name, as
5074 the former contains the exported name, which the user expects
5075 to be able to reference. Ideally, we want the user to be able
5076 to reference this entity using either natural or linkage name,
5077 but we haven't started looking at this enhancement yet. */
5078 struct attribute
*attr
;
5080 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5082 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5083 if (attr
&& DW_STRING (attr
))
5084 return DW_STRING (attr
);
5087 /* These are the only languages we know how to qualify names in. */
5089 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5090 || cu
->language
== language_fortran
))
5092 if (die_needs_namespace (die
, cu
))
5096 struct ui_file
*buf
;
5098 prefix
= determine_prefix (die
, cu
);
5099 buf
= mem_fileopen ();
5100 if (*prefix
!= '\0')
5102 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5105 fputs_unfiltered (prefixed_name
, buf
);
5106 xfree (prefixed_name
);
5109 fputs_unfiltered (name
, buf
);
5111 /* Template parameters may be specified in the DIE's DW_AT_name, or
5112 as children with DW_TAG_template_type_param or
5113 DW_TAG_value_type_param. If the latter, add them to the name
5114 here. If the name already has template parameters, then
5115 skip this step; some versions of GCC emit both, and
5116 it is more efficient to use the pre-computed name.
5118 Something to keep in mind about this process: it is very
5119 unlikely, or in some cases downright impossible, to produce
5120 something that will match the mangled name of a function.
5121 If the definition of the function has the same debug info,
5122 we should be able to match up with it anyway. But fallbacks
5123 using the minimal symbol, for instance to find a method
5124 implemented in a stripped copy of libstdc++, will not work.
5125 If we do not have debug info for the definition, we will have to
5126 match them up some other way.
5128 When we do name matching there is a related problem with function
5129 templates; two instantiated function templates are allowed to
5130 differ only by their return types, which we do not add here. */
5132 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5134 struct attribute
*attr
;
5135 struct die_info
*child
;
5138 die
->building_fullname
= 1;
5140 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5145 struct dwarf2_locexpr_baton
*baton
;
5148 if (child
->tag
!= DW_TAG_template_type_param
5149 && child
->tag
!= DW_TAG_template_value_param
)
5154 fputs_unfiltered ("<", buf
);
5158 fputs_unfiltered (", ", buf
);
5160 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5163 complaint (&symfile_complaints
,
5164 _("template parameter missing DW_AT_type"));
5165 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5168 type
= die_type (child
, cu
);
5170 if (child
->tag
== DW_TAG_template_type_param
)
5172 c_print_type (type
, "", buf
, -1, 0);
5176 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5179 complaint (&symfile_complaints
,
5180 _("template parameter missing "
5181 "DW_AT_const_value"));
5182 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5186 dwarf2_const_value_attr (attr
, type
, name
,
5187 &cu
->comp_unit_obstack
, cu
,
5188 &value
, &bytes
, &baton
);
5190 if (TYPE_NOSIGN (type
))
5191 /* GDB prints characters as NUMBER 'CHAR'. If that's
5192 changed, this can use value_print instead. */
5193 c_printchar (value
, type
, buf
);
5196 struct value_print_options opts
;
5199 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5203 else if (bytes
!= NULL
)
5205 v
= allocate_value (type
);
5206 memcpy (value_contents_writeable (v
), bytes
,
5207 TYPE_LENGTH (type
));
5210 v
= value_from_longest (type
, value
);
5212 /* Specify decimal so that we do not depend on
5214 get_formatted_print_options (&opts
, 'd');
5216 value_print (v
, buf
, &opts
);
5222 die
->building_fullname
= 0;
5226 /* Close the argument list, with a space if necessary
5227 (nested templates). */
5228 char last_char
= '\0';
5229 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5230 if (last_char
== '>')
5231 fputs_unfiltered (" >", buf
);
5233 fputs_unfiltered (">", buf
);
5237 /* For Java and C++ methods, append formal parameter type
5238 information, if PHYSNAME. */
5240 if (physname
&& die
->tag
== DW_TAG_subprogram
5241 && (cu
->language
== language_cplus
5242 || cu
->language
== language_java
))
5244 struct type
*type
= read_type_die (die
, cu
);
5246 c_type_print_args (type
, buf
, 1, cu
->language
);
5248 if (cu
->language
== language_java
)
5250 /* For java, we must append the return type to method
5252 if (die
->tag
== DW_TAG_subprogram
)
5253 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5256 else if (cu
->language
== language_cplus
)
5258 /* Assume that an artificial first parameter is
5259 "this", but do not crash if it is not. RealView
5260 marks unnamed (and thus unused) parameters as
5261 artificial; there is no way to differentiate
5263 if (TYPE_NFIELDS (type
) > 0
5264 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5265 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5266 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5268 fputs_unfiltered (" const", buf
);
5272 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
5274 ui_file_delete (buf
);
5276 if (cu
->language
== language_cplus
)
5279 = dwarf2_canonicalize_name (name
, cu
,
5280 &objfile
->objfile_obstack
);
5291 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5292 If scope qualifiers are appropriate they will be added. The result
5293 will be allocated on the objfile_obstack, or NULL if the DIE does
5294 not have a name. NAME may either be from a previous call to
5295 dwarf2_name or NULL.
5297 The output string will be canonicalized (if C++/Java). */
5300 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5302 return dwarf2_compute_name (name
, die
, cu
, 0);
5305 /* Construct a physname for the given DIE in CU. NAME may either be
5306 from a previous call to dwarf2_name or NULL. The result will be
5307 allocated on the objfile_objstack or NULL if the DIE does not have a
5310 The output string will be canonicalized (if C++/Java). */
5313 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5315 struct objfile
*objfile
= cu
->objfile
;
5316 struct attribute
*attr
;
5317 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5318 struct cleanup
*back_to
;
5321 /* In this case dwarf2_compute_name is just a shortcut not building anything
5323 if (!die_needs_namespace (die
, cu
))
5324 return dwarf2_compute_name (name
, die
, cu
, 1);
5326 back_to
= make_cleanup (null_cleanup
, NULL
);
5328 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5330 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5332 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5334 if (attr
&& DW_STRING (attr
))
5338 mangled
= DW_STRING (attr
);
5340 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5341 type. It is easier for GDB users to search for such functions as
5342 `name(params)' than `long name(params)'. In such case the minimal
5343 symbol names do not match the full symbol names but for template
5344 functions there is never a need to look up their definition from their
5345 declaration so the only disadvantage remains the minimal symbol
5346 variant `long name(params)' does not have the proper inferior type.
5349 demangled
= cplus_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
5350 | (cu
->language
== language_java
5351 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5355 make_cleanup (xfree
, demangled
);
5365 if (canon
== NULL
|| check_physname
)
5367 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5369 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5371 /* It may not mean a bug in GDB. The compiler could also
5372 compute DW_AT_linkage_name incorrectly. But in such case
5373 GDB would need to be bug-to-bug compatible. */
5375 complaint (&symfile_complaints
,
5376 _("Computed physname <%s> does not match demangled <%s> "
5377 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5378 physname
, canon
, mangled
, die
->offset
, objfile
->name
);
5380 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5381 is available here - over computed PHYSNAME. It is safer
5382 against both buggy GDB and buggy compilers. */
5396 retval
= obsavestring (retval
, strlen (retval
),
5397 &objfile
->objfile_obstack
);
5399 do_cleanups (back_to
);
5403 /* Read the import statement specified by the given die and record it. */
5406 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5408 struct objfile
*objfile
= cu
->objfile
;
5409 struct attribute
*import_attr
;
5410 struct die_info
*imported_die
, *child_die
;
5411 struct dwarf2_cu
*imported_cu
;
5412 const char *imported_name
;
5413 const char *imported_name_prefix
;
5414 const char *canonical_name
;
5415 const char *import_alias
;
5416 const char *imported_declaration
= NULL
;
5417 const char *import_prefix
;
5418 VEC (const_char_ptr
) *excludes
= NULL
;
5419 struct cleanup
*cleanups
;
5423 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5424 if (import_attr
== NULL
)
5426 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5427 dwarf_tag_name (die
->tag
));
5432 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5433 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5434 if (imported_name
== NULL
)
5436 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5438 The import in the following code:
5452 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5453 <52> DW_AT_decl_file : 1
5454 <53> DW_AT_decl_line : 6
5455 <54> DW_AT_import : <0x75>
5456 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5458 <5b> DW_AT_decl_file : 1
5459 <5c> DW_AT_decl_line : 2
5460 <5d> DW_AT_type : <0x6e>
5462 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5463 <76> DW_AT_byte_size : 4
5464 <77> DW_AT_encoding : 5 (signed)
5466 imports the wrong die ( 0x75 instead of 0x58 ).
5467 This case will be ignored until the gcc bug is fixed. */
5471 /* Figure out the local name after import. */
5472 import_alias
= dwarf2_name (die
, cu
);
5474 /* Figure out where the statement is being imported to. */
5475 import_prefix
= determine_prefix (die
, cu
);
5477 /* Figure out what the scope of the imported die is and prepend it
5478 to the name of the imported die. */
5479 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5481 if (imported_die
->tag
!= DW_TAG_namespace
5482 && imported_die
->tag
!= DW_TAG_module
)
5484 imported_declaration
= imported_name
;
5485 canonical_name
= imported_name_prefix
;
5487 else if (strlen (imported_name_prefix
) > 0)
5489 temp
= alloca (strlen (imported_name_prefix
)
5490 + 2 + strlen (imported_name
) + 1);
5491 strcpy (temp
, imported_name_prefix
);
5492 strcat (temp
, "::");
5493 strcat (temp
, imported_name
);
5494 canonical_name
= temp
;
5497 canonical_name
= imported_name
;
5499 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5501 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5502 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5503 child_die
= sibling_die (child_die
))
5505 /* DWARF-4: A Fortran use statement with a “rename list” may be
5506 represented by an imported module entry with an import attribute
5507 referring to the module and owned entries corresponding to those
5508 entities that are renamed as part of being imported. */
5510 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5512 complaint (&symfile_complaints
,
5513 _("child DW_TAG_imported_declaration expected "
5514 "- DIE at 0x%x [in module %s]"),
5515 child_die
->offset
, objfile
->name
);
5519 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5520 if (import_attr
== NULL
)
5522 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5523 dwarf_tag_name (child_die
->tag
));
5528 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5530 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5531 if (imported_name
== NULL
)
5533 complaint (&symfile_complaints
,
5534 _("child DW_TAG_imported_declaration has unknown "
5535 "imported name - DIE at 0x%x [in module %s]"),
5536 child_die
->offset
, objfile
->name
);
5540 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5542 process_die (child_die
, cu
);
5545 cp_add_using_directive (import_prefix
,
5548 imported_declaration
,
5550 &objfile
->objfile_obstack
);
5552 do_cleanups (cleanups
);
5555 /* Cleanup function for read_file_scope. */
5558 free_cu_line_header (void *arg
)
5560 struct dwarf2_cu
*cu
= arg
;
5562 free_line_header (cu
->line_header
);
5563 cu
->line_header
= NULL
;
5567 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5568 char **name
, char **comp_dir
)
5570 struct attribute
*attr
;
5575 /* Find the filename. Do not use dwarf2_name here, since the filename
5576 is not a source language identifier. */
5577 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5580 *name
= DW_STRING (attr
);
5583 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5585 *comp_dir
= DW_STRING (attr
);
5586 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5588 *comp_dir
= ldirname (*name
);
5589 if (*comp_dir
!= NULL
)
5590 make_cleanup (xfree
, *comp_dir
);
5592 if (*comp_dir
!= NULL
)
5594 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5595 directory, get rid of it. */
5596 char *cp
= strchr (*comp_dir
, ':');
5598 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5603 *name
= "<unknown>";
5606 /* Handle DW_AT_stmt_list for a compilation unit. */
5609 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
5610 const char *comp_dir
)
5612 struct attribute
*attr
;
5613 struct objfile
*objfile
= cu
->objfile
;
5614 bfd
*abfd
= objfile
->obfd
;
5616 /* Decode line number information if present. We do this before
5617 processing child DIEs, so that the line header table is available
5618 for DW_AT_decl_file. */
5619 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5622 unsigned int line_offset
= DW_UNSND (attr
);
5623 struct line_header
*line_header
5624 = dwarf_decode_line_header (line_offset
, abfd
, cu
);
5628 cu
->line_header
= line_header
;
5629 make_cleanup (free_cu_line_header
, cu
);
5630 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5635 /* Process DW_TAG_compile_unit. */
5638 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5640 struct objfile
*objfile
= cu
->objfile
;
5641 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5642 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5643 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5644 struct attribute
*attr
;
5646 char *comp_dir
= NULL
;
5647 struct die_info
*child_die
;
5648 bfd
*abfd
= objfile
->obfd
;
5651 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5653 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5655 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5656 from finish_block. */
5657 if (lowpc
== ((CORE_ADDR
) -1))
5662 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5664 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5667 set_cu_language (DW_UNSND (attr
), cu
);
5670 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5672 cu
->producer
= DW_STRING (attr
);
5674 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5675 standardised yet. As a workaround for the language detection we fall
5676 back to the DW_AT_producer string. */
5677 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5678 cu
->language
= language_opencl
;
5680 /* We assume that we're processing GCC output. */
5681 processing_gcc_compilation
= 2;
5683 processing_has_namespace_info
= 0;
5685 start_symtab (name
, comp_dir
, lowpc
);
5686 record_debugformat ("DWARF 2");
5687 record_producer (cu
->producer
);
5689 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5691 /* Process all dies in compilation unit. */
5692 if (die
->child
!= NULL
)
5694 child_die
= die
->child
;
5695 while (child_die
&& child_die
->tag
)
5697 process_die (child_die
, cu
);
5698 child_die
= sibling_die (child_die
);
5702 /* Decode macro information, if present. Dwarf 2 macro information
5703 refers to information in the line number info statement program
5704 header, so we can only read it if we've read the header
5706 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
5707 if (attr
&& cu
->line_header
)
5709 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
5710 complaint (&symfile_complaints
,
5711 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5713 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
5715 &dwarf2_per_objfile
->macro
, 1);
5719 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5720 if (attr
&& cu
->line_header
)
5722 unsigned int macro_offset
= DW_UNSND (attr
);
5724 dwarf_decode_macros (cu
->line_header
, macro_offset
,
5726 &dwarf2_per_objfile
->macinfo
, 0);
5730 do_cleanups (back_to
);
5733 /* Process DW_TAG_type_unit.
5734 For TUs we want to skip the first top level sibling if it's not the
5735 actual type being defined by this TU. In this case the first top
5736 level sibling is there to provide context only. */
5739 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5741 struct objfile
*objfile
= cu
->objfile
;
5742 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5744 struct attribute
*attr
;
5746 char *comp_dir
= NULL
;
5747 struct die_info
*child_die
;
5748 bfd
*abfd
= objfile
->obfd
;
5750 /* start_symtab needs a low pc, but we don't really have one.
5751 Do what read_file_scope would do in the absence of such info. */
5752 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5754 /* Find the filename. Do not use dwarf2_name here, since the filename
5755 is not a source language identifier. */
5756 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5758 name
= DW_STRING (attr
);
5760 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5762 comp_dir
= DW_STRING (attr
);
5763 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5765 comp_dir
= ldirname (name
);
5766 if (comp_dir
!= NULL
)
5767 make_cleanup (xfree
, comp_dir
);
5773 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5775 set_cu_language (DW_UNSND (attr
), cu
);
5777 /* This isn't technically needed today. It is done for symmetry
5778 with read_file_scope. */
5779 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5781 cu
->producer
= DW_STRING (attr
);
5783 /* We assume that we're processing GCC output. */
5784 processing_gcc_compilation
= 2;
5786 processing_has_namespace_info
= 0;
5788 start_symtab (name
, comp_dir
, lowpc
);
5789 record_debugformat ("DWARF 2");
5790 record_producer (cu
->producer
);
5792 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5794 /* Process the dies in the type unit. */
5795 if (die
->child
== NULL
)
5797 dump_die_for_error (die
);
5798 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5799 bfd_get_filename (abfd
));
5802 child_die
= die
->child
;
5804 while (child_die
&& child_die
->tag
)
5806 process_die (child_die
, cu
);
5808 child_die
= sibling_die (child_die
);
5811 do_cleanups (back_to
);
5814 /* qsort helper for inherit_abstract_dies. */
5817 unsigned_int_compar (const void *ap
, const void *bp
)
5819 unsigned int a
= *(unsigned int *) ap
;
5820 unsigned int b
= *(unsigned int *) bp
;
5822 return (a
> b
) - (b
> a
);
5825 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5826 Inherit only the children of the DW_AT_abstract_origin DIE not being
5827 already referenced by DW_AT_abstract_origin from the children of the
5831 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5833 struct die_info
*child_die
;
5834 unsigned die_children_count
;
5835 /* CU offsets which were referenced by children of the current DIE. */
5837 unsigned *offsets_end
, *offsetp
;
5838 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5839 struct die_info
*origin_die
;
5840 /* Iterator of the ORIGIN_DIE children. */
5841 struct die_info
*origin_child_die
;
5842 struct cleanup
*cleanups
;
5843 struct attribute
*attr
;
5844 struct dwarf2_cu
*origin_cu
;
5845 struct pending
**origin_previous_list_in_scope
;
5847 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5851 /* Note that following die references may follow to a die in a
5855 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5857 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5859 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5860 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5862 if (die
->tag
!= origin_die
->tag
5863 && !(die
->tag
== DW_TAG_inlined_subroutine
5864 && origin_die
->tag
== DW_TAG_subprogram
))
5865 complaint (&symfile_complaints
,
5866 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5867 die
->offset
, origin_die
->offset
);
5869 child_die
= die
->child
;
5870 die_children_count
= 0;
5871 while (child_die
&& child_die
->tag
)
5873 child_die
= sibling_die (child_die
);
5874 die_children_count
++;
5876 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5877 cleanups
= make_cleanup (xfree
, offsets
);
5879 offsets_end
= offsets
;
5880 child_die
= die
->child
;
5881 while (child_die
&& child_die
->tag
)
5883 /* For each CHILD_DIE, find the corresponding child of
5884 ORIGIN_DIE. If there is more than one layer of
5885 DW_AT_abstract_origin, follow them all; there shouldn't be,
5886 but GCC versions at least through 4.4 generate this (GCC PR
5888 struct die_info
*child_origin_die
= child_die
;
5889 struct dwarf2_cu
*child_origin_cu
= cu
;
5893 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5897 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5901 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5902 counterpart may exist. */
5903 if (child_origin_die
!= child_die
)
5905 if (child_die
->tag
!= child_origin_die
->tag
5906 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5907 && child_origin_die
->tag
== DW_TAG_subprogram
))
5908 complaint (&symfile_complaints
,
5909 _("Child DIE 0x%x and its abstract origin 0x%x have "
5910 "different tags"), child_die
->offset
,
5911 child_origin_die
->offset
);
5912 if (child_origin_die
->parent
!= origin_die
)
5913 complaint (&symfile_complaints
,
5914 _("Child DIE 0x%x and its abstract origin 0x%x have "
5915 "different parents"), child_die
->offset
,
5916 child_origin_die
->offset
);
5918 *offsets_end
++ = child_origin_die
->offset
;
5920 child_die
= sibling_die (child_die
);
5922 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5923 unsigned_int_compar
);
5924 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5925 if (offsetp
[-1] == *offsetp
)
5926 complaint (&symfile_complaints
,
5927 _("Multiple children of DIE 0x%x refer "
5928 "to DIE 0x%x as their abstract origin"),
5929 die
->offset
, *offsetp
);
5932 origin_child_die
= origin_die
->child
;
5933 while (origin_child_die
&& origin_child_die
->tag
)
5935 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5936 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5938 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5940 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5941 process_die (origin_child_die
, origin_cu
);
5943 origin_child_die
= sibling_die (origin_child_die
);
5945 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5947 do_cleanups (cleanups
);
5951 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5953 struct objfile
*objfile
= cu
->objfile
;
5954 struct context_stack
*new;
5957 struct die_info
*child_die
;
5958 struct attribute
*attr
, *call_line
, *call_file
;
5961 struct block
*block
;
5962 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5963 VEC (symbolp
) *template_args
= NULL
;
5964 struct template_symbol
*templ_func
= NULL
;
5968 /* If we do not have call site information, we can't show the
5969 caller of this inlined function. That's too confusing, so
5970 only use the scope for local variables. */
5971 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5972 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5973 if (call_line
== NULL
|| call_file
== NULL
)
5975 read_lexical_block_scope (die
, cu
);
5980 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5982 name
= dwarf2_name (die
, cu
);
5984 /* Ignore functions with missing or empty names. These are actually
5985 illegal according to the DWARF standard. */
5988 complaint (&symfile_complaints
,
5989 _("missing name for subprogram DIE at %d"), die
->offset
);
5993 /* Ignore functions with missing or invalid low and high pc attributes. */
5994 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5996 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5997 if (!attr
|| !DW_UNSND (attr
))
5998 complaint (&symfile_complaints
,
5999 _("cannot get low and high bounds "
6000 "for subprogram DIE at %d"),
6008 /* If we have any template arguments, then we must allocate a
6009 different sort of symbol. */
6010 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
6012 if (child_die
->tag
== DW_TAG_template_type_param
6013 || child_die
->tag
== DW_TAG_template_value_param
)
6015 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6016 struct template_symbol
);
6017 templ_func
->base
.is_cplus_template_function
= 1;
6022 new = push_context (0, lowpc
);
6023 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
6024 (struct symbol
*) templ_func
);
6026 /* If there is a location expression for DW_AT_frame_base, record
6028 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
6030 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
6031 expression is being recorded directly in the function's symbol
6032 and not in a separate frame-base object. I guess this hack is
6033 to avoid adding some sort of frame-base adjunct/annex to the
6034 function's symbol :-(. The problem with doing this is that it
6035 results in a function symbol with a location expression that
6036 has nothing to do with the location of the function, ouch! The
6037 relationship should be: a function's symbol has-a frame base; a
6038 frame-base has-a location expression. */
6039 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
6041 cu
->list_in_scope
= &local_symbols
;
6043 if (die
->child
!= NULL
)
6045 child_die
= die
->child
;
6046 while (child_die
&& child_die
->tag
)
6048 if (child_die
->tag
== DW_TAG_template_type_param
6049 || child_die
->tag
== DW_TAG_template_value_param
)
6051 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6054 VEC_safe_push (symbolp
, template_args
, arg
);
6057 process_die (child_die
, cu
);
6058 child_die
= sibling_die (child_die
);
6062 inherit_abstract_dies (die
, cu
);
6064 /* If we have a DW_AT_specification, we might need to import using
6065 directives from the context of the specification DIE. See the
6066 comment in determine_prefix. */
6067 if (cu
->language
== language_cplus
6068 && dwarf2_attr (die
, DW_AT_specification
, cu
))
6070 struct dwarf2_cu
*spec_cu
= cu
;
6071 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
6075 child_die
= spec_die
->child
;
6076 while (child_die
&& child_die
->tag
)
6078 if (child_die
->tag
== DW_TAG_imported_module
)
6079 process_die (child_die
, spec_cu
);
6080 child_die
= sibling_die (child_die
);
6083 /* In some cases, GCC generates specification DIEs that
6084 themselves contain DW_AT_specification attributes. */
6085 spec_die
= die_specification (spec_die
, &spec_cu
);
6089 new = pop_context ();
6090 /* Make a block for the local symbols within. */
6091 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
6092 lowpc
, highpc
, objfile
);
6094 /* For C++, set the block's scope. */
6095 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
6096 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
6097 determine_prefix (die
, cu
),
6098 processing_has_namespace_info
);
6100 /* If we have address ranges, record them. */
6101 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6103 /* Attach template arguments to function. */
6104 if (! VEC_empty (symbolp
, template_args
))
6106 gdb_assert (templ_func
!= NULL
);
6108 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
6109 templ_func
->template_arguments
6110 = obstack_alloc (&objfile
->objfile_obstack
,
6111 (templ_func
->n_template_arguments
6112 * sizeof (struct symbol
*)));
6113 memcpy (templ_func
->template_arguments
,
6114 VEC_address (symbolp
, template_args
),
6115 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
6116 VEC_free (symbolp
, template_args
);
6119 /* In C++, we can have functions nested inside functions (e.g., when
6120 a function declares a class that has methods). This means that
6121 when we finish processing a function scope, we may need to go
6122 back to building a containing block's symbol lists. */
6123 local_symbols
= new->locals
;
6124 param_symbols
= new->params
;
6125 using_directives
= new->using_directives
;
6127 /* If we've finished processing a top-level function, subsequent
6128 symbols go in the file symbol list. */
6129 if (outermost_context_p ())
6130 cu
->list_in_scope
= &file_symbols
;
6133 /* Process all the DIES contained within a lexical block scope. Start
6134 a new scope, process the dies, and then close the scope. */
6137 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6139 struct objfile
*objfile
= cu
->objfile
;
6140 struct context_stack
*new;
6141 CORE_ADDR lowpc
, highpc
;
6142 struct die_info
*child_die
;
6145 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6147 /* Ignore blocks with missing or invalid low and high pc attributes. */
6148 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6149 as multiple lexical blocks? Handling children in a sane way would
6150 be nasty. Might be easier to properly extend generic blocks to
6152 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6157 push_context (0, lowpc
);
6158 if (die
->child
!= NULL
)
6160 child_die
= die
->child
;
6161 while (child_die
&& child_die
->tag
)
6163 process_die (child_die
, cu
);
6164 child_die
= sibling_die (child_die
);
6167 new = pop_context ();
6169 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6172 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6175 /* Note that recording ranges after traversing children, as we
6176 do here, means that recording a parent's ranges entails
6177 walking across all its children's ranges as they appear in
6178 the address map, which is quadratic behavior.
6180 It would be nicer to record the parent's ranges before
6181 traversing its children, simply overriding whatever you find
6182 there. But since we don't even decide whether to create a
6183 block until after we've traversed its children, that's hard
6185 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6187 local_symbols
= new->locals
;
6188 using_directives
= new->using_directives
;
6191 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6194 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6196 struct objfile
*objfile
= cu
->objfile
;
6197 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6198 CORE_ADDR pc
, baseaddr
;
6199 struct attribute
*attr
;
6200 struct call_site
*call_site
, call_site_local
;
6203 struct die_info
*child_die
;
6205 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6207 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6210 complaint (&symfile_complaints
,
6211 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6212 "DIE 0x%x [in module %s]"),
6213 die
->offset
, objfile
->name
);
6216 pc
= DW_ADDR (attr
) + baseaddr
;
6218 if (cu
->call_site_htab
== NULL
)
6219 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
6220 NULL
, &objfile
->objfile_obstack
,
6221 hashtab_obstack_allocate
, NULL
);
6222 call_site_local
.pc
= pc
;
6223 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
6226 complaint (&symfile_complaints
,
6227 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6228 "DIE 0x%x [in module %s]"),
6229 paddress (gdbarch
, pc
), die
->offset
, objfile
->name
);
6233 /* Count parameters at the caller. */
6236 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6237 child_die
= sibling_die (child_die
))
6239 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6241 complaint (&symfile_complaints
,
6242 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6243 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6244 child_die
->tag
, child_die
->offset
, objfile
->name
);
6251 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
6252 (sizeof (*call_site
)
6253 + (sizeof (*call_site
->parameter
)
6256 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
6259 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
6261 struct die_info
*func_die
;
6263 /* Skip also over DW_TAG_inlined_subroutine. */
6264 for (func_die
= die
->parent
;
6265 func_die
&& func_die
->tag
!= DW_TAG_subprogram
6266 && func_die
->tag
!= DW_TAG_subroutine_type
;
6267 func_die
= func_die
->parent
);
6269 /* DW_AT_GNU_all_call_sites is a superset
6270 of DW_AT_GNU_all_tail_call_sites. */
6272 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
6273 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
6275 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6276 not complete. But keep CALL_SITE for look ups via call_site_htab,
6277 both the initial caller containing the real return address PC and
6278 the final callee containing the current PC of a chain of tail
6279 calls do not need to have the tail call list complete. But any
6280 function candidate for a virtual tail call frame searched via
6281 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6282 determined unambiguously. */
6286 struct type
*func_type
= NULL
;
6289 func_type
= get_die_type (func_die
, cu
);
6290 if (func_type
!= NULL
)
6292 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
6294 /* Enlist this call site to the function. */
6295 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
6296 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
6299 complaint (&symfile_complaints
,
6300 _("Cannot find function owning DW_TAG_GNU_call_site "
6301 "DIE 0x%x [in module %s]"),
6302 die
->offset
, objfile
->name
);
6306 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
6308 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
6309 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
6310 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
6311 /* Keep NULL DWARF_BLOCK. */;
6312 else if (attr_form_is_block (attr
))
6314 struct dwarf2_locexpr_baton
*dlbaton
;
6316 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
6317 dlbaton
->data
= DW_BLOCK (attr
)->data
;
6318 dlbaton
->size
= DW_BLOCK (attr
)->size
;
6319 dlbaton
->per_cu
= cu
->per_cu
;
6321 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
6323 else if (is_ref_attr (attr
))
6325 struct dwarf2_cu
*target_cu
= cu
;
6326 struct die_info
*target_die
;
6328 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
6329 gdb_assert (target_cu
->objfile
== objfile
);
6330 if (die_is_declaration (target_die
, target_cu
))
6332 const char *target_physname
;
6334 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
6335 if (target_physname
== NULL
)
6336 complaint (&symfile_complaints
,
6337 _("DW_AT_GNU_call_site_target target DIE has invalid "
6338 "physname, for referencing DIE 0x%x [in module %s]"),
6339 die
->offset
, objfile
->name
);
6341 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
6347 /* DW_AT_entry_pc should be preferred. */
6348 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
6349 complaint (&symfile_complaints
,
6350 _("DW_AT_GNU_call_site_target target DIE has invalid "
6351 "low pc, for referencing DIE 0x%x [in module %s]"),
6352 die
->offset
, objfile
->name
);
6354 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
6358 complaint (&symfile_complaints
,
6359 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6360 "block nor reference, for DIE 0x%x [in module %s]"),
6361 die
->offset
, objfile
->name
);
6363 call_site
->per_cu
= cu
->per_cu
;
6365 for (child_die
= die
->child
;
6366 child_die
&& child_die
->tag
;
6367 child_die
= sibling_die (child_die
))
6369 struct dwarf2_locexpr_baton
*dlbaton
;
6370 struct call_site_parameter
*parameter
;
6372 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6374 /* Already printed the complaint above. */
6378 gdb_assert (call_site
->parameter_count
< nparams
);
6379 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
6381 /* DW_AT_location specifies the register number. Value of the data
6382 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6384 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
6385 if (!attr
|| !attr_form_is_block (attr
))
6387 complaint (&symfile_complaints
,
6388 _("No DW_FORM_block* DW_AT_location for "
6389 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6390 child_die
->offset
, objfile
->name
);
6393 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
6394 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
6395 if (parameter
->dwarf_reg
== -1
6396 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
6397 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
6398 ¶meter
->fb_offset
))
6400 complaint (&symfile_complaints
,
6401 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6402 "for DW_FORM_block* DW_AT_location for "
6403 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6404 child_die
->offset
, objfile
->name
);
6408 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
6409 if (!attr_form_is_block (attr
))
6411 complaint (&symfile_complaints
,
6412 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6413 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6414 child_die
->offset
, objfile
->name
);
6417 parameter
->value
= DW_BLOCK (attr
)->data
;
6418 parameter
->value_size
= DW_BLOCK (attr
)->size
;
6420 /* Parameters are not pre-cleared by memset above. */
6421 parameter
->data_value
= NULL
;
6422 parameter
->data_value_size
= 0;
6423 call_site
->parameter_count
++;
6425 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
6428 if (!attr_form_is_block (attr
))
6429 complaint (&symfile_complaints
,
6430 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6431 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6432 child_die
->offset
, objfile
->name
);
6435 parameter
->data_value
= DW_BLOCK (attr
)->data
;
6436 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
6442 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6443 Return 1 if the attributes are present and valid, otherwise, return 0.
6444 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6447 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6448 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6449 struct partial_symtab
*ranges_pst
)
6451 struct objfile
*objfile
= cu
->objfile
;
6452 struct comp_unit_head
*cu_header
= &cu
->header
;
6453 bfd
*obfd
= objfile
->obfd
;
6454 unsigned int addr_size
= cu_header
->addr_size
;
6455 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6456 /* Base address selection entry. */
6467 found_base
= cu
->base_known
;
6468 base
= cu
->base_address
;
6470 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6471 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6473 complaint (&symfile_complaints
,
6474 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6478 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6480 /* Read in the largest possible address. */
6481 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6482 if ((marker
& mask
) == mask
)
6484 /* If we found the largest possible address, then
6485 read the base address. */
6486 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6487 buffer
+= 2 * addr_size
;
6488 offset
+= 2 * addr_size
;
6494 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6498 CORE_ADDR range_beginning
, range_end
;
6500 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6501 buffer
+= addr_size
;
6502 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6503 buffer
+= addr_size
;
6504 offset
+= 2 * addr_size
;
6506 /* An end of list marker is a pair of zero addresses. */
6507 if (range_beginning
== 0 && range_end
== 0)
6508 /* Found the end of list entry. */
6511 /* Each base address selection entry is a pair of 2 values.
6512 The first is the largest possible address, the second is
6513 the base address. Check for a base address here. */
6514 if ((range_beginning
& mask
) == mask
)
6516 /* If we found the largest possible address, then
6517 read the base address. */
6518 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6525 /* We have no valid base address for the ranges
6527 complaint (&symfile_complaints
,
6528 _("Invalid .debug_ranges data (no base address)"));
6532 if (range_beginning
> range_end
)
6534 /* Inverted range entries are invalid. */
6535 complaint (&symfile_complaints
,
6536 _("Invalid .debug_ranges data (inverted range)"));
6540 /* Empty range entries have no effect. */
6541 if (range_beginning
== range_end
)
6544 range_beginning
+= base
;
6547 if (ranges_pst
!= NULL
)
6548 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6549 range_beginning
+ baseaddr
,
6550 range_end
- 1 + baseaddr
,
6553 /* FIXME: This is recording everything as a low-high
6554 segment of consecutive addresses. We should have a
6555 data structure for discontiguous block ranges
6559 low
= range_beginning
;
6565 if (range_beginning
< low
)
6566 low
= range_beginning
;
6567 if (range_end
> high
)
6573 /* If the first entry is an end-of-list marker, the range
6574 describes an empty scope, i.e. no instructions. */
6580 *high_return
= high
;
6584 /* Get low and high pc attributes from a die. Return 1 if the attributes
6585 are present and valid, otherwise, return 0. Return -1 if the range is
6586 discontinuous, i.e. derived from DW_AT_ranges information. */
6588 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6589 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6590 struct partial_symtab
*pst
)
6592 struct attribute
*attr
;
6597 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6600 high
= DW_ADDR (attr
);
6601 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6603 low
= DW_ADDR (attr
);
6605 /* Found high w/o low attribute. */
6608 /* Found consecutive range of addresses. */
6613 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6616 /* Value of the DW_AT_ranges attribute is the offset in the
6617 .debug_ranges section. */
6618 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6620 /* Found discontinuous range of addresses. */
6625 /* read_partial_die has also the strict LOW < HIGH requirement. */
6629 /* When using the GNU linker, .gnu.linkonce. sections are used to
6630 eliminate duplicate copies of functions and vtables and such.
6631 The linker will arbitrarily choose one and discard the others.
6632 The AT_*_pc values for such functions refer to local labels in
6633 these sections. If the section from that file was discarded, the
6634 labels are not in the output, so the relocs get a value of 0.
6635 If this is a discarded function, mark the pc bounds as invalid,
6636 so that GDB will ignore it. */
6637 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6646 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6647 its low and high PC addresses. Do nothing if these addresses could not
6648 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6649 and HIGHPC to the high address if greater than HIGHPC. */
6652 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6653 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6654 struct dwarf2_cu
*cu
)
6656 CORE_ADDR low
, high
;
6657 struct die_info
*child
= die
->child
;
6659 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6661 *lowpc
= min (*lowpc
, low
);
6662 *highpc
= max (*highpc
, high
);
6665 /* If the language does not allow nested subprograms (either inside
6666 subprograms or lexical blocks), we're done. */
6667 if (cu
->language
!= language_ada
)
6670 /* Check all the children of the given DIE. If it contains nested
6671 subprograms, then check their pc bounds. Likewise, we need to
6672 check lexical blocks as well, as they may also contain subprogram
6674 while (child
&& child
->tag
)
6676 if (child
->tag
== DW_TAG_subprogram
6677 || child
->tag
== DW_TAG_lexical_block
)
6678 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6679 child
= sibling_die (child
);
6683 /* Get the low and high pc's represented by the scope DIE, and store
6684 them in *LOWPC and *HIGHPC. If the correct values can't be
6685 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6688 get_scope_pc_bounds (struct die_info
*die
,
6689 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6690 struct dwarf2_cu
*cu
)
6692 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6693 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6694 CORE_ADDR current_low
, current_high
;
6696 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6698 best_low
= current_low
;
6699 best_high
= current_high
;
6703 struct die_info
*child
= die
->child
;
6705 while (child
&& child
->tag
)
6707 switch (child
->tag
) {
6708 case DW_TAG_subprogram
:
6709 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6711 case DW_TAG_namespace
:
6713 /* FIXME: carlton/2004-01-16: Should we do this for
6714 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6715 that current GCC's always emit the DIEs corresponding
6716 to definitions of methods of classes as children of a
6717 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6718 the DIEs giving the declarations, which could be
6719 anywhere). But I don't see any reason why the
6720 standards says that they have to be there. */
6721 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6723 if (current_low
!= ((CORE_ADDR
) -1))
6725 best_low
= min (best_low
, current_low
);
6726 best_high
= max (best_high
, current_high
);
6734 child
= sibling_die (child
);
6739 *highpc
= best_high
;
6742 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6745 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6746 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6748 struct objfile
*objfile
= cu
->objfile
;
6749 struct attribute
*attr
;
6751 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6754 CORE_ADDR high
= DW_ADDR (attr
);
6756 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6759 CORE_ADDR low
= DW_ADDR (attr
);
6761 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6765 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6768 bfd
*obfd
= objfile
->obfd
;
6770 /* The value of the DW_AT_ranges attribute is the offset of the
6771 address range list in the .debug_ranges section. */
6772 unsigned long offset
= DW_UNSND (attr
);
6773 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6775 /* For some target architectures, but not others, the
6776 read_address function sign-extends the addresses it returns.
6777 To recognize base address selection entries, we need a
6779 unsigned int addr_size
= cu
->header
.addr_size
;
6780 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6782 /* The base address, to which the next pair is relative. Note
6783 that this 'base' is a DWARF concept: most entries in a range
6784 list are relative, to reduce the number of relocs against the
6785 debugging information. This is separate from this function's
6786 'baseaddr' argument, which GDB uses to relocate debugging
6787 information from a shared library based on the address at
6788 which the library was loaded. */
6789 CORE_ADDR base
= cu
->base_address
;
6790 int base_known
= cu
->base_known
;
6792 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6793 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6795 complaint (&symfile_complaints
,
6796 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6803 unsigned int bytes_read
;
6804 CORE_ADDR start
, end
;
6806 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6807 buffer
+= bytes_read
;
6808 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6809 buffer
+= bytes_read
;
6811 /* Did we find the end of the range list? */
6812 if (start
== 0 && end
== 0)
6815 /* Did we find a base address selection entry? */
6816 else if ((start
& base_select_mask
) == base_select_mask
)
6822 /* We found an ordinary address range. */
6827 complaint (&symfile_complaints
,
6828 _("Invalid .debug_ranges data "
6829 "(no base address)"));
6835 /* Inverted range entries are invalid. */
6836 complaint (&symfile_complaints
,
6837 _("Invalid .debug_ranges data "
6838 "(inverted range)"));
6842 /* Empty range entries have no effect. */
6846 record_block_range (block
,
6847 baseaddr
+ base
+ start
,
6848 baseaddr
+ base
+ end
- 1);
6854 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6855 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6856 during 4.6.0 experimental. */
6859 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6862 int major
, minor
, release
;
6864 if (cu
->producer
== NULL
)
6866 /* For unknown compilers expect their behavior is DWARF version
6869 GCC started to support .debug_types sections by -gdwarf-4 since
6870 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6871 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6872 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6873 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6878 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6880 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6882 /* For non-GCC compilers expect their behavior is DWARF version
6887 cs
= &cu
->producer
[strlen ("GNU ")];
6888 while (*cs
&& !isdigit (*cs
))
6890 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6892 /* Not recognized as GCC. */
6897 return major
< 4 || (major
== 4 && minor
< 6);
6900 /* Return the default accessibility type if it is not overriden by
6901 DW_AT_accessibility. */
6903 static enum dwarf_access_attribute
6904 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6906 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6908 /* The default DWARF 2 accessibility for members is public, the default
6909 accessibility for inheritance is private. */
6911 if (die
->tag
!= DW_TAG_inheritance
)
6912 return DW_ACCESS_public
;
6914 return DW_ACCESS_private
;
6918 /* DWARF 3+ defines the default accessibility a different way. The same
6919 rules apply now for DW_TAG_inheritance as for the members and it only
6920 depends on the container kind. */
6922 if (die
->parent
->tag
== DW_TAG_class_type
)
6923 return DW_ACCESS_private
;
6925 return DW_ACCESS_public
;
6929 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6930 offset. If the attribute was not found return 0, otherwise return
6931 1. If it was found but could not properly be handled, set *OFFSET
6935 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
6938 struct attribute
*attr
;
6940 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6945 /* Note that we do not check for a section offset first here.
6946 This is because DW_AT_data_member_location is new in DWARF 4,
6947 so if we see it, we can assume that a constant form is really
6948 a constant and not a section offset. */
6949 if (attr_form_is_constant (attr
))
6950 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
6951 else if (attr_form_is_section_offset (attr
))
6952 dwarf2_complex_location_expr_complaint ();
6953 else if (attr_form_is_block (attr
))
6954 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6956 dwarf2_complex_location_expr_complaint ();
6964 /* Add an aggregate field to the field list. */
6967 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6968 struct dwarf2_cu
*cu
)
6970 struct objfile
*objfile
= cu
->objfile
;
6971 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6972 struct nextfield
*new_field
;
6973 struct attribute
*attr
;
6975 char *fieldname
= "";
6977 /* Allocate a new field list entry and link it in. */
6978 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6979 make_cleanup (xfree
, new_field
);
6980 memset (new_field
, 0, sizeof (struct nextfield
));
6982 if (die
->tag
== DW_TAG_inheritance
)
6984 new_field
->next
= fip
->baseclasses
;
6985 fip
->baseclasses
= new_field
;
6989 new_field
->next
= fip
->fields
;
6990 fip
->fields
= new_field
;
6994 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6996 new_field
->accessibility
= DW_UNSND (attr
);
6998 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
6999 if (new_field
->accessibility
!= DW_ACCESS_public
)
7000 fip
->non_public_fields
= 1;
7002 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7004 new_field
->virtuality
= DW_UNSND (attr
);
7006 new_field
->virtuality
= DW_VIRTUALITY_none
;
7008 fp
= &new_field
->field
;
7010 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
7014 /* Data member other than a C++ static data member. */
7016 /* Get type of field. */
7017 fp
->type
= die_type (die
, cu
);
7019 SET_FIELD_BITPOS (*fp
, 0);
7021 /* Get bit size of field (zero if none). */
7022 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
7025 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
7029 FIELD_BITSIZE (*fp
) = 0;
7032 /* Get bit offset of field. */
7033 if (handle_data_member_location (die
, cu
, &offset
))
7034 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7035 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
7038 if (gdbarch_bits_big_endian (gdbarch
))
7040 /* For big endian bits, the DW_AT_bit_offset gives the
7041 additional bit offset from the MSB of the containing
7042 anonymous object to the MSB of the field. We don't
7043 have to do anything special since we don't need to
7044 know the size of the anonymous object. */
7045 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
7049 /* For little endian bits, compute the bit offset to the
7050 MSB of the anonymous object, subtract off the number of
7051 bits from the MSB of the field to the MSB of the
7052 object, and then subtract off the number of bits of
7053 the field itself. The result is the bit offset of
7054 the LSB of the field. */
7056 int bit_offset
= DW_UNSND (attr
);
7058 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7061 /* The size of the anonymous object containing
7062 the bit field is explicit, so use the
7063 indicated size (in bytes). */
7064 anonymous_size
= DW_UNSND (attr
);
7068 /* The size of the anonymous object containing
7069 the bit field must be inferred from the type
7070 attribute of the data member containing the
7072 anonymous_size
= TYPE_LENGTH (fp
->type
);
7074 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
7075 - bit_offset
- FIELD_BITSIZE (*fp
);
7079 /* Get name of field. */
7080 fieldname
= dwarf2_name (die
, cu
);
7081 if (fieldname
== NULL
)
7084 /* The name is already allocated along with this objfile, so we don't
7085 need to duplicate it for the type. */
7086 fp
->name
= fieldname
;
7088 /* Change accessibility for artificial fields (e.g. virtual table
7089 pointer or virtual base class pointer) to private. */
7090 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
7092 FIELD_ARTIFICIAL (*fp
) = 1;
7093 new_field
->accessibility
= DW_ACCESS_private
;
7094 fip
->non_public_fields
= 1;
7097 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
7099 /* C++ static member. */
7101 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7102 is a declaration, but all versions of G++ as of this writing
7103 (so through at least 3.2.1) incorrectly generate
7104 DW_TAG_variable tags. */
7106 const char *physname
;
7108 /* Get name of field. */
7109 fieldname
= dwarf2_name (die
, cu
);
7110 if (fieldname
== NULL
)
7113 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7115 /* Only create a symbol if this is an external value.
7116 new_symbol checks this and puts the value in the global symbol
7117 table, which we want. If it is not external, new_symbol
7118 will try to put the value in cu->list_in_scope which is wrong. */
7119 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
7121 /* A static const member, not much different than an enum as far as
7122 we're concerned, except that we can support more types. */
7123 new_symbol (die
, NULL
, cu
);
7126 /* Get physical name. */
7127 physname
= dwarf2_physname (fieldname
, die
, cu
);
7129 /* The name is already allocated along with this objfile, so we don't
7130 need to duplicate it for the type. */
7131 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
7132 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7133 FIELD_NAME (*fp
) = fieldname
;
7135 else if (die
->tag
== DW_TAG_inheritance
)
7139 /* C++ base class field. */
7140 if (handle_data_member_location (die
, cu
, &offset
))
7141 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7142 FIELD_BITSIZE (*fp
) = 0;
7143 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7144 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
7145 fip
->nbaseclasses
++;
7149 /* Add a typedef defined in the scope of the FIP's class. */
7152 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
7153 struct dwarf2_cu
*cu
)
7155 struct objfile
*objfile
= cu
->objfile
;
7156 struct typedef_field_list
*new_field
;
7157 struct attribute
*attr
;
7158 struct typedef_field
*fp
;
7159 char *fieldname
= "";
7161 /* Allocate a new field list entry and link it in. */
7162 new_field
= xzalloc (sizeof (*new_field
));
7163 make_cleanup (xfree
, new_field
);
7165 gdb_assert (die
->tag
== DW_TAG_typedef
);
7167 fp
= &new_field
->field
;
7169 /* Get name of field. */
7170 fp
->name
= dwarf2_name (die
, cu
);
7171 if (fp
->name
== NULL
)
7174 fp
->type
= read_type_die (die
, cu
);
7176 new_field
->next
= fip
->typedef_field_list
;
7177 fip
->typedef_field_list
= new_field
;
7178 fip
->typedef_field_list_count
++;
7181 /* Create the vector of fields, and attach it to the type. */
7184 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
7185 struct dwarf2_cu
*cu
)
7187 int nfields
= fip
->nfields
;
7189 /* Record the field count, allocate space for the array of fields,
7190 and create blank accessibility bitfields if necessary. */
7191 TYPE_NFIELDS (type
) = nfields
;
7192 TYPE_FIELDS (type
) = (struct field
*)
7193 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
7194 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
7196 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
7198 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7200 TYPE_FIELD_PRIVATE_BITS (type
) =
7201 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7202 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
7204 TYPE_FIELD_PROTECTED_BITS (type
) =
7205 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7206 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
7208 TYPE_FIELD_IGNORE_BITS (type
) =
7209 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7210 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
7213 /* If the type has baseclasses, allocate and clear a bit vector for
7214 TYPE_FIELD_VIRTUAL_BITS. */
7215 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
7217 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
7218 unsigned char *pointer
;
7220 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7221 pointer
= TYPE_ALLOC (type
, num_bytes
);
7222 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
7223 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
7224 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
7227 /* Copy the saved-up fields into the field vector. Start from the head of
7228 the list, adding to the tail of the field array, so that they end up in
7229 the same order in the array in which they were added to the list. */
7230 while (nfields
-- > 0)
7232 struct nextfield
*fieldp
;
7236 fieldp
= fip
->fields
;
7237 fip
->fields
= fieldp
->next
;
7241 fieldp
= fip
->baseclasses
;
7242 fip
->baseclasses
= fieldp
->next
;
7245 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
7246 switch (fieldp
->accessibility
)
7248 case DW_ACCESS_private
:
7249 if (cu
->language
!= language_ada
)
7250 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
7253 case DW_ACCESS_protected
:
7254 if (cu
->language
!= language_ada
)
7255 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
7258 case DW_ACCESS_public
:
7262 /* Unknown accessibility. Complain and treat it as public. */
7264 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
7265 fieldp
->accessibility
);
7269 if (nfields
< fip
->nbaseclasses
)
7271 switch (fieldp
->virtuality
)
7273 case DW_VIRTUALITY_virtual
:
7274 case DW_VIRTUALITY_pure_virtual
:
7275 if (cu
->language
== language_ada
)
7276 error (_("unexpected virtuality in component of Ada type"));
7277 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
7284 /* Add a member function to the proper fieldlist. */
7287 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
7288 struct type
*type
, struct dwarf2_cu
*cu
)
7290 struct objfile
*objfile
= cu
->objfile
;
7291 struct attribute
*attr
;
7292 struct fnfieldlist
*flp
;
7294 struct fn_field
*fnp
;
7296 struct nextfnfield
*new_fnfield
;
7297 struct type
*this_type
;
7298 enum dwarf_access_attribute accessibility
;
7300 if (cu
->language
== language_ada
)
7301 error (_("unexpected member function in Ada type"));
7303 /* Get name of member function. */
7304 fieldname
= dwarf2_name (die
, cu
);
7305 if (fieldname
== NULL
)
7308 /* Look up member function name in fieldlist. */
7309 for (i
= 0; i
< fip
->nfnfields
; i
++)
7311 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7315 /* Create new list element if necessary. */
7316 if (i
< fip
->nfnfields
)
7317 flp
= &fip
->fnfieldlists
[i
];
7320 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7322 fip
->fnfieldlists
= (struct fnfieldlist
*)
7323 xrealloc (fip
->fnfieldlists
,
7324 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7325 * sizeof (struct fnfieldlist
));
7326 if (fip
->nfnfields
== 0)
7327 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7329 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7330 flp
->name
= fieldname
;
7333 i
= fip
->nfnfields
++;
7336 /* Create a new member function field and chain it to the field list
7338 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7339 make_cleanup (xfree
, new_fnfield
);
7340 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7341 new_fnfield
->next
= flp
->head
;
7342 flp
->head
= new_fnfield
;
7345 /* Fill in the member function field info. */
7346 fnp
= &new_fnfield
->fnfield
;
7348 /* Delay processing of the physname until later. */
7349 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7351 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7356 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7357 fnp
->physname
= physname
? physname
: "";
7360 fnp
->type
= alloc_type (objfile
);
7361 this_type
= read_type_die (die
, cu
);
7362 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7364 int nparams
= TYPE_NFIELDS (this_type
);
7366 /* TYPE is the domain of this method, and THIS_TYPE is the type
7367 of the method itself (TYPE_CODE_METHOD). */
7368 smash_to_method_type (fnp
->type
, type
,
7369 TYPE_TARGET_TYPE (this_type
),
7370 TYPE_FIELDS (this_type
),
7371 TYPE_NFIELDS (this_type
),
7372 TYPE_VARARGS (this_type
));
7374 /* Handle static member functions.
7375 Dwarf2 has no clean way to discern C++ static and non-static
7376 member functions. G++ helps GDB by marking the first
7377 parameter for non-static member functions (which is the this
7378 pointer) as artificial. We obtain this information from
7379 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7380 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7381 fnp
->voffset
= VOFFSET_STATIC
;
7384 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7385 dwarf2_full_name (fieldname
, die
, cu
));
7387 /* Get fcontext from DW_AT_containing_type if present. */
7388 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7389 fnp
->fcontext
= die_containing_type (die
, cu
);
7391 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7392 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7394 /* Get accessibility. */
7395 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7397 accessibility
= DW_UNSND (attr
);
7399 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7400 switch (accessibility
)
7402 case DW_ACCESS_private
:
7403 fnp
->is_private
= 1;
7405 case DW_ACCESS_protected
:
7406 fnp
->is_protected
= 1;
7410 /* Check for artificial methods. */
7411 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7412 if (attr
&& DW_UNSND (attr
) != 0)
7413 fnp
->is_artificial
= 1;
7415 /* Get index in virtual function table if it is a virtual member
7416 function. For older versions of GCC, this is an offset in the
7417 appropriate virtual table, as specified by DW_AT_containing_type.
7418 For everyone else, it is an expression to be evaluated relative
7419 to the object address. */
7421 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7424 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7426 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7428 /* Old-style GCC. */
7429 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7431 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7432 || (DW_BLOCK (attr
)->size
> 1
7433 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7434 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7436 struct dwarf_block blk
;
7439 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7441 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7442 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7443 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7444 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7445 dwarf2_complex_location_expr_complaint ();
7447 fnp
->voffset
/= cu
->header
.addr_size
;
7451 dwarf2_complex_location_expr_complaint ();
7454 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7456 else if (attr_form_is_section_offset (attr
))
7458 dwarf2_complex_location_expr_complaint ();
7462 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7468 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7469 if (attr
&& DW_UNSND (attr
))
7471 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7472 complaint (&symfile_complaints
,
7473 _("Member function \"%s\" (offset %d) is virtual "
7474 "but the vtable offset is not specified"),
7475 fieldname
, die
->offset
);
7476 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7477 TYPE_CPLUS_DYNAMIC (type
) = 1;
7482 /* Create the vector of member function fields, and attach it to the type. */
7485 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7486 struct dwarf2_cu
*cu
)
7488 struct fnfieldlist
*flp
;
7489 int total_length
= 0;
7492 if (cu
->language
== language_ada
)
7493 error (_("unexpected member functions in Ada type"));
7495 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7496 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7497 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7499 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7501 struct nextfnfield
*nfp
= flp
->head
;
7502 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7505 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7506 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7507 fn_flp
->fn_fields
= (struct fn_field
*)
7508 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7509 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7510 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7512 total_length
+= flp
->length
;
7515 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7516 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
7519 /* Returns non-zero if NAME is the name of a vtable member in CU's
7520 language, zero otherwise. */
7522 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7524 static const char vptr
[] = "_vptr";
7525 static const char vtable
[] = "vtable";
7527 /* Look for the C++ and Java forms of the vtable. */
7528 if ((cu
->language
== language_java
7529 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7530 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7531 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7537 /* GCC outputs unnamed structures that are really pointers to member
7538 functions, with the ABI-specified layout. If TYPE describes
7539 such a structure, smash it into a member function type.
7541 GCC shouldn't do this; it should just output pointer to member DIEs.
7542 This is GCC PR debug/28767. */
7545 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7547 struct type
*pfn_type
, *domain_type
, *new_type
;
7549 /* Check for a structure with no name and two children. */
7550 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7553 /* Check for __pfn and __delta members. */
7554 if (TYPE_FIELD_NAME (type
, 0) == NULL
7555 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7556 || TYPE_FIELD_NAME (type
, 1) == NULL
7557 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7560 /* Find the type of the method. */
7561 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7562 if (pfn_type
== NULL
7563 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7564 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7567 /* Look for the "this" argument. */
7568 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7569 if (TYPE_NFIELDS (pfn_type
) == 0
7570 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7571 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7574 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7575 new_type
= alloc_type (objfile
);
7576 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7577 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7578 TYPE_VARARGS (pfn_type
));
7579 smash_to_methodptr_type (type
, new_type
);
7582 /* Called when we find the DIE that starts a structure or union scope
7583 (definition) to create a type for the structure or union. Fill in
7584 the type's name and general properties; the members will not be
7585 processed until process_structure_type.
7587 NOTE: we need to call these functions regardless of whether or not the
7588 DIE has a DW_AT_name attribute, since it might be an anonymous
7589 structure or union. This gets the type entered into our set of
7592 However, if the structure is incomplete (an opaque struct/union)
7593 then suppress creating a symbol table entry for it since gdb only
7594 wants to find the one with the complete definition. Note that if
7595 it is complete, we just call new_symbol, which does it's own
7596 checking about whether the struct/union is anonymous or not (and
7597 suppresses creating a symbol table entry itself). */
7599 static struct type
*
7600 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7602 struct objfile
*objfile
= cu
->objfile
;
7604 struct attribute
*attr
;
7607 /* If the definition of this type lives in .debug_types, read that type.
7608 Don't follow DW_AT_specification though, that will take us back up
7609 the chain and we want to go down. */
7610 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7613 struct dwarf2_cu
*type_cu
= cu
;
7614 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7616 /* We could just recurse on read_structure_type, but we need to call
7617 get_die_type to ensure only one type for this DIE is created.
7618 This is important, for example, because for c++ classes we need
7619 TYPE_NAME set which is only done by new_symbol. Blech. */
7620 type
= read_type_die (type_die
, type_cu
);
7622 /* TYPE_CU may not be the same as CU.
7623 Ensure TYPE is recorded in CU's type_hash table. */
7624 return set_die_type (die
, type
, cu
);
7627 type
= alloc_type (objfile
);
7628 INIT_CPLUS_SPECIFIC (type
);
7630 name
= dwarf2_name (die
, cu
);
7633 if (cu
->language
== language_cplus
7634 || cu
->language
== language_java
)
7636 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7638 /* dwarf2_full_name might have already finished building the DIE's
7639 type. If so, there is no need to continue. */
7640 if (get_die_type (die
, cu
) != NULL
)
7641 return get_die_type (die
, cu
);
7643 TYPE_TAG_NAME (type
) = full_name
;
7644 if (die
->tag
== DW_TAG_structure_type
7645 || die
->tag
== DW_TAG_class_type
)
7646 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7650 /* The name is already allocated along with this objfile, so
7651 we don't need to duplicate it for the type. */
7652 TYPE_TAG_NAME (type
) = (char *) name
;
7653 if (die
->tag
== DW_TAG_class_type
)
7654 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7658 if (die
->tag
== DW_TAG_structure_type
)
7660 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7662 else if (die
->tag
== DW_TAG_union_type
)
7664 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7668 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7671 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7672 TYPE_DECLARED_CLASS (type
) = 1;
7674 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7677 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7681 TYPE_LENGTH (type
) = 0;
7684 TYPE_STUB_SUPPORTED (type
) = 1;
7685 if (die_is_declaration (die
, cu
))
7686 TYPE_STUB (type
) = 1;
7687 else if (attr
== NULL
&& die
->child
== NULL
7688 && producer_is_realview (cu
->producer
))
7689 /* RealView does not output the required DW_AT_declaration
7690 on incomplete types. */
7691 TYPE_STUB (type
) = 1;
7693 /* We need to add the type field to the die immediately so we don't
7694 infinitely recurse when dealing with pointers to the structure
7695 type within the structure itself. */
7696 set_die_type (die
, type
, cu
);
7698 /* set_die_type should be already done. */
7699 set_descriptive_type (type
, die
, cu
);
7704 /* Finish creating a structure or union type, including filling in
7705 its members and creating a symbol for it. */
7708 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7710 struct objfile
*objfile
= cu
->objfile
;
7711 struct die_info
*child_die
= die
->child
;
7714 type
= get_die_type (die
, cu
);
7716 type
= read_structure_type (die
, cu
);
7718 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7720 struct field_info fi
;
7721 struct die_info
*child_die
;
7722 VEC (symbolp
) *template_args
= NULL
;
7723 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7725 memset (&fi
, 0, sizeof (struct field_info
));
7727 child_die
= die
->child
;
7729 while (child_die
&& child_die
->tag
)
7731 if (child_die
->tag
== DW_TAG_member
7732 || child_die
->tag
== DW_TAG_variable
)
7734 /* NOTE: carlton/2002-11-05: A C++ static data member
7735 should be a DW_TAG_member that is a declaration, but
7736 all versions of G++ as of this writing (so through at
7737 least 3.2.1) incorrectly generate DW_TAG_variable
7738 tags for them instead. */
7739 dwarf2_add_field (&fi
, child_die
, cu
);
7741 else if (child_die
->tag
== DW_TAG_subprogram
)
7743 /* C++ member function. */
7744 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7746 else if (child_die
->tag
== DW_TAG_inheritance
)
7748 /* C++ base class field. */
7749 dwarf2_add_field (&fi
, child_die
, cu
);
7751 else if (child_die
->tag
== DW_TAG_typedef
)
7752 dwarf2_add_typedef (&fi
, child_die
, cu
);
7753 else if (child_die
->tag
== DW_TAG_template_type_param
7754 || child_die
->tag
== DW_TAG_template_value_param
)
7756 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7759 VEC_safe_push (symbolp
, template_args
, arg
);
7762 child_die
= sibling_die (child_die
);
7765 /* Attach template arguments to type. */
7766 if (! VEC_empty (symbolp
, template_args
))
7768 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7769 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7770 = VEC_length (symbolp
, template_args
);
7771 TYPE_TEMPLATE_ARGUMENTS (type
)
7772 = obstack_alloc (&objfile
->objfile_obstack
,
7773 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7774 * sizeof (struct symbol
*)));
7775 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7776 VEC_address (symbolp
, template_args
),
7777 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7778 * sizeof (struct symbol
*)));
7779 VEC_free (symbolp
, template_args
);
7782 /* Attach fields and member functions to the type. */
7784 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7787 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7789 /* Get the type which refers to the base class (possibly this
7790 class itself) which contains the vtable pointer for the current
7791 class from the DW_AT_containing_type attribute. This use of
7792 DW_AT_containing_type is a GNU extension. */
7794 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7796 struct type
*t
= die_containing_type (die
, cu
);
7798 TYPE_VPTR_BASETYPE (type
) = t
;
7803 /* Our own class provides vtbl ptr. */
7804 for (i
= TYPE_NFIELDS (t
) - 1;
7805 i
>= TYPE_N_BASECLASSES (t
);
7808 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7810 if (is_vtable_name (fieldname
, cu
))
7812 TYPE_VPTR_FIELDNO (type
) = i
;
7817 /* Complain if virtual function table field not found. */
7818 if (i
< TYPE_N_BASECLASSES (t
))
7819 complaint (&symfile_complaints
,
7820 _("virtual function table pointer "
7821 "not found when defining class '%s'"),
7822 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7827 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7830 else if (cu
->producer
7831 && strncmp (cu
->producer
,
7832 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7834 /* The IBM XLC compiler does not provide direct indication
7835 of the containing type, but the vtable pointer is
7836 always named __vfp. */
7840 for (i
= TYPE_NFIELDS (type
) - 1;
7841 i
>= TYPE_N_BASECLASSES (type
);
7844 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7846 TYPE_VPTR_FIELDNO (type
) = i
;
7847 TYPE_VPTR_BASETYPE (type
) = type
;
7854 /* Copy fi.typedef_field_list linked list elements content into the
7855 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7856 if (fi
.typedef_field_list
)
7858 int i
= fi
.typedef_field_list_count
;
7860 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7861 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7862 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7863 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7865 /* Reverse the list order to keep the debug info elements order. */
7868 struct typedef_field
*dest
, *src
;
7870 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7871 src
= &fi
.typedef_field_list
->field
;
7872 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7877 do_cleanups (back_to
);
7879 if (HAVE_CPLUS_STRUCT (type
))
7880 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
7883 quirk_gcc_member_function_pointer (type
, objfile
);
7885 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7886 snapshots) has been known to create a die giving a declaration
7887 for a class that has, as a child, a die giving a definition for a
7888 nested class. So we have to process our children even if the
7889 current die is a declaration. Normally, of course, a declaration
7890 won't have any children at all. */
7892 while (child_die
!= NULL
&& child_die
->tag
)
7894 if (child_die
->tag
== DW_TAG_member
7895 || child_die
->tag
== DW_TAG_variable
7896 || child_die
->tag
== DW_TAG_inheritance
7897 || child_die
->tag
== DW_TAG_template_value_param
7898 || child_die
->tag
== DW_TAG_template_type_param
)
7903 process_die (child_die
, cu
);
7905 child_die
= sibling_die (child_die
);
7908 /* Do not consider external references. According to the DWARF standard,
7909 these DIEs are identified by the fact that they have no byte_size
7910 attribute, and a declaration attribute. */
7911 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7912 || !die_is_declaration (die
, cu
))
7913 new_symbol (die
, type
, cu
);
7916 /* Given a DW_AT_enumeration_type die, set its type. We do not
7917 complete the type's fields yet, or create any symbols. */
7919 static struct type
*
7920 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7922 struct objfile
*objfile
= cu
->objfile
;
7924 struct attribute
*attr
;
7927 /* If the definition of this type lives in .debug_types, read that type.
7928 Don't follow DW_AT_specification though, that will take us back up
7929 the chain and we want to go down. */
7930 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7933 struct dwarf2_cu
*type_cu
= cu
;
7934 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7936 type
= read_type_die (type_die
, type_cu
);
7938 /* TYPE_CU may not be the same as CU.
7939 Ensure TYPE is recorded in CU's type_hash table. */
7940 return set_die_type (die
, type
, cu
);
7943 type
= alloc_type (objfile
);
7945 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7946 name
= dwarf2_full_name (NULL
, die
, cu
);
7948 TYPE_TAG_NAME (type
) = (char *) name
;
7950 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7953 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7957 TYPE_LENGTH (type
) = 0;
7960 /* The enumeration DIE can be incomplete. In Ada, any type can be
7961 declared as private in the package spec, and then defined only
7962 inside the package body. Such types are known as Taft Amendment
7963 Types. When another package uses such a type, an incomplete DIE
7964 may be generated by the compiler. */
7965 if (die_is_declaration (die
, cu
))
7966 TYPE_STUB (type
) = 1;
7968 return set_die_type (die
, type
, cu
);
7971 /* Given a pointer to a die which begins an enumeration, process all
7972 the dies that define the members of the enumeration, and create the
7973 symbol for the enumeration type.
7975 NOTE: We reverse the order of the element list. */
7978 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7980 struct type
*this_type
;
7982 this_type
= get_die_type (die
, cu
);
7983 if (this_type
== NULL
)
7984 this_type
= read_enumeration_type (die
, cu
);
7986 if (die
->child
!= NULL
)
7988 struct die_info
*child_die
;
7990 struct field
*fields
= NULL
;
7992 int unsigned_enum
= 1;
7995 child_die
= die
->child
;
7996 while (child_die
&& child_die
->tag
)
7998 if (child_die
->tag
!= DW_TAG_enumerator
)
8000 process_die (child_die
, cu
);
8004 name
= dwarf2_name (child_die
, cu
);
8007 sym
= new_symbol (child_die
, this_type
, cu
);
8008 if (SYMBOL_VALUE (sym
) < 0)
8011 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8013 fields
= (struct field
*)
8015 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
8016 * sizeof (struct field
));
8019 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
8020 FIELD_TYPE (fields
[num_fields
]) = NULL
;
8021 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
8022 FIELD_BITSIZE (fields
[num_fields
]) = 0;
8028 child_die
= sibling_die (child_die
);
8033 TYPE_NFIELDS (this_type
) = num_fields
;
8034 TYPE_FIELDS (this_type
) = (struct field
*)
8035 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
8036 memcpy (TYPE_FIELDS (this_type
), fields
,
8037 sizeof (struct field
) * num_fields
);
8041 TYPE_UNSIGNED (this_type
) = 1;
8044 /* If we are reading an enum from a .debug_types unit, and the enum
8045 is a declaration, and the enum is not the signatured type in the
8046 unit, then we do not want to add a symbol for it. Adding a
8047 symbol would in some cases obscure the true definition of the
8048 enum, giving users an incomplete type when the definition is
8049 actually available. Note that we do not want to do this for all
8050 enums which are just declarations, because C++0x allows forward
8051 enum declarations. */
8052 if (cu
->per_cu
->debug_types_section
8053 && die_is_declaration (die
, cu
))
8055 struct signatured_type
*type_sig
;
8058 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
8059 cu
->per_cu
->debug_types_section
,
8060 cu
->per_cu
->offset
);
8061 if (type_sig
->type_offset
!= die
->offset
)
8065 new_symbol (die
, this_type
, cu
);
8068 /* Extract all information from a DW_TAG_array_type DIE and put it in
8069 the DIE's type field. For now, this only handles one dimensional
8072 static struct type
*
8073 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8075 struct objfile
*objfile
= cu
->objfile
;
8076 struct die_info
*child_die
;
8078 struct type
*element_type
, *range_type
, *index_type
;
8079 struct type
**range_types
= NULL
;
8080 struct attribute
*attr
;
8082 struct cleanup
*back_to
;
8085 element_type
= die_type (die
, cu
);
8087 /* The die_type call above may have already set the type for this DIE. */
8088 type
= get_die_type (die
, cu
);
8092 /* Irix 6.2 native cc creates array types without children for
8093 arrays with unspecified length. */
8094 if (die
->child
== NULL
)
8096 index_type
= objfile_type (objfile
)->builtin_int
;
8097 range_type
= create_range_type (NULL
, index_type
, 0, -1);
8098 type
= create_array_type (NULL
, element_type
, range_type
);
8099 return set_die_type (die
, type
, cu
);
8102 back_to
= make_cleanup (null_cleanup
, NULL
);
8103 child_die
= die
->child
;
8104 while (child_die
&& child_die
->tag
)
8106 if (child_die
->tag
== DW_TAG_subrange_type
)
8108 struct type
*child_type
= read_type_die (child_die
, cu
);
8110 if (child_type
!= NULL
)
8112 /* The range type was succesfully read. Save it for the
8113 array type creation. */
8114 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
8116 range_types
= (struct type
**)
8117 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
8118 * sizeof (struct type
*));
8120 make_cleanup (free_current_contents
, &range_types
);
8122 range_types
[ndim
++] = child_type
;
8125 child_die
= sibling_die (child_die
);
8128 /* Dwarf2 dimensions are output from left to right, create the
8129 necessary array types in backwards order. */
8131 type
= element_type
;
8133 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
8138 type
= create_array_type (NULL
, type
, range_types
[i
++]);
8143 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
8146 /* Understand Dwarf2 support for vector types (like they occur on
8147 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8148 array type. This is not part of the Dwarf2/3 standard yet, but a
8149 custom vendor extension. The main difference between a regular
8150 array and the vector variant is that vectors are passed by value
8152 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
8154 make_vector_type (type
);
8156 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8157 implementation may choose to implement triple vectors using this
8159 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8162 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
8163 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8165 complaint (&symfile_complaints
,
8166 _("DW_AT_byte_size for array type smaller "
8167 "than the total size of elements"));
8170 name
= dwarf2_name (die
, cu
);
8172 TYPE_NAME (type
) = name
;
8174 /* Install the type in the die. */
8175 set_die_type (die
, type
, cu
);
8177 /* set_die_type should be already done. */
8178 set_descriptive_type (type
, die
, cu
);
8180 do_cleanups (back_to
);
8185 static enum dwarf_array_dim_ordering
8186 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
8188 struct attribute
*attr
;
8190 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
8192 if (attr
) return DW_SND (attr
);
8194 /* GNU F77 is a special case, as at 08/2004 array type info is the
8195 opposite order to the dwarf2 specification, but data is still
8196 laid out as per normal fortran.
8198 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8199 version checking. */
8201 if (cu
->language
== language_fortran
8202 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
8204 return DW_ORD_row_major
;
8207 switch (cu
->language_defn
->la_array_ordering
)
8209 case array_column_major
:
8210 return DW_ORD_col_major
;
8211 case array_row_major
:
8213 return DW_ORD_row_major
;
8217 /* Extract all information from a DW_TAG_set_type DIE and put it in
8218 the DIE's type field. */
8220 static struct type
*
8221 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8223 struct type
*domain_type
, *set_type
;
8224 struct attribute
*attr
;
8226 domain_type
= die_type (die
, cu
);
8228 /* The die_type call above may have already set the type for this DIE. */
8229 set_type
= get_die_type (die
, cu
);
8233 set_type
= create_set_type (NULL
, domain_type
);
8235 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8237 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
8239 return set_die_type (die
, set_type
, cu
);
8242 /* First cut: install each common block member as a global variable. */
8245 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
8247 struct die_info
*child_die
;
8248 struct attribute
*attr
;
8250 CORE_ADDR base
= (CORE_ADDR
) 0;
8252 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8255 /* Support the .debug_loc offsets. */
8256 if (attr_form_is_block (attr
))
8258 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
8260 else if (attr_form_is_section_offset (attr
))
8262 dwarf2_complex_location_expr_complaint ();
8266 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8267 "common block member");
8270 if (die
->child
!= NULL
)
8272 child_die
= die
->child
;
8273 while (child_die
&& child_die
->tag
)
8277 sym
= new_symbol (child_die
, NULL
, cu
);
8279 && handle_data_member_location (child_die
, cu
, &offset
))
8281 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
8282 add_symbol_to_list (sym
, &global_symbols
);
8284 child_die
= sibling_die (child_die
);
8289 /* Create a type for a C++ namespace. */
8291 static struct type
*
8292 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8294 struct objfile
*objfile
= cu
->objfile
;
8295 const char *previous_prefix
, *name
;
8299 /* For extensions, reuse the type of the original namespace. */
8300 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
8302 struct die_info
*ext_die
;
8303 struct dwarf2_cu
*ext_cu
= cu
;
8305 ext_die
= dwarf2_extension (die
, &ext_cu
);
8306 type
= read_type_die (ext_die
, ext_cu
);
8308 /* EXT_CU may not be the same as CU.
8309 Ensure TYPE is recorded in CU's type_hash table. */
8310 return set_die_type (die
, type
, cu
);
8313 name
= namespace_name (die
, &is_anonymous
, cu
);
8315 /* Now build the name of the current namespace. */
8317 previous_prefix
= determine_prefix (die
, cu
);
8318 if (previous_prefix
[0] != '\0')
8319 name
= typename_concat (&objfile
->objfile_obstack
,
8320 previous_prefix
, name
, 0, cu
);
8322 /* Create the type. */
8323 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8325 TYPE_NAME (type
) = (char *) name
;
8326 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8328 return set_die_type (die
, type
, cu
);
8331 /* Read a C++ namespace. */
8334 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8336 struct objfile
*objfile
= cu
->objfile
;
8339 /* Add a symbol associated to this if we haven't seen the namespace
8340 before. Also, add a using directive if it's an anonymous
8343 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8347 type
= read_type_die (die
, cu
);
8348 new_symbol (die
, type
, cu
);
8350 namespace_name (die
, &is_anonymous
, cu
);
8353 const char *previous_prefix
= determine_prefix (die
, cu
);
8355 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8356 NULL
, NULL
, &objfile
->objfile_obstack
);
8360 if (die
->child
!= NULL
)
8362 struct die_info
*child_die
= die
->child
;
8364 while (child_die
&& child_die
->tag
)
8366 process_die (child_die
, cu
);
8367 child_die
= sibling_die (child_die
);
8372 /* Read a Fortran module as type. This DIE can be only a declaration used for
8373 imported module. Still we need that type as local Fortran "use ... only"
8374 declaration imports depend on the created type in determine_prefix. */
8376 static struct type
*
8377 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8379 struct objfile
*objfile
= cu
->objfile
;
8383 module_name
= dwarf2_name (die
, cu
);
8385 complaint (&symfile_complaints
,
8386 _("DW_TAG_module has no name, offset 0x%x"),
8388 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8390 /* determine_prefix uses TYPE_TAG_NAME. */
8391 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8393 return set_die_type (die
, type
, cu
);
8396 /* Read a Fortran module. */
8399 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8401 struct die_info
*child_die
= die
->child
;
8403 while (child_die
&& child_die
->tag
)
8405 process_die (child_die
, cu
);
8406 child_die
= sibling_die (child_die
);
8410 /* Return the name of the namespace represented by DIE. Set
8411 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8415 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8417 struct die_info
*current_die
;
8418 const char *name
= NULL
;
8420 /* Loop through the extensions until we find a name. */
8422 for (current_die
= die
;
8423 current_die
!= NULL
;
8424 current_die
= dwarf2_extension (die
, &cu
))
8426 name
= dwarf2_name (current_die
, cu
);
8431 /* Is it an anonymous namespace? */
8433 *is_anonymous
= (name
== NULL
);
8435 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8440 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8441 the user defined type vector. */
8443 static struct type
*
8444 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8446 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8447 struct comp_unit_head
*cu_header
= &cu
->header
;
8449 struct attribute
*attr_byte_size
;
8450 struct attribute
*attr_address_class
;
8451 int byte_size
, addr_class
;
8452 struct type
*target_type
;
8454 target_type
= die_type (die
, cu
);
8456 /* The die_type call above may have already set the type for this DIE. */
8457 type
= get_die_type (die
, cu
);
8461 type
= lookup_pointer_type (target_type
);
8463 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8465 byte_size
= DW_UNSND (attr_byte_size
);
8467 byte_size
= cu_header
->addr_size
;
8469 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8470 if (attr_address_class
)
8471 addr_class
= DW_UNSND (attr_address_class
);
8473 addr_class
= DW_ADDR_none
;
8475 /* If the pointer size or address class is different than the
8476 default, create a type variant marked as such and set the
8477 length accordingly. */
8478 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8480 if (gdbarch_address_class_type_flags_p (gdbarch
))
8484 type_flags
= gdbarch_address_class_type_flags
8485 (gdbarch
, byte_size
, addr_class
);
8486 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8488 type
= make_type_with_address_space (type
, type_flags
);
8490 else if (TYPE_LENGTH (type
) != byte_size
)
8492 complaint (&symfile_complaints
,
8493 _("invalid pointer size %d"), byte_size
);
8497 /* Should we also complain about unhandled address classes? */
8501 TYPE_LENGTH (type
) = byte_size
;
8502 return set_die_type (die
, type
, cu
);
8505 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8506 the user defined type vector. */
8508 static struct type
*
8509 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8512 struct type
*to_type
;
8513 struct type
*domain
;
8515 to_type
= die_type (die
, cu
);
8516 domain
= die_containing_type (die
, cu
);
8518 /* The calls above may have already set the type for this DIE. */
8519 type
= get_die_type (die
, cu
);
8523 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8524 type
= lookup_methodptr_type (to_type
);
8526 type
= lookup_memberptr_type (to_type
, domain
);
8528 return set_die_type (die
, type
, cu
);
8531 /* Extract all information from a DW_TAG_reference_type DIE and add to
8532 the user defined type vector. */
8534 static struct type
*
8535 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8537 struct comp_unit_head
*cu_header
= &cu
->header
;
8538 struct type
*type
, *target_type
;
8539 struct attribute
*attr
;
8541 target_type
= die_type (die
, cu
);
8543 /* The die_type call above may have already set the type for this DIE. */
8544 type
= get_die_type (die
, cu
);
8548 type
= lookup_reference_type (target_type
);
8549 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8552 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8556 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8558 return set_die_type (die
, type
, cu
);
8561 static struct type
*
8562 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8564 struct type
*base_type
, *cv_type
;
8566 base_type
= die_type (die
, cu
);
8568 /* The die_type call above may have already set the type for this DIE. */
8569 cv_type
= get_die_type (die
, cu
);
8573 /* In case the const qualifier is applied to an array type, the element type
8574 is so qualified, not the array type (section 6.7.3 of C99). */
8575 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8577 struct type
*el_type
, *inner_array
;
8579 base_type
= copy_type (base_type
);
8580 inner_array
= base_type
;
8582 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8584 TYPE_TARGET_TYPE (inner_array
) =
8585 copy_type (TYPE_TARGET_TYPE (inner_array
));
8586 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8589 el_type
= TYPE_TARGET_TYPE (inner_array
);
8590 TYPE_TARGET_TYPE (inner_array
) =
8591 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8593 return set_die_type (die
, base_type
, cu
);
8596 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8597 return set_die_type (die
, cv_type
, cu
);
8600 static struct type
*
8601 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8603 struct type
*base_type
, *cv_type
;
8605 base_type
= die_type (die
, cu
);
8607 /* The die_type call above may have already set the type for this DIE. */
8608 cv_type
= get_die_type (die
, cu
);
8612 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8613 return set_die_type (die
, cv_type
, cu
);
8616 /* Extract all information from a DW_TAG_string_type DIE and add to
8617 the user defined type vector. It isn't really a user defined type,
8618 but it behaves like one, with other DIE's using an AT_user_def_type
8619 attribute to reference it. */
8621 static struct type
*
8622 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8624 struct objfile
*objfile
= cu
->objfile
;
8625 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8626 struct type
*type
, *range_type
, *index_type
, *char_type
;
8627 struct attribute
*attr
;
8628 unsigned int length
;
8630 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8633 length
= DW_UNSND (attr
);
8637 /* Check for the DW_AT_byte_size attribute. */
8638 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8641 length
= DW_UNSND (attr
);
8649 index_type
= objfile_type (objfile
)->builtin_int
;
8650 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8651 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8652 type
= create_string_type (NULL
, char_type
, range_type
);
8654 return set_die_type (die
, type
, cu
);
8657 /* Handle DIES due to C code like:
8661 int (*funcp)(int a, long l);
8665 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8667 static struct type
*
8668 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8670 struct objfile
*objfile
= cu
->objfile
;
8671 struct type
*type
; /* Type that this function returns. */
8672 struct type
*ftype
; /* Function that returns above type. */
8673 struct attribute
*attr
;
8675 type
= die_type (die
, cu
);
8677 /* The die_type call above may have already set the type for this DIE. */
8678 ftype
= get_die_type (die
, cu
);
8682 ftype
= lookup_function_type (type
);
8684 /* All functions in C++, Pascal and Java have prototypes. */
8685 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8686 if ((attr
&& (DW_UNSND (attr
) != 0))
8687 || cu
->language
== language_cplus
8688 || cu
->language
== language_java
8689 || cu
->language
== language_pascal
)
8690 TYPE_PROTOTYPED (ftype
) = 1;
8691 else if (producer_is_realview (cu
->producer
))
8692 /* RealView does not emit DW_AT_prototyped. We can not
8693 distinguish prototyped and unprototyped functions; default to
8694 prototyped, since that is more common in modern code (and
8695 RealView warns about unprototyped functions). */
8696 TYPE_PROTOTYPED (ftype
) = 1;
8698 /* Store the calling convention in the type if it's available in
8699 the subroutine die. Otherwise set the calling convention to
8700 the default value DW_CC_normal. */
8701 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8703 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8704 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8705 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8707 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8709 /* We need to add the subroutine type to the die immediately so
8710 we don't infinitely recurse when dealing with parameters
8711 declared as the same subroutine type. */
8712 set_die_type (die
, ftype
, cu
);
8714 if (die
->child
!= NULL
)
8716 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
8717 struct die_info
*child_die
;
8718 int nparams
, iparams
;
8720 /* Count the number of parameters.
8721 FIXME: GDB currently ignores vararg functions, but knows about
8722 vararg member functions. */
8724 child_die
= die
->child
;
8725 while (child_die
&& child_die
->tag
)
8727 if (child_die
->tag
== DW_TAG_formal_parameter
)
8729 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8730 TYPE_VARARGS (ftype
) = 1;
8731 child_die
= sibling_die (child_die
);
8734 /* Allocate storage for parameters and fill them in. */
8735 TYPE_NFIELDS (ftype
) = nparams
;
8736 TYPE_FIELDS (ftype
) = (struct field
*)
8737 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8739 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8740 even if we error out during the parameters reading below. */
8741 for (iparams
= 0; iparams
< nparams
; iparams
++)
8742 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8745 child_die
= die
->child
;
8746 while (child_die
&& child_die
->tag
)
8748 if (child_die
->tag
== DW_TAG_formal_parameter
)
8750 struct type
*arg_type
;
8752 /* DWARF version 2 has no clean way to discern C++
8753 static and non-static member functions. G++ helps
8754 GDB by marking the first parameter for non-static
8755 member functions (which is the this pointer) as
8756 artificial. We pass this information to
8757 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8759 DWARF version 3 added DW_AT_object_pointer, which GCC
8760 4.5 does not yet generate. */
8761 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8763 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8766 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8768 /* GCC/43521: In java, the formal parameter
8769 "this" is sometimes not marked with DW_AT_artificial. */
8770 if (cu
->language
== language_java
)
8772 const char *name
= dwarf2_name (child_die
, cu
);
8774 if (name
&& !strcmp (name
, "this"))
8775 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8778 arg_type
= die_type (child_die
, cu
);
8780 /* RealView does not mark THIS as const, which the testsuite
8781 expects. GCC marks THIS as const in method definitions,
8782 but not in the class specifications (GCC PR 43053). */
8783 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8784 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8787 struct dwarf2_cu
*arg_cu
= cu
;
8788 const char *name
= dwarf2_name (child_die
, cu
);
8790 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8793 /* If the compiler emits this, use it. */
8794 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8797 else if (name
&& strcmp (name
, "this") == 0)
8798 /* Function definitions will have the argument names. */
8800 else if (name
== NULL
&& iparams
== 0)
8801 /* Declarations may not have the names, so like
8802 elsewhere in GDB, assume an artificial first
8803 argument is "this". */
8807 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8811 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8814 child_die
= sibling_die (child_die
);
8821 static struct type
*
8822 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8824 struct objfile
*objfile
= cu
->objfile
;
8825 const char *name
= NULL
;
8826 struct type
*this_type
, *target_type
;
8828 name
= dwarf2_full_name (NULL
, die
, cu
);
8829 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8830 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8831 TYPE_NAME (this_type
) = (char *) name
;
8832 set_die_type (die
, this_type
, cu
);
8833 target_type
= die_type (die
, cu
);
8834 if (target_type
!= this_type
)
8835 TYPE_TARGET_TYPE (this_type
) = target_type
;
8838 /* Self-referential typedefs are, it seems, not allowed by the DWARF
8839 spec and cause infinite loops in GDB. */
8840 complaint (&symfile_complaints
,
8841 _("Self-referential DW_TAG_typedef "
8842 "- DIE at 0x%x [in module %s]"),
8843 die
->offset
, objfile
->name
);
8844 TYPE_TARGET_TYPE (this_type
) = NULL
;
8849 /* Find a representation of a given base type and install
8850 it in the TYPE field of the die. */
8852 static struct type
*
8853 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8855 struct objfile
*objfile
= cu
->objfile
;
8857 struct attribute
*attr
;
8858 int encoding
= 0, size
= 0;
8860 enum type_code code
= TYPE_CODE_INT
;
8862 struct type
*target_type
= NULL
;
8864 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8867 encoding
= DW_UNSND (attr
);
8869 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8872 size
= DW_UNSND (attr
);
8874 name
= dwarf2_name (die
, cu
);
8877 complaint (&symfile_complaints
,
8878 _("DW_AT_name missing from DW_TAG_base_type"));
8883 case DW_ATE_address
:
8884 /* Turn DW_ATE_address into a void * pointer. */
8885 code
= TYPE_CODE_PTR
;
8886 type_flags
|= TYPE_FLAG_UNSIGNED
;
8887 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8889 case DW_ATE_boolean
:
8890 code
= TYPE_CODE_BOOL
;
8891 type_flags
|= TYPE_FLAG_UNSIGNED
;
8893 case DW_ATE_complex_float
:
8894 code
= TYPE_CODE_COMPLEX
;
8895 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8897 case DW_ATE_decimal_float
:
8898 code
= TYPE_CODE_DECFLOAT
;
8901 code
= TYPE_CODE_FLT
;
8905 case DW_ATE_unsigned
:
8906 type_flags
|= TYPE_FLAG_UNSIGNED
;
8907 if (cu
->language
== language_fortran
8909 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
8910 code
= TYPE_CODE_CHAR
;
8912 case DW_ATE_signed_char
:
8913 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8914 || cu
->language
== language_pascal
8915 || cu
->language
== language_fortran
)
8916 code
= TYPE_CODE_CHAR
;
8918 case DW_ATE_unsigned_char
:
8919 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8920 || cu
->language
== language_pascal
8921 || cu
->language
== language_fortran
)
8922 code
= TYPE_CODE_CHAR
;
8923 type_flags
|= TYPE_FLAG_UNSIGNED
;
8926 /* We just treat this as an integer and then recognize the
8927 type by name elsewhere. */
8931 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8932 dwarf_type_encoding_name (encoding
));
8936 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8937 TYPE_NAME (type
) = name
;
8938 TYPE_TARGET_TYPE (type
) = target_type
;
8940 if (name
&& strcmp (name
, "char") == 0)
8941 TYPE_NOSIGN (type
) = 1;
8943 return set_die_type (die
, type
, cu
);
8946 /* Read the given DW_AT_subrange DIE. */
8948 static struct type
*
8949 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8951 struct type
*base_type
;
8952 struct type
*range_type
;
8953 struct attribute
*attr
;
8957 LONGEST negative_mask
;
8959 base_type
= die_type (die
, cu
);
8960 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8961 check_typedef (base_type
);
8963 /* The die_type call above may have already set the type for this DIE. */
8964 range_type
= get_die_type (die
, cu
);
8968 if (cu
->language
== language_fortran
)
8970 /* FORTRAN implies a lower bound of 1, if not given. */
8974 /* FIXME: For variable sized arrays either of these could be
8975 a variable rather than a constant value. We'll allow it,
8976 but we don't know how to handle it. */
8977 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8979 low
= dwarf2_get_attr_constant_value (attr
, 0);
8981 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8984 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
8986 /* GCC encodes arrays with unspecified or dynamic length
8987 with a DW_FORM_block1 attribute or a reference attribute.
8988 FIXME: GDB does not yet know how to handle dynamic
8989 arrays properly, treat them as arrays with unspecified
8992 FIXME: jimb/2003-09-22: GDB does not really know
8993 how to handle arrays of unspecified length
8994 either; we just represent them as zero-length
8995 arrays. Choose an appropriate upper bound given
8996 the lower bound we've computed above. */
9000 high
= dwarf2_get_attr_constant_value (attr
, 1);
9004 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
9007 int count
= dwarf2_get_attr_constant_value (attr
, 1);
9008 high
= low
+ count
- 1;
9012 /* Unspecified array length. */
9017 /* Dwarf-2 specifications explicitly allows to create subrange types
9018 without specifying a base type.
9019 In that case, the base type must be set to the type of
9020 the lower bound, upper bound or count, in that order, if any of these
9021 three attributes references an object that has a type.
9022 If no base type is found, the Dwarf-2 specifications say that
9023 a signed integer type of size equal to the size of an address should
9025 For the following C code: `extern char gdb_int [];'
9026 GCC produces an empty range DIE.
9027 FIXME: muller/2010-05-28: Possible references to object for low bound,
9028 high bound or count are not yet handled by this code. */
9029 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
9031 struct objfile
*objfile
= cu
->objfile
;
9032 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9033 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
9034 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
9036 /* Test "int", "long int", and "long long int" objfile types,
9037 and select the first one having a size above or equal to the
9038 architecture address size. */
9039 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9040 base_type
= int_type
;
9043 int_type
= objfile_type (objfile
)->builtin_long
;
9044 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9045 base_type
= int_type
;
9048 int_type
= objfile_type (objfile
)->builtin_long_long
;
9049 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9050 base_type
= int_type
;
9056 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
9057 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
9058 low
|= negative_mask
;
9059 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
9060 high
|= negative_mask
;
9062 range_type
= create_range_type (NULL
, base_type
, low
, high
);
9064 /* Mark arrays with dynamic length at least as an array of unspecified
9065 length. GDB could check the boundary but before it gets implemented at
9066 least allow accessing the array elements. */
9067 if (attr
&& attr_form_is_block (attr
))
9068 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9070 /* Ada expects an empty array on no boundary attributes. */
9071 if (attr
== NULL
&& cu
->language
!= language_ada
)
9072 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9074 name
= dwarf2_name (die
, cu
);
9076 TYPE_NAME (range_type
) = name
;
9078 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9080 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
9082 set_die_type (die
, range_type
, cu
);
9084 /* set_die_type should be already done. */
9085 set_descriptive_type (range_type
, die
, cu
);
9090 static struct type
*
9091 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9095 /* For now, we only support the C meaning of an unspecified type: void. */
9097 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
9098 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
9100 return set_die_type (die
, type
, cu
);
9103 /* Trivial hash function for die_info: the hash value of a DIE
9104 is its offset in .debug_info for this objfile. */
9107 die_hash (const void *item
)
9109 const struct die_info
*die
= item
;
9114 /* Trivial comparison function for die_info structures: two DIEs
9115 are equal if they have the same offset. */
9118 die_eq (const void *item_lhs
, const void *item_rhs
)
9120 const struct die_info
*die_lhs
= item_lhs
;
9121 const struct die_info
*die_rhs
= item_rhs
;
9123 return die_lhs
->offset
== die_rhs
->offset
;
9126 /* Read a whole compilation unit into a linked list of dies. */
9128 static struct die_info
*
9129 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9131 struct die_reader_specs reader_specs
;
9132 int read_abbrevs
= 0;
9133 struct cleanup
*back_to
= NULL
;
9134 struct die_info
*die
;
9136 if (cu
->dwarf2_abbrevs
== NULL
)
9138 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
9139 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
9143 gdb_assert (cu
->die_hash
== NULL
);
9145 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9149 &cu
->comp_unit_obstack
,
9150 hashtab_obstack_allocate
,
9151 dummy_obstack_deallocate
);
9153 init_cu_die_reader (&reader_specs
, cu
);
9155 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
9158 do_cleanups (back_to
);
9163 /* Main entry point for reading a DIE and all children.
9164 Read the DIE and dump it if requested. */
9166 static struct die_info
*
9167 read_die_and_children (const struct die_reader_specs
*reader
,
9169 gdb_byte
**new_info_ptr
,
9170 struct die_info
*parent
)
9172 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
9173 new_info_ptr
, parent
);
9175 if (dwarf2_die_debug
)
9177 fprintf_unfiltered (gdb_stdlog
,
9178 "\nRead die from %s of %s:\n",
9179 (reader
->cu
->per_cu
->debug_types_section
9182 reader
->abfd
->filename
);
9183 dump_die (result
, dwarf2_die_debug
);
9189 /* Read a single die and all its descendents. Set the die's sibling
9190 field to NULL; set other fields in the die correctly, and set all
9191 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9192 location of the info_ptr after reading all of those dies. PARENT
9193 is the parent of the die in question. */
9195 static struct die_info
*
9196 read_die_and_children_1 (const struct die_reader_specs
*reader
,
9198 gdb_byte
**new_info_ptr
,
9199 struct die_info
*parent
)
9201 struct die_info
*die
;
9205 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
9208 *new_info_ptr
= cur_ptr
;
9211 store_in_ref_table (die
, reader
->cu
);
9214 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
9218 *new_info_ptr
= cur_ptr
;
9221 die
->sibling
= NULL
;
9222 die
->parent
= parent
;
9226 /* Read a die, all of its descendents, and all of its siblings; set
9227 all of the fields of all of the dies correctly. Arguments are as
9228 in read_die_and_children. */
9230 static struct die_info
*
9231 read_die_and_siblings (const struct die_reader_specs
*reader
,
9233 gdb_byte
**new_info_ptr
,
9234 struct die_info
*parent
)
9236 struct die_info
*first_die
, *last_sibling
;
9240 first_die
= last_sibling
= NULL
;
9244 struct die_info
*die
9245 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
9249 *new_info_ptr
= cur_ptr
;
9256 last_sibling
->sibling
= die
;
9262 /* Read the die from the .debug_info section buffer. Set DIEP to
9263 point to a newly allocated die with its information, except for its
9264 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9265 whether the die has children or not. */
9268 read_full_die (const struct die_reader_specs
*reader
,
9269 struct die_info
**diep
, gdb_byte
*info_ptr
,
9272 unsigned int abbrev_number
, bytes_read
, i
, offset
;
9273 struct abbrev_info
*abbrev
;
9274 struct die_info
*die
;
9275 struct dwarf2_cu
*cu
= reader
->cu
;
9276 bfd
*abfd
= reader
->abfd
;
9278 offset
= info_ptr
- reader
->buffer
;
9279 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9280 info_ptr
+= bytes_read
;
9288 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
9290 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9292 bfd_get_filename (abfd
));
9294 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
9295 die
->offset
= offset
;
9296 die
->tag
= abbrev
->tag
;
9297 die
->abbrev
= abbrev_number
;
9299 die
->num_attrs
= abbrev
->num_attrs
;
9301 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9302 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
9303 abfd
, info_ptr
, cu
);
9306 *has_children
= abbrev
->has_children
;
9310 /* In DWARF version 2, the description of the debugging information is
9311 stored in a separate .debug_abbrev section. Before we read any
9312 dies from a section we read in all abbreviations and install them
9313 in a hash table. This function also sets flags in CU describing
9314 the data found in the abbrev table. */
9317 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
9319 struct comp_unit_head
*cu_header
= &cu
->header
;
9320 gdb_byte
*abbrev_ptr
;
9321 struct abbrev_info
*cur_abbrev
;
9322 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9323 unsigned int abbrev_form
, hash_number
;
9324 struct attr_abbrev
*cur_attrs
;
9325 unsigned int allocated_attrs
;
9327 /* Initialize dwarf2 abbrevs. */
9328 obstack_init (&cu
->abbrev_obstack
);
9329 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9331 * sizeof (struct abbrev_info
*)));
9332 memset (cu
->dwarf2_abbrevs
, 0,
9333 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9335 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
9336 &dwarf2_per_objfile
->abbrev
);
9337 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
9338 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9339 abbrev_ptr
+= bytes_read
;
9341 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9342 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9344 /* Loop until we reach an abbrev number of 0. */
9345 while (abbrev_number
)
9347 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9349 /* read in abbrev header */
9350 cur_abbrev
->number
= abbrev_number
;
9351 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9352 abbrev_ptr
+= bytes_read
;
9353 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9356 if (cur_abbrev
->tag
== DW_TAG_namespace
)
9357 cu
->has_namespace_info
= 1;
9359 /* now read in declarations */
9360 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9361 abbrev_ptr
+= bytes_read
;
9362 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9363 abbrev_ptr
+= bytes_read
;
9366 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9368 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9370 = xrealloc (cur_attrs
, (allocated_attrs
9371 * sizeof (struct attr_abbrev
)));
9374 /* Record whether this compilation unit might have
9375 inter-compilation-unit references. If we don't know what form
9376 this attribute will have, then it might potentially be a
9377 DW_FORM_ref_addr, so we conservatively expect inter-CU
9380 if (abbrev_form
== DW_FORM_ref_addr
9381 || abbrev_form
== DW_FORM_indirect
)
9382 cu
->has_form_ref_addr
= 1;
9384 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9385 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9386 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9387 abbrev_ptr
+= bytes_read
;
9388 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9389 abbrev_ptr
+= bytes_read
;
9392 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9393 (cur_abbrev
->num_attrs
9394 * sizeof (struct attr_abbrev
)));
9395 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9396 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9398 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9399 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9400 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9402 /* Get next abbreviation.
9403 Under Irix6 the abbreviations for a compilation unit are not
9404 always properly terminated with an abbrev number of 0.
9405 Exit loop if we encounter an abbreviation which we have
9406 already read (which means we are about to read the abbreviations
9407 for the next compile unit) or if the end of the abbreviation
9408 table is reached. */
9409 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
9410 >= dwarf2_per_objfile
->abbrev
.size
)
9412 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9413 abbrev_ptr
+= bytes_read
;
9414 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9421 /* Release the memory used by the abbrev table for a compilation unit. */
9424 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9426 struct dwarf2_cu
*cu
= ptr_to_cu
;
9428 obstack_free (&cu
->abbrev_obstack
, NULL
);
9429 cu
->dwarf2_abbrevs
= NULL
;
9432 /* Lookup an abbrev_info structure in the abbrev hash table. */
9434 static struct abbrev_info
*
9435 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9437 unsigned int hash_number
;
9438 struct abbrev_info
*abbrev
;
9440 hash_number
= number
% ABBREV_HASH_SIZE
;
9441 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9445 if (abbrev
->number
== number
)
9448 abbrev
= abbrev
->next
;
9453 /* Returns nonzero if TAG represents a type that we might generate a partial
9457 is_type_tag_for_partial (int tag
)
9462 /* Some types that would be reasonable to generate partial symbols for,
9463 that we don't at present. */
9464 case DW_TAG_array_type
:
9465 case DW_TAG_file_type
:
9466 case DW_TAG_ptr_to_member_type
:
9467 case DW_TAG_set_type
:
9468 case DW_TAG_string_type
:
9469 case DW_TAG_subroutine_type
:
9471 case DW_TAG_base_type
:
9472 case DW_TAG_class_type
:
9473 case DW_TAG_interface_type
:
9474 case DW_TAG_enumeration_type
:
9475 case DW_TAG_structure_type
:
9476 case DW_TAG_subrange_type
:
9477 case DW_TAG_typedef
:
9478 case DW_TAG_union_type
:
9485 /* Load all DIEs that are interesting for partial symbols into memory. */
9487 static struct partial_die_info
*
9488 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9489 int building_psymtab
, struct dwarf2_cu
*cu
)
9491 struct objfile
*objfile
= cu
->objfile
;
9492 struct partial_die_info
*part_die
;
9493 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9494 struct abbrev_info
*abbrev
;
9495 unsigned int bytes_read
;
9496 unsigned int load_all
= 0;
9498 int nesting_level
= 1;
9503 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
9507 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9511 &cu
->comp_unit_obstack
,
9512 hashtab_obstack_allocate
,
9513 dummy_obstack_deallocate
);
9515 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9516 sizeof (struct partial_die_info
));
9520 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9522 /* A NULL abbrev means the end of a series of children. */
9525 if (--nesting_level
== 0)
9527 /* PART_DIE was probably the last thing allocated on the
9528 comp_unit_obstack, so we could call obstack_free
9529 here. We don't do that because the waste is small,
9530 and will be cleaned up when we're done with this
9531 compilation unit. This way, we're also more robust
9532 against other users of the comp_unit_obstack. */
9535 info_ptr
+= bytes_read
;
9536 last_die
= parent_die
;
9537 parent_die
= parent_die
->die_parent
;
9541 /* Check for template arguments. We never save these; if
9542 they're seen, we just mark the parent, and go on our way. */
9543 if (parent_die
!= NULL
9544 && cu
->language
== language_cplus
9545 && (abbrev
->tag
== DW_TAG_template_type_param
9546 || abbrev
->tag
== DW_TAG_template_value_param
))
9548 parent_die
->has_template_arguments
= 1;
9552 /* We don't need a partial DIE for the template argument. */
9553 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9559 /* We only recurse into subprograms looking for template arguments.
9560 Skip their other children. */
9562 && cu
->language
== language_cplus
9563 && parent_die
!= NULL
9564 && parent_die
->tag
== DW_TAG_subprogram
)
9566 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9570 /* Check whether this DIE is interesting enough to save. Normally
9571 we would not be interested in members here, but there may be
9572 later variables referencing them via DW_AT_specification (for
9575 && !is_type_tag_for_partial (abbrev
->tag
)
9576 && abbrev
->tag
!= DW_TAG_constant
9577 && abbrev
->tag
!= DW_TAG_enumerator
9578 && abbrev
->tag
!= DW_TAG_subprogram
9579 && abbrev
->tag
!= DW_TAG_lexical_block
9580 && abbrev
->tag
!= DW_TAG_variable
9581 && abbrev
->tag
!= DW_TAG_namespace
9582 && abbrev
->tag
!= DW_TAG_module
9583 && abbrev
->tag
!= DW_TAG_member
)
9585 /* Otherwise we skip to the next sibling, if any. */
9586 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9590 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9591 buffer
, info_ptr
, cu
);
9593 /* This two-pass algorithm for processing partial symbols has a
9594 high cost in cache pressure. Thus, handle some simple cases
9595 here which cover the majority of C partial symbols. DIEs
9596 which neither have specification tags in them, nor could have
9597 specification tags elsewhere pointing at them, can simply be
9598 processed and discarded.
9600 This segment is also optional; scan_partial_symbols and
9601 add_partial_symbol will handle these DIEs if we chain
9602 them in normally. When compilers which do not emit large
9603 quantities of duplicate debug information are more common,
9604 this code can probably be removed. */
9606 /* Any complete simple types at the top level (pretty much all
9607 of them, for a language without namespaces), can be processed
9609 if (parent_die
== NULL
9610 && part_die
->has_specification
== 0
9611 && part_die
->is_declaration
== 0
9612 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9613 || part_die
->tag
== DW_TAG_base_type
9614 || part_die
->tag
== DW_TAG_subrange_type
))
9616 if (building_psymtab
&& part_die
->name
!= NULL
)
9617 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9618 VAR_DOMAIN
, LOC_TYPEDEF
,
9619 &objfile
->static_psymbols
,
9620 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9621 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9625 /* The exception for DW_TAG_typedef with has_children above is
9626 a workaround of GCC PR debug/47510. In the case of this complaint
9627 type_name_no_tag_or_error will error on such types later.
9629 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9630 it could not find the child DIEs referenced later, this is checked
9631 above. In correct DWARF DW_TAG_typedef should have no children. */
9633 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9634 complaint (&symfile_complaints
,
9635 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9636 "- DIE at 0x%x [in module %s]"),
9637 part_die
->offset
, objfile
->name
);
9639 /* If we're at the second level, and we're an enumerator, and
9640 our parent has no specification (meaning possibly lives in a
9641 namespace elsewhere), then we can add the partial symbol now
9642 instead of queueing it. */
9643 if (part_die
->tag
== DW_TAG_enumerator
9644 && parent_die
!= NULL
9645 && parent_die
->die_parent
== NULL
9646 && parent_die
->tag
== DW_TAG_enumeration_type
9647 && parent_die
->has_specification
== 0)
9649 if (part_die
->name
== NULL
)
9650 complaint (&symfile_complaints
,
9651 _("malformed enumerator DIE ignored"));
9652 else if (building_psymtab
)
9653 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9654 VAR_DOMAIN
, LOC_CONST
,
9655 (cu
->language
== language_cplus
9656 || cu
->language
== language_java
)
9657 ? &objfile
->global_psymbols
9658 : &objfile
->static_psymbols
,
9659 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9661 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9665 /* We'll save this DIE so link it in. */
9666 part_die
->die_parent
= parent_die
;
9667 part_die
->die_sibling
= NULL
;
9668 part_die
->die_child
= NULL
;
9670 if (last_die
&& last_die
== parent_die
)
9671 last_die
->die_child
= part_die
;
9673 last_die
->die_sibling
= part_die
;
9675 last_die
= part_die
;
9677 if (first_die
== NULL
)
9678 first_die
= part_die
;
9680 /* Maybe add the DIE to the hash table. Not all DIEs that we
9681 find interesting need to be in the hash table, because we
9682 also have the parent/sibling/child chains; only those that we
9683 might refer to by offset later during partial symbol reading.
9685 For now this means things that might have be the target of a
9686 DW_AT_specification, DW_AT_abstract_origin, or
9687 DW_AT_extension. DW_AT_extension will refer only to
9688 namespaces; DW_AT_abstract_origin refers to functions (and
9689 many things under the function DIE, but we do not recurse
9690 into function DIEs during partial symbol reading) and
9691 possibly variables as well; DW_AT_specification refers to
9692 declarations. Declarations ought to have the DW_AT_declaration
9693 flag. It happens that GCC forgets to put it in sometimes, but
9694 only for functions, not for types.
9696 Adding more things than necessary to the hash table is harmless
9697 except for the performance cost. Adding too few will result in
9698 wasted time in find_partial_die, when we reread the compilation
9699 unit with load_all_dies set. */
9702 || abbrev
->tag
== DW_TAG_constant
9703 || abbrev
->tag
== DW_TAG_subprogram
9704 || abbrev
->tag
== DW_TAG_variable
9705 || abbrev
->tag
== DW_TAG_namespace
9706 || part_die
->is_declaration
)
9710 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9711 part_die
->offset
, INSERT
);
9715 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9716 sizeof (struct partial_die_info
));
9718 /* For some DIEs we want to follow their children (if any). For C
9719 we have no reason to follow the children of structures; for other
9720 languages we have to, so that we can get at method physnames
9721 to infer fully qualified class names, for DW_AT_specification,
9722 and for C++ template arguments. For C++, we also look one level
9723 inside functions to find template arguments (if the name of the
9724 function does not already contain the template arguments).
9726 For Ada, we need to scan the children of subprograms and lexical
9727 blocks as well because Ada allows the definition of nested
9728 entities that could be interesting for the debugger, such as
9729 nested subprograms for instance. */
9730 if (last_die
->has_children
9732 || last_die
->tag
== DW_TAG_namespace
9733 || last_die
->tag
== DW_TAG_module
9734 || last_die
->tag
== DW_TAG_enumeration_type
9735 || (cu
->language
== language_cplus
9736 && last_die
->tag
== DW_TAG_subprogram
9737 && (last_die
->name
== NULL
9738 || strchr (last_die
->name
, '<') == NULL
))
9739 || (cu
->language
!= language_c
9740 && (last_die
->tag
== DW_TAG_class_type
9741 || last_die
->tag
== DW_TAG_interface_type
9742 || last_die
->tag
== DW_TAG_structure_type
9743 || last_die
->tag
== DW_TAG_union_type
))
9744 || (cu
->language
== language_ada
9745 && (last_die
->tag
== DW_TAG_subprogram
9746 || last_die
->tag
== DW_TAG_lexical_block
))))
9749 parent_die
= last_die
;
9753 /* Otherwise we skip to the next sibling, if any. */
9754 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9756 /* Back to the top, do it again. */
9760 /* Read a minimal amount of information into the minimal die structure. */
9763 read_partial_die (struct partial_die_info
*part_die
,
9764 struct abbrev_info
*abbrev
,
9765 unsigned int abbrev_len
, bfd
*abfd
,
9766 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9767 struct dwarf2_cu
*cu
)
9769 struct objfile
*objfile
= cu
->objfile
;
9771 struct attribute attr
;
9772 int has_low_pc_attr
= 0;
9773 int has_high_pc_attr
= 0;
9775 memset (part_die
, 0, sizeof (struct partial_die_info
));
9777 part_die
->offset
= info_ptr
- buffer
;
9779 info_ptr
+= abbrev_len
;
9784 part_die
->tag
= abbrev
->tag
;
9785 part_die
->has_children
= abbrev
->has_children
;
9787 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9789 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9791 /* Store the data if it is of an attribute we want to keep in a
9792 partial symbol table. */
9796 switch (part_die
->tag
)
9798 case DW_TAG_compile_unit
:
9799 case DW_TAG_type_unit
:
9800 /* Compilation units have a DW_AT_name that is a filename, not
9801 a source language identifier. */
9802 case DW_TAG_enumeration_type
:
9803 case DW_TAG_enumerator
:
9804 /* These tags always have simple identifiers already; no need
9805 to canonicalize them. */
9806 part_die
->name
= DW_STRING (&attr
);
9810 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9811 &objfile
->objfile_obstack
);
9815 case DW_AT_linkage_name
:
9816 case DW_AT_MIPS_linkage_name
:
9817 /* Note that both forms of linkage name might appear. We
9818 assume they will be the same, and we only store the last
9820 if (cu
->language
== language_ada
)
9821 part_die
->name
= DW_STRING (&attr
);
9822 part_die
->linkage_name
= DW_STRING (&attr
);
9825 has_low_pc_attr
= 1;
9826 part_die
->lowpc
= DW_ADDR (&attr
);
9829 has_high_pc_attr
= 1;
9830 part_die
->highpc
= DW_ADDR (&attr
);
9832 case DW_AT_location
:
9833 /* Support the .debug_loc offsets. */
9834 if (attr_form_is_block (&attr
))
9836 part_die
->locdesc
= DW_BLOCK (&attr
);
9838 else if (attr_form_is_section_offset (&attr
))
9840 dwarf2_complex_location_expr_complaint ();
9844 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9845 "partial symbol information");
9848 case DW_AT_external
:
9849 part_die
->is_external
= DW_UNSND (&attr
);
9851 case DW_AT_declaration
:
9852 part_die
->is_declaration
= DW_UNSND (&attr
);
9855 part_die
->has_type
= 1;
9857 case DW_AT_abstract_origin
:
9858 case DW_AT_specification
:
9859 case DW_AT_extension
:
9860 part_die
->has_specification
= 1;
9861 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9864 /* Ignore absolute siblings, they might point outside of
9865 the current compile unit. */
9866 if (attr
.form
== DW_FORM_ref_addr
)
9867 complaint (&symfile_complaints
,
9868 _("ignoring absolute DW_AT_sibling"));
9870 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9872 case DW_AT_byte_size
:
9873 part_die
->has_byte_size
= 1;
9875 case DW_AT_calling_convention
:
9876 /* DWARF doesn't provide a way to identify a program's source-level
9877 entry point. DW_AT_calling_convention attributes are only meant
9878 to describe functions' calling conventions.
9880 However, because it's a necessary piece of information in
9881 Fortran, and because DW_CC_program is the only piece of debugging
9882 information whose definition refers to a 'main program' at all,
9883 several compilers have begun marking Fortran main programs with
9884 DW_CC_program --- even when those functions use the standard
9885 calling conventions.
9887 So until DWARF specifies a way to provide this information and
9888 compilers pick up the new representation, we'll support this
9890 if (DW_UNSND (&attr
) == DW_CC_program
9891 && cu
->language
== language_fortran
)
9893 set_main_name (part_die
->name
);
9895 /* As this DIE has a static linkage the name would be difficult
9896 to look up later. */
9897 language_of_main
= language_fortran
;
9905 if (has_low_pc_attr
&& has_high_pc_attr
)
9907 /* When using the GNU linker, .gnu.linkonce. sections are used to
9908 eliminate duplicate copies of functions and vtables and such.
9909 The linker will arbitrarily choose one and discard the others.
9910 The AT_*_pc values for such functions refer to local labels in
9911 these sections. If the section from that file was discarded, the
9912 labels are not in the output, so the relocs get a value of 0.
9913 If this is a discarded function, mark the pc bounds as invalid,
9914 so that GDB will ignore it. */
9915 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9917 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9919 complaint (&symfile_complaints
,
9920 _("DW_AT_low_pc %s is zero "
9921 "for DIE at 0x%x [in module %s]"),
9922 paddress (gdbarch
, part_die
->lowpc
),
9923 part_die
->offset
, objfile
->name
);
9925 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9926 else if (part_die
->lowpc
>= part_die
->highpc
)
9928 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9930 complaint (&symfile_complaints
,
9931 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9932 "for DIE at 0x%x [in module %s]"),
9933 paddress (gdbarch
, part_die
->lowpc
),
9934 paddress (gdbarch
, part_die
->highpc
),
9935 part_die
->offset
, objfile
->name
);
9938 part_die
->has_pc_info
= 1;
9944 /* Find a cached partial DIE at OFFSET in CU. */
9946 static struct partial_die_info
*
9947 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9949 struct partial_die_info
*lookup_die
= NULL
;
9950 struct partial_die_info part_die
;
9952 part_die
.offset
= offset
;
9953 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9958 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9959 except in the case of .debug_types DIEs which do not reference
9960 outside their CU (they do however referencing other types via
9961 DW_FORM_ref_sig8). */
9963 static struct partial_die_info
*
9964 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9966 struct objfile
*objfile
= cu
->objfile
;
9967 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9968 struct partial_die_info
*pd
= NULL
;
9970 if (cu
->per_cu
->debug_types_section
)
9972 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9978 if (offset_in_cu_p (&cu
->header
, offset
))
9980 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9985 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
9987 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9988 load_partial_comp_unit (per_cu
);
9990 per_cu
->cu
->last_used
= 0;
9991 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9993 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9995 struct cleanup
*back_to
;
9996 struct partial_die_info comp_unit_die
;
9997 struct abbrev_info
*abbrev
;
9998 unsigned int bytes_read
;
10001 per_cu
->load_all_dies
= 1;
10003 /* Re-read the DIEs. */
10004 back_to
= make_cleanup (null_cleanup
, 0);
10005 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
10007 dwarf2_read_abbrevs (objfile
->obfd
, per_cu
->cu
);
10008 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
10010 info_ptr
= (dwarf2_per_objfile
->info
.buffer
10011 + per_cu
->cu
->header
.offset
10012 + per_cu
->cu
->header
.first_die_offset
);
10013 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
10014 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
10016 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
10018 if (comp_unit_die
.has_children
)
10019 load_partial_dies (objfile
->obfd
,
10020 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
10022 do_cleanups (back_to
);
10024 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10030 internal_error (__FILE__
, __LINE__
,
10031 _("could not find partial DIE 0x%x "
10032 "in cache [from module %s]\n"),
10033 offset
, bfd_get_filename (objfile
->obfd
));
10037 /* See if we can figure out if the class lives in a namespace. We do
10038 this by looking for a member function; its demangled name will
10039 contain namespace info, if there is any. */
10042 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
10043 struct dwarf2_cu
*cu
)
10045 /* NOTE: carlton/2003-10-07: Getting the info this way changes
10046 what template types look like, because the demangler
10047 frequently doesn't give the same name as the debug info. We
10048 could fix this by only using the demangled name to get the
10049 prefix (but see comment in read_structure_type). */
10051 struct partial_die_info
*real_pdi
;
10052 struct partial_die_info
*child_pdi
;
10054 /* If this DIE (this DIE's specification, if any) has a parent, then
10055 we should not do this. We'll prepend the parent's fully qualified
10056 name when we create the partial symbol. */
10058 real_pdi
= struct_pdi
;
10059 while (real_pdi
->has_specification
)
10060 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
10062 if (real_pdi
->die_parent
!= NULL
)
10065 for (child_pdi
= struct_pdi
->die_child
;
10067 child_pdi
= child_pdi
->die_sibling
)
10069 if (child_pdi
->tag
== DW_TAG_subprogram
10070 && child_pdi
->linkage_name
!= NULL
)
10072 char *actual_class_name
10073 = language_class_name_from_physname (cu
->language_defn
,
10074 child_pdi
->linkage_name
);
10075 if (actual_class_name
!= NULL
)
10078 = obsavestring (actual_class_name
,
10079 strlen (actual_class_name
),
10080 &cu
->objfile
->objfile_obstack
);
10081 xfree (actual_class_name
);
10088 /* Adjust PART_DIE before generating a symbol for it. This function
10089 may set the is_external flag or change the DIE's name. */
10092 fixup_partial_die (struct partial_die_info
*part_die
,
10093 struct dwarf2_cu
*cu
)
10095 /* Once we've fixed up a die, there's no point in doing so again.
10096 This also avoids a memory leak if we were to call
10097 guess_partial_die_structure_name multiple times. */
10098 if (part_die
->fixup_called
)
10101 /* If we found a reference attribute and the DIE has no name, try
10102 to find a name in the referred to DIE. */
10104 if (part_die
->name
== NULL
&& part_die
->has_specification
)
10106 struct partial_die_info
*spec_die
;
10108 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
10110 fixup_partial_die (spec_die
, cu
);
10112 if (spec_die
->name
)
10114 part_die
->name
= spec_die
->name
;
10116 /* Copy DW_AT_external attribute if it is set. */
10117 if (spec_die
->is_external
)
10118 part_die
->is_external
= spec_die
->is_external
;
10122 /* Set default names for some unnamed DIEs. */
10124 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
10125 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
10127 /* If there is no parent die to provide a namespace, and there are
10128 children, see if we can determine the namespace from their linkage
10130 NOTE: We need to do this even if cu->has_namespace_info != 0.
10131 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
10132 if (cu
->language
== language_cplus
10133 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
10134 && part_die
->die_parent
== NULL
10135 && part_die
->has_children
10136 && (part_die
->tag
== DW_TAG_class_type
10137 || part_die
->tag
== DW_TAG_structure_type
10138 || part_die
->tag
== DW_TAG_union_type
))
10139 guess_partial_die_structure_name (part_die
, cu
);
10141 /* GCC might emit a nameless struct or union that has a linkage
10142 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10143 if (part_die
->name
== NULL
10144 && (part_die
->tag
== DW_TAG_class_type
10145 || part_die
->tag
== DW_TAG_interface_type
10146 || part_die
->tag
== DW_TAG_structure_type
10147 || part_die
->tag
== DW_TAG_union_type
)
10148 && part_die
->linkage_name
!= NULL
)
10152 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
10157 /* Strip any leading namespaces/classes, keep only the base name.
10158 DW_AT_name for named DIEs does not contain the prefixes. */
10159 base
= strrchr (demangled
, ':');
10160 if (base
&& base
> demangled
&& base
[-1] == ':')
10165 part_die
->name
= obsavestring (base
, strlen (base
),
10166 &cu
->objfile
->objfile_obstack
);
10171 part_die
->fixup_called
= 1;
10174 /* Read an attribute value described by an attribute form. */
10177 read_attribute_value (struct attribute
*attr
, unsigned form
,
10178 bfd
*abfd
, gdb_byte
*info_ptr
,
10179 struct dwarf2_cu
*cu
)
10181 struct comp_unit_head
*cu_header
= &cu
->header
;
10182 unsigned int bytes_read
;
10183 struct dwarf_block
*blk
;
10188 case DW_FORM_ref_addr
:
10189 if (cu
->header
.version
== 2)
10190 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10192 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
10193 &cu
->header
, &bytes_read
);
10194 info_ptr
+= bytes_read
;
10197 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10198 info_ptr
+= bytes_read
;
10200 case DW_FORM_block2
:
10201 blk
= dwarf_alloc_block (cu
);
10202 blk
->size
= read_2_bytes (abfd
, info_ptr
);
10204 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10205 info_ptr
+= blk
->size
;
10206 DW_BLOCK (attr
) = blk
;
10208 case DW_FORM_block4
:
10209 blk
= dwarf_alloc_block (cu
);
10210 blk
->size
= read_4_bytes (abfd
, info_ptr
);
10212 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10213 info_ptr
+= blk
->size
;
10214 DW_BLOCK (attr
) = blk
;
10216 case DW_FORM_data2
:
10217 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
10220 case DW_FORM_data4
:
10221 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
10224 case DW_FORM_data8
:
10225 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
10228 case DW_FORM_sec_offset
:
10229 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
10230 info_ptr
+= bytes_read
;
10232 case DW_FORM_string
:
10233 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
10234 DW_STRING_IS_CANONICAL (attr
) = 0;
10235 info_ptr
+= bytes_read
;
10238 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
10240 DW_STRING_IS_CANONICAL (attr
) = 0;
10241 info_ptr
+= bytes_read
;
10243 case DW_FORM_exprloc
:
10244 case DW_FORM_block
:
10245 blk
= dwarf_alloc_block (cu
);
10246 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10247 info_ptr
+= bytes_read
;
10248 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10249 info_ptr
+= blk
->size
;
10250 DW_BLOCK (attr
) = blk
;
10252 case DW_FORM_block1
:
10253 blk
= dwarf_alloc_block (cu
);
10254 blk
->size
= read_1_byte (abfd
, info_ptr
);
10256 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10257 info_ptr
+= blk
->size
;
10258 DW_BLOCK (attr
) = blk
;
10260 case DW_FORM_data1
:
10261 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10265 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10268 case DW_FORM_flag_present
:
10269 DW_UNSND (attr
) = 1;
10271 case DW_FORM_sdata
:
10272 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
10273 info_ptr
+= bytes_read
;
10275 case DW_FORM_udata
:
10276 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10277 info_ptr
+= bytes_read
;
10280 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
10284 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
10288 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
10292 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
10295 case DW_FORM_ref_sig8
:
10296 /* Convert the signature to something we can record in DW_UNSND
10298 NOTE: This is NULL if the type wasn't found. */
10299 DW_SIGNATURED_TYPE (attr
) =
10300 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
10303 case DW_FORM_ref_udata
:
10304 DW_ADDR (attr
) = (cu
->header
.offset
10305 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
10306 info_ptr
+= bytes_read
;
10308 case DW_FORM_indirect
:
10309 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10310 info_ptr
+= bytes_read
;
10311 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
10314 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10315 dwarf_form_name (form
),
10316 bfd_get_filename (abfd
));
10319 /* We have seen instances where the compiler tried to emit a byte
10320 size attribute of -1 which ended up being encoded as an unsigned
10321 0xffffffff. Although 0xffffffff is technically a valid size value,
10322 an object of this size seems pretty unlikely so we can relatively
10323 safely treat these cases as if the size attribute was invalid and
10324 treat them as zero by default. */
10325 if (attr
->name
== DW_AT_byte_size
10326 && form
== DW_FORM_data4
10327 && DW_UNSND (attr
) >= 0xffffffff)
10330 (&symfile_complaints
,
10331 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10332 hex_string (DW_UNSND (attr
)));
10333 DW_UNSND (attr
) = 0;
10339 /* Read an attribute described by an abbreviated attribute. */
10342 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10343 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
10345 attr
->name
= abbrev
->name
;
10346 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
10349 /* Read dwarf information from a buffer. */
10351 static unsigned int
10352 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10354 return bfd_get_8 (abfd
, buf
);
10358 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10360 return bfd_get_signed_8 (abfd
, buf
);
10363 static unsigned int
10364 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10366 return bfd_get_16 (abfd
, buf
);
10370 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10372 return bfd_get_signed_16 (abfd
, buf
);
10375 static unsigned int
10376 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10378 return bfd_get_32 (abfd
, buf
);
10382 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10384 return bfd_get_signed_32 (abfd
, buf
);
10388 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10390 return bfd_get_64 (abfd
, buf
);
10394 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10395 unsigned int *bytes_read
)
10397 struct comp_unit_head
*cu_header
= &cu
->header
;
10398 CORE_ADDR retval
= 0;
10400 if (cu_header
->signed_addr_p
)
10402 switch (cu_header
->addr_size
)
10405 retval
= bfd_get_signed_16 (abfd
, buf
);
10408 retval
= bfd_get_signed_32 (abfd
, buf
);
10411 retval
= bfd_get_signed_64 (abfd
, buf
);
10414 internal_error (__FILE__
, __LINE__
,
10415 _("read_address: bad switch, signed [in module %s]"),
10416 bfd_get_filename (abfd
));
10421 switch (cu_header
->addr_size
)
10424 retval
= bfd_get_16 (abfd
, buf
);
10427 retval
= bfd_get_32 (abfd
, buf
);
10430 retval
= bfd_get_64 (abfd
, buf
);
10433 internal_error (__FILE__
, __LINE__
,
10434 _("read_address: bad switch, "
10435 "unsigned [in module %s]"),
10436 bfd_get_filename (abfd
));
10440 *bytes_read
= cu_header
->addr_size
;
10444 /* Read the initial length from a section. The (draft) DWARF 3
10445 specification allows the initial length to take up either 4 bytes
10446 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10447 bytes describe the length and all offsets will be 8 bytes in length
10450 An older, non-standard 64-bit format is also handled by this
10451 function. The older format in question stores the initial length
10452 as an 8-byte quantity without an escape value. Lengths greater
10453 than 2^32 aren't very common which means that the initial 4 bytes
10454 is almost always zero. Since a length value of zero doesn't make
10455 sense for the 32-bit format, this initial zero can be considered to
10456 be an escape value which indicates the presence of the older 64-bit
10457 format. As written, the code can't detect (old format) lengths
10458 greater than 4GB. If it becomes necessary to handle lengths
10459 somewhat larger than 4GB, we could allow other small values (such
10460 as the non-sensical values of 1, 2, and 3) to also be used as
10461 escape values indicating the presence of the old format.
10463 The value returned via bytes_read should be used to increment the
10464 relevant pointer after calling read_initial_length().
10466 [ Note: read_initial_length() and read_offset() are based on the
10467 document entitled "DWARF Debugging Information Format", revision
10468 3, draft 8, dated November 19, 2001. This document was obtained
10471 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10473 This document is only a draft and is subject to change. (So beware.)
10475 Details regarding the older, non-standard 64-bit format were
10476 determined empirically by examining 64-bit ELF files produced by
10477 the SGI toolchain on an IRIX 6.5 machine.
10479 - Kevin, July 16, 2002
10483 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10485 LONGEST length
= bfd_get_32 (abfd
, buf
);
10487 if (length
== 0xffffffff)
10489 length
= bfd_get_64 (abfd
, buf
+ 4);
10492 else if (length
== 0)
10494 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10495 length
= bfd_get_64 (abfd
, buf
);
10506 /* Cover function for read_initial_length.
10507 Returns the length of the object at BUF, and stores the size of the
10508 initial length in *BYTES_READ and stores the size that offsets will be in
10510 If the initial length size is not equivalent to that specified in
10511 CU_HEADER then issue a complaint.
10512 This is useful when reading non-comp-unit headers. */
10515 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10516 const struct comp_unit_head
*cu_header
,
10517 unsigned int *bytes_read
,
10518 unsigned int *offset_size
)
10520 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10522 gdb_assert (cu_header
->initial_length_size
== 4
10523 || cu_header
->initial_length_size
== 8
10524 || cu_header
->initial_length_size
== 12);
10526 if (cu_header
->initial_length_size
!= *bytes_read
)
10527 complaint (&symfile_complaints
,
10528 _("intermixed 32-bit and 64-bit DWARF sections"));
10530 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10534 /* Read an offset from the data stream. The size of the offset is
10535 given by cu_header->offset_size. */
10538 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10539 unsigned int *bytes_read
)
10541 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10543 *bytes_read
= cu_header
->offset_size
;
10547 /* Read an offset from the data stream. */
10550 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10552 LONGEST retval
= 0;
10554 switch (offset_size
)
10557 retval
= bfd_get_32 (abfd
, buf
);
10560 retval
= bfd_get_64 (abfd
, buf
);
10563 internal_error (__FILE__
, __LINE__
,
10564 _("read_offset_1: bad switch [in module %s]"),
10565 bfd_get_filename (abfd
));
10572 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10574 /* If the size of a host char is 8 bits, we can return a pointer
10575 to the buffer, otherwise we have to copy the data to a buffer
10576 allocated on the temporary obstack. */
10577 gdb_assert (HOST_CHAR_BIT
== 8);
10582 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10584 /* If the size of a host char is 8 bits, we can return a pointer
10585 to the string, otherwise we have to copy the string to a buffer
10586 allocated on the temporary obstack. */
10587 gdb_assert (HOST_CHAR_BIT
== 8);
10590 *bytes_read_ptr
= 1;
10593 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10594 return (char *) buf
;
10598 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
10600 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10601 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10602 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10603 bfd_get_filename (abfd
));
10604 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10605 error (_("DW_FORM_strp pointing outside of "
10606 ".debug_str section [in module %s]"),
10607 bfd_get_filename (abfd
));
10608 gdb_assert (HOST_CHAR_BIT
== 8);
10609 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10611 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10615 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10616 const struct comp_unit_head
*cu_header
,
10617 unsigned int *bytes_read_ptr
)
10619 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10621 return read_indirect_string_at_offset (abfd
, str_offset
);
10624 static unsigned long
10625 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10627 unsigned long result
;
10628 unsigned int num_read
;
10630 unsigned char byte
;
10638 byte
= bfd_get_8 (abfd
, buf
);
10641 result
|= ((unsigned long)(byte
& 127) << shift
);
10642 if ((byte
& 128) == 0)
10648 *bytes_read_ptr
= num_read
;
10653 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10656 int i
, shift
, num_read
;
10657 unsigned char byte
;
10665 byte
= bfd_get_8 (abfd
, buf
);
10668 result
|= ((long)(byte
& 127) << shift
);
10670 if ((byte
& 128) == 0)
10675 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10676 result
|= -(((long)1) << shift
);
10677 *bytes_read_ptr
= num_read
;
10681 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10684 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10690 byte
= bfd_get_8 (abfd
, buf
);
10692 if ((byte
& 128) == 0)
10698 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10705 cu
->language
= language_c
;
10707 case DW_LANG_C_plus_plus
:
10708 cu
->language
= language_cplus
;
10711 cu
->language
= language_d
;
10713 case DW_LANG_Fortran77
:
10714 case DW_LANG_Fortran90
:
10715 case DW_LANG_Fortran95
:
10716 cu
->language
= language_fortran
;
10718 case DW_LANG_Mips_Assembler
:
10719 cu
->language
= language_asm
;
10722 cu
->language
= language_java
;
10724 case DW_LANG_Ada83
:
10725 case DW_LANG_Ada95
:
10726 cu
->language
= language_ada
;
10728 case DW_LANG_Modula2
:
10729 cu
->language
= language_m2
;
10731 case DW_LANG_Pascal83
:
10732 cu
->language
= language_pascal
;
10735 cu
->language
= language_objc
;
10737 case DW_LANG_Cobol74
:
10738 case DW_LANG_Cobol85
:
10740 cu
->language
= language_minimal
;
10743 cu
->language_defn
= language_def (cu
->language
);
10746 /* Return the named attribute or NULL if not there. */
10748 static struct attribute
*
10749 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10752 struct attribute
*spec
= NULL
;
10754 for (i
= 0; i
< die
->num_attrs
; ++i
)
10756 if (die
->attrs
[i
].name
== name
)
10757 return &die
->attrs
[i
];
10758 if (die
->attrs
[i
].name
== DW_AT_specification
10759 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10760 spec
= &die
->attrs
[i
];
10765 die
= follow_die_ref (die
, spec
, &cu
);
10766 return dwarf2_attr (die
, name
, cu
);
10772 /* Return the named attribute or NULL if not there,
10773 but do not follow DW_AT_specification, etc.
10774 This is for use in contexts where we're reading .debug_types dies.
10775 Following DW_AT_specification, DW_AT_abstract_origin will take us
10776 back up the chain, and we want to go down. */
10778 static struct attribute
*
10779 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10780 struct dwarf2_cu
*cu
)
10784 for (i
= 0; i
< die
->num_attrs
; ++i
)
10785 if (die
->attrs
[i
].name
== name
)
10786 return &die
->attrs
[i
];
10791 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10792 and holds a non-zero value. This function should only be used for
10793 DW_FORM_flag or DW_FORM_flag_present attributes. */
10796 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10798 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10800 return (attr
&& DW_UNSND (attr
));
10804 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10806 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10807 which value is non-zero. However, we have to be careful with
10808 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10809 (via dwarf2_flag_true_p) follows this attribute. So we may
10810 end up accidently finding a declaration attribute that belongs
10811 to a different DIE referenced by the specification attribute,
10812 even though the given DIE does not have a declaration attribute. */
10813 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10814 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10817 /* Return the die giving the specification for DIE, if there is
10818 one. *SPEC_CU is the CU containing DIE on input, and the CU
10819 containing the return value on output. If there is no
10820 specification, but there is an abstract origin, that is
10823 static struct die_info
*
10824 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10826 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10829 if (spec_attr
== NULL
)
10830 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10832 if (spec_attr
== NULL
)
10835 return follow_die_ref (die
, spec_attr
, spec_cu
);
10838 /* Free the line_header structure *LH, and any arrays and strings it
10840 NOTE: This is also used as a "cleanup" function. */
10843 free_line_header (struct line_header
*lh
)
10845 if (lh
->standard_opcode_lengths
)
10846 xfree (lh
->standard_opcode_lengths
);
10848 /* Remember that all the lh->file_names[i].name pointers are
10849 pointers into debug_line_buffer, and don't need to be freed. */
10850 if (lh
->file_names
)
10851 xfree (lh
->file_names
);
10853 /* Similarly for the include directory names. */
10854 if (lh
->include_dirs
)
10855 xfree (lh
->include_dirs
);
10860 /* Add an entry to LH's include directory table. */
10863 add_include_dir (struct line_header
*lh
, char *include_dir
)
10865 /* Grow the array if necessary. */
10866 if (lh
->include_dirs_size
== 0)
10868 lh
->include_dirs_size
= 1; /* for testing */
10869 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10870 * sizeof (*lh
->include_dirs
));
10872 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10874 lh
->include_dirs_size
*= 2;
10875 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10876 (lh
->include_dirs_size
10877 * sizeof (*lh
->include_dirs
)));
10880 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10883 /* Add an entry to LH's file name table. */
10886 add_file_name (struct line_header
*lh
,
10888 unsigned int dir_index
,
10889 unsigned int mod_time
,
10890 unsigned int length
)
10892 struct file_entry
*fe
;
10894 /* Grow the array if necessary. */
10895 if (lh
->file_names_size
== 0)
10897 lh
->file_names_size
= 1; /* for testing */
10898 lh
->file_names
= xmalloc (lh
->file_names_size
10899 * sizeof (*lh
->file_names
));
10901 else if (lh
->num_file_names
>= lh
->file_names_size
)
10903 lh
->file_names_size
*= 2;
10904 lh
->file_names
= xrealloc (lh
->file_names
,
10905 (lh
->file_names_size
10906 * sizeof (*lh
->file_names
)));
10909 fe
= &lh
->file_names
[lh
->num_file_names
++];
10911 fe
->dir_index
= dir_index
;
10912 fe
->mod_time
= mod_time
;
10913 fe
->length
= length
;
10914 fe
->included_p
= 0;
10918 /* Read the statement program header starting at OFFSET in
10919 .debug_line, according to the endianness of ABFD. Return a pointer
10920 to a struct line_header, allocated using xmalloc.
10922 NOTE: the strings in the include directory and file name tables of
10923 the returned object point into debug_line_buffer, and must not be
10926 static struct line_header
*
10927 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10928 struct dwarf2_cu
*cu
)
10930 struct cleanup
*back_to
;
10931 struct line_header
*lh
;
10932 gdb_byte
*line_ptr
;
10933 unsigned int bytes_read
, offset_size
;
10935 char *cur_dir
, *cur_file
;
10937 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10938 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10940 complaint (&symfile_complaints
, _("missing .debug_line section"));
10944 /* Make sure that at least there's room for the total_length field.
10945 That could be 12 bytes long, but we're just going to fudge that. */
10946 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10948 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10952 lh
= xmalloc (sizeof (*lh
));
10953 memset (lh
, 0, sizeof (*lh
));
10954 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10957 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10959 /* Read in the header. */
10961 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10962 &bytes_read
, &offset_size
);
10963 line_ptr
+= bytes_read
;
10964 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10965 + dwarf2_per_objfile
->line
.size
))
10967 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10970 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10971 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10973 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10974 line_ptr
+= offset_size
;
10975 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10977 if (lh
->version
>= 4)
10979 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10983 lh
->maximum_ops_per_instruction
= 1;
10985 if (lh
->maximum_ops_per_instruction
== 0)
10987 lh
->maximum_ops_per_instruction
= 1;
10988 complaint (&symfile_complaints
,
10989 _("invalid maximum_ops_per_instruction "
10990 "in `.debug_line' section"));
10993 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10995 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10997 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10999 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
11001 lh
->standard_opcode_lengths
11002 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
11004 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
11005 for (i
= 1; i
< lh
->opcode_base
; ++i
)
11007 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
11011 /* Read directory table. */
11012 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11014 line_ptr
+= bytes_read
;
11015 add_include_dir (lh
, cur_dir
);
11017 line_ptr
+= bytes_read
;
11019 /* Read file name table. */
11020 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11022 unsigned int dir_index
, mod_time
, length
;
11024 line_ptr
+= bytes_read
;
11025 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11026 line_ptr
+= bytes_read
;
11027 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11028 line_ptr
+= bytes_read
;
11029 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11030 line_ptr
+= bytes_read
;
11032 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11034 line_ptr
+= bytes_read
;
11035 lh
->statement_program_start
= line_ptr
;
11037 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
11038 + dwarf2_per_objfile
->line
.size
))
11039 complaint (&symfile_complaints
,
11040 _("line number info header doesn't "
11041 "fit in `.debug_line' section"));
11043 discard_cleanups (back_to
);
11047 /* Subroutine of dwarf_decode_lines to simplify it.
11048 Return the file name of the psymtab for included file FILE_INDEX
11049 in line header LH of PST.
11050 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11051 If space for the result is malloc'd, it will be freed by a cleanup.
11052 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
11055 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
11056 const struct partial_symtab
*pst
,
11057 const char *comp_dir
)
11059 const struct file_entry fe
= lh
->file_names
[file_index
];
11060 char *include_name
= fe
.name
;
11061 char *include_name_to_compare
= include_name
;
11062 char *dir_name
= NULL
;
11063 const char *pst_filename
;
11064 char *copied_name
= NULL
;
11068 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
11070 if (!IS_ABSOLUTE_PATH (include_name
)
11071 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
11073 /* Avoid creating a duplicate psymtab for PST.
11074 We do this by comparing INCLUDE_NAME and PST_FILENAME.
11075 Before we do the comparison, however, we need to account
11076 for DIR_NAME and COMP_DIR.
11077 First prepend dir_name (if non-NULL). If we still don't
11078 have an absolute path prepend comp_dir (if non-NULL).
11079 However, the directory we record in the include-file's
11080 psymtab does not contain COMP_DIR (to match the
11081 corresponding symtab(s)).
11086 bash$ gcc -g ./hello.c
11087 include_name = "hello.c"
11089 DW_AT_comp_dir = comp_dir = "/tmp"
11090 DW_AT_name = "./hello.c" */
11092 if (dir_name
!= NULL
)
11094 include_name
= concat (dir_name
, SLASH_STRING
,
11095 include_name
, (char *)NULL
);
11096 include_name_to_compare
= include_name
;
11097 make_cleanup (xfree
, include_name
);
11099 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
11101 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
11102 include_name
, (char *)NULL
);
11106 pst_filename
= pst
->filename
;
11107 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
11109 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
11110 pst_filename
, (char *)NULL
);
11111 pst_filename
= copied_name
;
11114 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
11116 if (include_name_to_compare
!= include_name
)
11117 xfree (include_name_to_compare
);
11118 if (copied_name
!= NULL
)
11119 xfree (copied_name
);
11123 return include_name
;
11126 /* Ignore this record_line request. */
11129 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11134 /* Decode the Line Number Program (LNP) for the given line_header
11135 structure and CU. The actual information extracted and the type
11136 of structures created from the LNP depends on the value of PST.
11138 1. If PST is NULL, then this procedure uses the data from the program
11139 to create all necessary symbol tables, and their linetables.
11141 2. If PST is not NULL, this procedure reads the program to determine
11142 the list of files included by the unit represented by PST, and
11143 builds all the associated partial symbol tables.
11145 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11146 It is used for relative paths in the line table.
11147 NOTE: When processing partial symtabs (pst != NULL),
11148 comp_dir == pst->dirname.
11150 NOTE: It is important that psymtabs have the same file name (via strcmp)
11151 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11152 symtab we don't use it in the name of the psymtabs we create.
11153 E.g. expand_line_sal requires this when finding psymtabs to expand.
11154 A good testcase for this is mb-inline.exp. */
11157 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
11158 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
11160 gdb_byte
*line_ptr
, *extended_end
;
11161 gdb_byte
*line_end
;
11162 unsigned int bytes_read
, extended_len
;
11163 unsigned char op_code
, extended_op
, adj_opcode
;
11164 CORE_ADDR baseaddr
;
11165 struct objfile
*objfile
= cu
->objfile
;
11166 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11167 const int decode_for_pst_p
= (pst
!= NULL
);
11168 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
11169 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11172 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11174 line_ptr
= lh
->statement_program_start
;
11175 line_end
= lh
->statement_program_end
;
11177 /* Read the statement sequences until there's nothing left. */
11178 while (line_ptr
< line_end
)
11180 /* state machine registers */
11181 CORE_ADDR address
= 0;
11182 unsigned int file
= 1;
11183 unsigned int line
= 1;
11184 unsigned int column
= 0;
11185 int is_stmt
= lh
->default_is_stmt
;
11186 int basic_block
= 0;
11187 int end_sequence
= 0;
11189 unsigned char op_index
= 0;
11191 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
11193 /* Start a subfile for the current file of the state machine. */
11194 /* lh->include_dirs and lh->file_names are 0-based, but the
11195 directory and file name numbers in the statement program
11197 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11201 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11203 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11206 /* Decode the table. */
11207 while (!end_sequence
)
11209 op_code
= read_1_byte (abfd
, line_ptr
);
11211 if (line_ptr
> line_end
)
11213 dwarf2_debug_line_missing_end_sequence_complaint ();
11217 if (op_code
>= lh
->opcode_base
)
11219 /* Special operand. */
11220 adj_opcode
= op_code
- lh
->opcode_base
;
11221 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
11222 / lh
->maximum_ops_per_instruction
)
11223 * lh
->minimum_instruction_length
);
11224 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
11225 % lh
->maximum_ops_per_instruction
);
11226 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
11227 if (lh
->num_file_names
< file
|| file
== 0)
11228 dwarf2_debug_line_missing_file_complaint ();
11229 /* For now we ignore lines not starting on an
11230 instruction boundary. */
11231 else if (op_index
== 0)
11233 lh
->file_names
[file
- 1].included_p
= 1;
11234 if (!decode_for_pst_p
&& is_stmt
)
11236 if (last_subfile
!= current_subfile
)
11238 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11240 (*p_record_line
) (last_subfile
, 0, addr
);
11241 last_subfile
= current_subfile
;
11243 /* Append row to matrix using current values. */
11244 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11245 (*p_record_line
) (current_subfile
, line
, addr
);
11250 else switch (op_code
)
11252 case DW_LNS_extended_op
:
11253 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
11255 line_ptr
+= bytes_read
;
11256 extended_end
= line_ptr
+ extended_len
;
11257 extended_op
= read_1_byte (abfd
, line_ptr
);
11259 switch (extended_op
)
11261 case DW_LNE_end_sequence
:
11262 p_record_line
= record_line
;
11265 case DW_LNE_set_address
:
11266 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
11268 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11270 /* This line table is for a function which has been
11271 GCd by the linker. Ignore it. PR gdb/12528 */
11274 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
11276 complaint (&symfile_complaints
,
11277 _(".debug_line address at offset 0x%lx is 0 "
11279 line_offset
, objfile
->name
);
11280 p_record_line
= noop_record_line
;
11284 line_ptr
+= bytes_read
;
11285 address
+= baseaddr
;
11287 case DW_LNE_define_file
:
11290 unsigned int dir_index
, mod_time
, length
;
11292 cur_file
= read_direct_string (abfd
, line_ptr
,
11294 line_ptr
+= bytes_read
;
11296 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11297 line_ptr
+= bytes_read
;
11299 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11300 line_ptr
+= bytes_read
;
11302 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11303 line_ptr
+= bytes_read
;
11304 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11307 case DW_LNE_set_discriminator
:
11308 /* The discriminator is not interesting to the debugger;
11310 line_ptr
= extended_end
;
11313 complaint (&symfile_complaints
,
11314 _("mangled .debug_line section"));
11317 /* Make sure that we parsed the extended op correctly. If e.g.
11318 we expected a different address size than the producer used,
11319 we may have read the wrong number of bytes. */
11320 if (line_ptr
!= extended_end
)
11322 complaint (&symfile_complaints
,
11323 _("mangled .debug_line section"));
11328 if (lh
->num_file_names
< file
|| file
== 0)
11329 dwarf2_debug_line_missing_file_complaint ();
11332 lh
->file_names
[file
- 1].included_p
= 1;
11333 if (!decode_for_pst_p
&& is_stmt
)
11335 if (last_subfile
!= current_subfile
)
11337 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11339 (*p_record_line
) (last_subfile
, 0, addr
);
11340 last_subfile
= current_subfile
;
11342 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11343 (*p_record_line
) (current_subfile
, line
, addr
);
11348 case DW_LNS_advance_pc
:
11351 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11353 address
+= (((op_index
+ adjust
)
11354 / lh
->maximum_ops_per_instruction
)
11355 * lh
->minimum_instruction_length
);
11356 op_index
= ((op_index
+ adjust
)
11357 % lh
->maximum_ops_per_instruction
);
11358 line_ptr
+= bytes_read
;
11361 case DW_LNS_advance_line
:
11362 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11363 line_ptr
+= bytes_read
;
11365 case DW_LNS_set_file
:
11367 /* The arrays lh->include_dirs and lh->file_names are
11368 0-based, but the directory and file name numbers in
11369 the statement program are 1-based. */
11370 struct file_entry
*fe
;
11373 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11374 line_ptr
+= bytes_read
;
11375 if (lh
->num_file_names
< file
|| file
== 0)
11376 dwarf2_debug_line_missing_file_complaint ();
11379 fe
= &lh
->file_names
[file
- 1];
11381 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11382 if (!decode_for_pst_p
)
11384 last_subfile
= current_subfile
;
11385 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11390 case DW_LNS_set_column
:
11391 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11392 line_ptr
+= bytes_read
;
11394 case DW_LNS_negate_stmt
:
11395 is_stmt
= (!is_stmt
);
11397 case DW_LNS_set_basic_block
:
11400 /* Add to the address register of the state machine the
11401 address increment value corresponding to special opcode
11402 255. I.e., this value is scaled by the minimum
11403 instruction length since special opcode 255 would have
11404 scaled the increment. */
11405 case DW_LNS_const_add_pc
:
11407 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11409 address
+= (((op_index
+ adjust
)
11410 / lh
->maximum_ops_per_instruction
)
11411 * lh
->minimum_instruction_length
);
11412 op_index
= ((op_index
+ adjust
)
11413 % lh
->maximum_ops_per_instruction
);
11416 case DW_LNS_fixed_advance_pc
:
11417 address
+= read_2_bytes (abfd
, line_ptr
);
11423 /* Unknown standard opcode, ignore it. */
11426 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11428 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11429 line_ptr
+= bytes_read
;
11434 if (lh
->num_file_names
< file
|| file
== 0)
11435 dwarf2_debug_line_missing_file_complaint ();
11438 lh
->file_names
[file
- 1].included_p
= 1;
11439 if (!decode_for_pst_p
)
11441 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11442 (*p_record_line
) (current_subfile
, 0, addr
);
11447 if (decode_for_pst_p
)
11451 /* Now that we're done scanning the Line Header Program, we can
11452 create the psymtab of each included file. */
11453 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11454 if (lh
->file_names
[file_index
].included_p
== 1)
11456 char *include_name
=
11457 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11458 if (include_name
!= NULL
)
11459 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11464 /* Make sure a symtab is created for every file, even files
11465 which contain only variables (i.e. no code with associated
11469 struct file_entry
*fe
;
11471 for (i
= 0; i
< lh
->num_file_names
; i
++)
11475 fe
= &lh
->file_names
[i
];
11477 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11478 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11480 /* Skip the main file; we don't need it, and it must be
11481 allocated last, so that it will show up before the
11482 non-primary symtabs in the objfile's symtab list. */
11483 if (current_subfile
== first_subfile
)
11486 if (current_subfile
->symtab
== NULL
)
11487 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11489 fe
->symtab
= current_subfile
->symtab
;
11494 /* Start a subfile for DWARF. FILENAME is the name of the file and
11495 DIRNAME the name of the source directory which contains FILENAME
11496 or NULL if not known. COMP_DIR is the compilation directory for the
11497 linetable's compilation unit or NULL if not known.
11498 This routine tries to keep line numbers from identical absolute and
11499 relative file names in a common subfile.
11501 Using the `list' example from the GDB testsuite, which resides in
11502 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11503 of /srcdir/list0.c yields the following debugging information for list0.c:
11505 DW_AT_name: /srcdir/list0.c
11506 DW_AT_comp_dir: /compdir
11507 files.files[0].name: list0.h
11508 files.files[0].dir: /srcdir
11509 files.files[1].name: list0.c
11510 files.files[1].dir: /srcdir
11512 The line number information for list0.c has to end up in a single
11513 subfile, so that `break /srcdir/list0.c:1' works as expected.
11514 start_subfile will ensure that this happens provided that we pass the
11515 concatenation of files.files[1].dir and files.files[1].name as the
11519 dwarf2_start_subfile (char *filename
, const char *dirname
,
11520 const char *comp_dir
)
11524 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11525 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11526 second argument to start_subfile. To be consistent, we do the
11527 same here. In order not to lose the line information directory,
11528 we concatenate it to the filename when it makes sense.
11529 Note that the Dwarf3 standard says (speaking of filenames in line
11530 information): ``The directory index is ignored for file names
11531 that represent full path names''. Thus ignoring dirname in the
11532 `else' branch below isn't an issue. */
11534 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11535 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11537 fullname
= filename
;
11539 start_subfile (fullname
, comp_dir
);
11541 if (fullname
!= filename
)
11546 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11547 struct dwarf2_cu
*cu
)
11549 struct objfile
*objfile
= cu
->objfile
;
11550 struct comp_unit_head
*cu_header
= &cu
->header
;
11552 /* NOTE drow/2003-01-30: There used to be a comment and some special
11553 code here to turn a symbol with DW_AT_external and a
11554 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11555 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11556 with some versions of binutils) where shared libraries could have
11557 relocations against symbols in their debug information - the
11558 minimal symbol would have the right address, but the debug info
11559 would not. It's no longer necessary, because we will explicitly
11560 apply relocations when we read in the debug information now. */
11562 /* A DW_AT_location attribute with no contents indicates that a
11563 variable has been optimized away. */
11564 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11566 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11570 /* Handle one degenerate form of location expression specially, to
11571 preserve GDB's previous behavior when section offsets are
11572 specified. If this is just a DW_OP_addr then mark this symbol
11575 if (attr_form_is_block (attr
)
11576 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11577 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11579 unsigned int dummy
;
11581 SYMBOL_VALUE_ADDRESS (sym
) =
11582 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11583 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11584 fixup_symbol_section (sym
, objfile
);
11585 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11586 SYMBOL_SECTION (sym
));
11590 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11591 expression evaluator, and use LOC_COMPUTED only when necessary
11592 (i.e. when the value of a register or memory location is
11593 referenced, or a thread-local block, etc.). Then again, it might
11594 not be worthwhile. I'm assuming that it isn't unless performance
11595 or memory numbers show me otherwise. */
11597 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11598 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11600 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11601 cu
->has_loclist
= 1;
11604 /* Given a pointer to a DWARF information entry, figure out if we need
11605 to make a symbol table entry for it, and if so, create a new entry
11606 and return a pointer to it.
11607 If TYPE is NULL, determine symbol type from the die, otherwise
11608 used the passed type.
11609 If SPACE is not NULL, use it to hold the new symbol. If it is
11610 NULL, allocate a new symbol on the objfile's obstack. */
11612 static struct symbol
*
11613 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11614 struct symbol
*space
)
11616 struct objfile
*objfile
= cu
->objfile
;
11617 struct symbol
*sym
= NULL
;
11619 struct attribute
*attr
= NULL
;
11620 struct attribute
*attr2
= NULL
;
11621 CORE_ADDR baseaddr
;
11622 struct pending
**list_to_add
= NULL
;
11624 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11626 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11628 name
= dwarf2_name (die
, cu
);
11631 const char *linkagename
;
11632 int suppress_add
= 0;
11637 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11638 OBJSTAT (objfile
, n_syms
++);
11640 /* Cache this symbol's name and the name's demangled form (if any). */
11641 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11642 linkagename
= dwarf2_physname (name
, die
, cu
);
11643 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11645 /* Fortran does not have mangling standard and the mangling does differ
11646 between gfortran, iFort etc. */
11647 if (cu
->language
== language_fortran
11648 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11649 symbol_set_demangled_name (&(sym
->ginfo
),
11650 (char *) dwarf2_full_name (name
, die
, cu
),
11653 /* Default assumptions.
11654 Use the passed type or decode it from the die. */
11655 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11656 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11658 SYMBOL_TYPE (sym
) = type
;
11660 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11661 attr
= dwarf2_attr (die
,
11662 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11666 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11669 attr
= dwarf2_attr (die
,
11670 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11674 int file_index
= DW_UNSND (attr
);
11676 if (cu
->line_header
== NULL
11677 || file_index
> cu
->line_header
->num_file_names
)
11678 complaint (&symfile_complaints
,
11679 _("file index out of range"));
11680 else if (file_index
> 0)
11682 struct file_entry
*fe
;
11684 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11685 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11692 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11695 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11697 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11698 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11699 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11700 add_symbol_to_list (sym
, cu
->list_in_scope
);
11702 case DW_TAG_subprogram
:
11703 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11705 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11706 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11707 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11708 || cu
->language
== language_ada
)
11710 /* Subprograms marked external are stored as a global symbol.
11711 Ada subprograms, whether marked external or not, are always
11712 stored as a global symbol, because we want to be able to
11713 access them globally. For instance, we want to be able
11714 to break on a nested subprogram without having to
11715 specify the context. */
11716 list_to_add
= &global_symbols
;
11720 list_to_add
= cu
->list_in_scope
;
11723 case DW_TAG_inlined_subroutine
:
11724 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11726 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11727 SYMBOL_INLINED (sym
) = 1;
11728 /* Do not add the symbol to any lists. It will be found via
11729 BLOCK_FUNCTION from the blockvector. */
11731 case DW_TAG_template_value_param
:
11733 /* Fall through. */
11734 case DW_TAG_constant
:
11735 case DW_TAG_variable
:
11736 case DW_TAG_member
:
11737 /* Compilation with minimal debug info may result in
11738 variables with missing type entries. Change the
11739 misleading `void' type to something sensible. */
11740 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11742 = objfile_type (objfile
)->nodebug_data_symbol
;
11744 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11745 /* In the case of DW_TAG_member, we should only be called for
11746 static const members. */
11747 if (die
->tag
== DW_TAG_member
)
11749 /* dwarf2_add_field uses die_is_declaration,
11750 so we do the same. */
11751 gdb_assert (die_is_declaration (die
, cu
));
11756 dwarf2_const_value (attr
, sym
, cu
);
11757 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11760 if (attr2
&& (DW_UNSND (attr2
) != 0))
11761 list_to_add
= &global_symbols
;
11763 list_to_add
= cu
->list_in_scope
;
11767 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11770 var_decode_location (attr
, sym
, cu
);
11771 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11772 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11773 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11774 && !dwarf2_per_objfile
->has_section_at_zero
)
11776 /* When a static variable is eliminated by the linker,
11777 the corresponding debug information is not stripped
11778 out, but the variable address is set to null;
11779 do not add such variables into symbol table. */
11781 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11783 /* Workaround gfortran PR debug/40040 - it uses
11784 DW_AT_location for variables in -fPIC libraries which may
11785 get overriden by other libraries/executable and get
11786 a different address. Resolve it by the minimal symbol
11787 which may come from inferior's executable using copy
11788 relocation. Make this workaround only for gfortran as for
11789 other compilers GDB cannot guess the minimal symbol
11790 Fortran mangling kind. */
11791 if (cu
->language
== language_fortran
&& die
->parent
11792 && die
->parent
->tag
== DW_TAG_module
11794 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11795 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11797 /* A variable with DW_AT_external is never static,
11798 but it may be block-scoped. */
11799 list_to_add
= (cu
->list_in_scope
== &file_symbols
11800 ? &global_symbols
: cu
->list_in_scope
);
11803 list_to_add
= cu
->list_in_scope
;
11807 /* We do not know the address of this symbol.
11808 If it is an external symbol and we have type information
11809 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11810 The address of the variable will then be determined from
11811 the minimal symbol table whenever the variable is
11813 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11814 if (attr2
&& (DW_UNSND (attr2
) != 0)
11815 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11817 /* A variable with DW_AT_external is never static, but it
11818 may be block-scoped. */
11819 list_to_add
= (cu
->list_in_scope
== &file_symbols
11820 ? &global_symbols
: cu
->list_in_scope
);
11822 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11824 else if (!die_is_declaration (die
, cu
))
11826 /* Use the default LOC_OPTIMIZED_OUT class. */
11827 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11829 list_to_add
= cu
->list_in_scope
;
11833 case DW_TAG_formal_parameter
:
11834 /* If we are inside a function, mark this as an argument. If
11835 not, we might be looking at an argument to an inlined function
11836 when we do not have enough information to show inlined frames;
11837 pretend it's a local variable in that case so that the user can
11839 if (context_stack_depth
> 0
11840 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11841 SYMBOL_IS_ARGUMENT (sym
) = 1;
11842 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11845 var_decode_location (attr
, sym
, cu
);
11847 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11850 dwarf2_const_value (attr
, sym
, cu
);
11853 list_to_add
= cu
->list_in_scope
;
11855 case DW_TAG_unspecified_parameters
:
11856 /* From varargs functions; gdb doesn't seem to have any
11857 interest in this information, so just ignore it for now.
11860 case DW_TAG_template_type_param
:
11862 /* Fall through. */
11863 case DW_TAG_class_type
:
11864 case DW_TAG_interface_type
:
11865 case DW_TAG_structure_type
:
11866 case DW_TAG_union_type
:
11867 case DW_TAG_set_type
:
11868 case DW_TAG_enumeration_type
:
11869 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11870 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11873 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11874 really ever be static objects: otherwise, if you try
11875 to, say, break of a class's method and you're in a file
11876 which doesn't mention that class, it won't work unless
11877 the check for all static symbols in lookup_symbol_aux
11878 saves you. See the OtherFileClass tests in
11879 gdb.c++/namespace.exp. */
11883 list_to_add
= (cu
->list_in_scope
== &file_symbols
11884 && (cu
->language
== language_cplus
11885 || cu
->language
== language_java
)
11886 ? &global_symbols
: cu
->list_in_scope
);
11888 /* The semantics of C++ state that "struct foo {
11889 ... }" also defines a typedef for "foo". A Java
11890 class declaration also defines a typedef for the
11892 if (cu
->language
== language_cplus
11893 || cu
->language
== language_java
11894 || cu
->language
== language_ada
)
11896 /* The symbol's name is already allocated along
11897 with this objfile, so we don't need to
11898 duplicate it for the type. */
11899 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11900 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11905 case DW_TAG_typedef
:
11906 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11907 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11908 list_to_add
= cu
->list_in_scope
;
11910 case DW_TAG_base_type
:
11911 case DW_TAG_subrange_type
:
11912 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11913 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11914 list_to_add
= cu
->list_in_scope
;
11916 case DW_TAG_enumerator
:
11917 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11920 dwarf2_const_value (attr
, sym
, cu
);
11923 /* NOTE: carlton/2003-11-10: See comment above in the
11924 DW_TAG_class_type, etc. block. */
11926 list_to_add
= (cu
->list_in_scope
== &file_symbols
11927 && (cu
->language
== language_cplus
11928 || cu
->language
== language_java
)
11929 ? &global_symbols
: cu
->list_in_scope
);
11932 case DW_TAG_namespace
:
11933 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11934 list_to_add
= &global_symbols
;
11937 /* Not a tag we recognize. Hopefully we aren't processing
11938 trash data, but since we must specifically ignore things
11939 we don't recognize, there is nothing else we should do at
11941 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11942 dwarf_tag_name (die
->tag
));
11948 sym
->hash_next
= objfile
->template_symbols
;
11949 objfile
->template_symbols
= sym
;
11950 list_to_add
= NULL
;
11953 if (list_to_add
!= NULL
)
11954 add_symbol_to_list (sym
, list_to_add
);
11956 /* For the benefit of old versions of GCC, check for anonymous
11957 namespaces based on the demangled name. */
11958 if (!processing_has_namespace_info
11959 && cu
->language
== language_cplus
)
11960 cp_scan_for_anonymous_namespaces (sym
, objfile
);
11965 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11967 static struct symbol
*
11968 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11970 return new_symbol_full (die
, type
, cu
, NULL
);
11973 /* Given an attr with a DW_FORM_dataN value in host byte order,
11974 zero-extend it as appropriate for the symbol's type. The DWARF
11975 standard (v4) is not entirely clear about the meaning of using
11976 DW_FORM_dataN for a constant with a signed type, where the type is
11977 wider than the data. The conclusion of a discussion on the DWARF
11978 list was that this is unspecified. We choose to always zero-extend
11979 because that is the interpretation long in use by GCC. */
11982 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11983 const char *name
, struct obstack
*obstack
,
11984 struct dwarf2_cu
*cu
, long *value
, int bits
)
11986 struct objfile
*objfile
= cu
->objfile
;
11987 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11988 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11989 LONGEST l
= DW_UNSND (attr
);
11991 if (bits
< sizeof (*value
) * 8)
11993 l
&= ((LONGEST
) 1 << bits
) - 1;
11996 else if (bits
== sizeof (*value
) * 8)
12000 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
12001 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
12008 /* Read a constant value from an attribute. Either set *VALUE, or if
12009 the value does not fit in *VALUE, set *BYTES - either already
12010 allocated on the objfile obstack, or newly allocated on OBSTACK,
12011 or, set *BATON, if we translated the constant to a location
12015 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
12016 const char *name
, struct obstack
*obstack
,
12017 struct dwarf2_cu
*cu
,
12018 long *value
, gdb_byte
**bytes
,
12019 struct dwarf2_locexpr_baton
**baton
)
12021 struct objfile
*objfile
= cu
->objfile
;
12022 struct comp_unit_head
*cu_header
= &cu
->header
;
12023 struct dwarf_block
*blk
;
12024 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
12025 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
12031 switch (attr
->form
)
12037 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
12038 dwarf2_const_value_length_mismatch_complaint (name
,
12039 cu_header
->addr_size
,
12040 TYPE_LENGTH (type
));
12041 /* Symbols of this form are reasonably rare, so we just
12042 piggyback on the existing location code rather than writing
12043 a new implementation of symbol_computed_ops. */
12044 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
12045 sizeof (struct dwarf2_locexpr_baton
));
12046 (*baton
)->per_cu
= cu
->per_cu
;
12047 gdb_assert ((*baton
)->per_cu
);
12049 (*baton
)->size
= 2 + cu_header
->addr_size
;
12050 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
12051 (*baton
)->data
= data
;
12053 data
[0] = DW_OP_addr
;
12054 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
12055 byte_order
, DW_ADDR (attr
));
12056 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
12059 case DW_FORM_string
:
12061 /* DW_STRING is already allocated on the objfile obstack, point
12063 *bytes
= (gdb_byte
*) DW_STRING (attr
);
12065 case DW_FORM_block1
:
12066 case DW_FORM_block2
:
12067 case DW_FORM_block4
:
12068 case DW_FORM_block
:
12069 case DW_FORM_exprloc
:
12070 blk
= DW_BLOCK (attr
);
12071 if (TYPE_LENGTH (type
) != blk
->size
)
12072 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
12073 TYPE_LENGTH (type
));
12074 *bytes
= blk
->data
;
12077 /* The DW_AT_const_value attributes are supposed to carry the
12078 symbol's value "represented as it would be on the target
12079 architecture." By the time we get here, it's already been
12080 converted to host endianness, so we just need to sign- or
12081 zero-extend it as appropriate. */
12082 case DW_FORM_data1
:
12083 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12084 obstack
, cu
, value
, 8);
12086 case DW_FORM_data2
:
12087 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12088 obstack
, cu
, value
, 16);
12090 case DW_FORM_data4
:
12091 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12092 obstack
, cu
, value
, 32);
12094 case DW_FORM_data8
:
12095 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12096 obstack
, cu
, value
, 64);
12099 case DW_FORM_sdata
:
12100 *value
= DW_SND (attr
);
12103 case DW_FORM_udata
:
12104 *value
= DW_UNSND (attr
);
12108 complaint (&symfile_complaints
,
12109 _("unsupported const value attribute form: '%s'"),
12110 dwarf_form_name (attr
->form
));
12117 /* Copy constant value from an attribute to a symbol. */
12120 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
12121 struct dwarf2_cu
*cu
)
12123 struct objfile
*objfile
= cu
->objfile
;
12124 struct comp_unit_head
*cu_header
= &cu
->header
;
12127 struct dwarf2_locexpr_baton
*baton
;
12129 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
12130 SYMBOL_PRINT_NAME (sym
),
12131 &objfile
->objfile_obstack
, cu
,
12132 &value
, &bytes
, &baton
);
12136 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
12137 SYMBOL_LOCATION_BATON (sym
) = baton
;
12138 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
12140 else if (bytes
!= NULL
)
12142 SYMBOL_VALUE_BYTES (sym
) = bytes
;
12143 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
12147 SYMBOL_VALUE (sym
) = value
;
12148 SYMBOL_CLASS (sym
) = LOC_CONST
;
12152 /* Return the type of the die in question using its DW_AT_type attribute. */
12154 static struct type
*
12155 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12157 struct attribute
*type_attr
;
12159 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
12162 /* A missing DW_AT_type represents a void type. */
12163 return objfile_type (cu
->objfile
)->builtin_void
;
12166 return lookup_die_type (die
, type_attr
, cu
);
12169 /* True iff CU's producer generates GNAT Ada auxiliary information
12170 that allows to find parallel types through that information instead
12171 of having to do expensive parallel lookups by type name. */
12174 need_gnat_info (struct dwarf2_cu
*cu
)
12176 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12177 of GNAT produces this auxiliary information, without any indication
12178 that it is produced. Part of enhancing the FSF version of GNAT
12179 to produce that information will be to put in place an indicator
12180 that we can use in order to determine whether the descriptive type
12181 info is available or not. One suggestion that has been made is
12182 to use a new attribute, attached to the CU die. For now, assume
12183 that the descriptive type info is not available. */
12187 /* Return the auxiliary type of the die in question using its
12188 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12189 attribute is not present. */
12191 static struct type
*
12192 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12194 struct attribute
*type_attr
;
12196 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
12200 return lookup_die_type (die
, type_attr
, cu
);
12203 /* If DIE has a descriptive_type attribute, then set the TYPE's
12204 descriptive type accordingly. */
12207 set_descriptive_type (struct type
*type
, struct die_info
*die
,
12208 struct dwarf2_cu
*cu
)
12210 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
12212 if (descriptive_type
)
12214 ALLOCATE_GNAT_AUX_TYPE (type
);
12215 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
12219 /* Return the containing type of the die in question using its
12220 DW_AT_containing_type attribute. */
12222 static struct type
*
12223 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12225 struct attribute
*type_attr
;
12227 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
12229 error (_("Dwarf Error: Problem turning containing type into gdb type "
12230 "[in module %s]"), cu
->objfile
->name
);
12232 return lookup_die_type (die
, type_attr
, cu
);
12235 /* Look up the type of DIE in CU using its type attribute ATTR.
12236 If there is no type substitute an error marker. */
12238 static struct type
*
12239 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
12240 struct dwarf2_cu
*cu
)
12242 struct objfile
*objfile
= cu
->objfile
;
12243 struct type
*this_type
;
12245 /* First see if we have it cached. */
12247 if (is_ref_attr (attr
))
12249 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
12251 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
12253 else if (attr
->form
== DW_FORM_ref_sig8
)
12255 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12256 struct dwarf2_cu
*sig_cu
;
12257 unsigned int offset
;
12259 /* sig_type will be NULL if the signatured type is missing from
12261 if (sig_type
== NULL
)
12262 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12263 "at 0x%x [in module %s]"),
12264 die
->offset
, objfile
->name
);
12266 gdb_assert (sig_type
->per_cu
.debug_types_section
);
12267 offset
= sig_type
->per_cu
.offset
+ sig_type
->type_offset
;
12268 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
12272 dump_die_for_error (die
);
12273 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12274 dwarf_attr_name (attr
->name
), objfile
->name
);
12277 /* If not cached we need to read it in. */
12279 if (this_type
== NULL
)
12281 struct die_info
*type_die
;
12282 struct dwarf2_cu
*type_cu
= cu
;
12284 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
12285 /* If the type is cached, we should have found it above. */
12286 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
12287 this_type
= read_type_die_1 (type_die
, type_cu
);
12290 /* If we still don't have a type use an error marker. */
12292 if (this_type
== NULL
)
12294 char *message
, *saved
;
12296 /* read_type_die already issued a complaint. */
12297 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12301 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
12302 message
, strlen (message
));
12305 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
12311 /* Return the type in DIE, CU.
12312 Returns NULL for invalid types.
12314 This first does a lookup in the appropriate type_hash table,
12315 and only reads the die in if necessary.
12317 NOTE: This can be called when reading in partial or full symbols. */
12319 static struct type
*
12320 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12322 struct type
*this_type
;
12324 this_type
= get_die_type (die
, cu
);
12328 return read_type_die_1 (die
, cu
);
12331 /* Read the type in DIE, CU.
12332 Returns NULL for invalid types. */
12334 static struct type
*
12335 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12337 struct type
*this_type
= NULL
;
12341 case DW_TAG_class_type
:
12342 case DW_TAG_interface_type
:
12343 case DW_TAG_structure_type
:
12344 case DW_TAG_union_type
:
12345 this_type
= read_structure_type (die
, cu
);
12347 case DW_TAG_enumeration_type
:
12348 this_type
= read_enumeration_type (die
, cu
);
12350 case DW_TAG_subprogram
:
12351 case DW_TAG_subroutine_type
:
12352 case DW_TAG_inlined_subroutine
:
12353 this_type
= read_subroutine_type (die
, cu
);
12355 case DW_TAG_array_type
:
12356 this_type
= read_array_type (die
, cu
);
12358 case DW_TAG_set_type
:
12359 this_type
= read_set_type (die
, cu
);
12361 case DW_TAG_pointer_type
:
12362 this_type
= read_tag_pointer_type (die
, cu
);
12364 case DW_TAG_ptr_to_member_type
:
12365 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12367 case DW_TAG_reference_type
:
12368 this_type
= read_tag_reference_type (die
, cu
);
12370 case DW_TAG_const_type
:
12371 this_type
= read_tag_const_type (die
, cu
);
12373 case DW_TAG_volatile_type
:
12374 this_type
= read_tag_volatile_type (die
, cu
);
12376 case DW_TAG_string_type
:
12377 this_type
= read_tag_string_type (die
, cu
);
12379 case DW_TAG_typedef
:
12380 this_type
= read_typedef (die
, cu
);
12382 case DW_TAG_subrange_type
:
12383 this_type
= read_subrange_type (die
, cu
);
12385 case DW_TAG_base_type
:
12386 this_type
= read_base_type (die
, cu
);
12388 case DW_TAG_unspecified_type
:
12389 this_type
= read_unspecified_type (die
, cu
);
12391 case DW_TAG_namespace
:
12392 this_type
= read_namespace_type (die
, cu
);
12394 case DW_TAG_module
:
12395 this_type
= read_module_type (die
, cu
);
12398 complaint (&symfile_complaints
,
12399 _("unexpected tag in read_type_die: '%s'"),
12400 dwarf_tag_name (die
->tag
));
12407 /* See if we can figure out if the class lives in a namespace. We do
12408 this by looking for a member function; its demangled name will
12409 contain namespace info, if there is any.
12410 Return the computed name or NULL.
12411 Space for the result is allocated on the objfile's obstack.
12412 This is the full-die version of guess_partial_die_structure_name.
12413 In this case we know DIE has no useful parent. */
12416 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12418 struct die_info
*spec_die
;
12419 struct dwarf2_cu
*spec_cu
;
12420 struct die_info
*child
;
12423 spec_die
= die_specification (die
, &spec_cu
);
12424 if (spec_die
!= NULL
)
12430 for (child
= die
->child
;
12432 child
= child
->sibling
)
12434 if (child
->tag
== DW_TAG_subprogram
)
12436 struct attribute
*attr
;
12438 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12440 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12444 = language_class_name_from_physname (cu
->language_defn
,
12448 if (actual_name
!= NULL
)
12450 char *die_name
= dwarf2_name (die
, cu
);
12452 if (die_name
!= NULL
12453 && strcmp (die_name
, actual_name
) != 0)
12455 /* Strip off the class name from the full name.
12456 We want the prefix. */
12457 int die_name_len
= strlen (die_name
);
12458 int actual_name_len
= strlen (actual_name
);
12460 /* Test for '::' as a sanity check. */
12461 if (actual_name_len
> die_name_len
+ 2
12462 && actual_name
[actual_name_len
12463 - die_name_len
- 1] == ':')
12465 obsavestring (actual_name
,
12466 actual_name_len
- die_name_len
- 2,
12467 &cu
->objfile
->objfile_obstack
);
12470 xfree (actual_name
);
12479 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12480 prefix part in such case. See
12481 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12484 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12486 struct attribute
*attr
;
12489 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
12490 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
12493 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12494 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
12497 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12499 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12500 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12503 /* dwarf2_name had to be already called. */
12504 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
12506 /* Strip the base name, keep any leading namespaces/classes. */
12507 base
= strrchr (DW_STRING (attr
), ':');
12508 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
12511 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
12512 &cu
->objfile
->objfile_obstack
);
12515 /* Return the name of the namespace/class that DIE is defined within,
12516 or "" if we can't tell. The caller should not xfree the result.
12518 For example, if we're within the method foo() in the following
12528 then determine_prefix on foo's die will return "N::C". */
12531 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12533 struct die_info
*parent
, *spec_die
;
12534 struct dwarf2_cu
*spec_cu
;
12535 struct type
*parent_type
;
12538 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12539 && cu
->language
!= language_fortran
)
12542 retval
= anonymous_struct_prefix (die
, cu
);
12546 /* We have to be careful in the presence of DW_AT_specification.
12547 For example, with GCC 3.4, given the code
12551 // Definition of N::foo.
12555 then we'll have a tree of DIEs like this:
12557 1: DW_TAG_compile_unit
12558 2: DW_TAG_namespace // N
12559 3: DW_TAG_subprogram // declaration of N::foo
12560 4: DW_TAG_subprogram // definition of N::foo
12561 DW_AT_specification // refers to die #3
12563 Thus, when processing die #4, we have to pretend that we're in
12564 the context of its DW_AT_specification, namely the contex of die
12567 spec_die
= die_specification (die
, &spec_cu
);
12568 if (spec_die
== NULL
)
12569 parent
= die
->parent
;
12572 parent
= spec_die
->parent
;
12576 if (parent
== NULL
)
12578 else if (parent
->building_fullname
)
12581 const char *parent_name
;
12583 /* It has been seen on RealView 2.2 built binaries,
12584 DW_TAG_template_type_param types actually _defined_ as
12585 children of the parent class:
12588 template class <class Enum> Class{};
12589 Class<enum E> class_e;
12591 1: DW_TAG_class_type (Class)
12592 2: DW_TAG_enumeration_type (E)
12593 3: DW_TAG_enumerator (enum1:0)
12594 3: DW_TAG_enumerator (enum2:1)
12596 2: DW_TAG_template_type_param
12597 DW_AT_type DW_FORM_ref_udata (E)
12599 Besides being broken debug info, it can put GDB into an
12600 infinite loop. Consider:
12602 When we're building the full name for Class<E>, we'll start
12603 at Class, and go look over its template type parameters,
12604 finding E. We'll then try to build the full name of E, and
12605 reach here. We're now trying to build the full name of E,
12606 and look over the parent DIE for containing scope. In the
12607 broken case, if we followed the parent DIE of E, we'd again
12608 find Class, and once again go look at its template type
12609 arguments, etc., etc. Simply don't consider such parent die
12610 as source-level parent of this die (it can't be, the language
12611 doesn't allow it), and break the loop here. */
12612 name
= dwarf2_name (die
, cu
);
12613 parent_name
= dwarf2_name (parent
, cu
);
12614 complaint (&symfile_complaints
,
12615 _("template param type '%s' defined within parent '%s'"),
12616 name
? name
: "<unknown>",
12617 parent_name
? parent_name
: "<unknown>");
12621 switch (parent
->tag
)
12623 case DW_TAG_namespace
:
12624 parent_type
= read_type_die (parent
, cu
);
12625 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12626 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12627 Work around this problem here. */
12628 if (cu
->language
== language_cplus
12629 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12631 /* We give a name to even anonymous namespaces. */
12632 return TYPE_TAG_NAME (parent_type
);
12633 case DW_TAG_class_type
:
12634 case DW_TAG_interface_type
:
12635 case DW_TAG_structure_type
:
12636 case DW_TAG_union_type
:
12637 case DW_TAG_module
:
12638 parent_type
= read_type_die (parent
, cu
);
12639 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12640 return TYPE_TAG_NAME (parent_type
);
12642 /* An anonymous structure is only allowed non-static data
12643 members; no typedefs, no member functions, et cetera.
12644 So it does not need a prefix. */
12646 case DW_TAG_compile_unit
:
12647 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12648 if (cu
->language
== language_cplus
12649 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12650 && die
->child
!= NULL
12651 && (die
->tag
== DW_TAG_class_type
12652 || die
->tag
== DW_TAG_structure_type
12653 || die
->tag
== DW_TAG_union_type
))
12655 char *name
= guess_full_die_structure_name (die
, cu
);
12661 return determine_prefix (parent
, cu
);
12665 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12666 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12667 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12668 an obconcat, otherwise allocate storage for the result. The CU argument is
12669 used to determine the language and hence, the appropriate separator. */
12671 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12674 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12675 int physname
, struct dwarf2_cu
*cu
)
12677 const char *lead
= "";
12680 if (suffix
== NULL
|| suffix
[0] == '\0'
12681 || prefix
== NULL
|| prefix
[0] == '\0')
12683 else if (cu
->language
== language_java
)
12685 else if (cu
->language
== language_fortran
&& physname
)
12687 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12688 DW_AT_MIPS_linkage_name is preferred and used instead. */
12696 if (prefix
== NULL
)
12698 if (suffix
== NULL
)
12704 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12706 strcpy (retval
, lead
);
12707 strcat (retval
, prefix
);
12708 strcat (retval
, sep
);
12709 strcat (retval
, suffix
);
12714 /* We have an obstack. */
12715 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12719 /* Return sibling of die, NULL if no sibling. */
12721 static struct die_info
*
12722 sibling_die (struct die_info
*die
)
12724 return die
->sibling
;
12727 /* Get name of a die, return NULL if not found. */
12730 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12731 struct obstack
*obstack
)
12733 if (name
&& cu
->language
== language_cplus
)
12735 char *canon_name
= cp_canonicalize_string (name
);
12737 if (canon_name
!= NULL
)
12739 if (strcmp (canon_name
, name
) != 0)
12740 name
= obsavestring (canon_name
, strlen (canon_name
),
12742 xfree (canon_name
);
12749 /* Get name of a die, return NULL if not found. */
12752 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12754 struct attribute
*attr
;
12756 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12757 if ((!attr
|| !DW_STRING (attr
))
12758 && die
->tag
!= DW_TAG_class_type
12759 && die
->tag
!= DW_TAG_interface_type
12760 && die
->tag
!= DW_TAG_structure_type
12761 && die
->tag
!= DW_TAG_union_type
)
12766 case DW_TAG_compile_unit
:
12767 /* Compilation units have a DW_AT_name that is a filename, not
12768 a source language identifier. */
12769 case DW_TAG_enumeration_type
:
12770 case DW_TAG_enumerator
:
12771 /* These tags always have simple identifiers already; no need
12772 to canonicalize them. */
12773 return DW_STRING (attr
);
12775 case DW_TAG_subprogram
:
12776 /* Java constructors will all be named "<init>", so return
12777 the class name when we see this special case. */
12778 if (cu
->language
== language_java
12779 && DW_STRING (attr
) != NULL
12780 && strcmp (DW_STRING (attr
), "<init>") == 0)
12782 struct dwarf2_cu
*spec_cu
= cu
;
12783 struct die_info
*spec_die
;
12785 /* GCJ will output '<init>' for Java constructor names.
12786 For this special case, return the name of the parent class. */
12788 /* GCJ may output suprogram DIEs with AT_specification set.
12789 If so, use the name of the specified DIE. */
12790 spec_die
= die_specification (die
, &spec_cu
);
12791 if (spec_die
!= NULL
)
12792 return dwarf2_name (spec_die
, spec_cu
);
12797 if (die
->tag
== DW_TAG_class_type
)
12798 return dwarf2_name (die
, cu
);
12800 while (die
->tag
!= DW_TAG_compile_unit
);
12804 case DW_TAG_class_type
:
12805 case DW_TAG_interface_type
:
12806 case DW_TAG_structure_type
:
12807 case DW_TAG_union_type
:
12808 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12809 structures or unions. These were of the form "._%d" in GCC 4.1,
12810 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12811 and GCC 4.4. We work around this problem by ignoring these. */
12812 if (attr
&& DW_STRING (attr
)
12813 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12814 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12817 /* GCC might emit a nameless typedef that has a linkage name. See
12818 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12819 if (!attr
|| DW_STRING (attr
) == NULL
)
12821 char *demangled
= NULL
;
12823 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12825 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12827 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12830 /* Avoid demangling DW_STRING (attr) the second time on a second
12831 call for the same DIE. */
12832 if (!DW_STRING_IS_CANONICAL (attr
))
12833 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12839 /* FIXME: we already did this for the partial symbol... */
12840 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
12841 &cu
->objfile
->objfile_obstack
);
12842 DW_STRING_IS_CANONICAL (attr
) = 1;
12845 /* Strip any leading namespaces/classes, keep only the base name.
12846 DW_AT_name for named DIEs does not contain the prefixes. */
12847 base
= strrchr (DW_STRING (attr
), ':');
12848 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
12851 return DW_STRING (attr
);
12860 if (!DW_STRING_IS_CANONICAL (attr
))
12863 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12864 &cu
->objfile
->objfile_obstack
);
12865 DW_STRING_IS_CANONICAL (attr
) = 1;
12867 return DW_STRING (attr
);
12870 /* Return the die that this die in an extension of, or NULL if there
12871 is none. *EXT_CU is the CU containing DIE on input, and the CU
12872 containing the return value on output. */
12874 static struct die_info
*
12875 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12877 struct attribute
*attr
;
12879 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12883 return follow_die_ref (die
, attr
, ext_cu
);
12886 /* Convert a DIE tag into its string name. */
12889 dwarf_tag_name (unsigned tag
)
12893 case DW_TAG_padding
:
12894 return "DW_TAG_padding";
12895 case DW_TAG_array_type
:
12896 return "DW_TAG_array_type";
12897 case DW_TAG_class_type
:
12898 return "DW_TAG_class_type";
12899 case DW_TAG_entry_point
:
12900 return "DW_TAG_entry_point";
12901 case DW_TAG_enumeration_type
:
12902 return "DW_TAG_enumeration_type";
12903 case DW_TAG_formal_parameter
:
12904 return "DW_TAG_formal_parameter";
12905 case DW_TAG_imported_declaration
:
12906 return "DW_TAG_imported_declaration";
12908 return "DW_TAG_label";
12909 case DW_TAG_lexical_block
:
12910 return "DW_TAG_lexical_block";
12911 case DW_TAG_member
:
12912 return "DW_TAG_member";
12913 case DW_TAG_pointer_type
:
12914 return "DW_TAG_pointer_type";
12915 case DW_TAG_reference_type
:
12916 return "DW_TAG_reference_type";
12917 case DW_TAG_compile_unit
:
12918 return "DW_TAG_compile_unit";
12919 case DW_TAG_string_type
:
12920 return "DW_TAG_string_type";
12921 case DW_TAG_structure_type
:
12922 return "DW_TAG_structure_type";
12923 case DW_TAG_subroutine_type
:
12924 return "DW_TAG_subroutine_type";
12925 case DW_TAG_typedef
:
12926 return "DW_TAG_typedef";
12927 case DW_TAG_union_type
:
12928 return "DW_TAG_union_type";
12929 case DW_TAG_unspecified_parameters
:
12930 return "DW_TAG_unspecified_parameters";
12931 case DW_TAG_variant
:
12932 return "DW_TAG_variant";
12933 case DW_TAG_common_block
:
12934 return "DW_TAG_common_block";
12935 case DW_TAG_common_inclusion
:
12936 return "DW_TAG_common_inclusion";
12937 case DW_TAG_inheritance
:
12938 return "DW_TAG_inheritance";
12939 case DW_TAG_inlined_subroutine
:
12940 return "DW_TAG_inlined_subroutine";
12941 case DW_TAG_module
:
12942 return "DW_TAG_module";
12943 case DW_TAG_ptr_to_member_type
:
12944 return "DW_TAG_ptr_to_member_type";
12945 case DW_TAG_set_type
:
12946 return "DW_TAG_set_type";
12947 case DW_TAG_subrange_type
:
12948 return "DW_TAG_subrange_type";
12949 case DW_TAG_with_stmt
:
12950 return "DW_TAG_with_stmt";
12951 case DW_TAG_access_declaration
:
12952 return "DW_TAG_access_declaration";
12953 case DW_TAG_base_type
:
12954 return "DW_TAG_base_type";
12955 case DW_TAG_catch_block
:
12956 return "DW_TAG_catch_block";
12957 case DW_TAG_const_type
:
12958 return "DW_TAG_const_type";
12959 case DW_TAG_constant
:
12960 return "DW_TAG_constant";
12961 case DW_TAG_enumerator
:
12962 return "DW_TAG_enumerator";
12963 case DW_TAG_file_type
:
12964 return "DW_TAG_file_type";
12965 case DW_TAG_friend
:
12966 return "DW_TAG_friend";
12967 case DW_TAG_namelist
:
12968 return "DW_TAG_namelist";
12969 case DW_TAG_namelist_item
:
12970 return "DW_TAG_namelist_item";
12971 case DW_TAG_packed_type
:
12972 return "DW_TAG_packed_type";
12973 case DW_TAG_subprogram
:
12974 return "DW_TAG_subprogram";
12975 case DW_TAG_template_type_param
:
12976 return "DW_TAG_template_type_param";
12977 case DW_TAG_template_value_param
:
12978 return "DW_TAG_template_value_param";
12979 case DW_TAG_thrown_type
:
12980 return "DW_TAG_thrown_type";
12981 case DW_TAG_try_block
:
12982 return "DW_TAG_try_block";
12983 case DW_TAG_variant_part
:
12984 return "DW_TAG_variant_part";
12985 case DW_TAG_variable
:
12986 return "DW_TAG_variable";
12987 case DW_TAG_volatile_type
:
12988 return "DW_TAG_volatile_type";
12989 case DW_TAG_dwarf_procedure
:
12990 return "DW_TAG_dwarf_procedure";
12991 case DW_TAG_restrict_type
:
12992 return "DW_TAG_restrict_type";
12993 case DW_TAG_interface_type
:
12994 return "DW_TAG_interface_type";
12995 case DW_TAG_namespace
:
12996 return "DW_TAG_namespace";
12997 case DW_TAG_imported_module
:
12998 return "DW_TAG_imported_module";
12999 case DW_TAG_unspecified_type
:
13000 return "DW_TAG_unspecified_type";
13001 case DW_TAG_partial_unit
:
13002 return "DW_TAG_partial_unit";
13003 case DW_TAG_imported_unit
:
13004 return "DW_TAG_imported_unit";
13005 case DW_TAG_condition
:
13006 return "DW_TAG_condition";
13007 case DW_TAG_shared_type
:
13008 return "DW_TAG_shared_type";
13009 case DW_TAG_type_unit
:
13010 return "DW_TAG_type_unit";
13011 case DW_TAG_MIPS_loop
:
13012 return "DW_TAG_MIPS_loop";
13013 case DW_TAG_HP_array_descriptor
:
13014 return "DW_TAG_HP_array_descriptor";
13015 case DW_TAG_format_label
:
13016 return "DW_TAG_format_label";
13017 case DW_TAG_function_template
:
13018 return "DW_TAG_function_template";
13019 case DW_TAG_class_template
:
13020 return "DW_TAG_class_template";
13021 case DW_TAG_GNU_BINCL
:
13022 return "DW_TAG_GNU_BINCL";
13023 case DW_TAG_GNU_EINCL
:
13024 return "DW_TAG_GNU_EINCL";
13025 case DW_TAG_upc_shared_type
:
13026 return "DW_TAG_upc_shared_type";
13027 case DW_TAG_upc_strict_type
:
13028 return "DW_TAG_upc_strict_type";
13029 case DW_TAG_upc_relaxed_type
:
13030 return "DW_TAG_upc_relaxed_type";
13031 case DW_TAG_PGI_kanji_type
:
13032 return "DW_TAG_PGI_kanji_type";
13033 case DW_TAG_PGI_interface_block
:
13034 return "DW_TAG_PGI_interface_block";
13035 case DW_TAG_GNU_call_site
:
13036 return "DW_TAG_GNU_call_site";
13038 return "DW_TAG_<unknown>";
13042 /* Convert a DWARF attribute code into its string name. */
13045 dwarf_attr_name (unsigned attr
)
13049 case DW_AT_sibling
:
13050 return "DW_AT_sibling";
13051 case DW_AT_location
:
13052 return "DW_AT_location";
13054 return "DW_AT_name";
13055 case DW_AT_ordering
:
13056 return "DW_AT_ordering";
13057 case DW_AT_subscr_data
:
13058 return "DW_AT_subscr_data";
13059 case DW_AT_byte_size
:
13060 return "DW_AT_byte_size";
13061 case DW_AT_bit_offset
:
13062 return "DW_AT_bit_offset";
13063 case DW_AT_bit_size
:
13064 return "DW_AT_bit_size";
13065 case DW_AT_element_list
:
13066 return "DW_AT_element_list";
13067 case DW_AT_stmt_list
:
13068 return "DW_AT_stmt_list";
13070 return "DW_AT_low_pc";
13071 case DW_AT_high_pc
:
13072 return "DW_AT_high_pc";
13073 case DW_AT_language
:
13074 return "DW_AT_language";
13076 return "DW_AT_member";
13078 return "DW_AT_discr";
13079 case DW_AT_discr_value
:
13080 return "DW_AT_discr_value";
13081 case DW_AT_visibility
:
13082 return "DW_AT_visibility";
13084 return "DW_AT_import";
13085 case DW_AT_string_length
:
13086 return "DW_AT_string_length";
13087 case DW_AT_common_reference
:
13088 return "DW_AT_common_reference";
13089 case DW_AT_comp_dir
:
13090 return "DW_AT_comp_dir";
13091 case DW_AT_const_value
:
13092 return "DW_AT_const_value";
13093 case DW_AT_containing_type
:
13094 return "DW_AT_containing_type";
13095 case DW_AT_default_value
:
13096 return "DW_AT_default_value";
13098 return "DW_AT_inline";
13099 case DW_AT_is_optional
:
13100 return "DW_AT_is_optional";
13101 case DW_AT_lower_bound
:
13102 return "DW_AT_lower_bound";
13103 case DW_AT_producer
:
13104 return "DW_AT_producer";
13105 case DW_AT_prototyped
:
13106 return "DW_AT_prototyped";
13107 case DW_AT_return_addr
:
13108 return "DW_AT_return_addr";
13109 case DW_AT_start_scope
:
13110 return "DW_AT_start_scope";
13111 case DW_AT_bit_stride
:
13112 return "DW_AT_bit_stride";
13113 case DW_AT_upper_bound
:
13114 return "DW_AT_upper_bound";
13115 case DW_AT_abstract_origin
:
13116 return "DW_AT_abstract_origin";
13117 case DW_AT_accessibility
:
13118 return "DW_AT_accessibility";
13119 case DW_AT_address_class
:
13120 return "DW_AT_address_class";
13121 case DW_AT_artificial
:
13122 return "DW_AT_artificial";
13123 case DW_AT_base_types
:
13124 return "DW_AT_base_types";
13125 case DW_AT_calling_convention
:
13126 return "DW_AT_calling_convention";
13128 return "DW_AT_count";
13129 case DW_AT_data_member_location
:
13130 return "DW_AT_data_member_location";
13131 case DW_AT_decl_column
:
13132 return "DW_AT_decl_column";
13133 case DW_AT_decl_file
:
13134 return "DW_AT_decl_file";
13135 case DW_AT_decl_line
:
13136 return "DW_AT_decl_line";
13137 case DW_AT_declaration
:
13138 return "DW_AT_declaration";
13139 case DW_AT_discr_list
:
13140 return "DW_AT_discr_list";
13141 case DW_AT_encoding
:
13142 return "DW_AT_encoding";
13143 case DW_AT_external
:
13144 return "DW_AT_external";
13145 case DW_AT_frame_base
:
13146 return "DW_AT_frame_base";
13148 return "DW_AT_friend";
13149 case DW_AT_identifier_case
:
13150 return "DW_AT_identifier_case";
13151 case DW_AT_macro_info
:
13152 return "DW_AT_macro_info";
13153 case DW_AT_namelist_items
:
13154 return "DW_AT_namelist_items";
13155 case DW_AT_priority
:
13156 return "DW_AT_priority";
13157 case DW_AT_segment
:
13158 return "DW_AT_segment";
13159 case DW_AT_specification
:
13160 return "DW_AT_specification";
13161 case DW_AT_static_link
:
13162 return "DW_AT_static_link";
13164 return "DW_AT_type";
13165 case DW_AT_use_location
:
13166 return "DW_AT_use_location";
13167 case DW_AT_variable_parameter
:
13168 return "DW_AT_variable_parameter";
13169 case DW_AT_virtuality
:
13170 return "DW_AT_virtuality";
13171 case DW_AT_vtable_elem_location
:
13172 return "DW_AT_vtable_elem_location";
13173 /* DWARF 3 values. */
13174 case DW_AT_allocated
:
13175 return "DW_AT_allocated";
13176 case DW_AT_associated
:
13177 return "DW_AT_associated";
13178 case DW_AT_data_location
:
13179 return "DW_AT_data_location";
13180 case DW_AT_byte_stride
:
13181 return "DW_AT_byte_stride";
13182 case DW_AT_entry_pc
:
13183 return "DW_AT_entry_pc";
13184 case DW_AT_use_UTF8
:
13185 return "DW_AT_use_UTF8";
13186 case DW_AT_extension
:
13187 return "DW_AT_extension";
13189 return "DW_AT_ranges";
13190 case DW_AT_trampoline
:
13191 return "DW_AT_trampoline";
13192 case DW_AT_call_column
:
13193 return "DW_AT_call_column";
13194 case DW_AT_call_file
:
13195 return "DW_AT_call_file";
13196 case DW_AT_call_line
:
13197 return "DW_AT_call_line";
13198 case DW_AT_description
:
13199 return "DW_AT_description";
13200 case DW_AT_binary_scale
:
13201 return "DW_AT_binary_scale";
13202 case DW_AT_decimal_scale
:
13203 return "DW_AT_decimal_scale";
13205 return "DW_AT_small";
13206 case DW_AT_decimal_sign
:
13207 return "DW_AT_decimal_sign";
13208 case DW_AT_digit_count
:
13209 return "DW_AT_digit_count";
13210 case DW_AT_picture_string
:
13211 return "DW_AT_picture_string";
13212 case DW_AT_mutable
:
13213 return "DW_AT_mutable";
13214 case DW_AT_threads_scaled
:
13215 return "DW_AT_threads_scaled";
13216 case DW_AT_explicit
:
13217 return "DW_AT_explicit";
13218 case DW_AT_object_pointer
:
13219 return "DW_AT_object_pointer";
13220 case DW_AT_endianity
:
13221 return "DW_AT_endianity";
13222 case DW_AT_elemental
:
13223 return "DW_AT_elemental";
13225 return "DW_AT_pure";
13226 case DW_AT_recursive
:
13227 return "DW_AT_recursive";
13228 /* DWARF 4 values. */
13229 case DW_AT_signature
:
13230 return "DW_AT_signature";
13231 case DW_AT_linkage_name
:
13232 return "DW_AT_linkage_name";
13233 /* SGI/MIPS extensions. */
13234 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13235 case DW_AT_MIPS_fde
:
13236 return "DW_AT_MIPS_fde";
13238 case DW_AT_MIPS_loop_begin
:
13239 return "DW_AT_MIPS_loop_begin";
13240 case DW_AT_MIPS_tail_loop_begin
:
13241 return "DW_AT_MIPS_tail_loop_begin";
13242 case DW_AT_MIPS_epilog_begin
:
13243 return "DW_AT_MIPS_epilog_begin";
13244 case DW_AT_MIPS_loop_unroll_factor
:
13245 return "DW_AT_MIPS_loop_unroll_factor";
13246 case DW_AT_MIPS_software_pipeline_depth
:
13247 return "DW_AT_MIPS_software_pipeline_depth";
13248 case DW_AT_MIPS_linkage_name
:
13249 return "DW_AT_MIPS_linkage_name";
13250 case DW_AT_MIPS_stride
:
13251 return "DW_AT_MIPS_stride";
13252 case DW_AT_MIPS_abstract_name
:
13253 return "DW_AT_MIPS_abstract_name";
13254 case DW_AT_MIPS_clone_origin
:
13255 return "DW_AT_MIPS_clone_origin";
13256 case DW_AT_MIPS_has_inlines
:
13257 return "DW_AT_MIPS_has_inlines";
13258 /* HP extensions. */
13259 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13260 case DW_AT_HP_block_index
:
13261 return "DW_AT_HP_block_index";
13263 case DW_AT_HP_unmodifiable
:
13264 return "DW_AT_HP_unmodifiable";
13265 case DW_AT_HP_actuals_stmt_list
:
13266 return "DW_AT_HP_actuals_stmt_list";
13267 case DW_AT_HP_proc_per_section
:
13268 return "DW_AT_HP_proc_per_section";
13269 case DW_AT_HP_raw_data_ptr
:
13270 return "DW_AT_HP_raw_data_ptr";
13271 case DW_AT_HP_pass_by_reference
:
13272 return "DW_AT_HP_pass_by_reference";
13273 case DW_AT_HP_opt_level
:
13274 return "DW_AT_HP_opt_level";
13275 case DW_AT_HP_prof_version_id
:
13276 return "DW_AT_HP_prof_version_id";
13277 case DW_AT_HP_opt_flags
:
13278 return "DW_AT_HP_opt_flags";
13279 case DW_AT_HP_cold_region_low_pc
:
13280 return "DW_AT_HP_cold_region_low_pc";
13281 case DW_AT_HP_cold_region_high_pc
:
13282 return "DW_AT_HP_cold_region_high_pc";
13283 case DW_AT_HP_all_variables_modifiable
:
13284 return "DW_AT_HP_all_variables_modifiable";
13285 case DW_AT_HP_linkage_name
:
13286 return "DW_AT_HP_linkage_name";
13287 case DW_AT_HP_prof_flags
:
13288 return "DW_AT_HP_prof_flags";
13289 /* GNU extensions. */
13290 case DW_AT_sf_names
:
13291 return "DW_AT_sf_names";
13292 case DW_AT_src_info
:
13293 return "DW_AT_src_info";
13294 case DW_AT_mac_info
:
13295 return "DW_AT_mac_info";
13296 case DW_AT_src_coords
:
13297 return "DW_AT_src_coords";
13298 case DW_AT_body_begin
:
13299 return "DW_AT_body_begin";
13300 case DW_AT_body_end
:
13301 return "DW_AT_body_end";
13302 case DW_AT_GNU_vector
:
13303 return "DW_AT_GNU_vector";
13304 case DW_AT_GNU_odr_signature
:
13305 return "DW_AT_GNU_odr_signature";
13306 /* VMS extensions. */
13307 case DW_AT_VMS_rtnbeg_pd_address
:
13308 return "DW_AT_VMS_rtnbeg_pd_address";
13309 /* UPC extension. */
13310 case DW_AT_upc_threads_scaled
:
13311 return "DW_AT_upc_threads_scaled";
13312 /* PGI (STMicroelectronics) extensions. */
13313 case DW_AT_PGI_lbase
:
13314 return "DW_AT_PGI_lbase";
13315 case DW_AT_PGI_soffset
:
13316 return "DW_AT_PGI_soffset";
13317 case DW_AT_PGI_lstride
:
13318 return "DW_AT_PGI_lstride";
13320 return "DW_AT_<unknown>";
13324 /* Convert a DWARF value form code into its string name. */
13327 dwarf_form_name (unsigned form
)
13332 return "DW_FORM_addr";
13333 case DW_FORM_block2
:
13334 return "DW_FORM_block2";
13335 case DW_FORM_block4
:
13336 return "DW_FORM_block4";
13337 case DW_FORM_data2
:
13338 return "DW_FORM_data2";
13339 case DW_FORM_data4
:
13340 return "DW_FORM_data4";
13341 case DW_FORM_data8
:
13342 return "DW_FORM_data8";
13343 case DW_FORM_string
:
13344 return "DW_FORM_string";
13345 case DW_FORM_block
:
13346 return "DW_FORM_block";
13347 case DW_FORM_block1
:
13348 return "DW_FORM_block1";
13349 case DW_FORM_data1
:
13350 return "DW_FORM_data1";
13352 return "DW_FORM_flag";
13353 case DW_FORM_sdata
:
13354 return "DW_FORM_sdata";
13356 return "DW_FORM_strp";
13357 case DW_FORM_udata
:
13358 return "DW_FORM_udata";
13359 case DW_FORM_ref_addr
:
13360 return "DW_FORM_ref_addr";
13362 return "DW_FORM_ref1";
13364 return "DW_FORM_ref2";
13366 return "DW_FORM_ref4";
13368 return "DW_FORM_ref8";
13369 case DW_FORM_ref_udata
:
13370 return "DW_FORM_ref_udata";
13371 case DW_FORM_indirect
:
13372 return "DW_FORM_indirect";
13373 case DW_FORM_sec_offset
:
13374 return "DW_FORM_sec_offset";
13375 case DW_FORM_exprloc
:
13376 return "DW_FORM_exprloc";
13377 case DW_FORM_flag_present
:
13378 return "DW_FORM_flag_present";
13379 case DW_FORM_ref_sig8
:
13380 return "DW_FORM_ref_sig8";
13382 return "DW_FORM_<unknown>";
13386 /* Convert a DWARF stack opcode into its string name. */
13389 dwarf_stack_op_name (unsigned op
)
13394 return "DW_OP_addr";
13396 return "DW_OP_deref";
13397 case DW_OP_const1u
:
13398 return "DW_OP_const1u";
13399 case DW_OP_const1s
:
13400 return "DW_OP_const1s";
13401 case DW_OP_const2u
:
13402 return "DW_OP_const2u";
13403 case DW_OP_const2s
:
13404 return "DW_OP_const2s";
13405 case DW_OP_const4u
:
13406 return "DW_OP_const4u";
13407 case DW_OP_const4s
:
13408 return "DW_OP_const4s";
13409 case DW_OP_const8u
:
13410 return "DW_OP_const8u";
13411 case DW_OP_const8s
:
13412 return "DW_OP_const8s";
13414 return "DW_OP_constu";
13416 return "DW_OP_consts";
13418 return "DW_OP_dup";
13420 return "DW_OP_drop";
13422 return "DW_OP_over";
13424 return "DW_OP_pick";
13426 return "DW_OP_swap";
13428 return "DW_OP_rot";
13430 return "DW_OP_xderef";
13432 return "DW_OP_abs";
13434 return "DW_OP_and";
13436 return "DW_OP_div";
13438 return "DW_OP_minus";
13440 return "DW_OP_mod";
13442 return "DW_OP_mul";
13444 return "DW_OP_neg";
13446 return "DW_OP_not";
13450 return "DW_OP_plus";
13451 case DW_OP_plus_uconst
:
13452 return "DW_OP_plus_uconst";
13454 return "DW_OP_shl";
13456 return "DW_OP_shr";
13458 return "DW_OP_shra";
13460 return "DW_OP_xor";
13462 return "DW_OP_bra";
13476 return "DW_OP_skip";
13478 return "DW_OP_lit0";
13480 return "DW_OP_lit1";
13482 return "DW_OP_lit2";
13484 return "DW_OP_lit3";
13486 return "DW_OP_lit4";
13488 return "DW_OP_lit5";
13490 return "DW_OP_lit6";
13492 return "DW_OP_lit7";
13494 return "DW_OP_lit8";
13496 return "DW_OP_lit9";
13498 return "DW_OP_lit10";
13500 return "DW_OP_lit11";
13502 return "DW_OP_lit12";
13504 return "DW_OP_lit13";
13506 return "DW_OP_lit14";
13508 return "DW_OP_lit15";
13510 return "DW_OP_lit16";
13512 return "DW_OP_lit17";
13514 return "DW_OP_lit18";
13516 return "DW_OP_lit19";
13518 return "DW_OP_lit20";
13520 return "DW_OP_lit21";
13522 return "DW_OP_lit22";
13524 return "DW_OP_lit23";
13526 return "DW_OP_lit24";
13528 return "DW_OP_lit25";
13530 return "DW_OP_lit26";
13532 return "DW_OP_lit27";
13534 return "DW_OP_lit28";
13536 return "DW_OP_lit29";
13538 return "DW_OP_lit30";
13540 return "DW_OP_lit31";
13542 return "DW_OP_reg0";
13544 return "DW_OP_reg1";
13546 return "DW_OP_reg2";
13548 return "DW_OP_reg3";
13550 return "DW_OP_reg4";
13552 return "DW_OP_reg5";
13554 return "DW_OP_reg6";
13556 return "DW_OP_reg7";
13558 return "DW_OP_reg8";
13560 return "DW_OP_reg9";
13562 return "DW_OP_reg10";
13564 return "DW_OP_reg11";
13566 return "DW_OP_reg12";
13568 return "DW_OP_reg13";
13570 return "DW_OP_reg14";
13572 return "DW_OP_reg15";
13574 return "DW_OP_reg16";
13576 return "DW_OP_reg17";
13578 return "DW_OP_reg18";
13580 return "DW_OP_reg19";
13582 return "DW_OP_reg20";
13584 return "DW_OP_reg21";
13586 return "DW_OP_reg22";
13588 return "DW_OP_reg23";
13590 return "DW_OP_reg24";
13592 return "DW_OP_reg25";
13594 return "DW_OP_reg26";
13596 return "DW_OP_reg27";
13598 return "DW_OP_reg28";
13600 return "DW_OP_reg29";
13602 return "DW_OP_reg30";
13604 return "DW_OP_reg31";
13606 return "DW_OP_breg0";
13608 return "DW_OP_breg1";
13610 return "DW_OP_breg2";
13612 return "DW_OP_breg3";
13614 return "DW_OP_breg4";
13616 return "DW_OP_breg5";
13618 return "DW_OP_breg6";
13620 return "DW_OP_breg7";
13622 return "DW_OP_breg8";
13624 return "DW_OP_breg9";
13626 return "DW_OP_breg10";
13628 return "DW_OP_breg11";
13630 return "DW_OP_breg12";
13632 return "DW_OP_breg13";
13634 return "DW_OP_breg14";
13636 return "DW_OP_breg15";
13638 return "DW_OP_breg16";
13640 return "DW_OP_breg17";
13642 return "DW_OP_breg18";
13644 return "DW_OP_breg19";
13646 return "DW_OP_breg20";
13648 return "DW_OP_breg21";
13650 return "DW_OP_breg22";
13652 return "DW_OP_breg23";
13654 return "DW_OP_breg24";
13656 return "DW_OP_breg25";
13658 return "DW_OP_breg26";
13660 return "DW_OP_breg27";
13662 return "DW_OP_breg28";
13664 return "DW_OP_breg29";
13666 return "DW_OP_breg30";
13668 return "DW_OP_breg31";
13670 return "DW_OP_regx";
13672 return "DW_OP_fbreg";
13674 return "DW_OP_bregx";
13676 return "DW_OP_piece";
13677 case DW_OP_deref_size
:
13678 return "DW_OP_deref_size";
13679 case DW_OP_xderef_size
:
13680 return "DW_OP_xderef_size";
13682 return "DW_OP_nop";
13683 /* DWARF 3 extensions. */
13684 case DW_OP_push_object_address
:
13685 return "DW_OP_push_object_address";
13687 return "DW_OP_call2";
13689 return "DW_OP_call4";
13690 case DW_OP_call_ref
:
13691 return "DW_OP_call_ref";
13692 case DW_OP_form_tls_address
:
13693 return "DW_OP_form_tls_address";
13694 case DW_OP_call_frame_cfa
:
13695 return "DW_OP_call_frame_cfa";
13696 case DW_OP_bit_piece
:
13697 return "DW_OP_bit_piece";
13698 /* DWARF 4 extensions. */
13699 case DW_OP_implicit_value
:
13700 return "DW_OP_implicit_value";
13701 case DW_OP_stack_value
:
13702 return "DW_OP_stack_value";
13703 /* GNU extensions. */
13704 case DW_OP_GNU_push_tls_address
:
13705 return "DW_OP_GNU_push_tls_address";
13706 case DW_OP_GNU_uninit
:
13707 return "DW_OP_GNU_uninit";
13708 case DW_OP_GNU_implicit_pointer
:
13709 return "DW_OP_GNU_implicit_pointer";
13710 case DW_OP_GNU_entry_value
:
13711 return "DW_OP_GNU_entry_value";
13712 case DW_OP_GNU_const_type
:
13713 return "DW_OP_GNU_const_type";
13714 case DW_OP_GNU_regval_type
:
13715 return "DW_OP_GNU_regval_type";
13716 case DW_OP_GNU_deref_type
:
13717 return "DW_OP_GNU_deref_type";
13718 case DW_OP_GNU_convert
:
13719 return "DW_OP_GNU_convert";
13720 case DW_OP_GNU_reinterpret
:
13721 return "DW_OP_GNU_reinterpret";
13728 dwarf_bool_name (unsigned mybool
)
13736 /* Convert a DWARF type code into its string name. */
13739 dwarf_type_encoding_name (unsigned enc
)
13744 return "DW_ATE_void";
13745 case DW_ATE_address
:
13746 return "DW_ATE_address";
13747 case DW_ATE_boolean
:
13748 return "DW_ATE_boolean";
13749 case DW_ATE_complex_float
:
13750 return "DW_ATE_complex_float";
13752 return "DW_ATE_float";
13753 case DW_ATE_signed
:
13754 return "DW_ATE_signed";
13755 case DW_ATE_signed_char
:
13756 return "DW_ATE_signed_char";
13757 case DW_ATE_unsigned
:
13758 return "DW_ATE_unsigned";
13759 case DW_ATE_unsigned_char
:
13760 return "DW_ATE_unsigned_char";
13762 case DW_ATE_imaginary_float
:
13763 return "DW_ATE_imaginary_float";
13764 case DW_ATE_packed_decimal
:
13765 return "DW_ATE_packed_decimal";
13766 case DW_ATE_numeric_string
:
13767 return "DW_ATE_numeric_string";
13768 case DW_ATE_edited
:
13769 return "DW_ATE_edited";
13770 case DW_ATE_signed_fixed
:
13771 return "DW_ATE_signed_fixed";
13772 case DW_ATE_unsigned_fixed
:
13773 return "DW_ATE_unsigned_fixed";
13774 case DW_ATE_decimal_float
:
13775 return "DW_ATE_decimal_float";
13778 return "DW_ATE_UTF";
13779 /* HP extensions. */
13780 case DW_ATE_HP_float80
:
13781 return "DW_ATE_HP_float80";
13782 case DW_ATE_HP_complex_float80
:
13783 return "DW_ATE_HP_complex_float80";
13784 case DW_ATE_HP_float128
:
13785 return "DW_ATE_HP_float128";
13786 case DW_ATE_HP_complex_float128
:
13787 return "DW_ATE_HP_complex_float128";
13788 case DW_ATE_HP_floathpintel
:
13789 return "DW_ATE_HP_floathpintel";
13790 case DW_ATE_HP_imaginary_float80
:
13791 return "DW_ATE_HP_imaginary_float80";
13792 case DW_ATE_HP_imaginary_float128
:
13793 return "DW_ATE_HP_imaginary_float128";
13795 return "DW_ATE_<unknown>";
13799 /* Convert a DWARF call frame info operation to its string name. */
13803 dwarf_cfi_name (unsigned cfi_opc
)
13807 case DW_CFA_advance_loc
:
13808 return "DW_CFA_advance_loc";
13809 case DW_CFA_offset
:
13810 return "DW_CFA_offset";
13811 case DW_CFA_restore
:
13812 return "DW_CFA_restore";
13814 return "DW_CFA_nop";
13815 case DW_CFA_set_loc
:
13816 return "DW_CFA_set_loc";
13817 case DW_CFA_advance_loc1
:
13818 return "DW_CFA_advance_loc1";
13819 case DW_CFA_advance_loc2
:
13820 return "DW_CFA_advance_loc2";
13821 case DW_CFA_advance_loc4
:
13822 return "DW_CFA_advance_loc4";
13823 case DW_CFA_offset_extended
:
13824 return "DW_CFA_offset_extended";
13825 case DW_CFA_restore_extended
:
13826 return "DW_CFA_restore_extended";
13827 case DW_CFA_undefined
:
13828 return "DW_CFA_undefined";
13829 case DW_CFA_same_value
:
13830 return "DW_CFA_same_value";
13831 case DW_CFA_register
:
13832 return "DW_CFA_register";
13833 case DW_CFA_remember_state
:
13834 return "DW_CFA_remember_state";
13835 case DW_CFA_restore_state
:
13836 return "DW_CFA_restore_state";
13837 case DW_CFA_def_cfa
:
13838 return "DW_CFA_def_cfa";
13839 case DW_CFA_def_cfa_register
:
13840 return "DW_CFA_def_cfa_register";
13841 case DW_CFA_def_cfa_offset
:
13842 return "DW_CFA_def_cfa_offset";
13844 case DW_CFA_def_cfa_expression
:
13845 return "DW_CFA_def_cfa_expression";
13846 case DW_CFA_expression
:
13847 return "DW_CFA_expression";
13848 case DW_CFA_offset_extended_sf
:
13849 return "DW_CFA_offset_extended_sf";
13850 case DW_CFA_def_cfa_sf
:
13851 return "DW_CFA_def_cfa_sf";
13852 case DW_CFA_def_cfa_offset_sf
:
13853 return "DW_CFA_def_cfa_offset_sf";
13854 case DW_CFA_val_offset
:
13855 return "DW_CFA_val_offset";
13856 case DW_CFA_val_offset_sf
:
13857 return "DW_CFA_val_offset_sf";
13858 case DW_CFA_val_expression
:
13859 return "DW_CFA_val_expression";
13860 /* SGI/MIPS specific. */
13861 case DW_CFA_MIPS_advance_loc8
:
13862 return "DW_CFA_MIPS_advance_loc8";
13863 /* GNU extensions. */
13864 case DW_CFA_GNU_window_save
:
13865 return "DW_CFA_GNU_window_save";
13866 case DW_CFA_GNU_args_size
:
13867 return "DW_CFA_GNU_args_size";
13868 case DW_CFA_GNU_negative_offset_extended
:
13869 return "DW_CFA_GNU_negative_offset_extended";
13871 return "DW_CFA_<unknown>";
13877 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13881 print_spaces (indent
, f
);
13882 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13883 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13885 if (die
->parent
!= NULL
)
13887 print_spaces (indent
, f
);
13888 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13889 die
->parent
->offset
);
13892 print_spaces (indent
, f
);
13893 fprintf_unfiltered (f
, " has children: %s\n",
13894 dwarf_bool_name (die
->child
!= NULL
));
13896 print_spaces (indent
, f
);
13897 fprintf_unfiltered (f
, " attributes:\n");
13899 for (i
= 0; i
< die
->num_attrs
; ++i
)
13901 print_spaces (indent
, f
);
13902 fprintf_unfiltered (f
, " %s (%s) ",
13903 dwarf_attr_name (die
->attrs
[i
].name
),
13904 dwarf_form_name (die
->attrs
[i
].form
));
13906 switch (die
->attrs
[i
].form
)
13908 case DW_FORM_ref_addr
:
13910 fprintf_unfiltered (f
, "address: ");
13911 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13913 case DW_FORM_block2
:
13914 case DW_FORM_block4
:
13915 case DW_FORM_block
:
13916 case DW_FORM_block1
:
13917 fprintf_unfiltered (f
, "block: size %d",
13918 DW_BLOCK (&die
->attrs
[i
])->size
);
13920 case DW_FORM_exprloc
:
13921 fprintf_unfiltered (f
, "expression: size %u",
13922 DW_BLOCK (&die
->attrs
[i
])->size
);
13927 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13928 (long) (DW_ADDR (&die
->attrs
[i
])));
13930 case DW_FORM_data1
:
13931 case DW_FORM_data2
:
13932 case DW_FORM_data4
:
13933 case DW_FORM_data8
:
13934 case DW_FORM_udata
:
13935 case DW_FORM_sdata
:
13936 fprintf_unfiltered (f
, "constant: %s",
13937 pulongest (DW_UNSND (&die
->attrs
[i
])));
13939 case DW_FORM_sec_offset
:
13940 fprintf_unfiltered (f
, "section offset: %s",
13941 pulongest (DW_UNSND (&die
->attrs
[i
])));
13943 case DW_FORM_ref_sig8
:
13944 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13945 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13946 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
);
13948 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13950 case DW_FORM_string
:
13952 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13953 DW_STRING (&die
->attrs
[i
])
13954 ? DW_STRING (&die
->attrs
[i
]) : "",
13955 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13958 if (DW_UNSND (&die
->attrs
[i
]))
13959 fprintf_unfiltered (f
, "flag: TRUE");
13961 fprintf_unfiltered (f
, "flag: FALSE");
13963 case DW_FORM_flag_present
:
13964 fprintf_unfiltered (f
, "flag: TRUE");
13966 case DW_FORM_indirect
:
13967 /* The reader will have reduced the indirect form to
13968 the "base form" so this form should not occur. */
13969 fprintf_unfiltered (f
,
13970 "unexpected attribute form: DW_FORM_indirect");
13973 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13974 die
->attrs
[i
].form
);
13977 fprintf_unfiltered (f
, "\n");
13982 dump_die_for_error (struct die_info
*die
)
13984 dump_die_shallow (gdb_stderr
, 0, die
);
13988 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13990 int indent
= level
* 4;
13992 gdb_assert (die
!= NULL
);
13994 if (level
>= max_level
)
13997 dump_die_shallow (f
, indent
, die
);
13999 if (die
->child
!= NULL
)
14001 print_spaces (indent
, f
);
14002 fprintf_unfiltered (f
, " Children:");
14003 if (level
+ 1 < max_level
)
14005 fprintf_unfiltered (f
, "\n");
14006 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
14010 fprintf_unfiltered (f
,
14011 " [not printed, max nesting level reached]\n");
14015 if (die
->sibling
!= NULL
&& level
> 0)
14017 dump_die_1 (f
, level
, max_level
, die
->sibling
);
14021 /* This is called from the pdie macro in gdbinit.in.
14022 It's not static so gcc will keep a copy callable from gdb. */
14025 dump_die (struct die_info
*die
, int max_level
)
14027 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
14031 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
14035 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
14041 is_ref_attr (struct attribute
*attr
)
14043 switch (attr
->form
)
14045 case DW_FORM_ref_addr
:
14050 case DW_FORM_ref_udata
:
14057 static unsigned int
14058 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14060 if (is_ref_attr (attr
))
14061 return DW_ADDR (attr
);
14063 complaint (&symfile_complaints
,
14064 _("unsupported die ref attribute form: '%s'"),
14065 dwarf_form_name (attr
->form
));
14069 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14070 * the value held by the attribute is not constant. */
14073 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
14075 if (attr
->form
== DW_FORM_sdata
)
14076 return DW_SND (attr
);
14077 else if (attr
->form
== DW_FORM_udata
14078 || attr
->form
== DW_FORM_data1
14079 || attr
->form
== DW_FORM_data2
14080 || attr
->form
== DW_FORM_data4
14081 || attr
->form
== DW_FORM_data8
)
14082 return DW_UNSND (attr
);
14085 complaint (&symfile_complaints
,
14086 _("Attribute value is not a constant (%s)"),
14087 dwarf_form_name (attr
->form
));
14088 return default_value
;
14092 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14093 unit and add it to our queue.
14094 The result is non-zero if PER_CU was queued, otherwise the result is zero
14095 meaning either PER_CU is already queued or it is already loaded. */
14098 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14099 struct dwarf2_per_cu_data
*per_cu
)
14101 /* We may arrive here during partial symbol reading, if we need full
14102 DIEs to process an unusual case (e.g. template arguments). Do
14103 not queue PER_CU, just tell our caller to load its DIEs. */
14104 if (dwarf2_per_objfile
->reading_partial_symbols
)
14106 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14111 /* Mark the dependence relation so that we don't flush PER_CU
14113 dwarf2_add_dependence (this_cu
, per_cu
);
14115 /* If it's already on the queue, we have nothing to do. */
14116 if (per_cu
->queued
)
14119 /* If the compilation unit is already loaded, just mark it as
14121 if (per_cu
->cu
!= NULL
)
14123 per_cu
->cu
->last_used
= 0;
14127 /* Add it to the queue. */
14128 queue_comp_unit (per_cu
);
14133 /* Follow reference or signature attribute ATTR of SRC_DIE.
14134 On entry *REF_CU is the CU of SRC_DIE.
14135 On exit *REF_CU is the CU of the result. */
14137 static struct die_info
*
14138 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14139 struct dwarf2_cu
**ref_cu
)
14141 struct die_info
*die
;
14143 if (is_ref_attr (attr
))
14144 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14145 else if (attr
->form
== DW_FORM_ref_sig8
)
14146 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14149 dump_die_for_error (src_die
);
14150 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14151 (*ref_cu
)->objfile
->name
);
14157 /* Follow reference OFFSET.
14158 On entry *REF_CU is the CU of the source die referencing OFFSET.
14159 On exit *REF_CU is the CU of the result.
14160 Returns NULL if OFFSET is invalid. */
14162 static struct die_info
*
14163 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
14165 struct die_info temp_die
;
14166 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14168 gdb_assert (cu
->per_cu
!= NULL
);
14172 if (cu
->per_cu
->debug_types_section
)
14174 /* .debug_types CUs cannot reference anything outside their CU.
14175 If they need to, they have to reference a signatured type via
14176 DW_FORM_ref_sig8. */
14177 if (! offset_in_cu_p (&cu
->header
, offset
))
14180 else if (! offset_in_cu_p (&cu
->header
, offset
))
14182 struct dwarf2_per_cu_data
*per_cu
;
14184 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14186 /* If necessary, add it to the queue and load its DIEs. */
14187 if (maybe_queue_comp_unit (cu
, per_cu
))
14188 load_full_comp_unit (per_cu
);
14190 target_cu
= per_cu
->cu
;
14192 else if (cu
->dies
== NULL
)
14194 /* We're loading full DIEs during partial symbol reading. */
14195 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14196 load_full_comp_unit (cu
->per_cu
);
14199 *ref_cu
= target_cu
;
14200 temp_die
.offset
= offset
;
14201 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
14204 /* Follow reference attribute ATTR of SRC_DIE.
14205 On entry *REF_CU is the CU of SRC_DIE.
14206 On exit *REF_CU is the CU of the result. */
14208 static struct die_info
*
14209 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14210 struct dwarf2_cu
**ref_cu
)
14212 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
14213 struct dwarf2_cu
*cu
= *ref_cu
;
14214 struct die_info
*die
;
14216 die
= follow_die_offset (offset
, ref_cu
);
14218 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14219 "at 0x%x [in module %s]"),
14220 offset
, src_die
->offset
, cu
->objfile
->name
);
14225 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14226 Returned value is intended for DW_OP_call*. Returned
14227 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14229 struct dwarf2_locexpr_baton
14230 dwarf2_fetch_die_location_block (unsigned int offset
,
14231 struct dwarf2_per_cu_data
*per_cu
,
14232 CORE_ADDR (*get_frame_pc
) (void *baton
),
14235 struct dwarf2_cu
*cu
;
14236 struct die_info
*die
;
14237 struct attribute
*attr
;
14238 struct dwarf2_locexpr_baton retval
;
14240 dw2_setup (per_cu
->objfile
);
14242 if (per_cu
->cu
== NULL
)
14246 die
= follow_die_offset (offset
, &cu
);
14248 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14249 offset
, per_cu
->objfile
->name
);
14251 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14254 /* DWARF: "If there is no such attribute, then there is no effect.".
14255 DATA is ignored if SIZE is 0. */
14257 retval
.data
= NULL
;
14260 else if (attr_form_is_section_offset (attr
))
14262 struct dwarf2_loclist_baton loclist_baton
;
14263 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
14266 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
14268 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
14270 retval
.size
= size
;
14274 if (!attr_form_is_block (attr
))
14275 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14276 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14277 offset
, per_cu
->objfile
->name
);
14279 retval
.data
= DW_BLOCK (attr
)->data
;
14280 retval
.size
= DW_BLOCK (attr
)->size
;
14282 retval
.per_cu
= cu
->per_cu
;
14284 age_cached_comp_units ();
14289 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14293 dwarf2_get_die_type (unsigned int die_offset
,
14294 struct dwarf2_per_cu_data
*per_cu
)
14296 dw2_setup (per_cu
->objfile
);
14297 return get_die_type_at_offset (die_offset
, per_cu
);
14300 /* Follow the signature attribute ATTR in SRC_DIE.
14301 On entry *REF_CU is the CU of SRC_DIE.
14302 On exit *REF_CU is the CU of the result. */
14304 static struct die_info
*
14305 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
14306 struct dwarf2_cu
**ref_cu
)
14308 struct objfile
*objfile
= (*ref_cu
)->objfile
;
14309 struct die_info temp_die
;
14310 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14311 struct dwarf2_cu
*sig_cu
;
14312 struct die_info
*die
;
14314 /* sig_type will be NULL if the signatured type is missing from
14316 if (sig_type
== NULL
)
14317 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14318 "at 0x%x [in module %s]"),
14319 src_die
->offset
, objfile
->name
);
14321 /* If necessary, add it to the queue and load its DIEs. */
14323 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14324 read_signatured_type (sig_type
);
14326 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14328 sig_cu
= sig_type
->per_cu
.cu
;
14329 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
14330 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
14337 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14338 "from DIE at 0x%x [in module %s]"),
14339 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
14342 /* Given an offset of a signatured type, return its signatured_type. */
14344 static struct signatured_type
*
14345 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14346 struct dwarf2_section_info
*section
,
14347 unsigned int offset
)
14349 gdb_byte
*info_ptr
= section
->buffer
+ offset
;
14350 unsigned int length
, initial_length_size
;
14351 unsigned int sig_offset
;
14352 struct signatured_type find_entry
, *type_sig
;
14354 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14355 sig_offset
= (initial_length_size
14357 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14358 + 1 /*address_size*/);
14359 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14360 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14362 /* This is only used to lookup previously recorded types.
14363 If we didn't find it, it's our bug. */
14364 gdb_assert (type_sig
!= NULL
);
14365 gdb_assert (offset
== type_sig
->per_cu
.offset
);
14370 /* Read in signatured type at OFFSET and build its CU and die(s). */
14373 read_signatured_type_at_offset (struct objfile
*objfile
,
14374 struct dwarf2_section_info
*sect
,
14375 unsigned int offset
)
14377 struct signatured_type
*type_sig
;
14379 dwarf2_read_section (objfile
, sect
);
14381 /* We have the section offset, but we need the signature to do the
14382 hash table lookup. */
14383 type_sig
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14385 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14387 read_signatured_type (type_sig
);
14389 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
14392 /* Read in a signatured type and build its CU and DIEs. */
14395 read_signatured_type (struct signatured_type
*type_sig
)
14397 struct objfile
*objfile
= type_sig
->per_cu
.objfile
;
14398 gdb_byte
*types_ptr
;
14399 struct die_reader_specs reader_specs
;
14400 struct dwarf2_cu
*cu
;
14401 ULONGEST signature
;
14402 struct cleanup
*back_to
, *free_cu_cleanup
;
14403 struct dwarf2_section_info
*section
= type_sig
->per_cu
.debug_types_section
;
14405 dwarf2_read_section (objfile
, section
);
14406 types_ptr
= section
->buffer
+ type_sig
->per_cu
.offset
;
14408 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14410 cu
= xmalloc (sizeof (*cu
));
14411 init_one_comp_unit (cu
, &type_sig
->per_cu
);
14413 /* If an error occurs while loading, release our storage. */
14414 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
14416 types_ptr
= read_type_comp_unit_head (&cu
->header
, section
, &signature
,
14417 types_ptr
, objfile
->obfd
);
14418 gdb_assert (signature
== type_sig
->signature
);
14421 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14425 &cu
->comp_unit_obstack
,
14426 hashtab_obstack_allocate
,
14427 dummy_obstack_deallocate
);
14429 dwarf2_read_abbrevs (objfile
->obfd
, cu
);
14430 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
14432 init_cu_die_reader (&reader_specs
, cu
);
14434 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14437 /* We try not to read any attributes in this function, because not
14438 all CUs needed for references have been loaded yet, and symbol
14439 table processing isn't initialized. But we have to set the CU language,
14440 or we won't be able to build types correctly. */
14441 prepare_one_comp_unit (cu
, cu
->dies
);
14443 do_cleanups (back_to
);
14445 /* We've successfully allocated this compilation unit. Let our caller
14446 clean it up when finished with it. */
14447 discard_cleanups (free_cu_cleanup
);
14449 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14450 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
14453 /* Decode simple location descriptions.
14454 Given a pointer to a dwarf block that defines a location, compute
14455 the location and return the value.
14457 NOTE drow/2003-11-18: This function is called in two situations
14458 now: for the address of static or global variables (partial symbols
14459 only) and for offsets into structures which are expected to be
14460 (more or less) constant. The partial symbol case should go away,
14461 and only the constant case should remain. That will let this
14462 function complain more accurately. A few special modes are allowed
14463 without complaint for global variables (for instance, global
14464 register values and thread-local values).
14466 A location description containing no operations indicates that the
14467 object is optimized out. The return value is 0 for that case.
14468 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14469 callers will only want a very basic result and this can become a
14472 Note that stack[0] is unused except as a default error return. */
14475 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14477 struct objfile
*objfile
= cu
->objfile
;
14479 int size
= blk
->size
;
14480 gdb_byte
*data
= blk
->data
;
14481 CORE_ADDR stack
[64];
14483 unsigned int bytes_read
, unsnd
;
14489 stack
[++stacki
] = 0;
14528 stack
[++stacki
] = op
- DW_OP_lit0
;
14563 stack
[++stacki
] = op
- DW_OP_reg0
;
14565 dwarf2_complex_location_expr_complaint ();
14569 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14571 stack
[++stacki
] = unsnd
;
14573 dwarf2_complex_location_expr_complaint ();
14577 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14582 case DW_OP_const1u
:
14583 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14587 case DW_OP_const1s
:
14588 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14592 case DW_OP_const2u
:
14593 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14597 case DW_OP_const2s
:
14598 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14602 case DW_OP_const4u
:
14603 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14607 case DW_OP_const4s
:
14608 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14612 case DW_OP_const8u
:
14613 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
14618 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14624 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14629 stack
[stacki
+ 1] = stack
[stacki
];
14634 stack
[stacki
- 1] += stack
[stacki
];
14638 case DW_OP_plus_uconst
:
14639 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14645 stack
[stacki
- 1] -= stack
[stacki
];
14650 /* If we're not the last op, then we definitely can't encode
14651 this using GDB's address_class enum. This is valid for partial
14652 global symbols, although the variable's address will be bogus
14655 dwarf2_complex_location_expr_complaint ();
14658 case DW_OP_GNU_push_tls_address
:
14659 /* The top of the stack has the offset from the beginning
14660 of the thread control block at which the variable is located. */
14661 /* Nothing should follow this operator, so the top of stack would
14663 /* This is valid for partial global symbols, but the variable's
14664 address will be bogus in the psymtab. Make it always at least
14665 non-zero to not look as a variable garbage collected by linker
14666 which have DW_OP_addr 0. */
14668 dwarf2_complex_location_expr_complaint ();
14672 case DW_OP_GNU_uninit
:
14677 const char *name
= dwarf_stack_op_name (op
);
14680 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14683 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14687 return (stack
[stacki
]);
14690 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14691 outside of the allocated space. Also enforce minimum>0. */
14692 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14694 complaint (&symfile_complaints
,
14695 _("location description stack overflow"));
14701 complaint (&symfile_complaints
,
14702 _("location description stack underflow"));
14706 return (stack
[stacki
]);
14709 /* memory allocation interface */
14711 static struct dwarf_block
*
14712 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14714 struct dwarf_block
*blk
;
14716 blk
= (struct dwarf_block
*)
14717 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14721 static struct abbrev_info
*
14722 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14724 struct abbrev_info
*abbrev
;
14726 abbrev
= (struct abbrev_info
*)
14727 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14728 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14732 static struct die_info
*
14733 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14735 struct die_info
*die
;
14736 size_t size
= sizeof (struct die_info
);
14739 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14741 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14742 memset (die
, 0, sizeof (struct die_info
));
14747 /* Macro support. */
14749 /* Return the full name of file number I in *LH's file name table.
14750 Use COMP_DIR as the name of the current directory of the
14751 compilation. The result is allocated using xmalloc; the caller is
14752 responsible for freeing it. */
14754 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14756 /* Is the file number a valid index into the line header's file name
14757 table? Remember that file numbers start with one, not zero. */
14758 if (1 <= file
&& file
<= lh
->num_file_names
)
14760 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14762 if (IS_ABSOLUTE_PATH (fe
->name
))
14763 return xstrdup (fe
->name
);
14771 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14777 dir_len
= strlen (dir
);
14778 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14779 strcpy (full_name
, dir
);
14780 full_name
[dir_len
] = '/';
14781 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14785 return xstrdup (fe
->name
);
14790 /* The compiler produced a bogus file number. We can at least
14791 record the macro definitions made in the file, even if we
14792 won't be able to find the file by name. */
14793 char fake_name
[80];
14795 sprintf (fake_name
, "<bad macro file number %d>", file
);
14797 complaint (&symfile_complaints
,
14798 _("bad file number in macro information (%d)"),
14801 return xstrdup (fake_name
);
14806 static struct macro_source_file
*
14807 macro_start_file (int file
, int line
,
14808 struct macro_source_file
*current_file
,
14809 const char *comp_dir
,
14810 struct line_header
*lh
, struct objfile
*objfile
)
14812 /* The full name of this source file. */
14813 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14815 /* We don't create a macro table for this compilation unit
14816 at all until we actually get a filename. */
14817 if (! pending_macros
)
14818 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14819 objfile
->macro_cache
);
14821 if (! current_file
)
14822 /* If we have no current file, then this must be the start_file
14823 directive for the compilation unit's main source file. */
14824 current_file
= macro_set_main (pending_macros
, full_name
);
14826 current_file
= macro_include (current_file
, line
, full_name
);
14830 return current_file
;
14834 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14835 followed by a null byte. */
14837 copy_string (const char *buf
, int len
)
14839 char *s
= xmalloc (len
+ 1);
14841 memcpy (s
, buf
, len
);
14847 static const char *
14848 consume_improper_spaces (const char *p
, const char *body
)
14852 complaint (&symfile_complaints
,
14853 _("macro definition contains spaces "
14854 "in formal argument list:\n`%s'"),
14866 parse_macro_definition (struct macro_source_file
*file
, int line
,
14871 /* The body string takes one of two forms. For object-like macro
14872 definitions, it should be:
14874 <macro name> " " <definition>
14876 For function-like macro definitions, it should be:
14878 <macro name> "() " <definition>
14880 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14882 Spaces may appear only where explicitly indicated, and in the
14885 The Dwarf 2 spec says that an object-like macro's name is always
14886 followed by a space, but versions of GCC around March 2002 omit
14887 the space when the macro's definition is the empty string.
14889 The Dwarf 2 spec says that there should be no spaces between the
14890 formal arguments in a function-like macro's formal argument list,
14891 but versions of GCC around March 2002 include spaces after the
14895 /* Find the extent of the macro name. The macro name is terminated
14896 by either a space or null character (for an object-like macro) or
14897 an opening paren (for a function-like macro). */
14898 for (p
= body
; *p
; p
++)
14899 if (*p
== ' ' || *p
== '(')
14902 if (*p
== ' ' || *p
== '\0')
14904 /* It's an object-like macro. */
14905 int name_len
= p
- body
;
14906 char *name
= copy_string (body
, name_len
);
14907 const char *replacement
;
14910 replacement
= body
+ name_len
+ 1;
14913 dwarf2_macro_malformed_definition_complaint (body
);
14914 replacement
= body
+ name_len
;
14917 macro_define_object (file
, line
, name
, replacement
);
14921 else if (*p
== '(')
14923 /* It's a function-like macro. */
14924 char *name
= copy_string (body
, p
- body
);
14927 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14931 p
= consume_improper_spaces (p
, body
);
14933 /* Parse the formal argument list. */
14934 while (*p
&& *p
!= ')')
14936 /* Find the extent of the current argument name. */
14937 const char *arg_start
= p
;
14939 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14942 if (! *p
|| p
== arg_start
)
14943 dwarf2_macro_malformed_definition_complaint (body
);
14946 /* Make sure argv has room for the new argument. */
14947 if (argc
>= argv_size
)
14950 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14953 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14956 p
= consume_improper_spaces (p
, body
);
14958 /* Consume the comma, if present. */
14963 p
= consume_improper_spaces (p
, body
);
14972 /* Perfectly formed definition, no complaints. */
14973 macro_define_function (file
, line
, name
,
14974 argc
, (const char **) argv
,
14976 else if (*p
== '\0')
14978 /* Complain, but do define it. */
14979 dwarf2_macro_malformed_definition_complaint (body
);
14980 macro_define_function (file
, line
, name
,
14981 argc
, (const char **) argv
,
14985 /* Just complain. */
14986 dwarf2_macro_malformed_definition_complaint (body
);
14989 /* Just complain. */
14990 dwarf2_macro_malformed_definition_complaint (body
);
14996 for (i
= 0; i
< argc
; i
++)
15002 dwarf2_macro_malformed_definition_complaint (body
);
15005 /* Skip some bytes from BYTES according to the form given in FORM.
15006 Returns the new pointer. */
15009 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
15010 enum dwarf_form form
,
15011 unsigned int offset_size
,
15012 struct dwarf2_section_info
*section
)
15014 unsigned int bytes_read
;
15018 case DW_FORM_data1
:
15023 case DW_FORM_data2
:
15027 case DW_FORM_data4
:
15031 case DW_FORM_data8
:
15035 case DW_FORM_string
:
15036 read_direct_string (abfd
, bytes
, &bytes_read
);
15037 bytes
+= bytes_read
;
15040 case DW_FORM_sec_offset
:
15042 bytes
+= offset_size
;
15045 case DW_FORM_block
:
15046 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
15047 bytes
+= bytes_read
;
15050 case DW_FORM_block1
:
15051 bytes
+= 1 + read_1_byte (abfd
, bytes
);
15053 case DW_FORM_block2
:
15054 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
15056 case DW_FORM_block4
:
15057 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
15060 case DW_FORM_sdata
:
15061 case DW_FORM_udata
:
15062 bytes
= skip_leb128 (abfd
, bytes
);
15068 complaint (&symfile_complaints
,
15069 _("invalid form 0x%x in `%s'"),
15071 section
->asection
->name
);
15079 /* A helper for dwarf_decode_macros that handles skipping an unknown
15080 opcode. Returns an updated pointer to the macro data buffer; or,
15081 on error, issues a complaint and returns NULL. */
15084 skip_unknown_opcode (unsigned int opcode
,
15085 gdb_byte
**opcode_definitions
,
15088 unsigned int offset_size
,
15089 struct dwarf2_section_info
*section
)
15091 unsigned int bytes_read
, i
;
15095 if (opcode_definitions
[opcode
] == NULL
)
15097 complaint (&symfile_complaints
,
15098 _("unrecognized DW_MACFINO opcode 0x%x"),
15103 defn
= opcode_definitions
[opcode
];
15104 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15105 defn
+= bytes_read
;
15107 for (i
= 0; i
< arg
; ++i
)
15109 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
15110 if (mac_ptr
== NULL
)
15112 /* skip_form_bytes already issued the complaint. */
15120 /* A helper function which parses the header of a macro section.
15121 If the macro section is the extended (for now called "GNU") type,
15122 then this updates *OFFSET_SIZE. Returns a pointer to just after
15123 the header, or issues a complaint and returns NULL on error. */
15126 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15129 unsigned int *offset_size
,
15130 int section_is_gnu
)
15132 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15134 if (section_is_gnu
)
15136 unsigned int version
, flags
;
15138 version
= read_2_bytes (abfd
, mac_ptr
);
15141 complaint (&symfile_complaints
,
15142 _("unrecognized version `%d' in .debug_macro section"),
15148 flags
= read_1_byte (abfd
, mac_ptr
);
15150 *offset_size
= (flags
& 1) ? 8 : 4;
15152 if ((flags
& 2) != 0)
15153 /* We don't need the line table offset. */
15154 mac_ptr
+= *offset_size
;
15156 /* Vendor opcode descriptions. */
15157 if ((flags
& 4) != 0)
15159 unsigned int i
, count
;
15161 count
= read_1_byte (abfd
, mac_ptr
);
15163 for (i
= 0; i
< count
; ++i
)
15165 unsigned int opcode
, bytes_read
;
15168 opcode
= read_1_byte (abfd
, mac_ptr
);
15170 opcode_definitions
[opcode
] = mac_ptr
;
15171 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15172 mac_ptr
+= bytes_read
;
15181 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15182 including DW_GNU_MACINFO_transparent_include. */
15185 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15186 struct macro_source_file
*current_file
,
15187 struct line_header
*lh
, char *comp_dir
,
15188 struct dwarf2_section_info
*section
,
15189 int section_is_gnu
,
15190 unsigned int offset_size
,
15191 struct objfile
*objfile
)
15193 enum dwarf_macro_record_type macinfo_type
;
15194 int at_commandline
;
15195 gdb_byte
*opcode_definitions
[256];
15197 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15198 &offset_size
, section_is_gnu
);
15199 if (mac_ptr
== NULL
)
15201 /* We already issued a complaint. */
15205 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15206 GDB is still reading the definitions from command line. First
15207 DW_MACINFO_start_file will need to be ignored as it was already executed
15208 to create CURRENT_FILE for the main source holding also the command line
15209 definitions. On first met DW_MACINFO_start_file this flag is reset to
15210 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15212 at_commandline
= 1;
15216 /* Do we at least have room for a macinfo type byte? */
15217 if (mac_ptr
>= mac_end
)
15219 dwarf2_macros_too_long_complaint (section
);
15223 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15226 /* Note that we rely on the fact that the corresponding GNU and
15227 DWARF constants are the same. */
15228 switch (macinfo_type
)
15230 /* A zero macinfo type indicates the end of the macro
15235 case DW_MACRO_GNU_define
:
15236 case DW_MACRO_GNU_undef
:
15237 case DW_MACRO_GNU_define_indirect
:
15238 case DW_MACRO_GNU_undef_indirect
:
15240 unsigned int bytes_read
;
15245 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15246 mac_ptr
+= bytes_read
;
15248 if (macinfo_type
== DW_MACRO_GNU_define
15249 || macinfo_type
== DW_MACRO_GNU_undef
)
15251 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15252 mac_ptr
+= bytes_read
;
15256 LONGEST str_offset
;
15258 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15259 mac_ptr
+= offset_size
;
15261 body
= read_indirect_string_at_offset (abfd
, str_offset
);
15264 is_define
= (macinfo_type
== DW_MACRO_GNU_define
15265 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
15266 if (! current_file
)
15268 /* DWARF violation as no main source is present. */
15269 complaint (&symfile_complaints
,
15270 _("debug info with no main source gives macro %s "
15272 is_define
? _("definition") : _("undefinition"),
15276 if ((line
== 0 && !at_commandline
)
15277 || (line
!= 0 && at_commandline
))
15278 complaint (&symfile_complaints
,
15279 _("debug info gives %s macro %s with %s line %d: %s"),
15280 at_commandline
? _("command-line") : _("in-file"),
15281 is_define
? _("definition") : _("undefinition"),
15282 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
15285 parse_macro_definition (current_file
, line
, body
);
15288 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
15289 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
15290 macro_undef (current_file
, line
, body
);
15295 case DW_MACRO_GNU_start_file
:
15297 unsigned int bytes_read
;
15300 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15301 mac_ptr
+= bytes_read
;
15302 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15303 mac_ptr
+= bytes_read
;
15305 if ((line
== 0 && !at_commandline
)
15306 || (line
!= 0 && at_commandline
))
15307 complaint (&symfile_complaints
,
15308 _("debug info gives source %d included "
15309 "from %s at %s line %d"),
15310 file
, at_commandline
? _("command-line") : _("file"),
15311 line
== 0 ? _("zero") : _("non-zero"), line
);
15313 if (at_commandline
)
15315 /* This DW_MACRO_GNU_start_file was executed in the
15317 at_commandline
= 0;
15320 current_file
= macro_start_file (file
, line
,
15321 current_file
, comp_dir
,
15326 case DW_MACRO_GNU_end_file
:
15327 if (! current_file
)
15328 complaint (&symfile_complaints
,
15329 _("macro debug info has an unmatched "
15330 "`close_file' directive"));
15333 current_file
= current_file
->included_by
;
15334 if (! current_file
)
15336 enum dwarf_macro_record_type next_type
;
15338 /* GCC circa March 2002 doesn't produce the zero
15339 type byte marking the end of the compilation
15340 unit. Complain if it's not there, but exit no
15343 /* Do we at least have room for a macinfo type byte? */
15344 if (mac_ptr
>= mac_end
)
15346 dwarf2_macros_too_long_complaint (section
);
15350 /* We don't increment mac_ptr here, so this is just
15352 next_type
= read_1_byte (abfd
, mac_ptr
);
15353 if (next_type
!= 0)
15354 complaint (&symfile_complaints
,
15355 _("no terminating 0-type entry for "
15356 "macros in `.debug_macinfo' section"));
15363 case DW_MACRO_GNU_transparent_include
:
15367 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15368 mac_ptr
+= offset_size
;
15370 dwarf_decode_macro_bytes (abfd
,
15371 section
->buffer
+ offset
,
15372 mac_end
, current_file
,
15374 section
, section_is_gnu
,
15375 offset_size
, objfile
);
15379 case DW_MACINFO_vendor_ext
:
15380 if (!section_is_gnu
)
15382 unsigned int bytes_read
;
15385 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15386 mac_ptr
+= bytes_read
;
15387 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15388 mac_ptr
+= bytes_read
;
15390 /* We don't recognize any vendor extensions. */
15396 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15397 mac_ptr
, abfd
, offset_size
,
15399 if (mac_ptr
== NULL
)
15403 } while (macinfo_type
!= 0);
15407 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
15408 char *comp_dir
, bfd
*abfd
,
15409 struct dwarf2_cu
*cu
,
15410 struct dwarf2_section_info
*section
,
15411 int section_is_gnu
)
15413 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15414 gdb_byte
*mac_ptr
, *mac_end
;
15415 struct macro_source_file
*current_file
= 0;
15416 enum dwarf_macro_record_type macinfo_type
;
15417 unsigned int offset_size
= cu
->header
.offset_size
;
15418 gdb_byte
*opcode_definitions
[256];
15420 dwarf2_read_section (objfile
, section
);
15421 if (section
->buffer
== NULL
)
15423 complaint (&symfile_complaints
, _("missing %s section"),
15424 section
->asection
->name
);
15428 /* First pass: Find the name of the base filename.
15429 This filename is needed in order to process all macros whose definition
15430 (or undefinition) comes from the command line. These macros are defined
15431 before the first DW_MACINFO_start_file entry, and yet still need to be
15432 associated to the base file.
15434 To determine the base file name, we scan the macro definitions until we
15435 reach the first DW_MACINFO_start_file entry. We then initialize
15436 CURRENT_FILE accordingly so that any macro definition found before the
15437 first DW_MACINFO_start_file can still be associated to the base file. */
15439 mac_ptr
= section
->buffer
+ offset
;
15440 mac_end
= section
->buffer
+ section
->size
;
15442 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15443 &offset_size
, section_is_gnu
);
15444 if (mac_ptr
== NULL
)
15446 /* We already issued a complaint. */
15452 /* Do we at least have room for a macinfo type byte? */
15453 if (mac_ptr
>= mac_end
)
15455 /* Complaint is printed during the second pass as GDB will probably
15456 stop the first pass earlier upon finding
15457 DW_MACINFO_start_file. */
15461 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15464 /* Note that we rely on the fact that the corresponding GNU and
15465 DWARF constants are the same. */
15466 switch (macinfo_type
)
15468 /* A zero macinfo type indicates the end of the macro
15473 case DW_MACRO_GNU_define
:
15474 case DW_MACRO_GNU_undef
:
15475 /* Only skip the data by MAC_PTR. */
15477 unsigned int bytes_read
;
15479 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15480 mac_ptr
+= bytes_read
;
15481 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15482 mac_ptr
+= bytes_read
;
15486 case DW_MACRO_GNU_start_file
:
15488 unsigned int bytes_read
;
15491 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15492 mac_ptr
+= bytes_read
;
15493 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15494 mac_ptr
+= bytes_read
;
15496 current_file
= macro_start_file (file
, line
, current_file
,
15497 comp_dir
, lh
, objfile
);
15501 case DW_MACRO_GNU_end_file
:
15502 /* No data to skip by MAC_PTR. */
15505 case DW_MACRO_GNU_define_indirect
:
15506 case DW_MACRO_GNU_undef_indirect
:
15508 unsigned int bytes_read
;
15510 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15511 mac_ptr
+= bytes_read
;
15512 mac_ptr
+= offset_size
;
15516 case DW_MACRO_GNU_transparent_include
:
15517 /* Note that, according to the spec, a transparent include
15518 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15519 skip this opcode. */
15520 mac_ptr
+= offset_size
;
15523 case DW_MACINFO_vendor_ext
:
15524 /* Only skip the data by MAC_PTR. */
15525 if (!section_is_gnu
)
15527 unsigned int bytes_read
;
15529 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15530 mac_ptr
+= bytes_read
;
15531 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15532 mac_ptr
+= bytes_read
;
15537 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15538 mac_ptr
, abfd
, offset_size
,
15540 if (mac_ptr
== NULL
)
15544 } while (macinfo_type
!= 0 && current_file
== NULL
);
15546 /* Second pass: Process all entries.
15548 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15549 command-line macro definitions/undefinitions. This flag is unset when we
15550 reach the first DW_MACINFO_start_file entry. */
15552 dwarf_decode_macro_bytes (abfd
, section
->buffer
+ offset
, mac_end
,
15553 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
15554 offset_size
, objfile
);
15557 /* Check if the attribute's form is a DW_FORM_block*
15558 if so return true else false. */
15560 attr_form_is_block (struct attribute
*attr
)
15562 return (attr
== NULL
? 0 :
15563 attr
->form
== DW_FORM_block1
15564 || attr
->form
== DW_FORM_block2
15565 || attr
->form
== DW_FORM_block4
15566 || attr
->form
== DW_FORM_block
15567 || attr
->form
== DW_FORM_exprloc
);
15570 /* Return non-zero if ATTR's value is a section offset --- classes
15571 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15572 You may use DW_UNSND (attr) to retrieve such offsets.
15574 Section 7.5.4, "Attribute Encodings", explains that no attribute
15575 may have a value that belongs to more than one of these classes; it
15576 would be ambiguous if we did, because we use the same forms for all
15579 attr_form_is_section_offset (struct attribute
*attr
)
15581 return (attr
->form
== DW_FORM_data4
15582 || attr
->form
== DW_FORM_data8
15583 || attr
->form
== DW_FORM_sec_offset
);
15587 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15588 zero otherwise. When this function returns true, you can apply
15589 dwarf2_get_attr_constant_value to it.
15591 However, note that for some attributes you must check
15592 attr_form_is_section_offset before using this test. DW_FORM_data4
15593 and DW_FORM_data8 are members of both the constant class, and of
15594 the classes that contain offsets into other debug sections
15595 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15596 that, if an attribute's can be either a constant or one of the
15597 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15598 taken as section offsets, not constants. */
15600 attr_form_is_constant (struct attribute
*attr
)
15602 switch (attr
->form
)
15604 case DW_FORM_sdata
:
15605 case DW_FORM_udata
:
15606 case DW_FORM_data1
:
15607 case DW_FORM_data2
:
15608 case DW_FORM_data4
:
15609 case DW_FORM_data8
:
15616 /* A helper function that fills in a dwarf2_loclist_baton. */
15619 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15620 struct dwarf2_loclist_baton
*baton
,
15621 struct attribute
*attr
)
15623 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15624 &dwarf2_per_objfile
->loc
);
15626 baton
->per_cu
= cu
->per_cu
;
15627 gdb_assert (baton
->per_cu
);
15628 /* We don't know how long the location list is, but make sure we
15629 don't run off the edge of the section. */
15630 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15631 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15632 baton
->base_address
= cu
->base_address
;
15636 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15637 struct dwarf2_cu
*cu
)
15639 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15641 if (attr_form_is_section_offset (attr
)
15642 /* ".debug_loc" may not exist at all, or the offset may be outside
15643 the section. If so, fall through to the complaint in the
15645 && DW_UNSND (attr
) < dwarf2_section_size (objfile
,
15646 &dwarf2_per_objfile
->loc
))
15648 struct dwarf2_loclist_baton
*baton
;
15650 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15651 sizeof (struct dwarf2_loclist_baton
));
15653 fill_in_loclist_baton (cu
, baton
, attr
);
15655 if (cu
->base_known
== 0)
15656 complaint (&symfile_complaints
,
15657 _("Location list used without "
15658 "specifying the CU base address."));
15660 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15661 SYMBOL_LOCATION_BATON (sym
) = baton
;
15665 struct dwarf2_locexpr_baton
*baton
;
15667 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15668 sizeof (struct dwarf2_locexpr_baton
));
15669 baton
->per_cu
= cu
->per_cu
;
15670 gdb_assert (baton
->per_cu
);
15672 if (attr_form_is_block (attr
))
15674 /* Note that we're just copying the block's data pointer
15675 here, not the actual data. We're still pointing into the
15676 info_buffer for SYM's objfile; right now we never release
15677 that buffer, but when we do clean up properly this may
15679 baton
->size
= DW_BLOCK (attr
)->size
;
15680 baton
->data
= DW_BLOCK (attr
)->data
;
15684 dwarf2_invalid_attrib_class_complaint ("location description",
15685 SYMBOL_NATURAL_NAME (sym
));
15689 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15690 SYMBOL_LOCATION_BATON (sym
) = baton
;
15694 /* Return the OBJFILE associated with the compilation unit CU. If CU
15695 came from a separate debuginfo file, then the master objfile is
15699 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
15701 struct objfile
*objfile
= per_cu
->objfile
;
15703 /* Return the master objfile, so that we can report and look up the
15704 correct file containing this variable. */
15705 if (objfile
->separate_debug_objfile_backlink
)
15706 objfile
= objfile
->separate_debug_objfile_backlink
;
15711 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15712 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15713 CU_HEADERP first. */
15715 static const struct comp_unit_head
*
15716 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
15717 struct dwarf2_per_cu_data
*per_cu
)
15719 struct objfile
*objfile
;
15720 struct dwarf2_per_objfile
*per_objfile
;
15721 gdb_byte
*info_ptr
;
15724 return &per_cu
->cu
->header
;
15726 objfile
= per_cu
->objfile
;
15727 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15728 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
15730 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
15731 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
15736 /* Return the address size given in the compilation unit header for CU. */
15739 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15741 struct comp_unit_head cu_header_local
;
15742 const struct comp_unit_head
*cu_headerp
;
15744 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15746 return cu_headerp
->addr_size
;
15749 /* Return the offset size given in the compilation unit header for CU. */
15752 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
15754 struct comp_unit_head cu_header_local
;
15755 const struct comp_unit_head
*cu_headerp
;
15757 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15759 return cu_headerp
->offset_size
;
15762 /* See its dwarf2loc.h declaration. */
15765 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15767 struct comp_unit_head cu_header_local
;
15768 const struct comp_unit_head
*cu_headerp
;
15770 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15772 if (cu_headerp
->version
== 2)
15773 return cu_headerp
->addr_size
;
15775 return cu_headerp
->offset_size
;
15778 /* Return the text offset of the CU. The returned offset comes from
15779 this CU's objfile. If this objfile came from a separate debuginfo
15780 file, then the offset may be different from the corresponding
15781 offset in the parent objfile. */
15784 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
15786 struct objfile
*objfile
= per_cu
->objfile
;
15788 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15791 /* Locate the .debug_info compilation unit from CU's objfile which contains
15792 the DIE at OFFSET. Raises an error on failure. */
15794 static struct dwarf2_per_cu_data
*
15795 dwarf2_find_containing_comp_unit (unsigned int offset
,
15796 struct objfile
*objfile
)
15798 struct dwarf2_per_cu_data
*this_cu
;
15802 high
= dwarf2_per_objfile
->n_comp_units
- 1;
15805 int mid
= low
+ (high
- low
) / 2;
15807 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
15812 gdb_assert (low
== high
);
15813 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
15816 error (_("Dwarf Error: could not find partial DIE containing "
15817 "offset 0x%lx [in module %s]"),
15818 (long) offset
, bfd_get_filename (objfile
->obfd
));
15820 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
15821 return dwarf2_per_objfile
->all_comp_units
[low
-1];
15825 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
15826 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
15827 && offset
>= this_cu
->offset
+ this_cu
->length
)
15828 error (_("invalid dwarf2 offset %u"), offset
);
15829 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
15834 /* Locate the compilation unit from OBJFILE which is located at exactly
15835 OFFSET. Raises an error on failure. */
15837 static struct dwarf2_per_cu_data
*
15838 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
15840 struct dwarf2_per_cu_data
*this_cu
;
15842 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
15843 if (this_cu
->offset
!= offset
)
15844 error (_("no compilation unit with offset %u."), offset
);
15848 /* Initialize dwarf2_cu CU, owned by PER_CU. */
15851 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
15853 memset (cu
, 0, sizeof (*cu
));
15855 cu
->per_cu
= per_cu
;
15856 cu
->objfile
= per_cu
->objfile
;
15857 obstack_init (&cu
->comp_unit_obstack
);
15860 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15863 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
15865 struct attribute
*attr
;
15867 /* Set the language we're debugging. */
15868 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
15870 set_cu_language (DW_UNSND (attr
), cu
);
15873 cu
->language
= language_minimal
;
15874 cu
->language_defn
= language_def (cu
->language
);
15878 /* Release one cached compilation unit, CU. We unlink it from the tree
15879 of compilation units, but we don't remove it from the read_in_chain;
15880 the caller is responsible for that.
15881 NOTE: DATA is a void * because this function is also used as a
15882 cleanup routine. */
15885 free_heap_comp_unit (void *data
)
15887 struct dwarf2_cu
*cu
= data
;
15889 gdb_assert (cu
->per_cu
!= NULL
);
15890 cu
->per_cu
->cu
= NULL
;
15893 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15898 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15899 when we're finished with it. We can't free the pointer itself, but be
15900 sure to unlink it from the cache. Also release any associated storage
15901 and perform cache maintenance.
15903 Only used during partial symbol parsing. */
15906 free_stack_comp_unit (void *data
)
15908 struct dwarf2_cu
*cu
= data
;
15910 gdb_assert (cu
->per_cu
!= NULL
);
15911 cu
->per_cu
->cu
= NULL
;
15914 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15915 cu
->partial_dies
= NULL
;
15917 /* The previous code only did this if per_cu != NULL.
15918 But that would always succeed, so now we just unconditionally do
15919 the aging. This seems like the wrong place to do such aging,
15920 but cleaning that up is left for later. */
15921 age_cached_comp_units ();
15924 /* Free all cached compilation units. */
15927 free_cached_comp_units (void *data
)
15929 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15931 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15932 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15933 while (per_cu
!= NULL
)
15935 struct dwarf2_per_cu_data
*next_cu
;
15937 next_cu
= per_cu
->cu
->read_in_chain
;
15939 free_heap_comp_unit (per_cu
->cu
);
15940 *last_chain
= next_cu
;
15946 /* Increase the age counter on each cached compilation unit, and free
15947 any that are too old. */
15950 age_cached_comp_units (void)
15952 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15954 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
15955 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15956 while (per_cu
!= NULL
)
15958 per_cu
->cu
->last_used
++;
15959 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
15960 dwarf2_mark (per_cu
->cu
);
15961 per_cu
= per_cu
->cu
->read_in_chain
;
15964 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15965 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15966 while (per_cu
!= NULL
)
15968 struct dwarf2_per_cu_data
*next_cu
;
15970 next_cu
= per_cu
->cu
->read_in_chain
;
15972 if (!per_cu
->cu
->mark
)
15974 free_heap_comp_unit (per_cu
->cu
);
15975 *last_chain
= next_cu
;
15978 last_chain
= &per_cu
->cu
->read_in_chain
;
15984 /* Remove a single compilation unit from the cache. */
15987 free_one_cached_comp_unit (void *target_cu
)
15989 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15991 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15992 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15993 while (per_cu
!= NULL
)
15995 struct dwarf2_per_cu_data
*next_cu
;
15997 next_cu
= per_cu
->cu
->read_in_chain
;
15999 if (per_cu
->cu
== target_cu
)
16001 free_heap_comp_unit (per_cu
->cu
);
16002 *last_chain
= next_cu
;
16006 last_chain
= &per_cu
->cu
->read_in_chain
;
16012 /* Release all extra memory associated with OBJFILE. */
16015 dwarf2_free_objfile (struct objfile
*objfile
)
16017 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16019 if (dwarf2_per_objfile
== NULL
)
16022 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16023 free_cached_comp_units (NULL
);
16025 if (dwarf2_per_objfile
->quick_file_names_table
)
16026 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
16028 /* Everything else should be on the objfile obstack. */
16031 /* A pair of DIE offset and GDB type pointer. We store these
16032 in a hash table separate from the DIEs, and preserve them
16033 when the DIEs are flushed out of cache. */
16035 struct dwarf2_offset_and_type
16037 unsigned int offset
;
16041 /* Hash function for a dwarf2_offset_and_type. */
16044 offset_and_type_hash (const void *item
)
16046 const struct dwarf2_offset_and_type
*ofs
= item
;
16048 return ofs
->offset
;
16051 /* Equality function for a dwarf2_offset_and_type. */
16054 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
16056 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
16057 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
16059 return ofs_lhs
->offset
== ofs_rhs
->offset
;
16062 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16063 table if necessary. For convenience, return TYPE.
16065 The DIEs reading must have careful ordering to:
16066 * Not cause infite loops trying to read in DIEs as a prerequisite for
16067 reading current DIE.
16068 * Not trying to dereference contents of still incompletely read in types
16069 while reading in other DIEs.
16070 * Enable referencing still incompletely read in types just by a pointer to
16071 the type without accessing its fields.
16073 Therefore caller should follow these rules:
16074 * Try to fetch any prerequisite types we may need to build this DIE type
16075 before building the type and calling set_die_type.
16076 * After building type call set_die_type for current DIE as soon as
16077 possible before fetching more types to complete the current type.
16078 * Make the type as complete as possible before fetching more types. */
16080 static struct type
*
16081 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16083 struct dwarf2_offset_and_type
**slot
, ofs
;
16084 struct objfile
*objfile
= cu
->objfile
;
16085 htab_t
*type_hash_ptr
;
16087 /* For Ada types, make sure that the gnat-specific data is always
16088 initialized (if not already set). There are a few types where
16089 we should not be doing so, because the type-specific area is
16090 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16091 where the type-specific area is used to store the floatformat).
16092 But this is not a problem, because the gnat-specific information
16093 is actually not needed for these types. */
16094 if (need_gnat_info (cu
)
16095 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16096 && TYPE_CODE (type
) != TYPE_CODE_FLT
16097 && !HAVE_GNAT_AUX_INFO (type
))
16098 INIT_GNAT_SPECIFIC (type
);
16100 if (cu
->per_cu
->debug_types_section
)
16101 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
16103 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
16105 if (*type_hash_ptr
== NULL
)
16108 = htab_create_alloc_ex (127,
16109 offset_and_type_hash
,
16110 offset_and_type_eq
,
16112 &objfile
->objfile_obstack
,
16113 hashtab_obstack_allocate
,
16114 dummy_obstack_deallocate
);
16117 ofs
.offset
= die
->offset
;
16119 slot
= (struct dwarf2_offset_and_type
**)
16120 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
16122 complaint (&symfile_complaints
,
16123 _("A problem internal to GDB: DIE 0x%x has type already set"),
16125 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16130 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
16131 table, or return NULL if the die does not have a saved type. */
16133 static struct type
*
16134 get_die_type_at_offset (unsigned int offset
,
16135 struct dwarf2_per_cu_data
*per_cu
)
16137 struct dwarf2_offset_and_type
*slot
, ofs
;
16140 if (per_cu
->debug_types_section
)
16141 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
16143 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
16144 if (type_hash
== NULL
)
16147 ofs
.offset
= offset
;
16148 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
16155 /* Look up the type for DIE in the appropriate type_hash table,
16156 or return NULL if DIE does not have a saved type. */
16158 static struct type
*
16159 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16161 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16164 /* Add a dependence relationship from CU to REF_PER_CU. */
16167 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16168 struct dwarf2_per_cu_data
*ref_per_cu
)
16172 if (cu
->dependencies
== NULL
)
16174 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16175 NULL
, &cu
->comp_unit_obstack
,
16176 hashtab_obstack_allocate
,
16177 dummy_obstack_deallocate
);
16179 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16181 *slot
= ref_per_cu
;
16184 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16185 Set the mark field in every compilation unit in the
16186 cache that we must keep because we are keeping CU. */
16189 dwarf2_mark_helper (void **slot
, void *data
)
16191 struct dwarf2_per_cu_data
*per_cu
;
16193 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
16195 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16196 reading of the chain. As such dependencies remain valid it is not much
16197 useful to track and undo them during QUIT cleanups. */
16198 if (per_cu
->cu
== NULL
)
16201 if (per_cu
->cu
->mark
)
16203 per_cu
->cu
->mark
= 1;
16205 if (per_cu
->cu
->dependencies
!= NULL
)
16206 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16211 /* Set the mark field in CU and in every other compilation unit in the
16212 cache that we must keep because we are keeping CU. */
16215 dwarf2_mark (struct dwarf2_cu
*cu
)
16220 if (cu
->dependencies
!= NULL
)
16221 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16225 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
16229 per_cu
->cu
->mark
= 0;
16230 per_cu
= per_cu
->cu
->read_in_chain
;
16234 /* Trivial hash function for partial_die_info: the hash value of a DIE
16235 is its offset in .debug_info for this objfile. */
16238 partial_die_hash (const void *item
)
16240 const struct partial_die_info
*part_die
= item
;
16242 return part_die
->offset
;
16245 /* Trivial comparison function for partial_die_info structures: two DIEs
16246 are equal if they have the same offset. */
16249 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
16251 const struct partial_die_info
*part_die_lhs
= item_lhs
;
16252 const struct partial_die_info
*part_die_rhs
= item_rhs
;
16254 return part_die_lhs
->offset
== part_die_rhs
->offset
;
16257 static struct cmd_list_element
*set_dwarf2_cmdlist
;
16258 static struct cmd_list_element
*show_dwarf2_cmdlist
;
16261 set_dwarf2_cmd (char *args
, int from_tty
)
16263 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
16267 show_dwarf2_cmd (char *args
, int from_tty
)
16269 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
16272 /* If section described by INFO was mmapped, munmap it now. */
16275 munmap_section_buffer (struct dwarf2_section_info
*info
)
16277 if (info
->map_addr
!= NULL
)
16282 res
= munmap (info
->map_addr
, info
->map_len
);
16283 gdb_assert (res
== 0);
16285 /* Without HAVE_MMAP, we should never be here to begin with. */
16286 gdb_assert_not_reached ("no mmap support");
16291 /* munmap debug sections for OBJFILE, if necessary. */
16294 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
16296 struct dwarf2_per_objfile
*data
= d
;
16298 struct dwarf2_section_info
*section
;
16300 /* This is sorted according to the order they're defined in to make it easier
16301 to keep in sync. */
16302 munmap_section_buffer (&data
->info
);
16303 munmap_section_buffer (&data
->abbrev
);
16304 munmap_section_buffer (&data
->line
);
16305 munmap_section_buffer (&data
->loc
);
16306 munmap_section_buffer (&data
->macinfo
);
16307 munmap_section_buffer (&data
->macro
);
16308 munmap_section_buffer (&data
->str
);
16309 munmap_section_buffer (&data
->ranges
);
16310 munmap_section_buffer (&data
->frame
);
16311 munmap_section_buffer (&data
->eh_frame
);
16312 munmap_section_buffer (&data
->gdb_index
);
16315 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
16317 munmap_section_buffer (section
);
16319 VEC_free (dwarf2_section_info_def
, data
->types
);
16323 /* The "save gdb-index" command. */
16325 /* The contents of the hash table we create when building the string
16327 struct strtab_entry
16329 offset_type offset
;
16333 /* Hash function for a strtab_entry.
16335 Function is used only during write_hash_table so no index format backward
16336 compatibility is needed. */
16339 hash_strtab_entry (const void *e
)
16341 const struct strtab_entry
*entry
= e
;
16342 return mapped_index_string_hash (INT_MAX
, entry
->str
);
16345 /* Equality function for a strtab_entry. */
16348 eq_strtab_entry (const void *a
, const void *b
)
16350 const struct strtab_entry
*ea
= a
;
16351 const struct strtab_entry
*eb
= b
;
16352 return !strcmp (ea
->str
, eb
->str
);
16355 /* Create a strtab_entry hash table. */
16358 create_strtab (void)
16360 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
16361 xfree
, xcalloc
, xfree
);
16364 /* Add a string to the constant pool. Return the string's offset in
16368 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
16371 struct strtab_entry entry
;
16372 struct strtab_entry
*result
;
16375 slot
= htab_find_slot (table
, &entry
, INSERT
);
16380 result
= XNEW (struct strtab_entry
);
16381 result
->offset
= obstack_object_size (cpool
);
16383 obstack_grow_str0 (cpool
, str
);
16386 return result
->offset
;
16389 /* An entry in the symbol table. */
16390 struct symtab_index_entry
16392 /* The name of the symbol. */
16394 /* The offset of the name in the constant pool. */
16395 offset_type index_offset
;
16396 /* A sorted vector of the indices of all the CUs that hold an object
16398 VEC (offset_type
) *cu_indices
;
16401 /* The symbol table. This is a power-of-2-sized hash table. */
16402 struct mapped_symtab
16404 offset_type n_elements
;
16406 struct symtab_index_entry
**data
;
16409 /* Hash function for a symtab_index_entry. */
16412 hash_symtab_entry (const void *e
)
16414 const struct symtab_index_entry
*entry
= e
;
16415 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
16416 sizeof (offset_type
) * VEC_length (offset_type
,
16417 entry
->cu_indices
),
16421 /* Equality function for a symtab_index_entry. */
16424 eq_symtab_entry (const void *a
, const void *b
)
16426 const struct symtab_index_entry
*ea
= a
;
16427 const struct symtab_index_entry
*eb
= b
;
16428 int len
= VEC_length (offset_type
, ea
->cu_indices
);
16429 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
16431 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
16432 VEC_address (offset_type
, eb
->cu_indices
),
16433 sizeof (offset_type
) * len
);
16436 /* Destroy a symtab_index_entry. */
16439 delete_symtab_entry (void *p
)
16441 struct symtab_index_entry
*entry
= p
;
16442 VEC_free (offset_type
, entry
->cu_indices
);
16446 /* Create a hash table holding symtab_index_entry objects. */
16449 create_symbol_hash_table (void)
16451 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
16452 delete_symtab_entry
, xcalloc
, xfree
);
16455 /* Create a new mapped symtab object. */
16457 static struct mapped_symtab
*
16458 create_mapped_symtab (void)
16460 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
16461 symtab
->n_elements
= 0;
16462 symtab
->size
= 1024;
16463 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16467 /* Destroy a mapped_symtab. */
16470 cleanup_mapped_symtab (void *p
)
16472 struct mapped_symtab
*symtab
= p
;
16473 /* The contents of the array are freed when the other hash table is
16475 xfree (symtab
->data
);
16479 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16482 Function is used only during write_hash_table so no index format backward
16483 compatibility is needed. */
16485 static struct symtab_index_entry
**
16486 find_slot (struct mapped_symtab
*symtab
, const char *name
)
16488 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
16490 index
= hash
& (symtab
->size
- 1);
16491 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
16495 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
16496 return &symtab
->data
[index
];
16497 index
= (index
+ step
) & (symtab
->size
- 1);
16501 /* Expand SYMTAB's hash table. */
16504 hash_expand (struct mapped_symtab
*symtab
)
16506 offset_type old_size
= symtab
->size
;
16508 struct symtab_index_entry
**old_entries
= symtab
->data
;
16511 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16513 for (i
= 0; i
< old_size
; ++i
)
16515 if (old_entries
[i
])
16517 struct symtab_index_entry
**slot
= find_slot (symtab
,
16518 old_entries
[i
]->name
);
16519 *slot
= old_entries
[i
];
16523 xfree (old_entries
);
16526 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16527 is the index of the CU in which the symbol appears. */
16530 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
16531 offset_type cu_index
)
16533 struct symtab_index_entry
**slot
;
16535 ++symtab
->n_elements
;
16536 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
16537 hash_expand (symtab
);
16539 slot
= find_slot (symtab
, name
);
16542 *slot
= XNEW (struct symtab_index_entry
);
16543 (*slot
)->name
= name
;
16544 (*slot
)->cu_indices
= NULL
;
16546 /* Don't push an index twice. Due to how we add entries we only
16547 have to check the last one. */
16548 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
16549 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
16550 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
16553 /* Add a vector of indices to the constant pool. */
16556 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
16557 struct symtab_index_entry
*entry
)
16561 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
16564 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
16565 offset_type val
= MAYBE_SWAP (len
);
16570 entry
->index_offset
= obstack_object_size (cpool
);
16572 obstack_grow (cpool
, &val
, sizeof (val
));
16574 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
16577 val
= MAYBE_SWAP (iter
);
16578 obstack_grow (cpool
, &val
, sizeof (val
));
16583 struct symtab_index_entry
*old_entry
= *slot
;
16584 entry
->index_offset
= old_entry
->index_offset
;
16587 return entry
->index_offset
;
16590 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16591 constant pool entries going into the obstack CPOOL. */
16594 write_hash_table (struct mapped_symtab
*symtab
,
16595 struct obstack
*output
, struct obstack
*cpool
)
16598 htab_t symbol_hash_table
;
16601 symbol_hash_table
= create_symbol_hash_table ();
16602 str_table
= create_strtab ();
16604 /* We add all the index vectors to the constant pool first, to
16605 ensure alignment is ok. */
16606 for (i
= 0; i
< symtab
->size
; ++i
)
16608 if (symtab
->data
[i
])
16609 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
16612 /* Now write out the hash table. */
16613 for (i
= 0; i
< symtab
->size
; ++i
)
16615 offset_type str_off
, vec_off
;
16617 if (symtab
->data
[i
])
16619 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
16620 vec_off
= symtab
->data
[i
]->index_offset
;
16624 /* While 0 is a valid constant pool index, it is not valid
16625 to have 0 for both offsets. */
16630 str_off
= MAYBE_SWAP (str_off
);
16631 vec_off
= MAYBE_SWAP (vec_off
);
16633 obstack_grow (output
, &str_off
, sizeof (str_off
));
16634 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
16637 htab_delete (str_table
);
16638 htab_delete (symbol_hash_table
);
16641 /* Struct to map psymtab to CU index in the index file. */
16642 struct psymtab_cu_index_map
16644 struct partial_symtab
*psymtab
;
16645 unsigned int cu_index
;
16649 hash_psymtab_cu_index (const void *item
)
16651 const struct psymtab_cu_index_map
*map
= item
;
16653 return htab_hash_pointer (map
->psymtab
);
16657 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16659 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16660 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16662 return lhs
->psymtab
== rhs
->psymtab
;
16665 /* Helper struct for building the address table. */
16666 struct addrmap_index_data
16668 struct objfile
*objfile
;
16669 struct obstack
*addr_obstack
;
16670 htab_t cu_index_htab
;
16672 /* Non-zero if the previous_* fields are valid.
16673 We can't write an entry until we see the next entry (since it is only then
16674 that we know the end of the entry). */
16675 int previous_valid
;
16676 /* Index of the CU in the table of all CUs in the index file. */
16677 unsigned int previous_cu_index
;
16678 /* Start address of the CU. */
16679 CORE_ADDR previous_cu_start
;
16682 /* Write an address entry to OBSTACK. */
16685 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16686 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16688 offset_type cu_index_to_write
;
16690 CORE_ADDR baseaddr
;
16692 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16694 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16695 obstack_grow (obstack
, addr
, 8);
16696 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16697 obstack_grow (obstack
, addr
, 8);
16698 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16699 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16702 /* Worker function for traversing an addrmap to build the address table. */
16705 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
16707 struct addrmap_index_data
*data
= datap
;
16708 struct partial_symtab
*pst
= obj
;
16709 offset_type cu_index
;
16712 if (data
->previous_valid
)
16713 add_address_entry (data
->objfile
, data
->addr_obstack
,
16714 data
->previous_cu_start
, start_addr
,
16715 data
->previous_cu_index
);
16717 data
->previous_cu_start
= start_addr
;
16720 struct psymtab_cu_index_map find_map
, *map
;
16721 find_map
.psymtab
= pst
;
16722 map
= htab_find (data
->cu_index_htab
, &find_map
);
16723 gdb_assert (map
!= NULL
);
16724 data
->previous_cu_index
= map
->cu_index
;
16725 data
->previous_valid
= 1;
16728 data
->previous_valid
= 0;
16733 /* Write OBJFILE's address map to OBSTACK.
16734 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16735 in the index file. */
16738 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
16739 htab_t cu_index_htab
)
16741 struct addrmap_index_data addrmap_index_data
;
16743 /* When writing the address table, we have to cope with the fact that
16744 the addrmap iterator only provides the start of a region; we have to
16745 wait until the next invocation to get the start of the next region. */
16747 addrmap_index_data
.objfile
= objfile
;
16748 addrmap_index_data
.addr_obstack
= obstack
;
16749 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
16750 addrmap_index_data
.previous_valid
= 0;
16752 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
16753 &addrmap_index_data
);
16755 /* It's highly unlikely the last entry (end address = 0xff...ff)
16756 is valid, but we should still handle it.
16757 The end address is recorded as the start of the next region, but that
16758 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16760 if (addrmap_index_data
.previous_valid
)
16761 add_address_entry (objfile
, obstack
,
16762 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
16763 addrmap_index_data
.previous_cu_index
);
16766 /* Add a list of partial symbols to SYMTAB. */
16769 write_psymbols (struct mapped_symtab
*symtab
,
16771 struct partial_symbol
**psymp
,
16773 offset_type cu_index
,
16776 for (; count
-- > 0; ++psymp
)
16778 void **slot
, *lookup
;
16780 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
16781 error (_("Ada is not currently supported by the index"));
16783 /* We only want to add a given psymbol once. However, we also
16784 want to account for whether it is global or static. So, we
16785 may add it twice, using slightly different values. */
16788 uintptr_t val
= 1 | (uintptr_t) *psymp
;
16790 lookup
= (void *) val
;
16795 /* Only add a given psymbol once. */
16796 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
16800 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (*psymp
), cu_index
);
16805 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16806 exception if there is an error. */
16809 write_obstack (FILE *file
, struct obstack
*obstack
)
16811 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
16813 != obstack_object_size (obstack
))
16814 error (_("couldn't data write to file"));
16817 /* Unlink a file if the argument is not NULL. */
16820 unlink_if_set (void *p
)
16822 char **filename
= p
;
16824 unlink (*filename
);
16827 /* A helper struct used when iterating over debug_types. */
16828 struct signatured_type_index_data
16830 struct objfile
*objfile
;
16831 struct mapped_symtab
*symtab
;
16832 struct obstack
*types_list
;
16837 /* A helper function that writes a single signatured_type to an
16841 write_one_signatured_type (void **slot
, void *d
)
16843 struct signatured_type_index_data
*info
= d
;
16844 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
16845 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
16846 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16849 write_psymbols (info
->symtab
,
16851 info
->objfile
->global_psymbols
.list
16852 + psymtab
->globals_offset
,
16853 psymtab
->n_global_syms
, info
->cu_index
,
16855 write_psymbols (info
->symtab
,
16857 info
->objfile
->static_psymbols
.list
16858 + psymtab
->statics_offset
,
16859 psymtab
->n_static_syms
, info
->cu_index
,
16862 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->per_cu
.offset
);
16863 obstack_grow (info
->types_list
, val
, 8);
16864 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
16865 obstack_grow (info
->types_list
, val
, 8);
16866 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
16867 obstack_grow (info
->types_list
, val
, 8);
16874 /* Create an index file for OBJFILE in the directory DIR. */
16877 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
16879 struct cleanup
*cleanup
;
16880 char *filename
, *cleanup_filename
;
16881 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
16882 struct obstack cu_list
, types_cu_list
;
16885 struct mapped_symtab
*symtab
;
16886 offset_type val
, size_of_contents
, total_len
;
16890 htab_t cu_index_htab
;
16891 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
16893 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
16896 if (dwarf2_per_objfile
->using_index
)
16897 error (_("Cannot use an index to create the index"));
16899 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
16900 error (_("Cannot make an index when the file has multiple .debug_types sections"));
16902 if (stat (objfile
->name
, &st
) < 0)
16903 perror_with_name (objfile
->name
);
16905 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
16906 INDEX_SUFFIX
, (char *) NULL
);
16907 cleanup
= make_cleanup (xfree
, filename
);
16909 out_file
= fopen (filename
, "wb");
16911 error (_("Can't open `%s' for writing"), filename
);
16913 cleanup_filename
= filename
;
16914 make_cleanup (unlink_if_set
, &cleanup_filename
);
16916 symtab
= create_mapped_symtab ();
16917 make_cleanup (cleanup_mapped_symtab
, symtab
);
16919 obstack_init (&addr_obstack
);
16920 make_cleanup_obstack_free (&addr_obstack
);
16922 obstack_init (&cu_list
);
16923 make_cleanup_obstack_free (&cu_list
);
16925 obstack_init (&types_cu_list
);
16926 make_cleanup_obstack_free (&types_cu_list
);
16928 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
16929 NULL
, xcalloc
, xfree
);
16930 make_cleanup_htab_delete (psyms_seen
);
16932 /* While we're scanning CU's create a table that maps a psymtab pointer
16933 (which is what addrmap records) to its index (which is what is recorded
16934 in the index file). This will later be needed to write the address
16936 cu_index_htab
= htab_create_alloc (100,
16937 hash_psymtab_cu_index
,
16938 eq_psymtab_cu_index
,
16939 NULL
, xcalloc
, xfree
);
16940 make_cleanup_htab_delete (cu_index_htab
);
16941 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
16942 xmalloc (sizeof (struct psymtab_cu_index_map
)
16943 * dwarf2_per_objfile
->n_comp_units
);
16944 make_cleanup (xfree
, psymtab_cu_index_map
);
16946 /* The CU list is already sorted, so we don't need to do additional
16947 work here. Also, the debug_types entries do not appear in
16948 all_comp_units, but only in their own hash table. */
16949 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
16951 struct dwarf2_per_cu_data
*per_cu
16952 = dwarf2_per_objfile
->all_comp_units
[i
];
16953 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16955 struct psymtab_cu_index_map
*map
;
16958 write_psymbols (symtab
,
16960 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
16961 psymtab
->n_global_syms
, i
,
16963 write_psymbols (symtab
,
16965 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
16966 psymtab
->n_static_syms
, i
,
16969 map
= &psymtab_cu_index_map
[i
];
16970 map
->psymtab
= psymtab
;
16972 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
16973 gdb_assert (slot
!= NULL
);
16974 gdb_assert (*slot
== NULL
);
16977 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
16978 obstack_grow (&cu_list
, val
, 8);
16979 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
16980 obstack_grow (&cu_list
, val
, 8);
16983 /* Dump the address map. */
16984 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
16986 /* Write out the .debug_type entries, if any. */
16987 if (dwarf2_per_objfile
->signatured_types
)
16989 struct signatured_type_index_data sig_data
;
16991 sig_data
.objfile
= objfile
;
16992 sig_data
.symtab
= symtab
;
16993 sig_data
.types_list
= &types_cu_list
;
16994 sig_data
.psyms_seen
= psyms_seen
;
16995 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
16996 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
16997 write_one_signatured_type
, &sig_data
);
17000 obstack_init (&constant_pool
);
17001 make_cleanup_obstack_free (&constant_pool
);
17002 obstack_init (&symtab_obstack
);
17003 make_cleanup_obstack_free (&symtab_obstack
);
17004 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
17006 obstack_init (&contents
);
17007 make_cleanup_obstack_free (&contents
);
17008 size_of_contents
= 6 * sizeof (offset_type
);
17009 total_len
= size_of_contents
;
17011 /* The version number. */
17012 val
= MAYBE_SWAP (5);
17013 obstack_grow (&contents
, &val
, sizeof (val
));
17015 /* The offset of the CU list from the start of the file. */
17016 val
= MAYBE_SWAP (total_len
);
17017 obstack_grow (&contents
, &val
, sizeof (val
));
17018 total_len
+= obstack_object_size (&cu_list
);
17020 /* The offset of the types CU list from the start of the file. */
17021 val
= MAYBE_SWAP (total_len
);
17022 obstack_grow (&contents
, &val
, sizeof (val
));
17023 total_len
+= obstack_object_size (&types_cu_list
);
17025 /* The offset of the address table from the start of the file. */
17026 val
= MAYBE_SWAP (total_len
);
17027 obstack_grow (&contents
, &val
, sizeof (val
));
17028 total_len
+= obstack_object_size (&addr_obstack
);
17030 /* The offset of the symbol table from the start of the file. */
17031 val
= MAYBE_SWAP (total_len
);
17032 obstack_grow (&contents
, &val
, sizeof (val
));
17033 total_len
+= obstack_object_size (&symtab_obstack
);
17035 /* The offset of the constant pool from the start of the file. */
17036 val
= MAYBE_SWAP (total_len
);
17037 obstack_grow (&contents
, &val
, sizeof (val
));
17038 total_len
+= obstack_object_size (&constant_pool
);
17040 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
17042 write_obstack (out_file
, &contents
);
17043 write_obstack (out_file
, &cu_list
);
17044 write_obstack (out_file
, &types_cu_list
);
17045 write_obstack (out_file
, &addr_obstack
);
17046 write_obstack (out_file
, &symtab_obstack
);
17047 write_obstack (out_file
, &constant_pool
);
17051 /* We want to keep the file, so we set cleanup_filename to NULL
17052 here. See unlink_if_set. */
17053 cleanup_filename
= NULL
;
17055 do_cleanups (cleanup
);
17058 /* Implementation of the `save gdb-index' command.
17060 Note that the file format used by this command is documented in the
17061 GDB manual. Any changes here must be documented there. */
17064 save_gdb_index_command (char *arg
, int from_tty
)
17066 struct objfile
*objfile
;
17069 error (_("usage: save gdb-index DIRECTORY"));
17071 ALL_OBJFILES (objfile
)
17075 /* If the objfile does not correspond to an actual file, skip it. */
17076 if (stat (objfile
->name
, &st
) < 0)
17079 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17080 if (dwarf2_per_objfile
)
17082 volatile struct gdb_exception except
;
17084 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17086 write_psymtabs_to_index (objfile
, arg
);
17088 if (except
.reason
< 0)
17089 exception_fprintf (gdb_stderr
, except
,
17090 _("Error while writing index for `%s': "),
17098 int dwarf2_always_disassemble
;
17101 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17102 struct cmd_list_element
*c
, const char *value
)
17104 fprintf_filtered (file
,
17105 _("Whether to always disassemble "
17106 "DWARF expressions is %s.\n"),
17111 show_check_physname (struct ui_file
*file
, int from_tty
,
17112 struct cmd_list_element
*c
, const char *value
)
17114 fprintf_filtered (file
,
17115 _("Whether to check \"physname\" is %s.\n"),
17119 void _initialize_dwarf2_read (void);
17122 _initialize_dwarf2_read (void)
17124 struct cmd_list_element
*c
;
17126 dwarf2_objfile_data_key
17127 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17129 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17130 Set DWARF 2 specific variables.\n\
17131 Configure DWARF 2 variables such as the cache size"),
17132 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17133 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17135 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17136 Show DWARF 2 specific variables\n\
17137 Show DWARF 2 variables such as the cache size"),
17138 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17139 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17141 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17142 &dwarf2_max_cache_age
, _("\
17143 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17144 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17145 A higher limit means that cached compilation units will be stored\n\
17146 in memory longer, and more total memory will be used. Zero disables\n\
17147 caching, which can slow down startup."),
17149 show_dwarf2_max_cache_age
,
17150 &set_dwarf2_cmdlist
,
17151 &show_dwarf2_cmdlist
);
17153 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17154 &dwarf2_always_disassemble
, _("\
17155 Set whether `info address' always disassembles DWARF expressions."), _("\
17156 Show whether `info address' always disassembles DWARF expressions."), _("\
17157 When enabled, DWARF expressions are always printed in an assembly-like\n\
17158 syntax. When disabled, expressions will be printed in a more\n\
17159 conversational style, when possible."),
17161 show_dwarf2_always_disassemble
,
17162 &set_dwarf2_cmdlist
,
17163 &show_dwarf2_cmdlist
);
17165 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
17166 Set debugging of the dwarf2 DIE reader."), _("\
17167 Show debugging of the dwarf2 DIE reader."), _("\
17168 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17169 The value is the maximum depth to print."),
17172 &setdebuglist
, &showdebuglist
);
17174 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
17175 Set cross-checking of \"physname\" code against demangler."), _("\
17176 Show cross-checking of \"physname\" code against demangler."), _("\
17177 When enabled, GDB's internal \"physname\" code is checked against\n\
17179 NULL
, show_check_physname
,
17180 &setdebuglist
, &showdebuglist
);
17182 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
17184 Save a gdb-index file.\n\
17185 Usage: save gdb-index DIRECTORY"),
17187 set_cmd_completer (c
, filename_completer
);