1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
51 #include "typeprint.h"
54 #include "exceptions.h"
56 #include "completer.h"
63 #include "gdb_string.h"
64 #include "gdb_assert.h"
65 #include <sys/types.h>
72 #define MAP_FAILED ((void *) -1)
76 typedef struct symbol
*symbolp
;
80 /* .debug_info header for a compilation unit
81 Because of alignment constraints, this structure has padding and cannot
82 be mapped directly onto the beginning of the .debug_info section. */
83 typedef struct comp_unit_header
85 unsigned int length
; /* length of the .debug_info
87 unsigned short version
; /* version number -- 2 for DWARF
89 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
90 unsigned char addr_size
; /* byte size of an address -- 4 */
93 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
96 /* .debug_line statement program prologue
97 Because of alignment constraints, this structure has padding and cannot
98 be mapped directly onto the beginning of the .debug_info section. */
99 typedef struct statement_prologue
101 unsigned int total_length
; /* byte length of the statement
103 unsigned short version
; /* version number -- 2 for DWARF
105 unsigned int prologue_length
; /* # bytes between prologue &
107 unsigned char minimum_instruction_length
; /* byte size of
109 unsigned char default_is_stmt
; /* initial value of is_stmt
112 unsigned char line_range
;
113 unsigned char opcode_base
; /* number assigned to first special
115 unsigned char *standard_opcode_lengths
;
119 /* When non-zero, dump DIEs after they are read in. */
120 static int dwarf2_die_debug
= 0;
122 /* When non-zero, cross-check physname against demangler. */
123 static int check_physname
= 0;
127 /* When set, the file that we're processing is known to have debugging
128 info for C++ namespaces. GCC 3.3.x did not produce this information,
129 but later versions do. */
131 static int processing_has_namespace_info
;
133 static const struct objfile_data
*dwarf2_objfile_data_key
;
135 struct dwarf2_section_info
140 /* Not NULL if the section was actually mmapped. */
142 /* Page aligned size of mmapped area. */
143 bfd_size_type map_len
;
144 /* True if we have tried to read this section. */
148 typedef struct dwarf2_section_info dwarf2_section_info_def
;
149 DEF_VEC_O (dwarf2_section_info_def
);
151 /* All offsets in the index are of this type. It must be
152 architecture-independent. */
153 typedef uint32_t offset_type
;
155 DEF_VEC_I (offset_type
);
157 /* A description of the mapped index. The file format is described in
158 a comment by the code that writes the index. */
161 /* Index data format version. */
164 /* The total length of the buffer. */
167 /* A pointer to the address table data. */
168 const gdb_byte
*address_table
;
170 /* Size of the address table data in bytes. */
171 offset_type address_table_size
;
173 /* The symbol table, implemented as a hash table. */
174 const offset_type
*symbol_table
;
176 /* Size in slots, each slot is 2 offset_types. */
177 offset_type symbol_table_slots
;
179 /* A pointer to the constant pool. */
180 const char *constant_pool
;
183 struct dwarf2_per_objfile
185 struct dwarf2_section_info info
;
186 struct dwarf2_section_info abbrev
;
187 struct dwarf2_section_info line
;
188 struct dwarf2_section_info loc
;
189 struct dwarf2_section_info macinfo
;
190 struct dwarf2_section_info macro
;
191 struct dwarf2_section_info str
;
192 struct dwarf2_section_info ranges
;
193 struct dwarf2_section_info frame
;
194 struct dwarf2_section_info eh_frame
;
195 struct dwarf2_section_info gdb_index
;
197 VEC (dwarf2_section_info_def
) *types
;
200 struct objfile
*objfile
;
202 /* A list of all the compilation units. This is used to locate
203 the target compilation unit of a particular reference. */
204 struct dwarf2_per_cu_data
**all_comp_units
;
206 /* The number of compilation units in ALL_COMP_UNITS. */
209 /* The number of .debug_types-related CUs. */
210 int n_type_comp_units
;
212 /* The .debug_types-related CUs. */
213 struct dwarf2_per_cu_data
**type_comp_units
;
215 /* A chain of compilation units that are currently read in, so that
216 they can be freed later. */
217 struct dwarf2_per_cu_data
*read_in_chain
;
219 /* A table mapping .debug_types signatures to its signatured_type entry.
220 This is NULL if the .debug_types section hasn't been read in yet. */
221 htab_t signatured_types
;
223 /* A flag indicating wether this objfile has a section loaded at a
225 int has_section_at_zero
;
227 /* True if we are using the mapped index,
228 or we are faking it for OBJF_READNOW's sake. */
229 unsigned char using_index
;
231 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
232 struct mapped_index
*index_table
;
234 /* When using index_table, this keeps track of all quick_file_names entries.
235 TUs can share line table entries with CUs or other TUs, and there can be
236 a lot more TUs than unique line tables, so we maintain a separate table
237 of all line table entries to support the sharing. */
238 htab_t quick_file_names_table
;
240 /* Set during partial symbol reading, to prevent queueing of full
242 int reading_partial_symbols
;
244 /* Table mapping type .debug_info DIE offsets to types.
245 This is NULL if not allocated yet.
246 It (currently) makes sense to allocate debug_types_type_hash lazily.
247 To keep things simple we allocate both lazily. */
248 htab_t debug_info_type_hash
;
250 /* Table mapping type .debug_types DIE offsets to types.
251 This is NULL if not allocated yet. */
252 htab_t debug_types_type_hash
;
255 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
257 /* Default names of the debugging sections. */
259 /* Note that if the debugging section has been compressed, it might
260 have a name like .zdebug_info. */
262 static const struct dwarf2_debug_sections dwarf2_elf_names
= {
263 { ".debug_info", ".zdebug_info" },
264 { ".debug_abbrev", ".zdebug_abbrev" },
265 { ".debug_line", ".zdebug_line" },
266 { ".debug_loc", ".zdebug_loc" },
267 { ".debug_macinfo", ".zdebug_macinfo" },
268 { ".debug_macro", ".zdebug_macro" },
269 { ".debug_str", ".zdebug_str" },
270 { ".debug_ranges", ".zdebug_ranges" },
271 { ".debug_types", ".zdebug_types" },
272 { ".debug_frame", ".zdebug_frame" },
273 { ".eh_frame", NULL
},
274 { ".gdb_index", ".zgdb_index" },
278 /* local data types */
280 /* We hold several abbreviation tables in memory at the same time. */
281 #ifndef ABBREV_HASH_SIZE
282 #define ABBREV_HASH_SIZE 121
285 /* The data in a compilation unit header, after target2host
286 translation, looks like this. */
287 struct comp_unit_head
291 unsigned char addr_size
;
292 unsigned char signed_addr_p
;
293 unsigned int abbrev_offset
;
295 /* Size of file offsets; either 4 or 8. */
296 unsigned int offset_size
;
298 /* Size of the length field; either 4 or 12. */
299 unsigned int initial_length_size
;
301 /* Offset to the first byte of this compilation unit header in the
302 .debug_info section, for resolving relative reference dies. */
305 /* Offset to first die in this cu from the start of the cu.
306 This will be the first byte following the compilation unit header. */
307 unsigned int first_die_offset
;
310 /* Type used for delaying computation of method physnames.
311 See comments for compute_delayed_physnames. */
312 struct delayed_method_info
314 /* The type to which the method is attached, i.e., its parent class. */
317 /* The index of the method in the type's function fieldlists. */
320 /* The index of the method in the fieldlist. */
323 /* The name of the DIE. */
326 /* The DIE associated with this method. */
327 struct die_info
*die
;
330 typedef struct delayed_method_info delayed_method_info
;
331 DEF_VEC_O (delayed_method_info
);
333 /* Internal state when decoding a particular compilation unit. */
336 /* The objfile containing this compilation unit. */
337 struct objfile
*objfile
;
339 /* The header of the compilation unit. */
340 struct comp_unit_head header
;
342 /* Base address of this compilation unit. */
343 CORE_ADDR base_address
;
345 /* Non-zero if base_address has been set. */
348 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
350 /* The language we are debugging. */
351 enum language language
;
352 const struct language_defn
*language_defn
;
354 const char *producer
;
356 /* The generic symbol table building routines have separate lists for
357 file scope symbols and all all other scopes (local scopes). So
358 we need to select the right one to pass to add_symbol_to_list().
359 We do it by keeping a pointer to the correct list in list_in_scope.
361 FIXME: The original dwarf code just treated the file scope as the
362 first local scope, and all other local scopes as nested local
363 scopes, and worked fine. Check to see if we really need to
364 distinguish these in buildsym.c. */
365 struct pending
**list_in_scope
;
367 /* DWARF abbreviation table associated with this compilation unit. */
368 struct abbrev_info
**dwarf2_abbrevs
;
370 /* Storage for the abbrev table. */
371 struct obstack abbrev_obstack
;
373 /* Hash table holding all the loaded partial DIEs. */
376 /* Storage for things with the same lifetime as this read-in compilation
377 unit, including partial DIEs. */
378 struct obstack comp_unit_obstack
;
380 /* When multiple dwarf2_cu structures are living in memory, this field
381 chains them all together, so that they can be released efficiently.
382 We will probably also want a generation counter so that most-recently-used
383 compilation units are cached... */
384 struct dwarf2_per_cu_data
*read_in_chain
;
386 /* Backchain to our per_cu entry if the tree has been built. */
387 struct dwarf2_per_cu_data
*per_cu
;
389 /* How many compilation units ago was this CU last referenced? */
392 /* A hash table of die offsets for following references. */
395 /* Full DIEs if read in. */
396 struct die_info
*dies
;
398 /* A set of pointers to dwarf2_per_cu_data objects for compilation
399 units referenced by this one. Only set during full symbol processing;
400 partial symbol tables do not have dependencies. */
403 /* Header data from the line table, during full symbol processing. */
404 struct line_header
*line_header
;
406 /* A list of methods which need to have physnames computed
407 after all type information has been read. */
408 VEC (delayed_method_info
) *method_list
;
410 /* Mark used when releasing cached dies. */
411 unsigned int mark
: 1;
413 /* This flag will be set if this compilation unit might include
414 inter-compilation-unit references. */
415 unsigned int has_form_ref_addr
: 1;
417 /* This flag will be set if this compilation unit includes any
418 DW_TAG_namespace DIEs. If we know that there are explicit
419 DIEs for namespaces, we don't need to try to infer them
420 from mangled names. */
421 unsigned int has_namespace_info
: 1;
423 /* This CU references .debug_loc. See the symtab->locations_valid field.
424 This test is imperfect as there may exist optimized debug code not using
425 any location list and still facing inlining issues if handled as
426 unoptimized code. For a future better test see GCC PR other/32998. */
428 unsigned int has_loclist
: 1;
431 /* Persistent data held for a compilation unit, even when not
432 processing it. We put a pointer to this structure in the
433 read_symtab_private field of the psymtab. If we encounter
434 inter-compilation-unit references, we also maintain a sorted
435 list of all compilation units. */
437 struct dwarf2_per_cu_data
439 /* The start offset and length of this compilation unit. 2**29-1
440 bytes should suffice to store the length of any compilation unit
441 - if it doesn't, GDB will fall over anyway.
442 NOTE: Unlike comp_unit_head.length, this length includes
443 initial_length_size. */
445 unsigned int length
: 29;
447 /* Flag indicating this compilation unit will be read in before
448 any of the current compilation units are processed. */
449 unsigned int queued
: 1;
451 /* This flag will be set if we need to load absolutely all DIEs
452 for this compilation unit, instead of just the ones we think
453 are interesting. It gets set if we look for a DIE in the
454 hash table and don't find it. */
455 unsigned int load_all_dies
: 1;
457 /* Non-null if this CU is from .debug_types; in which case it points
458 to the section. Otherwise it's from .debug_info. */
459 struct dwarf2_section_info
*debug_type_section
;
461 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
462 of the CU cache it gets reset to NULL again. */
463 struct dwarf2_cu
*cu
;
465 /* The corresponding objfile. */
466 struct objfile
*objfile
;
468 /* When using partial symbol tables, the 'psymtab' field is active.
469 Otherwise the 'quick' field is active. */
472 /* The partial symbol table associated with this compilation unit,
473 or NULL for partial units (which do not have an associated
475 struct partial_symtab
*psymtab
;
477 /* Data needed by the "quick" functions. */
478 struct dwarf2_per_cu_quick_data
*quick
;
482 /* Entry in the signatured_types hash table. */
484 struct signatured_type
488 /* Offset in .debug_types of the type defined by this TU. */
489 unsigned int type_offset
;
491 /* The CU(/TU) of this type. */
492 struct dwarf2_per_cu_data per_cu
;
495 /* Struct used to pass misc. parameters to read_die_and_children, et
496 al. which are used for both .debug_info and .debug_types dies.
497 All parameters here are unchanging for the life of the call. This
498 struct exists to abstract away the constant parameters of die
501 struct die_reader_specs
503 /* The bfd of this objfile. */
506 /* The CU of the DIE we are parsing. */
507 struct dwarf2_cu
*cu
;
509 /* Pointer to start of section buffer.
510 This is either the start of .debug_info or .debug_types. */
511 const gdb_byte
*buffer
;
514 /* The line number information for a compilation unit (found in the
515 .debug_line section) begins with a "statement program header",
516 which contains the following information. */
519 unsigned int total_length
;
520 unsigned short version
;
521 unsigned int header_length
;
522 unsigned char minimum_instruction_length
;
523 unsigned char maximum_ops_per_instruction
;
524 unsigned char default_is_stmt
;
526 unsigned char line_range
;
527 unsigned char opcode_base
;
529 /* standard_opcode_lengths[i] is the number of operands for the
530 standard opcode whose value is i. This means that
531 standard_opcode_lengths[0] is unused, and the last meaningful
532 element is standard_opcode_lengths[opcode_base - 1]. */
533 unsigned char *standard_opcode_lengths
;
535 /* The include_directories table. NOTE! These strings are not
536 allocated with xmalloc; instead, they are pointers into
537 debug_line_buffer. If you try to free them, `free' will get
539 unsigned int num_include_dirs
, include_dirs_size
;
542 /* The file_names table. NOTE! These strings are not allocated
543 with xmalloc; instead, they are pointers into debug_line_buffer.
544 Don't try to free them directly. */
545 unsigned int num_file_names
, file_names_size
;
549 unsigned int dir_index
;
550 unsigned int mod_time
;
552 int included_p
; /* Non-zero if referenced by the Line Number Program. */
553 struct symtab
*symtab
; /* The associated symbol table, if any. */
556 /* The start and end of the statement program following this
557 header. These point into dwarf2_per_objfile->line_buffer. */
558 gdb_byte
*statement_program_start
, *statement_program_end
;
561 /* When we construct a partial symbol table entry we only
562 need this much information. */
563 struct partial_die_info
565 /* Offset of this DIE. */
568 /* DWARF-2 tag for this DIE. */
569 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
571 /* Assorted flags describing the data found in this DIE. */
572 unsigned int has_children
: 1;
573 unsigned int is_external
: 1;
574 unsigned int is_declaration
: 1;
575 unsigned int has_type
: 1;
576 unsigned int has_specification
: 1;
577 unsigned int has_pc_info
: 1;
579 /* Flag set if the SCOPE field of this structure has been
581 unsigned int scope_set
: 1;
583 /* Flag set if the DIE has a byte_size attribute. */
584 unsigned int has_byte_size
: 1;
586 /* Flag set if any of the DIE's children are template arguments. */
587 unsigned int has_template_arguments
: 1;
589 /* Flag set if fixup_partial_die has been called on this die. */
590 unsigned int fixup_called
: 1;
592 /* The name of this DIE. Normally the value of DW_AT_name, but
593 sometimes a default name for unnamed DIEs. */
596 /* The linkage name, if present. */
597 const char *linkage_name
;
599 /* The scope to prepend to our children. This is generally
600 allocated on the comp_unit_obstack, so will disappear
601 when this compilation unit leaves the cache. */
604 /* The location description associated with this DIE, if any. */
605 struct dwarf_block
*locdesc
;
607 /* If HAS_PC_INFO, the PC range associated with this DIE. */
611 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
612 DW_AT_sibling, if any. */
613 /* NOTE: This member isn't strictly necessary, read_partial_die could
614 return DW_AT_sibling values to its caller load_partial_dies. */
617 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
618 DW_AT_specification (or DW_AT_abstract_origin or
620 unsigned int spec_offset
;
622 /* Pointers to this DIE's parent, first child, and next sibling,
624 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
627 /* This data structure holds the information of an abbrev. */
630 unsigned int number
; /* number identifying abbrev */
631 enum dwarf_tag tag
; /* dwarf tag */
632 unsigned short has_children
; /* boolean */
633 unsigned short num_attrs
; /* number of attributes */
634 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
635 struct abbrev_info
*next
; /* next in chain */
640 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
641 ENUM_BITFIELD(dwarf_form
) form
: 16;
644 /* Attributes have a name and a value. */
647 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
648 ENUM_BITFIELD(dwarf_form
) form
: 15;
650 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
651 field should be in u.str (existing only for DW_STRING) but it is kept
652 here for better struct attribute alignment. */
653 unsigned int string_is_canonical
: 1;
658 struct dwarf_block
*blk
;
662 struct signatured_type
*signatured_type
;
667 /* This data structure holds a complete die structure. */
670 /* DWARF-2 tag for this DIE. */
671 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
673 /* Number of attributes */
674 unsigned char num_attrs
;
676 /* True if we're presently building the full type name for the
677 type derived from this DIE. */
678 unsigned char building_fullname
: 1;
683 /* Offset in .debug_info or .debug_types section. */
686 /* The dies in a compilation unit form an n-ary tree. PARENT
687 points to this die's parent; CHILD points to the first child of
688 this node; and all the children of a given node are chained
689 together via their SIBLING fields. */
690 struct die_info
*child
; /* Its first child, if any. */
691 struct die_info
*sibling
; /* Its next sibling, if any. */
692 struct die_info
*parent
; /* Its parent, if any. */
694 /* An array of attributes, with NUM_ATTRS elements. There may be
695 zero, but it's not common and zero-sized arrays are not
696 sufficiently portable C. */
697 struct attribute attrs
[1];
700 struct function_range
703 CORE_ADDR lowpc
, highpc
;
705 struct function_range
*next
;
708 /* Get at parts of an attribute structure. */
710 #define DW_STRING(attr) ((attr)->u.str)
711 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
712 #define DW_UNSND(attr) ((attr)->u.unsnd)
713 #define DW_BLOCK(attr) ((attr)->u.blk)
714 #define DW_SND(attr) ((attr)->u.snd)
715 #define DW_ADDR(attr) ((attr)->u.addr)
716 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
718 /* Blocks are a bunch of untyped bytes. */
725 #ifndef ATTR_ALLOC_CHUNK
726 #define ATTR_ALLOC_CHUNK 4
729 /* Allocate fields for structs, unions and enums in this size. */
730 #ifndef DW_FIELD_ALLOC_CHUNK
731 #define DW_FIELD_ALLOC_CHUNK 4
734 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
735 but this would require a corresponding change in unpack_field_as_long
737 static int bits_per_byte
= 8;
739 /* The routines that read and process dies for a C struct or C++ class
740 pass lists of data member fields and lists of member function fields
741 in an instance of a field_info structure, as defined below. */
744 /* List of data member and baseclasses fields. */
747 struct nextfield
*next
;
752 *fields
, *baseclasses
;
754 /* Number of fields (including baseclasses). */
757 /* Number of baseclasses. */
760 /* Set if the accesibility of one of the fields is not public. */
761 int non_public_fields
;
763 /* Member function fields array, entries are allocated in the order they
764 are encountered in the object file. */
767 struct nextfnfield
*next
;
768 struct fn_field fnfield
;
772 /* Member function fieldlist array, contains name of possibly overloaded
773 member function, number of overloaded member functions and a pointer
774 to the head of the member function field chain. */
779 struct nextfnfield
*head
;
783 /* Number of entries in the fnfieldlists array. */
786 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
787 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
788 struct typedef_field_list
790 struct typedef_field field
;
791 struct typedef_field_list
*next
;
794 unsigned typedef_field_list_count
;
797 /* One item on the queue of compilation units to read in full symbols
799 struct dwarf2_queue_item
801 struct dwarf2_per_cu_data
*per_cu
;
802 struct dwarf2_queue_item
*next
;
805 /* The current queue. */
806 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
808 /* Loaded secondary compilation units are kept in memory until they
809 have not been referenced for the processing of this many
810 compilation units. Set this to zero to disable caching. Cache
811 sizes of up to at least twenty will improve startup time for
812 typical inter-CU-reference binaries, at an obvious memory cost. */
813 static int dwarf2_max_cache_age
= 5;
815 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
816 struct cmd_list_element
*c
, const char *value
)
818 fprintf_filtered (file
, _("The upper bound on the age of cached "
819 "dwarf2 compilation units is %s.\n"),
824 /* Various complaints about symbol reading that don't abort the process. */
827 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
829 complaint (&symfile_complaints
,
830 _("statement list doesn't fit in .debug_line section"));
834 dwarf2_debug_line_missing_file_complaint (void)
836 complaint (&symfile_complaints
,
837 _(".debug_line section has line data without a file"));
841 dwarf2_debug_line_missing_end_sequence_complaint (void)
843 complaint (&symfile_complaints
,
844 _(".debug_line section has line "
845 "program sequence without an end"));
849 dwarf2_complex_location_expr_complaint (void)
851 complaint (&symfile_complaints
, _("location expression too complex"));
855 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
858 complaint (&symfile_complaints
,
859 _("const value length mismatch for '%s', got %d, expected %d"),
864 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
866 complaint (&symfile_complaints
,
867 _("macro info runs off end of `%s' section"),
868 section
->asection
->name
);
872 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
874 complaint (&symfile_complaints
,
875 _("macro debug info contains a "
876 "malformed macro definition:\n`%s'"),
881 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
883 complaint (&symfile_complaints
,
884 _("invalid attribute class or form for '%s' in '%s'"),
888 /* local function prototypes */
890 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
892 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
895 static void dwarf2_find_base_address (struct die_info
*die
,
896 struct dwarf2_cu
*cu
);
898 static void dwarf2_build_psymtabs_hard (struct objfile
*);
900 static void scan_partial_symbols (struct partial_die_info
*,
901 CORE_ADDR
*, CORE_ADDR
*,
902 int, struct dwarf2_cu
*);
904 static void add_partial_symbol (struct partial_die_info
*,
907 static void add_partial_namespace (struct partial_die_info
*pdi
,
908 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
909 int need_pc
, struct dwarf2_cu
*cu
);
911 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
912 CORE_ADDR
*highpc
, int need_pc
,
913 struct dwarf2_cu
*cu
);
915 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
916 struct dwarf2_cu
*cu
);
918 static void add_partial_subprogram (struct partial_die_info
*pdi
,
919 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
920 int need_pc
, struct dwarf2_cu
*cu
);
922 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
923 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
924 bfd
*abfd
, struct dwarf2_cu
*cu
);
926 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
928 static void psymtab_to_symtab_1 (struct partial_symtab
*);
930 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
932 static void dwarf2_free_abbrev_table (void *);
934 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
937 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
940 static struct partial_die_info
*load_partial_dies (bfd
*,
941 gdb_byte
*, gdb_byte
*,
942 int, struct dwarf2_cu
*);
944 static gdb_byte
*read_partial_die (struct partial_die_info
*,
945 struct abbrev_info
*abbrev
,
947 gdb_byte
*, gdb_byte
*,
950 static struct partial_die_info
*find_partial_die (unsigned int,
953 static void fixup_partial_die (struct partial_die_info
*,
956 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
957 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
959 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
960 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
962 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
964 static int read_1_signed_byte (bfd
*, gdb_byte
*);
966 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
968 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
970 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
972 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
975 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
977 static LONGEST read_checked_initial_length_and_offset
978 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
979 unsigned int *, unsigned int *);
981 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
984 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
986 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
988 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
990 static char *read_indirect_string (bfd
*, gdb_byte
*,
991 const struct comp_unit_head
*,
994 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
996 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
998 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
1000 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1002 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1003 struct dwarf2_cu
*);
1005 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1007 struct dwarf2_cu
*);
1009 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1010 struct dwarf2_cu
*cu
);
1012 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1014 static struct die_info
*die_specification (struct die_info
*die
,
1015 struct dwarf2_cu
**);
1017 static void free_line_header (struct line_header
*lh
);
1019 static void add_file_name (struct line_header
*, char *, unsigned int,
1020 unsigned int, unsigned int);
1022 static struct line_header
*(dwarf_decode_line_header
1023 (unsigned int offset
,
1024 bfd
*abfd
, struct dwarf2_cu
*cu
));
1026 static void dwarf_decode_lines (struct line_header
*, const char *, bfd
*,
1027 struct dwarf2_cu
*, struct partial_symtab
*);
1029 static void dwarf2_start_subfile (char *, const char *, const char *);
1031 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1032 struct dwarf2_cu
*);
1034 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1035 struct dwarf2_cu
*, struct symbol
*);
1037 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1038 struct dwarf2_cu
*);
1040 static void dwarf2_const_value_attr (struct attribute
*attr
,
1043 struct obstack
*obstack
,
1044 struct dwarf2_cu
*cu
, long *value
,
1046 struct dwarf2_locexpr_baton
**baton
);
1048 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1050 static int need_gnat_info (struct dwarf2_cu
*);
1052 static struct type
*die_descriptive_type (struct die_info
*,
1053 struct dwarf2_cu
*);
1055 static void set_descriptive_type (struct type
*, struct die_info
*,
1056 struct dwarf2_cu
*);
1058 static struct type
*die_containing_type (struct die_info
*,
1059 struct dwarf2_cu
*);
1061 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1062 struct dwarf2_cu
*);
1064 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1066 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1068 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1070 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1071 const char *suffix
, int physname
,
1072 struct dwarf2_cu
*cu
);
1074 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1076 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1078 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1080 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1082 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1083 struct dwarf2_cu
*, struct partial_symtab
*);
1085 static int dwarf2_get_pc_bounds (struct die_info
*,
1086 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1087 struct partial_symtab
*);
1089 static void get_scope_pc_bounds (struct die_info
*,
1090 CORE_ADDR
*, CORE_ADDR
*,
1091 struct dwarf2_cu
*);
1093 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1094 CORE_ADDR
, struct dwarf2_cu
*);
1096 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1097 struct dwarf2_cu
*);
1099 static void dwarf2_attach_fields_to_type (struct field_info
*,
1100 struct type
*, struct dwarf2_cu
*);
1102 static void dwarf2_add_member_fn (struct field_info
*,
1103 struct die_info
*, struct type
*,
1104 struct dwarf2_cu
*);
1106 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1108 struct dwarf2_cu
*);
1110 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1112 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1114 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1116 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1118 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1120 static struct type
*read_module_type (struct die_info
*die
,
1121 struct dwarf2_cu
*cu
);
1123 static const char *namespace_name (struct die_info
*die
,
1124 int *is_anonymous
, struct dwarf2_cu
*);
1126 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1128 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1130 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1131 struct dwarf2_cu
*);
1133 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1135 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1137 gdb_byte
**new_info_ptr
,
1138 struct die_info
*parent
);
1140 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1142 gdb_byte
**new_info_ptr
,
1143 struct die_info
*parent
);
1145 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1147 gdb_byte
**new_info_ptr
,
1148 struct die_info
*parent
);
1150 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1151 struct die_info
**, gdb_byte
*,
1154 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1156 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1159 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1161 static const char *dwarf2_full_name (char *name
,
1162 struct die_info
*die
,
1163 struct dwarf2_cu
*cu
);
1165 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1166 struct dwarf2_cu
**);
1168 static char *dwarf_tag_name (unsigned int);
1170 static char *dwarf_attr_name (unsigned int);
1172 static char *dwarf_form_name (unsigned int);
1174 static char *dwarf_bool_name (unsigned int);
1176 static char *dwarf_type_encoding_name (unsigned int);
1179 static char *dwarf_cfi_name (unsigned int);
1182 static struct die_info
*sibling_die (struct die_info
*);
1184 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1186 static void dump_die_for_error (struct die_info
*);
1188 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1191 /*static*/ void dump_die (struct die_info
*, int max_level
);
1193 static void store_in_ref_table (struct die_info
*,
1194 struct dwarf2_cu
*);
1196 static int is_ref_attr (struct attribute
*);
1198 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1200 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1202 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1204 struct dwarf2_cu
**);
1206 static struct die_info
*follow_die_ref (struct die_info
*,
1208 struct dwarf2_cu
**);
1210 static struct die_info
*follow_die_sig (struct die_info
*,
1212 struct dwarf2_cu
**);
1214 static struct signatured_type
*lookup_signatured_type_at_offset
1215 (struct objfile
*objfile
,
1216 struct dwarf2_section_info
*section
,
1217 unsigned int offset
);
1219 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1220 struct dwarf2_section_info
*sect
,
1221 unsigned int offset
);
1223 static void read_signatured_type (struct objfile
*,
1224 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 initialize_cu_func_list (struct dwarf2_cu
*);
1236 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1237 struct dwarf2_cu
*);
1239 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1240 char *, bfd
*, struct dwarf2_cu
*,
1241 struct dwarf2_section_info
*,
1244 static int attr_form_is_block (struct attribute
*);
1246 static int attr_form_is_section_offset (struct attribute
*);
1248 static int attr_form_is_constant (struct attribute
*);
1250 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1251 struct dwarf2_loclist_baton
*baton
,
1252 struct attribute
*attr
);
1254 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1256 struct dwarf2_cu
*cu
);
1258 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1259 struct abbrev_info
*abbrev
,
1260 struct dwarf2_cu
*cu
);
1262 static void free_stack_comp_unit (void *);
1264 static hashval_t
partial_die_hash (const void *item
);
1266 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1268 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1269 (unsigned int offset
, struct objfile
*objfile
);
1271 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1272 (unsigned int offset
, struct objfile
*objfile
);
1274 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1275 struct objfile
*objfile
);
1277 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1278 struct die_info
*comp_unit_die
);
1280 static void free_one_comp_unit (void *);
1282 static void free_cached_comp_units (void *);
1284 static void age_cached_comp_units (void);
1286 static void free_one_cached_comp_unit (void *);
1288 static struct type
*set_die_type (struct die_info
*, struct type
*,
1289 struct dwarf2_cu
*);
1291 static void create_all_comp_units (struct objfile
*);
1293 static int create_debug_types_hash_table (struct objfile
*objfile
);
1295 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1298 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1300 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1301 struct dwarf2_per_cu_data
*);
1303 static void dwarf2_mark (struct dwarf2_cu
*);
1305 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1307 static struct type
*get_die_type_at_offset (unsigned int,
1308 struct dwarf2_per_cu_data
*per_cu
);
1310 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1312 static void dwarf2_release_queue (void *dummy
);
1314 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1315 struct objfile
*objfile
);
1317 static void process_queue (struct objfile
*objfile
);
1319 static void find_file_and_directory (struct die_info
*die
,
1320 struct dwarf2_cu
*cu
,
1321 char **name
, char **comp_dir
);
1323 static char *file_full_name (int file
, struct line_header
*lh
,
1324 const char *comp_dir
);
1326 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1329 unsigned int buffer_size
,
1332 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1333 struct dwarf2_cu
*cu
);
1335 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1339 /* Convert VALUE between big- and little-endian. */
1341 byte_swap (offset_type value
)
1345 result
= (value
& 0xff) << 24;
1346 result
|= (value
& 0xff00) << 8;
1347 result
|= (value
& 0xff0000) >> 8;
1348 result
|= (value
& 0xff000000) >> 24;
1352 #define MAYBE_SWAP(V) byte_swap (V)
1355 #define MAYBE_SWAP(V) (V)
1356 #endif /* WORDS_BIGENDIAN */
1358 /* The suffix for an index file. */
1359 #define INDEX_SUFFIX ".gdb-index"
1361 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1362 struct dwarf2_cu
*cu
);
1364 /* Try to locate the sections we need for DWARF 2 debugging
1365 information and return true if we have enough to do something.
1366 NAMES points to the dwarf2 section names, or is NULL if the standard
1367 ELF names are used. */
1370 dwarf2_has_info (struct objfile
*objfile
,
1371 const struct dwarf2_debug_sections
*names
)
1373 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1374 if (!dwarf2_per_objfile
)
1376 /* Initialize per-objfile state. */
1377 struct dwarf2_per_objfile
*data
1378 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1380 memset (data
, 0, sizeof (*data
));
1381 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1382 dwarf2_per_objfile
= data
;
1384 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1386 dwarf2_per_objfile
->objfile
= objfile
;
1388 return (dwarf2_per_objfile
->info
.asection
!= NULL
1389 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1392 /* When loading sections, we look either for uncompressed section or for
1393 compressed section names. */
1396 section_is_p (const char *section_name
,
1397 const struct dwarf2_section_names
*names
)
1399 if (names
->normal
!= NULL
1400 && strcmp (section_name
, names
->normal
) == 0)
1402 if (names
->compressed
!= NULL
1403 && strcmp (section_name
, names
->compressed
) == 0)
1408 /* This function is mapped across the sections and remembers the
1409 offset and size of each of the debugging sections we are interested
1413 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1415 const struct dwarf2_debug_sections
*names
;
1418 names
= &dwarf2_elf_names
;
1420 names
= (const struct dwarf2_debug_sections
*) vnames
;
1422 if (section_is_p (sectp
->name
, &names
->info
))
1424 dwarf2_per_objfile
->info
.asection
= sectp
;
1425 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1427 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1429 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1430 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1432 else if (section_is_p (sectp
->name
, &names
->line
))
1434 dwarf2_per_objfile
->line
.asection
= sectp
;
1435 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1437 else if (section_is_p (sectp
->name
, &names
->loc
))
1439 dwarf2_per_objfile
->loc
.asection
= sectp
;
1440 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1442 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1444 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1445 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1447 else if (section_is_p (sectp
->name
, &names
->macro
))
1449 dwarf2_per_objfile
->macro
.asection
= sectp
;
1450 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1452 else if (section_is_p (sectp
->name
, &names
->str
))
1454 dwarf2_per_objfile
->str
.asection
= sectp
;
1455 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1457 else if (section_is_p (sectp
->name
, &names
->frame
))
1459 dwarf2_per_objfile
->frame
.asection
= sectp
;
1460 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1462 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1464 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1466 if (aflag
& SEC_HAS_CONTENTS
)
1468 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1469 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1472 else if (section_is_p (sectp
->name
, &names
->ranges
))
1474 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1475 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1477 else if (section_is_p (sectp
->name
, &names
->types
))
1479 struct dwarf2_section_info type_section
;
1481 memset (&type_section
, 0, sizeof (type_section
));
1482 type_section
.asection
= sectp
;
1483 type_section
.size
= bfd_get_section_size (sectp
);
1485 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1488 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1490 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1491 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1494 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1495 && bfd_section_vma (abfd
, sectp
) == 0)
1496 dwarf2_per_objfile
->has_section_at_zero
= 1;
1499 /* Decompress a section that was compressed using zlib. Store the
1500 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1503 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1504 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1506 bfd
*abfd
= objfile
->obfd
;
1508 error (_("Support for zlib-compressed DWARF data (from '%s') "
1509 "is disabled in this copy of GDB"),
1510 bfd_get_filename (abfd
));
1512 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1513 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1514 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1515 bfd_size_type uncompressed_size
;
1516 gdb_byte
*uncompressed_buffer
;
1519 int header_size
= 12;
1521 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1522 || bfd_bread (compressed_buffer
,
1523 compressed_size
, abfd
) != compressed_size
)
1524 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1525 bfd_get_filename (abfd
));
1527 /* Read the zlib header. In this case, it should be "ZLIB" followed
1528 by the uncompressed section size, 8 bytes in big-endian order. */
1529 if (compressed_size
< header_size
1530 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1531 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1532 bfd_get_filename (abfd
));
1533 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1534 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1535 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1536 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1537 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1538 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1539 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1540 uncompressed_size
+= compressed_buffer
[11];
1542 /* It is possible the section consists of several compressed
1543 buffers concatenated together, so we uncompress in a loop. */
1547 strm
.avail_in
= compressed_size
- header_size
;
1548 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1549 strm
.avail_out
= uncompressed_size
;
1550 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1552 rc
= inflateInit (&strm
);
1553 while (strm
.avail_in
> 0)
1556 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1557 bfd_get_filename (abfd
), rc
);
1558 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1559 + (uncompressed_size
- strm
.avail_out
));
1560 rc
= inflate (&strm
, Z_FINISH
);
1561 if (rc
!= Z_STREAM_END
)
1562 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1563 bfd_get_filename (abfd
), rc
);
1564 rc
= inflateReset (&strm
);
1566 rc
= inflateEnd (&strm
);
1568 || strm
.avail_out
!= 0)
1569 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1570 bfd_get_filename (abfd
), rc
);
1572 do_cleanups (cleanup
);
1573 *outbuf
= uncompressed_buffer
;
1574 *outsize
= uncompressed_size
;
1578 /* A helper function that decides whether a section is empty. */
1581 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1583 return info
->asection
== NULL
|| info
->size
== 0;
1586 /* Read the contents of the section SECTP from object file specified by
1587 OBJFILE, store info about the section into INFO.
1588 If the section is compressed, uncompress it before returning. */
1591 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1593 bfd
*abfd
= objfile
->obfd
;
1594 asection
*sectp
= info
->asection
;
1595 gdb_byte
*buf
, *retbuf
;
1596 unsigned char header
[4];
1600 info
->buffer
= NULL
;
1601 info
->map_addr
= NULL
;
1604 if (dwarf2_section_empty_p (info
))
1607 /* Check if the file has a 4-byte header indicating compression. */
1608 if (info
->size
> sizeof (header
)
1609 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1610 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1612 /* Upon decompression, update the buffer and its size. */
1613 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1615 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1623 pagesize
= getpagesize ();
1625 /* Only try to mmap sections which are large enough: we don't want to
1626 waste space due to fragmentation. Also, only try mmap for sections
1627 without relocations. */
1629 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1631 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1632 MAP_PRIVATE
, sectp
->filepos
,
1633 &info
->map_addr
, &info
->map_len
);
1635 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1637 #if HAVE_POSIX_MADVISE
1638 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1645 /* If we get here, we are a normal, not-compressed section. */
1647 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1649 /* When debugging .o files, we may need to apply relocations; see
1650 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1651 We never compress sections in .o files, so we only need to
1652 try this when the section is not compressed. */
1653 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1656 info
->buffer
= retbuf
;
1660 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1661 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1662 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1663 bfd_get_filename (abfd
));
1666 /* A helper function that returns the size of a section in a safe way.
1667 If you are positive that the section has been read before using the
1668 size, then it is safe to refer to the dwarf2_section_info object's
1669 "size" field directly. In other cases, you must call this
1670 function, because for compressed sections the size field is not set
1671 correctly until the section has been read. */
1673 static bfd_size_type
1674 dwarf2_section_size (struct objfile
*objfile
,
1675 struct dwarf2_section_info
*info
)
1678 dwarf2_read_section (objfile
, info
);
1682 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1686 dwarf2_get_section_info (struct objfile
*objfile
,
1687 enum dwarf2_section_enum sect
,
1688 asection
**sectp
, gdb_byte
**bufp
,
1689 bfd_size_type
*sizep
)
1691 struct dwarf2_per_objfile
*data
1692 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1693 struct dwarf2_section_info
*info
;
1695 /* We may see an objfile without any DWARF, in which case we just
1706 case DWARF2_DEBUG_FRAME
:
1707 info
= &data
->frame
;
1709 case DWARF2_EH_FRAME
:
1710 info
= &data
->eh_frame
;
1713 gdb_assert_not_reached ("unexpected section");
1716 dwarf2_read_section (objfile
, info
);
1718 *sectp
= info
->asection
;
1719 *bufp
= info
->buffer
;
1720 *sizep
= info
->size
;
1724 /* DWARF quick_symbols_functions support. */
1726 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1727 unique line tables, so we maintain a separate table of all .debug_line
1728 derived entries to support the sharing.
1729 All the quick functions need is the list of file names. We discard the
1730 line_header when we're done and don't need to record it here. */
1731 struct quick_file_names
1733 /* The offset in .debug_line of the line table. We hash on this. */
1734 unsigned int offset
;
1736 /* The number of entries in file_names, real_names. */
1737 unsigned int num_file_names
;
1739 /* The file names from the line table, after being run through
1741 const char **file_names
;
1743 /* The file names from the line table after being run through
1744 gdb_realpath. These are computed lazily. */
1745 const char **real_names
;
1748 /* When using the index (and thus not using psymtabs), each CU has an
1749 object of this type. This is used to hold information needed by
1750 the various "quick" methods. */
1751 struct dwarf2_per_cu_quick_data
1753 /* The file table. This can be NULL if there was no file table
1754 or it's currently not read in.
1755 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1756 struct quick_file_names
*file_names
;
1758 /* The corresponding symbol table. This is NULL if symbols for this
1759 CU have not yet been read. */
1760 struct symtab
*symtab
;
1762 /* A temporary mark bit used when iterating over all CUs in
1763 expand_symtabs_matching. */
1764 unsigned int mark
: 1;
1766 /* True if we've tried to read the file table and found there isn't one.
1767 There will be no point in trying to read it again next time. */
1768 unsigned int no_file_data
: 1;
1771 /* Hash function for a quick_file_names. */
1774 hash_file_name_entry (const void *e
)
1776 const struct quick_file_names
*file_data
= e
;
1778 return file_data
->offset
;
1781 /* Equality function for a quick_file_names. */
1784 eq_file_name_entry (const void *a
, const void *b
)
1786 const struct quick_file_names
*ea
= a
;
1787 const struct quick_file_names
*eb
= b
;
1789 return ea
->offset
== eb
->offset
;
1792 /* Delete function for a quick_file_names. */
1795 delete_file_name_entry (void *e
)
1797 struct quick_file_names
*file_data
= e
;
1800 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1802 xfree ((void*) file_data
->file_names
[i
]);
1803 if (file_data
->real_names
)
1804 xfree ((void*) file_data
->real_names
[i
]);
1807 /* The space for the struct itself lives on objfile_obstack,
1808 so we don't free it here. */
1811 /* Create a quick_file_names hash table. */
1814 create_quick_file_names_table (unsigned int nr_initial_entries
)
1816 return htab_create_alloc (nr_initial_entries
,
1817 hash_file_name_entry
, eq_file_name_entry
,
1818 delete_file_name_entry
, xcalloc
, xfree
);
1821 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1822 have to be created afterwards. You should call age_cached_comp_units after
1823 processing PER_CU->CU. dw2_setup must have been already called. */
1826 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1828 if (per_cu
->debug_type_section
)
1829 read_signatured_type_at_offset (per_cu
->objfile
,
1830 per_cu
->debug_type_section
,
1833 load_full_comp_unit (per_cu
, per_cu
->objfile
);
1835 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1837 gdb_assert (per_cu
->cu
!= NULL
);
1840 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1844 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1845 struct dwarf2_per_cu_data
*per_cu
)
1847 struct cleanup
*back_to
;
1849 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1851 queue_comp_unit (per_cu
, objfile
);
1855 process_queue (objfile
);
1857 /* Age the cache, releasing compilation units that have not
1858 been used recently. */
1859 age_cached_comp_units ();
1861 do_cleanups (back_to
);
1864 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1865 the objfile from which this CU came. Returns the resulting symbol
1868 static struct symtab
*
1869 dw2_instantiate_symtab (struct objfile
*objfile
,
1870 struct dwarf2_per_cu_data
*per_cu
)
1872 if (!per_cu
->v
.quick
->symtab
)
1874 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1875 increment_reading_symtab ();
1876 dw2_do_instantiate_symtab (objfile
, per_cu
);
1877 do_cleanups (back_to
);
1879 return per_cu
->v
.quick
->symtab
;
1882 /* Return the CU given its index. */
1884 static struct dwarf2_per_cu_data
*
1885 dw2_get_cu (int index
)
1887 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1889 index
-= dwarf2_per_objfile
->n_comp_units
;
1890 return dwarf2_per_objfile
->type_comp_units
[index
];
1892 return dwarf2_per_objfile
->all_comp_units
[index
];
1895 /* A helper function that knows how to read a 64-bit value in a way
1896 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1900 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1902 if (sizeof (ULONGEST
) < 8)
1906 /* Ignore the upper 4 bytes if they are all zero. */
1907 for (i
= 0; i
< 4; ++i
)
1908 if (bytes
[i
+ 4] != 0)
1911 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1914 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1918 /* Read the CU list from the mapped index, and use it to create all
1919 the CU objects for this objfile. Return 0 if something went wrong,
1920 1 if everything went ok. */
1923 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1924 offset_type cu_list_elements
)
1928 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1929 dwarf2_per_objfile
->all_comp_units
1930 = obstack_alloc (&objfile
->objfile_obstack
,
1931 dwarf2_per_objfile
->n_comp_units
1932 * sizeof (struct dwarf2_per_cu_data
*));
1934 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1936 struct dwarf2_per_cu_data
*the_cu
;
1937 ULONGEST offset
, length
;
1939 if (!extract_cu_value (cu_list
, &offset
)
1940 || !extract_cu_value (cu_list
+ 8, &length
))
1944 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1945 struct dwarf2_per_cu_data
);
1946 the_cu
->offset
= offset
;
1947 the_cu
->length
= length
;
1948 the_cu
->objfile
= objfile
;
1949 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1950 struct dwarf2_per_cu_quick_data
);
1951 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1957 /* Create the signatured type hash table from the index. */
1960 create_signatured_type_table_from_index (struct objfile
*objfile
,
1961 struct dwarf2_section_info
*section
,
1962 const gdb_byte
*bytes
,
1963 offset_type elements
)
1966 htab_t sig_types_hash
;
1968 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1969 dwarf2_per_objfile
->type_comp_units
1970 = obstack_alloc (&objfile
->objfile_obstack
,
1971 dwarf2_per_objfile
->n_type_comp_units
1972 * sizeof (struct dwarf2_per_cu_data
*));
1974 sig_types_hash
= allocate_signatured_type_table (objfile
);
1976 for (i
= 0; i
< elements
; i
+= 3)
1978 struct signatured_type
*type_sig
;
1979 ULONGEST offset
, type_offset
, signature
;
1982 if (!extract_cu_value (bytes
, &offset
)
1983 || !extract_cu_value (bytes
+ 8, &type_offset
))
1985 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1988 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1989 struct signatured_type
);
1990 type_sig
->signature
= signature
;
1991 type_sig
->type_offset
= type_offset
;
1992 type_sig
->per_cu
.debug_type_section
= section
;
1993 type_sig
->per_cu
.offset
= offset
;
1994 type_sig
->per_cu
.objfile
= objfile
;
1995 type_sig
->per_cu
.v
.quick
1996 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1997 struct dwarf2_per_cu_quick_data
);
1999 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
2002 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
2005 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2010 /* Read the address map data from the mapped index, and use it to
2011 populate the objfile's psymtabs_addrmap. */
2014 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2016 const gdb_byte
*iter
, *end
;
2017 struct obstack temp_obstack
;
2018 struct addrmap
*mutable_map
;
2019 struct cleanup
*cleanup
;
2022 obstack_init (&temp_obstack
);
2023 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2024 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2026 iter
= index
->address_table
;
2027 end
= iter
+ index
->address_table_size
;
2029 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2033 ULONGEST hi
, lo
, cu_index
;
2034 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2036 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2038 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2041 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2042 dw2_get_cu (cu_index
));
2045 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2046 &objfile
->objfile_obstack
);
2047 do_cleanups (cleanup
);
2050 /* The hash function for strings in the mapped index. This is the same as
2051 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2052 implementation. This is necessary because the hash function is tied to the
2053 format of the mapped index file. The hash values do not have to match with
2056 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2059 mapped_index_string_hash (int index_version
, const void *p
)
2061 const unsigned char *str
= (const unsigned char *) p
;
2065 while ((c
= *str
++) != 0)
2067 if (index_version
>= 5)
2069 r
= r
* 67 + c
- 113;
2075 /* Find a slot in the mapped index INDEX for the object named NAME.
2076 If NAME is found, set *VEC_OUT to point to the CU vector in the
2077 constant pool and return 1. If NAME cannot be found, return 0. */
2080 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2081 offset_type
**vec_out
)
2083 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2085 offset_type slot
, step
;
2086 int (*cmp
) (const char *, const char *);
2088 if (current_language
->la_language
== language_cplus
2089 || current_language
->la_language
== language_java
2090 || current_language
->la_language
== language_fortran
)
2092 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2094 const char *paren
= strchr (name
, '(');
2100 dup
= xmalloc (paren
- name
+ 1);
2101 memcpy (dup
, name
, paren
- name
);
2102 dup
[paren
- name
] = 0;
2104 make_cleanup (xfree
, dup
);
2109 /* Index version 4 did not support case insensitive searches. But the
2110 indexes for case insensitive languages are built in lowercase, therefore
2111 simulate our NAME being searched is also lowercased. */
2112 hash
= mapped_index_string_hash ((index
->version
== 4
2113 && case_sensitivity
== case_sensitive_off
2114 ? 5 : index
->version
),
2117 slot
= hash
& (index
->symbol_table_slots
- 1);
2118 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2119 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2123 /* Convert a slot number to an offset into the table. */
2124 offset_type i
= 2 * slot
;
2126 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2128 do_cleanups (back_to
);
2132 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2133 if (!cmp (name
, str
))
2135 *vec_out
= (offset_type
*) (index
->constant_pool
2136 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2137 do_cleanups (back_to
);
2141 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2145 /* Read the index file. If everything went ok, initialize the "quick"
2146 elements of all the CUs and return 1. Otherwise, return 0. */
2149 dwarf2_read_index (struct objfile
*objfile
)
2152 struct mapped_index
*map
;
2153 offset_type
*metadata
;
2154 const gdb_byte
*cu_list
;
2155 const gdb_byte
*types_list
= NULL
;
2156 offset_type version
, cu_list_elements
;
2157 offset_type types_list_elements
= 0;
2160 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2163 /* Older elfutils strip versions could keep the section in the main
2164 executable while splitting it for the separate debug info file. */
2165 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2166 & SEC_HAS_CONTENTS
) == 0)
2169 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2171 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2172 /* Version check. */
2173 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2174 /* Versions earlier than 3 emitted every copy of a psymbol. This
2175 causes the index to behave very poorly for certain requests. Version 3
2176 contained incomplete addrmap. So, it seems better to just ignore such
2177 indices. Index version 4 uses a different hash function than index
2178 version 5 and later. */
2181 /* Indexes with higher version than the one supported by GDB may be no
2182 longer backward compatible. */
2186 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2187 map
->version
= version
;
2188 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2190 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2193 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2194 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2198 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2199 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2200 - MAYBE_SWAP (metadata
[i
]))
2204 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2205 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2206 - MAYBE_SWAP (metadata
[i
]));
2209 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2210 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2211 - MAYBE_SWAP (metadata
[i
]))
2212 / (2 * sizeof (offset_type
)));
2215 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2217 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2220 if (types_list_elements
)
2222 struct dwarf2_section_info
*section
;
2224 /* We can only handle a single .debug_types when we have an
2226 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2229 section
= VEC_index (dwarf2_section_info_def
,
2230 dwarf2_per_objfile
->types
, 0);
2232 if (!create_signatured_type_table_from_index (objfile
, section
,
2234 types_list_elements
))
2238 create_addrmap_from_index (objfile
, map
);
2240 dwarf2_per_objfile
->index_table
= map
;
2241 dwarf2_per_objfile
->using_index
= 1;
2242 dwarf2_per_objfile
->quick_file_names_table
=
2243 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2248 /* A helper for the "quick" functions which sets the global
2249 dwarf2_per_objfile according to OBJFILE. */
2252 dw2_setup (struct objfile
*objfile
)
2254 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2255 gdb_assert (dwarf2_per_objfile
);
2258 /* A helper for the "quick" functions which attempts to read the line
2259 table for THIS_CU. */
2261 static struct quick_file_names
*
2262 dw2_get_file_names (struct objfile
*objfile
,
2263 struct dwarf2_per_cu_data
*this_cu
)
2265 bfd
*abfd
= objfile
->obfd
;
2266 struct line_header
*lh
;
2267 struct attribute
*attr
;
2268 struct cleanup
*cleanups
;
2269 struct die_info
*comp_unit_die
;
2270 struct dwarf2_section_info
* sec
;
2271 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2272 int has_children
, i
;
2273 struct dwarf2_cu cu
;
2274 unsigned int bytes_read
, buffer_size
;
2275 struct die_reader_specs reader_specs
;
2276 char *name
, *comp_dir
;
2278 struct quick_file_names
*qfn
;
2279 unsigned int line_offset
;
2281 if (this_cu
->v
.quick
->file_names
!= NULL
)
2282 return this_cu
->v
.quick
->file_names
;
2283 /* If we know there is no line data, no point in looking again. */
2284 if (this_cu
->v
.quick
->no_file_data
)
2287 init_one_comp_unit (&cu
, objfile
);
2288 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2290 if (this_cu
->debug_type_section
)
2291 sec
= this_cu
->debug_type_section
;
2293 sec
= &dwarf2_per_objfile
->info
;
2294 dwarf2_read_section (objfile
, sec
);
2295 buffer_size
= sec
->size
;
2296 buffer
= sec
->buffer
;
2297 info_ptr
= buffer
+ this_cu
->offset
;
2298 beg_of_comp_unit
= info_ptr
;
2300 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2301 buffer
, buffer_size
,
2304 /* Complete the cu_header. */
2305 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2306 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2309 cu
.per_cu
= this_cu
;
2311 dwarf2_read_abbrevs (abfd
, &cu
);
2312 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2314 if (this_cu
->debug_type_section
)
2315 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2316 init_cu_die_reader (&reader_specs
, &cu
);
2317 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2323 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2326 struct quick_file_names find_entry
;
2328 line_offset
= DW_UNSND (attr
);
2330 /* We may have already read in this line header (TU line header sharing).
2331 If we have we're done. */
2332 find_entry
.offset
= line_offset
;
2333 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2334 &find_entry
, INSERT
);
2337 do_cleanups (cleanups
);
2338 this_cu
->v
.quick
->file_names
= *slot
;
2342 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2346 do_cleanups (cleanups
);
2347 this_cu
->v
.quick
->no_file_data
= 1;
2351 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2352 qfn
->offset
= line_offset
;
2353 gdb_assert (slot
!= NULL
);
2356 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2358 qfn
->num_file_names
= lh
->num_file_names
;
2359 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2360 lh
->num_file_names
* sizeof (char *));
2361 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2362 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2363 qfn
->real_names
= NULL
;
2365 free_line_header (lh
);
2366 do_cleanups (cleanups
);
2368 this_cu
->v
.quick
->file_names
= qfn
;
2372 /* A helper for the "quick" functions which computes and caches the
2373 real path for a given file name from the line table. */
2376 dw2_get_real_path (struct objfile
*objfile
,
2377 struct quick_file_names
*qfn
, int index
)
2379 if (qfn
->real_names
== NULL
)
2380 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2381 qfn
->num_file_names
, sizeof (char *));
2383 if (qfn
->real_names
[index
] == NULL
)
2384 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2386 return qfn
->real_names
[index
];
2389 static struct symtab
*
2390 dw2_find_last_source_symtab (struct objfile
*objfile
)
2394 dw2_setup (objfile
);
2395 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2396 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2399 /* Traversal function for dw2_forget_cached_source_info. */
2402 dw2_free_cached_file_names (void **slot
, void *info
)
2404 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2406 if (file_data
->real_names
)
2410 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2412 xfree ((void*) file_data
->real_names
[i
]);
2413 file_data
->real_names
[i
] = NULL
;
2421 dw2_forget_cached_source_info (struct objfile
*objfile
)
2423 dw2_setup (objfile
);
2425 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2426 dw2_free_cached_file_names
, NULL
);
2430 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2431 const char *full_path
, const char *real_path
,
2432 struct symtab
**result
)
2435 int check_basename
= lbasename (name
) == name
;
2436 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2438 dw2_setup (objfile
);
2440 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2441 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2444 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2445 struct quick_file_names
*file_data
;
2447 if (per_cu
->v
.quick
->symtab
)
2450 file_data
= dw2_get_file_names (objfile
, per_cu
);
2451 if (file_data
== NULL
)
2454 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2456 const char *this_name
= file_data
->file_names
[j
];
2458 if (FILENAME_CMP (name
, this_name
) == 0)
2460 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2464 if (check_basename
&& ! base_cu
2465 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2468 if (full_path
!= NULL
)
2470 const char *this_real_name
= dw2_get_real_path (objfile
,
2473 if (this_real_name
!= NULL
2474 && FILENAME_CMP (full_path
, this_real_name
) == 0)
2476 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2481 if (real_path
!= NULL
)
2483 const char *this_real_name
= dw2_get_real_path (objfile
,
2486 if (this_real_name
!= NULL
2487 && FILENAME_CMP (real_path
, this_real_name
) == 0)
2489 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2498 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2505 static struct symtab
*
2506 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2507 const char *name
, domain_enum domain
)
2509 /* We do all the work in the pre_expand_symtabs_matching hook
2514 /* A helper function that expands all symtabs that hold an object
2518 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2520 dw2_setup (objfile
);
2522 /* index_table is NULL if OBJF_READNOW. */
2523 if (dwarf2_per_objfile
->index_table
)
2527 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2530 offset_type i
, len
= MAYBE_SWAP (*vec
);
2531 for (i
= 0; i
< len
; ++i
)
2533 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2534 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2536 dw2_instantiate_symtab (objfile
, per_cu
);
2543 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2544 enum block_enum block_kind
, const char *name
,
2547 dw2_do_expand_symtabs_matching (objfile
, name
);
2551 dw2_print_stats (struct objfile
*objfile
)
2555 dw2_setup (objfile
);
2557 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2558 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2560 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2562 if (!per_cu
->v
.quick
->symtab
)
2565 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2569 dw2_dump (struct objfile
*objfile
)
2571 /* Nothing worth printing. */
2575 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2576 struct section_offsets
*delta
)
2578 /* There's nothing to relocate here. */
2582 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2583 const char *func_name
)
2585 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2589 dw2_expand_all_symtabs (struct objfile
*objfile
)
2593 dw2_setup (objfile
);
2595 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2596 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2598 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2600 dw2_instantiate_symtab (objfile
, per_cu
);
2605 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2606 const char *filename
)
2610 dw2_setup (objfile
);
2612 /* We don't need to consider type units here.
2613 This is only called for examining code, e.g. expand_line_sal.
2614 There can be an order of magnitude (or more) more type units
2615 than comp units, and we avoid them if we can. */
2617 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2620 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2621 struct quick_file_names
*file_data
;
2623 if (per_cu
->v
.quick
->symtab
)
2626 file_data
= dw2_get_file_names (objfile
, per_cu
);
2627 if (file_data
== NULL
)
2630 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2632 const char *this_name
= file_data
->file_names
[j
];
2633 if (FILENAME_CMP (this_name
, filename
) == 0)
2635 dw2_instantiate_symtab (objfile
, per_cu
);
2643 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2645 struct dwarf2_per_cu_data
*per_cu
;
2647 struct quick_file_names
*file_data
;
2649 dw2_setup (objfile
);
2651 /* index_table is NULL if OBJF_READNOW. */
2652 if (!dwarf2_per_objfile
->index_table
)
2656 ALL_OBJFILE_SYMTABS (objfile
, s
)
2659 struct blockvector
*bv
= BLOCKVECTOR (s
);
2660 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2661 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2664 return sym
->symtab
->filename
;
2669 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2673 /* Note that this just looks at the very first one named NAME -- but
2674 actually we are looking for a function. find_main_filename
2675 should be rewritten so that it doesn't require a custom hook. It
2676 could just use the ordinary symbol tables. */
2677 /* vec[0] is the length, which must always be >0. */
2678 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2680 file_data
= dw2_get_file_names (objfile
, per_cu
);
2681 if (file_data
== NULL
)
2684 return file_data
->file_names
[file_data
->num_file_names
- 1];
2688 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2689 struct objfile
*objfile
, int global
,
2690 int (*callback
) (struct block
*,
2691 struct symbol
*, void *),
2692 void *data
, symbol_compare_ftype
*match
,
2693 symbol_compare_ftype
*ordered_compare
)
2695 /* Currently unimplemented; used for Ada. The function can be called if the
2696 current language is Ada for a non-Ada objfile using GNU index. As Ada
2697 does not look for non-Ada symbols this function should just return. */
2701 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2702 int (*file_matcher
) (const char *, void *),
2703 int (*name_matcher
) (const char *, void *),
2704 enum search_domain kind
,
2709 struct mapped_index
*index
;
2711 dw2_setup (objfile
);
2713 /* index_table is NULL if OBJF_READNOW. */
2714 if (!dwarf2_per_objfile
->index_table
)
2716 index
= dwarf2_per_objfile
->index_table
;
2718 if (file_matcher
!= NULL
)
2719 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2720 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2723 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2724 struct quick_file_names
*file_data
;
2726 per_cu
->v
.quick
->mark
= 0;
2727 if (per_cu
->v
.quick
->symtab
)
2730 file_data
= dw2_get_file_names (objfile
, per_cu
);
2731 if (file_data
== NULL
)
2734 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2736 if (file_matcher (file_data
->file_names
[j
], data
))
2738 per_cu
->v
.quick
->mark
= 1;
2744 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2746 offset_type idx
= 2 * iter
;
2748 offset_type
*vec
, vec_len
, vec_idx
;
2750 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2753 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2755 if (! (*name_matcher
) (name
, data
))
2758 /* The name was matched, now expand corresponding CUs that were
2760 vec
= (offset_type
*) (index
->constant_pool
2761 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2762 vec_len
= MAYBE_SWAP (vec
[0]);
2763 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2765 struct dwarf2_per_cu_data
*per_cu
;
2767 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2768 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2769 dw2_instantiate_symtab (objfile
, per_cu
);
2774 static struct symtab
*
2775 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2776 struct minimal_symbol
*msymbol
,
2778 struct obj_section
*section
,
2781 struct dwarf2_per_cu_data
*data
;
2783 dw2_setup (objfile
);
2785 if (!objfile
->psymtabs_addrmap
)
2788 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2792 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2793 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2794 paddress (get_objfile_arch (objfile
), pc
));
2796 return dw2_instantiate_symtab (objfile
, data
);
2800 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2805 dw2_setup (objfile
);
2807 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2808 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2811 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2812 struct quick_file_names
*file_data
;
2814 if (per_cu
->v
.quick
->symtab
)
2817 file_data
= dw2_get_file_names (objfile
, per_cu
);
2818 if (file_data
== NULL
)
2821 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2823 const char *this_real_name
= dw2_get_real_path (objfile
, file_data
,
2825 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2831 dw2_has_symbols (struct objfile
*objfile
)
2836 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2839 dw2_find_last_source_symtab
,
2840 dw2_forget_cached_source_info
,
2843 dw2_pre_expand_symtabs_matching
,
2847 dw2_expand_symtabs_for_function
,
2848 dw2_expand_all_symtabs
,
2849 dw2_expand_symtabs_with_filename
,
2850 dw2_find_symbol_file
,
2851 dw2_map_matching_symbols
,
2852 dw2_expand_symtabs_matching
,
2853 dw2_find_pc_sect_symtab
,
2854 dw2_map_symbol_filenames
2857 /* Initialize for reading DWARF for this objfile. Return 0 if this
2858 file will use psymtabs, or 1 if using the GNU index. */
2861 dwarf2_initialize_objfile (struct objfile
*objfile
)
2863 /* If we're about to read full symbols, don't bother with the
2864 indices. In this case we also don't care if some other debug
2865 format is making psymtabs, because they are all about to be
2867 if ((objfile
->flags
& OBJF_READNOW
))
2871 dwarf2_per_objfile
->using_index
= 1;
2872 create_all_comp_units (objfile
);
2873 create_debug_types_hash_table (objfile
);
2874 dwarf2_per_objfile
->quick_file_names_table
=
2875 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2877 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2878 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2880 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2882 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2883 struct dwarf2_per_cu_quick_data
);
2886 /* Return 1 so that gdb sees the "quick" functions. However,
2887 these functions will be no-ops because we will have expanded
2892 if (dwarf2_read_index (objfile
))
2900 /* Build a partial symbol table. */
2903 dwarf2_build_psymtabs (struct objfile
*objfile
)
2905 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2907 init_psymbol_list (objfile
, 1024);
2910 dwarf2_build_psymtabs_hard (objfile
);
2913 /* Return TRUE if OFFSET is within CU_HEADER. */
2916 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2918 unsigned int bottom
= cu_header
->offset
;
2919 unsigned int top
= (cu_header
->offset
2921 + cu_header
->initial_length_size
);
2923 return (offset
>= bottom
&& offset
< top
);
2926 /* Read in the comp unit header information from the debug_info at info_ptr.
2927 NOTE: This leaves members offset, first_die_offset to be filled in
2931 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2932 gdb_byte
*info_ptr
, bfd
*abfd
)
2935 unsigned int bytes_read
;
2937 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2938 cu_header
->initial_length_size
= bytes_read
;
2939 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2940 info_ptr
+= bytes_read
;
2941 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2943 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2945 info_ptr
+= bytes_read
;
2946 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2948 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2949 if (signed_addr
< 0)
2950 internal_error (__FILE__
, __LINE__
,
2951 _("read_comp_unit_head: dwarf from non elf file"));
2952 cu_header
->signed_addr_p
= signed_addr
;
2958 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2959 gdb_byte
*buffer
, unsigned int buffer_size
,
2962 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2964 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2966 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2967 error (_("Dwarf Error: wrong version in compilation unit header "
2968 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2969 bfd_get_filename (abfd
));
2971 if (header
->abbrev_offset
2972 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
2973 &dwarf2_per_objfile
->abbrev
))
2974 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2975 "(offset 0x%lx + 6) [in module %s]"),
2976 (long) header
->abbrev_offset
,
2977 (long) (beg_of_comp_unit
- buffer
),
2978 bfd_get_filename (abfd
));
2980 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2981 > buffer
+ buffer_size
)
2982 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2983 "(offset 0x%lx + 0) [in module %s]"),
2984 (long) header
->length
,
2985 (long) (beg_of_comp_unit
- buffer
),
2986 bfd_get_filename (abfd
));
2991 /* Read in the types comp unit header information from .debug_types entry at
2992 types_ptr. The result is a pointer to one past the end of the header. */
2995 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2996 struct dwarf2_section_info
*section
,
2997 ULONGEST
*signature
,
2998 gdb_byte
*types_ptr
, bfd
*abfd
)
3000 gdb_byte
*initial_types_ptr
= types_ptr
;
3002 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
3003 cu_header
->offset
= types_ptr
- section
->buffer
;
3005 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
3007 *signature
= read_8_bytes (abfd
, types_ptr
);
3009 types_ptr
+= cu_header
->offset_size
;
3010 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
3015 /* Allocate a new partial symtab for file named NAME and mark this new
3016 partial symtab as being an include of PST. */
3019 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3020 struct objfile
*objfile
)
3022 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3024 subpst
->section_offsets
= pst
->section_offsets
;
3025 subpst
->textlow
= 0;
3026 subpst
->texthigh
= 0;
3028 subpst
->dependencies
= (struct partial_symtab
**)
3029 obstack_alloc (&objfile
->objfile_obstack
,
3030 sizeof (struct partial_symtab
*));
3031 subpst
->dependencies
[0] = pst
;
3032 subpst
->number_of_dependencies
= 1;
3034 subpst
->globals_offset
= 0;
3035 subpst
->n_global_syms
= 0;
3036 subpst
->statics_offset
= 0;
3037 subpst
->n_static_syms
= 0;
3038 subpst
->symtab
= NULL
;
3039 subpst
->read_symtab
= pst
->read_symtab
;
3042 /* No private part is necessary for include psymtabs. This property
3043 can be used to differentiate between such include psymtabs and
3044 the regular ones. */
3045 subpst
->read_symtab_private
= NULL
;
3048 /* Read the Line Number Program data and extract the list of files
3049 included by the source file represented by PST. Build an include
3050 partial symtab for each of these included files. */
3053 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3054 struct die_info
*die
,
3055 struct partial_symtab
*pst
)
3057 struct objfile
*objfile
= cu
->objfile
;
3058 bfd
*abfd
= objfile
->obfd
;
3059 struct line_header
*lh
= NULL
;
3060 struct attribute
*attr
;
3062 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3065 unsigned int line_offset
= DW_UNSND (attr
);
3067 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3070 return; /* No linetable, so no includes. */
3072 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3073 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
3075 free_line_header (lh
);
3079 hash_type_signature (const void *item
)
3081 const struct signatured_type
*type_sig
= item
;
3083 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3084 return type_sig
->signature
;
3088 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
3090 const struct signatured_type
*lhs
= item_lhs
;
3091 const struct signatured_type
*rhs
= item_rhs
;
3093 return lhs
->signature
== rhs
->signature
;
3096 /* Allocate a hash table for signatured types. */
3099 allocate_signatured_type_table (struct objfile
*objfile
)
3101 return htab_create_alloc_ex (41,
3102 hash_type_signature
,
3105 &objfile
->objfile_obstack
,
3106 hashtab_obstack_allocate
,
3107 dummy_obstack_deallocate
);
3110 /* A helper function to add a signatured type CU to a list. */
3113 add_signatured_type_cu_to_list (void **slot
, void *datum
)
3115 struct signatured_type
*sigt
= *slot
;
3116 struct dwarf2_per_cu_data
***datap
= datum
;
3118 **datap
= &sigt
->per_cu
;
3124 /* Create the hash table of all entries in the .debug_types section.
3125 The result is zero if there is an error (e.g. missing .debug_types section),
3126 otherwise non-zero. */
3129 create_debug_types_hash_table (struct objfile
*objfile
)
3131 htab_t types_htab
= NULL
;
3132 struct dwarf2_per_cu_data
**iter
;
3134 struct dwarf2_section_info
*section
;
3136 if (VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
))
3138 dwarf2_per_objfile
->signatured_types
= NULL
;
3143 VEC_iterate (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
3147 gdb_byte
*info_ptr
, *end_ptr
;
3149 dwarf2_read_section (objfile
, section
);
3150 info_ptr
= section
->buffer
;
3152 if (info_ptr
== NULL
)
3155 if (types_htab
== NULL
)
3156 types_htab
= allocate_signatured_type_table (objfile
);
3158 if (dwarf2_die_debug
)
3159 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3161 end_ptr
= info_ptr
+ section
->size
;
3162 while (info_ptr
< end_ptr
)
3164 unsigned int offset
;
3165 unsigned int offset_size
;
3166 unsigned int type_offset
;
3167 unsigned int length
, initial_length_size
;
3168 unsigned short version
;
3170 struct signatured_type
*type_sig
;
3172 gdb_byte
*ptr
= info_ptr
;
3174 offset
= ptr
- section
->buffer
;
3176 /* We need to read the type's signature in order to build the hash
3177 table, but we don't need to read anything else just yet. */
3179 /* Sanity check to ensure entire cu is present. */
3180 length
= read_initial_length (objfile
->obfd
, ptr
,
3181 &initial_length_size
);
3182 if (ptr
+ length
+ initial_length_size
> end_ptr
)
3184 complaint (&symfile_complaints
,
3185 _("debug type entry runs off end "
3186 "of `.debug_types' section, ignored"));
3190 offset_size
= initial_length_size
== 4 ? 4 : 8;
3191 ptr
+= initial_length_size
;
3192 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3194 ptr
+= offset_size
; /* abbrev offset */
3195 ptr
+= 1; /* address size */
3196 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3198 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3200 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3201 memset (type_sig
, 0, sizeof (*type_sig
));
3202 type_sig
->signature
= signature
;
3203 type_sig
->type_offset
= type_offset
;
3204 type_sig
->per_cu
.objfile
= objfile
;
3205 type_sig
->per_cu
.debug_type_section
= section
;
3206 type_sig
->per_cu
.offset
= offset
;
3208 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3209 gdb_assert (slot
!= NULL
);
3212 const struct signatured_type
*dup_sig
= *slot
;
3214 complaint (&symfile_complaints
,
3215 _("debug type entry at offset 0x%x is duplicate to the "
3216 "entry at offset 0x%x, signature 0x%s"),
3217 offset
, dup_sig
->per_cu
.offset
,
3218 phex (signature
, sizeof (signature
)));
3219 gdb_assert (signature
== dup_sig
->signature
);
3223 if (dwarf2_die_debug
)
3224 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3225 offset
, phex (signature
, sizeof (signature
)));
3227 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3231 dwarf2_per_objfile
->signatured_types
= types_htab
;
3233 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3234 dwarf2_per_objfile
->type_comp_units
3235 = obstack_alloc (&objfile
->objfile_obstack
,
3236 dwarf2_per_objfile
->n_type_comp_units
3237 * sizeof (struct dwarf2_per_cu_data
*));
3238 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3239 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3240 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3241 == dwarf2_per_objfile
->n_type_comp_units
);
3246 /* Lookup a signature based type.
3247 Returns NULL if SIG is not present in the table. */
3249 static struct signatured_type
*
3250 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3252 struct signatured_type find_entry
, *entry
;
3254 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3256 complaint (&symfile_complaints
,
3257 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3261 find_entry
.signature
= sig
;
3262 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3266 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3269 init_cu_die_reader (struct die_reader_specs
*reader
,
3270 struct dwarf2_cu
*cu
)
3272 reader
->abfd
= cu
->objfile
->obfd
;
3274 if (cu
->per_cu
->debug_type_section
)
3276 gdb_assert (cu
->per_cu
->debug_type_section
->readin
);
3277 reader
->buffer
= cu
->per_cu
->debug_type_section
->buffer
;
3281 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3282 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3286 /* Find the base address of the compilation unit for range lists and
3287 location lists. It will normally be specified by DW_AT_low_pc.
3288 In DWARF-3 draft 4, the base address could be overridden by
3289 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3290 compilation units with discontinuous ranges. */
3293 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3295 struct attribute
*attr
;
3298 cu
->base_address
= 0;
3300 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3303 cu
->base_address
= DW_ADDR (attr
);
3308 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3311 cu
->base_address
= DW_ADDR (attr
);
3317 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3318 to combine the common parts.
3319 Process a compilation unit for a psymtab.
3320 BUFFER is a pointer to the beginning of the dwarf section buffer,
3321 either .debug_info or debug_types.
3322 INFO_PTR is a pointer to the start of the CU.
3323 Returns a pointer to the next CU. */
3326 process_psymtab_comp_unit (struct objfile
*objfile
,
3327 struct dwarf2_per_cu_data
*this_cu
,
3328 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3329 unsigned int buffer_size
)
3331 bfd
*abfd
= objfile
->obfd
;
3332 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3333 struct die_info
*comp_unit_die
;
3334 struct partial_symtab
*pst
;
3336 struct cleanup
*back_to_inner
;
3337 struct dwarf2_cu cu
;
3338 int has_children
, has_pc_info
;
3339 struct attribute
*attr
;
3340 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3341 struct die_reader_specs reader_specs
;
3342 const char *filename
;
3344 init_one_comp_unit (&cu
, objfile
);
3345 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3347 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3348 buffer
, buffer_size
,
3351 /* Complete the cu_header. */
3352 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3353 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3355 cu
.list_in_scope
= &file_symbols
;
3357 /* If this compilation unit was already read in, free the
3358 cached copy in order to read it in again. This is
3359 necessary because we skipped some symbols when we first
3360 read in the compilation unit (see load_partial_dies).
3361 This problem could be avoided, but the benefit is
3363 if (this_cu
->cu
!= NULL
)
3364 free_one_cached_comp_unit (this_cu
->cu
);
3366 /* Note that this is a pointer to our stack frame, being
3367 added to a global data structure. It will be cleaned up
3368 in free_stack_comp_unit when we finish with this
3369 compilation unit. */
3371 cu
.per_cu
= this_cu
;
3373 /* Read the abbrevs for this compilation unit into a table. */
3374 dwarf2_read_abbrevs (abfd
, &cu
);
3375 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3377 /* Read the compilation unit die. */
3378 if (this_cu
->debug_type_section
)
3379 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3380 init_cu_die_reader (&reader_specs
, &cu
);
3381 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3384 if (this_cu
->debug_type_section
)
3386 /* LENGTH has not been set yet for type units. */
3387 gdb_assert (this_cu
->offset
== cu
.header
.offset
);
3388 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3390 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3392 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3393 + cu
.header
.initial_length_size
);
3394 do_cleanups (back_to_inner
);
3398 prepare_one_comp_unit (&cu
, comp_unit_die
);
3400 /* Allocate a new partial symbol table structure. */
3401 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3402 if (attr
== NULL
|| !DW_STRING (attr
))
3405 filename
= DW_STRING (attr
);
3406 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3408 /* TEXTLOW and TEXTHIGH are set below. */
3410 objfile
->global_psymbols
.next
,
3411 objfile
->static_psymbols
.next
);
3413 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3415 pst
->dirname
= DW_STRING (attr
);
3417 pst
->read_symtab_private
= this_cu
;
3419 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3421 /* Store the function that reads in the rest of the symbol table. */
3422 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3424 this_cu
->v
.psymtab
= pst
;
3426 dwarf2_find_base_address (comp_unit_die
, &cu
);
3428 /* Possibly set the default values of LOWPC and HIGHPC from
3430 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3431 &best_highpc
, &cu
, pst
);
3432 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3433 /* Store the contiguous range if it is not empty; it can be empty for
3434 CUs with no code. */
3435 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3436 best_lowpc
+ baseaddr
,
3437 best_highpc
+ baseaddr
- 1, pst
);
3439 /* Check if comp unit has_children.
3440 If so, read the rest of the partial symbols from this comp unit.
3441 If not, there's no more debug_info for this comp unit. */
3444 struct partial_die_info
*first_die
;
3445 CORE_ADDR lowpc
, highpc
;
3447 lowpc
= ((CORE_ADDR
) -1);
3448 highpc
= ((CORE_ADDR
) 0);
3450 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3452 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3453 ! has_pc_info
, &cu
);
3455 /* If we didn't find a lowpc, set it to highpc to avoid
3456 complaints from `maint check'. */
3457 if (lowpc
== ((CORE_ADDR
) -1))
3460 /* If the compilation unit didn't have an explicit address range,
3461 then use the information extracted from its child dies. */
3465 best_highpc
= highpc
;
3468 pst
->textlow
= best_lowpc
+ baseaddr
;
3469 pst
->texthigh
= best_highpc
+ baseaddr
;
3471 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3472 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3473 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3474 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3475 sort_pst_symbols (pst
);
3477 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3478 + cu
.header
.initial_length_size
);
3480 if (this_cu
->debug_type_section
)
3482 /* It's not clear we want to do anything with stmt lists here.
3483 Waiting to see what gcc ultimately does. */
3487 /* Get the list of files included in the current compilation unit,
3488 and build a psymtab for each of them. */
3489 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3492 do_cleanups (back_to_inner
);
3497 /* Traversal function for htab_traverse_noresize.
3498 Process one .debug_types comp-unit. */
3501 process_type_comp_unit (void **slot
, void *info
)
3503 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3504 struct objfile
*objfile
= (struct objfile
*) info
;
3505 struct dwarf2_per_cu_data
*this_cu
;
3507 this_cu
= &entry
->per_cu
;
3509 gdb_assert (this_cu
->debug_type_section
->readin
);
3510 process_psymtab_comp_unit (objfile
, this_cu
,
3511 this_cu
->debug_type_section
->buffer
,
3512 (this_cu
->debug_type_section
->buffer
3514 this_cu
->debug_type_section
->size
);
3519 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3520 Build partial symbol tables for the .debug_types comp-units. */
3523 build_type_psymtabs (struct objfile
*objfile
)
3525 if (! create_debug_types_hash_table (objfile
))
3528 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3529 process_type_comp_unit
, objfile
);
3532 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3535 psymtabs_addrmap_cleanup (void *o
)
3537 struct objfile
*objfile
= o
;
3539 objfile
->psymtabs_addrmap
= NULL
;
3542 /* Build the partial symbol table by doing a quick pass through the
3543 .debug_info and .debug_abbrev sections. */
3546 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3549 struct cleanup
*back_to
, *addrmap_cleanup
;
3550 struct obstack temp_obstack
;
3552 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3554 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3555 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3557 /* Any cached compilation units will be linked by the per-objfile
3558 read_in_chain. Make sure to free them when we're done. */
3559 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3561 build_type_psymtabs (objfile
);
3563 create_all_comp_units (objfile
);
3565 /* Create a temporary address map on a temporary obstack. We later
3566 copy this to the final obstack. */
3567 obstack_init (&temp_obstack
);
3568 make_cleanup_obstack_free (&temp_obstack
);
3569 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3570 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3572 /* Since the objects we're extracting from .debug_info vary in
3573 length, only the individual functions to extract them (like
3574 read_comp_unit_head and load_partial_die) can really know whether
3575 the buffer is large enough to hold another complete object.
3577 At the moment, they don't actually check that. If .debug_info
3578 holds just one extra byte after the last compilation unit's dies,
3579 then read_comp_unit_head will happily read off the end of the
3580 buffer. read_partial_die is similarly casual. Those functions
3583 For this loop condition, simply checking whether there's any data
3584 left at all should be sufficient. */
3586 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3587 + dwarf2_per_objfile
->info
.size
))
3589 struct dwarf2_per_cu_data
*this_cu
;
3591 this_cu
= dwarf2_find_comp_unit (info_ptr
3592 - dwarf2_per_objfile
->info
.buffer
,
3595 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3596 dwarf2_per_objfile
->info
.buffer
,
3598 dwarf2_per_objfile
->info
.size
);
3601 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3602 &objfile
->objfile_obstack
);
3603 discard_cleanups (addrmap_cleanup
);
3605 do_cleanups (back_to
);
3608 /* Load the partial DIEs for a secondary CU into memory. */
3611 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3612 struct objfile
*objfile
)
3614 bfd
*abfd
= objfile
->obfd
;
3615 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3616 struct die_info
*comp_unit_die
;
3617 struct dwarf2_cu
*cu
;
3618 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3620 struct die_reader_specs reader_specs
;
3623 gdb_assert (! this_cu
->debug_type_section
);
3625 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3626 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3627 beg_of_comp_unit
= info_ptr
;
3629 if (this_cu
->cu
== NULL
)
3631 cu
= xmalloc (sizeof (*cu
));
3632 init_one_comp_unit (cu
, objfile
);
3636 /* If an error occurs while loading, release our storage. */
3637 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3639 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3640 dwarf2_per_objfile
->info
.buffer
,
3641 dwarf2_per_objfile
->info
.size
,
3644 /* Complete the cu_header. */
3645 cu
->header
.offset
= this_cu
->offset
;
3646 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3648 /* Link this compilation unit into the compilation unit tree. */
3650 cu
->per_cu
= this_cu
;
3652 /* Link this CU into read_in_chain. */
3653 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3654 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3659 info_ptr
+= cu
->header
.first_die_offset
;
3662 /* Read the abbrevs for this compilation unit into a table. */
3663 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3664 dwarf2_read_abbrevs (abfd
, cu
);
3665 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3667 /* Read the compilation unit die. */
3668 init_cu_die_reader (&reader_specs
, cu
);
3669 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3672 prepare_one_comp_unit (cu
, comp_unit_die
);
3674 /* Check if comp unit has_children.
3675 If so, read the rest of the partial symbols from this comp unit.
3676 If not, there's no more debug_info for this comp unit. */
3678 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3680 do_cleanups (free_abbrevs_cleanup
);
3684 /* We've successfully allocated this compilation unit. Let our
3685 caller clean it up when finished with it. */
3686 discard_cleanups (free_cu_cleanup
);
3690 /* Create a list of all compilation units in OBJFILE. We do this only
3691 if an inter-comp-unit reference is found; presumably if there is one,
3692 there will be many, and one will occur early in the .debug_info section.
3693 So there's no point in building this list incrementally. */
3696 create_all_comp_units (struct objfile
*objfile
)
3700 struct dwarf2_per_cu_data
**all_comp_units
;
3703 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3704 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3708 all_comp_units
= xmalloc (n_allocated
3709 * sizeof (struct dwarf2_per_cu_data
*));
3711 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3712 + dwarf2_per_objfile
->info
.size
)
3714 unsigned int length
, initial_length_size
;
3715 struct dwarf2_per_cu_data
*this_cu
;
3716 unsigned int offset
;
3718 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3720 /* Read just enough information to find out where the next
3721 compilation unit is. */
3722 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3723 &initial_length_size
);
3725 /* Save the compilation unit for later lookup. */
3726 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3727 sizeof (struct dwarf2_per_cu_data
));
3728 memset (this_cu
, 0, sizeof (*this_cu
));
3729 this_cu
->offset
= offset
;
3730 this_cu
->length
= length
+ initial_length_size
;
3731 this_cu
->objfile
= objfile
;
3733 if (n_comp_units
== n_allocated
)
3736 all_comp_units
= xrealloc (all_comp_units
,
3738 * sizeof (struct dwarf2_per_cu_data
*));
3740 all_comp_units
[n_comp_units
++] = this_cu
;
3742 info_ptr
= info_ptr
+ this_cu
->length
;
3745 dwarf2_per_objfile
->all_comp_units
3746 = obstack_alloc (&objfile
->objfile_obstack
,
3747 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3748 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3749 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3750 xfree (all_comp_units
);
3751 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3754 /* Process all loaded DIEs for compilation unit CU, starting at
3755 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3756 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3757 DW_AT_ranges). If NEED_PC is set, then this function will set
3758 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3759 and record the covered ranges in the addrmap. */
3762 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3763 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3765 struct partial_die_info
*pdi
;
3767 /* Now, march along the PDI's, descending into ones which have
3768 interesting children but skipping the children of the other ones,
3769 until we reach the end of the compilation unit. */
3775 fixup_partial_die (pdi
, cu
);
3777 /* Anonymous namespaces or modules have no name but have interesting
3778 children, so we need to look at them. Ditto for anonymous
3781 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3782 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3786 case DW_TAG_subprogram
:
3787 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3789 case DW_TAG_constant
:
3790 case DW_TAG_variable
:
3791 case DW_TAG_typedef
:
3792 case DW_TAG_union_type
:
3793 if (!pdi
->is_declaration
)
3795 add_partial_symbol (pdi
, cu
);
3798 case DW_TAG_class_type
:
3799 case DW_TAG_interface_type
:
3800 case DW_TAG_structure_type
:
3801 if (!pdi
->is_declaration
)
3803 add_partial_symbol (pdi
, cu
);
3806 case DW_TAG_enumeration_type
:
3807 if (!pdi
->is_declaration
)
3808 add_partial_enumeration (pdi
, cu
);
3810 case DW_TAG_base_type
:
3811 case DW_TAG_subrange_type
:
3812 /* File scope base type definitions are added to the partial
3814 add_partial_symbol (pdi
, cu
);
3816 case DW_TAG_namespace
:
3817 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3820 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3827 /* If the die has a sibling, skip to the sibling. */
3829 pdi
= pdi
->die_sibling
;
3833 /* Functions used to compute the fully scoped name of a partial DIE.
3835 Normally, this is simple. For C++, the parent DIE's fully scoped
3836 name is concatenated with "::" and the partial DIE's name. For
3837 Java, the same thing occurs except that "." is used instead of "::".
3838 Enumerators are an exception; they use the scope of their parent
3839 enumeration type, i.e. the name of the enumeration type is not
3840 prepended to the enumerator.
3842 There are two complexities. One is DW_AT_specification; in this
3843 case "parent" means the parent of the target of the specification,
3844 instead of the direct parent of the DIE. The other is compilers
3845 which do not emit DW_TAG_namespace; in this case we try to guess
3846 the fully qualified name of structure types from their members'
3847 linkage names. This must be done using the DIE's children rather
3848 than the children of any DW_AT_specification target. We only need
3849 to do this for structures at the top level, i.e. if the target of
3850 any DW_AT_specification (if any; otherwise the DIE itself) does not
3853 /* Compute the scope prefix associated with PDI's parent, in
3854 compilation unit CU. The result will be allocated on CU's
3855 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3856 field. NULL is returned if no prefix is necessary. */
3858 partial_die_parent_scope (struct partial_die_info
*pdi
,
3859 struct dwarf2_cu
*cu
)
3861 char *grandparent_scope
;
3862 struct partial_die_info
*parent
, *real_pdi
;
3864 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3865 then this means the parent of the specification DIE. */
3868 while (real_pdi
->has_specification
)
3869 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3871 parent
= real_pdi
->die_parent
;
3875 if (parent
->scope_set
)
3876 return parent
->scope
;
3878 fixup_partial_die (parent
, cu
);
3880 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3882 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3883 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3884 Work around this problem here. */
3885 if (cu
->language
== language_cplus
3886 && parent
->tag
== DW_TAG_namespace
3887 && strcmp (parent
->name
, "::") == 0
3888 && grandparent_scope
== NULL
)
3890 parent
->scope
= NULL
;
3891 parent
->scope_set
= 1;
3895 if (parent
->tag
== DW_TAG_namespace
3896 || parent
->tag
== DW_TAG_module
3897 || parent
->tag
== DW_TAG_structure_type
3898 || parent
->tag
== DW_TAG_class_type
3899 || parent
->tag
== DW_TAG_interface_type
3900 || parent
->tag
== DW_TAG_union_type
3901 || parent
->tag
== DW_TAG_enumeration_type
)
3903 if (grandparent_scope
== NULL
)
3904 parent
->scope
= parent
->name
;
3906 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3908 parent
->name
, 0, cu
);
3910 else if (parent
->tag
== DW_TAG_enumerator
)
3911 /* Enumerators should not get the name of the enumeration as a prefix. */
3912 parent
->scope
= grandparent_scope
;
3915 /* FIXME drow/2004-04-01: What should we be doing with
3916 function-local names? For partial symbols, we should probably be
3918 complaint (&symfile_complaints
,
3919 _("unhandled containing DIE tag %d for DIE at %d"),
3920 parent
->tag
, pdi
->offset
);
3921 parent
->scope
= grandparent_scope
;
3924 parent
->scope_set
= 1;
3925 return parent
->scope
;
3928 /* Return the fully scoped name associated with PDI, from compilation unit
3929 CU. The result will be allocated with malloc. */
3931 partial_die_full_name (struct partial_die_info
*pdi
,
3932 struct dwarf2_cu
*cu
)
3936 /* If this is a template instantiation, we can not work out the
3937 template arguments from partial DIEs. So, unfortunately, we have
3938 to go through the full DIEs. At least any work we do building
3939 types here will be reused if full symbols are loaded later. */
3940 if (pdi
->has_template_arguments
)
3942 fixup_partial_die (pdi
, cu
);
3944 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3946 struct die_info
*die
;
3947 struct attribute attr
;
3948 struct dwarf2_cu
*ref_cu
= cu
;
3951 attr
.form
= DW_FORM_ref_addr
;
3952 attr
.u
.addr
= pdi
->offset
;
3953 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3955 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3959 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3960 if (parent_scope
== NULL
)
3963 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3967 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3969 struct objfile
*objfile
= cu
->objfile
;
3971 char *actual_name
= NULL
;
3972 const struct partial_symbol
*psym
= NULL
;
3974 int built_actual_name
= 0;
3976 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3978 actual_name
= partial_die_full_name (pdi
, cu
);
3980 built_actual_name
= 1;
3982 if (actual_name
== NULL
)
3983 actual_name
= pdi
->name
;
3987 case DW_TAG_subprogram
:
3988 if (pdi
->is_external
|| cu
->language
== language_ada
)
3990 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3991 of the global scope. But in Ada, we want to be able to access
3992 nested procedures globally. So all Ada subprograms are stored
3993 in the global scope. */
3994 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3995 mst_text, objfile); */
3996 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3998 VAR_DOMAIN
, LOC_BLOCK
,
3999 &objfile
->global_psymbols
,
4000 0, pdi
->lowpc
+ baseaddr
,
4001 cu
->language
, objfile
);
4005 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4006 mst_file_text, objfile); */
4007 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4009 VAR_DOMAIN
, LOC_BLOCK
,
4010 &objfile
->static_psymbols
,
4011 0, pdi
->lowpc
+ baseaddr
,
4012 cu
->language
, objfile
);
4015 case DW_TAG_constant
:
4017 struct psymbol_allocation_list
*list
;
4019 if (pdi
->is_external
)
4020 list
= &objfile
->global_psymbols
;
4022 list
= &objfile
->static_psymbols
;
4023 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4024 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4025 list
, 0, 0, cu
->language
, objfile
);
4028 case DW_TAG_variable
:
4030 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4034 && !dwarf2_per_objfile
->has_section_at_zero
)
4036 /* A global or static variable may also have been stripped
4037 out by the linker if unused, in which case its address
4038 will be nullified; do not add such variables into partial
4039 symbol table then. */
4041 else if (pdi
->is_external
)
4044 Don't enter into the minimal symbol tables as there is
4045 a minimal symbol table entry from the ELF symbols already.
4046 Enter into partial symbol table if it has a location
4047 descriptor or a type.
4048 If the location descriptor is missing, new_symbol will create
4049 a LOC_UNRESOLVED symbol, the address of the variable will then
4050 be determined from the minimal symbol table whenever the variable
4052 The address for the partial symbol table entry is not
4053 used by GDB, but it comes in handy for debugging partial symbol
4056 if (pdi
->locdesc
|| pdi
->has_type
)
4057 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4059 VAR_DOMAIN
, LOC_STATIC
,
4060 &objfile
->global_psymbols
,
4062 cu
->language
, objfile
);
4066 /* Static Variable. Skip symbols without location descriptors. */
4067 if (pdi
->locdesc
== NULL
)
4069 if (built_actual_name
)
4070 xfree (actual_name
);
4073 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4074 mst_file_data, objfile); */
4075 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4077 VAR_DOMAIN
, LOC_STATIC
,
4078 &objfile
->static_psymbols
,
4080 cu
->language
, objfile
);
4083 case DW_TAG_typedef
:
4084 case DW_TAG_base_type
:
4085 case DW_TAG_subrange_type
:
4086 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4088 VAR_DOMAIN
, LOC_TYPEDEF
,
4089 &objfile
->static_psymbols
,
4090 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4092 case DW_TAG_namespace
:
4093 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4095 VAR_DOMAIN
, LOC_TYPEDEF
,
4096 &objfile
->global_psymbols
,
4097 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4099 case DW_TAG_class_type
:
4100 case DW_TAG_interface_type
:
4101 case DW_TAG_structure_type
:
4102 case DW_TAG_union_type
:
4103 case DW_TAG_enumeration_type
:
4104 /* Skip external references. The DWARF standard says in the section
4105 about "Structure, Union, and Class Type Entries": "An incomplete
4106 structure, union or class type is represented by a structure,
4107 union or class entry that does not have a byte size attribute
4108 and that has a DW_AT_declaration attribute." */
4109 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4111 if (built_actual_name
)
4112 xfree (actual_name
);
4116 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4117 static vs. global. */
4118 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4120 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4121 (cu
->language
== language_cplus
4122 || cu
->language
== language_java
)
4123 ? &objfile
->global_psymbols
4124 : &objfile
->static_psymbols
,
4125 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4128 case DW_TAG_enumerator
:
4129 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4131 VAR_DOMAIN
, LOC_CONST
,
4132 (cu
->language
== language_cplus
4133 || cu
->language
== language_java
)
4134 ? &objfile
->global_psymbols
4135 : &objfile
->static_psymbols
,
4136 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4142 if (built_actual_name
)
4143 xfree (actual_name
);
4146 /* Read a partial die corresponding to a namespace; also, add a symbol
4147 corresponding to that namespace to the symbol table. NAMESPACE is
4148 the name of the enclosing namespace. */
4151 add_partial_namespace (struct partial_die_info
*pdi
,
4152 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4153 int need_pc
, struct dwarf2_cu
*cu
)
4155 /* Add a symbol for the namespace. */
4157 add_partial_symbol (pdi
, cu
);
4159 /* Now scan partial symbols in that namespace. */
4161 if (pdi
->has_children
)
4162 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4165 /* Read a partial die corresponding to a Fortran module. */
4168 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4169 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4171 /* Now scan partial symbols in that module. */
4173 if (pdi
->has_children
)
4174 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4177 /* Read a partial die corresponding to a subprogram and create a partial
4178 symbol for that subprogram. When the CU language allows it, this
4179 routine also defines a partial symbol for each nested subprogram
4180 that this subprogram contains.
4182 DIE my also be a lexical block, in which case we simply search
4183 recursively for suprograms defined inside that lexical block.
4184 Again, this is only performed when the CU language allows this
4185 type of definitions. */
4188 add_partial_subprogram (struct partial_die_info
*pdi
,
4189 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4190 int need_pc
, struct dwarf2_cu
*cu
)
4192 if (pdi
->tag
== DW_TAG_subprogram
)
4194 if (pdi
->has_pc_info
)
4196 if (pdi
->lowpc
< *lowpc
)
4197 *lowpc
= pdi
->lowpc
;
4198 if (pdi
->highpc
> *highpc
)
4199 *highpc
= pdi
->highpc
;
4203 struct objfile
*objfile
= cu
->objfile
;
4205 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4206 SECT_OFF_TEXT (objfile
));
4207 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4208 pdi
->lowpc
+ baseaddr
,
4209 pdi
->highpc
- 1 + baseaddr
,
4210 cu
->per_cu
->v
.psymtab
);
4212 if (!pdi
->is_declaration
)
4213 /* Ignore subprogram DIEs that do not have a name, they are
4214 illegal. Do not emit a complaint at this point, we will
4215 do so when we convert this psymtab into a symtab. */
4217 add_partial_symbol (pdi
, cu
);
4221 if (! pdi
->has_children
)
4224 if (cu
->language
== language_ada
)
4226 pdi
= pdi
->die_child
;
4229 fixup_partial_die (pdi
, cu
);
4230 if (pdi
->tag
== DW_TAG_subprogram
4231 || pdi
->tag
== DW_TAG_lexical_block
)
4232 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4233 pdi
= pdi
->die_sibling
;
4238 /* Read a partial die corresponding to an enumeration type. */
4241 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4242 struct dwarf2_cu
*cu
)
4244 struct partial_die_info
*pdi
;
4246 if (enum_pdi
->name
!= NULL
)
4247 add_partial_symbol (enum_pdi
, cu
);
4249 pdi
= enum_pdi
->die_child
;
4252 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4253 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4255 add_partial_symbol (pdi
, cu
);
4256 pdi
= pdi
->die_sibling
;
4260 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4261 Return the corresponding abbrev, or NULL if the number is zero (indicating
4262 an empty DIE). In either case *BYTES_READ will be set to the length of
4263 the initial number. */
4265 static struct abbrev_info
*
4266 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4267 struct dwarf2_cu
*cu
)
4269 bfd
*abfd
= cu
->objfile
->obfd
;
4270 unsigned int abbrev_number
;
4271 struct abbrev_info
*abbrev
;
4273 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4275 if (abbrev_number
== 0)
4278 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4281 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4282 abbrev_number
, bfd_get_filename (abfd
));
4288 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4289 Returns a pointer to the end of a series of DIEs, terminated by an empty
4290 DIE. Any children of the skipped DIEs will also be skipped. */
4293 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4295 struct abbrev_info
*abbrev
;
4296 unsigned int bytes_read
;
4300 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4302 return info_ptr
+ bytes_read
;
4304 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4308 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4309 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4310 abbrev corresponding to that skipped uleb128 should be passed in
4311 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4315 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4316 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4318 unsigned int bytes_read
;
4319 struct attribute attr
;
4320 bfd
*abfd
= cu
->objfile
->obfd
;
4321 unsigned int form
, i
;
4323 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4325 /* The only abbrev we care about is DW_AT_sibling. */
4326 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4328 read_attribute (&attr
, &abbrev
->attrs
[i
],
4329 abfd
, info_ptr
, cu
);
4330 if (attr
.form
== DW_FORM_ref_addr
)
4331 complaint (&symfile_complaints
,
4332 _("ignoring absolute DW_AT_sibling"));
4334 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4337 /* If it isn't DW_AT_sibling, skip this attribute. */
4338 form
= abbrev
->attrs
[i
].form
;
4342 case DW_FORM_ref_addr
:
4343 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4344 and later it is offset sized. */
4345 if (cu
->header
.version
== 2)
4346 info_ptr
+= cu
->header
.addr_size
;
4348 info_ptr
+= cu
->header
.offset_size
;
4351 info_ptr
+= cu
->header
.addr_size
;
4358 case DW_FORM_flag_present
:
4370 case DW_FORM_ref_sig8
:
4373 case DW_FORM_string
:
4374 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4375 info_ptr
+= bytes_read
;
4377 case DW_FORM_sec_offset
:
4379 info_ptr
+= cu
->header
.offset_size
;
4381 case DW_FORM_exprloc
:
4383 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4384 info_ptr
+= bytes_read
;
4386 case DW_FORM_block1
:
4387 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4389 case DW_FORM_block2
:
4390 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4392 case DW_FORM_block4
:
4393 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4397 case DW_FORM_ref_udata
:
4398 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4400 case DW_FORM_indirect
:
4401 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4402 info_ptr
+= bytes_read
;
4403 /* We need to continue parsing from here, so just go back to
4405 goto skip_attribute
;
4408 error (_("Dwarf Error: Cannot handle %s "
4409 "in DWARF reader [in module %s]"),
4410 dwarf_form_name (form
),
4411 bfd_get_filename (abfd
));
4415 if (abbrev
->has_children
)
4416 return skip_children (buffer
, info_ptr
, cu
);
4421 /* Locate ORIG_PDI's sibling.
4422 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4426 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4427 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4428 bfd
*abfd
, struct dwarf2_cu
*cu
)
4430 /* Do we know the sibling already? */
4432 if (orig_pdi
->sibling
)
4433 return orig_pdi
->sibling
;
4435 /* Are there any children to deal with? */
4437 if (!orig_pdi
->has_children
)
4440 /* Skip the children the long way. */
4442 return skip_children (buffer
, info_ptr
, cu
);
4445 /* Expand this partial symbol table into a full symbol table. */
4448 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4454 warning (_("bug: psymtab for %s is already read in."),
4461 printf_filtered (_("Reading in symbols for %s..."),
4463 gdb_flush (gdb_stdout
);
4466 /* Restore our global data. */
4467 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4468 dwarf2_objfile_data_key
);
4470 /* If this psymtab is constructed from a debug-only objfile, the
4471 has_section_at_zero flag will not necessarily be correct. We
4472 can get the correct value for this flag by looking at the data
4473 associated with the (presumably stripped) associated objfile. */
4474 if (pst
->objfile
->separate_debug_objfile_backlink
)
4476 struct dwarf2_per_objfile
*dpo_backlink
4477 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4478 dwarf2_objfile_data_key
);
4480 dwarf2_per_objfile
->has_section_at_zero
4481 = dpo_backlink
->has_section_at_zero
;
4484 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4486 psymtab_to_symtab_1 (pst
);
4488 /* Finish up the debug error message. */
4490 printf_filtered (_("done.\n"));
4495 /* Add PER_CU to the queue. */
4498 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4500 struct dwarf2_queue_item
*item
;
4503 item
= xmalloc (sizeof (*item
));
4504 item
->per_cu
= per_cu
;
4507 if (dwarf2_queue
== NULL
)
4508 dwarf2_queue
= item
;
4510 dwarf2_queue_tail
->next
= item
;
4512 dwarf2_queue_tail
= item
;
4515 /* Process the queue. */
4518 process_queue (struct objfile
*objfile
)
4520 struct dwarf2_queue_item
*item
, *next_item
;
4522 /* The queue starts out with one item, but following a DIE reference
4523 may load a new CU, adding it to the end of the queue. */
4524 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4526 if (dwarf2_per_objfile
->using_index
4527 ? !item
->per_cu
->v
.quick
->symtab
4528 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4529 process_full_comp_unit (item
->per_cu
);
4531 item
->per_cu
->queued
= 0;
4532 next_item
= item
->next
;
4536 dwarf2_queue_tail
= NULL
;
4539 /* Free all allocated queue entries. This function only releases anything if
4540 an error was thrown; if the queue was processed then it would have been
4541 freed as we went along. */
4544 dwarf2_release_queue (void *dummy
)
4546 struct dwarf2_queue_item
*item
, *last
;
4548 item
= dwarf2_queue
;
4551 /* Anything still marked queued is likely to be in an
4552 inconsistent state, so discard it. */
4553 if (item
->per_cu
->queued
)
4555 if (item
->per_cu
->cu
!= NULL
)
4556 free_one_cached_comp_unit (item
->per_cu
->cu
);
4557 item
->per_cu
->queued
= 0;
4565 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4568 /* Read in full symbols for PST, and anything it depends on. */
4571 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4573 struct dwarf2_per_cu_data
*per_cu
;
4574 struct cleanup
*back_to
;
4577 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4578 if (!pst
->dependencies
[i
]->readin
)
4580 /* Inform about additional files that need to be read in. */
4583 /* FIXME: i18n: Need to make this a single string. */
4584 fputs_filtered (" ", gdb_stdout
);
4586 fputs_filtered ("and ", gdb_stdout
);
4588 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4589 wrap_here (""); /* Flush output. */
4590 gdb_flush (gdb_stdout
);
4592 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4595 per_cu
= pst
->read_symtab_private
;
4599 /* It's an include file, no symbols to read for it.
4600 Everything is in the parent symtab. */
4605 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4608 /* Load the DIEs associated with PER_CU into memory. */
4611 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
4612 struct objfile
*objfile
)
4614 bfd
*abfd
= objfile
->obfd
;
4615 struct dwarf2_cu
*cu
;
4616 unsigned int offset
;
4617 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4618 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4619 struct attribute
*attr
;
4622 gdb_assert (! per_cu
->debug_type_section
);
4624 /* Set local variables from the partial symbol table info. */
4625 offset
= per_cu
->offset
;
4627 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4628 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4629 beg_of_comp_unit
= info_ptr
;
4631 if (per_cu
->cu
== NULL
)
4633 cu
= xmalloc (sizeof (*cu
));
4634 init_one_comp_unit (cu
, objfile
);
4638 /* If an error occurs while loading, release our storage. */
4639 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4641 /* Read in the comp_unit header. */
4642 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4644 /* Complete the cu_header. */
4645 cu
->header
.offset
= offset
;
4646 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4648 /* Read the abbrevs for this compilation unit. */
4649 dwarf2_read_abbrevs (abfd
, cu
);
4650 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4652 /* Link this compilation unit into the compilation unit tree. */
4654 cu
->per_cu
= per_cu
;
4656 /* Link this CU into read_in_chain. */
4657 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4658 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4663 info_ptr
+= cu
->header
.first_die_offset
;
4666 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4668 /* We try not to read any attributes in this function, because not
4669 all objfiles needed for references have been loaded yet, and symbol
4670 table processing isn't initialized. But we have to set the CU language,
4671 or we won't be able to build types correctly. */
4672 prepare_one_comp_unit (cu
, cu
->dies
);
4674 /* Similarly, if we do not read the producer, we can not apply
4675 producer-specific interpretation. */
4676 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4678 cu
->producer
= DW_STRING (attr
);
4682 do_cleanups (free_abbrevs_cleanup
);
4684 /* We've successfully allocated this compilation unit. Let our
4685 caller clean it up when finished with it. */
4686 discard_cleanups (free_cu_cleanup
);
4690 /* Add a DIE to the delayed physname list. */
4693 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4694 const char *name
, struct die_info
*die
,
4695 struct dwarf2_cu
*cu
)
4697 struct delayed_method_info mi
;
4699 mi
.fnfield_index
= fnfield_index
;
4703 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4706 /* A cleanup for freeing the delayed method list. */
4709 free_delayed_list (void *ptr
)
4711 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4712 if (cu
->method_list
!= NULL
)
4714 VEC_free (delayed_method_info
, cu
->method_list
);
4715 cu
->method_list
= NULL
;
4719 /* Compute the physnames of any methods on the CU's method list.
4721 The computation of method physnames is delayed in order to avoid the
4722 (bad) condition that one of the method's formal parameters is of an as yet
4726 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4729 struct delayed_method_info
*mi
;
4730 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4732 const char *physname
;
4733 struct fn_fieldlist
*fn_flp
4734 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4735 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4736 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4740 /* Generate full symbol information for PST and CU, whose DIEs have
4741 already been loaded into memory. */
4744 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4746 struct dwarf2_cu
*cu
= per_cu
->cu
;
4747 struct objfile
*objfile
= per_cu
->objfile
;
4748 CORE_ADDR lowpc
, highpc
;
4749 struct symtab
*symtab
;
4750 struct cleanup
*back_to
, *delayed_list_cleanup
;
4753 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4756 back_to
= make_cleanup (really_free_pendings
, NULL
);
4757 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4759 cu
->list_in_scope
= &file_symbols
;
4761 /* Do line number decoding in read_file_scope () */
4762 process_die (cu
->dies
, cu
);
4764 /* Now that we have processed all the DIEs in the CU, all the types
4765 should be complete, and it should now be safe to compute all of the
4767 compute_delayed_physnames (cu
);
4768 do_cleanups (delayed_list_cleanup
);
4770 /* Some compilers don't define a DW_AT_high_pc attribute for the
4771 compilation unit. If the DW_AT_high_pc is missing, synthesize
4772 it, by scanning the DIE's below the compilation unit. */
4773 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4775 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4779 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
4781 /* Set symtab language to language from DW_AT_language. If the
4782 compilation is from a C file generated by language preprocessors, do
4783 not set the language if it was already deduced by start_subfile. */
4784 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4785 symtab
->language
= cu
->language
;
4787 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4788 produce DW_AT_location with location lists but it can be possibly
4789 invalid without -fvar-tracking.
4791 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4792 needed, it would be wrong due to missing DW_AT_producer there.
4794 Still one can confuse GDB by using non-standard GCC compilation
4795 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4797 if (cu
->has_loclist
&& gcc_4_minor
>= 0)
4798 symtab
->locations_valid
= 1;
4800 if (gcc_4_minor
>= 5)
4801 symtab
->epilogue_unwind_valid
= 1;
4804 if (dwarf2_per_objfile
->using_index
)
4805 per_cu
->v
.quick
->symtab
= symtab
;
4808 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4809 pst
->symtab
= symtab
;
4813 do_cleanups (back_to
);
4816 /* Process a die and its children. */
4819 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4823 case DW_TAG_padding
:
4825 case DW_TAG_compile_unit
:
4826 read_file_scope (die
, cu
);
4828 case DW_TAG_type_unit
:
4829 read_type_unit_scope (die
, cu
);
4831 case DW_TAG_subprogram
:
4832 case DW_TAG_inlined_subroutine
:
4833 read_func_scope (die
, cu
);
4835 case DW_TAG_lexical_block
:
4836 case DW_TAG_try_block
:
4837 case DW_TAG_catch_block
:
4838 read_lexical_block_scope (die
, cu
);
4840 case DW_TAG_class_type
:
4841 case DW_TAG_interface_type
:
4842 case DW_TAG_structure_type
:
4843 case DW_TAG_union_type
:
4844 process_structure_scope (die
, cu
);
4846 case DW_TAG_enumeration_type
:
4847 process_enumeration_scope (die
, cu
);
4850 /* These dies have a type, but processing them does not create
4851 a symbol or recurse to process the children. Therefore we can
4852 read them on-demand through read_type_die. */
4853 case DW_TAG_subroutine_type
:
4854 case DW_TAG_set_type
:
4855 case DW_TAG_array_type
:
4856 case DW_TAG_pointer_type
:
4857 case DW_TAG_ptr_to_member_type
:
4858 case DW_TAG_reference_type
:
4859 case DW_TAG_string_type
:
4862 case DW_TAG_base_type
:
4863 case DW_TAG_subrange_type
:
4864 case DW_TAG_typedef
:
4865 /* Add a typedef symbol for the type definition, if it has a
4867 new_symbol (die
, read_type_die (die
, cu
), cu
);
4869 case DW_TAG_common_block
:
4870 read_common_block (die
, cu
);
4872 case DW_TAG_common_inclusion
:
4874 case DW_TAG_namespace
:
4875 processing_has_namespace_info
= 1;
4876 read_namespace (die
, cu
);
4879 processing_has_namespace_info
= 1;
4880 read_module (die
, cu
);
4882 case DW_TAG_imported_declaration
:
4883 case DW_TAG_imported_module
:
4884 processing_has_namespace_info
= 1;
4885 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4886 || cu
->language
!= language_fortran
))
4887 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4888 dwarf_tag_name (die
->tag
));
4889 read_import_statement (die
, cu
);
4892 new_symbol (die
, NULL
, cu
);
4897 /* A helper function for dwarf2_compute_name which determines whether DIE
4898 needs to have the name of the scope prepended to the name listed in the
4902 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4904 struct attribute
*attr
;
4908 case DW_TAG_namespace
:
4909 case DW_TAG_typedef
:
4910 case DW_TAG_class_type
:
4911 case DW_TAG_interface_type
:
4912 case DW_TAG_structure_type
:
4913 case DW_TAG_union_type
:
4914 case DW_TAG_enumeration_type
:
4915 case DW_TAG_enumerator
:
4916 case DW_TAG_subprogram
:
4920 case DW_TAG_variable
:
4921 case DW_TAG_constant
:
4922 /* We only need to prefix "globally" visible variables. These include
4923 any variable marked with DW_AT_external or any variable that
4924 lives in a namespace. [Variables in anonymous namespaces
4925 require prefixing, but they are not DW_AT_external.] */
4927 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4929 struct dwarf2_cu
*spec_cu
= cu
;
4931 return die_needs_namespace (die_specification (die
, &spec_cu
),
4935 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4936 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4937 && die
->parent
->tag
!= DW_TAG_module
)
4939 /* A variable in a lexical block of some kind does not need a
4940 namespace, even though in C++ such variables may be external
4941 and have a mangled name. */
4942 if (die
->parent
->tag
== DW_TAG_lexical_block
4943 || die
->parent
->tag
== DW_TAG_try_block
4944 || die
->parent
->tag
== DW_TAG_catch_block
4945 || die
->parent
->tag
== DW_TAG_subprogram
)
4954 /* Retrieve the last character from a mem_file. */
4957 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4959 char *last_char_p
= (char *) object
;
4962 *last_char_p
= buffer
[length
- 1];
4965 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4966 compute the physname for the object, which include a method's
4967 formal parameters (C++/Java) and return type (Java).
4969 For Ada, return the DIE's linkage name rather than the fully qualified
4970 name. PHYSNAME is ignored..
4972 The result is allocated on the objfile_obstack and canonicalized. */
4975 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4979 name
= dwarf2_name (die
, cu
);
4981 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4982 compute it by typename_concat inside GDB. */
4983 if (cu
->language
== language_ada
4984 || (cu
->language
== language_fortran
&& physname
))
4986 /* For Ada unit, we prefer the linkage name over the name, as
4987 the former contains the exported name, which the user expects
4988 to be able to reference. Ideally, we want the user to be able
4989 to reference this entity using either natural or linkage name,
4990 but we haven't started looking at this enhancement yet. */
4991 struct attribute
*attr
;
4993 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4995 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4996 if (attr
&& DW_STRING (attr
))
4997 return DW_STRING (attr
);
5000 /* These are the only languages we know how to qualify names in. */
5002 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5003 || cu
->language
== language_fortran
))
5005 if (die_needs_namespace (die
, cu
))
5009 struct ui_file
*buf
;
5011 prefix
= determine_prefix (die
, cu
);
5012 buf
= mem_fileopen ();
5013 if (*prefix
!= '\0')
5015 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5018 fputs_unfiltered (prefixed_name
, buf
);
5019 xfree (prefixed_name
);
5022 fputs_unfiltered (name
, buf
);
5024 /* Template parameters may be specified in the DIE's DW_AT_name, or
5025 as children with DW_TAG_template_type_param or
5026 DW_TAG_value_type_param. If the latter, add them to the name
5027 here. If the name already has template parameters, then
5028 skip this step; some versions of GCC emit both, and
5029 it is more efficient to use the pre-computed name.
5031 Something to keep in mind about this process: it is very
5032 unlikely, or in some cases downright impossible, to produce
5033 something that will match the mangled name of a function.
5034 If the definition of the function has the same debug info,
5035 we should be able to match up with it anyway. But fallbacks
5036 using the minimal symbol, for instance to find a method
5037 implemented in a stripped copy of libstdc++, will not work.
5038 If we do not have debug info for the definition, we will have to
5039 match them up some other way.
5041 When we do name matching there is a related problem with function
5042 templates; two instantiated function templates are allowed to
5043 differ only by their return types, which we do not add here. */
5045 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5047 struct attribute
*attr
;
5048 struct die_info
*child
;
5051 die
->building_fullname
= 1;
5053 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5058 struct dwarf2_locexpr_baton
*baton
;
5061 if (child
->tag
!= DW_TAG_template_type_param
5062 && child
->tag
!= DW_TAG_template_value_param
)
5067 fputs_unfiltered ("<", buf
);
5071 fputs_unfiltered (", ", buf
);
5073 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5076 complaint (&symfile_complaints
,
5077 _("template parameter missing DW_AT_type"));
5078 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5081 type
= die_type (child
, cu
);
5083 if (child
->tag
== DW_TAG_template_type_param
)
5085 c_print_type (type
, "", buf
, -1, 0);
5089 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5092 complaint (&symfile_complaints
,
5093 _("template parameter missing "
5094 "DW_AT_const_value"));
5095 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5099 dwarf2_const_value_attr (attr
, type
, name
,
5100 &cu
->comp_unit_obstack
, cu
,
5101 &value
, &bytes
, &baton
);
5103 if (TYPE_NOSIGN (type
))
5104 /* GDB prints characters as NUMBER 'CHAR'. If that's
5105 changed, this can use value_print instead. */
5106 c_printchar (value
, type
, buf
);
5109 struct value_print_options opts
;
5112 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5116 else if (bytes
!= NULL
)
5118 v
= allocate_value (type
);
5119 memcpy (value_contents_writeable (v
), bytes
,
5120 TYPE_LENGTH (type
));
5123 v
= value_from_longest (type
, value
);
5125 /* Specify decimal so that we do not depend on
5127 get_formatted_print_options (&opts
, 'd');
5129 value_print (v
, buf
, &opts
);
5135 die
->building_fullname
= 0;
5139 /* Close the argument list, with a space if necessary
5140 (nested templates). */
5141 char last_char
= '\0';
5142 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5143 if (last_char
== '>')
5144 fputs_unfiltered (" >", buf
);
5146 fputs_unfiltered (">", buf
);
5150 /* For Java and C++ methods, append formal parameter type
5151 information, if PHYSNAME. */
5153 if (physname
&& die
->tag
== DW_TAG_subprogram
5154 && (cu
->language
== language_cplus
5155 || cu
->language
== language_java
))
5157 struct type
*type
= read_type_die (die
, cu
);
5159 c_type_print_args (type
, buf
, 1, cu
->language
);
5161 if (cu
->language
== language_java
)
5163 /* For java, we must append the return type to method
5165 if (die
->tag
== DW_TAG_subprogram
)
5166 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5169 else if (cu
->language
== language_cplus
)
5171 /* Assume that an artificial first parameter is
5172 "this", but do not crash if it is not. RealView
5173 marks unnamed (and thus unused) parameters as
5174 artificial; there is no way to differentiate
5176 if (TYPE_NFIELDS (type
) > 0
5177 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5178 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5179 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5181 fputs_unfiltered (" const", buf
);
5185 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
5187 ui_file_delete (buf
);
5189 if (cu
->language
== language_cplus
)
5192 = dwarf2_canonicalize_name (name
, cu
,
5193 &cu
->objfile
->objfile_obstack
);
5204 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5205 If scope qualifiers are appropriate they will be added. The result
5206 will be allocated on the objfile_obstack, or NULL if the DIE does
5207 not have a name. NAME may either be from a previous call to
5208 dwarf2_name or NULL.
5210 The output string will be canonicalized (if C++/Java). */
5213 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5215 return dwarf2_compute_name (name
, die
, cu
, 0);
5218 /* Construct a physname for the given DIE in CU. NAME may either be
5219 from a previous call to dwarf2_name or NULL. The result will be
5220 allocated on the objfile_objstack or NULL if the DIE does not have a
5223 The output string will be canonicalized (if C++/Java). */
5226 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5228 struct attribute
*attr
;
5229 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5230 struct cleanup
*back_to
;
5233 /* In this case dwarf2_compute_name is just a shortcut not building anything
5235 if (!die_needs_namespace (die
, cu
))
5236 return dwarf2_compute_name (name
, die
, cu
, 1);
5238 back_to
= make_cleanup (null_cleanup
, NULL
);
5240 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5242 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5244 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5246 if (attr
&& DW_STRING (attr
))
5250 mangled
= DW_STRING (attr
);
5252 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5253 type. It is easier for GDB users to search for such functions as
5254 `name(params)' than `long name(params)'. In such case the minimal
5255 symbol names do not match the full symbol names but for template
5256 functions there is never a need to look up their definition from their
5257 declaration so the only disadvantage remains the minimal symbol
5258 variant `long name(params)' does not have the proper inferior type.
5261 demangled
= cplus_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
5262 | (cu
->language
== language_java
5263 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5267 make_cleanup (xfree
, demangled
);
5277 if (canon
== NULL
|| check_physname
)
5279 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5281 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5283 /* It may not mean a bug in GDB. The compiler could also
5284 compute DW_AT_linkage_name incorrectly. But in such case
5285 GDB would need to be bug-to-bug compatible. */
5287 complaint (&symfile_complaints
,
5288 _("Computed physname <%s> does not match demangled <%s> "
5289 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5290 physname
, canon
, mangled
, die
->offset
, cu
->objfile
->name
);
5292 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5293 is available here - over computed PHYSNAME. It is safer
5294 against both buggy GDB and buggy compilers. */
5308 retval
= obsavestring (retval
, strlen (retval
),
5309 &cu
->objfile
->objfile_obstack
);
5311 do_cleanups (back_to
);
5315 /* Read the import statement specified by the given die and record it. */
5318 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5320 struct attribute
*import_attr
;
5321 struct die_info
*imported_die
, *child_die
;
5322 struct dwarf2_cu
*imported_cu
;
5323 const char *imported_name
;
5324 const char *imported_name_prefix
;
5325 const char *canonical_name
;
5326 const char *import_alias
;
5327 const char *imported_declaration
= NULL
;
5328 const char *import_prefix
;
5329 VEC (const_char_ptr
) *excludes
= NULL
;
5330 struct cleanup
*cleanups
;
5334 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5335 if (import_attr
== NULL
)
5337 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5338 dwarf_tag_name (die
->tag
));
5343 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5344 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5345 if (imported_name
== NULL
)
5347 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5349 The import in the following code:
5363 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5364 <52> DW_AT_decl_file : 1
5365 <53> DW_AT_decl_line : 6
5366 <54> DW_AT_import : <0x75>
5367 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5369 <5b> DW_AT_decl_file : 1
5370 <5c> DW_AT_decl_line : 2
5371 <5d> DW_AT_type : <0x6e>
5373 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5374 <76> DW_AT_byte_size : 4
5375 <77> DW_AT_encoding : 5 (signed)
5377 imports the wrong die ( 0x75 instead of 0x58 ).
5378 This case will be ignored until the gcc bug is fixed. */
5382 /* Figure out the local name after import. */
5383 import_alias
= dwarf2_name (die
, cu
);
5385 /* Figure out where the statement is being imported to. */
5386 import_prefix
= determine_prefix (die
, cu
);
5388 /* Figure out what the scope of the imported die is and prepend it
5389 to the name of the imported die. */
5390 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5392 if (imported_die
->tag
!= DW_TAG_namespace
5393 && imported_die
->tag
!= DW_TAG_module
)
5395 imported_declaration
= imported_name
;
5396 canonical_name
= imported_name_prefix
;
5398 else if (strlen (imported_name_prefix
) > 0)
5400 temp
= alloca (strlen (imported_name_prefix
)
5401 + 2 + strlen (imported_name
) + 1);
5402 strcpy (temp
, imported_name_prefix
);
5403 strcat (temp
, "::");
5404 strcat (temp
, imported_name
);
5405 canonical_name
= temp
;
5408 canonical_name
= imported_name
;
5410 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5412 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5413 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5414 child_die
= sibling_die (child_die
))
5416 /* DWARF-4: A Fortran use statement with a “rename list” may be
5417 represented by an imported module entry with an import attribute
5418 referring to the module and owned entries corresponding to those
5419 entities that are renamed as part of being imported. */
5421 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5423 complaint (&symfile_complaints
,
5424 _("child DW_TAG_imported_declaration expected "
5425 "- DIE at 0x%x [in module %s]"),
5426 child_die
->offset
, cu
->objfile
->name
);
5430 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5431 if (import_attr
== NULL
)
5433 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5434 dwarf_tag_name (child_die
->tag
));
5439 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5441 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5442 if (imported_name
== NULL
)
5444 complaint (&symfile_complaints
,
5445 _("child DW_TAG_imported_declaration has unknown "
5446 "imported name - DIE at 0x%x [in module %s]"),
5447 child_die
->offset
, cu
->objfile
->name
);
5451 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5453 process_die (child_die
, cu
);
5456 cp_add_using_directive (import_prefix
,
5459 imported_declaration
,
5461 &cu
->objfile
->objfile_obstack
);
5463 do_cleanups (cleanups
);
5467 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5469 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5472 /* Cleanup function for read_file_scope. */
5475 free_cu_line_header (void *arg
)
5477 struct dwarf2_cu
*cu
= arg
;
5479 free_line_header (cu
->line_header
);
5480 cu
->line_header
= NULL
;
5484 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5485 char **name
, char **comp_dir
)
5487 struct attribute
*attr
;
5492 /* Find the filename. Do not use dwarf2_name here, since the filename
5493 is not a source language identifier. */
5494 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5497 *name
= DW_STRING (attr
);
5500 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5502 *comp_dir
= DW_STRING (attr
);
5503 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5505 *comp_dir
= ldirname (*name
);
5506 if (*comp_dir
!= NULL
)
5507 make_cleanup (xfree
, *comp_dir
);
5509 if (*comp_dir
!= NULL
)
5511 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5512 directory, get rid of it. */
5513 char *cp
= strchr (*comp_dir
, ':');
5515 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5520 *name
= "<unknown>";
5523 /* Handle DW_AT_stmt_list for a compilation unit. */
5526 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
5527 const char *comp_dir
)
5529 struct attribute
*attr
;
5530 struct objfile
*objfile
= cu
->objfile
;
5531 bfd
*abfd
= objfile
->obfd
;
5533 /* Decode line number information if present. We do this before
5534 processing child DIEs, so that the line header table is available
5535 for DW_AT_decl_file. */
5536 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5539 unsigned int line_offset
= DW_UNSND (attr
);
5540 struct line_header
*line_header
5541 = dwarf_decode_line_header (line_offset
, abfd
, cu
);
5545 cu
->line_header
= line_header
;
5546 make_cleanup (free_cu_line_header
, cu
);
5547 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5552 /* Process DW_TAG_compile_unit. */
5555 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5557 struct objfile
*objfile
= cu
->objfile
;
5558 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5559 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5560 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5561 struct attribute
*attr
;
5563 char *comp_dir
= NULL
;
5564 struct die_info
*child_die
;
5565 bfd
*abfd
= objfile
->obfd
;
5568 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5570 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5572 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5573 from finish_block. */
5574 if (lowpc
== ((CORE_ADDR
) -1))
5579 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5581 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5584 set_cu_language (DW_UNSND (attr
), cu
);
5587 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5589 cu
->producer
= DW_STRING (attr
);
5591 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5592 standardised yet. As a workaround for the language detection we fall
5593 back to the DW_AT_producer string. */
5594 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5595 cu
->language
= language_opencl
;
5597 /* We assume that we're processing GCC output. */
5598 processing_gcc_compilation
= 2;
5600 processing_has_namespace_info
= 0;
5602 start_symtab (name
, comp_dir
, lowpc
);
5603 record_debugformat ("DWARF 2");
5604 record_producer (cu
->producer
);
5606 initialize_cu_func_list (cu
);
5608 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5610 /* Process all dies in compilation unit. */
5611 if (die
->child
!= NULL
)
5613 child_die
= die
->child
;
5614 while (child_die
&& child_die
->tag
)
5616 process_die (child_die
, cu
);
5617 child_die
= sibling_die (child_die
);
5621 /* Decode macro information, if present. Dwarf 2 macro information
5622 refers to information in the line number info statement program
5623 header, so we can only read it if we've read the header
5625 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
5626 if (attr
&& cu
->line_header
)
5628 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
5629 complaint (&symfile_complaints
,
5630 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5632 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
5634 &dwarf2_per_objfile
->macro
, 1);
5638 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5639 if (attr
&& cu
->line_header
)
5641 unsigned int macro_offset
= DW_UNSND (attr
);
5643 dwarf_decode_macros (cu
->line_header
, macro_offset
,
5645 &dwarf2_per_objfile
->macinfo
, 0);
5648 do_cleanups (back_to
);
5651 /* Process DW_TAG_type_unit.
5652 For TUs we want to skip the first top level sibling if it's not the
5653 actual type being defined by this TU. In this case the first top
5654 level sibling is there to provide context only. */
5657 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5659 struct objfile
*objfile
= cu
->objfile
;
5660 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5662 struct attribute
*attr
;
5664 char *comp_dir
= NULL
;
5665 struct die_info
*child_die
;
5666 bfd
*abfd
= objfile
->obfd
;
5668 /* start_symtab needs a low pc, but we don't really have one.
5669 Do what read_file_scope would do in the absence of such info. */
5670 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5672 /* Find the filename. Do not use dwarf2_name here, since the filename
5673 is not a source language identifier. */
5674 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5676 name
= DW_STRING (attr
);
5678 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5680 comp_dir
= DW_STRING (attr
);
5681 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5683 comp_dir
= ldirname (name
);
5684 if (comp_dir
!= NULL
)
5685 make_cleanup (xfree
, comp_dir
);
5691 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5693 set_cu_language (DW_UNSND (attr
), cu
);
5695 /* This isn't technically needed today. It is done for symmetry
5696 with read_file_scope. */
5697 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5699 cu
->producer
= DW_STRING (attr
);
5701 /* We assume that we're processing GCC output. */
5702 processing_gcc_compilation
= 2;
5704 processing_has_namespace_info
= 0;
5706 start_symtab (name
, comp_dir
, lowpc
);
5707 record_debugformat ("DWARF 2");
5708 record_producer (cu
->producer
);
5710 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5712 /* Process the dies in the type unit. */
5713 if (die
->child
== NULL
)
5715 dump_die_for_error (die
);
5716 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5717 bfd_get_filename (abfd
));
5720 child_die
= die
->child
;
5722 while (child_die
&& child_die
->tag
)
5724 process_die (child_die
, cu
);
5726 child_die
= sibling_die (child_die
);
5729 do_cleanups (back_to
);
5733 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5734 struct dwarf2_cu
*cu
)
5736 struct function_range
*thisfn
;
5738 thisfn
= (struct function_range
*)
5739 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5740 thisfn
->name
= name
;
5741 thisfn
->lowpc
= lowpc
;
5742 thisfn
->highpc
= highpc
;
5743 thisfn
->seen_line
= 0;
5744 thisfn
->next
= NULL
;
5746 if (cu
->last_fn
== NULL
)
5747 cu
->first_fn
= thisfn
;
5749 cu
->last_fn
->next
= thisfn
;
5751 cu
->last_fn
= thisfn
;
5754 /* qsort helper for inherit_abstract_dies. */
5757 unsigned_int_compar (const void *ap
, const void *bp
)
5759 unsigned int a
= *(unsigned int *) ap
;
5760 unsigned int b
= *(unsigned int *) bp
;
5762 return (a
> b
) - (b
> a
);
5765 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5766 Inherit only the children of the DW_AT_abstract_origin DIE not being
5767 already referenced by DW_AT_abstract_origin from the children of the
5771 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5773 struct die_info
*child_die
;
5774 unsigned die_children_count
;
5775 /* CU offsets which were referenced by children of the current DIE. */
5777 unsigned *offsets_end
, *offsetp
;
5778 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5779 struct die_info
*origin_die
;
5780 /* Iterator of the ORIGIN_DIE children. */
5781 struct die_info
*origin_child_die
;
5782 struct cleanup
*cleanups
;
5783 struct attribute
*attr
;
5784 struct dwarf2_cu
*origin_cu
;
5785 struct pending
**origin_previous_list_in_scope
;
5787 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5791 /* Note that following die references may follow to a die in a
5795 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5797 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5799 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5800 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5802 if (die
->tag
!= origin_die
->tag
5803 && !(die
->tag
== DW_TAG_inlined_subroutine
5804 && origin_die
->tag
== DW_TAG_subprogram
))
5805 complaint (&symfile_complaints
,
5806 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5807 die
->offset
, origin_die
->offset
);
5809 child_die
= die
->child
;
5810 die_children_count
= 0;
5811 while (child_die
&& child_die
->tag
)
5813 child_die
= sibling_die (child_die
);
5814 die_children_count
++;
5816 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5817 cleanups
= make_cleanup (xfree
, offsets
);
5819 offsets_end
= offsets
;
5820 child_die
= die
->child
;
5821 while (child_die
&& child_die
->tag
)
5823 /* For each CHILD_DIE, find the corresponding child of
5824 ORIGIN_DIE. If there is more than one layer of
5825 DW_AT_abstract_origin, follow them all; there shouldn't be,
5826 but GCC versions at least through 4.4 generate this (GCC PR
5828 struct die_info
*child_origin_die
= child_die
;
5829 struct dwarf2_cu
*child_origin_cu
= cu
;
5833 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5837 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5841 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5842 counterpart may exist. */
5843 if (child_origin_die
!= child_die
)
5845 if (child_die
->tag
!= child_origin_die
->tag
5846 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5847 && child_origin_die
->tag
== DW_TAG_subprogram
))
5848 complaint (&symfile_complaints
,
5849 _("Child DIE 0x%x and its abstract origin 0x%x have "
5850 "different tags"), child_die
->offset
,
5851 child_origin_die
->offset
);
5852 if (child_origin_die
->parent
!= origin_die
)
5853 complaint (&symfile_complaints
,
5854 _("Child DIE 0x%x and its abstract origin 0x%x have "
5855 "different parents"), child_die
->offset
,
5856 child_origin_die
->offset
);
5858 *offsets_end
++ = child_origin_die
->offset
;
5860 child_die
= sibling_die (child_die
);
5862 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5863 unsigned_int_compar
);
5864 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5865 if (offsetp
[-1] == *offsetp
)
5866 complaint (&symfile_complaints
,
5867 _("Multiple children of DIE 0x%x refer "
5868 "to DIE 0x%x as their abstract origin"),
5869 die
->offset
, *offsetp
);
5872 origin_child_die
= origin_die
->child
;
5873 while (origin_child_die
&& origin_child_die
->tag
)
5875 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5876 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5878 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5880 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5881 process_die (origin_child_die
, origin_cu
);
5883 origin_child_die
= sibling_die (origin_child_die
);
5885 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5887 do_cleanups (cleanups
);
5891 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5893 struct objfile
*objfile
= cu
->objfile
;
5894 struct context_stack
*new;
5897 struct die_info
*child_die
;
5898 struct attribute
*attr
, *call_line
, *call_file
;
5901 struct block
*block
;
5902 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5903 VEC (symbolp
) *template_args
= NULL
;
5904 struct template_symbol
*templ_func
= NULL
;
5908 /* If we do not have call site information, we can't show the
5909 caller of this inlined function. That's too confusing, so
5910 only use the scope for local variables. */
5911 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5912 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5913 if (call_line
== NULL
|| call_file
== NULL
)
5915 read_lexical_block_scope (die
, cu
);
5920 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5922 name
= dwarf2_name (die
, cu
);
5924 /* Ignore functions with missing or empty names. These are actually
5925 illegal according to the DWARF standard. */
5928 complaint (&symfile_complaints
,
5929 _("missing name for subprogram DIE at %d"), die
->offset
);
5933 /* Ignore functions with missing or invalid low and high pc attributes. */
5934 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5936 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5937 if (!attr
|| !DW_UNSND (attr
))
5938 complaint (&symfile_complaints
,
5939 _("cannot get low and high bounds "
5940 "for subprogram DIE at %d"),
5948 /* Record the function range for dwarf_decode_lines. */
5949 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5951 /* If we have any template arguments, then we must allocate a
5952 different sort of symbol. */
5953 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5955 if (child_die
->tag
== DW_TAG_template_type_param
5956 || child_die
->tag
== DW_TAG_template_value_param
)
5958 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5959 struct template_symbol
);
5960 templ_func
->base
.is_cplus_template_function
= 1;
5965 new = push_context (0, lowpc
);
5966 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5967 (struct symbol
*) templ_func
);
5969 /* If there is a location expression for DW_AT_frame_base, record
5971 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5973 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5974 expression is being recorded directly in the function's symbol
5975 and not in a separate frame-base object. I guess this hack is
5976 to avoid adding some sort of frame-base adjunct/annex to the
5977 function's symbol :-(. The problem with doing this is that it
5978 results in a function symbol with a location expression that
5979 has nothing to do with the location of the function, ouch! The
5980 relationship should be: a function's symbol has-a frame base; a
5981 frame-base has-a location expression. */
5982 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5984 cu
->list_in_scope
= &local_symbols
;
5986 if (die
->child
!= NULL
)
5988 child_die
= die
->child
;
5989 while (child_die
&& child_die
->tag
)
5991 if (child_die
->tag
== DW_TAG_template_type_param
5992 || child_die
->tag
== DW_TAG_template_value_param
)
5994 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5997 VEC_safe_push (symbolp
, template_args
, arg
);
6000 process_die (child_die
, cu
);
6001 child_die
= sibling_die (child_die
);
6005 inherit_abstract_dies (die
, cu
);
6007 /* If we have a DW_AT_specification, we might need to import using
6008 directives from the context of the specification DIE. See the
6009 comment in determine_prefix. */
6010 if (cu
->language
== language_cplus
6011 && dwarf2_attr (die
, DW_AT_specification
, cu
))
6013 struct dwarf2_cu
*spec_cu
= cu
;
6014 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
6018 child_die
= spec_die
->child
;
6019 while (child_die
&& child_die
->tag
)
6021 if (child_die
->tag
== DW_TAG_imported_module
)
6022 process_die (child_die
, spec_cu
);
6023 child_die
= sibling_die (child_die
);
6026 /* In some cases, GCC generates specification DIEs that
6027 themselves contain DW_AT_specification attributes. */
6028 spec_die
= die_specification (spec_die
, &spec_cu
);
6032 new = pop_context ();
6033 /* Make a block for the local symbols within. */
6034 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
6035 lowpc
, highpc
, objfile
);
6037 /* For C++, set the block's scope. */
6038 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
6039 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
6040 determine_prefix (die
, cu
),
6041 processing_has_namespace_info
);
6043 /* If we have address ranges, record them. */
6044 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6046 /* Attach template arguments to function. */
6047 if (! VEC_empty (symbolp
, template_args
))
6049 gdb_assert (templ_func
!= NULL
);
6051 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
6052 templ_func
->template_arguments
6053 = obstack_alloc (&objfile
->objfile_obstack
,
6054 (templ_func
->n_template_arguments
6055 * sizeof (struct symbol
*)));
6056 memcpy (templ_func
->template_arguments
,
6057 VEC_address (symbolp
, template_args
),
6058 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
6059 VEC_free (symbolp
, template_args
);
6062 /* In C++, we can have functions nested inside functions (e.g., when
6063 a function declares a class that has methods). This means that
6064 when we finish processing a function scope, we may need to go
6065 back to building a containing block's symbol lists. */
6066 local_symbols
= new->locals
;
6067 param_symbols
= new->params
;
6068 using_directives
= new->using_directives
;
6070 /* If we've finished processing a top-level function, subsequent
6071 symbols go in the file symbol list. */
6072 if (outermost_context_p ())
6073 cu
->list_in_scope
= &file_symbols
;
6076 /* Process all the DIES contained within a lexical block scope. Start
6077 a new scope, process the dies, and then close the scope. */
6080 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6082 struct objfile
*objfile
= cu
->objfile
;
6083 struct context_stack
*new;
6084 CORE_ADDR lowpc
, highpc
;
6085 struct die_info
*child_die
;
6088 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6090 /* Ignore blocks with missing or invalid low and high pc attributes. */
6091 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6092 as multiple lexical blocks? Handling children in a sane way would
6093 be nasty. Might be easier to properly extend generic blocks to
6095 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6100 push_context (0, lowpc
);
6101 if (die
->child
!= NULL
)
6103 child_die
= die
->child
;
6104 while (child_die
&& child_die
->tag
)
6106 process_die (child_die
, cu
);
6107 child_die
= sibling_die (child_die
);
6110 new = pop_context ();
6112 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6115 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6118 /* Note that recording ranges after traversing children, as we
6119 do here, means that recording a parent's ranges entails
6120 walking across all its children's ranges as they appear in
6121 the address map, which is quadratic behavior.
6123 It would be nicer to record the parent's ranges before
6124 traversing its children, simply overriding whatever you find
6125 there. But since we don't even decide whether to create a
6126 block until after we've traversed its children, that's hard
6128 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6130 local_symbols
= new->locals
;
6131 using_directives
= new->using_directives
;
6134 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6135 Return 1 if the attributes are present and valid, otherwise, return 0.
6136 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6139 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6140 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6141 struct partial_symtab
*ranges_pst
)
6143 struct objfile
*objfile
= cu
->objfile
;
6144 struct comp_unit_head
*cu_header
= &cu
->header
;
6145 bfd
*obfd
= objfile
->obfd
;
6146 unsigned int addr_size
= cu_header
->addr_size
;
6147 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6148 /* Base address selection entry. */
6159 found_base
= cu
->base_known
;
6160 base
= cu
->base_address
;
6162 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6163 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6165 complaint (&symfile_complaints
,
6166 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6170 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6172 /* Read in the largest possible address. */
6173 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6174 if ((marker
& mask
) == mask
)
6176 /* If we found the largest possible address, then
6177 read the base address. */
6178 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6179 buffer
+= 2 * addr_size
;
6180 offset
+= 2 * addr_size
;
6186 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6190 CORE_ADDR range_beginning
, range_end
;
6192 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6193 buffer
+= addr_size
;
6194 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6195 buffer
+= addr_size
;
6196 offset
+= 2 * addr_size
;
6198 /* An end of list marker is a pair of zero addresses. */
6199 if (range_beginning
== 0 && range_end
== 0)
6200 /* Found the end of list entry. */
6203 /* Each base address selection entry is a pair of 2 values.
6204 The first is the largest possible address, the second is
6205 the base address. Check for a base address here. */
6206 if ((range_beginning
& mask
) == mask
)
6208 /* If we found the largest possible address, then
6209 read the base address. */
6210 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6217 /* We have no valid base address for the ranges
6219 complaint (&symfile_complaints
,
6220 _("Invalid .debug_ranges data (no base address)"));
6224 if (range_beginning
> range_end
)
6226 /* Inverted range entries are invalid. */
6227 complaint (&symfile_complaints
,
6228 _("Invalid .debug_ranges data (inverted range)"));
6232 /* Empty range entries have no effect. */
6233 if (range_beginning
== range_end
)
6236 range_beginning
+= base
;
6239 if (ranges_pst
!= NULL
)
6240 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6241 range_beginning
+ baseaddr
,
6242 range_end
- 1 + baseaddr
,
6245 /* FIXME: This is recording everything as a low-high
6246 segment of consecutive addresses. We should have a
6247 data structure for discontiguous block ranges
6251 low
= range_beginning
;
6257 if (range_beginning
< low
)
6258 low
= range_beginning
;
6259 if (range_end
> high
)
6265 /* If the first entry is an end-of-list marker, the range
6266 describes an empty scope, i.e. no instructions. */
6272 *high_return
= high
;
6276 /* Get low and high pc attributes from a die. Return 1 if the attributes
6277 are present and valid, otherwise, return 0. Return -1 if the range is
6278 discontinuous, i.e. derived from DW_AT_ranges information. */
6280 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6281 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6282 struct partial_symtab
*pst
)
6284 struct attribute
*attr
;
6289 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6292 high
= DW_ADDR (attr
);
6293 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6295 low
= DW_ADDR (attr
);
6297 /* Found high w/o low attribute. */
6300 /* Found consecutive range of addresses. */
6305 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6308 /* Value of the DW_AT_ranges attribute is the offset in the
6309 .debug_ranges section. */
6310 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6312 /* Found discontinuous range of addresses. */
6317 /* read_partial_die has also the strict LOW < HIGH requirement. */
6321 /* When using the GNU linker, .gnu.linkonce. sections are used to
6322 eliminate duplicate copies of functions and vtables and such.
6323 The linker will arbitrarily choose one and discard the others.
6324 The AT_*_pc values for such functions refer to local labels in
6325 these sections. If the section from that file was discarded, the
6326 labels are not in the output, so the relocs get a value of 0.
6327 If this is a discarded function, mark the pc bounds as invalid,
6328 so that GDB will ignore it. */
6329 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6337 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6338 its low and high PC addresses. Do nothing if these addresses could not
6339 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6340 and HIGHPC to the high address if greater than HIGHPC. */
6343 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6344 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6345 struct dwarf2_cu
*cu
)
6347 CORE_ADDR low
, high
;
6348 struct die_info
*child
= die
->child
;
6350 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6352 *lowpc
= min (*lowpc
, low
);
6353 *highpc
= max (*highpc
, high
);
6356 /* If the language does not allow nested subprograms (either inside
6357 subprograms or lexical blocks), we're done. */
6358 if (cu
->language
!= language_ada
)
6361 /* Check all the children of the given DIE. If it contains nested
6362 subprograms, then check their pc bounds. Likewise, we need to
6363 check lexical blocks as well, as they may also contain subprogram
6365 while (child
&& child
->tag
)
6367 if (child
->tag
== DW_TAG_subprogram
6368 || child
->tag
== DW_TAG_lexical_block
)
6369 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6370 child
= sibling_die (child
);
6374 /* Get the low and high pc's represented by the scope DIE, and store
6375 them in *LOWPC and *HIGHPC. If the correct values can't be
6376 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6379 get_scope_pc_bounds (struct die_info
*die
,
6380 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6381 struct dwarf2_cu
*cu
)
6383 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6384 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6385 CORE_ADDR current_low
, current_high
;
6387 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6389 best_low
= current_low
;
6390 best_high
= current_high
;
6394 struct die_info
*child
= die
->child
;
6396 while (child
&& child
->tag
)
6398 switch (child
->tag
) {
6399 case DW_TAG_subprogram
:
6400 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6402 case DW_TAG_namespace
:
6404 /* FIXME: carlton/2004-01-16: Should we do this for
6405 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6406 that current GCC's always emit the DIEs corresponding
6407 to definitions of methods of classes as children of a
6408 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6409 the DIEs giving the declarations, which could be
6410 anywhere). But I don't see any reason why the
6411 standards says that they have to be there. */
6412 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6414 if (current_low
!= ((CORE_ADDR
) -1))
6416 best_low
= min (best_low
, current_low
);
6417 best_high
= max (best_high
, current_high
);
6425 child
= sibling_die (child
);
6430 *highpc
= best_high
;
6433 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6436 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6437 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6439 struct attribute
*attr
;
6441 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6444 CORE_ADDR high
= DW_ADDR (attr
);
6446 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6449 CORE_ADDR low
= DW_ADDR (attr
);
6451 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6455 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6458 bfd
*obfd
= cu
->objfile
->obfd
;
6460 /* The value of the DW_AT_ranges attribute is the offset of the
6461 address range list in the .debug_ranges section. */
6462 unsigned long offset
= DW_UNSND (attr
);
6463 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6465 /* For some target architectures, but not others, the
6466 read_address function sign-extends the addresses it returns.
6467 To recognize base address selection entries, we need a
6469 unsigned int addr_size
= cu
->header
.addr_size
;
6470 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6472 /* The base address, to which the next pair is relative. Note
6473 that this 'base' is a DWARF concept: most entries in a range
6474 list are relative, to reduce the number of relocs against the
6475 debugging information. This is separate from this function's
6476 'baseaddr' argument, which GDB uses to relocate debugging
6477 information from a shared library based on the address at
6478 which the library was loaded. */
6479 CORE_ADDR base
= cu
->base_address
;
6480 int base_known
= cu
->base_known
;
6482 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6483 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6485 complaint (&symfile_complaints
,
6486 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6493 unsigned int bytes_read
;
6494 CORE_ADDR start
, end
;
6496 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6497 buffer
+= bytes_read
;
6498 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6499 buffer
+= bytes_read
;
6501 /* Did we find the end of the range list? */
6502 if (start
== 0 && end
== 0)
6505 /* Did we find a base address selection entry? */
6506 else if ((start
& base_select_mask
) == base_select_mask
)
6512 /* We found an ordinary address range. */
6517 complaint (&symfile_complaints
,
6518 _("Invalid .debug_ranges data "
6519 "(no base address)"));
6525 /* Inverted range entries are invalid. */
6526 complaint (&symfile_complaints
,
6527 _("Invalid .debug_ranges data "
6528 "(inverted range)"));
6532 /* Empty range entries have no effect. */
6536 record_block_range (block
,
6537 baseaddr
+ base
+ start
,
6538 baseaddr
+ base
+ end
- 1);
6544 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6545 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6546 during 4.6.0 experimental. */
6549 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6552 int major
, minor
, release
;
6554 if (cu
->producer
== NULL
)
6556 /* For unknown compilers expect their behavior is DWARF version
6559 GCC started to support .debug_types sections by -gdwarf-4 since
6560 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6561 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6562 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6563 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6568 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6570 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6572 /* For non-GCC compilers expect their behavior is DWARF version
6577 cs
= &cu
->producer
[strlen ("GNU ")];
6578 while (*cs
&& !isdigit (*cs
))
6580 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6582 /* Not recognized as GCC. */
6587 return major
< 4 || (major
== 4 && minor
< 6);
6590 /* Return the default accessibility type if it is not overriden by
6591 DW_AT_accessibility. */
6593 static enum dwarf_access_attribute
6594 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6596 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6598 /* The default DWARF 2 accessibility for members is public, the default
6599 accessibility for inheritance is private. */
6601 if (die
->tag
!= DW_TAG_inheritance
)
6602 return DW_ACCESS_public
;
6604 return DW_ACCESS_private
;
6608 /* DWARF 3+ defines the default accessibility a different way. The same
6609 rules apply now for DW_TAG_inheritance as for the members and it only
6610 depends on the container kind. */
6612 if (die
->parent
->tag
== DW_TAG_class_type
)
6613 return DW_ACCESS_private
;
6615 return DW_ACCESS_public
;
6619 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6620 offset. If the attribute was not found return 0, otherwise return
6621 1. If it was found but could not properly be handled, set *OFFSET
6625 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
6628 struct attribute
*attr
;
6630 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6635 /* Note that we do not check for a section offset first here.
6636 This is because DW_AT_data_member_location is new in DWARF 4,
6637 so if we see it, we can assume that a constant form is really
6638 a constant and not a section offset. */
6639 if (attr_form_is_constant (attr
))
6640 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
6641 else if (attr_form_is_section_offset (attr
))
6642 dwarf2_complex_location_expr_complaint ();
6643 else if (attr_form_is_block (attr
))
6644 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6646 dwarf2_complex_location_expr_complaint ();
6654 /* Add an aggregate field to the field list. */
6657 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6658 struct dwarf2_cu
*cu
)
6660 struct objfile
*objfile
= cu
->objfile
;
6661 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6662 struct nextfield
*new_field
;
6663 struct attribute
*attr
;
6665 char *fieldname
= "";
6667 /* Allocate a new field list entry and link it in. */
6668 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6669 make_cleanup (xfree
, new_field
);
6670 memset (new_field
, 0, sizeof (struct nextfield
));
6672 if (die
->tag
== DW_TAG_inheritance
)
6674 new_field
->next
= fip
->baseclasses
;
6675 fip
->baseclasses
= new_field
;
6679 new_field
->next
= fip
->fields
;
6680 fip
->fields
= new_field
;
6684 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6686 new_field
->accessibility
= DW_UNSND (attr
);
6688 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
6689 if (new_field
->accessibility
!= DW_ACCESS_public
)
6690 fip
->non_public_fields
= 1;
6692 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6694 new_field
->virtuality
= DW_UNSND (attr
);
6696 new_field
->virtuality
= DW_VIRTUALITY_none
;
6698 fp
= &new_field
->field
;
6700 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6704 /* Data member other than a C++ static data member. */
6706 /* Get type of field. */
6707 fp
->type
= die_type (die
, cu
);
6709 SET_FIELD_BITPOS (*fp
, 0);
6711 /* Get bit size of field (zero if none). */
6712 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6715 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6719 FIELD_BITSIZE (*fp
) = 0;
6722 /* Get bit offset of field. */
6723 if (handle_data_member_location (die
, cu
, &offset
))
6724 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
6725 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6728 if (gdbarch_bits_big_endian (gdbarch
))
6730 /* For big endian bits, the DW_AT_bit_offset gives the
6731 additional bit offset from the MSB of the containing
6732 anonymous object to the MSB of the field. We don't
6733 have to do anything special since we don't need to
6734 know the size of the anonymous object. */
6735 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6739 /* For little endian bits, compute the bit offset to the
6740 MSB of the anonymous object, subtract off the number of
6741 bits from the MSB of the field to the MSB of the
6742 object, and then subtract off the number of bits of
6743 the field itself. The result is the bit offset of
6744 the LSB of the field. */
6746 int bit_offset
= DW_UNSND (attr
);
6748 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6751 /* The size of the anonymous object containing
6752 the bit field is explicit, so use the
6753 indicated size (in bytes). */
6754 anonymous_size
= DW_UNSND (attr
);
6758 /* The size of the anonymous object containing
6759 the bit field must be inferred from the type
6760 attribute of the data member containing the
6762 anonymous_size
= TYPE_LENGTH (fp
->type
);
6764 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6765 - bit_offset
- FIELD_BITSIZE (*fp
);
6769 /* Get name of field. */
6770 fieldname
= dwarf2_name (die
, cu
);
6771 if (fieldname
== NULL
)
6774 /* The name is already allocated along with this objfile, so we don't
6775 need to duplicate it for the type. */
6776 fp
->name
= fieldname
;
6778 /* Change accessibility for artificial fields (e.g. virtual table
6779 pointer or virtual base class pointer) to private. */
6780 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6782 FIELD_ARTIFICIAL (*fp
) = 1;
6783 new_field
->accessibility
= DW_ACCESS_private
;
6784 fip
->non_public_fields
= 1;
6787 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6789 /* C++ static member. */
6791 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6792 is a declaration, but all versions of G++ as of this writing
6793 (so through at least 3.2.1) incorrectly generate
6794 DW_TAG_variable tags. */
6796 const char *physname
;
6798 /* Get name of field. */
6799 fieldname
= dwarf2_name (die
, cu
);
6800 if (fieldname
== NULL
)
6803 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6805 /* Only create a symbol if this is an external value.
6806 new_symbol checks this and puts the value in the global symbol
6807 table, which we want. If it is not external, new_symbol
6808 will try to put the value in cu->list_in_scope which is wrong. */
6809 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6811 /* A static const member, not much different than an enum as far as
6812 we're concerned, except that we can support more types. */
6813 new_symbol (die
, NULL
, cu
);
6816 /* Get physical name. */
6817 physname
= dwarf2_physname (fieldname
, die
, cu
);
6819 /* The name is already allocated along with this objfile, so we don't
6820 need to duplicate it for the type. */
6821 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6822 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6823 FIELD_NAME (*fp
) = fieldname
;
6825 else if (die
->tag
== DW_TAG_inheritance
)
6829 /* C++ base class field. */
6830 if (handle_data_member_location (die
, cu
, &offset
))
6831 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
6832 FIELD_BITSIZE (*fp
) = 0;
6833 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6834 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6835 fip
->nbaseclasses
++;
6839 /* Add a typedef defined in the scope of the FIP's class. */
6842 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6843 struct dwarf2_cu
*cu
)
6845 struct objfile
*objfile
= cu
->objfile
;
6846 struct typedef_field_list
*new_field
;
6847 struct attribute
*attr
;
6848 struct typedef_field
*fp
;
6849 char *fieldname
= "";
6851 /* Allocate a new field list entry and link it in. */
6852 new_field
= xzalloc (sizeof (*new_field
));
6853 make_cleanup (xfree
, new_field
);
6855 gdb_assert (die
->tag
== DW_TAG_typedef
);
6857 fp
= &new_field
->field
;
6859 /* Get name of field. */
6860 fp
->name
= dwarf2_name (die
, cu
);
6861 if (fp
->name
== NULL
)
6864 fp
->type
= read_type_die (die
, cu
);
6866 new_field
->next
= fip
->typedef_field_list
;
6867 fip
->typedef_field_list
= new_field
;
6868 fip
->typedef_field_list_count
++;
6871 /* Create the vector of fields, and attach it to the type. */
6874 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6875 struct dwarf2_cu
*cu
)
6877 int nfields
= fip
->nfields
;
6879 /* Record the field count, allocate space for the array of fields,
6880 and create blank accessibility bitfields if necessary. */
6881 TYPE_NFIELDS (type
) = nfields
;
6882 TYPE_FIELDS (type
) = (struct field
*)
6883 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6884 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6886 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6888 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6890 TYPE_FIELD_PRIVATE_BITS (type
) =
6891 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6892 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6894 TYPE_FIELD_PROTECTED_BITS (type
) =
6895 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6896 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6898 TYPE_FIELD_IGNORE_BITS (type
) =
6899 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6900 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6903 /* If the type has baseclasses, allocate and clear a bit vector for
6904 TYPE_FIELD_VIRTUAL_BITS. */
6905 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6907 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6908 unsigned char *pointer
;
6910 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6911 pointer
= TYPE_ALLOC (type
, num_bytes
);
6912 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6913 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6914 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6917 /* Copy the saved-up fields into the field vector. Start from the head of
6918 the list, adding to the tail of the field array, so that they end up in
6919 the same order in the array in which they were added to the list. */
6920 while (nfields
-- > 0)
6922 struct nextfield
*fieldp
;
6926 fieldp
= fip
->fields
;
6927 fip
->fields
= fieldp
->next
;
6931 fieldp
= fip
->baseclasses
;
6932 fip
->baseclasses
= fieldp
->next
;
6935 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6936 switch (fieldp
->accessibility
)
6938 case DW_ACCESS_private
:
6939 if (cu
->language
!= language_ada
)
6940 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6943 case DW_ACCESS_protected
:
6944 if (cu
->language
!= language_ada
)
6945 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6948 case DW_ACCESS_public
:
6952 /* Unknown accessibility. Complain and treat it as public. */
6954 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6955 fieldp
->accessibility
);
6959 if (nfields
< fip
->nbaseclasses
)
6961 switch (fieldp
->virtuality
)
6963 case DW_VIRTUALITY_virtual
:
6964 case DW_VIRTUALITY_pure_virtual
:
6965 if (cu
->language
== language_ada
)
6966 error (_("unexpected virtuality in component of Ada type"));
6967 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6974 /* Add a member function to the proper fieldlist. */
6977 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6978 struct type
*type
, struct dwarf2_cu
*cu
)
6980 struct objfile
*objfile
= cu
->objfile
;
6981 struct attribute
*attr
;
6982 struct fnfieldlist
*flp
;
6984 struct fn_field
*fnp
;
6986 struct nextfnfield
*new_fnfield
;
6987 struct type
*this_type
;
6988 enum dwarf_access_attribute accessibility
;
6990 if (cu
->language
== language_ada
)
6991 error (_("unexpected member function in Ada type"));
6993 /* Get name of member function. */
6994 fieldname
= dwarf2_name (die
, cu
);
6995 if (fieldname
== NULL
)
6998 /* Look up member function name in fieldlist. */
6999 for (i
= 0; i
< fip
->nfnfields
; i
++)
7001 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7005 /* Create new list element if necessary. */
7006 if (i
< fip
->nfnfields
)
7007 flp
= &fip
->fnfieldlists
[i
];
7010 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7012 fip
->fnfieldlists
= (struct fnfieldlist
*)
7013 xrealloc (fip
->fnfieldlists
,
7014 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7015 * sizeof (struct fnfieldlist
));
7016 if (fip
->nfnfields
== 0)
7017 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7019 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7020 flp
->name
= fieldname
;
7023 i
= fip
->nfnfields
++;
7026 /* Create a new member function field and chain it to the field list
7028 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7029 make_cleanup (xfree
, new_fnfield
);
7030 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7031 new_fnfield
->next
= flp
->head
;
7032 flp
->head
= new_fnfield
;
7035 /* Fill in the member function field info. */
7036 fnp
= &new_fnfield
->fnfield
;
7038 /* Delay processing of the physname until later. */
7039 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7041 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7046 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7047 fnp
->physname
= physname
? physname
: "";
7050 fnp
->type
= alloc_type (objfile
);
7051 this_type
= read_type_die (die
, cu
);
7052 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7054 int nparams
= TYPE_NFIELDS (this_type
);
7056 /* TYPE is the domain of this method, and THIS_TYPE is the type
7057 of the method itself (TYPE_CODE_METHOD). */
7058 smash_to_method_type (fnp
->type
, type
,
7059 TYPE_TARGET_TYPE (this_type
),
7060 TYPE_FIELDS (this_type
),
7061 TYPE_NFIELDS (this_type
),
7062 TYPE_VARARGS (this_type
));
7064 /* Handle static member functions.
7065 Dwarf2 has no clean way to discern C++ static and non-static
7066 member functions. G++ helps GDB by marking the first
7067 parameter for non-static member functions (which is the this
7068 pointer) as artificial. We obtain this information from
7069 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7070 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7071 fnp
->voffset
= VOFFSET_STATIC
;
7074 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7075 dwarf2_full_name (fieldname
, die
, cu
));
7077 /* Get fcontext from DW_AT_containing_type if present. */
7078 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7079 fnp
->fcontext
= die_containing_type (die
, cu
);
7081 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7082 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7084 /* Get accessibility. */
7085 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7087 accessibility
= DW_UNSND (attr
);
7089 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7090 switch (accessibility
)
7092 case DW_ACCESS_private
:
7093 fnp
->is_private
= 1;
7095 case DW_ACCESS_protected
:
7096 fnp
->is_protected
= 1;
7100 /* Check for artificial methods. */
7101 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7102 if (attr
&& DW_UNSND (attr
) != 0)
7103 fnp
->is_artificial
= 1;
7105 /* Get index in virtual function table if it is a virtual member
7106 function. For older versions of GCC, this is an offset in the
7107 appropriate virtual table, as specified by DW_AT_containing_type.
7108 For everyone else, it is an expression to be evaluated relative
7109 to the object address. */
7111 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7114 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7116 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7118 /* Old-style GCC. */
7119 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7121 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7122 || (DW_BLOCK (attr
)->size
> 1
7123 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7124 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7126 struct dwarf_block blk
;
7129 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7131 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7132 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7133 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7134 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7135 dwarf2_complex_location_expr_complaint ();
7137 fnp
->voffset
/= cu
->header
.addr_size
;
7141 dwarf2_complex_location_expr_complaint ();
7144 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7146 else if (attr_form_is_section_offset (attr
))
7148 dwarf2_complex_location_expr_complaint ();
7152 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7158 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7159 if (attr
&& DW_UNSND (attr
))
7161 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7162 complaint (&symfile_complaints
,
7163 _("Member function \"%s\" (offset %d) is virtual "
7164 "but the vtable offset is not specified"),
7165 fieldname
, die
->offset
);
7166 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7167 TYPE_CPLUS_DYNAMIC (type
) = 1;
7172 /* Create the vector of member function fields, and attach it to the type. */
7175 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7176 struct dwarf2_cu
*cu
)
7178 struct fnfieldlist
*flp
;
7179 int total_length
= 0;
7182 if (cu
->language
== language_ada
)
7183 error (_("unexpected member functions in Ada type"));
7185 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7186 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7187 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7189 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7191 struct nextfnfield
*nfp
= flp
->head
;
7192 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7195 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7196 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7197 fn_flp
->fn_fields
= (struct fn_field
*)
7198 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7199 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7200 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7202 total_length
+= flp
->length
;
7205 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7206 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
7209 /* Returns non-zero if NAME is the name of a vtable member in CU's
7210 language, zero otherwise. */
7212 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7214 static const char vptr
[] = "_vptr";
7215 static const char vtable
[] = "vtable";
7217 /* Look for the C++ and Java forms of the vtable. */
7218 if ((cu
->language
== language_java
7219 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7220 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7221 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7227 /* GCC outputs unnamed structures that are really pointers to member
7228 functions, with the ABI-specified layout. If TYPE describes
7229 such a structure, smash it into a member function type.
7231 GCC shouldn't do this; it should just output pointer to member DIEs.
7232 This is GCC PR debug/28767. */
7235 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7237 struct type
*pfn_type
, *domain_type
, *new_type
;
7239 /* Check for a structure with no name and two children. */
7240 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7243 /* Check for __pfn and __delta members. */
7244 if (TYPE_FIELD_NAME (type
, 0) == NULL
7245 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7246 || TYPE_FIELD_NAME (type
, 1) == NULL
7247 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7250 /* Find the type of the method. */
7251 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7252 if (pfn_type
== NULL
7253 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7254 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7257 /* Look for the "this" argument. */
7258 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7259 if (TYPE_NFIELDS (pfn_type
) == 0
7260 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7261 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7264 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7265 new_type
= alloc_type (objfile
);
7266 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7267 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7268 TYPE_VARARGS (pfn_type
));
7269 smash_to_methodptr_type (type
, new_type
);
7272 /* Called when we find the DIE that starts a structure or union scope
7273 (definition) to create a type for the structure or union. Fill in
7274 the type's name and general properties; the members will not be
7275 processed until process_structure_type.
7277 NOTE: we need to call these functions regardless of whether or not the
7278 DIE has a DW_AT_name attribute, since it might be an anonymous
7279 structure or union. This gets the type entered into our set of
7282 However, if the structure is incomplete (an opaque struct/union)
7283 then suppress creating a symbol table entry for it since gdb only
7284 wants to find the one with the complete definition. Note that if
7285 it is complete, we just call new_symbol, which does it's own
7286 checking about whether the struct/union is anonymous or not (and
7287 suppresses creating a symbol table entry itself). */
7289 static struct type
*
7290 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7292 struct objfile
*objfile
= cu
->objfile
;
7294 struct attribute
*attr
;
7297 /* If the definition of this type lives in .debug_types, read that type.
7298 Don't follow DW_AT_specification though, that will take us back up
7299 the chain and we want to go down. */
7300 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7303 struct dwarf2_cu
*type_cu
= cu
;
7304 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7306 /* We could just recurse on read_structure_type, but we need to call
7307 get_die_type to ensure only one type for this DIE is created.
7308 This is important, for example, because for c++ classes we need
7309 TYPE_NAME set which is only done by new_symbol. Blech. */
7310 type
= read_type_die (type_die
, type_cu
);
7312 /* TYPE_CU may not be the same as CU.
7313 Ensure TYPE is recorded in CU's type_hash table. */
7314 return set_die_type (die
, type
, cu
);
7317 type
= alloc_type (objfile
);
7318 INIT_CPLUS_SPECIFIC (type
);
7320 name
= dwarf2_name (die
, cu
);
7323 if (cu
->language
== language_cplus
7324 || cu
->language
== language_java
)
7326 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7328 /* dwarf2_full_name might have already finished building the DIE's
7329 type. If so, there is no need to continue. */
7330 if (get_die_type (die
, cu
) != NULL
)
7331 return get_die_type (die
, cu
);
7333 TYPE_TAG_NAME (type
) = full_name
;
7334 if (die
->tag
== DW_TAG_structure_type
7335 || die
->tag
== DW_TAG_class_type
)
7336 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7340 /* The name is already allocated along with this objfile, so
7341 we don't need to duplicate it for the type. */
7342 TYPE_TAG_NAME (type
) = (char *) name
;
7343 if (die
->tag
== DW_TAG_class_type
)
7344 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7348 if (die
->tag
== DW_TAG_structure_type
)
7350 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7352 else if (die
->tag
== DW_TAG_union_type
)
7354 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7358 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7361 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7362 TYPE_DECLARED_CLASS (type
) = 1;
7364 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7367 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7371 TYPE_LENGTH (type
) = 0;
7374 TYPE_STUB_SUPPORTED (type
) = 1;
7375 if (die_is_declaration (die
, cu
))
7376 TYPE_STUB (type
) = 1;
7377 else if (attr
== NULL
&& die
->child
== NULL
7378 && producer_is_realview (cu
->producer
))
7379 /* RealView does not output the required DW_AT_declaration
7380 on incomplete types. */
7381 TYPE_STUB (type
) = 1;
7383 /* We need to add the type field to the die immediately so we don't
7384 infinitely recurse when dealing with pointers to the structure
7385 type within the structure itself. */
7386 set_die_type (die
, type
, cu
);
7388 /* set_die_type should be already done. */
7389 set_descriptive_type (type
, die
, cu
);
7394 /* Finish creating a structure or union type, including filling in
7395 its members and creating a symbol for it. */
7398 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7400 struct objfile
*objfile
= cu
->objfile
;
7401 struct die_info
*child_die
= die
->child
;
7404 type
= get_die_type (die
, cu
);
7406 type
= read_structure_type (die
, cu
);
7408 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7410 struct field_info fi
;
7411 struct die_info
*child_die
;
7412 VEC (symbolp
) *template_args
= NULL
;
7413 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7415 memset (&fi
, 0, sizeof (struct field_info
));
7417 child_die
= die
->child
;
7419 while (child_die
&& child_die
->tag
)
7421 if (child_die
->tag
== DW_TAG_member
7422 || child_die
->tag
== DW_TAG_variable
)
7424 /* NOTE: carlton/2002-11-05: A C++ static data member
7425 should be a DW_TAG_member that is a declaration, but
7426 all versions of G++ as of this writing (so through at
7427 least 3.2.1) incorrectly generate DW_TAG_variable
7428 tags for them instead. */
7429 dwarf2_add_field (&fi
, child_die
, cu
);
7431 else if (child_die
->tag
== DW_TAG_subprogram
)
7433 /* C++ member function. */
7434 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7436 else if (child_die
->tag
== DW_TAG_inheritance
)
7438 /* C++ base class field. */
7439 dwarf2_add_field (&fi
, child_die
, cu
);
7441 else if (child_die
->tag
== DW_TAG_typedef
)
7442 dwarf2_add_typedef (&fi
, child_die
, cu
);
7443 else if (child_die
->tag
== DW_TAG_template_type_param
7444 || child_die
->tag
== DW_TAG_template_value_param
)
7446 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7449 VEC_safe_push (symbolp
, template_args
, arg
);
7452 child_die
= sibling_die (child_die
);
7455 /* Attach template arguments to type. */
7456 if (! VEC_empty (symbolp
, template_args
))
7458 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7459 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7460 = VEC_length (symbolp
, template_args
);
7461 TYPE_TEMPLATE_ARGUMENTS (type
)
7462 = obstack_alloc (&objfile
->objfile_obstack
,
7463 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7464 * sizeof (struct symbol
*)));
7465 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7466 VEC_address (symbolp
, template_args
),
7467 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7468 * sizeof (struct symbol
*)));
7469 VEC_free (symbolp
, template_args
);
7472 /* Attach fields and member functions to the type. */
7474 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7477 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7479 /* Get the type which refers to the base class (possibly this
7480 class itself) which contains the vtable pointer for the current
7481 class from the DW_AT_containing_type attribute. This use of
7482 DW_AT_containing_type is a GNU extension. */
7484 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7486 struct type
*t
= die_containing_type (die
, cu
);
7488 TYPE_VPTR_BASETYPE (type
) = t
;
7493 /* Our own class provides vtbl ptr. */
7494 for (i
= TYPE_NFIELDS (t
) - 1;
7495 i
>= TYPE_N_BASECLASSES (t
);
7498 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7500 if (is_vtable_name (fieldname
, cu
))
7502 TYPE_VPTR_FIELDNO (type
) = i
;
7507 /* Complain if virtual function table field not found. */
7508 if (i
< TYPE_N_BASECLASSES (t
))
7509 complaint (&symfile_complaints
,
7510 _("virtual function table pointer "
7511 "not found when defining class '%s'"),
7512 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7517 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7520 else if (cu
->producer
7521 && strncmp (cu
->producer
,
7522 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7524 /* The IBM XLC compiler does not provide direct indication
7525 of the containing type, but the vtable pointer is
7526 always named __vfp. */
7530 for (i
= TYPE_NFIELDS (type
) - 1;
7531 i
>= TYPE_N_BASECLASSES (type
);
7534 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7536 TYPE_VPTR_FIELDNO (type
) = i
;
7537 TYPE_VPTR_BASETYPE (type
) = type
;
7544 /* Copy fi.typedef_field_list linked list elements content into the
7545 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7546 if (fi
.typedef_field_list
)
7548 int i
= fi
.typedef_field_list_count
;
7550 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7551 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7552 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7553 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7555 /* Reverse the list order to keep the debug info elements order. */
7558 struct typedef_field
*dest
, *src
;
7560 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7561 src
= &fi
.typedef_field_list
->field
;
7562 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7567 do_cleanups (back_to
);
7569 if (HAVE_CPLUS_STRUCT (type
))
7570 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
7573 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
7575 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7576 snapshots) has been known to create a die giving a declaration
7577 for a class that has, as a child, a die giving a definition for a
7578 nested class. So we have to process our children even if the
7579 current die is a declaration. Normally, of course, a declaration
7580 won't have any children at all. */
7582 while (child_die
!= NULL
&& child_die
->tag
)
7584 if (child_die
->tag
== DW_TAG_member
7585 || child_die
->tag
== DW_TAG_variable
7586 || child_die
->tag
== DW_TAG_inheritance
7587 || child_die
->tag
== DW_TAG_template_value_param
7588 || child_die
->tag
== DW_TAG_template_type_param
)
7593 process_die (child_die
, cu
);
7595 child_die
= sibling_die (child_die
);
7598 /* Do not consider external references. According to the DWARF standard,
7599 these DIEs are identified by the fact that they have no byte_size
7600 attribute, and a declaration attribute. */
7601 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7602 || !die_is_declaration (die
, cu
))
7603 new_symbol (die
, type
, cu
);
7606 /* Given a DW_AT_enumeration_type die, set its type. We do not
7607 complete the type's fields yet, or create any symbols. */
7609 static struct type
*
7610 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7612 struct objfile
*objfile
= cu
->objfile
;
7614 struct attribute
*attr
;
7617 /* If the definition of this type lives in .debug_types, read that type.
7618 Don't follow DW_AT_specification though, that will take us back up
7619 the chain and we want to go down. */
7620 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7623 struct dwarf2_cu
*type_cu
= cu
;
7624 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7626 type
= read_type_die (type_die
, type_cu
);
7628 /* TYPE_CU may not be the same as CU.
7629 Ensure TYPE is recorded in CU's type_hash table. */
7630 return set_die_type (die
, type
, cu
);
7633 type
= alloc_type (objfile
);
7635 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7636 name
= dwarf2_full_name (NULL
, die
, cu
);
7638 TYPE_TAG_NAME (type
) = (char *) name
;
7640 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7643 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7647 TYPE_LENGTH (type
) = 0;
7650 /* The enumeration DIE can be incomplete. In Ada, any type can be
7651 declared as private in the package spec, and then defined only
7652 inside the package body. Such types are known as Taft Amendment
7653 Types. When another package uses such a type, an incomplete DIE
7654 may be generated by the compiler. */
7655 if (die_is_declaration (die
, cu
))
7656 TYPE_STUB (type
) = 1;
7658 return set_die_type (die
, type
, cu
);
7661 /* Given a pointer to a die which begins an enumeration, process all
7662 the dies that define the members of the enumeration, and create the
7663 symbol for the enumeration type.
7665 NOTE: We reverse the order of the element list. */
7668 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7670 struct type
*this_type
;
7672 this_type
= get_die_type (die
, cu
);
7673 if (this_type
== NULL
)
7674 this_type
= read_enumeration_type (die
, cu
);
7676 if (die
->child
!= NULL
)
7678 struct die_info
*child_die
;
7680 struct field
*fields
= NULL
;
7682 int unsigned_enum
= 1;
7685 child_die
= die
->child
;
7686 while (child_die
&& child_die
->tag
)
7688 if (child_die
->tag
!= DW_TAG_enumerator
)
7690 process_die (child_die
, cu
);
7694 name
= dwarf2_name (child_die
, cu
);
7697 sym
= new_symbol (child_die
, this_type
, cu
);
7698 if (SYMBOL_VALUE (sym
) < 0)
7701 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7703 fields
= (struct field
*)
7705 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7706 * sizeof (struct field
));
7709 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7710 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7711 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7712 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7718 child_die
= sibling_die (child_die
);
7723 TYPE_NFIELDS (this_type
) = num_fields
;
7724 TYPE_FIELDS (this_type
) = (struct field
*)
7725 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7726 memcpy (TYPE_FIELDS (this_type
), fields
,
7727 sizeof (struct field
) * num_fields
);
7731 TYPE_UNSIGNED (this_type
) = 1;
7734 /* If we are reading an enum from a .debug_types unit, and the enum
7735 is a declaration, and the enum is not the signatured type in the
7736 unit, then we do not want to add a symbol for it. Adding a
7737 symbol would in some cases obscure the true definition of the
7738 enum, giving users an incomplete type when the definition is
7739 actually available. Note that we do not want to do this for all
7740 enums which are just declarations, because C++0x allows forward
7741 enum declarations. */
7742 if (cu
->per_cu
->debug_type_section
7743 && die_is_declaration (die
, cu
))
7745 struct signatured_type
*type_sig
;
7748 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
7749 cu
->per_cu
->debug_type_section
,
7750 cu
->per_cu
->offset
);
7751 if (type_sig
->type_offset
!= die
->offset
)
7755 new_symbol (die
, this_type
, cu
);
7758 /* Extract all information from a DW_TAG_array_type DIE and put it in
7759 the DIE's type field. For now, this only handles one dimensional
7762 static struct type
*
7763 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7765 struct objfile
*objfile
= cu
->objfile
;
7766 struct die_info
*child_die
;
7768 struct type
*element_type
, *range_type
, *index_type
;
7769 struct type
**range_types
= NULL
;
7770 struct attribute
*attr
;
7772 struct cleanup
*back_to
;
7775 element_type
= die_type (die
, cu
);
7777 /* The die_type call above may have already set the type for this DIE. */
7778 type
= get_die_type (die
, cu
);
7782 /* Irix 6.2 native cc creates array types without children for
7783 arrays with unspecified length. */
7784 if (die
->child
== NULL
)
7786 index_type
= objfile_type (objfile
)->builtin_int
;
7787 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7788 type
= create_array_type (NULL
, element_type
, range_type
);
7789 return set_die_type (die
, type
, cu
);
7792 back_to
= make_cleanup (null_cleanup
, NULL
);
7793 child_die
= die
->child
;
7794 while (child_die
&& child_die
->tag
)
7796 if (child_die
->tag
== DW_TAG_subrange_type
)
7798 struct type
*child_type
= read_type_die (child_die
, cu
);
7800 if (child_type
!= NULL
)
7802 /* The range type was succesfully read. Save it for the
7803 array type creation. */
7804 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7806 range_types
= (struct type
**)
7807 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7808 * sizeof (struct type
*));
7810 make_cleanup (free_current_contents
, &range_types
);
7812 range_types
[ndim
++] = child_type
;
7815 child_die
= sibling_die (child_die
);
7818 /* Dwarf2 dimensions are output from left to right, create the
7819 necessary array types in backwards order. */
7821 type
= element_type
;
7823 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7828 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7833 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7836 /* Understand Dwarf2 support for vector types (like they occur on
7837 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7838 array type. This is not part of the Dwarf2/3 standard yet, but a
7839 custom vendor extension. The main difference between a regular
7840 array and the vector variant is that vectors are passed by value
7842 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7844 make_vector_type (type
);
7846 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7847 implementation may choose to implement triple vectors using this
7849 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7852 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
7853 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7855 complaint (&symfile_complaints
,
7856 _("DW_AT_byte_size for array type smaller "
7857 "than the total size of elements"));
7860 name
= dwarf2_name (die
, cu
);
7862 TYPE_NAME (type
) = name
;
7864 /* Install the type in the die. */
7865 set_die_type (die
, type
, cu
);
7867 /* set_die_type should be already done. */
7868 set_descriptive_type (type
, die
, cu
);
7870 do_cleanups (back_to
);
7875 static enum dwarf_array_dim_ordering
7876 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7878 struct attribute
*attr
;
7880 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7882 if (attr
) return DW_SND (attr
);
7884 /* GNU F77 is a special case, as at 08/2004 array type info is the
7885 opposite order to the dwarf2 specification, but data is still
7886 laid out as per normal fortran.
7888 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7889 version checking. */
7891 if (cu
->language
== language_fortran
7892 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7894 return DW_ORD_row_major
;
7897 switch (cu
->language_defn
->la_array_ordering
)
7899 case array_column_major
:
7900 return DW_ORD_col_major
;
7901 case array_row_major
:
7903 return DW_ORD_row_major
;
7907 /* Extract all information from a DW_TAG_set_type DIE and put it in
7908 the DIE's type field. */
7910 static struct type
*
7911 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7913 struct type
*domain_type
, *set_type
;
7914 struct attribute
*attr
;
7916 domain_type
= die_type (die
, cu
);
7918 /* The die_type call above may have already set the type for this DIE. */
7919 set_type
= get_die_type (die
, cu
);
7923 set_type
= create_set_type (NULL
, domain_type
);
7925 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7927 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7929 return set_die_type (die
, set_type
, cu
);
7932 /* First cut: install each common block member as a global variable. */
7935 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7937 struct die_info
*child_die
;
7938 struct attribute
*attr
;
7940 CORE_ADDR base
= (CORE_ADDR
) 0;
7942 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7945 /* Support the .debug_loc offsets. */
7946 if (attr_form_is_block (attr
))
7948 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7950 else if (attr_form_is_section_offset (attr
))
7952 dwarf2_complex_location_expr_complaint ();
7956 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7957 "common block member");
7960 if (die
->child
!= NULL
)
7962 child_die
= die
->child
;
7963 while (child_die
&& child_die
->tag
)
7967 sym
= new_symbol (child_die
, NULL
, cu
);
7969 && handle_data_member_location (child_die
, cu
, &offset
))
7971 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
7972 add_symbol_to_list (sym
, &global_symbols
);
7974 child_die
= sibling_die (child_die
);
7979 /* Create a type for a C++ namespace. */
7981 static struct type
*
7982 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7984 struct objfile
*objfile
= cu
->objfile
;
7985 const char *previous_prefix
, *name
;
7989 /* For extensions, reuse the type of the original namespace. */
7990 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7992 struct die_info
*ext_die
;
7993 struct dwarf2_cu
*ext_cu
= cu
;
7995 ext_die
= dwarf2_extension (die
, &ext_cu
);
7996 type
= read_type_die (ext_die
, ext_cu
);
7998 /* EXT_CU may not be the same as CU.
7999 Ensure TYPE is recorded in CU's type_hash table. */
8000 return set_die_type (die
, type
, cu
);
8003 name
= namespace_name (die
, &is_anonymous
, cu
);
8005 /* Now build the name of the current namespace. */
8007 previous_prefix
= determine_prefix (die
, cu
);
8008 if (previous_prefix
[0] != '\0')
8009 name
= typename_concat (&objfile
->objfile_obstack
,
8010 previous_prefix
, name
, 0, cu
);
8012 /* Create the type. */
8013 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8015 TYPE_NAME (type
) = (char *) name
;
8016 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8018 return set_die_type (die
, type
, cu
);
8021 /* Read a C++ namespace. */
8024 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8026 struct objfile
*objfile
= cu
->objfile
;
8029 /* Add a symbol associated to this if we haven't seen the namespace
8030 before. Also, add a using directive if it's an anonymous
8033 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8037 type
= read_type_die (die
, cu
);
8038 new_symbol (die
, type
, cu
);
8040 namespace_name (die
, &is_anonymous
, cu
);
8043 const char *previous_prefix
= determine_prefix (die
, cu
);
8045 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8046 NULL
, NULL
, &objfile
->objfile_obstack
);
8050 if (die
->child
!= NULL
)
8052 struct die_info
*child_die
= die
->child
;
8054 while (child_die
&& child_die
->tag
)
8056 process_die (child_die
, cu
);
8057 child_die
= sibling_die (child_die
);
8062 /* Read a Fortran module as type. This DIE can be only a declaration used for
8063 imported module. Still we need that type as local Fortran "use ... only"
8064 declaration imports depend on the created type in determine_prefix. */
8066 static struct type
*
8067 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8069 struct objfile
*objfile
= cu
->objfile
;
8073 module_name
= dwarf2_name (die
, cu
);
8075 complaint (&symfile_complaints
,
8076 _("DW_TAG_module has no name, offset 0x%x"),
8078 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8080 /* determine_prefix uses TYPE_TAG_NAME. */
8081 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8083 return set_die_type (die
, type
, cu
);
8086 /* Read a Fortran module. */
8089 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8091 struct die_info
*child_die
= die
->child
;
8093 while (child_die
&& child_die
->tag
)
8095 process_die (child_die
, cu
);
8096 child_die
= sibling_die (child_die
);
8100 /* Return the name of the namespace represented by DIE. Set
8101 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8105 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8107 struct die_info
*current_die
;
8108 const char *name
= NULL
;
8110 /* Loop through the extensions until we find a name. */
8112 for (current_die
= die
;
8113 current_die
!= NULL
;
8114 current_die
= dwarf2_extension (die
, &cu
))
8116 name
= dwarf2_name (current_die
, cu
);
8121 /* Is it an anonymous namespace? */
8123 *is_anonymous
= (name
== NULL
);
8125 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8130 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8131 the user defined type vector. */
8133 static struct type
*
8134 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8136 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8137 struct comp_unit_head
*cu_header
= &cu
->header
;
8139 struct attribute
*attr_byte_size
;
8140 struct attribute
*attr_address_class
;
8141 int byte_size
, addr_class
;
8142 struct type
*target_type
;
8144 target_type
= die_type (die
, cu
);
8146 /* The die_type call above may have already set the type for this DIE. */
8147 type
= get_die_type (die
, cu
);
8151 type
= lookup_pointer_type (target_type
);
8153 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8155 byte_size
= DW_UNSND (attr_byte_size
);
8157 byte_size
= cu_header
->addr_size
;
8159 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8160 if (attr_address_class
)
8161 addr_class
= DW_UNSND (attr_address_class
);
8163 addr_class
= DW_ADDR_none
;
8165 /* If the pointer size or address class is different than the
8166 default, create a type variant marked as such and set the
8167 length accordingly. */
8168 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8170 if (gdbarch_address_class_type_flags_p (gdbarch
))
8174 type_flags
= gdbarch_address_class_type_flags
8175 (gdbarch
, byte_size
, addr_class
);
8176 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8178 type
= make_type_with_address_space (type
, type_flags
);
8180 else if (TYPE_LENGTH (type
) != byte_size
)
8182 complaint (&symfile_complaints
,
8183 _("invalid pointer size %d"), byte_size
);
8187 /* Should we also complain about unhandled address classes? */
8191 TYPE_LENGTH (type
) = byte_size
;
8192 return set_die_type (die
, type
, cu
);
8195 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8196 the user defined type vector. */
8198 static struct type
*
8199 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8202 struct type
*to_type
;
8203 struct type
*domain
;
8205 to_type
= die_type (die
, cu
);
8206 domain
= die_containing_type (die
, cu
);
8208 /* The calls above may have already set the type for this DIE. */
8209 type
= get_die_type (die
, cu
);
8213 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8214 type
= lookup_methodptr_type (to_type
);
8216 type
= lookup_memberptr_type (to_type
, domain
);
8218 return set_die_type (die
, type
, cu
);
8221 /* Extract all information from a DW_TAG_reference_type DIE and add to
8222 the user defined type vector. */
8224 static struct type
*
8225 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8227 struct comp_unit_head
*cu_header
= &cu
->header
;
8228 struct type
*type
, *target_type
;
8229 struct attribute
*attr
;
8231 target_type
= die_type (die
, cu
);
8233 /* The die_type call above may have already set the type for this DIE. */
8234 type
= get_die_type (die
, cu
);
8238 type
= lookup_reference_type (target_type
);
8239 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8242 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8246 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8248 return set_die_type (die
, type
, cu
);
8251 static struct type
*
8252 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8254 struct type
*base_type
, *cv_type
;
8256 base_type
= die_type (die
, cu
);
8258 /* The die_type call above may have already set the type for this DIE. */
8259 cv_type
= get_die_type (die
, cu
);
8263 /* In case the const qualifier is applied to an array type, the element type
8264 is so qualified, not the array type (section 6.7.3 of C99). */
8265 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8267 struct type
*el_type
, *inner_array
;
8269 base_type
= copy_type (base_type
);
8270 inner_array
= base_type
;
8272 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8274 TYPE_TARGET_TYPE (inner_array
) =
8275 copy_type (TYPE_TARGET_TYPE (inner_array
));
8276 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8279 el_type
= TYPE_TARGET_TYPE (inner_array
);
8280 TYPE_TARGET_TYPE (inner_array
) =
8281 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8283 return set_die_type (die
, base_type
, cu
);
8286 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8287 return set_die_type (die
, cv_type
, cu
);
8290 static struct type
*
8291 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8293 struct type
*base_type
, *cv_type
;
8295 base_type
= die_type (die
, cu
);
8297 /* The die_type call above may have already set the type for this DIE. */
8298 cv_type
= get_die_type (die
, cu
);
8302 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8303 return set_die_type (die
, cv_type
, cu
);
8306 /* Extract all information from a DW_TAG_string_type DIE and add to
8307 the user defined type vector. It isn't really a user defined type,
8308 but it behaves like one, with other DIE's using an AT_user_def_type
8309 attribute to reference it. */
8311 static struct type
*
8312 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8314 struct objfile
*objfile
= cu
->objfile
;
8315 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8316 struct type
*type
, *range_type
, *index_type
, *char_type
;
8317 struct attribute
*attr
;
8318 unsigned int length
;
8320 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8323 length
= DW_UNSND (attr
);
8327 /* Check for the DW_AT_byte_size attribute. */
8328 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8331 length
= DW_UNSND (attr
);
8339 index_type
= objfile_type (objfile
)->builtin_int
;
8340 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8341 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8342 type
= create_string_type (NULL
, char_type
, range_type
);
8344 return set_die_type (die
, type
, cu
);
8347 /* Handle DIES due to C code like:
8351 int (*funcp)(int a, long l);
8355 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8357 static struct type
*
8358 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8360 struct type
*type
; /* Type that this function returns. */
8361 struct type
*ftype
; /* Function that returns above type. */
8362 struct attribute
*attr
;
8364 type
= die_type (die
, cu
);
8366 /* The die_type call above may have already set the type for this DIE. */
8367 ftype
= get_die_type (die
, cu
);
8371 ftype
= lookup_function_type (type
);
8373 /* All functions in C++, Pascal and Java have prototypes. */
8374 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8375 if ((attr
&& (DW_UNSND (attr
) != 0))
8376 || cu
->language
== language_cplus
8377 || cu
->language
== language_java
8378 || cu
->language
== language_pascal
)
8379 TYPE_PROTOTYPED (ftype
) = 1;
8380 else if (producer_is_realview (cu
->producer
))
8381 /* RealView does not emit DW_AT_prototyped. We can not
8382 distinguish prototyped and unprototyped functions; default to
8383 prototyped, since that is more common in modern code (and
8384 RealView warns about unprototyped functions). */
8385 TYPE_PROTOTYPED (ftype
) = 1;
8387 /* Store the calling convention in the type if it's available in
8388 the subroutine die. Otherwise set the calling convention to
8389 the default value DW_CC_normal. */
8390 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8392 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8393 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8394 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8396 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8398 /* We need to add the subroutine type to the die immediately so
8399 we don't infinitely recurse when dealing with parameters
8400 declared as the same subroutine type. */
8401 set_die_type (die
, ftype
, cu
);
8403 if (die
->child
!= NULL
)
8405 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
8406 struct die_info
*child_die
;
8407 int nparams
, iparams
;
8409 /* Count the number of parameters.
8410 FIXME: GDB currently ignores vararg functions, but knows about
8411 vararg member functions. */
8413 child_die
= die
->child
;
8414 while (child_die
&& child_die
->tag
)
8416 if (child_die
->tag
== DW_TAG_formal_parameter
)
8418 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8419 TYPE_VARARGS (ftype
) = 1;
8420 child_die
= sibling_die (child_die
);
8423 /* Allocate storage for parameters and fill them in. */
8424 TYPE_NFIELDS (ftype
) = nparams
;
8425 TYPE_FIELDS (ftype
) = (struct field
*)
8426 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8428 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8429 even if we error out during the parameters reading below. */
8430 for (iparams
= 0; iparams
< nparams
; iparams
++)
8431 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8434 child_die
= die
->child
;
8435 while (child_die
&& child_die
->tag
)
8437 if (child_die
->tag
== DW_TAG_formal_parameter
)
8439 struct type
*arg_type
;
8441 /* DWARF version 2 has no clean way to discern C++
8442 static and non-static member functions. G++ helps
8443 GDB by marking the first parameter for non-static
8444 member functions (which is the this pointer) as
8445 artificial. We pass this information to
8446 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8448 DWARF version 3 added DW_AT_object_pointer, which GCC
8449 4.5 does not yet generate. */
8450 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8452 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8455 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8457 /* GCC/43521: In java, the formal parameter
8458 "this" is sometimes not marked with DW_AT_artificial. */
8459 if (cu
->language
== language_java
)
8461 const char *name
= dwarf2_name (child_die
, cu
);
8463 if (name
&& !strcmp (name
, "this"))
8464 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8467 arg_type
= die_type (child_die
, cu
);
8469 /* RealView does not mark THIS as const, which the testsuite
8470 expects. GCC marks THIS as const in method definitions,
8471 but not in the class specifications (GCC PR 43053). */
8472 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8473 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8476 struct dwarf2_cu
*arg_cu
= cu
;
8477 const char *name
= dwarf2_name (child_die
, cu
);
8479 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8482 /* If the compiler emits this, use it. */
8483 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8486 else if (name
&& strcmp (name
, "this") == 0)
8487 /* Function definitions will have the argument names. */
8489 else if (name
== NULL
&& iparams
== 0)
8490 /* Declarations may not have the names, so like
8491 elsewhere in GDB, assume an artificial first
8492 argument is "this". */
8496 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8500 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8503 child_die
= sibling_die (child_die
);
8510 static struct type
*
8511 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8513 struct objfile
*objfile
= cu
->objfile
;
8514 const char *name
= NULL
;
8515 struct type
*this_type
;
8517 name
= dwarf2_full_name (NULL
, die
, cu
);
8518 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8519 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8520 TYPE_NAME (this_type
) = (char *) name
;
8521 set_die_type (die
, this_type
, cu
);
8522 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
8526 /* Find a representation of a given base type and install
8527 it in the TYPE field of the die. */
8529 static struct type
*
8530 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8532 struct objfile
*objfile
= cu
->objfile
;
8534 struct attribute
*attr
;
8535 int encoding
= 0, size
= 0;
8537 enum type_code code
= TYPE_CODE_INT
;
8539 struct type
*target_type
= NULL
;
8541 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8544 encoding
= DW_UNSND (attr
);
8546 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8549 size
= DW_UNSND (attr
);
8551 name
= dwarf2_name (die
, cu
);
8554 complaint (&symfile_complaints
,
8555 _("DW_AT_name missing from DW_TAG_base_type"));
8560 case DW_ATE_address
:
8561 /* Turn DW_ATE_address into a void * pointer. */
8562 code
= TYPE_CODE_PTR
;
8563 type_flags
|= TYPE_FLAG_UNSIGNED
;
8564 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8566 case DW_ATE_boolean
:
8567 code
= TYPE_CODE_BOOL
;
8568 type_flags
|= TYPE_FLAG_UNSIGNED
;
8570 case DW_ATE_complex_float
:
8571 code
= TYPE_CODE_COMPLEX
;
8572 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8574 case DW_ATE_decimal_float
:
8575 code
= TYPE_CODE_DECFLOAT
;
8578 code
= TYPE_CODE_FLT
;
8582 case DW_ATE_unsigned
:
8583 type_flags
|= TYPE_FLAG_UNSIGNED
;
8584 if (cu
->language
== language_fortran
8586 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
8587 code
= TYPE_CODE_CHAR
;
8589 case DW_ATE_signed_char
:
8590 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8591 || cu
->language
== language_pascal
8592 || cu
->language
== language_fortran
)
8593 code
= TYPE_CODE_CHAR
;
8595 case DW_ATE_unsigned_char
:
8596 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8597 || cu
->language
== language_pascal
8598 || cu
->language
== language_fortran
)
8599 code
= TYPE_CODE_CHAR
;
8600 type_flags
|= TYPE_FLAG_UNSIGNED
;
8603 /* We just treat this as an integer and then recognize the
8604 type by name elsewhere. */
8608 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8609 dwarf_type_encoding_name (encoding
));
8613 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8614 TYPE_NAME (type
) = name
;
8615 TYPE_TARGET_TYPE (type
) = target_type
;
8617 if (name
&& strcmp (name
, "char") == 0)
8618 TYPE_NOSIGN (type
) = 1;
8620 return set_die_type (die
, type
, cu
);
8623 /* Read the given DW_AT_subrange DIE. */
8625 static struct type
*
8626 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8628 struct type
*base_type
;
8629 struct type
*range_type
;
8630 struct attribute
*attr
;
8634 LONGEST negative_mask
;
8636 base_type
= die_type (die
, cu
);
8637 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8638 check_typedef (base_type
);
8640 /* The die_type call above may have already set the type for this DIE. */
8641 range_type
= get_die_type (die
, cu
);
8645 if (cu
->language
== language_fortran
)
8647 /* FORTRAN implies a lower bound of 1, if not given. */
8651 /* FIXME: For variable sized arrays either of these could be
8652 a variable rather than a constant value. We'll allow it,
8653 but we don't know how to handle it. */
8654 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8656 low
= dwarf2_get_attr_constant_value (attr
, 0);
8658 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8661 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
8663 /* GCC encodes arrays with unspecified or dynamic length
8664 with a DW_FORM_block1 attribute or a reference attribute.
8665 FIXME: GDB does not yet know how to handle dynamic
8666 arrays properly, treat them as arrays with unspecified
8669 FIXME: jimb/2003-09-22: GDB does not really know
8670 how to handle arrays of unspecified length
8671 either; we just represent them as zero-length
8672 arrays. Choose an appropriate upper bound given
8673 the lower bound we've computed above. */
8677 high
= dwarf2_get_attr_constant_value (attr
, 1);
8681 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8684 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8685 high
= low
+ count
- 1;
8689 /* Unspecified array length. */
8694 /* Dwarf-2 specifications explicitly allows to create subrange types
8695 without specifying a base type.
8696 In that case, the base type must be set to the type of
8697 the lower bound, upper bound or count, in that order, if any of these
8698 three attributes references an object that has a type.
8699 If no base type is found, the Dwarf-2 specifications say that
8700 a signed integer type of size equal to the size of an address should
8702 For the following C code: `extern char gdb_int [];'
8703 GCC produces an empty range DIE.
8704 FIXME: muller/2010-05-28: Possible references to object for low bound,
8705 high bound or count are not yet handled by this code. */
8706 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8708 struct objfile
*objfile
= cu
->objfile
;
8709 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8710 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8711 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8713 /* Test "int", "long int", and "long long int" objfile types,
8714 and select the first one having a size above or equal to the
8715 architecture address size. */
8716 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8717 base_type
= int_type
;
8720 int_type
= objfile_type (objfile
)->builtin_long
;
8721 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8722 base_type
= int_type
;
8725 int_type
= objfile_type (objfile
)->builtin_long_long
;
8726 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8727 base_type
= int_type
;
8733 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8734 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8735 low
|= negative_mask
;
8736 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8737 high
|= negative_mask
;
8739 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8741 /* Mark arrays with dynamic length at least as an array of unspecified
8742 length. GDB could check the boundary but before it gets implemented at
8743 least allow accessing the array elements. */
8744 if (attr
&& attr_form_is_block (attr
))
8745 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8747 /* Ada expects an empty array on no boundary attributes. */
8748 if (attr
== NULL
&& cu
->language
!= language_ada
)
8749 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8751 name
= dwarf2_name (die
, cu
);
8753 TYPE_NAME (range_type
) = name
;
8755 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8757 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8759 set_die_type (die
, range_type
, cu
);
8761 /* set_die_type should be already done. */
8762 set_descriptive_type (range_type
, die
, cu
);
8767 static struct type
*
8768 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8772 /* For now, we only support the C meaning of an unspecified type: void. */
8774 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8775 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8777 return set_die_type (die
, type
, cu
);
8780 /* Trivial hash function for die_info: the hash value of a DIE
8781 is its offset in .debug_info for this objfile. */
8784 die_hash (const void *item
)
8786 const struct die_info
*die
= item
;
8791 /* Trivial comparison function for die_info structures: two DIEs
8792 are equal if they have the same offset. */
8795 die_eq (const void *item_lhs
, const void *item_rhs
)
8797 const struct die_info
*die_lhs
= item_lhs
;
8798 const struct die_info
*die_rhs
= item_rhs
;
8800 return die_lhs
->offset
== die_rhs
->offset
;
8803 /* Read a whole compilation unit into a linked list of dies. */
8805 static struct die_info
*
8806 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8808 struct die_reader_specs reader_specs
;
8809 int read_abbrevs
= 0;
8810 struct cleanup
*back_to
= NULL
;
8811 struct die_info
*die
;
8813 if (cu
->dwarf2_abbrevs
== NULL
)
8815 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8816 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8820 gdb_assert (cu
->die_hash
== NULL
);
8822 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8826 &cu
->comp_unit_obstack
,
8827 hashtab_obstack_allocate
,
8828 dummy_obstack_deallocate
);
8830 init_cu_die_reader (&reader_specs
, cu
);
8832 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8835 do_cleanups (back_to
);
8840 /* Main entry point for reading a DIE and all children.
8841 Read the DIE and dump it if requested. */
8843 static struct die_info
*
8844 read_die_and_children (const struct die_reader_specs
*reader
,
8846 gdb_byte
**new_info_ptr
,
8847 struct die_info
*parent
)
8849 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8850 new_info_ptr
, parent
);
8852 if (dwarf2_die_debug
)
8854 fprintf_unfiltered (gdb_stdlog
,
8855 "\nRead die from %s of %s:\n",
8856 (reader
->cu
->per_cu
->debug_type_section
8859 reader
->abfd
->filename
);
8860 dump_die (result
, dwarf2_die_debug
);
8866 /* Read a single die and all its descendents. Set the die's sibling
8867 field to NULL; set other fields in the die correctly, and set all
8868 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8869 location of the info_ptr after reading all of those dies. PARENT
8870 is the parent of the die in question. */
8872 static struct die_info
*
8873 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8875 gdb_byte
**new_info_ptr
,
8876 struct die_info
*parent
)
8878 struct die_info
*die
;
8882 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8885 *new_info_ptr
= cur_ptr
;
8888 store_in_ref_table (die
, reader
->cu
);
8891 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8895 *new_info_ptr
= cur_ptr
;
8898 die
->sibling
= NULL
;
8899 die
->parent
= parent
;
8903 /* Read a die, all of its descendents, and all of its siblings; set
8904 all of the fields of all of the dies correctly. Arguments are as
8905 in read_die_and_children. */
8907 static struct die_info
*
8908 read_die_and_siblings (const struct die_reader_specs
*reader
,
8910 gdb_byte
**new_info_ptr
,
8911 struct die_info
*parent
)
8913 struct die_info
*first_die
, *last_sibling
;
8917 first_die
= last_sibling
= NULL
;
8921 struct die_info
*die
8922 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8926 *new_info_ptr
= cur_ptr
;
8933 last_sibling
->sibling
= die
;
8939 /* Read the die from the .debug_info section buffer. Set DIEP to
8940 point to a newly allocated die with its information, except for its
8941 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8942 whether the die has children or not. */
8945 read_full_die (const struct die_reader_specs
*reader
,
8946 struct die_info
**diep
, gdb_byte
*info_ptr
,
8949 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8950 struct abbrev_info
*abbrev
;
8951 struct die_info
*die
;
8952 struct dwarf2_cu
*cu
= reader
->cu
;
8953 bfd
*abfd
= reader
->abfd
;
8955 offset
= info_ptr
- reader
->buffer
;
8956 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8957 info_ptr
+= bytes_read
;
8965 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8967 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8969 bfd_get_filename (abfd
));
8971 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8972 die
->offset
= offset
;
8973 die
->tag
= abbrev
->tag
;
8974 die
->abbrev
= abbrev_number
;
8976 die
->num_attrs
= abbrev
->num_attrs
;
8978 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8979 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8980 abfd
, info_ptr
, cu
);
8983 *has_children
= abbrev
->has_children
;
8987 /* In DWARF version 2, the description of the debugging information is
8988 stored in a separate .debug_abbrev section. Before we read any
8989 dies from a section we read in all abbreviations and install them
8990 in a hash table. This function also sets flags in CU describing
8991 the data found in the abbrev table. */
8994 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8996 struct comp_unit_head
*cu_header
= &cu
->header
;
8997 gdb_byte
*abbrev_ptr
;
8998 struct abbrev_info
*cur_abbrev
;
8999 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9000 unsigned int abbrev_form
, hash_number
;
9001 struct attr_abbrev
*cur_attrs
;
9002 unsigned int allocated_attrs
;
9004 /* Initialize dwarf2 abbrevs. */
9005 obstack_init (&cu
->abbrev_obstack
);
9006 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9008 * sizeof (struct abbrev_info
*)));
9009 memset (cu
->dwarf2_abbrevs
, 0,
9010 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9012 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
9013 &dwarf2_per_objfile
->abbrev
);
9014 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
9015 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9016 abbrev_ptr
+= bytes_read
;
9018 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9019 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9021 /* Loop until we reach an abbrev number of 0. */
9022 while (abbrev_number
)
9024 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9026 /* read in abbrev header */
9027 cur_abbrev
->number
= abbrev_number
;
9028 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9029 abbrev_ptr
+= bytes_read
;
9030 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9033 if (cur_abbrev
->tag
== DW_TAG_namespace
)
9034 cu
->has_namespace_info
= 1;
9036 /* now read in declarations */
9037 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9038 abbrev_ptr
+= bytes_read
;
9039 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9040 abbrev_ptr
+= bytes_read
;
9043 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9045 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9047 = xrealloc (cur_attrs
, (allocated_attrs
9048 * sizeof (struct attr_abbrev
)));
9051 /* Record whether this compilation unit might have
9052 inter-compilation-unit references. If we don't know what form
9053 this attribute will have, then it might potentially be a
9054 DW_FORM_ref_addr, so we conservatively expect inter-CU
9057 if (abbrev_form
== DW_FORM_ref_addr
9058 || abbrev_form
== DW_FORM_indirect
)
9059 cu
->has_form_ref_addr
= 1;
9061 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9062 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9063 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9064 abbrev_ptr
+= bytes_read
;
9065 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9066 abbrev_ptr
+= bytes_read
;
9069 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9070 (cur_abbrev
->num_attrs
9071 * sizeof (struct attr_abbrev
)));
9072 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9073 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9075 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9076 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9077 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9079 /* Get next abbreviation.
9080 Under Irix6 the abbreviations for a compilation unit are not
9081 always properly terminated with an abbrev number of 0.
9082 Exit loop if we encounter an abbreviation which we have
9083 already read (which means we are about to read the abbreviations
9084 for the next compile unit) or if the end of the abbreviation
9085 table is reached. */
9086 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
9087 >= dwarf2_per_objfile
->abbrev
.size
)
9089 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9090 abbrev_ptr
+= bytes_read
;
9091 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9098 /* Release the memory used by the abbrev table for a compilation unit. */
9101 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9103 struct dwarf2_cu
*cu
= ptr_to_cu
;
9105 obstack_free (&cu
->abbrev_obstack
, NULL
);
9106 cu
->dwarf2_abbrevs
= NULL
;
9109 /* Lookup an abbrev_info structure in the abbrev hash table. */
9111 static struct abbrev_info
*
9112 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9114 unsigned int hash_number
;
9115 struct abbrev_info
*abbrev
;
9117 hash_number
= number
% ABBREV_HASH_SIZE
;
9118 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9122 if (abbrev
->number
== number
)
9125 abbrev
= abbrev
->next
;
9130 /* Returns nonzero if TAG represents a type that we might generate a partial
9134 is_type_tag_for_partial (int tag
)
9139 /* Some types that would be reasonable to generate partial symbols for,
9140 that we don't at present. */
9141 case DW_TAG_array_type
:
9142 case DW_TAG_file_type
:
9143 case DW_TAG_ptr_to_member_type
:
9144 case DW_TAG_set_type
:
9145 case DW_TAG_string_type
:
9146 case DW_TAG_subroutine_type
:
9148 case DW_TAG_base_type
:
9149 case DW_TAG_class_type
:
9150 case DW_TAG_interface_type
:
9151 case DW_TAG_enumeration_type
:
9152 case DW_TAG_structure_type
:
9153 case DW_TAG_subrange_type
:
9154 case DW_TAG_typedef
:
9155 case DW_TAG_union_type
:
9162 /* Load all DIEs that are interesting for partial symbols into memory. */
9164 static struct partial_die_info
*
9165 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9166 int building_psymtab
, struct dwarf2_cu
*cu
)
9168 struct partial_die_info
*part_die
;
9169 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9170 struct abbrev_info
*abbrev
;
9171 unsigned int bytes_read
;
9172 unsigned int load_all
= 0;
9174 int nesting_level
= 1;
9179 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
9183 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9187 &cu
->comp_unit_obstack
,
9188 hashtab_obstack_allocate
,
9189 dummy_obstack_deallocate
);
9191 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9192 sizeof (struct partial_die_info
));
9196 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9198 /* A NULL abbrev means the end of a series of children. */
9201 if (--nesting_level
== 0)
9203 /* PART_DIE was probably the last thing allocated on the
9204 comp_unit_obstack, so we could call obstack_free
9205 here. We don't do that because the waste is small,
9206 and will be cleaned up when we're done with this
9207 compilation unit. This way, we're also more robust
9208 against other users of the comp_unit_obstack. */
9211 info_ptr
+= bytes_read
;
9212 last_die
= parent_die
;
9213 parent_die
= parent_die
->die_parent
;
9217 /* Check for template arguments. We never save these; if
9218 they're seen, we just mark the parent, and go on our way. */
9219 if (parent_die
!= NULL
9220 && cu
->language
== language_cplus
9221 && (abbrev
->tag
== DW_TAG_template_type_param
9222 || abbrev
->tag
== DW_TAG_template_value_param
))
9224 parent_die
->has_template_arguments
= 1;
9228 /* We don't need a partial DIE for the template argument. */
9229 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9235 /* We only recurse into subprograms looking for template arguments.
9236 Skip their other children. */
9238 && cu
->language
== language_cplus
9239 && parent_die
!= NULL
9240 && parent_die
->tag
== DW_TAG_subprogram
)
9242 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9246 /* Check whether this DIE is interesting enough to save. Normally
9247 we would not be interested in members here, but there may be
9248 later variables referencing them via DW_AT_specification (for
9251 && !is_type_tag_for_partial (abbrev
->tag
)
9252 && abbrev
->tag
!= DW_TAG_constant
9253 && abbrev
->tag
!= DW_TAG_enumerator
9254 && abbrev
->tag
!= DW_TAG_subprogram
9255 && abbrev
->tag
!= DW_TAG_lexical_block
9256 && abbrev
->tag
!= DW_TAG_variable
9257 && abbrev
->tag
!= DW_TAG_namespace
9258 && abbrev
->tag
!= DW_TAG_module
9259 && abbrev
->tag
!= DW_TAG_member
)
9261 /* Otherwise we skip to the next sibling, if any. */
9262 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9266 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9267 buffer
, info_ptr
, cu
);
9269 /* This two-pass algorithm for processing partial symbols has a
9270 high cost in cache pressure. Thus, handle some simple cases
9271 here which cover the majority of C partial symbols. DIEs
9272 which neither have specification tags in them, nor could have
9273 specification tags elsewhere pointing at them, can simply be
9274 processed and discarded.
9276 This segment is also optional; scan_partial_symbols and
9277 add_partial_symbol will handle these DIEs if we chain
9278 them in normally. When compilers which do not emit large
9279 quantities of duplicate debug information are more common,
9280 this code can probably be removed. */
9282 /* Any complete simple types at the top level (pretty much all
9283 of them, for a language without namespaces), can be processed
9285 if (parent_die
== NULL
9286 && part_die
->has_specification
== 0
9287 && part_die
->is_declaration
== 0
9288 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9289 || part_die
->tag
== DW_TAG_base_type
9290 || part_die
->tag
== DW_TAG_subrange_type
))
9292 if (building_psymtab
&& part_die
->name
!= NULL
)
9293 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9294 VAR_DOMAIN
, LOC_TYPEDEF
,
9295 &cu
->objfile
->static_psymbols
,
9296 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9297 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9301 /* The exception for DW_TAG_typedef with has_children above is
9302 a workaround of GCC PR debug/47510. In the case of this complaint
9303 type_name_no_tag_or_error will error on such types later.
9305 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9306 it could not find the child DIEs referenced later, this is checked
9307 above. In correct DWARF DW_TAG_typedef should have no children. */
9309 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9310 complaint (&symfile_complaints
,
9311 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9312 "- DIE at 0x%x [in module %s]"),
9313 part_die
->offset
, cu
->objfile
->name
);
9315 /* If we're at the second level, and we're an enumerator, and
9316 our parent has no specification (meaning possibly lives in a
9317 namespace elsewhere), then we can add the partial symbol now
9318 instead of queueing it. */
9319 if (part_die
->tag
== DW_TAG_enumerator
9320 && parent_die
!= NULL
9321 && parent_die
->die_parent
== NULL
9322 && parent_die
->tag
== DW_TAG_enumeration_type
9323 && parent_die
->has_specification
== 0)
9325 if (part_die
->name
== NULL
)
9326 complaint (&symfile_complaints
,
9327 _("malformed enumerator DIE ignored"));
9328 else if (building_psymtab
)
9329 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9330 VAR_DOMAIN
, LOC_CONST
,
9331 (cu
->language
== language_cplus
9332 || cu
->language
== language_java
)
9333 ? &cu
->objfile
->global_psymbols
9334 : &cu
->objfile
->static_psymbols
,
9335 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9337 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9341 /* We'll save this DIE so link it in. */
9342 part_die
->die_parent
= parent_die
;
9343 part_die
->die_sibling
= NULL
;
9344 part_die
->die_child
= NULL
;
9346 if (last_die
&& last_die
== parent_die
)
9347 last_die
->die_child
= part_die
;
9349 last_die
->die_sibling
= part_die
;
9351 last_die
= part_die
;
9353 if (first_die
== NULL
)
9354 first_die
= part_die
;
9356 /* Maybe add the DIE to the hash table. Not all DIEs that we
9357 find interesting need to be in the hash table, because we
9358 also have the parent/sibling/child chains; only those that we
9359 might refer to by offset later during partial symbol reading.
9361 For now this means things that might have be the target of a
9362 DW_AT_specification, DW_AT_abstract_origin, or
9363 DW_AT_extension. DW_AT_extension will refer only to
9364 namespaces; DW_AT_abstract_origin refers to functions (and
9365 many things under the function DIE, but we do not recurse
9366 into function DIEs during partial symbol reading) and
9367 possibly variables as well; DW_AT_specification refers to
9368 declarations. Declarations ought to have the DW_AT_declaration
9369 flag. It happens that GCC forgets to put it in sometimes, but
9370 only for functions, not for types.
9372 Adding more things than necessary to the hash table is harmless
9373 except for the performance cost. Adding too few will result in
9374 wasted time in find_partial_die, when we reread the compilation
9375 unit with load_all_dies set. */
9378 || abbrev
->tag
== DW_TAG_constant
9379 || abbrev
->tag
== DW_TAG_subprogram
9380 || abbrev
->tag
== DW_TAG_variable
9381 || abbrev
->tag
== DW_TAG_namespace
9382 || part_die
->is_declaration
)
9386 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9387 part_die
->offset
, INSERT
);
9391 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9392 sizeof (struct partial_die_info
));
9394 /* For some DIEs we want to follow their children (if any). For C
9395 we have no reason to follow the children of structures; for other
9396 languages we have to, so that we can get at method physnames
9397 to infer fully qualified class names, for DW_AT_specification,
9398 and for C++ template arguments. For C++, we also look one level
9399 inside functions to find template arguments (if the name of the
9400 function does not already contain the template arguments).
9402 For Ada, we need to scan the children of subprograms and lexical
9403 blocks as well because Ada allows the definition of nested
9404 entities that could be interesting for the debugger, such as
9405 nested subprograms for instance. */
9406 if (last_die
->has_children
9408 || last_die
->tag
== DW_TAG_namespace
9409 || last_die
->tag
== DW_TAG_module
9410 || last_die
->tag
== DW_TAG_enumeration_type
9411 || (cu
->language
== language_cplus
9412 && last_die
->tag
== DW_TAG_subprogram
9413 && (last_die
->name
== NULL
9414 || strchr (last_die
->name
, '<') == NULL
))
9415 || (cu
->language
!= language_c
9416 && (last_die
->tag
== DW_TAG_class_type
9417 || last_die
->tag
== DW_TAG_interface_type
9418 || last_die
->tag
== DW_TAG_structure_type
9419 || last_die
->tag
== DW_TAG_union_type
))
9420 || (cu
->language
== language_ada
9421 && (last_die
->tag
== DW_TAG_subprogram
9422 || last_die
->tag
== DW_TAG_lexical_block
))))
9425 parent_die
= last_die
;
9429 /* Otherwise we skip to the next sibling, if any. */
9430 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9432 /* Back to the top, do it again. */
9436 /* Read a minimal amount of information into the minimal die structure. */
9439 read_partial_die (struct partial_die_info
*part_die
,
9440 struct abbrev_info
*abbrev
,
9441 unsigned int abbrev_len
, bfd
*abfd
,
9442 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9443 struct dwarf2_cu
*cu
)
9446 struct attribute attr
;
9447 int has_low_pc_attr
= 0;
9448 int has_high_pc_attr
= 0;
9450 memset (part_die
, 0, sizeof (struct partial_die_info
));
9452 part_die
->offset
= info_ptr
- buffer
;
9454 info_ptr
+= abbrev_len
;
9459 part_die
->tag
= abbrev
->tag
;
9460 part_die
->has_children
= abbrev
->has_children
;
9462 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9464 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9466 /* Store the data if it is of an attribute we want to keep in a
9467 partial symbol table. */
9471 switch (part_die
->tag
)
9473 case DW_TAG_compile_unit
:
9474 case DW_TAG_type_unit
:
9475 /* Compilation units have a DW_AT_name that is a filename, not
9476 a source language identifier. */
9477 case DW_TAG_enumeration_type
:
9478 case DW_TAG_enumerator
:
9479 /* These tags always have simple identifiers already; no need
9480 to canonicalize them. */
9481 part_die
->name
= DW_STRING (&attr
);
9485 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9486 &cu
->objfile
->objfile_obstack
);
9490 case DW_AT_linkage_name
:
9491 case DW_AT_MIPS_linkage_name
:
9492 /* Note that both forms of linkage name might appear. We
9493 assume they will be the same, and we only store the last
9495 if (cu
->language
== language_ada
)
9496 part_die
->name
= DW_STRING (&attr
);
9497 part_die
->linkage_name
= DW_STRING (&attr
);
9500 has_low_pc_attr
= 1;
9501 part_die
->lowpc
= DW_ADDR (&attr
);
9504 has_high_pc_attr
= 1;
9505 part_die
->highpc
= DW_ADDR (&attr
);
9507 case DW_AT_location
:
9508 /* Support the .debug_loc offsets. */
9509 if (attr_form_is_block (&attr
))
9511 part_die
->locdesc
= DW_BLOCK (&attr
);
9513 else if (attr_form_is_section_offset (&attr
))
9515 dwarf2_complex_location_expr_complaint ();
9519 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9520 "partial symbol information");
9523 case DW_AT_external
:
9524 part_die
->is_external
= DW_UNSND (&attr
);
9526 case DW_AT_declaration
:
9527 part_die
->is_declaration
= DW_UNSND (&attr
);
9530 part_die
->has_type
= 1;
9532 case DW_AT_abstract_origin
:
9533 case DW_AT_specification
:
9534 case DW_AT_extension
:
9535 part_die
->has_specification
= 1;
9536 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9539 /* Ignore absolute siblings, they might point outside of
9540 the current compile unit. */
9541 if (attr
.form
== DW_FORM_ref_addr
)
9542 complaint (&symfile_complaints
,
9543 _("ignoring absolute DW_AT_sibling"));
9545 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9547 case DW_AT_byte_size
:
9548 part_die
->has_byte_size
= 1;
9550 case DW_AT_calling_convention
:
9551 /* DWARF doesn't provide a way to identify a program's source-level
9552 entry point. DW_AT_calling_convention attributes are only meant
9553 to describe functions' calling conventions.
9555 However, because it's a necessary piece of information in
9556 Fortran, and because DW_CC_program is the only piece of debugging
9557 information whose definition refers to a 'main program' at all,
9558 several compilers have begun marking Fortran main programs with
9559 DW_CC_program --- even when those functions use the standard
9560 calling conventions.
9562 So until DWARF specifies a way to provide this information and
9563 compilers pick up the new representation, we'll support this
9565 if (DW_UNSND (&attr
) == DW_CC_program
9566 && cu
->language
== language_fortran
)
9568 set_main_name (part_die
->name
);
9570 /* As this DIE has a static linkage the name would be difficult
9571 to look up later. */
9572 language_of_main
= language_fortran
;
9580 if (has_low_pc_attr
&& has_high_pc_attr
)
9582 /* When using the GNU linker, .gnu.linkonce. sections are used to
9583 eliminate duplicate copies of functions and vtables and such.
9584 The linker will arbitrarily choose one and discard the others.
9585 The AT_*_pc values for such functions refer to local labels in
9586 these sections. If the section from that file was discarded, the
9587 labels are not in the output, so the relocs get a value of 0.
9588 If this is a discarded function, mark the pc bounds as invalid,
9589 so that GDB will ignore it. */
9590 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9592 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9594 complaint (&symfile_complaints
,
9595 _("DW_AT_low_pc %s is zero "
9596 "for DIE at 0x%x [in module %s]"),
9597 paddress (gdbarch
, part_die
->lowpc
),
9598 part_die
->offset
, cu
->objfile
->name
);
9600 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9601 else if (part_die
->lowpc
>= part_die
->highpc
)
9603 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9605 complaint (&symfile_complaints
,
9606 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9607 "for DIE at 0x%x [in module %s]"),
9608 paddress (gdbarch
, part_die
->lowpc
),
9609 paddress (gdbarch
, part_die
->highpc
),
9610 part_die
->offset
, cu
->objfile
->name
);
9613 part_die
->has_pc_info
= 1;
9619 /* Find a cached partial DIE at OFFSET in CU. */
9621 static struct partial_die_info
*
9622 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9624 struct partial_die_info
*lookup_die
= NULL
;
9625 struct partial_die_info part_die
;
9627 part_die
.offset
= offset
;
9628 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9633 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9634 except in the case of .debug_types DIEs which do not reference
9635 outside their CU (they do however referencing other types via
9636 DW_FORM_ref_sig8). */
9638 static struct partial_die_info
*
9639 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9641 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9642 struct partial_die_info
*pd
= NULL
;
9644 if (cu
->per_cu
->debug_type_section
)
9646 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9652 if (offset_in_cu_p (&cu
->header
, offset
))
9654 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9659 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9661 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9662 load_partial_comp_unit (per_cu
, cu
->objfile
);
9664 per_cu
->cu
->last_used
= 0;
9665 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9667 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9669 struct cleanup
*back_to
;
9670 struct partial_die_info comp_unit_die
;
9671 struct abbrev_info
*abbrev
;
9672 unsigned int bytes_read
;
9675 per_cu
->load_all_dies
= 1;
9677 /* Re-read the DIEs. */
9678 back_to
= make_cleanup (null_cleanup
, 0);
9679 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9681 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
9682 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9684 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9685 + per_cu
->cu
->header
.offset
9686 + per_cu
->cu
->header
.first_die_offset
);
9687 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9688 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9689 per_cu
->cu
->objfile
->obfd
,
9690 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9692 if (comp_unit_die
.has_children
)
9693 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
9694 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9696 do_cleanups (back_to
);
9698 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9704 internal_error (__FILE__
, __LINE__
,
9705 _("could not find partial DIE 0x%x "
9706 "in cache [from module %s]\n"),
9707 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9711 /* See if we can figure out if the class lives in a namespace. We do
9712 this by looking for a member function; its demangled name will
9713 contain namespace info, if there is any. */
9716 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9717 struct dwarf2_cu
*cu
)
9719 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9720 what template types look like, because the demangler
9721 frequently doesn't give the same name as the debug info. We
9722 could fix this by only using the demangled name to get the
9723 prefix (but see comment in read_structure_type). */
9725 struct partial_die_info
*real_pdi
;
9726 struct partial_die_info
*child_pdi
;
9728 /* If this DIE (this DIE's specification, if any) has a parent, then
9729 we should not do this. We'll prepend the parent's fully qualified
9730 name when we create the partial symbol. */
9732 real_pdi
= struct_pdi
;
9733 while (real_pdi
->has_specification
)
9734 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9736 if (real_pdi
->die_parent
!= NULL
)
9739 for (child_pdi
= struct_pdi
->die_child
;
9741 child_pdi
= child_pdi
->die_sibling
)
9743 if (child_pdi
->tag
== DW_TAG_subprogram
9744 && child_pdi
->linkage_name
!= NULL
)
9746 char *actual_class_name
9747 = language_class_name_from_physname (cu
->language_defn
,
9748 child_pdi
->linkage_name
);
9749 if (actual_class_name
!= NULL
)
9752 = obsavestring (actual_class_name
,
9753 strlen (actual_class_name
),
9754 &cu
->objfile
->objfile_obstack
);
9755 xfree (actual_class_name
);
9762 /* Adjust PART_DIE before generating a symbol for it. This function
9763 may set the is_external flag or change the DIE's name. */
9766 fixup_partial_die (struct partial_die_info
*part_die
,
9767 struct dwarf2_cu
*cu
)
9769 /* Once we've fixed up a die, there's no point in doing so again.
9770 This also avoids a memory leak if we were to call
9771 guess_partial_die_structure_name multiple times. */
9772 if (part_die
->fixup_called
)
9775 /* If we found a reference attribute and the DIE has no name, try
9776 to find a name in the referred to DIE. */
9778 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9780 struct partial_die_info
*spec_die
;
9782 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9784 fixup_partial_die (spec_die
, cu
);
9788 part_die
->name
= spec_die
->name
;
9790 /* Copy DW_AT_external attribute if it is set. */
9791 if (spec_die
->is_external
)
9792 part_die
->is_external
= spec_die
->is_external
;
9796 /* Set default names for some unnamed DIEs. */
9798 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9799 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
9801 /* If there is no parent die to provide a namespace, and there are
9802 children, see if we can determine the namespace from their linkage
9804 NOTE: We need to do this even if cu->has_namespace_info != 0.
9805 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9806 if (cu
->language
== language_cplus
9807 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
9808 && part_die
->die_parent
== NULL
9809 && part_die
->has_children
9810 && (part_die
->tag
== DW_TAG_class_type
9811 || part_die
->tag
== DW_TAG_structure_type
9812 || part_die
->tag
== DW_TAG_union_type
))
9813 guess_partial_die_structure_name (part_die
, cu
);
9815 /* GCC might emit a nameless struct or union that has a linkage
9816 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
9817 if (part_die
->name
== NULL
9818 && (part_die
->tag
== DW_TAG_class_type
9819 || part_die
->tag
== DW_TAG_interface_type
9820 || part_die
->tag
== DW_TAG_structure_type
9821 || part_die
->tag
== DW_TAG_union_type
)
9822 && part_die
->linkage_name
!= NULL
)
9826 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
9831 /* Strip any leading namespaces/classes, keep only the base name.
9832 DW_AT_name for named DIEs does not contain the prefixes. */
9833 base
= strrchr (demangled
, ':');
9834 if (base
&& base
> demangled
&& base
[-1] == ':')
9839 part_die
->name
= obsavestring (base
, strlen (base
),
9840 &cu
->objfile
->objfile_obstack
);
9845 part_die
->fixup_called
= 1;
9848 /* Read an attribute value described by an attribute form. */
9851 read_attribute_value (struct attribute
*attr
, unsigned form
,
9852 bfd
*abfd
, gdb_byte
*info_ptr
,
9853 struct dwarf2_cu
*cu
)
9855 struct comp_unit_head
*cu_header
= &cu
->header
;
9856 unsigned int bytes_read
;
9857 struct dwarf_block
*blk
;
9862 case DW_FORM_ref_addr
:
9863 if (cu
->header
.version
== 2)
9864 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9866 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
9867 &cu
->header
, &bytes_read
);
9868 info_ptr
+= bytes_read
;
9871 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9872 info_ptr
+= bytes_read
;
9874 case DW_FORM_block2
:
9875 blk
= dwarf_alloc_block (cu
);
9876 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9878 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9879 info_ptr
+= blk
->size
;
9880 DW_BLOCK (attr
) = blk
;
9882 case DW_FORM_block4
:
9883 blk
= dwarf_alloc_block (cu
);
9884 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9886 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9887 info_ptr
+= blk
->size
;
9888 DW_BLOCK (attr
) = blk
;
9891 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9895 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9899 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9902 case DW_FORM_sec_offset
:
9903 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9904 info_ptr
+= bytes_read
;
9906 case DW_FORM_string
:
9907 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9908 DW_STRING_IS_CANONICAL (attr
) = 0;
9909 info_ptr
+= bytes_read
;
9912 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9914 DW_STRING_IS_CANONICAL (attr
) = 0;
9915 info_ptr
+= bytes_read
;
9917 case DW_FORM_exprloc
:
9919 blk
= dwarf_alloc_block (cu
);
9920 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9921 info_ptr
+= bytes_read
;
9922 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9923 info_ptr
+= blk
->size
;
9924 DW_BLOCK (attr
) = blk
;
9926 case DW_FORM_block1
:
9927 blk
= dwarf_alloc_block (cu
);
9928 blk
->size
= read_1_byte (abfd
, info_ptr
);
9930 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9931 info_ptr
+= blk
->size
;
9932 DW_BLOCK (attr
) = blk
;
9935 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9939 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9942 case DW_FORM_flag_present
:
9943 DW_UNSND (attr
) = 1;
9946 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9947 info_ptr
+= bytes_read
;
9950 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9951 info_ptr
+= bytes_read
;
9954 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9958 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9962 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9966 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9969 case DW_FORM_ref_sig8
:
9970 /* Convert the signature to something we can record in DW_UNSND
9972 NOTE: This is NULL if the type wasn't found. */
9973 DW_SIGNATURED_TYPE (attr
) =
9974 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9977 case DW_FORM_ref_udata
:
9978 DW_ADDR (attr
) = (cu
->header
.offset
9979 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9980 info_ptr
+= bytes_read
;
9982 case DW_FORM_indirect
:
9983 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9984 info_ptr
+= bytes_read
;
9985 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9988 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9989 dwarf_form_name (form
),
9990 bfd_get_filename (abfd
));
9993 /* We have seen instances where the compiler tried to emit a byte
9994 size attribute of -1 which ended up being encoded as an unsigned
9995 0xffffffff. Although 0xffffffff is technically a valid size value,
9996 an object of this size seems pretty unlikely so we can relatively
9997 safely treat these cases as if the size attribute was invalid and
9998 treat them as zero by default. */
9999 if (attr
->name
== DW_AT_byte_size
10000 && form
== DW_FORM_data4
10001 && DW_UNSND (attr
) >= 0xffffffff)
10004 (&symfile_complaints
,
10005 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10006 hex_string (DW_UNSND (attr
)));
10007 DW_UNSND (attr
) = 0;
10013 /* Read an attribute described by an abbreviated attribute. */
10016 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10017 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
10019 attr
->name
= abbrev
->name
;
10020 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
10023 /* Read dwarf information from a buffer. */
10025 static unsigned int
10026 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10028 return bfd_get_8 (abfd
, buf
);
10032 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10034 return bfd_get_signed_8 (abfd
, buf
);
10037 static unsigned int
10038 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10040 return bfd_get_16 (abfd
, buf
);
10043 static unsigned int
10044 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10046 return bfd_get_32 (abfd
, buf
);
10050 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10052 return bfd_get_64 (abfd
, buf
);
10056 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10057 unsigned int *bytes_read
)
10059 struct comp_unit_head
*cu_header
= &cu
->header
;
10060 CORE_ADDR retval
= 0;
10062 if (cu_header
->signed_addr_p
)
10064 switch (cu_header
->addr_size
)
10067 retval
= bfd_get_signed_16 (abfd
, buf
);
10070 retval
= bfd_get_signed_32 (abfd
, buf
);
10073 retval
= bfd_get_signed_64 (abfd
, buf
);
10076 internal_error (__FILE__
, __LINE__
,
10077 _("read_address: bad switch, signed [in module %s]"),
10078 bfd_get_filename (abfd
));
10083 switch (cu_header
->addr_size
)
10086 retval
= bfd_get_16 (abfd
, buf
);
10089 retval
= bfd_get_32 (abfd
, buf
);
10092 retval
= bfd_get_64 (abfd
, buf
);
10095 internal_error (__FILE__
, __LINE__
,
10096 _("read_address: bad switch, "
10097 "unsigned [in module %s]"),
10098 bfd_get_filename (abfd
));
10102 *bytes_read
= cu_header
->addr_size
;
10106 /* Read the initial length from a section. The (draft) DWARF 3
10107 specification allows the initial length to take up either 4 bytes
10108 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10109 bytes describe the length and all offsets will be 8 bytes in length
10112 An older, non-standard 64-bit format is also handled by this
10113 function. The older format in question stores the initial length
10114 as an 8-byte quantity without an escape value. Lengths greater
10115 than 2^32 aren't very common which means that the initial 4 bytes
10116 is almost always zero. Since a length value of zero doesn't make
10117 sense for the 32-bit format, this initial zero can be considered to
10118 be an escape value which indicates the presence of the older 64-bit
10119 format. As written, the code can't detect (old format) lengths
10120 greater than 4GB. If it becomes necessary to handle lengths
10121 somewhat larger than 4GB, we could allow other small values (such
10122 as the non-sensical values of 1, 2, and 3) to also be used as
10123 escape values indicating the presence of the old format.
10125 The value returned via bytes_read should be used to increment the
10126 relevant pointer after calling read_initial_length().
10128 [ Note: read_initial_length() and read_offset() are based on the
10129 document entitled "DWARF Debugging Information Format", revision
10130 3, draft 8, dated November 19, 2001. This document was obtained
10133 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10135 This document is only a draft and is subject to change. (So beware.)
10137 Details regarding the older, non-standard 64-bit format were
10138 determined empirically by examining 64-bit ELF files produced by
10139 the SGI toolchain on an IRIX 6.5 machine.
10141 - Kevin, July 16, 2002
10145 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10147 LONGEST length
= bfd_get_32 (abfd
, buf
);
10149 if (length
== 0xffffffff)
10151 length
= bfd_get_64 (abfd
, buf
+ 4);
10154 else if (length
== 0)
10156 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10157 length
= bfd_get_64 (abfd
, buf
);
10168 /* Cover function for read_initial_length.
10169 Returns the length of the object at BUF, and stores the size of the
10170 initial length in *BYTES_READ and stores the size that offsets will be in
10172 If the initial length size is not equivalent to that specified in
10173 CU_HEADER then issue a complaint.
10174 This is useful when reading non-comp-unit headers. */
10177 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10178 const struct comp_unit_head
*cu_header
,
10179 unsigned int *bytes_read
,
10180 unsigned int *offset_size
)
10182 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10184 gdb_assert (cu_header
->initial_length_size
== 4
10185 || cu_header
->initial_length_size
== 8
10186 || cu_header
->initial_length_size
== 12);
10188 if (cu_header
->initial_length_size
!= *bytes_read
)
10189 complaint (&symfile_complaints
,
10190 _("intermixed 32-bit and 64-bit DWARF sections"));
10192 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10196 /* Read an offset from the data stream. The size of the offset is
10197 given by cu_header->offset_size. */
10200 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10201 unsigned int *bytes_read
)
10203 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10205 *bytes_read
= cu_header
->offset_size
;
10209 /* Read an offset from the data stream. */
10212 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10214 LONGEST retval
= 0;
10216 switch (offset_size
)
10219 retval
= bfd_get_32 (abfd
, buf
);
10222 retval
= bfd_get_64 (abfd
, buf
);
10225 internal_error (__FILE__
, __LINE__
,
10226 _("read_offset_1: bad switch [in module %s]"),
10227 bfd_get_filename (abfd
));
10234 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10236 /* If the size of a host char is 8 bits, we can return a pointer
10237 to the buffer, otherwise we have to copy the data to a buffer
10238 allocated on the temporary obstack. */
10239 gdb_assert (HOST_CHAR_BIT
== 8);
10244 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10246 /* If the size of a host char is 8 bits, we can return a pointer
10247 to the string, otherwise we have to copy the string to a buffer
10248 allocated on the temporary obstack. */
10249 gdb_assert (HOST_CHAR_BIT
== 8);
10252 *bytes_read_ptr
= 1;
10255 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10256 return (char *) buf
;
10260 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
10262 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10263 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10264 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10265 bfd_get_filename (abfd
));
10266 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10267 error (_("DW_FORM_strp pointing outside of "
10268 ".debug_str section [in module %s]"),
10269 bfd_get_filename (abfd
));
10270 gdb_assert (HOST_CHAR_BIT
== 8);
10271 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10273 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10277 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10278 const struct comp_unit_head
*cu_header
,
10279 unsigned int *bytes_read_ptr
)
10281 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10283 return read_indirect_string_at_offset (abfd
, str_offset
);
10286 static unsigned long
10287 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10289 unsigned long result
;
10290 unsigned int num_read
;
10292 unsigned char byte
;
10300 byte
= bfd_get_8 (abfd
, buf
);
10303 result
|= ((unsigned long)(byte
& 127) << shift
);
10304 if ((byte
& 128) == 0)
10310 *bytes_read_ptr
= num_read
;
10315 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10318 int i
, shift
, num_read
;
10319 unsigned char byte
;
10327 byte
= bfd_get_8 (abfd
, buf
);
10330 result
|= ((long)(byte
& 127) << shift
);
10332 if ((byte
& 128) == 0)
10337 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10338 result
|= -(((long)1) << shift
);
10339 *bytes_read_ptr
= num_read
;
10343 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10346 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10352 byte
= bfd_get_8 (abfd
, buf
);
10354 if ((byte
& 128) == 0)
10360 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10367 cu
->language
= language_c
;
10369 case DW_LANG_C_plus_plus
:
10370 cu
->language
= language_cplus
;
10373 cu
->language
= language_d
;
10375 case DW_LANG_Fortran77
:
10376 case DW_LANG_Fortran90
:
10377 case DW_LANG_Fortran95
:
10378 cu
->language
= language_fortran
;
10380 case DW_LANG_Mips_Assembler
:
10381 cu
->language
= language_asm
;
10384 cu
->language
= language_java
;
10386 case DW_LANG_Ada83
:
10387 case DW_LANG_Ada95
:
10388 cu
->language
= language_ada
;
10390 case DW_LANG_Modula2
:
10391 cu
->language
= language_m2
;
10393 case DW_LANG_Pascal83
:
10394 cu
->language
= language_pascal
;
10397 cu
->language
= language_objc
;
10399 case DW_LANG_Cobol74
:
10400 case DW_LANG_Cobol85
:
10402 cu
->language
= language_minimal
;
10405 cu
->language_defn
= language_def (cu
->language
);
10408 /* Return the named attribute or NULL if not there. */
10410 static struct attribute
*
10411 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10414 struct attribute
*spec
= NULL
;
10416 for (i
= 0; i
< die
->num_attrs
; ++i
)
10418 if (die
->attrs
[i
].name
== name
)
10419 return &die
->attrs
[i
];
10420 if (die
->attrs
[i
].name
== DW_AT_specification
10421 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10422 spec
= &die
->attrs
[i
];
10427 die
= follow_die_ref (die
, spec
, &cu
);
10428 return dwarf2_attr (die
, name
, cu
);
10434 /* Return the named attribute or NULL if not there,
10435 but do not follow DW_AT_specification, etc.
10436 This is for use in contexts where we're reading .debug_types dies.
10437 Following DW_AT_specification, DW_AT_abstract_origin will take us
10438 back up the chain, and we want to go down. */
10440 static struct attribute
*
10441 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10442 struct dwarf2_cu
*cu
)
10446 for (i
= 0; i
< die
->num_attrs
; ++i
)
10447 if (die
->attrs
[i
].name
== name
)
10448 return &die
->attrs
[i
];
10453 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10454 and holds a non-zero value. This function should only be used for
10455 DW_FORM_flag or DW_FORM_flag_present attributes. */
10458 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10460 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10462 return (attr
&& DW_UNSND (attr
));
10466 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10468 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10469 which value is non-zero. However, we have to be careful with
10470 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10471 (via dwarf2_flag_true_p) follows this attribute. So we may
10472 end up accidently finding a declaration attribute that belongs
10473 to a different DIE referenced by the specification attribute,
10474 even though the given DIE does not have a declaration attribute. */
10475 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10476 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10479 /* Return the die giving the specification for DIE, if there is
10480 one. *SPEC_CU is the CU containing DIE on input, and the CU
10481 containing the return value on output. If there is no
10482 specification, but there is an abstract origin, that is
10485 static struct die_info
*
10486 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10488 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10491 if (spec_attr
== NULL
)
10492 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10494 if (spec_attr
== NULL
)
10497 return follow_die_ref (die
, spec_attr
, spec_cu
);
10500 /* Free the line_header structure *LH, and any arrays and strings it
10502 NOTE: This is also used as a "cleanup" function. */
10505 free_line_header (struct line_header
*lh
)
10507 if (lh
->standard_opcode_lengths
)
10508 xfree (lh
->standard_opcode_lengths
);
10510 /* Remember that all the lh->file_names[i].name pointers are
10511 pointers into debug_line_buffer, and don't need to be freed. */
10512 if (lh
->file_names
)
10513 xfree (lh
->file_names
);
10515 /* Similarly for the include directory names. */
10516 if (lh
->include_dirs
)
10517 xfree (lh
->include_dirs
);
10522 /* Add an entry to LH's include directory table. */
10525 add_include_dir (struct line_header
*lh
, char *include_dir
)
10527 /* Grow the array if necessary. */
10528 if (lh
->include_dirs_size
== 0)
10530 lh
->include_dirs_size
= 1; /* for testing */
10531 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10532 * sizeof (*lh
->include_dirs
));
10534 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10536 lh
->include_dirs_size
*= 2;
10537 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10538 (lh
->include_dirs_size
10539 * sizeof (*lh
->include_dirs
)));
10542 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10545 /* Add an entry to LH's file name table. */
10548 add_file_name (struct line_header
*lh
,
10550 unsigned int dir_index
,
10551 unsigned int mod_time
,
10552 unsigned int length
)
10554 struct file_entry
*fe
;
10556 /* Grow the array if necessary. */
10557 if (lh
->file_names_size
== 0)
10559 lh
->file_names_size
= 1; /* for testing */
10560 lh
->file_names
= xmalloc (lh
->file_names_size
10561 * sizeof (*lh
->file_names
));
10563 else if (lh
->num_file_names
>= lh
->file_names_size
)
10565 lh
->file_names_size
*= 2;
10566 lh
->file_names
= xrealloc (lh
->file_names
,
10567 (lh
->file_names_size
10568 * sizeof (*lh
->file_names
)));
10571 fe
= &lh
->file_names
[lh
->num_file_names
++];
10573 fe
->dir_index
= dir_index
;
10574 fe
->mod_time
= mod_time
;
10575 fe
->length
= length
;
10576 fe
->included_p
= 0;
10580 /* Read the statement program header starting at OFFSET in
10581 .debug_line, according to the endianness of ABFD. Return a pointer
10582 to a struct line_header, allocated using xmalloc.
10584 NOTE: the strings in the include directory and file name tables of
10585 the returned object point into debug_line_buffer, and must not be
10588 static struct line_header
*
10589 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10590 struct dwarf2_cu
*cu
)
10592 struct cleanup
*back_to
;
10593 struct line_header
*lh
;
10594 gdb_byte
*line_ptr
;
10595 unsigned int bytes_read
, offset_size
;
10597 char *cur_dir
, *cur_file
;
10599 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10600 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10602 complaint (&symfile_complaints
, _("missing .debug_line section"));
10606 /* Make sure that at least there's room for the total_length field.
10607 That could be 12 bytes long, but we're just going to fudge that. */
10608 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10610 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10614 lh
= xmalloc (sizeof (*lh
));
10615 memset (lh
, 0, sizeof (*lh
));
10616 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10619 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10621 /* Read in the header. */
10623 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10624 &bytes_read
, &offset_size
);
10625 line_ptr
+= bytes_read
;
10626 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10627 + dwarf2_per_objfile
->line
.size
))
10629 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10632 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10633 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10635 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10636 line_ptr
+= offset_size
;
10637 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10639 if (lh
->version
>= 4)
10641 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10645 lh
->maximum_ops_per_instruction
= 1;
10647 if (lh
->maximum_ops_per_instruction
== 0)
10649 lh
->maximum_ops_per_instruction
= 1;
10650 complaint (&symfile_complaints
,
10651 _("invalid maximum_ops_per_instruction "
10652 "in `.debug_line' section"));
10655 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10657 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10659 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10661 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10663 lh
->standard_opcode_lengths
10664 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10666 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10667 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10669 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10673 /* Read directory table. */
10674 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10676 line_ptr
+= bytes_read
;
10677 add_include_dir (lh
, cur_dir
);
10679 line_ptr
+= bytes_read
;
10681 /* Read file name table. */
10682 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10684 unsigned int dir_index
, mod_time
, length
;
10686 line_ptr
+= bytes_read
;
10687 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10688 line_ptr
+= bytes_read
;
10689 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10690 line_ptr
+= bytes_read
;
10691 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10692 line_ptr
+= bytes_read
;
10694 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10696 line_ptr
+= bytes_read
;
10697 lh
->statement_program_start
= line_ptr
;
10699 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
10700 + dwarf2_per_objfile
->line
.size
))
10701 complaint (&symfile_complaints
,
10702 _("line number info header doesn't "
10703 "fit in `.debug_line' section"));
10705 discard_cleanups (back_to
);
10709 /* This function exists to work around a bug in certain compilers
10710 (particularly GCC 2.95), in which the first line number marker of a
10711 function does not show up until after the prologue, right before
10712 the second line number marker. This function shifts ADDRESS down
10713 to the beginning of the function if necessary, and is called on
10714 addresses passed to record_line. */
10717 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
10719 struct function_range
*fn
;
10721 /* Find the function_range containing address. */
10725 if (!cu
->cached_fn
)
10726 cu
->cached_fn
= cu
->first_fn
;
10728 fn
= cu
->cached_fn
;
10730 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10736 while (fn
&& fn
!= cu
->cached_fn
)
10737 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10747 if (address
!= fn
->lowpc
)
10748 complaint (&symfile_complaints
,
10749 _("misplaced first line number at 0x%lx for '%s'"),
10750 (unsigned long) address
, fn
->name
);
10755 /* Subroutine of dwarf_decode_lines to simplify it.
10756 Return the file name of the psymtab for included file FILE_INDEX
10757 in line header LH of PST.
10758 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10759 If space for the result is malloc'd, it will be freed by a cleanup.
10760 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10763 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10764 const struct partial_symtab
*pst
,
10765 const char *comp_dir
)
10767 const struct file_entry fe
= lh
->file_names
[file_index
];
10768 char *include_name
= fe
.name
;
10769 char *include_name_to_compare
= include_name
;
10770 char *dir_name
= NULL
;
10771 const char *pst_filename
;
10772 char *copied_name
= NULL
;
10776 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10778 if (!IS_ABSOLUTE_PATH (include_name
)
10779 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10781 /* Avoid creating a duplicate psymtab for PST.
10782 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10783 Before we do the comparison, however, we need to account
10784 for DIR_NAME and COMP_DIR.
10785 First prepend dir_name (if non-NULL). If we still don't
10786 have an absolute path prepend comp_dir (if non-NULL).
10787 However, the directory we record in the include-file's
10788 psymtab does not contain COMP_DIR (to match the
10789 corresponding symtab(s)).
10794 bash$ gcc -g ./hello.c
10795 include_name = "hello.c"
10797 DW_AT_comp_dir = comp_dir = "/tmp"
10798 DW_AT_name = "./hello.c" */
10800 if (dir_name
!= NULL
)
10802 include_name
= concat (dir_name
, SLASH_STRING
,
10803 include_name
, (char *)NULL
);
10804 include_name_to_compare
= include_name
;
10805 make_cleanup (xfree
, include_name
);
10807 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10809 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10810 include_name
, (char *)NULL
);
10814 pst_filename
= pst
->filename
;
10815 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10817 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
10818 pst_filename
, (char *)NULL
);
10819 pst_filename
= copied_name
;
10822 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
10824 if (include_name_to_compare
!= include_name
)
10825 xfree (include_name_to_compare
);
10826 if (copied_name
!= NULL
)
10827 xfree (copied_name
);
10831 return include_name
;
10834 /* Ignore this record_line request. */
10837 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10842 /* Decode the Line Number Program (LNP) for the given line_header
10843 structure and CU. The actual information extracted and the type
10844 of structures created from the LNP depends on the value of PST.
10846 1. If PST is NULL, then this procedure uses the data from the program
10847 to create all necessary symbol tables, and their linetables.
10849 2. If PST is not NULL, this procedure reads the program to determine
10850 the list of files included by the unit represented by PST, and
10851 builds all the associated partial symbol tables.
10853 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10854 It is used for relative paths in the line table.
10855 NOTE: When processing partial symtabs (pst != NULL),
10856 comp_dir == pst->dirname.
10858 NOTE: It is important that psymtabs have the same file name (via strcmp)
10859 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10860 symtab we don't use it in the name of the psymtabs we create.
10861 E.g. expand_line_sal requires this when finding psymtabs to expand.
10862 A good testcase for this is mb-inline.exp. */
10865 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
10866 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10868 gdb_byte
*line_ptr
, *extended_end
;
10869 gdb_byte
*line_end
;
10870 unsigned int bytes_read
, extended_len
;
10871 unsigned char op_code
, extended_op
, adj_opcode
;
10872 CORE_ADDR baseaddr
;
10873 struct objfile
*objfile
= cu
->objfile
;
10874 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10875 const int decode_for_pst_p
= (pst
!= NULL
);
10876 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10877 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10880 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10882 line_ptr
= lh
->statement_program_start
;
10883 line_end
= lh
->statement_program_end
;
10885 /* Read the statement sequences until there's nothing left. */
10886 while (line_ptr
< line_end
)
10888 /* state machine registers */
10889 CORE_ADDR address
= 0;
10890 unsigned int file
= 1;
10891 unsigned int line
= 1;
10892 unsigned int column
= 0;
10893 int is_stmt
= lh
->default_is_stmt
;
10894 int basic_block
= 0;
10895 int end_sequence
= 0;
10897 unsigned char op_index
= 0;
10899 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10901 /* Start a subfile for the current file of the state machine. */
10902 /* lh->include_dirs and lh->file_names are 0-based, but the
10903 directory and file name numbers in the statement program
10905 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10909 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10911 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10914 /* Decode the table. */
10915 while (!end_sequence
)
10917 op_code
= read_1_byte (abfd
, line_ptr
);
10919 if (line_ptr
> line_end
)
10921 dwarf2_debug_line_missing_end_sequence_complaint ();
10925 if (op_code
>= lh
->opcode_base
)
10927 /* Special operand. */
10928 adj_opcode
= op_code
- lh
->opcode_base
;
10929 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10930 / lh
->maximum_ops_per_instruction
)
10931 * lh
->minimum_instruction_length
);
10932 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10933 % lh
->maximum_ops_per_instruction
);
10934 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10935 if (lh
->num_file_names
< file
|| file
== 0)
10936 dwarf2_debug_line_missing_file_complaint ();
10937 /* For now we ignore lines not starting on an
10938 instruction boundary. */
10939 else if (op_index
== 0)
10941 lh
->file_names
[file
- 1].included_p
= 1;
10942 if (!decode_for_pst_p
&& is_stmt
)
10944 if (last_subfile
!= current_subfile
)
10946 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10948 (*p_record_line
) (last_subfile
, 0, addr
);
10949 last_subfile
= current_subfile
;
10951 /* Append row to matrix using current values. */
10952 addr
= check_cu_functions (address
, cu
);
10953 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10954 (*p_record_line
) (current_subfile
, line
, addr
);
10959 else switch (op_code
)
10961 case DW_LNS_extended_op
:
10962 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
10964 line_ptr
+= bytes_read
;
10965 extended_end
= line_ptr
+ extended_len
;
10966 extended_op
= read_1_byte (abfd
, line_ptr
);
10968 switch (extended_op
)
10970 case DW_LNE_end_sequence
:
10971 p_record_line
= record_line
;
10974 case DW_LNE_set_address
:
10975 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10977 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10979 /* This line table is for a function which has been
10980 GCd by the linker. Ignore it. PR gdb/12528 */
10983 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
10985 complaint (&symfile_complaints
,
10986 _(".debug_line address at offset 0x%lx is 0 "
10988 line_offset
, cu
->objfile
->name
);
10989 p_record_line
= noop_record_line
;
10993 line_ptr
+= bytes_read
;
10994 address
+= baseaddr
;
10996 case DW_LNE_define_file
:
10999 unsigned int dir_index
, mod_time
, length
;
11001 cur_file
= read_direct_string (abfd
, line_ptr
,
11003 line_ptr
+= bytes_read
;
11005 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11006 line_ptr
+= bytes_read
;
11008 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11009 line_ptr
+= bytes_read
;
11011 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11012 line_ptr
+= bytes_read
;
11013 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11016 case DW_LNE_set_discriminator
:
11017 /* The discriminator is not interesting to the debugger;
11019 line_ptr
= extended_end
;
11022 complaint (&symfile_complaints
,
11023 _("mangled .debug_line section"));
11026 /* Make sure that we parsed the extended op correctly. If e.g.
11027 we expected a different address size than the producer used,
11028 we may have read the wrong number of bytes. */
11029 if (line_ptr
!= extended_end
)
11031 complaint (&symfile_complaints
,
11032 _("mangled .debug_line section"));
11037 if (lh
->num_file_names
< file
|| file
== 0)
11038 dwarf2_debug_line_missing_file_complaint ();
11041 lh
->file_names
[file
- 1].included_p
= 1;
11042 if (!decode_for_pst_p
&& is_stmt
)
11044 if (last_subfile
!= current_subfile
)
11046 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11048 (*p_record_line
) (last_subfile
, 0, addr
);
11049 last_subfile
= current_subfile
;
11051 addr
= check_cu_functions (address
, cu
);
11052 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
11053 (*p_record_line
) (current_subfile
, line
, addr
);
11058 case DW_LNS_advance_pc
:
11061 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11063 address
+= (((op_index
+ adjust
)
11064 / lh
->maximum_ops_per_instruction
)
11065 * lh
->minimum_instruction_length
);
11066 op_index
= ((op_index
+ adjust
)
11067 % lh
->maximum_ops_per_instruction
);
11068 line_ptr
+= bytes_read
;
11071 case DW_LNS_advance_line
:
11072 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11073 line_ptr
+= bytes_read
;
11075 case DW_LNS_set_file
:
11077 /* The arrays lh->include_dirs and lh->file_names are
11078 0-based, but the directory and file name numbers in
11079 the statement program are 1-based. */
11080 struct file_entry
*fe
;
11083 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11084 line_ptr
+= bytes_read
;
11085 if (lh
->num_file_names
< file
|| file
== 0)
11086 dwarf2_debug_line_missing_file_complaint ();
11089 fe
= &lh
->file_names
[file
- 1];
11091 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11092 if (!decode_for_pst_p
)
11094 last_subfile
= current_subfile
;
11095 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11100 case DW_LNS_set_column
:
11101 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11102 line_ptr
+= bytes_read
;
11104 case DW_LNS_negate_stmt
:
11105 is_stmt
= (!is_stmt
);
11107 case DW_LNS_set_basic_block
:
11110 /* Add to the address register of the state machine the
11111 address increment value corresponding to special opcode
11112 255. I.e., this value is scaled by the minimum
11113 instruction length since special opcode 255 would have
11114 scaled the increment. */
11115 case DW_LNS_const_add_pc
:
11117 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11119 address
+= (((op_index
+ adjust
)
11120 / lh
->maximum_ops_per_instruction
)
11121 * lh
->minimum_instruction_length
);
11122 op_index
= ((op_index
+ adjust
)
11123 % lh
->maximum_ops_per_instruction
);
11126 case DW_LNS_fixed_advance_pc
:
11127 address
+= read_2_bytes (abfd
, line_ptr
);
11133 /* Unknown standard opcode, ignore it. */
11136 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11138 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11139 line_ptr
+= bytes_read
;
11144 if (lh
->num_file_names
< file
|| file
== 0)
11145 dwarf2_debug_line_missing_file_complaint ();
11148 lh
->file_names
[file
- 1].included_p
= 1;
11149 if (!decode_for_pst_p
)
11151 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11152 (*p_record_line
) (current_subfile
, 0, addr
);
11157 if (decode_for_pst_p
)
11161 /* Now that we're done scanning the Line Header Program, we can
11162 create the psymtab of each included file. */
11163 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11164 if (lh
->file_names
[file_index
].included_p
== 1)
11166 char *include_name
=
11167 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11168 if (include_name
!= NULL
)
11169 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11174 /* Make sure a symtab is created for every file, even files
11175 which contain only variables (i.e. no code with associated
11179 struct file_entry
*fe
;
11181 for (i
= 0; i
< lh
->num_file_names
; i
++)
11185 fe
= &lh
->file_names
[i
];
11187 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11188 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11190 /* Skip the main file; we don't need it, and it must be
11191 allocated last, so that it will show up before the
11192 non-primary symtabs in the objfile's symtab list. */
11193 if (current_subfile
== first_subfile
)
11196 if (current_subfile
->symtab
== NULL
)
11197 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11199 fe
->symtab
= current_subfile
->symtab
;
11204 /* Start a subfile for DWARF. FILENAME is the name of the file and
11205 DIRNAME the name of the source directory which contains FILENAME
11206 or NULL if not known. COMP_DIR is the compilation directory for the
11207 linetable's compilation unit or NULL if not known.
11208 This routine tries to keep line numbers from identical absolute and
11209 relative file names in a common subfile.
11211 Using the `list' example from the GDB testsuite, which resides in
11212 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11213 of /srcdir/list0.c yields the following debugging information for list0.c:
11215 DW_AT_name: /srcdir/list0.c
11216 DW_AT_comp_dir: /compdir
11217 files.files[0].name: list0.h
11218 files.files[0].dir: /srcdir
11219 files.files[1].name: list0.c
11220 files.files[1].dir: /srcdir
11222 The line number information for list0.c has to end up in a single
11223 subfile, so that `break /srcdir/list0.c:1' works as expected.
11224 start_subfile will ensure that this happens provided that we pass the
11225 concatenation of files.files[1].dir and files.files[1].name as the
11229 dwarf2_start_subfile (char *filename
, const char *dirname
,
11230 const char *comp_dir
)
11234 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11235 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11236 second argument to start_subfile. To be consistent, we do the
11237 same here. In order not to lose the line information directory,
11238 we concatenate it to the filename when it makes sense.
11239 Note that the Dwarf3 standard says (speaking of filenames in line
11240 information): ``The directory index is ignored for file names
11241 that represent full path names''. Thus ignoring dirname in the
11242 `else' branch below isn't an issue. */
11244 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11245 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11247 fullname
= filename
;
11249 start_subfile (fullname
, comp_dir
);
11251 if (fullname
!= filename
)
11256 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11257 struct dwarf2_cu
*cu
)
11259 struct objfile
*objfile
= cu
->objfile
;
11260 struct comp_unit_head
*cu_header
= &cu
->header
;
11262 /* NOTE drow/2003-01-30: There used to be a comment and some special
11263 code here to turn a symbol with DW_AT_external and a
11264 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11265 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11266 with some versions of binutils) where shared libraries could have
11267 relocations against symbols in their debug information - the
11268 minimal symbol would have the right address, but the debug info
11269 would not. It's no longer necessary, because we will explicitly
11270 apply relocations when we read in the debug information now. */
11272 /* A DW_AT_location attribute with no contents indicates that a
11273 variable has been optimized away. */
11274 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11276 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11280 /* Handle one degenerate form of location expression specially, to
11281 preserve GDB's previous behavior when section offsets are
11282 specified. If this is just a DW_OP_addr then mark this symbol
11285 if (attr_form_is_block (attr
)
11286 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11287 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11289 unsigned int dummy
;
11291 SYMBOL_VALUE_ADDRESS (sym
) =
11292 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11293 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11294 fixup_symbol_section (sym
, objfile
);
11295 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11296 SYMBOL_SECTION (sym
));
11300 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11301 expression evaluator, and use LOC_COMPUTED only when necessary
11302 (i.e. when the value of a register or memory location is
11303 referenced, or a thread-local block, etc.). Then again, it might
11304 not be worthwhile. I'm assuming that it isn't unless performance
11305 or memory numbers show me otherwise. */
11307 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11308 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11310 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11311 cu
->has_loclist
= 1;
11314 /* Given a pointer to a DWARF information entry, figure out if we need
11315 to make a symbol table entry for it, and if so, create a new entry
11316 and return a pointer to it.
11317 If TYPE is NULL, determine symbol type from the die, otherwise
11318 used the passed type.
11319 If SPACE is not NULL, use it to hold the new symbol. If it is
11320 NULL, allocate a new symbol on the objfile's obstack. */
11322 static struct symbol
*
11323 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11324 struct symbol
*space
)
11326 struct objfile
*objfile
= cu
->objfile
;
11327 struct symbol
*sym
= NULL
;
11329 struct attribute
*attr
= NULL
;
11330 struct attribute
*attr2
= NULL
;
11331 CORE_ADDR baseaddr
;
11332 struct pending
**list_to_add
= NULL
;
11334 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11336 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11338 name
= dwarf2_name (die
, cu
);
11341 const char *linkagename
;
11342 int suppress_add
= 0;
11347 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11348 OBJSTAT (objfile
, n_syms
++);
11350 /* Cache this symbol's name and the name's demangled form (if any). */
11351 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11352 linkagename
= dwarf2_physname (name
, die
, cu
);
11353 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11355 /* Fortran does not have mangling standard and the mangling does differ
11356 between gfortran, iFort etc. */
11357 if (cu
->language
== language_fortran
11358 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11359 symbol_set_demangled_name (&(sym
->ginfo
),
11360 (char *) dwarf2_full_name (name
, die
, cu
),
11363 /* Default assumptions.
11364 Use the passed type or decode it from the die. */
11365 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11366 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11368 SYMBOL_TYPE (sym
) = type
;
11370 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11371 attr
= dwarf2_attr (die
,
11372 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11376 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11379 attr
= dwarf2_attr (die
,
11380 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11384 int file_index
= DW_UNSND (attr
);
11386 if (cu
->line_header
== NULL
11387 || file_index
> cu
->line_header
->num_file_names
)
11388 complaint (&symfile_complaints
,
11389 _("file index out of range"));
11390 else if (file_index
> 0)
11392 struct file_entry
*fe
;
11394 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11395 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11402 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11405 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11407 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11408 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11409 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11410 add_symbol_to_list (sym
, cu
->list_in_scope
);
11412 case DW_TAG_subprogram
:
11413 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11415 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11416 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11417 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11418 || cu
->language
== language_ada
)
11420 /* Subprograms marked external are stored as a global symbol.
11421 Ada subprograms, whether marked external or not, are always
11422 stored as a global symbol, because we want to be able to
11423 access them globally. For instance, we want to be able
11424 to break on a nested subprogram without having to
11425 specify the context. */
11426 list_to_add
= &global_symbols
;
11430 list_to_add
= cu
->list_in_scope
;
11433 case DW_TAG_inlined_subroutine
:
11434 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11436 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11437 SYMBOL_INLINED (sym
) = 1;
11438 /* Do not add the symbol to any lists. It will be found via
11439 BLOCK_FUNCTION from the blockvector. */
11441 case DW_TAG_template_value_param
:
11443 /* Fall through. */
11444 case DW_TAG_constant
:
11445 case DW_TAG_variable
:
11446 case DW_TAG_member
:
11447 /* Compilation with minimal debug info may result in
11448 variables with missing type entries. Change the
11449 misleading `void' type to something sensible. */
11450 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11452 = objfile_type (objfile
)->nodebug_data_symbol
;
11454 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11455 /* In the case of DW_TAG_member, we should only be called for
11456 static const members. */
11457 if (die
->tag
== DW_TAG_member
)
11459 /* dwarf2_add_field uses die_is_declaration,
11460 so we do the same. */
11461 gdb_assert (die_is_declaration (die
, cu
));
11466 dwarf2_const_value (attr
, sym
, cu
);
11467 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11470 if (attr2
&& (DW_UNSND (attr2
) != 0))
11471 list_to_add
= &global_symbols
;
11473 list_to_add
= cu
->list_in_scope
;
11477 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11480 var_decode_location (attr
, sym
, cu
);
11481 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11482 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11483 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11484 && !dwarf2_per_objfile
->has_section_at_zero
)
11486 /* When a static variable is eliminated by the linker,
11487 the corresponding debug information is not stripped
11488 out, but the variable address is set to null;
11489 do not add such variables into symbol table. */
11491 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11493 /* Workaround gfortran PR debug/40040 - it uses
11494 DW_AT_location for variables in -fPIC libraries which may
11495 get overriden by other libraries/executable and get
11496 a different address. Resolve it by the minimal symbol
11497 which may come from inferior's executable using copy
11498 relocation. Make this workaround only for gfortran as for
11499 other compilers GDB cannot guess the minimal symbol
11500 Fortran mangling kind. */
11501 if (cu
->language
== language_fortran
&& die
->parent
11502 && die
->parent
->tag
== DW_TAG_module
11504 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11505 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11507 /* A variable with DW_AT_external is never static,
11508 but it may be block-scoped. */
11509 list_to_add
= (cu
->list_in_scope
== &file_symbols
11510 ? &global_symbols
: cu
->list_in_scope
);
11513 list_to_add
= cu
->list_in_scope
;
11517 /* We do not know the address of this symbol.
11518 If it is an external symbol and we have type information
11519 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11520 The address of the variable will then be determined from
11521 the minimal symbol table whenever the variable is
11523 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11524 if (attr2
&& (DW_UNSND (attr2
) != 0)
11525 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11527 /* A variable with DW_AT_external is never static, but it
11528 may be block-scoped. */
11529 list_to_add
= (cu
->list_in_scope
== &file_symbols
11530 ? &global_symbols
: cu
->list_in_scope
);
11532 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11534 else if (!die_is_declaration (die
, cu
))
11536 /* Use the default LOC_OPTIMIZED_OUT class. */
11537 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11539 list_to_add
= cu
->list_in_scope
;
11543 case DW_TAG_formal_parameter
:
11544 /* If we are inside a function, mark this as an argument. If
11545 not, we might be looking at an argument to an inlined function
11546 when we do not have enough information to show inlined frames;
11547 pretend it's a local variable in that case so that the user can
11549 if (context_stack_depth
> 0
11550 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11551 SYMBOL_IS_ARGUMENT (sym
) = 1;
11552 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11555 var_decode_location (attr
, sym
, cu
);
11557 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11560 dwarf2_const_value (attr
, sym
, cu
);
11563 list_to_add
= cu
->list_in_scope
;
11565 case DW_TAG_unspecified_parameters
:
11566 /* From varargs functions; gdb doesn't seem to have any
11567 interest in this information, so just ignore it for now.
11570 case DW_TAG_template_type_param
:
11572 /* Fall through. */
11573 case DW_TAG_class_type
:
11574 case DW_TAG_interface_type
:
11575 case DW_TAG_structure_type
:
11576 case DW_TAG_union_type
:
11577 case DW_TAG_set_type
:
11578 case DW_TAG_enumeration_type
:
11579 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11580 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11583 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11584 really ever be static objects: otherwise, if you try
11585 to, say, break of a class's method and you're in a file
11586 which doesn't mention that class, it won't work unless
11587 the check for all static symbols in lookup_symbol_aux
11588 saves you. See the OtherFileClass tests in
11589 gdb.c++/namespace.exp. */
11593 list_to_add
= (cu
->list_in_scope
== &file_symbols
11594 && (cu
->language
== language_cplus
11595 || cu
->language
== language_java
)
11596 ? &global_symbols
: cu
->list_in_scope
);
11598 /* The semantics of C++ state that "struct foo {
11599 ... }" also defines a typedef for "foo". A Java
11600 class declaration also defines a typedef for the
11602 if (cu
->language
== language_cplus
11603 || cu
->language
== language_java
11604 || cu
->language
== language_ada
)
11606 /* The symbol's name is already allocated along
11607 with this objfile, so we don't need to
11608 duplicate it for the type. */
11609 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11610 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11615 case DW_TAG_typedef
:
11616 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11617 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11618 list_to_add
= cu
->list_in_scope
;
11620 case DW_TAG_base_type
:
11621 case DW_TAG_subrange_type
:
11622 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11623 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11624 list_to_add
= cu
->list_in_scope
;
11626 case DW_TAG_enumerator
:
11627 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11630 dwarf2_const_value (attr
, sym
, cu
);
11633 /* NOTE: carlton/2003-11-10: See comment above in the
11634 DW_TAG_class_type, etc. block. */
11636 list_to_add
= (cu
->list_in_scope
== &file_symbols
11637 && (cu
->language
== language_cplus
11638 || cu
->language
== language_java
)
11639 ? &global_symbols
: cu
->list_in_scope
);
11642 case DW_TAG_namespace
:
11643 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11644 list_to_add
= &global_symbols
;
11647 /* Not a tag we recognize. Hopefully we aren't processing
11648 trash data, but since we must specifically ignore things
11649 we don't recognize, there is nothing else we should do at
11651 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11652 dwarf_tag_name (die
->tag
));
11658 sym
->hash_next
= objfile
->template_symbols
;
11659 objfile
->template_symbols
= sym
;
11660 list_to_add
= NULL
;
11663 if (list_to_add
!= NULL
)
11664 add_symbol_to_list (sym
, list_to_add
);
11666 /* For the benefit of old versions of GCC, check for anonymous
11667 namespaces based on the demangled name. */
11668 if (!processing_has_namespace_info
11669 && cu
->language
== language_cplus
)
11670 cp_scan_for_anonymous_namespaces (sym
);
11675 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11677 static struct symbol
*
11678 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11680 return new_symbol_full (die
, type
, cu
, NULL
);
11683 /* Given an attr with a DW_FORM_dataN value in host byte order,
11684 zero-extend it as appropriate for the symbol's type. The DWARF
11685 standard (v4) is not entirely clear about the meaning of using
11686 DW_FORM_dataN for a constant with a signed type, where the type is
11687 wider than the data. The conclusion of a discussion on the DWARF
11688 list was that this is unspecified. We choose to always zero-extend
11689 because that is the interpretation long in use by GCC. */
11692 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11693 const char *name
, struct obstack
*obstack
,
11694 struct dwarf2_cu
*cu
, long *value
, int bits
)
11696 struct objfile
*objfile
= cu
->objfile
;
11697 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11698 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11699 LONGEST l
= DW_UNSND (attr
);
11701 if (bits
< sizeof (*value
) * 8)
11703 l
&= ((LONGEST
) 1 << bits
) - 1;
11706 else if (bits
== sizeof (*value
) * 8)
11710 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11711 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11718 /* Read a constant value from an attribute. Either set *VALUE, or if
11719 the value does not fit in *VALUE, set *BYTES - either already
11720 allocated on the objfile obstack, or newly allocated on OBSTACK,
11721 or, set *BATON, if we translated the constant to a location
11725 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11726 const char *name
, struct obstack
*obstack
,
11727 struct dwarf2_cu
*cu
,
11728 long *value
, gdb_byte
**bytes
,
11729 struct dwarf2_locexpr_baton
**baton
)
11731 struct objfile
*objfile
= cu
->objfile
;
11732 struct comp_unit_head
*cu_header
= &cu
->header
;
11733 struct dwarf_block
*blk
;
11734 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
11735 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
11741 switch (attr
->form
)
11747 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
11748 dwarf2_const_value_length_mismatch_complaint (name
,
11749 cu_header
->addr_size
,
11750 TYPE_LENGTH (type
));
11751 /* Symbols of this form are reasonably rare, so we just
11752 piggyback on the existing location code rather than writing
11753 a new implementation of symbol_computed_ops. */
11754 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11755 sizeof (struct dwarf2_locexpr_baton
));
11756 (*baton
)->per_cu
= cu
->per_cu
;
11757 gdb_assert ((*baton
)->per_cu
);
11759 (*baton
)->size
= 2 + cu_header
->addr_size
;
11760 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11761 (*baton
)->data
= data
;
11763 data
[0] = DW_OP_addr
;
11764 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11765 byte_order
, DW_ADDR (attr
));
11766 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11769 case DW_FORM_string
:
11771 /* DW_STRING is already allocated on the objfile obstack, point
11773 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11775 case DW_FORM_block1
:
11776 case DW_FORM_block2
:
11777 case DW_FORM_block4
:
11778 case DW_FORM_block
:
11779 case DW_FORM_exprloc
:
11780 blk
= DW_BLOCK (attr
);
11781 if (TYPE_LENGTH (type
) != blk
->size
)
11782 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11783 TYPE_LENGTH (type
));
11784 *bytes
= blk
->data
;
11787 /* The DW_AT_const_value attributes are supposed to carry the
11788 symbol's value "represented as it would be on the target
11789 architecture." By the time we get here, it's already been
11790 converted to host endianness, so we just need to sign- or
11791 zero-extend it as appropriate. */
11792 case DW_FORM_data1
:
11793 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11794 obstack
, cu
, value
, 8);
11796 case DW_FORM_data2
:
11797 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11798 obstack
, cu
, value
, 16);
11800 case DW_FORM_data4
:
11801 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11802 obstack
, cu
, value
, 32);
11804 case DW_FORM_data8
:
11805 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11806 obstack
, cu
, value
, 64);
11809 case DW_FORM_sdata
:
11810 *value
= DW_SND (attr
);
11813 case DW_FORM_udata
:
11814 *value
= DW_UNSND (attr
);
11818 complaint (&symfile_complaints
,
11819 _("unsupported const value attribute form: '%s'"),
11820 dwarf_form_name (attr
->form
));
11827 /* Copy constant value from an attribute to a symbol. */
11830 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11831 struct dwarf2_cu
*cu
)
11833 struct objfile
*objfile
= cu
->objfile
;
11834 struct comp_unit_head
*cu_header
= &cu
->header
;
11837 struct dwarf2_locexpr_baton
*baton
;
11839 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11840 SYMBOL_PRINT_NAME (sym
),
11841 &objfile
->objfile_obstack
, cu
,
11842 &value
, &bytes
, &baton
);
11846 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11847 SYMBOL_LOCATION_BATON (sym
) = baton
;
11848 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11850 else if (bytes
!= NULL
)
11852 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11853 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11857 SYMBOL_VALUE (sym
) = value
;
11858 SYMBOL_CLASS (sym
) = LOC_CONST
;
11862 /* Return the type of the die in question using its DW_AT_type attribute. */
11864 static struct type
*
11865 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11867 struct attribute
*type_attr
;
11869 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11872 /* A missing DW_AT_type represents a void type. */
11873 return objfile_type (cu
->objfile
)->builtin_void
;
11876 return lookup_die_type (die
, type_attr
, cu
);
11879 /* True iff CU's producer generates GNAT Ada auxiliary information
11880 that allows to find parallel types through that information instead
11881 of having to do expensive parallel lookups by type name. */
11884 need_gnat_info (struct dwarf2_cu
*cu
)
11886 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11887 of GNAT produces this auxiliary information, without any indication
11888 that it is produced. Part of enhancing the FSF version of GNAT
11889 to produce that information will be to put in place an indicator
11890 that we can use in order to determine whether the descriptive type
11891 info is available or not. One suggestion that has been made is
11892 to use a new attribute, attached to the CU die. For now, assume
11893 that the descriptive type info is not available. */
11897 /* Return the auxiliary type of the die in question using its
11898 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11899 attribute is not present. */
11901 static struct type
*
11902 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11904 struct attribute
*type_attr
;
11906 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11910 return lookup_die_type (die
, type_attr
, cu
);
11913 /* If DIE has a descriptive_type attribute, then set the TYPE's
11914 descriptive type accordingly. */
11917 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11918 struct dwarf2_cu
*cu
)
11920 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11922 if (descriptive_type
)
11924 ALLOCATE_GNAT_AUX_TYPE (type
);
11925 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11929 /* Return the containing type of the die in question using its
11930 DW_AT_containing_type attribute. */
11932 static struct type
*
11933 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11935 struct attribute
*type_attr
;
11937 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11939 error (_("Dwarf Error: Problem turning containing type into gdb type "
11940 "[in module %s]"), cu
->objfile
->name
);
11942 return lookup_die_type (die
, type_attr
, cu
);
11945 /* Look up the type of DIE in CU using its type attribute ATTR.
11946 If there is no type substitute an error marker. */
11948 static struct type
*
11949 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11950 struct dwarf2_cu
*cu
)
11952 struct type
*this_type
;
11954 /* First see if we have it cached. */
11956 if (is_ref_attr (attr
))
11958 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11960 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11962 else if (attr
->form
== DW_FORM_ref_sig8
)
11964 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11965 struct dwarf2_cu
*sig_cu
;
11966 unsigned int offset
;
11968 /* sig_type will be NULL if the signatured type is missing from
11970 if (sig_type
== NULL
)
11971 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11972 "at 0x%x [in module %s]"),
11973 die
->offset
, cu
->objfile
->name
);
11975 gdb_assert (sig_type
->per_cu
.debug_type_section
);
11976 offset
= sig_type
->per_cu
.offset
+ sig_type
->type_offset
;
11977 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11981 dump_die_for_error (die
);
11982 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11983 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11986 /* If not cached we need to read it in. */
11988 if (this_type
== NULL
)
11990 struct die_info
*type_die
;
11991 struct dwarf2_cu
*type_cu
= cu
;
11993 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11994 /* If the type is cached, we should have found it above. */
11995 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
11996 this_type
= read_type_die_1 (type_die
, type_cu
);
11999 /* If we still don't have a type use an error marker. */
12001 if (this_type
== NULL
)
12003 char *message
, *saved
;
12005 /* read_type_die already issued a complaint. */
12006 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12010 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
12011 message
, strlen (message
));
12014 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
12020 /* Return the type in DIE, CU.
12021 Returns NULL for invalid types.
12023 This first does a lookup in the appropriate type_hash table,
12024 and only reads the die in if necessary.
12026 NOTE: This can be called when reading in partial or full symbols. */
12028 static struct type
*
12029 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12031 struct type
*this_type
;
12033 this_type
= get_die_type (die
, cu
);
12037 return read_type_die_1 (die
, cu
);
12040 /* Read the type in DIE, CU.
12041 Returns NULL for invalid types. */
12043 static struct type
*
12044 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12046 struct type
*this_type
= NULL
;
12050 case DW_TAG_class_type
:
12051 case DW_TAG_interface_type
:
12052 case DW_TAG_structure_type
:
12053 case DW_TAG_union_type
:
12054 this_type
= read_structure_type (die
, cu
);
12056 case DW_TAG_enumeration_type
:
12057 this_type
= read_enumeration_type (die
, cu
);
12059 case DW_TAG_subprogram
:
12060 case DW_TAG_subroutine_type
:
12061 case DW_TAG_inlined_subroutine
:
12062 this_type
= read_subroutine_type (die
, cu
);
12064 case DW_TAG_array_type
:
12065 this_type
= read_array_type (die
, cu
);
12067 case DW_TAG_set_type
:
12068 this_type
= read_set_type (die
, cu
);
12070 case DW_TAG_pointer_type
:
12071 this_type
= read_tag_pointer_type (die
, cu
);
12073 case DW_TAG_ptr_to_member_type
:
12074 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12076 case DW_TAG_reference_type
:
12077 this_type
= read_tag_reference_type (die
, cu
);
12079 case DW_TAG_const_type
:
12080 this_type
= read_tag_const_type (die
, cu
);
12082 case DW_TAG_volatile_type
:
12083 this_type
= read_tag_volatile_type (die
, cu
);
12085 case DW_TAG_string_type
:
12086 this_type
= read_tag_string_type (die
, cu
);
12088 case DW_TAG_typedef
:
12089 this_type
= read_typedef (die
, cu
);
12091 case DW_TAG_subrange_type
:
12092 this_type
= read_subrange_type (die
, cu
);
12094 case DW_TAG_base_type
:
12095 this_type
= read_base_type (die
, cu
);
12097 case DW_TAG_unspecified_type
:
12098 this_type
= read_unspecified_type (die
, cu
);
12100 case DW_TAG_namespace
:
12101 this_type
= read_namespace_type (die
, cu
);
12103 case DW_TAG_module
:
12104 this_type
= read_module_type (die
, cu
);
12107 complaint (&symfile_complaints
,
12108 _("unexpected tag in read_type_die: '%s'"),
12109 dwarf_tag_name (die
->tag
));
12116 /* See if we can figure out if the class lives in a namespace. We do
12117 this by looking for a member function; its demangled name will
12118 contain namespace info, if there is any.
12119 Return the computed name or NULL.
12120 Space for the result is allocated on the objfile's obstack.
12121 This is the full-die version of guess_partial_die_structure_name.
12122 In this case we know DIE has no useful parent. */
12125 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12127 struct die_info
*spec_die
;
12128 struct dwarf2_cu
*spec_cu
;
12129 struct die_info
*child
;
12132 spec_die
= die_specification (die
, &spec_cu
);
12133 if (spec_die
!= NULL
)
12139 for (child
= die
->child
;
12141 child
= child
->sibling
)
12143 if (child
->tag
== DW_TAG_subprogram
)
12145 struct attribute
*attr
;
12147 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12149 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12153 = language_class_name_from_physname (cu
->language_defn
,
12157 if (actual_name
!= NULL
)
12159 char *die_name
= dwarf2_name (die
, cu
);
12161 if (die_name
!= NULL
12162 && strcmp (die_name
, actual_name
) != 0)
12164 /* Strip off the class name from the full name.
12165 We want the prefix. */
12166 int die_name_len
= strlen (die_name
);
12167 int actual_name_len
= strlen (actual_name
);
12169 /* Test for '::' as a sanity check. */
12170 if (actual_name_len
> die_name_len
+ 2
12171 && actual_name
[actual_name_len
12172 - die_name_len
- 1] == ':')
12174 obsavestring (actual_name
,
12175 actual_name_len
- die_name_len
- 2,
12176 &cu
->objfile
->objfile_obstack
);
12179 xfree (actual_name
);
12188 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12189 prefix part in such case. See
12190 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12193 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12195 struct attribute
*attr
;
12198 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
12199 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
12202 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12203 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
12206 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12208 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12209 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12212 /* dwarf2_name had to be already called. */
12213 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
12215 /* Strip the base name, keep any leading namespaces/classes. */
12216 base
= strrchr (DW_STRING (attr
), ':');
12217 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
12220 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
12221 &cu
->objfile
->objfile_obstack
);
12224 /* Return the name of the namespace/class that DIE is defined within,
12225 or "" if we can't tell. The caller should not xfree the result.
12227 For example, if we're within the method foo() in the following
12237 then determine_prefix on foo's die will return "N::C". */
12240 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12242 struct die_info
*parent
, *spec_die
;
12243 struct dwarf2_cu
*spec_cu
;
12244 struct type
*parent_type
;
12247 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12248 && cu
->language
!= language_fortran
)
12251 retval
= anonymous_struct_prefix (die
, cu
);
12255 /* We have to be careful in the presence of DW_AT_specification.
12256 For example, with GCC 3.4, given the code
12260 // Definition of N::foo.
12264 then we'll have a tree of DIEs like this:
12266 1: DW_TAG_compile_unit
12267 2: DW_TAG_namespace // N
12268 3: DW_TAG_subprogram // declaration of N::foo
12269 4: DW_TAG_subprogram // definition of N::foo
12270 DW_AT_specification // refers to die #3
12272 Thus, when processing die #4, we have to pretend that we're in
12273 the context of its DW_AT_specification, namely the contex of die
12276 spec_die
= die_specification (die
, &spec_cu
);
12277 if (spec_die
== NULL
)
12278 parent
= die
->parent
;
12281 parent
= spec_die
->parent
;
12285 if (parent
== NULL
)
12287 else if (parent
->building_fullname
)
12290 const char *parent_name
;
12292 /* It has been seen on RealView 2.2 built binaries,
12293 DW_TAG_template_type_param types actually _defined_ as
12294 children of the parent class:
12297 template class <class Enum> Class{};
12298 Class<enum E> class_e;
12300 1: DW_TAG_class_type (Class)
12301 2: DW_TAG_enumeration_type (E)
12302 3: DW_TAG_enumerator (enum1:0)
12303 3: DW_TAG_enumerator (enum2:1)
12305 2: DW_TAG_template_type_param
12306 DW_AT_type DW_FORM_ref_udata (E)
12308 Besides being broken debug info, it can put GDB into an
12309 infinite loop. Consider:
12311 When we're building the full name for Class<E>, we'll start
12312 at Class, and go look over its template type parameters,
12313 finding E. We'll then try to build the full name of E, and
12314 reach here. We're now trying to build the full name of E,
12315 and look over the parent DIE for containing scope. In the
12316 broken case, if we followed the parent DIE of E, we'd again
12317 find Class, and once again go look at its template type
12318 arguments, etc., etc. Simply don't consider such parent die
12319 as source-level parent of this die (it can't be, the language
12320 doesn't allow it), and break the loop here. */
12321 name
= dwarf2_name (die
, cu
);
12322 parent_name
= dwarf2_name (parent
, cu
);
12323 complaint (&symfile_complaints
,
12324 _("template param type '%s' defined within parent '%s'"),
12325 name
? name
: "<unknown>",
12326 parent_name
? parent_name
: "<unknown>");
12330 switch (parent
->tag
)
12332 case DW_TAG_namespace
:
12333 parent_type
= read_type_die (parent
, cu
);
12334 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12335 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12336 Work around this problem here. */
12337 if (cu
->language
== language_cplus
12338 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12340 /* We give a name to even anonymous namespaces. */
12341 return TYPE_TAG_NAME (parent_type
);
12342 case DW_TAG_class_type
:
12343 case DW_TAG_interface_type
:
12344 case DW_TAG_structure_type
:
12345 case DW_TAG_union_type
:
12346 case DW_TAG_module
:
12347 parent_type
= read_type_die (parent
, cu
);
12348 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12349 return TYPE_TAG_NAME (parent_type
);
12351 /* An anonymous structure is only allowed non-static data
12352 members; no typedefs, no member functions, et cetera.
12353 So it does not need a prefix. */
12355 case DW_TAG_compile_unit
:
12356 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12357 if (cu
->language
== language_cplus
12358 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12359 && die
->child
!= NULL
12360 && (die
->tag
== DW_TAG_class_type
12361 || die
->tag
== DW_TAG_structure_type
12362 || die
->tag
== DW_TAG_union_type
))
12364 char *name
= guess_full_die_structure_name (die
, cu
);
12370 return determine_prefix (parent
, cu
);
12374 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12375 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12376 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12377 an obconcat, otherwise allocate storage for the result. The CU argument is
12378 used to determine the language and hence, the appropriate separator. */
12380 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12383 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12384 int physname
, struct dwarf2_cu
*cu
)
12386 const char *lead
= "";
12389 if (suffix
== NULL
|| suffix
[0] == '\0'
12390 || prefix
== NULL
|| prefix
[0] == '\0')
12392 else if (cu
->language
== language_java
)
12394 else if (cu
->language
== language_fortran
&& physname
)
12396 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12397 DW_AT_MIPS_linkage_name is preferred and used instead. */
12405 if (prefix
== NULL
)
12407 if (suffix
== NULL
)
12413 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12415 strcpy (retval
, lead
);
12416 strcat (retval
, prefix
);
12417 strcat (retval
, sep
);
12418 strcat (retval
, suffix
);
12423 /* We have an obstack. */
12424 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12428 /* Return sibling of die, NULL if no sibling. */
12430 static struct die_info
*
12431 sibling_die (struct die_info
*die
)
12433 return die
->sibling
;
12436 /* Get name of a die, return NULL if not found. */
12439 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12440 struct obstack
*obstack
)
12442 if (name
&& cu
->language
== language_cplus
)
12444 char *canon_name
= cp_canonicalize_string (name
);
12446 if (canon_name
!= NULL
)
12448 if (strcmp (canon_name
, name
) != 0)
12449 name
= obsavestring (canon_name
, strlen (canon_name
),
12451 xfree (canon_name
);
12458 /* Get name of a die, return NULL if not found. */
12461 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12463 struct attribute
*attr
;
12465 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12466 if ((!attr
|| !DW_STRING (attr
))
12467 && die
->tag
!= DW_TAG_class_type
12468 && die
->tag
!= DW_TAG_interface_type
12469 && die
->tag
!= DW_TAG_structure_type
12470 && die
->tag
!= DW_TAG_union_type
)
12475 case DW_TAG_compile_unit
:
12476 /* Compilation units have a DW_AT_name that is a filename, not
12477 a source language identifier. */
12478 case DW_TAG_enumeration_type
:
12479 case DW_TAG_enumerator
:
12480 /* These tags always have simple identifiers already; no need
12481 to canonicalize them. */
12482 return DW_STRING (attr
);
12484 case DW_TAG_subprogram
:
12485 /* Java constructors will all be named "<init>", so return
12486 the class name when we see this special case. */
12487 if (cu
->language
== language_java
12488 && DW_STRING (attr
) != NULL
12489 && strcmp (DW_STRING (attr
), "<init>") == 0)
12491 struct dwarf2_cu
*spec_cu
= cu
;
12492 struct die_info
*spec_die
;
12494 /* GCJ will output '<init>' for Java constructor names.
12495 For this special case, return the name of the parent class. */
12497 /* GCJ may output suprogram DIEs with AT_specification set.
12498 If so, use the name of the specified DIE. */
12499 spec_die
= die_specification (die
, &spec_cu
);
12500 if (spec_die
!= NULL
)
12501 return dwarf2_name (spec_die
, spec_cu
);
12506 if (die
->tag
== DW_TAG_class_type
)
12507 return dwarf2_name (die
, cu
);
12509 while (die
->tag
!= DW_TAG_compile_unit
);
12513 case DW_TAG_class_type
:
12514 case DW_TAG_interface_type
:
12515 case DW_TAG_structure_type
:
12516 case DW_TAG_union_type
:
12517 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12518 structures or unions. These were of the form "._%d" in GCC 4.1,
12519 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12520 and GCC 4.4. We work around this problem by ignoring these. */
12521 if (attr
&& DW_STRING (attr
)
12522 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12523 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12526 /* GCC might emit a nameless typedef that has a linkage name. See
12527 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12528 if (!attr
|| DW_STRING (attr
) == NULL
)
12530 char *demangled
= NULL
;
12532 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12534 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12536 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12539 /* Avoid demangling DW_STRING (attr) the second time on a second
12540 call for the same DIE. */
12541 if (!DW_STRING_IS_CANONICAL (attr
))
12542 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12548 /* FIXME: we already did this for the partial symbol... */
12549 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
12550 &cu
->objfile
->objfile_obstack
);
12551 DW_STRING_IS_CANONICAL (attr
) = 1;
12554 /* Strip any leading namespaces/classes, keep only the base name.
12555 DW_AT_name for named DIEs does not contain the prefixes. */
12556 base
= strrchr (DW_STRING (attr
), ':');
12557 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
12560 return DW_STRING (attr
);
12569 if (!DW_STRING_IS_CANONICAL (attr
))
12572 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12573 &cu
->objfile
->objfile_obstack
);
12574 DW_STRING_IS_CANONICAL (attr
) = 1;
12576 return DW_STRING (attr
);
12579 /* Return the die that this die in an extension of, or NULL if there
12580 is none. *EXT_CU is the CU containing DIE on input, and the CU
12581 containing the return value on output. */
12583 static struct die_info
*
12584 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12586 struct attribute
*attr
;
12588 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12592 return follow_die_ref (die
, attr
, ext_cu
);
12595 /* Convert a DIE tag into its string name. */
12598 dwarf_tag_name (unsigned tag
)
12602 case DW_TAG_padding
:
12603 return "DW_TAG_padding";
12604 case DW_TAG_array_type
:
12605 return "DW_TAG_array_type";
12606 case DW_TAG_class_type
:
12607 return "DW_TAG_class_type";
12608 case DW_TAG_entry_point
:
12609 return "DW_TAG_entry_point";
12610 case DW_TAG_enumeration_type
:
12611 return "DW_TAG_enumeration_type";
12612 case DW_TAG_formal_parameter
:
12613 return "DW_TAG_formal_parameter";
12614 case DW_TAG_imported_declaration
:
12615 return "DW_TAG_imported_declaration";
12617 return "DW_TAG_label";
12618 case DW_TAG_lexical_block
:
12619 return "DW_TAG_lexical_block";
12620 case DW_TAG_member
:
12621 return "DW_TAG_member";
12622 case DW_TAG_pointer_type
:
12623 return "DW_TAG_pointer_type";
12624 case DW_TAG_reference_type
:
12625 return "DW_TAG_reference_type";
12626 case DW_TAG_compile_unit
:
12627 return "DW_TAG_compile_unit";
12628 case DW_TAG_string_type
:
12629 return "DW_TAG_string_type";
12630 case DW_TAG_structure_type
:
12631 return "DW_TAG_structure_type";
12632 case DW_TAG_subroutine_type
:
12633 return "DW_TAG_subroutine_type";
12634 case DW_TAG_typedef
:
12635 return "DW_TAG_typedef";
12636 case DW_TAG_union_type
:
12637 return "DW_TAG_union_type";
12638 case DW_TAG_unspecified_parameters
:
12639 return "DW_TAG_unspecified_parameters";
12640 case DW_TAG_variant
:
12641 return "DW_TAG_variant";
12642 case DW_TAG_common_block
:
12643 return "DW_TAG_common_block";
12644 case DW_TAG_common_inclusion
:
12645 return "DW_TAG_common_inclusion";
12646 case DW_TAG_inheritance
:
12647 return "DW_TAG_inheritance";
12648 case DW_TAG_inlined_subroutine
:
12649 return "DW_TAG_inlined_subroutine";
12650 case DW_TAG_module
:
12651 return "DW_TAG_module";
12652 case DW_TAG_ptr_to_member_type
:
12653 return "DW_TAG_ptr_to_member_type";
12654 case DW_TAG_set_type
:
12655 return "DW_TAG_set_type";
12656 case DW_TAG_subrange_type
:
12657 return "DW_TAG_subrange_type";
12658 case DW_TAG_with_stmt
:
12659 return "DW_TAG_with_stmt";
12660 case DW_TAG_access_declaration
:
12661 return "DW_TAG_access_declaration";
12662 case DW_TAG_base_type
:
12663 return "DW_TAG_base_type";
12664 case DW_TAG_catch_block
:
12665 return "DW_TAG_catch_block";
12666 case DW_TAG_const_type
:
12667 return "DW_TAG_const_type";
12668 case DW_TAG_constant
:
12669 return "DW_TAG_constant";
12670 case DW_TAG_enumerator
:
12671 return "DW_TAG_enumerator";
12672 case DW_TAG_file_type
:
12673 return "DW_TAG_file_type";
12674 case DW_TAG_friend
:
12675 return "DW_TAG_friend";
12676 case DW_TAG_namelist
:
12677 return "DW_TAG_namelist";
12678 case DW_TAG_namelist_item
:
12679 return "DW_TAG_namelist_item";
12680 case DW_TAG_packed_type
:
12681 return "DW_TAG_packed_type";
12682 case DW_TAG_subprogram
:
12683 return "DW_TAG_subprogram";
12684 case DW_TAG_template_type_param
:
12685 return "DW_TAG_template_type_param";
12686 case DW_TAG_template_value_param
:
12687 return "DW_TAG_template_value_param";
12688 case DW_TAG_thrown_type
:
12689 return "DW_TAG_thrown_type";
12690 case DW_TAG_try_block
:
12691 return "DW_TAG_try_block";
12692 case DW_TAG_variant_part
:
12693 return "DW_TAG_variant_part";
12694 case DW_TAG_variable
:
12695 return "DW_TAG_variable";
12696 case DW_TAG_volatile_type
:
12697 return "DW_TAG_volatile_type";
12698 case DW_TAG_dwarf_procedure
:
12699 return "DW_TAG_dwarf_procedure";
12700 case DW_TAG_restrict_type
:
12701 return "DW_TAG_restrict_type";
12702 case DW_TAG_interface_type
:
12703 return "DW_TAG_interface_type";
12704 case DW_TAG_namespace
:
12705 return "DW_TAG_namespace";
12706 case DW_TAG_imported_module
:
12707 return "DW_TAG_imported_module";
12708 case DW_TAG_unspecified_type
:
12709 return "DW_TAG_unspecified_type";
12710 case DW_TAG_partial_unit
:
12711 return "DW_TAG_partial_unit";
12712 case DW_TAG_imported_unit
:
12713 return "DW_TAG_imported_unit";
12714 case DW_TAG_condition
:
12715 return "DW_TAG_condition";
12716 case DW_TAG_shared_type
:
12717 return "DW_TAG_shared_type";
12718 case DW_TAG_type_unit
:
12719 return "DW_TAG_type_unit";
12720 case DW_TAG_MIPS_loop
:
12721 return "DW_TAG_MIPS_loop";
12722 case DW_TAG_HP_array_descriptor
:
12723 return "DW_TAG_HP_array_descriptor";
12724 case DW_TAG_format_label
:
12725 return "DW_TAG_format_label";
12726 case DW_TAG_function_template
:
12727 return "DW_TAG_function_template";
12728 case DW_TAG_class_template
:
12729 return "DW_TAG_class_template";
12730 case DW_TAG_GNU_BINCL
:
12731 return "DW_TAG_GNU_BINCL";
12732 case DW_TAG_GNU_EINCL
:
12733 return "DW_TAG_GNU_EINCL";
12734 case DW_TAG_upc_shared_type
:
12735 return "DW_TAG_upc_shared_type";
12736 case DW_TAG_upc_strict_type
:
12737 return "DW_TAG_upc_strict_type";
12738 case DW_TAG_upc_relaxed_type
:
12739 return "DW_TAG_upc_relaxed_type";
12740 case DW_TAG_PGI_kanji_type
:
12741 return "DW_TAG_PGI_kanji_type";
12742 case DW_TAG_PGI_interface_block
:
12743 return "DW_TAG_PGI_interface_block";
12745 return "DW_TAG_<unknown>";
12749 /* Convert a DWARF attribute code into its string name. */
12752 dwarf_attr_name (unsigned attr
)
12756 case DW_AT_sibling
:
12757 return "DW_AT_sibling";
12758 case DW_AT_location
:
12759 return "DW_AT_location";
12761 return "DW_AT_name";
12762 case DW_AT_ordering
:
12763 return "DW_AT_ordering";
12764 case DW_AT_subscr_data
:
12765 return "DW_AT_subscr_data";
12766 case DW_AT_byte_size
:
12767 return "DW_AT_byte_size";
12768 case DW_AT_bit_offset
:
12769 return "DW_AT_bit_offset";
12770 case DW_AT_bit_size
:
12771 return "DW_AT_bit_size";
12772 case DW_AT_element_list
:
12773 return "DW_AT_element_list";
12774 case DW_AT_stmt_list
:
12775 return "DW_AT_stmt_list";
12777 return "DW_AT_low_pc";
12778 case DW_AT_high_pc
:
12779 return "DW_AT_high_pc";
12780 case DW_AT_language
:
12781 return "DW_AT_language";
12783 return "DW_AT_member";
12785 return "DW_AT_discr";
12786 case DW_AT_discr_value
:
12787 return "DW_AT_discr_value";
12788 case DW_AT_visibility
:
12789 return "DW_AT_visibility";
12791 return "DW_AT_import";
12792 case DW_AT_string_length
:
12793 return "DW_AT_string_length";
12794 case DW_AT_common_reference
:
12795 return "DW_AT_common_reference";
12796 case DW_AT_comp_dir
:
12797 return "DW_AT_comp_dir";
12798 case DW_AT_const_value
:
12799 return "DW_AT_const_value";
12800 case DW_AT_containing_type
:
12801 return "DW_AT_containing_type";
12802 case DW_AT_default_value
:
12803 return "DW_AT_default_value";
12805 return "DW_AT_inline";
12806 case DW_AT_is_optional
:
12807 return "DW_AT_is_optional";
12808 case DW_AT_lower_bound
:
12809 return "DW_AT_lower_bound";
12810 case DW_AT_producer
:
12811 return "DW_AT_producer";
12812 case DW_AT_prototyped
:
12813 return "DW_AT_prototyped";
12814 case DW_AT_return_addr
:
12815 return "DW_AT_return_addr";
12816 case DW_AT_start_scope
:
12817 return "DW_AT_start_scope";
12818 case DW_AT_bit_stride
:
12819 return "DW_AT_bit_stride";
12820 case DW_AT_upper_bound
:
12821 return "DW_AT_upper_bound";
12822 case DW_AT_abstract_origin
:
12823 return "DW_AT_abstract_origin";
12824 case DW_AT_accessibility
:
12825 return "DW_AT_accessibility";
12826 case DW_AT_address_class
:
12827 return "DW_AT_address_class";
12828 case DW_AT_artificial
:
12829 return "DW_AT_artificial";
12830 case DW_AT_base_types
:
12831 return "DW_AT_base_types";
12832 case DW_AT_calling_convention
:
12833 return "DW_AT_calling_convention";
12835 return "DW_AT_count";
12836 case DW_AT_data_member_location
:
12837 return "DW_AT_data_member_location";
12838 case DW_AT_decl_column
:
12839 return "DW_AT_decl_column";
12840 case DW_AT_decl_file
:
12841 return "DW_AT_decl_file";
12842 case DW_AT_decl_line
:
12843 return "DW_AT_decl_line";
12844 case DW_AT_declaration
:
12845 return "DW_AT_declaration";
12846 case DW_AT_discr_list
:
12847 return "DW_AT_discr_list";
12848 case DW_AT_encoding
:
12849 return "DW_AT_encoding";
12850 case DW_AT_external
:
12851 return "DW_AT_external";
12852 case DW_AT_frame_base
:
12853 return "DW_AT_frame_base";
12855 return "DW_AT_friend";
12856 case DW_AT_identifier_case
:
12857 return "DW_AT_identifier_case";
12858 case DW_AT_macro_info
:
12859 return "DW_AT_macro_info";
12860 case DW_AT_namelist_items
:
12861 return "DW_AT_namelist_items";
12862 case DW_AT_priority
:
12863 return "DW_AT_priority";
12864 case DW_AT_segment
:
12865 return "DW_AT_segment";
12866 case DW_AT_specification
:
12867 return "DW_AT_specification";
12868 case DW_AT_static_link
:
12869 return "DW_AT_static_link";
12871 return "DW_AT_type";
12872 case DW_AT_use_location
:
12873 return "DW_AT_use_location";
12874 case DW_AT_variable_parameter
:
12875 return "DW_AT_variable_parameter";
12876 case DW_AT_virtuality
:
12877 return "DW_AT_virtuality";
12878 case DW_AT_vtable_elem_location
:
12879 return "DW_AT_vtable_elem_location";
12880 /* DWARF 3 values. */
12881 case DW_AT_allocated
:
12882 return "DW_AT_allocated";
12883 case DW_AT_associated
:
12884 return "DW_AT_associated";
12885 case DW_AT_data_location
:
12886 return "DW_AT_data_location";
12887 case DW_AT_byte_stride
:
12888 return "DW_AT_byte_stride";
12889 case DW_AT_entry_pc
:
12890 return "DW_AT_entry_pc";
12891 case DW_AT_use_UTF8
:
12892 return "DW_AT_use_UTF8";
12893 case DW_AT_extension
:
12894 return "DW_AT_extension";
12896 return "DW_AT_ranges";
12897 case DW_AT_trampoline
:
12898 return "DW_AT_trampoline";
12899 case DW_AT_call_column
:
12900 return "DW_AT_call_column";
12901 case DW_AT_call_file
:
12902 return "DW_AT_call_file";
12903 case DW_AT_call_line
:
12904 return "DW_AT_call_line";
12905 case DW_AT_description
:
12906 return "DW_AT_description";
12907 case DW_AT_binary_scale
:
12908 return "DW_AT_binary_scale";
12909 case DW_AT_decimal_scale
:
12910 return "DW_AT_decimal_scale";
12912 return "DW_AT_small";
12913 case DW_AT_decimal_sign
:
12914 return "DW_AT_decimal_sign";
12915 case DW_AT_digit_count
:
12916 return "DW_AT_digit_count";
12917 case DW_AT_picture_string
:
12918 return "DW_AT_picture_string";
12919 case DW_AT_mutable
:
12920 return "DW_AT_mutable";
12921 case DW_AT_threads_scaled
:
12922 return "DW_AT_threads_scaled";
12923 case DW_AT_explicit
:
12924 return "DW_AT_explicit";
12925 case DW_AT_object_pointer
:
12926 return "DW_AT_object_pointer";
12927 case DW_AT_endianity
:
12928 return "DW_AT_endianity";
12929 case DW_AT_elemental
:
12930 return "DW_AT_elemental";
12932 return "DW_AT_pure";
12933 case DW_AT_recursive
:
12934 return "DW_AT_recursive";
12935 /* DWARF 4 values. */
12936 case DW_AT_signature
:
12937 return "DW_AT_signature";
12938 case DW_AT_linkage_name
:
12939 return "DW_AT_linkage_name";
12940 /* SGI/MIPS extensions. */
12941 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12942 case DW_AT_MIPS_fde
:
12943 return "DW_AT_MIPS_fde";
12945 case DW_AT_MIPS_loop_begin
:
12946 return "DW_AT_MIPS_loop_begin";
12947 case DW_AT_MIPS_tail_loop_begin
:
12948 return "DW_AT_MIPS_tail_loop_begin";
12949 case DW_AT_MIPS_epilog_begin
:
12950 return "DW_AT_MIPS_epilog_begin";
12951 case DW_AT_MIPS_loop_unroll_factor
:
12952 return "DW_AT_MIPS_loop_unroll_factor";
12953 case DW_AT_MIPS_software_pipeline_depth
:
12954 return "DW_AT_MIPS_software_pipeline_depth";
12955 case DW_AT_MIPS_linkage_name
:
12956 return "DW_AT_MIPS_linkage_name";
12957 case DW_AT_MIPS_stride
:
12958 return "DW_AT_MIPS_stride";
12959 case DW_AT_MIPS_abstract_name
:
12960 return "DW_AT_MIPS_abstract_name";
12961 case DW_AT_MIPS_clone_origin
:
12962 return "DW_AT_MIPS_clone_origin";
12963 case DW_AT_MIPS_has_inlines
:
12964 return "DW_AT_MIPS_has_inlines";
12965 /* HP extensions. */
12966 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12967 case DW_AT_HP_block_index
:
12968 return "DW_AT_HP_block_index";
12970 case DW_AT_HP_unmodifiable
:
12971 return "DW_AT_HP_unmodifiable";
12972 case DW_AT_HP_actuals_stmt_list
:
12973 return "DW_AT_HP_actuals_stmt_list";
12974 case DW_AT_HP_proc_per_section
:
12975 return "DW_AT_HP_proc_per_section";
12976 case DW_AT_HP_raw_data_ptr
:
12977 return "DW_AT_HP_raw_data_ptr";
12978 case DW_AT_HP_pass_by_reference
:
12979 return "DW_AT_HP_pass_by_reference";
12980 case DW_AT_HP_opt_level
:
12981 return "DW_AT_HP_opt_level";
12982 case DW_AT_HP_prof_version_id
:
12983 return "DW_AT_HP_prof_version_id";
12984 case DW_AT_HP_opt_flags
:
12985 return "DW_AT_HP_opt_flags";
12986 case DW_AT_HP_cold_region_low_pc
:
12987 return "DW_AT_HP_cold_region_low_pc";
12988 case DW_AT_HP_cold_region_high_pc
:
12989 return "DW_AT_HP_cold_region_high_pc";
12990 case DW_AT_HP_all_variables_modifiable
:
12991 return "DW_AT_HP_all_variables_modifiable";
12992 case DW_AT_HP_linkage_name
:
12993 return "DW_AT_HP_linkage_name";
12994 case DW_AT_HP_prof_flags
:
12995 return "DW_AT_HP_prof_flags";
12996 /* GNU extensions. */
12997 case DW_AT_sf_names
:
12998 return "DW_AT_sf_names";
12999 case DW_AT_src_info
:
13000 return "DW_AT_src_info";
13001 case DW_AT_mac_info
:
13002 return "DW_AT_mac_info";
13003 case DW_AT_src_coords
:
13004 return "DW_AT_src_coords";
13005 case DW_AT_body_begin
:
13006 return "DW_AT_body_begin";
13007 case DW_AT_body_end
:
13008 return "DW_AT_body_end";
13009 case DW_AT_GNU_vector
:
13010 return "DW_AT_GNU_vector";
13011 case DW_AT_GNU_odr_signature
:
13012 return "DW_AT_GNU_odr_signature";
13013 /* VMS extensions. */
13014 case DW_AT_VMS_rtnbeg_pd_address
:
13015 return "DW_AT_VMS_rtnbeg_pd_address";
13016 /* UPC extension. */
13017 case DW_AT_upc_threads_scaled
:
13018 return "DW_AT_upc_threads_scaled";
13019 /* PGI (STMicroelectronics) extensions. */
13020 case DW_AT_PGI_lbase
:
13021 return "DW_AT_PGI_lbase";
13022 case DW_AT_PGI_soffset
:
13023 return "DW_AT_PGI_soffset";
13024 case DW_AT_PGI_lstride
:
13025 return "DW_AT_PGI_lstride";
13027 return "DW_AT_<unknown>";
13031 /* Convert a DWARF value form code into its string name. */
13034 dwarf_form_name (unsigned form
)
13039 return "DW_FORM_addr";
13040 case DW_FORM_block2
:
13041 return "DW_FORM_block2";
13042 case DW_FORM_block4
:
13043 return "DW_FORM_block4";
13044 case DW_FORM_data2
:
13045 return "DW_FORM_data2";
13046 case DW_FORM_data4
:
13047 return "DW_FORM_data4";
13048 case DW_FORM_data8
:
13049 return "DW_FORM_data8";
13050 case DW_FORM_string
:
13051 return "DW_FORM_string";
13052 case DW_FORM_block
:
13053 return "DW_FORM_block";
13054 case DW_FORM_block1
:
13055 return "DW_FORM_block1";
13056 case DW_FORM_data1
:
13057 return "DW_FORM_data1";
13059 return "DW_FORM_flag";
13060 case DW_FORM_sdata
:
13061 return "DW_FORM_sdata";
13063 return "DW_FORM_strp";
13064 case DW_FORM_udata
:
13065 return "DW_FORM_udata";
13066 case DW_FORM_ref_addr
:
13067 return "DW_FORM_ref_addr";
13069 return "DW_FORM_ref1";
13071 return "DW_FORM_ref2";
13073 return "DW_FORM_ref4";
13075 return "DW_FORM_ref8";
13076 case DW_FORM_ref_udata
:
13077 return "DW_FORM_ref_udata";
13078 case DW_FORM_indirect
:
13079 return "DW_FORM_indirect";
13080 case DW_FORM_sec_offset
:
13081 return "DW_FORM_sec_offset";
13082 case DW_FORM_exprloc
:
13083 return "DW_FORM_exprloc";
13084 case DW_FORM_flag_present
:
13085 return "DW_FORM_flag_present";
13086 case DW_FORM_ref_sig8
:
13087 return "DW_FORM_ref_sig8";
13089 return "DW_FORM_<unknown>";
13093 /* Convert a DWARF stack opcode into its string name. */
13096 dwarf_stack_op_name (unsigned op
)
13101 return "DW_OP_addr";
13103 return "DW_OP_deref";
13104 case DW_OP_const1u
:
13105 return "DW_OP_const1u";
13106 case DW_OP_const1s
:
13107 return "DW_OP_const1s";
13108 case DW_OP_const2u
:
13109 return "DW_OP_const2u";
13110 case DW_OP_const2s
:
13111 return "DW_OP_const2s";
13112 case DW_OP_const4u
:
13113 return "DW_OP_const4u";
13114 case DW_OP_const4s
:
13115 return "DW_OP_const4s";
13116 case DW_OP_const8u
:
13117 return "DW_OP_const8u";
13118 case DW_OP_const8s
:
13119 return "DW_OP_const8s";
13121 return "DW_OP_constu";
13123 return "DW_OP_consts";
13125 return "DW_OP_dup";
13127 return "DW_OP_drop";
13129 return "DW_OP_over";
13131 return "DW_OP_pick";
13133 return "DW_OP_swap";
13135 return "DW_OP_rot";
13137 return "DW_OP_xderef";
13139 return "DW_OP_abs";
13141 return "DW_OP_and";
13143 return "DW_OP_div";
13145 return "DW_OP_minus";
13147 return "DW_OP_mod";
13149 return "DW_OP_mul";
13151 return "DW_OP_neg";
13153 return "DW_OP_not";
13157 return "DW_OP_plus";
13158 case DW_OP_plus_uconst
:
13159 return "DW_OP_plus_uconst";
13161 return "DW_OP_shl";
13163 return "DW_OP_shr";
13165 return "DW_OP_shra";
13167 return "DW_OP_xor";
13169 return "DW_OP_bra";
13183 return "DW_OP_skip";
13185 return "DW_OP_lit0";
13187 return "DW_OP_lit1";
13189 return "DW_OP_lit2";
13191 return "DW_OP_lit3";
13193 return "DW_OP_lit4";
13195 return "DW_OP_lit5";
13197 return "DW_OP_lit6";
13199 return "DW_OP_lit7";
13201 return "DW_OP_lit8";
13203 return "DW_OP_lit9";
13205 return "DW_OP_lit10";
13207 return "DW_OP_lit11";
13209 return "DW_OP_lit12";
13211 return "DW_OP_lit13";
13213 return "DW_OP_lit14";
13215 return "DW_OP_lit15";
13217 return "DW_OP_lit16";
13219 return "DW_OP_lit17";
13221 return "DW_OP_lit18";
13223 return "DW_OP_lit19";
13225 return "DW_OP_lit20";
13227 return "DW_OP_lit21";
13229 return "DW_OP_lit22";
13231 return "DW_OP_lit23";
13233 return "DW_OP_lit24";
13235 return "DW_OP_lit25";
13237 return "DW_OP_lit26";
13239 return "DW_OP_lit27";
13241 return "DW_OP_lit28";
13243 return "DW_OP_lit29";
13245 return "DW_OP_lit30";
13247 return "DW_OP_lit31";
13249 return "DW_OP_reg0";
13251 return "DW_OP_reg1";
13253 return "DW_OP_reg2";
13255 return "DW_OP_reg3";
13257 return "DW_OP_reg4";
13259 return "DW_OP_reg5";
13261 return "DW_OP_reg6";
13263 return "DW_OP_reg7";
13265 return "DW_OP_reg8";
13267 return "DW_OP_reg9";
13269 return "DW_OP_reg10";
13271 return "DW_OP_reg11";
13273 return "DW_OP_reg12";
13275 return "DW_OP_reg13";
13277 return "DW_OP_reg14";
13279 return "DW_OP_reg15";
13281 return "DW_OP_reg16";
13283 return "DW_OP_reg17";
13285 return "DW_OP_reg18";
13287 return "DW_OP_reg19";
13289 return "DW_OP_reg20";
13291 return "DW_OP_reg21";
13293 return "DW_OP_reg22";
13295 return "DW_OP_reg23";
13297 return "DW_OP_reg24";
13299 return "DW_OP_reg25";
13301 return "DW_OP_reg26";
13303 return "DW_OP_reg27";
13305 return "DW_OP_reg28";
13307 return "DW_OP_reg29";
13309 return "DW_OP_reg30";
13311 return "DW_OP_reg31";
13313 return "DW_OP_breg0";
13315 return "DW_OP_breg1";
13317 return "DW_OP_breg2";
13319 return "DW_OP_breg3";
13321 return "DW_OP_breg4";
13323 return "DW_OP_breg5";
13325 return "DW_OP_breg6";
13327 return "DW_OP_breg7";
13329 return "DW_OP_breg8";
13331 return "DW_OP_breg9";
13333 return "DW_OP_breg10";
13335 return "DW_OP_breg11";
13337 return "DW_OP_breg12";
13339 return "DW_OP_breg13";
13341 return "DW_OP_breg14";
13343 return "DW_OP_breg15";
13345 return "DW_OP_breg16";
13347 return "DW_OP_breg17";
13349 return "DW_OP_breg18";
13351 return "DW_OP_breg19";
13353 return "DW_OP_breg20";
13355 return "DW_OP_breg21";
13357 return "DW_OP_breg22";
13359 return "DW_OP_breg23";
13361 return "DW_OP_breg24";
13363 return "DW_OP_breg25";
13365 return "DW_OP_breg26";
13367 return "DW_OP_breg27";
13369 return "DW_OP_breg28";
13371 return "DW_OP_breg29";
13373 return "DW_OP_breg30";
13375 return "DW_OP_breg31";
13377 return "DW_OP_regx";
13379 return "DW_OP_fbreg";
13381 return "DW_OP_bregx";
13383 return "DW_OP_piece";
13384 case DW_OP_deref_size
:
13385 return "DW_OP_deref_size";
13386 case DW_OP_xderef_size
:
13387 return "DW_OP_xderef_size";
13389 return "DW_OP_nop";
13390 /* DWARF 3 extensions. */
13391 case DW_OP_push_object_address
:
13392 return "DW_OP_push_object_address";
13394 return "DW_OP_call2";
13396 return "DW_OP_call4";
13397 case DW_OP_call_ref
:
13398 return "DW_OP_call_ref";
13399 case DW_OP_form_tls_address
:
13400 return "DW_OP_form_tls_address";
13401 case DW_OP_call_frame_cfa
:
13402 return "DW_OP_call_frame_cfa";
13403 case DW_OP_bit_piece
:
13404 return "DW_OP_bit_piece";
13405 /* DWARF 4 extensions. */
13406 case DW_OP_implicit_value
:
13407 return "DW_OP_implicit_value";
13408 case DW_OP_stack_value
:
13409 return "DW_OP_stack_value";
13410 /* GNU extensions. */
13411 case DW_OP_GNU_push_tls_address
:
13412 return "DW_OP_GNU_push_tls_address";
13413 case DW_OP_GNU_uninit
:
13414 return "DW_OP_GNU_uninit";
13415 case DW_OP_GNU_implicit_pointer
:
13416 return "DW_OP_GNU_implicit_pointer";
13417 case DW_OP_GNU_entry_value
:
13418 return "DW_OP_GNU_entry_value";
13419 case DW_OP_GNU_const_type
:
13420 return "DW_OP_GNU_const_type";
13421 case DW_OP_GNU_regval_type
:
13422 return "DW_OP_GNU_regval_type";
13423 case DW_OP_GNU_deref_type
:
13424 return "DW_OP_GNU_deref_type";
13425 case DW_OP_GNU_convert
:
13426 return "DW_OP_GNU_convert";
13427 case DW_OP_GNU_reinterpret
:
13428 return "DW_OP_GNU_reinterpret";
13435 dwarf_bool_name (unsigned mybool
)
13443 /* Convert a DWARF type code into its string name. */
13446 dwarf_type_encoding_name (unsigned enc
)
13451 return "DW_ATE_void";
13452 case DW_ATE_address
:
13453 return "DW_ATE_address";
13454 case DW_ATE_boolean
:
13455 return "DW_ATE_boolean";
13456 case DW_ATE_complex_float
:
13457 return "DW_ATE_complex_float";
13459 return "DW_ATE_float";
13460 case DW_ATE_signed
:
13461 return "DW_ATE_signed";
13462 case DW_ATE_signed_char
:
13463 return "DW_ATE_signed_char";
13464 case DW_ATE_unsigned
:
13465 return "DW_ATE_unsigned";
13466 case DW_ATE_unsigned_char
:
13467 return "DW_ATE_unsigned_char";
13469 case DW_ATE_imaginary_float
:
13470 return "DW_ATE_imaginary_float";
13471 case DW_ATE_packed_decimal
:
13472 return "DW_ATE_packed_decimal";
13473 case DW_ATE_numeric_string
:
13474 return "DW_ATE_numeric_string";
13475 case DW_ATE_edited
:
13476 return "DW_ATE_edited";
13477 case DW_ATE_signed_fixed
:
13478 return "DW_ATE_signed_fixed";
13479 case DW_ATE_unsigned_fixed
:
13480 return "DW_ATE_unsigned_fixed";
13481 case DW_ATE_decimal_float
:
13482 return "DW_ATE_decimal_float";
13485 return "DW_ATE_UTF";
13486 /* HP extensions. */
13487 case DW_ATE_HP_float80
:
13488 return "DW_ATE_HP_float80";
13489 case DW_ATE_HP_complex_float80
:
13490 return "DW_ATE_HP_complex_float80";
13491 case DW_ATE_HP_float128
:
13492 return "DW_ATE_HP_float128";
13493 case DW_ATE_HP_complex_float128
:
13494 return "DW_ATE_HP_complex_float128";
13495 case DW_ATE_HP_floathpintel
:
13496 return "DW_ATE_HP_floathpintel";
13497 case DW_ATE_HP_imaginary_float80
:
13498 return "DW_ATE_HP_imaginary_float80";
13499 case DW_ATE_HP_imaginary_float128
:
13500 return "DW_ATE_HP_imaginary_float128";
13502 return "DW_ATE_<unknown>";
13506 /* Convert a DWARF call frame info operation to its string name. */
13510 dwarf_cfi_name (unsigned cfi_opc
)
13514 case DW_CFA_advance_loc
:
13515 return "DW_CFA_advance_loc";
13516 case DW_CFA_offset
:
13517 return "DW_CFA_offset";
13518 case DW_CFA_restore
:
13519 return "DW_CFA_restore";
13521 return "DW_CFA_nop";
13522 case DW_CFA_set_loc
:
13523 return "DW_CFA_set_loc";
13524 case DW_CFA_advance_loc1
:
13525 return "DW_CFA_advance_loc1";
13526 case DW_CFA_advance_loc2
:
13527 return "DW_CFA_advance_loc2";
13528 case DW_CFA_advance_loc4
:
13529 return "DW_CFA_advance_loc4";
13530 case DW_CFA_offset_extended
:
13531 return "DW_CFA_offset_extended";
13532 case DW_CFA_restore_extended
:
13533 return "DW_CFA_restore_extended";
13534 case DW_CFA_undefined
:
13535 return "DW_CFA_undefined";
13536 case DW_CFA_same_value
:
13537 return "DW_CFA_same_value";
13538 case DW_CFA_register
:
13539 return "DW_CFA_register";
13540 case DW_CFA_remember_state
:
13541 return "DW_CFA_remember_state";
13542 case DW_CFA_restore_state
:
13543 return "DW_CFA_restore_state";
13544 case DW_CFA_def_cfa
:
13545 return "DW_CFA_def_cfa";
13546 case DW_CFA_def_cfa_register
:
13547 return "DW_CFA_def_cfa_register";
13548 case DW_CFA_def_cfa_offset
:
13549 return "DW_CFA_def_cfa_offset";
13551 case DW_CFA_def_cfa_expression
:
13552 return "DW_CFA_def_cfa_expression";
13553 case DW_CFA_expression
:
13554 return "DW_CFA_expression";
13555 case DW_CFA_offset_extended_sf
:
13556 return "DW_CFA_offset_extended_sf";
13557 case DW_CFA_def_cfa_sf
:
13558 return "DW_CFA_def_cfa_sf";
13559 case DW_CFA_def_cfa_offset_sf
:
13560 return "DW_CFA_def_cfa_offset_sf";
13561 case DW_CFA_val_offset
:
13562 return "DW_CFA_val_offset";
13563 case DW_CFA_val_offset_sf
:
13564 return "DW_CFA_val_offset_sf";
13565 case DW_CFA_val_expression
:
13566 return "DW_CFA_val_expression";
13567 /* SGI/MIPS specific. */
13568 case DW_CFA_MIPS_advance_loc8
:
13569 return "DW_CFA_MIPS_advance_loc8";
13570 /* GNU extensions. */
13571 case DW_CFA_GNU_window_save
:
13572 return "DW_CFA_GNU_window_save";
13573 case DW_CFA_GNU_args_size
:
13574 return "DW_CFA_GNU_args_size";
13575 case DW_CFA_GNU_negative_offset_extended
:
13576 return "DW_CFA_GNU_negative_offset_extended";
13578 return "DW_CFA_<unknown>";
13584 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13588 print_spaces (indent
, f
);
13589 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13590 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13592 if (die
->parent
!= NULL
)
13594 print_spaces (indent
, f
);
13595 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13596 die
->parent
->offset
);
13599 print_spaces (indent
, f
);
13600 fprintf_unfiltered (f
, " has children: %s\n",
13601 dwarf_bool_name (die
->child
!= NULL
));
13603 print_spaces (indent
, f
);
13604 fprintf_unfiltered (f
, " attributes:\n");
13606 for (i
= 0; i
< die
->num_attrs
; ++i
)
13608 print_spaces (indent
, f
);
13609 fprintf_unfiltered (f
, " %s (%s) ",
13610 dwarf_attr_name (die
->attrs
[i
].name
),
13611 dwarf_form_name (die
->attrs
[i
].form
));
13613 switch (die
->attrs
[i
].form
)
13615 case DW_FORM_ref_addr
:
13617 fprintf_unfiltered (f
, "address: ");
13618 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13620 case DW_FORM_block2
:
13621 case DW_FORM_block4
:
13622 case DW_FORM_block
:
13623 case DW_FORM_block1
:
13624 fprintf_unfiltered (f
, "block: size %d",
13625 DW_BLOCK (&die
->attrs
[i
])->size
);
13627 case DW_FORM_exprloc
:
13628 fprintf_unfiltered (f
, "expression: size %u",
13629 DW_BLOCK (&die
->attrs
[i
])->size
);
13634 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13635 (long) (DW_ADDR (&die
->attrs
[i
])));
13637 case DW_FORM_data1
:
13638 case DW_FORM_data2
:
13639 case DW_FORM_data4
:
13640 case DW_FORM_data8
:
13641 case DW_FORM_udata
:
13642 case DW_FORM_sdata
:
13643 fprintf_unfiltered (f
, "constant: %s",
13644 pulongest (DW_UNSND (&die
->attrs
[i
])));
13646 case DW_FORM_sec_offset
:
13647 fprintf_unfiltered (f
, "section offset: %s",
13648 pulongest (DW_UNSND (&die
->attrs
[i
])));
13650 case DW_FORM_ref_sig8
:
13651 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13652 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13653 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
);
13655 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13657 case DW_FORM_string
:
13659 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13660 DW_STRING (&die
->attrs
[i
])
13661 ? DW_STRING (&die
->attrs
[i
]) : "",
13662 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13665 if (DW_UNSND (&die
->attrs
[i
]))
13666 fprintf_unfiltered (f
, "flag: TRUE");
13668 fprintf_unfiltered (f
, "flag: FALSE");
13670 case DW_FORM_flag_present
:
13671 fprintf_unfiltered (f
, "flag: TRUE");
13673 case DW_FORM_indirect
:
13674 /* The reader will have reduced the indirect form to
13675 the "base form" so this form should not occur. */
13676 fprintf_unfiltered (f
,
13677 "unexpected attribute form: DW_FORM_indirect");
13680 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13681 die
->attrs
[i
].form
);
13684 fprintf_unfiltered (f
, "\n");
13689 dump_die_for_error (struct die_info
*die
)
13691 dump_die_shallow (gdb_stderr
, 0, die
);
13695 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13697 int indent
= level
* 4;
13699 gdb_assert (die
!= NULL
);
13701 if (level
>= max_level
)
13704 dump_die_shallow (f
, indent
, die
);
13706 if (die
->child
!= NULL
)
13708 print_spaces (indent
, f
);
13709 fprintf_unfiltered (f
, " Children:");
13710 if (level
+ 1 < max_level
)
13712 fprintf_unfiltered (f
, "\n");
13713 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13717 fprintf_unfiltered (f
,
13718 " [not printed, max nesting level reached]\n");
13722 if (die
->sibling
!= NULL
&& level
> 0)
13724 dump_die_1 (f
, level
, max_level
, die
->sibling
);
13728 /* This is called from the pdie macro in gdbinit.in.
13729 It's not static so gcc will keep a copy callable from gdb. */
13732 dump_die (struct die_info
*die
, int max_level
)
13734 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
13738 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
13742 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
13748 is_ref_attr (struct attribute
*attr
)
13750 switch (attr
->form
)
13752 case DW_FORM_ref_addr
:
13757 case DW_FORM_ref_udata
:
13764 static unsigned int
13765 dwarf2_get_ref_die_offset (struct attribute
*attr
)
13767 if (is_ref_attr (attr
))
13768 return DW_ADDR (attr
);
13770 complaint (&symfile_complaints
,
13771 _("unsupported die ref attribute form: '%s'"),
13772 dwarf_form_name (attr
->form
));
13776 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13777 * the value held by the attribute is not constant. */
13780 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
13782 if (attr
->form
== DW_FORM_sdata
)
13783 return DW_SND (attr
);
13784 else if (attr
->form
== DW_FORM_udata
13785 || attr
->form
== DW_FORM_data1
13786 || attr
->form
== DW_FORM_data2
13787 || attr
->form
== DW_FORM_data4
13788 || attr
->form
== DW_FORM_data8
)
13789 return DW_UNSND (attr
);
13792 complaint (&symfile_complaints
,
13793 _("Attribute value is not a constant (%s)"),
13794 dwarf_form_name (attr
->form
));
13795 return default_value
;
13799 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13800 unit and add it to our queue.
13801 The result is non-zero if PER_CU was queued, otherwise the result is zero
13802 meaning either PER_CU is already queued or it is already loaded. */
13805 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
13806 struct dwarf2_per_cu_data
*per_cu
)
13808 /* We may arrive here during partial symbol reading, if we need full
13809 DIEs to process an unusual case (e.g. template arguments). Do
13810 not queue PER_CU, just tell our caller to load its DIEs. */
13811 if (dwarf2_per_objfile
->reading_partial_symbols
)
13813 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
13818 /* Mark the dependence relation so that we don't flush PER_CU
13820 dwarf2_add_dependence (this_cu
, per_cu
);
13822 /* If it's already on the queue, we have nothing to do. */
13823 if (per_cu
->queued
)
13826 /* If the compilation unit is already loaded, just mark it as
13828 if (per_cu
->cu
!= NULL
)
13830 per_cu
->cu
->last_used
= 0;
13834 /* Add it to the queue. */
13835 queue_comp_unit (per_cu
, this_cu
->objfile
);
13840 /* Follow reference or signature attribute ATTR of SRC_DIE.
13841 On entry *REF_CU is the CU of SRC_DIE.
13842 On exit *REF_CU is the CU of the result. */
13844 static struct die_info
*
13845 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
13846 struct dwarf2_cu
**ref_cu
)
13848 struct die_info
*die
;
13850 if (is_ref_attr (attr
))
13851 die
= follow_die_ref (src_die
, attr
, ref_cu
);
13852 else if (attr
->form
== DW_FORM_ref_sig8
)
13853 die
= follow_die_sig (src_die
, attr
, ref_cu
);
13856 dump_die_for_error (src_die
);
13857 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13858 (*ref_cu
)->objfile
->name
);
13864 /* Follow reference OFFSET.
13865 On entry *REF_CU is the CU of the source die referencing OFFSET.
13866 On exit *REF_CU is the CU of the result.
13867 Returns NULL if OFFSET is invalid. */
13869 static struct die_info
*
13870 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
13872 struct die_info temp_die
;
13873 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
13875 gdb_assert (cu
->per_cu
!= NULL
);
13879 if (cu
->per_cu
->debug_type_section
)
13881 /* .debug_types CUs cannot reference anything outside their CU.
13882 If they need to, they have to reference a signatured type via
13883 DW_FORM_ref_sig8. */
13884 if (! offset_in_cu_p (&cu
->header
, offset
))
13887 else if (! offset_in_cu_p (&cu
->header
, offset
))
13889 struct dwarf2_per_cu_data
*per_cu
;
13891 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
13893 /* If necessary, add it to the queue and load its DIEs. */
13894 if (maybe_queue_comp_unit (cu
, per_cu
))
13895 load_full_comp_unit (per_cu
, cu
->objfile
);
13897 target_cu
= per_cu
->cu
;
13899 else if (cu
->dies
== NULL
)
13901 /* We're loading full DIEs during partial symbol reading. */
13902 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
13903 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
13906 *ref_cu
= target_cu
;
13907 temp_die
.offset
= offset
;
13908 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13911 /* Follow reference attribute ATTR of SRC_DIE.
13912 On entry *REF_CU is the CU of SRC_DIE.
13913 On exit *REF_CU is the CU of the result. */
13915 static struct die_info
*
13916 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13917 struct dwarf2_cu
**ref_cu
)
13919 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13920 struct dwarf2_cu
*cu
= *ref_cu
;
13921 struct die_info
*die
;
13923 die
= follow_die_offset (offset
, ref_cu
);
13925 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13926 "at 0x%x [in module %s]"),
13927 offset
, src_die
->offset
, cu
->objfile
->name
);
13932 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
13933 Returned value is intended for DW_OP_call*. Returned
13934 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
13936 struct dwarf2_locexpr_baton
13937 dwarf2_fetch_die_location_block (unsigned int offset
,
13938 struct dwarf2_per_cu_data
*per_cu
,
13939 CORE_ADDR (*get_frame_pc
) (void *baton
),
13942 struct dwarf2_cu
*cu
;
13943 struct die_info
*die
;
13944 struct attribute
*attr
;
13945 struct dwarf2_locexpr_baton retval
;
13947 dw2_setup (per_cu
->objfile
);
13949 if (per_cu
->cu
== NULL
)
13953 die
= follow_die_offset (offset
, &cu
);
13955 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13956 offset
, per_cu
->cu
->objfile
->name
);
13958 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13961 /* DWARF: "If there is no such attribute, then there is no effect.". */
13963 retval
.data
= NULL
;
13966 else if (attr_form_is_section_offset (attr
))
13968 struct dwarf2_loclist_baton loclist_baton
;
13969 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
13972 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
13974 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
13976 retval
.size
= size
;
13980 if (!attr_form_is_block (attr
))
13981 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13982 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13983 offset
, per_cu
->cu
->objfile
->name
);
13985 retval
.data
= DW_BLOCK (attr
)->data
;
13986 retval
.size
= DW_BLOCK (attr
)->size
;
13988 retval
.per_cu
= cu
->per_cu
;
13990 age_cached_comp_units ();
13995 /* Return the type of the DIE at DIE_OFFSET in the CU named by
13999 dwarf2_get_die_type (unsigned int die_offset
,
14000 struct dwarf2_per_cu_data
*per_cu
)
14002 dw2_setup (per_cu
->objfile
);
14003 return get_die_type_at_offset (die_offset
, per_cu
);
14006 /* Follow the signature attribute ATTR in SRC_DIE.
14007 On entry *REF_CU is the CU of SRC_DIE.
14008 On exit *REF_CU is the CU of the result. */
14010 static struct die_info
*
14011 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
14012 struct dwarf2_cu
**ref_cu
)
14014 struct objfile
*objfile
= (*ref_cu
)->objfile
;
14015 struct die_info temp_die
;
14016 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14017 struct dwarf2_cu
*sig_cu
;
14018 struct die_info
*die
;
14020 /* sig_type will be NULL if the signatured type is missing from
14022 if (sig_type
== NULL
)
14023 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14024 "at 0x%x [in module %s]"),
14025 src_die
->offset
, objfile
->name
);
14027 /* If necessary, add it to the queue and load its DIEs. */
14029 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14030 read_signatured_type (objfile
, sig_type
);
14032 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14034 sig_cu
= sig_type
->per_cu
.cu
;
14035 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
14036 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
14043 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14044 "from DIE at 0x%x [in module %s]"),
14045 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
14048 /* Given an offset of a signatured type, return its signatured_type. */
14050 static struct signatured_type
*
14051 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14052 struct dwarf2_section_info
*section
,
14053 unsigned int offset
)
14055 gdb_byte
*info_ptr
= section
->buffer
+ offset
;
14056 unsigned int length
, initial_length_size
;
14057 unsigned int sig_offset
;
14058 struct signatured_type find_entry
, *type_sig
;
14060 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14061 sig_offset
= (initial_length_size
14063 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14064 + 1 /*address_size*/);
14065 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14066 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14068 /* This is only used to lookup previously recorded types.
14069 If we didn't find it, it's our bug. */
14070 gdb_assert (type_sig
!= NULL
);
14071 gdb_assert (offset
== type_sig
->per_cu
.offset
);
14076 /* Read in signatured type at OFFSET and build its CU and die(s). */
14079 read_signatured_type_at_offset (struct objfile
*objfile
,
14080 struct dwarf2_section_info
*sect
,
14081 unsigned int offset
)
14083 struct signatured_type
*type_sig
;
14085 dwarf2_read_section (objfile
, sect
);
14087 /* We have the section offset, but we need the signature to do the
14088 hash table lookup. */
14089 type_sig
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14091 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14093 read_signatured_type (objfile
, type_sig
);
14095 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
14098 /* Read in a signatured type and build its CU and DIEs. */
14101 read_signatured_type (struct objfile
*objfile
,
14102 struct signatured_type
*type_sig
)
14104 gdb_byte
*types_ptr
;
14105 struct die_reader_specs reader_specs
;
14106 struct dwarf2_cu
*cu
;
14107 ULONGEST signature
;
14108 struct cleanup
*back_to
, *free_cu_cleanup
;
14109 struct dwarf2_section_info
*section
= type_sig
->per_cu
.debug_type_section
;
14111 dwarf2_read_section (objfile
, section
);
14112 types_ptr
= section
->buffer
+ type_sig
->per_cu
.offset
;
14114 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14116 cu
= xmalloc (sizeof (*cu
));
14117 init_one_comp_unit (cu
, objfile
);
14119 type_sig
->per_cu
.cu
= cu
;
14120 cu
->per_cu
= &type_sig
->per_cu
;
14122 /* If an error occurs while loading, release our storage. */
14123 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
14125 types_ptr
= read_type_comp_unit_head (&cu
->header
, section
, &signature
,
14126 types_ptr
, objfile
->obfd
);
14127 gdb_assert (signature
== type_sig
->signature
);
14130 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14134 &cu
->comp_unit_obstack
,
14135 hashtab_obstack_allocate
,
14136 dummy_obstack_deallocate
);
14138 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
14139 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
14141 init_cu_die_reader (&reader_specs
, cu
);
14143 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14146 /* We try not to read any attributes in this function, because not
14147 all objfiles needed for references have been loaded yet, and symbol
14148 table processing isn't initialized. But we have to set the CU language,
14149 or we won't be able to build types correctly. */
14150 prepare_one_comp_unit (cu
, cu
->dies
);
14152 do_cleanups (back_to
);
14154 /* We've successfully allocated this compilation unit. Let our caller
14155 clean it up when finished with it. */
14156 discard_cleanups (free_cu_cleanup
);
14158 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14159 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
14162 /* Workaround as dwarf_expr_context_funcs.read_mem implementation before
14163 a proper runtime DWARF expressions evaluator gets implemented.
14164 Otherwise gnuv3_baseclass_offset would error by:
14165 Expected a negative vbase offset (old compiler?) */
14168 decode_locdesc_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
,
14171 struct dwarf_expr_context
*ctx
= baton
;
14172 struct gdbarch
*gdbarch
= ctx
->gdbarch
;
14173 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
14175 memset (buf
, 0, length
);
14177 if (TYPE_LENGTH (ptr_type
) == length
)
14178 store_typed_address (buf
, ptr_type
, addr
);
14181 static const struct dwarf_expr_context_funcs decode_locdesc_ctx_funcs
=
14184 decode_locdesc_read_mem
,
14185 ctx_no_get_frame_base
,
14186 ctx_no_get_frame_cfa
,
14187 ctx_no_get_frame_pc
,
14188 ctx_no_get_tls_address
,
14190 ctx_no_get_base_type
14193 /* Decode simple location descriptions.
14194 Given a pointer to a dwarf block that defines a location, compute
14195 the location and return the value.
14197 NOTE drow/2003-11-18: This function is called in two situations
14198 now: for the address of static or global variables (partial symbols
14199 only) and for offsets into structures which are expected to be
14200 (more or less) constant. The partial symbol case should go away,
14201 and only the constant case should remain. That will let this
14202 function complain more accurately. A few special modes are allowed
14203 without complaint for global variables (for instance, global
14204 register values and thread-local values).
14206 A location description containing no operations indicates that the
14207 object is optimized out. The return value is 0 for that case.
14208 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14209 callers will only want a very basic result and this can become a
14213 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14215 struct objfile
*objfile
= cu
->objfile
;
14216 struct dwarf_expr_context
*ctx
;
14217 struct cleanup
*old_chain
;
14218 volatile struct gdb_exception ex
;
14220 ctx
= new_dwarf_expr_context ();
14221 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
14222 make_cleanup_value_free_to_mark (value_mark ());
14224 ctx
->gdbarch
= get_objfile_arch (objfile
);
14225 ctx
->addr_size
= cu
->header
.addr_size
;
14226 ctx
->offset
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14228 ctx
->funcs
= &decode_locdesc_ctx_funcs
;
14230 /* DW_AT_data_member_location expects the structure address to be pushed on
14231 the stack. Simulate the offset by address 0. */
14232 dwarf_expr_push_address (ctx
, 0, 0);
14234 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
14236 dwarf_expr_eval (ctx
, blk
->data
, blk
->size
);
14241 complaint (&symfile_complaints
, "%s", ex
.message
);
14243 else if (ctx
->num_pieces
== 0)
14244 switch (ctx
->location
)
14246 /* The returned number will be bogus, just do not complain for locations
14247 in global registers - it is here only a partial symbol address. */
14248 case DWARF_VALUE_REGISTER
:
14250 case DWARF_VALUE_MEMORY
:
14251 case DWARF_VALUE_STACK
:
14253 CORE_ADDR address
= dwarf_expr_fetch_address (ctx
, 0);
14255 do_cleanups (old_chain
);
14260 do_cleanups (old_chain
);
14261 dwarf2_complex_location_expr_complaint ();
14265 /* memory allocation interface */
14267 static struct dwarf_block
*
14268 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14270 struct dwarf_block
*blk
;
14272 blk
= (struct dwarf_block
*)
14273 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14277 static struct abbrev_info
*
14278 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14280 struct abbrev_info
*abbrev
;
14282 abbrev
= (struct abbrev_info
*)
14283 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14284 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14288 static struct die_info
*
14289 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14291 struct die_info
*die
;
14292 size_t size
= sizeof (struct die_info
);
14295 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14297 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14298 memset (die
, 0, sizeof (struct die_info
));
14303 /* Macro support. */
14305 /* Return the full name of file number I in *LH's file name table.
14306 Use COMP_DIR as the name of the current directory of the
14307 compilation. The result is allocated using xmalloc; the caller is
14308 responsible for freeing it. */
14310 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14312 /* Is the file number a valid index into the line header's file name
14313 table? Remember that file numbers start with one, not zero. */
14314 if (1 <= file
&& file
<= lh
->num_file_names
)
14316 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14318 if (IS_ABSOLUTE_PATH (fe
->name
))
14319 return xstrdup (fe
->name
);
14327 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14333 dir_len
= strlen (dir
);
14334 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14335 strcpy (full_name
, dir
);
14336 full_name
[dir_len
] = '/';
14337 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14341 return xstrdup (fe
->name
);
14346 /* The compiler produced a bogus file number. We can at least
14347 record the macro definitions made in the file, even if we
14348 won't be able to find the file by name. */
14349 char fake_name
[80];
14351 sprintf (fake_name
, "<bad macro file number %d>", file
);
14353 complaint (&symfile_complaints
,
14354 _("bad file number in macro information (%d)"),
14357 return xstrdup (fake_name
);
14362 static struct macro_source_file
*
14363 macro_start_file (int file
, int line
,
14364 struct macro_source_file
*current_file
,
14365 const char *comp_dir
,
14366 struct line_header
*lh
, struct objfile
*objfile
)
14368 /* The full name of this source file. */
14369 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14371 /* We don't create a macro table for this compilation unit
14372 at all until we actually get a filename. */
14373 if (! pending_macros
)
14374 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14375 objfile
->macro_cache
);
14377 if (! current_file
)
14378 /* If we have no current file, then this must be the start_file
14379 directive for the compilation unit's main source file. */
14380 current_file
= macro_set_main (pending_macros
, full_name
);
14382 current_file
= macro_include (current_file
, line
, full_name
);
14386 return current_file
;
14390 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14391 followed by a null byte. */
14393 copy_string (const char *buf
, int len
)
14395 char *s
= xmalloc (len
+ 1);
14397 memcpy (s
, buf
, len
);
14403 static const char *
14404 consume_improper_spaces (const char *p
, const char *body
)
14408 complaint (&symfile_complaints
,
14409 _("macro definition contains spaces "
14410 "in formal argument list:\n`%s'"),
14422 parse_macro_definition (struct macro_source_file
*file
, int line
,
14427 /* The body string takes one of two forms. For object-like macro
14428 definitions, it should be:
14430 <macro name> " " <definition>
14432 For function-like macro definitions, it should be:
14434 <macro name> "() " <definition>
14436 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14438 Spaces may appear only where explicitly indicated, and in the
14441 The Dwarf 2 spec says that an object-like macro's name is always
14442 followed by a space, but versions of GCC around March 2002 omit
14443 the space when the macro's definition is the empty string.
14445 The Dwarf 2 spec says that there should be no spaces between the
14446 formal arguments in a function-like macro's formal argument list,
14447 but versions of GCC around March 2002 include spaces after the
14451 /* Find the extent of the macro name. The macro name is terminated
14452 by either a space or null character (for an object-like macro) or
14453 an opening paren (for a function-like macro). */
14454 for (p
= body
; *p
; p
++)
14455 if (*p
== ' ' || *p
== '(')
14458 if (*p
== ' ' || *p
== '\0')
14460 /* It's an object-like macro. */
14461 int name_len
= p
- body
;
14462 char *name
= copy_string (body
, name_len
);
14463 const char *replacement
;
14466 replacement
= body
+ name_len
+ 1;
14469 dwarf2_macro_malformed_definition_complaint (body
);
14470 replacement
= body
+ name_len
;
14473 macro_define_object (file
, line
, name
, replacement
);
14477 else if (*p
== '(')
14479 /* It's a function-like macro. */
14480 char *name
= copy_string (body
, p
- body
);
14483 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14487 p
= consume_improper_spaces (p
, body
);
14489 /* Parse the formal argument list. */
14490 while (*p
&& *p
!= ')')
14492 /* Find the extent of the current argument name. */
14493 const char *arg_start
= p
;
14495 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14498 if (! *p
|| p
== arg_start
)
14499 dwarf2_macro_malformed_definition_complaint (body
);
14502 /* Make sure argv has room for the new argument. */
14503 if (argc
>= argv_size
)
14506 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14509 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14512 p
= consume_improper_spaces (p
, body
);
14514 /* Consume the comma, if present. */
14519 p
= consume_improper_spaces (p
, body
);
14528 /* Perfectly formed definition, no complaints. */
14529 macro_define_function (file
, line
, name
,
14530 argc
, (const char **) argv
,
14532 else if (*p
== '\0')
14534 /* Complain, but do define it. */
14535 dwarf2_macro_malformed_definition_complaint (body
);
14536 macro_define_function (file
, line
, name
,
14537 argc
, (const char **) argv
,
14541 /* Just complain. */
14542 dwarf2_macro_malformed_definition_complaint (body
);
14545 /* Just complain. */
14546 dwarf2_macro_malformed_definition_complaint (body
);
14552 for (i
= 0; i
< argc
; i
++)
14558 dwarf2_macro_malformed_definition_complaint (body
);
14561 /* Skip some bytes from BYTES according to the form given in FORM.
14562 Returns the new pointer. */
14565 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
14566 enum dwarf_form form
,
14567 unsigned int offset_size
,
14568 struct dwarf2_section_info
*section
)
14570 unsigned int bytes_read
;
14574 case DW_FORM_data1
:
14579 case DW_FORM_data2
:
14583 case DW_FORM_data4
:
14587 case DW_FORM_data8
:
14591 case DW_FORM_string
:
14592 read_direct_string (abfd
, bytes
, &bytes_read
);
14593 bytes
+= bytes_read
;
14596 case DW_FORM_sec_offset
:
14598 bytes
+= offset_size
;
14601 case DW_FORM_block
:
14602 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
14603 bytes
+= bytes_read
;
14606 case DW_FORM_block1
:
14607 bytes
+= 1 + read_1_byte (abfd
, bytes
);
14609 case DW_FORM_block2
:
14610 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
14612 case DW_FORM_block4
:
14613 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
14616 case DW_FORM_sdata
:
14617 case DW_FORM_udata
:
14618 bytes
= skip_leb128 (abfd
, bytes
);
14624 complaint (&symfile_complaints
,
14625 _("invalid form 0x%x in `%s'"),
14627 section
->asection
->name
);
14635 /* A helper for dwarf_decode_macros that handles skipping an unknown
14636 opcode. Returns an updated pointer to the macro data buffer; or,
14637 on error, issues a complaint and returns NULL. */
14640 skip_unknown_opcode (unsigned int opcode
,
14641 gdb_byte
**opcode_definitions
,
14644 unsigned int offset_size
,
14645 struct dwarf2_section_info
*section
)
14647 unsigned int bytes_read
, i
;
14651 if (opcode_definitions
[opcode
] == NULL
)
14653 complaint (&symfile_complaints
,
14654 _("unrecognized DW_MACFINO opcode 0x%x"),
14659 defn
= opcode_definitions
[opcode
];
14660 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
14661 defn
+= bytes_read
;
14663 for (i
= 0; i
< arg
; ++i
)
14665 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
14666 if (mac_ptr
== NULL
)
14668 /* skip_form_bytes already issued the complaint. */
14676 /* A helper function which parses the header of a macro section.
14677 If the macro section is the extended (for now called "GNU") type,
14678 then this updates *OFFSET_SIZE. Returns a pointer to just after
14679 the header, or issues a complaint and returns NULL on error. */
14682 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
14685 unsigned int *offset_size
,
14686 int section_is_gnu
)
14688 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
14690 if (section_is_gnu
)
14692 unsigned int version
, flags
;
14694 version
= read_2_bytes (abfd
, mac_ptr
);
14697 complaint (&symfile_complaints
,
14698 _("unrecognized version `%d' in .debug_macro section"),
14704 flags
= read_1_byte (abfd
, mac_ptr
);
14706 *offset_size
= (flags
& 1) ? 8 : 4;
14708 if ((flags
& 2) != 0)
14709 /* We don't need the line table offset. */
14710 mac_ptr
+= *offset_size
;
14712 /* Vendor opcode descriptions. */
14713 if ((flags
& 4) != 0)
14715 unsigned int i
, count
;
14717 count
= read_1_byte (abfd
, mac_ptr
);
14719 for (i
= 0; i
< count
; ++i
)
14721 unsigned int opcode
, bytes_read
;
14724 opcode
= read_1_byte (abfd
, mac_ptr
);
14726 opcode_definitions
[opcode
] = mac_ptr
;
14727 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14728 mac_ptr
+= bytes_read
;
14737 /* A helper for dwarf_decode_macros that handles the GNU extensions,
14738 including DW_GNU_MACINFO_transparent_include. */
14741 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
14742 struct macro_source_file
*current_file
,
14743 struct line_header
*lh
, char *comp_dir
,
14744 struct dwarf2_section_info
*section
,
14745 int section_is_gnu
,
14746 unsigned int offset_size
,
14747 struct objfile
*objfile
)
14749 enum dwarf_macro_record_type macinfo_type
;
14750 int at_commandline
;
14751 gdb_byte
*opcode_definitions
[256];
14753 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
14754 &offset_size
, section_is_gnu
);
14755 if (mac_ptr
== NULL
)
14757 /* We already issued a complaint. */
14761 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14762 GDB is still reading the definitions from command line. First
14763 DW_MACINFO_start_file will need to be ignored as it was already executed
14764 to create CURRENT_FILE for the main source holding also the command line
14765 definitions. On first met DW_MACINFO_start_file this flag is reset to
14766 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14768 at_commandline
= 1;
14772 /* Do we at least have room for a macinfo type byte? */
14773 if (mac_ptr
>= mac_end
)
14775 dwarf2_macros_too_long_complaint (section
);
14779 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14782 /* Note that we rely on the fact that the corresponding GNU and
14783 DWARF constants are the same. */
14784 switch (macinfo_type
)
14786 /* A zero macinfo type indicates the end of the macro
14791 case DW_MACRO_GNU_define
:
14792 case DW_MACRO_GNU_undef
:
14793 case DW_MACRO_GNU_define_indirect
:
14794 case DW_MACRO_GNU_undef_indirect
:
14796 unsigned int bytes_read
;
14801 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14802 mac_ptr
+= bytes_read
;
14804 if (macinfo_type
== DW_MACRO_GNU_define
14805 || macinfo_type
== DW_MACRO_GNU_undef
)
14807 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14808 mac_ptr
+= bytes_read
;
14812 LONGEST str_offset
;
14814 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
14815 mac_ptr
+= offset_size
;
14817 body
= read_indirect_string_at_offset (abfd
, str_offset
);
14820 is_define
= (macinfo_type
== DW_MACRO_GNU_define
14821 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
14822 if (! current_file
)
14824 /* DWARF violation as no main source is present. */
14825 complaint (&symfile_complaints
,
14826 _("debug info with no main source gives macro %s "
14828 is_define
? _("definition") : _("undefinition"),
14832 if ((line
== 0 && !at_commandline
)
14833 || (line
!= 0 && at_commandline
))
14834 complaint (&symfile_complaints
,
14835 _("debug info gives %s macro %s with %s line %d: %s"),
14836 at_commandline
? _("command-line") : _("in-file"),
14837 is_define
? _("definition") : _("undefinition"),
14838 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
14841 parse_macro_definition (current_file
, line
, body
);
14844 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
14845 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
14846 macro_undef (current_file
, line
, body
);
14851 case DW_MACRO_GNU_start_file
:
14853 unsigned int bytes_read
;
14856 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14857 mac_ptr
+= bytes_read
;
14858 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14859 mac_ptr
+= bytes_read
;
14861 if ((line
== 0 && !at_commandline
)
14862 || (line
!= 0 && at_commandline
))
14863 complaint (&symfile_complaints
,
14864 _("debug info gives source %d included "
14865 "from %s at %s line %d"),
14866 file
, at_commandline
? _("command-line") : _("file"),
14867 line
== 0 ? _("zero") : _("non-zero"), line
);
14869 if (at_commandline
)
14871 /* This DW_MACRO_GNU_start_file was executed in the
14873 at_commandline
= 0;
14876 current_file
= macro_start_file (file
, line
,
14877 current_file
, comp_dir
,
14882 case DW_MACRO_GNU_end_file
:
14883 if (! current_file
)
14884 complaint (&symfile_complaints
,
14885 _("macro debug info has an unmatched "
14886 "`close_file' directive"));
14889 current_file
= current_file
->included_by
;
14890 if (! current_file
)
14892 enum dwarf_macro_record_type next_type
;
14894 /* GCC circa March 2002 doesn't produce the zero
14895 type byte marking the end of the compilation
14896 unit. Complain if it's not there, but exit no
14899 /* Do we at least have room for a macinfo type byte? */
14900 if (mac_ptr
>= mac_end
)
14902 dwarf2_macros_too_long_complaint (section
);
14906 /* We don't increment mac_ptr here, so this is just
14908 next_type
= read_1_byte (abfd
, mac_ptr
);
14909 if (next_type
!= 0)
14910 complaint (&symfile_complaints
,
14911 _("no terminating 0-type entry for "
14912 "macros in `.debug_macinfo' section"));
14919 case DW_MACRO_GNU_transparent_include
:
14923 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
14924 mac_ptr
+= offset_size
;
14926 dwarf_decode_macro_bytes (abfd
,
14927 section
->buffer
+ offset
,
14928 mac_end
, current_file
,
14930 section
, section_is_gnu
,
14931 offset_size
, objfile
);
14935 case DW_MACINFO_vendor_ext
:
14936 if (!section_is_gnu
)
14938 unsigned int bytes_read
;
14941 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14942 mac_ptr
+= bytes_read
;
14943 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14944 mac_ptr
+= bytes_read
;
14946 /* We don't recognize any vendor extensions. */
14952 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
14953 mac_ptr
, abfd
, offset_size
,
14955 if (mac_ptr
== NULL
)
14959 } while (macinfo_type
!= 0);
14963 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
14964 char *comp_dir
, bfd
*abfd
,
14965 struct dwarf2_cu
*cu
,
14966 struct dwarf2_section_info
*section
,
14967 int section_is_gnu
)
14969 gdb_byte
*mac_ptr
, *mac_end
;
14970 struct macro_source_file
*current_file
= 0;
14971 enum dwarf_macro_record_type macinfo_type
;
14972 unsigned int offset_size
= cu
->header
.offset_size
;
14973 gdb_byte
*opcode_definitions
[256];
14975 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
14976 if (section
->buffer
== NULL
)
14978 complaint (&symfile_complaints
, _("missing %s section"),
14979 section
->asection
->name
);
14983 /* First pass: Find the name of the base filename.
14984 This filename is needed in order to process all macros whose definition
14985 (or undefinition) comes from the command line. These macros are defined
14986 before the first DW_MACINFO_start_file entry, and yet still need to be
14987 associated to the base file.
14989 To determine the base file name, we scan the macro definitions until we
14990 reach the first DW_MACINFO_start_file entry. We then initialize
14991 CURRENT_FILE accordingly so that any macro definition found before the
14992 first DW_MACINFO_start_file can still be associated to the base file. */
14994 mac_ptr
= section
->buffer
+ offset
;
14995 mac_end
= section
->buffer
+ section
->size
;
14997 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
14998 &offset_size
, section_is_gnu
);
14999 if (mac_ptr
== NULL
)
15001 /* We already issued a complaint. */
15007 /* Do we at least have room for a macinfo type byte? */
15008 if (mac_ptr
>= mac_end
)
15010 /* Complaint is printed during the second pass as GDB will probably
15011 stop the first pass earlier upon finding
15012 DW_MACINFO_start_file. */
15016 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15019 /* Note that we rely on the fact that the corresponding GNU and
15020 DWARF constants are the same. */
15021 switch (macinfo_type
)
15023 /* A zero macinfo type indicates the end of the macro
15028 case DW_MACRO_GNU_define
:
15029 case DW_MACRO_GNU_undef
:
15030 /* Only skip the data by MAC_PTR. */
15032 unsigned int bytes_read
;
15034 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15035 mac_ptr
+= bytes_read
;
15036 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15037 mac_ptr
+= bytes_read
;
15041 case DW_MACRO_GNU_start_file
:
15043 unsigned int bytes_read
;
15046 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15047 mac_ptr
+= bytes_read
;
15048 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15049 mac_ptr
+= bytes_read
;
15051 current_file
= macro_start_file (file
, line
, current_file
,
15052 comp_dir
, lh
, cu
->objfile
);
15056 case DW_MACRO_GNU_end_file
:
15057 /* No data to skip by MAC_PTR. */
15060 case DW_MACRO_GNU_define_indirect
:
15061 case DW_MACRO_GNU_undef_indirect
:
15063 unsigned int bytes_read
;
15065 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15066 mac_ptr
+= bytes_read
;
15067 mac_ptr
+= offset_size
;
15071 case DW_MACRO_GNU_transparent_include
:
15072 /* Note that, according to the spec, a transparent include
15073 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15074 skip this opcode. */
15075 mac_ptr
+= offset_size
;
15078 case DW_MACINFO_vendor_ext
:
15079 /* Only skip the data by MAC_PTR. */
15080 if (!section_is_gnu
)
15082 unsigned int bytes_read
;
15084 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15085 mac_ptr
+= bytes_read
;
15086 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15087 mac_ptr
+= bytes_read
;
15092 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15093 mac_ptr
, abfd
, offset_size
,
15095 if (mac_ptr
== NULL
)
15099 } while (macinfo_type
!= 0 && current_file
== NULL
);
15101 /* Second pass: Process all entries.
15103 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15104 command-line macro definitions/undefinitions. This flag is unset when we
15105 reach the first DW_MACINFO_start_file entry. */
15107 dwarf_decode_macro_bytes (abfd
, section
->buffer
+ offset
, mac_end
,
15108 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
15109 offset_size
, cu
->objfile
);
15112 /* Check if the attribute's form is a DW_FORM_block*
15113 if so return true else false. */
15115 attr_form_is_block (struct attribute
*attr
)
15117 return (attr
== NULL
? 0 :
15118 attr
->form
== DW_FORM_block1
15119 || attr
->form
== DW_FORM_block2
15120 || attr
->form
== DW_FORM_block4
15121 || attr
->form
== DW_FORM_block
15122 || attr
->form
== DW_FORM_exprloc
);
15125 /* Return non-zero if ATTR's value is a section offset --- classes
15126 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15127 You may use DW_UNSND (attr) to retrieve such offsets.
15129 Section 7.5.4, "Attribute Encodings", explains that no attribute
15130 may have a value that belongs to more than one of these classes; it
15131 would be ambiguous if we did, because we use the same forms for all
15134 attr_form_is_section_offset (struct attribute
*attr
)
15136 return (attr
->form
== DW_FORM_data4
15137 || attr
->form
== DW_FORM_data8
15138 || attr
->form
== DW_FORM_sec_offset
);
15142 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15143 zero otherwise. When this function returns true, you can apply
15144 dwarf2_get_attr_constant_value to it.
15146 However, note that for some attributes you must check
15147 attr_form_is_section_offset before using this test. DW_FORM_data4
15148 and DW_FORM_data8 are members of both the constant class, and of
15149 the classes that contain offsets into other debug sections
15150 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15151 that, if an attribute's can be either a constant or one of the
15152 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15153 taken as section offsets, not constants. */
15155 attr_form_is_constant (struct attribute
*attr
)
15157 switch (attr
->form
)
15159 case DW_FORM_sdata
:
15160 case DW_FORM_udata
:
15161 case DW_FORM_data1
:
15162 case DW_FORM_data2
:
15163 case DW_FORM_data4
:
15164 case DW_FORM_data8
:
15171 /* A helper function that fills in a dwarf2_loclist_baton. */
15174 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15175 struct dwarf2_loclist_baton
*baton
,
15176 struct attribute
*attr
)
15178 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15179 &dwarf2_per_objfile
->loc
);
15181 baton
->per_cu
= cu
->per_cu
;
15182 gdb_assert (baton
->per_cu
);
15183 /* We don't know how long the location list is, but make sure we
15184 don't run off the edge of the section. */
15185 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15186 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15187 baton
->base_address
= cu
->base_address
;
15191 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15192 struct dwarf2_cu
*cu
)
15194 if (attr_form_is_section_offset (attr
)
15195 /* ".debug_loc" may not exist at all, or the offset may be outside
15196 the section. If so, fall through to the complaint in the
15198 && DW_UNSND (attr
) < dwarf2_section_size (dwarf2_per_objfile
->objfile
,
15199 &dwarf2_per_objfile
->loc
))
15201 struct dwarf2_loclist_baton
*baton
;
15203 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
15204 sizeof (struct dwarf2_loclist_baton
));
15206 fill_in_loclist_baton (cu
, baton
, attr
);
15208 if (cu
->base_known
== 0)
15209 complaint (&symfile_complaints
,
15210 _("Location list used without "
15211 "specifying the CU base address."));
15213 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15214 SYMBOL_LOCATION_BATON (sym
) = baton
;
15218 struct dwarf2_locexpr_baton
*baton
;
15220 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
15221 sizeof (struct dwarf2_locexpr_baton
));
15222 baton
->per_cu
= cu
->per_cu
;
15223 gdb_assert (baton
->per_cu
);
15225 if (attr_form_is_block (attr
))
15227 /* Note that we're just copying the block's data pointer
15228 here, not the actual data. We're still pointing into the
15229 info_buffer for SYM's objfile; right now we never release
15230 that buffer, but when we do clean up properly this may
15232 baton
->size
= DW_BLOCK (attr
)->size
;
15233 baton
->data
= DW_BLOCK (attr
)->data
;
15237 dwarf2_invalid_attrib_class_complaint ("location description",
15238 SYMBOL_NATURAL_NAME (sym
));
15240 baton
->data
= NULL
;
15243 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15244 SYMBOL_LOCATION_BATON (sym
) = baton
;
15248 /* Return the OBJFILE associated with the compilation unit CU. If CU
15249 came from a separate debuginfo file, then the master objfile is
15253 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
15255 struct objfile
*objfile
= per_cu
->objfile
;
15257 /* Return the master objfile, so that we can report and look up the
15258 correct file containing this variable. */
15259 if (objfile
->separate_debug_objfile_backlink
)
15260 objfile
= objfile
->separate_debug_objfile_backlink
;
15265 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15266 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15267 CU_HEADERP first. */
15269 static const struct comp_unit_head
*
15270 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
15271 struct dwarf2_per_cu_data
*per_cu
)
15273 struct objfile
*objfile
;
15274 struct dwarf2_per_objfile
*per_objfile
;
15275 gdb_byte
*info_ptr
;
15278 return &per_cu
->cu
->header
;
15280 objfile
= per_cu
->objfile
;
15281 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15282 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
15284 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
15285 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
15290 /* Return the address size given in the compilation unit header for CU. */
15293 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15295 struct comp_unit_head cu_header_local
;
15296 const struct comp_unit_head
*cu_headerp
;
15298 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15300 return cu_headerp
->addr_size
;
15303 /* Return the offset size given in the compilation unit header for CU. */
15306 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
15308 struct comp_unit_head cu_header_local
;
15309 const struct comp_unit_head
*cu_headerp
;
15311 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15313 return cu_headerp
->offset_size
;
15316 /* Return the text offset of the CU. The returned offset comes from
15317 this CU's objfile. If this objfile came from a separate debuginfo
15318 file, then the offset may be different from the corresponding
15319 offset in the parent objfile. */
15322 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
15324 struct objfile
*objfile
= per_cu
->objfile
;
15326 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15329 /* Locate the .debug_info compilation unit from CU's objfile which contains
15330 the DIE at OFFSET. Raises an error on failure. */
15332 static struct dwarf2_per_cu_data
*
15333 dwarf2_find_containing_comp_unit (unsigned int offset
,
15334 struct objfile
*objfile
)
15336 struct dwarf2_per_cu_data
*this_cu
;
15340 high
= dwarf2_per_objfile
->n_comp_units
- 1;
15343 int mid
= low
+ (high
- low
) / 2;
15345 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
15350 gdb_assert (low
== high
);
15351 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
15354 error (_("Dwarf Error: could not find partial DIE containing "
15355 "offset 0x%lx [in module %s]"),
15356 (long) offset
, bfd_get_filename (objfile
->obfd
));
15358 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
15359 return dwarf2_per_objfile
->all_comp_units
[low
-1];
15363 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
15364 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
15365 && offset
>= this_cu
->offset
+ this_cu
->length
)
15366 error (_("invalid dwarf2 offset %u"), offset
);
15367 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
15372 /* Locate the compilation unit from OBJFILE which is located at exactly
15373 OFFSET. Raises an error on failure. */
15375 static struct dwarf2_per_cu_data
*
15376 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
15378 struct dwarf2_per_cu_data
*this_cu
;
15380 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
15381 if (this_cu
->offset
!= offset
)
15382 error (_("no compilation unit with offset %u."), offset
);
15386 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
15389 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
15391 memset (cu
, 0, sizeof (*cu
));
15392 cu
->objfile
= objfile
;
15393 obstack_init (&cu
->comp_unit_obstack
);
15396 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15399 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
15401 struct attribute
*attr
;
15403 /* Set the language we're debugging. */
15404 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
15406 set_cu_language (DW_UNSND (attr
), cu
);
15409 cu
->language
= language_minimal
;
15410 cu
->language_defn
= language_def (cu
->language
);
15414 /* Release one cached compilation unit, CU. We unlink it from the tree
15415 of compilation units, but we don't remove it from the read_in_chain;
15416 the caller is responsible for that.
15417 NOTE: DATA is a void * because this function is also used as a
15418 cleanup routine. */
15421 free_one_comp_unit (void *data
)
15423 struct dwarf2_cu
*cu
= data
;
15425 if (cu
->per_cu
!= NULL
)
15426 cu
->per_cu
->cu
= NULL
;
15429 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15434 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15435 when we're finished with it. We can't free the pointer itself, but be
15436 sure to unlink it from the cache. Also release any associated storage
15437 and perform cache maintenance.
15439 Only used during partial symbol parsing. */
15442 free_stack_comp_unit (void *data
)
15444 struct dwarf2_cu
*cu
= data
;
15446 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15447 cu
->partial_dies
= NULL
;
15449 if (cu
->per_cu
!= NULL
)
15451 /* This compilation unit is on the stack in our caller, so we
15452 should not xfree it. Just unlink it. */
15453 cu
->per_cu
->cu
= NULL
;
15456 /* If we had a per-cu pointer, then we may have other compilation
15457 units loaded, so age them now. */
15458 age_cached_comp_units ();
15462 /* Free all cached compilation units. */
15465 free_cached_comp_units (void *data
)
15467 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15469 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15470 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15471 while (per_cu
!= NULL
)
15473 struct dwarf2_per_cu_data
*next_cu
;
15475 next_cu
= per_cu
->cu
->read_in_chain
;
15477 free_one_comp_unit (per_cu
->cu
);
15478 *last_chain
= next_cu
;
15484 /* Increase the age counter on each cached compilation unit, and free
15485 any that are too old. */
15488 age_cached_comp_units (void)
15490 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15492 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
15493 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15494 while (per_cu
!= NULL
)
15496 per_cu
->cu
->last_used
++;
15497 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
15498 dwarf2_mark (per_cu
->cu
);
15499 per_cu
= per_cu
->cu
->read_in_chain
;
15502 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15503 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15504 while (per_cu
!= NULL
)
15506 struct dwarf2_per_cu_data
*next_cu
;
15508 next_cu
= per_cu
->cu
->read_in_chain
;
15510 if (!per_cu
->cu
->mark
)
15512 free_one_comp_unit (per_cu
->cu
);
15513 *last_chain
= next_cu
;
15516 last_chain
= &per_cu
->cu
->read_in_chain
;
15522 /* Remove a single compilation unit from the cache. */
15525 free_one_cached_comp_unit (void *target_cu
)
15527 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15529 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15530 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15531 while (per_cu
!= NULL
)
15533 struct dwarf2_per_cu_data
*next_cu
;
15535 next_cu
= per_cu
->cu
->read_in_chain
;
15537 if (per_cu
->cu
== target_cu
)
15539 free_one_comp_unit (per_cu
->cu
);
15540 *last_chain
= next_cu
;
15544 last_chain
= &per_cu
->cu
->read_in_chain
;
15550 /* Release all extra memory associated with OBJFILE. */
15553 dwarf2_free_objfile (struct objfile
*objfile
)
15555 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15557 if (dwarf2_per_objfile
== NULL
)
15560 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
15561 free_cached_comp_units (NULL
);
15563 if (dwarf2_per_objfile
->quick_file_names_table
)
15564 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
15566 /* Everything else should be on the objfile obstack. */
15569 /* A pair of DIE offset and GDB type pointer. We store these
15570 in a hash table separate from the DIEs, and preserve them
15571 when the DIEs are flushed out of cache. */
15573 struct dwarf2_offset_and_type
15575 unsigned int offset
;
15579 /* Hash function for a dwarf2_offset_and_type. */
15582 offset_and_type_hash (const void *item
)
15584 const struct dwarf2_offset_and_type
*ofs
= item
;
15586 return ofs
->offset
;
15589 /* Equality function for a dwarf2_offset_and_type. */
15592 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
15594 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
15595 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
15597 return ofs_lhs
->offset
== ofs_rhs
->offset
;
15600 /* Set the type associated with DIE to TYPE. Save it in CU's hash
15601 table if necessary. For convenience, return TYPE.
15603 The DIEs reading must have careful ordering to:
15604 * Not cause infite loops trying to read in DIEs as a prerequisite for
15605 reading current DIE.
15606 * Not trying to dereference contents of still incompletely read in types
15607 while reading in other DIEs.
15608 * Enable referencing still incompletely read in types just by a pointer to
15609 the type without accessing its fields.
15611 Therefore caller should follow these rules:
15612 * Try to fetch any prerequisite types we may need to build this DIE type
15613 before building the type and calling set_die_type.
15614 * After building type call set_die_type for current DIE as soon as
15615 possible before fetching more types to complete the current type.
15616 * Make the type as complete as possible before fetching more types. */
15618 static struct type
*
15619 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
15621 struct dwarf2_offset_and_type
**slot
, ofs
;
15622 struct objfile
*objfile
= cu
->objfile
;
15623 htab_t
*type_hash_ptr
;
15625 /* For Ada types, make sure that the gnat-specific data is always
15626 initialized (if not already set). There are a few types where
15627 we should not be doing so, because the type-specific area is
15628 already used to hold some other piece of info (eg: TYPE_CODE_FLT
15629 where the type-specific area is used to store the floatformat).
15630 But this is not a problem, because the gnat-specific information
15631 is actually not needed for these types. */
15632 if (need_gnat_info (cu
)
15633 && TYPE_CODE (type
) != TYPE_CODE_FUNC
15634 && TYPE_CODE (type
) != TYPE_CODE_FLT
15635 && !HAVE_GNAT_AUX_INFO (type
))
15636 INIT_GNAT_SPECIFIC (type
);
15638 if (cu
->per_cu
->debug_type_section
)
15639 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
15641 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
15643 if (*type_hash_ptr
== NULL
)
15646 = htab_create_alloc_ex (127,
15647 offset_and_type_hash
,
15648 offset_and_type_eq
,
15650 &objfile
->objfile_obstack
,
15651 hashtab_obstack_allocate
,
15652 dummy_obstack_deallocate
);
15655 ofs
.offset
= die
->offset
;
15657 slot
= (struct dwarf2_offset_and_type
**)
15658 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
15660 complaint (&symfile_complaints
,
15661 _("A problem internal to GDB: DIE 0x%x has type already set"),
15663 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
15668 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
15669 table, or return NULL if the die does not have a saved type. */
15671 static struct type
*
15672 get_die_type_at_offset (unsigned int offset
,
15673 struct dwarf2_per_cu_data
*per_cu
)
15675 struct dwarf2_offset_and_type
*slot
, ofs
;
15678 if (per_cu
->debug_type_section
)
15679 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
15681 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
15682 if (type_hash
== NULL
)
15685 ofs
.offset
= offset
;
15686 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
15693 /* Look up the type for DIE in the appropriate type_hash table,
15694 or return NULL if DIE does not have a saved type. */
15696 static struct type
*
15697 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15699 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
15702 /* Add a dependence relationship from CU to REF_PER_CU. */
15705 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
15706 struct dwarf2_per_cu_data
*ref_per_cu
)
15710 if (cu
->dependencies
== NULL
)
15712 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
15713 NULL
, &cu
->comp_unit_obstack
,
15714 hashtab_obstack_allocate
,
15715 dummy_obstack_deallocate
);
15717 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
15719 *slot
= ref_per_cu
;
15722 /* Subroutine of dwarf2_mark to pass to htab_traverse.
15723 Set the mark field in every compilation unit in the
15724 cache that we must keep because we are keeping CU. */
15727 dwarf2_mark_helper (void **slot
, void *data
)
15729 struct dwarf2_per_cu_data
*per_cu
;
15731 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
15733 /* cu->dependencies references may not yet have been ever read if QUIT aborts
15734 reading of the chain. As such dependencies remain valid it is not much
15735 useful to track and undo them during QUIT cleanups. */
15736 if (per_cu
->cu
== NULL
)
15739 if (per_cu
->cu
->mark
)
15741 per_cu
->cu
->mark
= 1;
15743 if (per_cu
->cu
->dependencies
!= NULL
)
15744 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15749 /* Set the mark field in CU and in every other compilation unit in the
15750 cache that we must keep because we are keeping CU. */
15753 dwarf2_mark (struct dwarf2_cu
*cu
)
15758 if (cu
->dependencies
!= NULL
)
15759 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15763 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
15767 per_cu
->cu
->mark
= 0;
15768 per_cu
= per_cu
->cu
->read_in_chain
;
15772 /* Trivial hash function for partial_die_info: the hash value of a DIE
15773 is its offset in .debug_info for this objfile. */
15776 partial_die_hash (const void *item
)
15778 const struct partial_die_info
*part_die
= item
;
15780 return part_die
->offset
;
15783 /* Trivial comparison function for partial_die_info structures: two DIEs
15784 are equal if they have the same offset. */
15787 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
15789 const struct partial_die_info
*part_die_lhs
= item_lhs
;
15790 const struct partial_die_info
*part_die_rhs
= item_rhs
;
15792 return part_die_lhs
->offset
== part_die_rhs
->offset
;
15795 static struct cmd_list_element
*set_dwarf2_cmdlist
;
15796 static struct cmd_list_element
*show_dwarf2_cmdlist
;
15799 set_dwarf2_cmd (char *args
, int from_tty
)
15801 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
15805 show_dwarf2_cmd (char *args
, int from_tty
)
15807 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
15810 /* If section described by INFO was mmapped, munmap it now. */
15813 munmap_section_buffer (struct dwarf2_section_info
*info
)
15815 if (info
->map_addr
!= NULL
)
15820 res
= munmap (info
->map_addr
, info
->map_len
);
15821 gdb_assert (res
== 0);
15823 /* Without HAVE_MMAP, we should never be here to begin with. */
15824 gdb_assert_not_reached ("no mmap support");
15829 /* munmap debug sections for OBJFILE, if necessary. */
15832 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
15834 struct dwarf2_per_objfile
*data
= d
;
15836 struct dwarf2_section_info
*section
;
15838 /* This is sorted according to the order they're defined in to make it easier
15839 to keep in sync. */
15840 munmap_section_buffer (&data
->info
);
15841 munmap_section_buffer (&data
->abbrev
);
15842 munmap_section_buffer (&data
->line
);
15843 munmap_section_buffer (&data
->loc
);
15844 munmap_section_buffer (&data
->macinfo
);
15845 munmap_section_buffer (&data
->macro
);
15846 munmap_section_buffer (&data
->str
);
15847 munmap_section_buffer (&data
->ranges
);
15848 munmap_section_buffer (&data
->frame
);
15849 munmap_section_buffer (&data
->eh_frame
);
15850 munmap_section_buffer (&data
->gdb_index
);
15853 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
15855 munmap_section_buffer (section
);
15857 VEC_free (dwarf2_section_info_def
, data
->types
);
15861 /* The "save gdb-index" command. */
15863 /* The contents of the hash table we create when building the string
15865 struct strtab_entry
15867 offset_type offset
;
15871 /* Hash function for a strtab_entry.
15873 Function is used only during write_hash_table so no index format backward
15874 compatibility is needed. */
15877 hash_strtab_entry (const void *e
)
15879 const struct strtab_entry
*entry
= e
;
15880 return mapped_index_string_hash (INT_MAX
, entry
->str
);
15883 /* Equality function for a strtab_entry. */
15886 eq_strtab_entry (const void *a
, const void *b
)
15888 const struct strtab_entry
*ea
= a
;
15889 const struct strtab_entry
*eb
= b
;
15890 return !strcmp (ea
->str
, eb
->str
);
15893 /* Create a strtab_entry hash table. */
15896 create_strtab (void)
15898 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
15899 xfree
, xcalloc
, xfree
);
15902 /* Add a string to the constant pool. Return the string's offset in
15906 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
15909 struct strtab_entry entry
;
15910 struct strtab_entry
*result
;
15913 slot
= htab_find_slot (table
, &entry
, INSERT
);
15918 result
= XNEW (struct strtab_entry
);
15919 result
->offset
= obstack_object_size (cpool
);
15921 obstack_grow_str0 (cpool
, str
);
15924 return result
->offset
;
15927 /* An entry in the symbol table. */
15928 struct symtab_index_entry
15930 /* The name of the symbol. */
15932 /* The offset of the name in the constant pool. */
15933 offset_type index_offset
;
15934 /* A sorted vector of the indices of all the CUs that hold an object
15936 VEC (offset_type
) *cu_indices
;
15939 /* The symbol table. This is a power-of-2-sized hash table. */
15940 struct mapped_symtab
15942 offset_type n_elements
;
15944 struct symtab_index_entry
**data
;
15947 /* Hash function for a symtab_index_entry. */
15950 hash_symtab_entry (const void *e
)
15952 const struct symtab_index_entry
*entry
= e
;
15953 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
15954 sizeof (offset_type
) * VEC_length (offset_type
,
15955 entry
->cu_indices
),
15959 /* Equality function for a symtab_index_entry. */
15962 eq_symtab_entry (const void *a
, const void *b
)
15964 const struct symtab_index_entry
*ea
= a
;
15965 const struct symtab_index_entry
*eb
= b
;
15966 int len
= VEC_length (offset_type
, ea
->cu_indices
);
15967 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
15969 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
15970 VEC_address (offset_type
, eb
->cu_indices
),
15971 sizeof (offset_type
) * len
);
15974 /* Destroy a symtab_index_entry. */
15977 delete_symtab_entry (void *p
)
15979 struct symtab_index_entry
*entry
= p
;
15980 VEC_free (offset_type
, entry
->cu_indices
);
15984 /* Create a hash table holding symtab_index_entry objects. */
15987 create_symbol_hash_table (void)
15989 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
15990 delete_symtab_entry
, xcalloc
, xfree
);
15993 /* Create a new mapped symtab object. */
15995 static struct mapped_symtab
*
15996 create_mapped_symtab (void)
15998 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
15999 symtab
->n_elements
= 0;
16000 symtab
->size
= 1024;
16001 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16005 /* Destroy a mapped_symtab. */
16008 cleanup_mapped_symtab (void *p
)
16010 struct mapped_symtab
*symtab
= p
;
16011 /* The contents of the array are freed when the other hash table is
16013 xfree (symtab
->data
);
16017 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16020 Function is used only during write_hash_table so no index format backward
16021 compatibility is needed. */
16023 static struct symtab_index_entry
**
16024 find_slot (struct mapped_symtab
*symtab
, const char *name
)
16026 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
16028 index
= hash
& (symtab
->size
- 1);
16029 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
16033 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
16034 return &symtab
->data
[index
];
16035 index
= (index
+ step
) & (symtab
->size
- 1);
16039 /* Expand SYMTAB's hash table. */
16042 hash_expand (struct mapped_symtab
*symtab
)
16044 offset_type old_size
= symtab
->size
;
16046 struct symtab_index_entry
**old_entries
= symtab
->data
;
16049 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16051 for (i
= 0; i
< old_size
; ++i
)
16053 if (old_entries
[i
])
16055 struct symtab_index_entry
**slot
= find_slot (symtab
,
16056 old_entries
[i
]->name
);
16057 *slot
= old_entries
[i
];
16061 xfree (old_entries
);
16064 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16065 is the index of the CU in which the symbol appears. */
16068 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
16069 offset_type cu_index
)
16071 struct symtab_index_entry
**slot
;
16073 ++symtab
->n_elements
;
16074 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
16075 hash_expand (symtab
);
16077 slot
= find_slot (symtab
, name
);
16080 *slot
= XNEW (struct symtab_index_entry
);
16081 (*slot
)->name
= name
;
16082 (*slot
)->cu_indices
= NULL
;
16084 /* Don't push an index twice. Due to how we add entries we only
16085 have to check the last one. */
16086 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
16087 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
16088 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
16091 /* Add a vector of indices to the constant pool. */
16094 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
16095 struct symtab_index_entry
*entry
)
16099 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
16102 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
16103 offset_type val
= MAYBE_SWAP (len
);
16108 entry
->index_offset
= obstack_object_size (cpool
);
16110 obstack_grow (cpool
, &val
, sizeof (val
));
16112 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
16115 val
= MAYBE_SWAP (iter
);
16116 obstack_grow (cpool
, &val
, sizeof (val
));
16121 struct symtab_index_entry
*old_entry
= *slot
;
16122 entry
->index_offset
= old_entry
->index_offset
;
16125 return entry
->index_offset
;
16128 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16129 constant pool entries going into the obstack CPOOL. */
16132 write_hash_table (struct mapped_symtab
*symtab
,
16133 struct obstack
*output
, struct obstack
*cpool
)
16136 htab_t symbol_hash_table
;
16139 symbol_hash_table
= create_symbol_hash_table ();
16140 str_table
= create_strtab ();
16142 /* We add all the index vectors to the constant pool first, to
16143 ensure alignment is ok. */
16144 for (i
= 0; i
< symtab
->size
; ++i
)
16146 if (symtab
->data
[i
])
16147 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
16150 /* Now write out the hash table. */
16151 for (i
= 0; i
< symtab
->size
; ++i
)
16153 offset_type str_off
, vec_off
;
16155 if (symtab
->data
[i
])
16157 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
16158 vec_off
= symtab
->data
[i
]->index_offset
;
16162 /* While 0 is a valid constant pool index, it is not valid
16163 to have 0 for both offsets. */
16168 str_off
= MAYBE_SWAP (str_off
);
16169 vec_off
= MAYBE_SWAP (vec_off
);
16171 obstack_grow (output
, &str_off
, sizeof (str_off
));
16172 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
16175 htab_delete (str_table
);
16176 htab_delete (symbol_hash_table
);
16179 /* Struct to map psymtab to CU index in the index file. */
16180 struct psymtab_cu_index_map
16182 struct partial_symtab
*psymtab
;
16183 unsigned int cu_index
;
16187 hash_psymtab_cu_index (const void *item
)
16189 const struct psymtab_cu_index_map
*map
= item
;
16191 return htab_hash_pointer (map
->psymtab
);
16195 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16197 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16198 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16200 return lhs
->psymtab
== rhs
->psymtab
;
16203 /* Helper struct for building the address table. */
16204 struct addrmap_index_data
16206 struct objfile
*objfile
;
16207 struct obstack
*addr_obstack
;
16208 htab_t cu_index_htab
;
16210 /* Non-zero if the previous_* fields are valid.
16211 We can't write an entry until we see the next entry (since it is only then
16212 that we know the end of the entry). */
16213 int previous_valid
;
16214 /* Index of the CU in the table of all CUs in the index file. */
16215 unsigned int previous_cu_index
;
16216 /* Start address of the CU. */
16217 CORE_ADDR previous_cu_start
;
16220 /* Write an address entry to OBSTACK. */
16223 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16224 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16226 offset_type cu_index_to_write
;
16228 CORE_ADDR baseaddr
;
16230 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16232 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16233 obstack_grow (obstack
, addr
, 8);
16234 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16235 obstack_grow (obstack
, addr
, 8);
16236 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16237 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16240 /* Worker function for traversing an addrmap to build the address table. */
16243 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
16245 struct addrmap_index_data
*data
= datap
;
16246 struct partial_symtab
*pst
= obj
;
16247 offset_type cu_index
;
16250 if (data
->previous_valid
)
16251 add_address_entry (data
->objfile
, data
->addr_obstack
,
16252 data
->previous_cu_start
, start_addr
,
16253 data
->previous_cu_index
);
16255 data
->previous_cu_start
= start_addr
;
16258 struct psymtab_cu_index_map find_map
, *map
;
16259 find_map
.psymtab
= pst
;
16260 map
= htab_find (data
->cu_index_htab
, &find_map
);
16261 gdb_assert (map
!= NULL
);
16262 data
->previous_cu_index
= map
->cu_index
;
16263 data
->previous_valid
= 1;
16266 data
->previous_valid
= 0;
16271 /* Write OBJFILE's address map to OBSTACK.
16272 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16273 in the index file. */
16276 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
16277 htab_t cu_index_htab
)
16279 struct addrmap_index_data addrmap_index_data
;
16281 /* When writing the address table, we have to cope with the fact that
16282 the addrmap iterator only provides the start of a region; we have to
16283 wait until the next invocation to get the start of the next region. */
16285 addrmap_index_data
.objfile
= objfile
;
16286 addrmap_index_data
.addr_obstack
= obstack
;
16287 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
16288 addrmap_index_data
.previous_valid
= 0;
16290 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
16291 &addrmap_index_data
);
16293 /* It's highly unlikely the last entry (end address = 0xff...ff)
16294 is valid, but we should still handle it.
16295 The end address is recorded as the start of the next region, but that
16296 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16298 if (addrmap_index_data
.previous_valid
)
16299 add_address_entry (objfile
, obstack
,
16300 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
16301 addrmap_index_data
.previous_cu_index
);
16304 /* Add a list of partial symbols to SYMTAB. */
16307 write_psymbols (struct mapped_symtab
*symtab
,
16309 struct partial_symbol
**psymp
,
16311 offset_type cu_index
,
16314 for (; count
-- > 0; ++psymp
)
16316 void **slot
, *lookup
;
16318 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
16319 error (_("Ada is not currently supported by the index"));
16321 /* We only want to add a given psymbol once. However, we also
16322 want to account for whether it is global or static. So, we
16323 may add it twice, using slightly different values. */
16326 uintptr_t val
= 1 | (uintptr_t) *psymp
;
16328 lookup
= (void *) val
;
16333 /* Only add a given psymbol once. */
16334 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
16338 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
16343 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16344 exception if there is an error. */
16347 write_obstack (FILE *file
, struct obstack
*obstack
)
16349 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
16351 != obstack_object_size (obstack
))
16352 error (_("couldn't data write to file"));
16355 /* Unlink a file if the argument is not NULL. */
16358 unlink_if_set (void *p
)
16360 char **filename
= p
;
16362 unlink (*filename
);
16365 /* A helper struct used when iterating over debug_types. */
16366 struct signatured_type_index_data
16368 struct objfile
*objfile
;
16369 struct mapped_symtab
*symtab
;
16370 struct obstack
*types_list
;
16375 /* A helper function that writes a single signatured_type to an
16379 write_one_signatured_type (void **slot
, void *d
)
16381 struct signatured_type_index_data
*info
= d
;
16382 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
16383 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
16384 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16387 write_psymbols (info
->symtab
,
16389 info
->objfile
->global_psymbols
.list
16390 + psymtab
->globals_offset
,
16391 psymtab
->n_global_syms
, info
->cu_index
,
16393 write_psymbols (info
->symtab
,
16395 info
->objfile
->static_psymbols
.list
16396 + psymtab
->statics_offset
,
16397 psymtab
->n_static_syms
, info
->cu_index
,
16400 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->per_cu
.offset
);
16401 obstack_grow (info
->types_list
, val
, 8);
16402 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
16403 obstack_grow (info
->types_list
, val
, 8);
16404 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
16405 obstack_grow (info
->types_list
, val
, 8);
16412 /* A cleanup function for an htab_t. */
16415 cleanup_htab (void *arg
)
16420 /* Create an index file for OBJFILE in the directory DIR. */
16423 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
16425 struct cleanup
*cleanup
;
16426 char *filename
, *cleanup_filename
;
16427 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
16428 struct obstack cu_list
, types_cu_list
;
16431 struct mapped_symtab
*symtab
;
16432 offset_type val
, size_of_contents
, total_len
;
16436 htab_t cu_index_htab
;
16437 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
16439 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
16442 if (dwarf2_per_objfile
->using_index
)
16443 error (_("Cannot use an index to create the index"));
16445 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
16446 error (_("Cannot make an index when the file has multiple .debug_types sections"));
16448 if (stat (objfile
->name
, &st
) < 0)
16449 perror_with_name (objfile
->name
);
16451 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
16452 INDEX_SUFFIX
, (char *) NULL
);
16453 cleanup
= make_cleanup (xfree
, filename
);
16455 out_file
= fopen (filename
, "wb");
16457 error (_("Can't open `%s' for writing"), filename
);
16459 cleanup_filename
= filename
;
16460 make_cleanup (unlink_if_set
, &cleanup_filename
);
16462 symtab
= create_mapped_symtab ();
16463 make_cleanup (cleanup_mapped_symtab
, symtab
);
16465 obstack_init (&addr_obstack
);
16466 make_cleanup_obstack_free (&addr_obstack
);
16468 obstack_init (&cu_list
);
16469 make_cleanup_obstack_free (&cu_list
);
16471 obstack_init (&types_cu_list
);
16472 make_cleanup_obstack_free (&types_cu_list
);
16474 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
16475 NULL
, xcalloc
, xfree
);
16476 make_cleanup (cleanup_htab
, psyms_seen
);
16478 /* While we're scanning CU's create a table that maps a psymtab pointer
16479 (which is what addrmap records) to its index (which is what is recorded
16480 in the index file). This will later be needed to write the address
16482 cu_index_htab
= htab_create_alloc (100,
16483 hash_psymtab_cu_index
,
16484 eq_psymtab_cu_index
,
16485 NULL
, xcalloc
, xfree
);
16486 make_cleanup (cleanup_htab
, cu_index_htab
);
16487 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
16488 xmalloc (sizeof (struct psymtab_cu_index_map
)
16489 * dwarf2_per_objfile
->n_comp_units
);
16490 make_cleanup (xfree
, psymtab_cu_index_map
);
16492 /* The CU list is already sorted, so we don't need to do additional
16493 work here. Also, the debug_types entries do not appear in
16494 all_comp_units, but only in their own hash table. */
16495 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
16497 struct dwarf2_per_cu_data
*per_cu
16498 = dwarf2_per_objfile
->all_comp_units
[i
];
16499 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16501 struct psymtab_cu_index_map
*map
;
16504 write_psymbols (symtab
,
16506 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
16507 psymtab
->n_global_syms
, i
,
16509 write_psymbols (symtab
,
16511 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
16512 psymtab
->n_static_syms
, i
,
16515 map
= &psymtab_cu_index_map
[i
];
16516 map
->psymtab
= psymtab
;
16518 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
16519 gdb_assert (slot
!= NULL
);
16520 gdb_assert (*slot
== NULL
);
16523 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
16524 obstack_grow (&cu_list
, val
, 8);
16525 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
16526 obstack_grow (&cu_list
, val
, 8);
16529 /* Dump the address map. */
16530 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
16532 /* Write out the .debug_type entries, if any. */
16533 if (dwarf2_per_objfile
->signatured_types
)
16535 struct signatured_type_index_data sig_data
;
16537 sig_data
.objfile
= objfile
;
16538 sig_data
.symtab
= symtab
;
16539 sig_data
.types_list
= &types_cu_list
;
16540 sig_data
.psyms_seen
= psyms_seen
;
16541 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
16542 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
16543 write_one_signatured_type
, &sig_data
);
16546 obstack_init (&constant_pool
);
16547 make_cleanup_obstack_free (&constant_pool
);
16548 obstack_init (&symtab_obstack
);
16549 make_cleanup_obstack_free (&symtab_obstack
);
16550 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
16552 obstack_init (&contents
);
16553 make_cleanup_obstack_free (&contents
);
16554 size_of_contents
= 6 * sizeof (offset_type
);
16555 total_len
= size_of_contents
;
16557 /* The version number. */
16558 val
= MAYBE_SWAP (5);
16559 obstack_grow (&contents
, &val
, sizeof (val
));
16561 /* The offset of the CU list from the start of the file. */
16562 val
= MAYBE_SWAP (total_len
);
16563 obstack_grow (&contents
, &val
, sizeof (val
));
16564 total_len
+= obstack_object_size (&cu_list
);
16566 /* The offset of the types CU list from the start of the file. */
16567 val
= MAYBE_SWAP (total_len
);
16568 obstack_grow (&contents
, &val
, sizeof (val
));
16569 total_len
+= obstack_object_size (&types_cu_list
);
16571 /* The offset of the address table from the start of the file. */
16572 val
= MAYBE_SWAP (total_len
);
16573 obstack_grow (&contents
, &val
, sizeof (val
));
16574 total_len
+= obstack_object_size (&addr_obstack
);
16576 /* The offset of the symbol table from the start of the file. */
16577 val
= MAYBE_SWAP (total_len
);
16578 obstack_grow (&contents
, &val
, sizeof (val
));
16579 total_len
+= obstack_object_size (&symtab_obstack
);
16581 /* The offset of the constant pool from the start of the file. */
16582 val
= MAYBE_SWAP (total_len
);
16583 obstack_grow (&contents
, &val
, sizeof (val
));
16584 total_len
+= obstack_object_size (&constant_pool
);
16586 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
16588 write_obstack (out_file
, &contents
);
16589 write_obstack (out_file
, &cu_list
);
16590 write_obstack (out_file
, &types_cu_list
);
16591 write_obstack (out_file
, &addr_obstack
);
16592 write_obstack (out_file
, &symtab_obstack
);
16593 write_obstack (out_file
, &constant_pool
);
16597 /* We want to keep the file, so we set cleanup_filename to NULL
16598 here. See unlink_if_set. */
16599 cleanup_filename
= NULL
;
16601 do_cleanups (cleanup
);
16604 /* Implementation of the `save gdb-index' command.
16606 Note that the file format used by this command is documented in the
16607 GDB manual. Any changes here must be documented there. */
16610 save_gdb_index_command (char *arg
, int from_tty
)
16612 struct objfile
*objfile
;
16615 error (_("usage: save gdb-index DIRECTORY"));
16617 ALL_OBJFILES (objfile
)
16621 /* If the objfile does not correspond to an actual file, skip it. */
16622 if (stat (objfile
->name
, &st
) < 0)
16625 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16626 if (dwarf2_per_objfile
)
16628 volatile struct gdb_exception except
;
16630 TRY_CATCH (except
, RETURN_MASK_ERROR
)
16632 write_psymtabs_to_index (objfile
, arg
);
16634 if (except
.reason
< 0)
16635 exception_fprintf (gdb_stderr
, except
,
16636 _("Error while writing index for `%s': "),
16644 int dwarf2_always_disassemble
;
16647 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
16648 struct cmd_list_element
*c
, const char *value
)
16650 fprintf_filtered (file
,
16651 _("Whether to always disassemble "
16652 "DWARF expressions is %s.\n"),
16657 show_check_physname (struct ui_file
*file
, int from_tty
,
16658 struct cmd_list_element
*c
, const char *value
)
16660 fprintf_filtered (file
,
16661 _("Whether to check \"physname\" is %s.\n"),
16665 void _initialize_dwarf2_read (void);
16668 _initialize_dwarf2_read (void)
16670 struct cmd_list_element
*c
;
16672 dwarf2_objfile_data_key
16673 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
16675 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
16676 Set DWARF 2 specific variables.\n\
16677 Configure DWARF 2 variables such as the cache size"),
16678 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
16679 0/*allow-unknown*/, &maintenance_set_cmdlist
);
16681 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
16682 Show DWARF 2 specific variables\n\
16683 Show DWARF 2 variables such as the cache size"),
16684 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
16685 0/*allow-unknown*/, &maintenance_show_cmdlist
);
16687 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
16688 &dwarf2_max_cache_age
, _("\
16689 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
16690 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
16691 A higher limit means that cached compilation units will be stored\n\
16692 in memory longer, and more total memory will be used. Zero disables\n\
16693 caching, which can slow down startup."),
16695 show_dwarf2_max_cache_age
,
16696 &set_dwarf2_cmdlist
,
16697 &show_dwarf2_cmdlist
);
16699 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
16700 &dwarf2_always_disassemble
, _("\
16701 Set whether `info address' always disassembles DWARF expressions."), _("\
16702 Show whether `info address' always disassembles DWARF expressions."), _("\
16703 When enabled, DWARF expressions are always printed in an assembly-like\n\
16704 syntax. When disabled, expressions will be printed in a more\n\
16705 conversational style, when possible."),
16707 show_dwarf2_always_disassemble
,
16708 &set_dwarf2_cmdlist
,
16709 &show_dwarf2_cmdlist
);
16711 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
16712 Set debugging of the dwarf2 DIE reader."), _("\
16713 Show debugging of the dwarf2 DIE reader."), _("\
16714 When enabled (non-zero), DIEs are dumped after they are read in.\n\
16715 The value is the maximum depth to print."),
16718 &setdebuglist
, &showdebuglist
);
16720 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
16721 Set cross-checking of \"physname\" code against demangler."), _("\
16722 Show cross-checking of \"physname\" code against demangler."), _("\
16723 When enabled, GDB's internal \"physname\" code is checked against\n\
16725 NULL
, show_check_physname
,
16726 &setdebuglist
, &showdebuglist
);
16728 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
16730 Save a gdb-index file.\n\
16731 Usage: save gdb-index DIRECTORY"),
16733 set_cmd_completer (c
, filename_completer
);