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" }
277 /* local data types */
279 /* We hold several abbreviation tables in memory at the same time. */
280 #ifndef ABBREV_HASH_SIZE
281 #define ABBREV_HASH_SIZE 121
284 /* The data in a compilation unit header, after target2host
285 translation, looks like this. */
286 struct comp_unit_head
290 unsigned char addr_size
;
291 unsigned char signed_addr_p
;
292 unsigned int abbrev_offset
;
294 /* Size of file offsets; either 4 or 8. */
295 unsigned int offset_size
;
297 /* Size of the length field; either 4 or 12. */
298 unsigned int initial_length_size
;
300 /* Offset to the first byte of this compilation unit header in the
301 .debug_info section, for resolving relative reference dies. */
304 /* Offset to first die in this cu from the start of the cu.
305 This will be the first byte following the compilation unit header. */
306 unsigned int first_die_offset
;
309 /* Type used for delaying computation of method physnames.
310 See comments for compute_delayed_physnames. */
311 struct delayed_method_info
313 /* The type to which the method is attached, i.e., its parent class. */
316 /* The index of the method in the type's function fieldlists. */
319 /* The index of the method in the fieldlist. */
322 /* The name of the DIE. */
325 /* The DIE associated with this method. */
326 struct die_info
*die
;
329 typedef struct delayed_method_info delayed_method_info
;
330 DEF_VEC_O (delayed_method_info
);
332 /* Internal state when decoding a particular compilation unit. */
335 /* The objfile containing this compilation unit. */
336 struct objfile
*objfile
;
338 /* The header of the compilation unit. */
339 struct comp_unit_head header
;
341 /* Base address of this compilation unit. */
342 CORE_ADDR base_address
;
344 /* Non-zero if base_address has been set. */
347 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
349 /* The language we are debugging. */
350 enum language language
;
351 const struct language_defn
*language_defn
;
353 const char *producer
;
355 /* The generic symbol table building routines have separate lists for
356 file scope symbols and all all other scopes (local scopes). So
357 we need to select the right one to pass to add_symbol_to_list().
358 We do it by keeping a pointer to the correct list in list_in_scope.
360 FIXME: The original dwarf code just treated the file scope as the
361 first local scope, and all other local scopes as nested local
362 scopes, and worked fine. Check to see if we really need to
363 distinguish these in buildsym.c. */
364 struct pending
**list_in_scope
;
366 /* DWARF abbreviation table associated with this compilation unit. */
367 struct abbrev_info
**dwarf2_abbrevs
;
369 /* Storage for the abbrev table. */
370 struct obstack abbrev_obstack
;
372 /* Hash table holding all the loaded partial DIEs. */
375 /* Storage for things with the same lifetime as this read-in compilation
376 unit, including partial DIEs. */
377 struct obstack comp_unit_obstack
;
379 /* When multiple dwarf2_cu structures are living in memory, this field
380 chains them all together, so that they can be released efficiently.
381 We will probably also want a generation counter so that most-recently-used
382 compilation units are cached... */
383 struct dwarf2_per_cu_data
*read_in_chain
;
385 /* Backchain to our per_cu entry if the tree has been built. */
386 struct dwarf2_per_cu_data
*per_cu
;
388 /* How many compilation units ago was this CU last referenced? */
391 /* A hash table of die offsets for following references. */
394 /* Full DIEs if read in. */
395 struct die_info
*dies
;
397 /* A set of pointers to dwarf2_per_cu_data objects for compilation
398 units referenced by this one. Only set during full symbol processing;
399 partial symbol tables do not have dependencies. */
402 /* Header data from the line table, during full symbol processing. */
403 struct line_header
*line_header
;
405 /* A list of methods which need to have physnames computed
406 after all type information has been read. */
407 VEC (delayed_method_info
) *method_list
;
409 /* Mark used when releasing cached dies. */
410 unsigned int mark
: 1;
412 /* This flag will be set if this compilation unit might include
413 inter-compilation-unit references. */
414 unsigned int has_form_ref_addr
: 1;
416 /* This flag will be set if this compilation unit includes any
417 DW_TAG_namespace DIEs. If we know that there are explicit
418 DIEs for namespaces, we don't need to try to infer them
419 from mangled names. */
420 unsigned int has_namespace_info
: 1;
422 /* This CU references .debug_loc. See the symtab->locations_valid field.
423 This test is imperfect as there may exist optimized debug code not using
424 any location list and still facing inlining issues if handled as
425 unoptimized code. For a future better test see GCC PR other/32998. */
427 unsigned int has_loclist
: 1;
430 /* Persistent data held for a compilation unit, even when not
431 processing it. We put a pointer to this structure in the
432 read_symtab_private field of the psymtab. If we encounter
433 inter-compilation-unit references, we also maintain a sorted
434 list of all compilation units. */
436 struct dwarf2_per_cu_data
438 /* The start offset and length of this compilation unit. 2**29-1
439 bytes should suffice to store the length of any compilation unit
440 - if it doesn't, GDB will fall over anyway.
441 NOTE: Unlike comp_unit_head.length, this length includes
442 initial_length_size. */
444 unsigned int length
: 29;
446 /* Flag indicating this compilation unit will be read in before
447 any of the current compilation units are processed. */
448 unsigned int queued
: 1;
450 /* This flag will be set if we need to load absolutely all DIEs
451 for this compilation unit, instead of just the ones we think
452 are interesting. It gets set if we look for a DIE in the
453 hash table and don't find it. */
454 unsigned int load_all_dies
: 1;
456 /* Non-null if this CU is from .debug_types; in which case it points
457 to the section. Otherwise it's from .debug_info. */
458 struct dwarf2_section_info
*debug_type_section
;
460 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
461 of the CU cache it gets reset to NULL again. */
462 struct dwarf2_cu
*cu
;
464 /* The corresponding objfile. */
465 struct objfile
*objfile
;
467 /* When using partial symbol tables, the 'psymtab' field is active.
468 Otherwise the 'quick' field is active. */
471 /* The partial symbol table associated with this compilation unit,
472 or NULL for partial units (which do not have an associated
474 struct partial_symtab
*psymtab
;
476 /* Data needed by the "quick" functions. */
477 struct dwarf2_per_cu_quick_data
*quick
;
481 /* Entry in the signatured_types hash table. */
483 struct signatured_type
487 /* Offset in .debug_types of the type defined by this TU. */
488 unsigned int type_offset
;
490 /* The CU(/TU) of this type. */
491 struct dwarf2_per_cu_data per_cu
;
494 /* Struct used to pass misc. parameters to read_die_and_children, et
495 al. which are used for both .debug_info and .debug_types dies.
496 All parameters here are unchanging for the life of the call. This
497 struct exists to abstract away the constant parameters of die
500 struct die_reader_specs
502 /* The bfd of this objfile. */
505 /* The CU of the DIE we are parsing. */
506 struct dwarf2_cu
*cu
;
508 /* Pointer to start of section buffer.
509 This is either the start of .debug_info or .debug_types. */
510 const gdb_byte
*buffer
;
513 /* The line number information for a compilation unit (found in the
514 .debug_line section) begins with a "statement program header",
515 which contains the following information. */
518 unsigned int total_length
;
519 unsigned short version
;
520 unsigned int header_length
;
521 unsigned char minimum_instruction_length
;
522 unsigned char maximum_ops_per_instruction
;
523 unsigned char default_is_stmt
;
525 unsigned char line_range
;
526 unsigned char opcode_base
;
528 /* standard_opcode_lengths[i] is the number of operands for the
529 standard opcode whose value is i. This means that
530 standard_opcode_lengths[0] is unused, and the last meaningful
531 element is standard_opcode_lengths[opcode_base - 1]. */
532 unsigned char *standard_opcode_lengths
;
534 /* The include_directories table. NOTE! These strings are not
535 allocated with xmalloc; instead, they are pointers into
536 debug_line_buffer. If you try to free them, `free' will get
538 unsigned int num_include_dirs
, include_dirs_size
;
541 /* The file_names table. NOTE! These strings are not allocated
542 with xmalloc; instead, they are pointers into debug_line_buffer.
543 Don't try to free them directly. */
544 unsigned int num_file_names
, file_names_size
;
548 unsigned int dir_index
;
549 unsigned int mod_time
;
551 int included_p
; /* Non-zero if referenced by the Line Number Program. */
552 struct symtab
*symtab
; /* The associated symbol table, if any. */
555 /* The start and end of the statement program following this
556 header. These point into dwarf2_per_objfile->line_buffer. */
557 gdb_byte
*statement_program_start
, *statement_program_end
;
560 /* When we construct a partial symbol table entry we only
561 need this much information. */
562 struct partial_die_info
564 /* Offset of this DIE. */
567 /* DWARF-2 tag for this DIE. */
568 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
570 /* Assorted flags describing the data found in this DIE. */
571 unsigned int has_children
: 1;
572 unsigned int is_external
: 1;
573 unsigned int is_declaration
: 1;
574 unsigned int has_type
: 1;
575 unsigned int has_specification
: 1;
576 unsigned int has_pc_info
: 1;
578 /* Flag set if the SCOPE field of this structure has been
580 unsigned int scope_set
: 1;
582 /* Flag set if the DIE has a byte_size attribute. */
583 unsigned int has_byte_size
: 1;
585 /* Flag set if any of the DIE's children are template arguments. */
586 unsigned int has_template_arguments
: 1;
588 /* Flag set if fixup_partial_die has been called on this die. */
589 unsigned int fixup_called
: 1;
591 /* The name of this DIE. Normally the value of DW_AT_name, but
592 sometimes a default name for unnamed DIEs. */
595 /* The linkage name, if present. */
596 const char *linkage_name
;
598 /* The scope to prepend to our children. This is generally
599 allocated on the comp_unit_obstack, so will disappear
600 when this compilation unit leaves the cache. */
603 /* The location description associated with this DIE, if any. */
604 struct dwarf_block
*locdesc
;
606 /* If HAS_PC_INFO, the PC range associated with this DIE. */
610 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
611 DW_AT_sibling, if any. */
612 /* NOTE: This member isn't strictly necessary, read_partial_die could
613 return DW_AT_sibling values to its caller load_partial_dies. */
616 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
617 DW_AT_specification (or DW_AT_abstract_origin or
619 unsigned int spec_offset
;
621 /* Pointers to this DIE's parent, first child, and next sibling,
623 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
626 /* This data structure holds the information of an abbrev. */
629 unsigned int number
; /* number identifying abbrev */
630 enum dwarf_tag tag
; /* dwarf tag */
631 unsigned short has_children
; /* boolean */
632 unsigned short num_attrs
; /* number of attributes */
633 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
634 struct abbrev_info
*next
; /* next in chain */
639 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
640 ENUM_BITFIELD(dwarf_form
) form
: 16;
643 /* Attributes have a name and a value. */
646 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
647 ENUM_BITFIELD(dwarf_form
) form
: 15;
649 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
650 field should be in u.str (existing only for DW_STRING) but it is kept
651 here for better struct attribute alignment. */
652 unsigned int string_is_canonical
: 1;
657 struct dwarf_block
*blk
;
661 struct signatured_type
*signatured_type
;
666 /* This data structure holds a complete die structure. */
669 /* DWARF-2 tag for this DIE. */
670 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
672 /* Number of attributes */
673 unsigned char num_attrs
;
675 /* True if we're presently building the full type name for the
676 type derived from this DIE. */
677 unsigned char building_fullname
: 1;
682 /* Offset in .debug_info or .debug_types section. */
685 /* The dies in a compilation unit form an n-ary tree. PARENT
686 points to this die's parent; CHILD points to the first child of
687 this node; and all the children of a given node are chained
688 together via their SIBLING fields. */
689 struct die_info
*child
; /* Its first child, if any. */
690 struct die_info
*sibling
; /* Its next sibling, if any. */
691 struct die_info
*parent
; /* Its parent, if any. */
693 /* An array of attributes, with NUM_ATTRS elements. There may be
694 zero, but it's not common and zero-sized arrays are not
695 sufficiently portable C. */
696 struct attribute attrs
[1];
699 struct function_range
702 CORE_ADDR lowpc
, highpc
;
704 struct function_range
*next
;
707 /* Get at parts of an attribute structure. */
709 #define DW_STRING(attr) ((attr)->u.str)
710 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
711 #define DW_UNSND(attr) ((attr)->u.unsnd)
712 #define DW_BLOCK(attr) ((attr)->u.blk)
713 #define DW_SND(attr) ((attr)->u.snd)
714 #define DW_ADDR(attr) ((attr)->u.addr)
715 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
717 /* Blocks are a bunch of untyped bytes. */
724 #ifndef ATTR_ALLOC_CHUNK
725 #define ATTR_ALLOC_CHUNK 4
728 /* Allocate fields for structs, unions and enums in this size. */
729 #ifndef DW_FIELD_ALLOC_CHUNK
730 #define DW_FIELD_ALLOC_CHUNK 4
733 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
734 but this would require a corresponding change in unpack_field_as_long
736 static int bits_per_byte
= 8;
738 /* The routines that read and process dies for a C struct or C++ class
739 pass lists of data member fields and lists of member function fields
740 in an instance of a field_info structure, as defined below. */
743 /* List of data member and baseclasses fields. */
746 struct nextfield
*next
;
751 *fields
, *baseclasses
;
753 /* Number of fields (including baseclasses). */
756 /* Number of baseclasses. */
759 /* Set if the accesibility of one of the fields is not public. */
760 int non_public_fields
;
762 /* Member function fields array, entries are allocated in the order they
763 are encountered in the object file. */
766 struct nextfnfield
*next
;
767 struct fn_field fnfield
;
771 /* Member function fieldlist array, contains name of possibly overloaded
772 member function, number of overloaded member functions and a pointer
773 to the head of the member function field chain. */
778 struct nextfnfield
*head
;
782 /* Number of entries in the fnfieldlists array. */
785 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
786 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
787 struct typedef_field_list
789 struct typedef_field field
;
790 struct typedef_field_list
*next
;
793 unsigned typedef_field_list_count
;
796 /* One item on the queue of compilation units to read in full symbols
798 struct dwarf2_queue_item
800 struct dwarf2_per_cu_data
*per_cu
;
801 struct dwarf2_queue_item
*next
;
804 /* The current queue. */
805 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
807 /* Loaded secondary compilation units are kept in memory until they
808 have not been referenced for the processing of this many
809 compilation units. Set this to zero to disable caching. Cache
810 sizes of up to at least twenty will improve startup time for
811 typical inter-CU-reference binaries, at an obvious memory cost. */
812 static int dwarf2_max_cache_age
= 5;
814 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
815 struct cmd_list_element
*c
, const char *value
)
817 fprintf_filtered (file
, _("The upper bound on the age of cached "
818 "dwarf2 compilation units is %s.\n"),
823 /* Various complaints about symbol reading that don't abort the process. */
826 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
828 complaint (&symfile_complaints
,
829 _("statement list doesn't fit in .debug_line section"));
833 dwarf2_debug_line_missing_file_complaint (void)
835 complaint (&symfile_complaints
,
836 _(".debug_line section has line data without a file"));
840 dwarf2_debug_line_missing_end_sequence_complaint (void)
842 complaint (&symfile_complaints
,
843 _(".debug_line section has line "
844 "program sequence without an end"));
848 dwarf2_complex_location_expr_complaint (void)
850 complaint (&symfile_complaints
, _("location expression too complex"));
854 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
857 complaint (&symfile_complaints
,
858 _("const value length mismatch for '%s', got %d, expected %d"),
863 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
865 complaint (&symfile_complaints
,
866 _("macro info runs off end of `%s' section"),
867 section
->asection
->name
);
871 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
873 complaint (&symfile_complaints
,
874 _("macro debug info contains a "
875 "malformed macro definition:\n`%s'"),
880 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
882 complaint (&symfile_complaints
,
883 _("invalid attribute class or form for '%s' in '%s'"),
887 /* local function prototypes */
889 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
891 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
894 static void dwarf2_find_base_address (struct die_info
*die
,
895 struct dwarf2_cu
*cu
);
897 static void dwarf2_build_psymtabs_hard (struct objfile
*);
899 static void scan_partial_symbols (struct partial_die_info
*,
900 CORE_ADDR
*, CORE_ADDR
*,
901 int, struct dwarf2_cu
*);
903 static void add_partial_symbol (struct partial_die_info
*,
906 static void add_partial_namespace (struct partial_die_info
*pdi
,
907 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
908 int need_pc
, struct dwarf2_cu
*cu
);
910 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
911 CORE_ADDR
*highpc
, int need_pc
,
912 struct dwarf2_cu
*cu
);
914 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
915 struct dwarf2_cu
*cu
);
917 static void add_partial_subprogram (struct partial_die_info
*pdi
,
918 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
919 int need_pc
, struct dwarf2_cu
*cu
);
921 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
922 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
923 bfd
*abfd
, struct dwarf2_cu
*cu
);
925 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
927 static void psymtab_to_symtab_1 (struct partial_symtab
*);
929 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
931 static void dwarf2_free_abbrev_table (void *);
933 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
936 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
939 static struct partial_die_info
*load_partial_dies (bfd
*,
940 gdb_byte
*, gdb_byte
*,
941 int, struct dwarf2_cu
*);
943 static gdb_byte
*read_partial_die (struct partial_die_info
*,
944 struct abbrev_info
*abbrev
,
946 gdb_byte
*, gdb_byte
*,
949 static struct partial_die_info
*find_partial_die (unsigned int,
952 static void fixup_partial_die (struct partial_die_info
*,
955 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
956 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
958 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
959 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
961 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
963 static int read_1_signed_byte (bfd
*, gdb_byte
*);
965 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
967 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
969 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
971 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
974 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
976 static LONGEST read_checked_initial_length_and_offset
977 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
978 unsigned int *, unsigned int *);
980 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
983 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
985 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
987 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
989 static char *read_indirect_string (bfd
*, gdb_byte
*,
990 const struct comp_unit_head
*,
993 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
995 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
997 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
999 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1001 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1002 struct dwarf2_cu
*);
1004 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1006 struct dwarf2_cu
*);
1008 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1009 struct dwarf2_cu
*cu
);
1011 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1013 static struct die_info
*die_specification (struct die_info
*die
,
1014 struct dwarf2_cu
**);
1016 static void free_line_header (struct line_header
*lh
);
1018 static void add_file_name (struct line_header
*, char *, unsigned int,
1019 unsigned int, unsigned int);
1021 static struct line_header
*(dwarf_decode_line_header
1022 (unsigned int offset
,
1023 bfd
*abfd
, struct dwarf2_cu
*cu
));
1025 static void dwarf_decode_lines (struct line_header
*, const char *, bfd
*,
1026 struct dwarf2_cu
*, struct partial_symtab
*);
1028 static void dwarf2_start_subfile (char *, const char *, const char *);
1030 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1031 struct dwarf2_cu
*);
1033 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1034 struct dwarf2_cu
*, struct symbol
*);
1036 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1037 struct dwarf2_cu
*);
1039 static void dwarf2_const_value_attr (struct attribute
*attr
,
1042 struct obstack
*obstack
,
1043 struct dwarf2_cu
*cu
, long *value
,
1045 struct dwarf2_locexpr_baton
**baton
);
1047 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1049 static int need_gnat_info (struct dwarf2_cu
*);
1051 static struct type
*die_descriptive_type (struct die_info
*,
1052 struct dwarf2_cu
*);
1054 static void set_descriptive_type (struct type
*, struct die_info
*,
1055 struct dwarf2_cu
*);
1057 static struct type
*die_containing_type (struct die_info
*,
1058 struct dwarf2_cu
*);
1060 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1061 struct dwarf2_cu
*);
1063 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1065 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1067 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1069 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1070 const char *suffix
, int physname
,
1071 struct dwarf2_cu
*cu
);
1073 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1075 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1077 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1079 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1081 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1082 struct dwarf2_cu
*, struct partial_symtab
*);
1084 static int dwarf2_get_pc_bounds (struct die_info
*,
1085 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1086 struct partial_symtab
*);
1088 static void get_scope_pc_bounds (struct die_info
*,
1089 CORE_ADDR
*, CORE_ADDR
*,
1090 struct dwarf2_cu
*);
1092 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1093 CORE_ADDR
, struct dwarf2_cu
*);
1095 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1096 struct dwarf2_cu
*);
1098 static void dwarf2_attach_fields_to_type (struct field_info
*,
1099 struct type
*, struct dwarf2_cu
*);
1101 static void dwarf2_add_member_fn (struct field_info
*,
1102 struct die_info
*, struct type
*,
1103 struct dwarf2_cu
*);
1105 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1107 struct dwarf2_cu
*);
1109 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1111 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1113 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1115 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1117 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1119 static struct type
*read_module_type (struct die_info
*die
,
1120 struct dwarf2_cu
*cu
);
1122 static const char *namespace_name (struct die_info
*die
,
1123 int *is_anonymous
, struct dwarf2_cu
*);
1125 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1127 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1129 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1130 struct dwarf2_cu
*);
1132 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1134 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1136 gdb_byte
**new_info_ptr
,
1137 struct die_info
*parent
);
1139 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1141 gdb_byte
**new_info_ptr
,
1142 struct die_info
*parent
);
1144 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1146 gdb_byte
**new_info_ptr
,
1147 struct die_info
*parent
);
1149 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1150 struct die_info
**, gdb_byte
*,
1153 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1155 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1158 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1160 static const char *dwarf2_full_name (char *name
,
1161 struct die_info
*die
,
1162 struct dwarf2_cu
*cu
);
1164 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1165 struct dwarf2_cu
**);
1167 static char *dwarf_tag_name (unsigned int);
1169 static char *dwarf_attr_name (unsigned int);
1171 static char *dwarf_form_name (unsigned int);
1173 static char *dwarf_bool_name (unsigned int);
1175 static char *dwarf_type_encoding_name (unsigned int);
1178 static char *dwarf_cfi_name (unsigned int);
1181 static struct die_info
*sibling_die (struct die_info
*);
1183 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1185 static void dump_die_for_error (struct die_info
*);
1187 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1190 /*static*/ void dump_die (struct die_info
*, int max_level
);
1192 static void store_in_ref_table (struct die_info
*,
1193 struct dwarf2_cu
*);
1195 static int is_ref_attr (struct attribute
*);
1197 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1199 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1201 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1203 struct dwarf2_cu
**);
1205 static struct die_info
*follow_die_ref (struct die_info
*,
1207 struct dwarf2_cu
**);
1209 static struct die_info
*follow_die_sig (struct die_info
*,
1211 struct dwarf2_cu
**);
1213 static struct signatured_type
*lookup_signatured_type_at_offset
1214 (struct objfile
*objfile
,
1215 struct dwarf2_section_info
*section
,
1216 unsigned int offset
);
1218 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1219 struct dwarf2_section_info
*sect
,
1220 unsigned int offset
);
1222 static void read_signatured_type (struct objfile
*,
1223 struct signatured_type
*type_sig
);
1225 /* memory allocation interface */
1227 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1229 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1231 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1233 static void initialize_cu_func_list (struct dwarf2_cu
*);
1235 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1236 struct dwarf2_cu
*);
1238 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1239 char *, bfd
*, struct dwarf2_cu
*,
1240 struct dwarf2_section_info
*,
1243 static int attr_form_is_block (struct attribute
*);
1245 static int attr_form_is_section_offset (struct attribute
*);
1247 static int attr_form_is_constant (struct attribute
*);
1249 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1250 struct dwarf2_loclist_baton
*baton
,
1251 struct attribute
*attr
);
1253 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1255 struct dwarf2_cu
*cu
);
1257 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1258 struct abbrev_info
*abbrev
,
1259 struct dwarf2_cu
*cu
);
1261 static void free_stack_comp_unit (void *);
1263 static hashval_t
partial_die_hash (const void *item
);
1265 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1267 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1268 (unsigned int offset
, struct objfile
*objfile
);
1270 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1271 (unsigned int offset
, struct objfile
*objfile
);
1273 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1274 struct objfile
*objfile
);
1276 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1277 struct die_info
*comp_unit_die
);
1279 static void free_one_comp_unit (void *);
1281 static void free_cached_comp_units (void *);
1283 static void age_cached_comp_units (void);
1285 static void free_one_cached_comp_unit (void *);
1287 static struct type
*set_die_type (struct die_info
*, struct type
*,
1288 struct dwarf2_cu
*);
1290 static void create_all_comp_units (struct objfile
*);
1292 static int create_debug_types_hash_table (struct objfile
*objfile
);
1294 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1297 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1299 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1300 struct dwarf2_per_cu_data
*);
1302 static void dwarf2_mark (struct dwarf2_cu
*);
1304 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1306 static struct type
*get_die_type_at_offset (unsigned int,
1307 struct dwarf2_per_cu_data
*per_cu
);
1309 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1311 static void dwarf2_release_queue (void *dummy
);
1313 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1314 struct objfile
*objfile
);
1316 static void process_queue (struct objfile
*objfile
);
1318 static void find_file_and_directory (struct die_info
*die
,
1319 struct dwarf2_cu
*cu
,
1320 char **name
, char **comp_dir
);
1322 static char *file_full_name (int file
, struct line_header
*lh
,
1323 const char *comp_dir
);
1325 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1328 unsigned int buffer_size
,
1331 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1332 struct dwarf2_cu
*cu
);
1334 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1338 /* Convert VALUE between big- and little-endian. */
1340 byte_swap (offset_type value
)
1344 result
= (value
& 0xff) << 24;
1345 result
|= (value
& 0xff00) << 8;
1346 result
|= (value
& 0xff0000) >> 8;
1347 result
|= (value
& 0xff000000) >> 24;
1351 #define MAYBE_SWAP(V) byte_swap (V)
1354 #define MAYBE_SWAP(V) (V)
1355 #endif /* WORDS_BIGENDIAN */
1357 /* The suffix for an index file. */
1358 #define INDEX_SUFFIX ".gdb-index"
1360 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1361 struct dwarf2_cu
*cu
);
1363 /* Try to locate the sections we need for DWARF 2 debugging
1364 information and return true if we have enough to do something.
1365 NAMES points to the dwarf2 section names, or is NULL if the standard
1366 ELF names are used. */
1369 dwarf2_has_info (struct objfile
*objfile
,
1370 const struct dwarf2_debug_sections
*names
)
1372 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1373 if (!dwarf2_per_objfile
)
1375 /* Initialize per-objfile state. */
1376 struct dwarf2_per_objfile
*data
1377 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1379 memset (data
, 0, sizeof (*data
));
1380 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1381 dwarf2_per_objfile
= data
;
1383 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1385 dwarf2_per_objfile
->objfile
= objfile
;
1387 return (dwarf2_per_objfile
->info
.asection
!= NULL
1388 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1391 /* When loading sections, we look either for uncompressed section or for
1392 compressed section names. */
1395 section_is_p (const char *section_name
,
1396 const struct dwarf2_section_names
*names
)
1398 if (names
->normal
!= NULL
1399 && strcmp (section_name
, names
->normal
) == 0)
1401 if (names
->compressed
!= NULL
1402 && strcmp (section_name
, names
->compressed
) == 0)
1407 /* This function is mapped across the sections and remembers the
1408 offset and size of each of the debugging sections we are interested
1412 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1414 const struct dwarf2_debug_sections
*names
;
1417 names
= &dwarf2_elf_names
;
1419 names
= (const struct dwarf2_debug_sections
*) vnames
;
1421 if (section_is_p (sectp
->name
, &names
->info
))
1423 dwarf2_per_objfile
->info
.asection
= sectp
;
1424 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1426 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1428 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1429 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1431 else if (section_is_p (sectp
->name
, &names
->line
))
1433 dwarf2_per_objfile
->line
.asection
= sectp
;
1434 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1436 else if (section_is_p (sectp
->name
, &names
->loc
))
1438 dwarf2_per_objfile
->loc
.asection
= sectp
;
1439 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1441 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1443 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1444 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1446 else if (section_is_p (sectp
->name
, &names
->macro
))
1448 dwarf2_per_objfile
->macro
.asection
= sectp
;
1449 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1451 else if (section_is_p (sectp
->name
, &names
->str
))
1453 dwarf2_per_objfile
->str
.asection
= sectp
;
1454 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1456 else if (section_is_p (sectp
->name
, &names
->frame
))
1458 dwarf2_per_objfile
->frame
.asection
= sectp
;
1459 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1461 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1463 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1465 if (aflag
& SEC_HAS_CONTENTS
)
1467 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1468 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1471 else if (section_is_p (sectp
->name
, &names
->ranges
))
1473 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1474 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1476 else if (section_is_p (sectp
->name
, &names
->types
))
1478 struct dwarf2_section_info type_section
;
1480 memset (&type_section
, 0, sizeof (type_section
));
1481 type_section
.asection
= sectp
;
1482 type_section
.size
= bfd_get_section_size (sectp
);
1484 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1487 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1489 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1490 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1493 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1494 && bfd_section_vma (abfd
, sectp
) == 0)
1495 dwarf2_per_objfile
->has_section_at_zero
= 1;
1498 /* Decompress a section that was compressed using zlib. Store the
1499 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1502 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1503 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1505 bfd
*abfd
= objfile
->obfd
;
1507 error (_("Support for zlib-compressed DWARF data (from '%s') "
1508 "is disabled in this copy of GDB"),
1509 bfd_get_filename (abfd
));
1511 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1512 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1513 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1514 bfd_size_type uncompressed_size
;
1515 gdb_byte
*uncompressed_buffer
;
1518 int header_size
= 12;
1520 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1521 || bfd_bread (compressed_buffer
,
1522 compressed_size
, abfd
) != compressed_size
)
1523 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1524 bfd_get_filename (abfd
));
1526 /* Read the zlib header. In this case, it should be "ZLIB" followed
1527 by the uncompressed section size, 8 bytes in big-endian order. */
1528 if (compressed_size
< header_size
1529 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1530 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1531 bfd_get_filename (abfd
));
1532 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1533 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1534 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1535 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1536 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1537 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1538 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1539 uncompressed_size
+= compressed_buffer
[11];
1541 /* It is possible the section consists of several compressed
1542 buffers concatenated together, so we uncompress in a loop. */
1546 strm
.avail_in
= compressed_size
- header_size
;
1547 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1548 strm
.avail_out
= uncompressed_size
;
1549 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1551 rc
= inflateInit (&strm
);
1552 while (strm
.avail_in
> 0)
1555 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1556 bfd_get_filename (abfd
), rc
);
1557 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1558 + (uncompressed_size
- strm
.avail_out
));
1559 rc
= inflate (&strm
, Z_FINISH
);
1560 if (rc
!= Z_STREAM_END
)
1561 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1562 bfd_get_filename (abfd
), rc
);
1563 rc
= inflateReset (&strm
);
1565 rc
= inflateEnd (&strm
);
1567 || strm
.avail_out
!= 0)
1568 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1569 bfd_get_filename (abfd
), rc
);
1571 do_cleanups (cleanup
);
1572 *outbuf
= uncompressed_buffer
;
1573 *outsize
= uncompressed_size
;
1577 /* A helper function that decides whether a section is empty. */
1580 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1582 return info
->asection
== NULL
|| info
->size
== 0;
1585 /* Read the contents of the section SECTP from object file specified by
1586 OBJFILE, store info about the section into INFO.
1587 If the section is compressed, uncompress it before returning. */
1590 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1592 bfd
*abfd
= objfile
->obfd
;
1593 asection
*sectp
= info
->asection
;
1594 gdb_byte
*buf
, *retbuf
;
1595 unsigned char header
[4];
1599 info
->buffer
= NULL
;
1600 info
->map_addr
= NULL
;
1603 if (dwarf2_section_empty_p (info
))
1606 /* Check if the file has a 4-byte header indicating compression. */
1607 if (info
->size
> sizeof (header
)
1608 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1609 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1611 /* Upon decompression, update the buffer and its size. */
1612 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1614 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1622 pagesize
= getpagesize ();
1624 /* Only try to mmap sections which are large enough: we don't want to
1625 waste space due to fragmentation. Also, only try mmap for sections
1626 without relocations. */
1628 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1630 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1631 MAP_PRIVATE
, sectp
->filepos
,
1632 &info
->map_addr
, &info
->map_len
);
1634 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1636 #if HAVE_POSIX_MADVISE
1637 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1644 /* If we get here, we are a normal, not-compressed section. */
1646 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1648 /* When debugging .o files, we may need to apply relocations; see
1649 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1650 We never compress sections in .o files, so we only need to
1651 try this when the section is not compressed. */
1652 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1655 info
->buffer
= retbuf
;
1659 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1660 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1661 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1662 bfd_get_filename (abfd
));
1665 /* A helper function that returns the size of a section in a safe way.
1666 If you are positive that the section has been read before using the
1667 size, then it is safe to refer to the dwarf2_section_info object's
1668 "size" field directly. In other cases, you must call this
1669 function, because for compressed sections the size field is not set
1670 correctly until the section has been read. */
1672 static bfd_size_type
1673 dwarf2_section_size (struct objfile
*objfile
,
1674 struct dwarf2_section_info
*info
)
1677 dwarf2_read_section (objfile
, info
);
1681 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1685 dwarf2_get_section_info (struct objfile
*objfile
,
1686 enum dwarf2_section_enum sect
,
1687 asection
**sectp
, gdb_byte
**bufp
,
1688 bfd_size_type
*sizep
)
1690 struct dwarf2_per_objfile
*data
1691 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1692 struct dwarf2_section_info
*info
;
1694 /* We may see an objfile without any DWARF, in which case we just
1705 case DWARF2_DEBUG_FRAME
:
1706 info
= &data
->frame
;
1708 case DWARF2_EH_FRAME
:
1709 info
= &data
->eh_frame
;
1712 gdb_assert_not_reached ("unexpected section");
1715 dwarf2_read_section (objfile
, info
);
1717 *sectp
= info
->asection
;
1718 *bufp
= info
->buffer
;
1719 *sizep
= info
->size
;
1723 /* DWARF quick_symbols_functions support. */
1725 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1726 unique line tables, so we maintain a separate table of all .debug_line
1727 derived entries to support the sharing.
1728 All the quick functions need is the list of file names. We discard the
1729 line_header when we're done and don't need to record it here. */
1730 struct quick_file_names
1732 /* The offset in .debug_line of the line table. We hash on this. */
1733 unsigned int offset
;
1735 /* The number of entries in file_names, real_names. */
1736 unsigned int num_file_names
;
1738 /* The file names from the line table, after being run through
1740 const char **file_names
;
1742 /* The file names from the line table after being run through
1743 gdb_realpath. These are computed lazily. */
1744 const char **real_names
;
1747 /* When using the index (and thus not using psymtabs), each CU has an
1748 object of this type. This is used to hold information needed by
1749 the various "quick" methods. */
1750 struct dwarf2_per_cu_quick_data
1752 /* The file table. This can be NULL if there was no file table
1753 or it's currently not read in.
1754 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1755 struct quick_file_names
*file_names
;
1757 /* The corresponding symbol table. This is NULL if symbols for this
1758 CU have not yet been read. */
1759 struct symtab
*symtab
;
1761 /* A temporary mark bit used when iterating over all CUs in
1762 expand_symtabs_matching. */
1763 unsigned int mark
: 1;
1765 /* True if we've tried to read the file table and found there isn't one.
1766 There will be no point in trying to read it again next time. */
1767 unsigned int no_file_data
: 1;
1770 /* Hash function for a quick_file_names. */
1773 hash_file_name_entry (const void *e
)
1775 const struct quick_file_names
*file_data
= e
;
1777 return file_data
->offset
;
1780 /* Equality function for a quick_file_names. */
1783 eq_file_name_entry (const void *a
, const void *b
)
1785 const struct quick_file_names
*ea
= a
;
1786 const struct quick_file_names
*eb
= b
;
1788 return ea
->offset
== eb
->offset
;
1791 /* Delete function for a quick_file_names. */
1794 delete_file_name_entry (void *e
)
1796 struct quick_file_names
*file_data
= e
;
1799 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1801 xfree ((void*) file_data
->file_names
[i
]);
1802 if (file_data
->real_names
)
1803 xfree ((void*) file_data
->real_names
[i
]);
1806 /* The space for the struct itself lives on objfile_obstack,
1807 so we don't free it here. */
1810 /* Create a quick_file_names hash table. */
1813 create_quick_file_names_table (unsigned int nr_initial_entries
)
1815 return htab_create_alloc (nr_initial_entries
,
1816 hash_file_name_entry
, eq_file_name_entry
,
1817 delete_file_name_entry
, xcalloc
, xfree
);
1820 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1821 have to be created afterwards. You should call age_cached_comp_units after
1822 processing PER_CU->CU. dw2_setup must have been already called. */
1825 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1827 if (per_cu
->debug_type_section
)
1828 read_signatured_type_at_offset (per_cu
->objfile
,
1829 per_cu
->debug_type_section
,
1832 load_full_comp_unit (per_cu
, per_cu
->objfile
);
1834 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1836 gdb_assert (per_cu
->cu
!= NULL
);
1839 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1843 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1844 struct dwarf2_per_cu_data
*per_cu
)
1846 struct cleanup
*back_to
;
1848 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1850 queue_comp_unit (per_cu
, objfile
);
1854 process_queue (objfile
);
1856 /* Age the cache, releasing compilation units that have not
1857 been used recently. */
1858 age_cached_comp_units ();
1860 do_cleanups (back_to
);
1863 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1864 the objfile from which this CU came. Returns the resulting symbol
1867 static struct symtab
*
1868 dw2_instantiate_symtab (struct objfile
*objfile
,
1869 struct dwarf2_per_cu_data
*per_cu
)
1871 if (!per_cu
->v
.quick
->symtab
)
1873 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1874 increment_reading_symtab ();
1875 dw2_do_instantiate_symtab (objfile
, per_cu
);
1876 do_cleanups (back_to
);
1878 return per_cu
->v
.quick
->symtab
;
1881 /* Return the CU given its index. */
1883 static struct dwarf2_per_cu_data
*
1884 dw2_get_cu (int index
)
1886 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1888 index
-= dwarf2_per_objfile
->n_comp_units
;
1889 return dwarf2_per_objfile
->type_comp_units
[index
];
1891 return dwarf2_per_objfile
->all_comp_units
[index
];
1894 /* A helper function that knows how to read a 64-bit value in a way
1895 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1899 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1901 if (sizeof (ULONGEST
) < 8)
1905 /* Ignore the upper 4 bytes if they are all zero. */
1906 for (i
= 0; i
< 4; ++i
)
1907 if (bytes
[i
+ 4] != 0)
1910 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1913 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1917 /* Read the CU list from the mapped index, and use it to create all
1918 the CU objects for this objfile. Return 0 if something went wrong,
1919 1 if everything went ok. */
1922 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1923 offset_type cu_list_elements
)
1927 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1928 dwarf2_per_objfile
->all_comp_units
1929 = obstack_alloc (&objfile
->objfile_obstack
,
1930 dwarf2_per_objfile
->n_comp_units
1931 * sizeof (struct dwarf2_per_cu_data
*));
1933 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1935 struct dwarf2_per_cu_data
*the_cu
;
1936 ULONGEST offset
, length
;
1938 if (!extract_cu_value (cu_list
, &offset
)
1939 || !extract_cu_value (cu_list
+ 8, &length
))
1943 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1944 struct dwarf2_per_cu_data
);
1945 the_cu
->offset
= offset
;
1946 the_cu
->length
= length
;
1947 the_cu
->objfile
= objfile
;
1948 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1949 struct dwarf2_per_cu_quick_data
);
1950 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1956 /* Create the signatured type hash table from the index. */
1959 create_signatured_type_table_from_index (struct objfile
*objfile
,
1960 struct dwarf2_section_info
*section
,
1961 const gdb_byte
*bytes
,
1962 offset_type elements
)
1965 htab_t sig_types_hash
;
1967 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1968 dwarf2_per_objfile
->type_comp_units
1969 = obstack_alloc (&objfile
->objfile_obstack
,
1970 dwarf2_per_objfile
->n_type_comp_units
1971 * sizeof (struct dwarf2_per_cu_data
*));
1973 sig_types_hash
= allocate_signatured_type_table (objfile
);
1975 for (i
= 0; i
< elements
; i
+= 3)
1977 struct signatured_type
*type_sig
;
1978 ULONGEST offset
, type_offset
, signature
;
1981 if (!extract_cu_value (bytes
, &offset
)
1982 || !extract_cu_value (bytes
+ 8, &type_offset
))
1984 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1987 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1988 struct signatured_type
);
1989 type_sig
->signature
= signature
;
1990 type_sig
->type_offset
= type_offset
;
1991 type_sig
->per_cu
.debug_type_section
= section
;
1992 type_sig
->per_cu
.offset
= offset
;
1993 type_sig
->per_cu
.objfile
= objfile
;
1994 type_sig
->per_cu
.v
.quick
1995 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1996 struct dwarf2_per_cu_quick_data
);
1998 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
2001 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
2004 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2009 /* Read the address map data from the mapped index, and use it to
2010 populate the objfile's psymtabs_addrmap. */
2013 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2015 const gdb_byte
*iter
, *end
;
2016 struct obstack temp_obstack
;
2017 struct addrmap
*mutable_map
;
2018 struct cleanup
*cleanup
;
2021 obstack_init (&temp_obstack
);
2022 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2023 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2025 iter
= index
->address_table
;
2026 end
= iter
+ index
->address_table_size
;
2028 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2032 ULONGEST hi
, lo
, cu_index
;
2033 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2035 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2037 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2040 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2041 dw2_get_cu (cu_index
));
2044 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2045 &objfile
->objfile_obstack
);
2046 do_cleanups (cleanup
);
2049 /* The hash function for strings in the mapped index. This is the same as
2050 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2051 implementation. This is necessary because the hash function is tied to the
2052 format of the mapped index file. The hash values do not have to match with
2055 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2058 mapped_index_string_hash (int index_version
, const void *p
)
2060 const unsigned char *str
= (const unsigned char *) p
;
2064 while ((c
= *str
++) != 0)
2066 if (index_version
>= 5)
2068 r
= r
* 67 + c
- 113;
2074 /* Find a slot in the mapped index INDEX for the object named NAME.
2075 If NAME is found, set *VEC_OUT to point to the CU vector in the
2076 constant pool and return 1. If NAME cannot be found, return 0. */
2079 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2080 offset_type
**vec_out
)
2082 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2084 offset_type slot
, step
;
2085 int (*cmp
) (const char *, const char *);
2087 if (current_language
->la_language
== language_cplus
2088 || current_language
->la_language
== language_java
2089 || current_language
->la_language
== language_fortran
)
2091 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2093 const char *paren
= strchr (name
, '(');
2099 dup
= xmalloc (paren
- name
+ 1);
2100 memcpy (dup
, name
, paren
- name
);
2101 dup
[paren
- name
] = 0;
2103 make_cleanup (xfree
, dup
);
2108 /* Index version 4 did not support case insensitive searches. But the
2109 indexes for case insensitive languages are built in lowercase, therefore
2110 simulate our NAME being searched is also lowercased. */
2111 hash
= mapped_index_string_hash ((index
->version
== 4
2112 && case_sensitivity
== case_sensitive_off
2113 ? 5 : index
->version
),
2116 slot
= hash
& (index
->symbol_table_slots
- 1);
2117 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2118 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2122 /* Convert a slot number to an offset into the table. */
2123 offset_type i
= 2 * slot
;
2125 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2127 do_cleanups (back_to
);
2131 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2132 if (!cmp (name
, str
))
2134 *vec_out
= (offset_type
*) (index
->constant_pool
2135 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2136 do_cleanups (back_to
);
2140 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2144 /* Read the index file. If everything went ok, initialize the "quick"
2145 elements of all the CUs and return 1. Otherwise, return 0. */
2148 dwarf2_read_index (struct objfile
*objfile
)
2151 struct mapped_index
*map
;
2152 offset_type
*metadata
;
2153 const gdb_byte
*cu_list
;
2154 const gdb_byte
*types_list
= NULL
;
2155 offset_type version
, cu_list_elements
;
2156 offset_type types_list_elements
= 0;
2159 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2162 /* Older elfutils strip versions could keep the section in the main
2163 executable while splitting it for the separate debug info file. */
2164 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2165 & SEC_HAS_CONTENTS
) == 0)
2168 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2170 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2171 /* Version check. */
2172 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2173 /* Versions earlier than 3 emitted every copy of a psymbol. This
2174 causes the index to behave very poorly for certain requests. Version 3
2175 contained incomplete addrmap. So, it seems better to just ignore such
2176 indices. Index version 4 uses a different hash function than index
2177 version 5 and later. */
2180 /* Indexes with higher version than the one supported by GDB may be no
2181 longer backward compatible. */
2185 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2186 map
->version
= version
;
2187 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2189 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2192 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2193 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2197 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2198 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2199 - MAYBE_SWAP (metadata
[i
]))
2203 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2204 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2205 - MAYBE_SWAP (metadata
[i
]));
2208 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2209 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2210 - MAYBE_SWAP (metadata
[i
]))
2211 / (2 * sizeof (offset_type
)));
2214 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2216 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2219 if (types_list_elements
)
2221 struct dwarf2_section_info
*section
;
2223 /* We can only handle a single .debug_types when we have an
2225 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2228 section
= VEC_index (dwarf2_section_info_def
,
2229 dwarf2_per_objfile
->types
, 0);
2231 if (!create_signatured_type_table_from_index (objfile
, section
,
2233 types_list_elements
))
2237 create_addrmap_from_index (objfile
, map
);
2239 dwarf2_per_objfile
->index_table
= map
;
2240 dwarf2_per_objfile
->using_index
= 1;
2241 dwarf2_per_objfile
->quick_file_names_table
=
2242 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2247 /* A helper for the "quick" functions which sets the global
2248 dwarf2_per_objfile according to OBJFILE. */
2251 dw2_setup (struct objfile
*objfile
)
2253 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2254 gdb_assert (dwarf2_per_objfile
);
2257 /* A helper for the "quick" functions which attempts to read the line
2258 table for THIS_CU. */
2260 static struct quick_file_names
*
2261 dw2_get_file_names (struct objfile
*objfile
,
2262 struct dwarf2_per_cu_data
*this_cu
)
2264 bfd
*abfd
= objfile
->obfd
;
2265 struct line_header
*lh
;
2266 struct attribute
*attr
;
2267 struct cleanup
*cleanups
;
2268 struct die_info
*comp_unit_die
;
2269 struct dwarf2_section_info
* sec
;
2270 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2271 int has_children
, i
;
2272 struct dwarf2_cu cu
;
2273 unsigned int bytes_read
, buffer_size
;
2274 struct die_reader_specs reader_specs
;
2275 char *name
, *comp_dir
;
2277 struct quick_file_names
*qfn
;
2278 unsigned int line_offset
;
2280 if (this_cu
->v
.quick
->file_names
!= NULL
)
2281 return this_cu
->v
.quick
->file_names
;
2282 /* If we know there is no line data, no point in looking again. */
2283 if (this_cu
->v
.quick
->no_file_data
)
2286 init_one_comp_unit (&cu
, objfile
);
2287 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2289 if (this_cu
->debug_type_section
)
2290 sec
= this_cu
->debug_type_section
;
2292 sec
= &dwarf2_per_objfile
->info
;
2293 dwarf2_read_section (objfile
, sec
);
2294 buffer_size
= sec
->size
;
2295 buffer
= sec
->buffer
;
2296 info_ptr
= buffer
+ this_cu
->offset
;
2297 beg_of_comp_unit
= info_ptr
;
2299 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2300 buffer
, buffer_size
,
2303 /* Complete the cu_header. */
2304 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2305 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2308 cu
.per_cu
= this_cu
;
2310 dwarf2_read_abbrevs (abfd
, &cu
);
2311 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2313 if (this_cu
->debug_type_section
)
2314 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2315 init_cu_die_reader (&reader_specs
, &cu
);
2316 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2322 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2325 struct quick_file_names find_entry
;
2327 line_offset
= DW_UNSND (attr
);
2329 /* We may have already read in this line header (TU line header sharing).
2330 If we have we're done. */
2331 find_entry
.offset
= line_offset
;
2332 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2333 &find_entry
, INSERT
);
2336 do_cleanups (cleanups
);
2337 this_cu
->v
.quick
->file_names
= *slot
;
2341 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2345 do_cleanups (cleanups
);
2346 this_cu
->v
.quick
->no_file_data
= 1;
2350 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2351 qfn
->offset
= line_offset
;
2352 gdb_assert (slot
!= NULL
);
2355 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2357 qfn
->num_file_names
= lh
->num_file_names
;
2358 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2359 lh
->num_file_names
* sizeof (char *));
2360 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2361 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2362 qfn
->real_names
= NULL
;
2364 free_line_header (lh
);
2365 do_cleanups (cleanups
);
2367 this_cu
->v
.quick
->file_names
= qfn
;
2371 /* A helper for the "quick" functions which computes and caches the
2372 real path for a given file name from the line table. */
2375 dw2_get_real_path (struct objfile
*objfile
,
2376 struct quick_file_names
*qfn
, int index
)
2378 if (qfn
->real_names
== NULL
)
2379 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2380 qfn
->num_file_names
, sizeof (char *));
2382 if (qfn
->real_names
[index
] == NULL
)
2383 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2385 return qfn
->real_names
[index
];
2388 static struct symtab
*
2389 dw2_find_last_source_symtab (struct objfile
*objfile
)
2393 dw2_setup (objfile
);
2394 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2395 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2398 /* Traversal function for dw2_forget_cached_source_info. */
2401 dw2_free_cached_file_names (void **slot
, void *info
)
2403 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2405 if (file_data
->real_names
)
2409 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2411 xfree ((void*) file_data
->real_names
[i
]);
2412 file_data
->real_names
[i
] = NULL
;
2420 dw2_forget_cached_source_info (struct objfile
*objfile
)
2422 dw2_setup (objfile
);
2424 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2425 dw2_free_cached_file_names
, NULL
);
2429 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2430 const char *full_path
, const char *real_path
,
2431 struct symtab
**result
)
2434 int check_basename
= lbasename (name
) == name
;
2435 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2437 dw2_setup (objfile
);
2439 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2440 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2443 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2444 struct quick_file_names
*file_data
;
2446 if (per_cu
->v
.quick
->symtab
)
2449 file_data
= dw2_get_file_names (objfile
, per_cu
);
2450 if (file_data
== NULL
)
2453 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2455 const char *this_name
= file_data
->file_names
[j
];
2457 if (FILENAME_CMP (name
, this_name
) == 0)
2459 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2463 if (check_basename
&& ! base_cu
2464 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2467 if (full_path
!= NULL
)
2469 const char *this_real_name
= dw2_get_real_path (objfile
,
2472 if (this_real_name
!= NULL
2473 && FILENAME_CMP (full_path
, this_real_name
) == 0)
2475 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2480 if (real_path
!= NULL
)
2482 const char *this_real_name
= dw2_get_real_path (objfile
,
2485 if (this_real_name
!= NULL
2486 && FILENAME_CMP (real_path
, this_real_name
) == 0)
2488 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2497 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2504 static struct symtab
*
2505 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2506 const char *name
, domain_enum domain
)
2508 /* We do all the work in the pre_expand_symtabs_matching hook
2513 /* A helper function that expands all symtabs that hold an object
2517 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2519 dw2_setup (objfile
);
2521 /* index_table is NULL if OBJF_READNOW. */
2522 if (dwarf2_per_objfile
->index_table
)
2526 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2529 offset_type i
, len
= MAYBE_SWAP (*vec
);
2530 for (i
= 0; i
< len
; ++i
)
2532 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2533 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2535 dw2_instantiate_symtab (objfile
, per_cu
);
2542 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2543 enum block_enum block_kind
, const char *name
,
2546 dw2_do_expand_symtabs_matching (objfile
, name
);
2550 dw2_print_stats (struct objfile
*objfile
)
2554 dw2_setup (objfile
);
2556 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2557 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2559 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2561 if (!per_cu
->v
.quick
->symtab
)
2564 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2568 dw2_dump (struct objfile
*objfile
)
2570 /* Nothing worth printing. */
2574 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2575 struct section_offsets
*delta
)
2577 /* There's nothing to relocate here. */
2581 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2582 const char *func_name
)
2584 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2588 dw2_expand_all_symtabs (struct objfile
*objfile
)
2592 dw2_setup (objfile
);
2594 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2595 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2597 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2599 dw2_instantiate_symtab (objfile
, per_cu
);
2604 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2605 const char *filename
)
2609 dw2_setup (objfile
);
2611 /* We don't need to consider type units here.
2612 This is only called for examining code, e.g. expand_line_sal.
2613 There can be an order of magnitude (or more) more type units
2614 than comp units, and we avoid them if we can. */
2616 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2619 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2620 struct quick_file_names
*file_data
;
2622 if (per_cu
->v
.quick
->symtab
)
2625 file_data
= dw2_get_file_names (objfile
, per_cu
);
2626 if (file_data
== NULL
)
2629 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2631 const char *this_name
= file_data
->file_names
[j
];
2632 if (FILENAME_CMP (this_name
, filename
) == 0)
2634 dw2_instantiate_symtab (objfile
, per_cu
);
2642 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2644 struct dwarf2_per_cu_data
*per_cu
;
2646 struct quick_file_names
*file_data
;
2648 dw2_setup (objfile
);
2650 /* index_table is NULL if OBJF_READNOW. */
2651 if (!dwarf2_per_objfile
->index_table
)
2654 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2658 /* Note that this just looks at the very first one named NAME -- but
2659 actually we are looking for a function. find_main_filename
2660 should be rewritten so that it doesn't require a custom hook. It
2661 could just use the ordinary symbol tables. */
2662 /* vec[0] is the length, which must always be >0. */
2663 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2665 file_data
= dw2_get_file_names (objfile
, per_cu
);
2666 if (file_data
== NULL
)
2669 return file_data
->file_names
[file_data
->num_file_names
- 1];
2673 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2674 struct objfile
*objfile
, int global
,
2675 int (*callback
) (struct block
*,
2676 struct symbol
*, void *),
2677 void *data
, symbol_compare_ftype
*match
,
2678 symbol_compare_ftype
*ordered_compare
)
2680 /* Currently unimplemented; used for Ada. The function can be called if the
2681 current language is Ada for a non-Ada objfile using GNU index. As Ada
2682 does not look for non-Ada symbols this function should just return. */
2686 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2687 int (*file_matcher
) (const char *, void *),
2688 int (*name_matcher
) (const char *, void *),
2689 enum search_domain kind
,
2694 struct mapped_index
*index
;
2696 dw2_setup (objfile
);
2698 /* index_table is NULL if OBJF_READNOW. */
2699 if (!dwarf2_per_objfile
->index_table
)
2701 index
= dwarf2_per_objfile
->index_table
;
2703 if (file_matcher
!= NULL
)
2704 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2705 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2708 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2709 struct quick_file_names
*file_data
;
2711 per_cu
->v
.quick
->mark
= 0;
2712 if (per_cu
->v
.quick
->symtab
)
2715 file_data
= dw2_get_file_names (objfile
, per_cu
);
2716 if (file_data
== NULL
)
2719 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2721 if (file_matcher (file_data
->file_names
[j
], data
))
2723 per_cu
->v
.quick
->mark
= 1;
2729 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2731 offset_type idx
= 2 * iter
;
2733 offset_type
*vec
, vec_len
, vec_idx
;
2735 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2738 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2740 if (! (*name_matcher
) (name
, data
))
2743 /* The name was matched, now expand corresponding CUs that were
2745 vec
= (offset_type
*) (index
->constant_pool
2746 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2747 vec_len
= MAYBE_SWAP (vec
[0]);
2748 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2750 struct dwarf2_per_cu_data
*per_cu
;
2752 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2753 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2754 dw2_instantiate_symtab (objfile
, per_cu
);
2759 static struct symtab
*
2760 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2761 struct minimal_symbol
*msymbol
,
2763 struct obj_section
*section
,
2766 struct dwarf2_per_cu_data
*data
;
2768 dw2_setup (objfile
);
2770 if (!objfile
->psymtabs_addrmap
)
2773 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2777 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2778 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2779 paddress (get_objfile_arch (objfile
), pc
));
2781 return dw2_instantiate_symtab (objfile
, data
);
2785 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2790 dw2_setup (objfile
);
2792 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2793 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2796 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2797 struct quick_file_names
*file_data
;
2799 if (per_cu
->v
.quick
->symtab
)
2802 file_data
= dw2_get_file_names (objfile
, per_cu
);
2803 if (file_data
== NULL
)
2806 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2808 const char *this_real_name
= dw2_get_real_path (objfile
, file_data
,
2810 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2816 dw2_has_symbols (struct objfile
*objfile
)
2821 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2824 dw2_find_last_source_symtab
,
2825 dw2_forget_cached_source_info
,
2828 dw2_pre_expand_symtabs_matching
,
2832 dw2_expand_symtabs_for_function
,
2833 dw2_expand_all_symtabs
,
2834 dw2_expand_symtabs_with_filename
,
2835 dw2_find_symbol_file
,
2836 dw2_map_matching_symbols
,
2837 dw2_expand_symtabs_matching
,
2838 dw2_find_pc_sect_symtab
,
2839 dw2_map_symbol_filenames
2842 /* Initialize for reading DWARF for this objfile. Return 0 if this
2843 file will use psymtabs, or 1 if using the GNU index. */
2846 dwarf2_initialize_objfile (struct objfile
*objfile
)
2848 /* If we're about to read full symbols, don't bother with the
2849 indices. In this case we also don't care if some other debug
2850 format is making psymtabs, because they are all about to be
2852 if ((objfile
->flags
& OBJF_READNOW
))
2856 dwarf2_per_objfile
->using_index
= 1;
2857 create_all_comp_units (objfile
);
2858 create_debug_types_hash_table (objfile
);
2859 dwarf2_per_objfile
->quick_file_names_table
=
2860 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2862 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2863 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2865 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2867 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2868 struct dwarf2_per_cu_quick_data
);
2871 /* Return 1 so that gdb sees the "quick" functions. However,
2872 these functions will be no-ops because we will have expanded
2877 if (dwarf2_read_index (objfile
))
2885 /* Build a partial symbol table. */
2888 dwarf2_build_psymtabs (struct objfile
*objfile
)
2890 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2892 init_psymbol_list (objfile
, 1024);
2895 dwarf2_build_psymtabs_hard (objfile
);
2898 /* Return TRUE if OFFSET is within CU_HEADER. */
2901 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2903 unsigned int bottom
= cu_header
->offset
;
2904 unsigned int top
= (cu_header
->offset
2906 + cu_header
->initial_length_size
);
2908 return (offset
>= bottom
&& offset
< top
);
2911 /* Read in the comp unit header information from the debug_info at info_ptr.
2912 NOTE: This leaves members offset, first_die_offset to be filled in
2916 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2917 gdb_byte
*info_ptr
, bfd
*abfd
)
2920 unsigned int bytes_read
;
2922 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2923 cu_header
->initial_length_size
= bytes_read
;
2924 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2925 info_ptr
+= bytes_read
;
2926 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2928 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2930 info_ptr
+= bytes_read
;
2931 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2933 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2934 if (signed_addr
< 0)
2935 internal_error (__FILE__
, __LINE__
,
2936 _("read_comp_unit_head: dwarf from non elf file"));
2937 cu_header
->signed_addr_p
= signed_addr
;
2943 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2944 gdb_byte
*buffer
, unsigned int buffer_size
,
2947 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2949 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2951 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2952 error (_("Dwarf Error: wrong version in compilation unit header "
2953 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2954 bfd_get_filename (abfd
));
2956 if (header
->abbrev_offset
2957 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
2958 &dwarf2_per_objfile
->abbrev
))
2959 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2960 "(offset 0x%lx + 6) [in module %s]"),
2961 (long) header
->abbrev_offset
,
2962 (long) (beg_of_comp_unit
- buffer
),
2963 bfd_get_filename (abfd
));
2965 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2966 > buffer
+ buffer_size
)
2967 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2968 "(offset 0x%lx + 0) [in module %s]"),
2969 (long) header
->length
,
2970 (long) (beg_of_comp_unit
- buffer
),
2971 bfd_get_filename (abfd
));
2976 /* Read in the types comp unit header information from .debug_types entry at
2977 types_ptr. The result is a pointer to one past the end of the header. */
2980 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2981 struct dwarf2_section_info
*section
,
2982 ULONGEST
*signature
,
2983 gdb_byte
*types_ptr
, bfd
*abfd
)
2985 gdb_byte
*initial_types_ptr
= types_ptr
;
2987 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
2988 cu_header
->offset
= types_ptr
- section
->buffer
;
2990 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2992 *signature
= read_8_bytes (abfd
, types_ptr
);
2994 types_ptr
+= cu_header
->offset_size
;
2995 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
3000 /* Allocate a new partial symtab for file named NAME and mark this new
3001 partial symtab as being an include of PST. */
3004 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3005 struct objfile
*objfile
)
3007 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3009 subpst
->section_offsets
= pst
->section_offsets
;
3010 subpst
->textlow
= 0;
3011 subpst
->texthigh
= 0;
3013 subpst
->dependencies
= (struct partial_symtab
**)
3014 obstack_alloc (&objfile
->objfile_obstack
,
3015 sizeof (struct partial_symtab
*));
3016 subpst
->dependencies
[0] = pst
;
3017 subpst
->number_of_dependencies
= 1;
3019 subpst
->globals_offset
= 0;
3020 subpst
->n_global_syms
= 0;
3021 subpst
->statics_offset
= 0;
3022 subpst
->n_static_syms
= 0;
3023 subpst
->symtab
= NULL
;
3024 subpst
->read_symtab
= pst
->read_symtab
;
3027 /* No private part is necessary for include psymtabs. This property
3028 can be used to differentiate between such include psymtabs and
3029 the regular ones. */
3030 subpst
->read_symtab_private
= NULL
;
3033 /* Read the Line Number Program data and extract the list of files
3034 included by the source file represented by PST. Build an include
3035 partial symtab for each of these included files. */
3038 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3039 struct die_info
*die
,
3040 struct partial_symtab
*pst
)
3042 struct objfile
*objfile
= cu
->objfile
;
3043 bfd
*abfd
= objfile
->obfd
;
3044 struct line_header
*lh
= NULL
;
3045 struct attribute
*attr
;
3047 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3050 unsigned int line_offset
= DW_UNSND (attr
);
3052 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3055 return; /* No linetable, so no includes. */
3057 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3058 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
3060 free_line_header (lh
);
3064 hash_type_signature (const void *item
)
3066 const struct signatured_type
*type_sig
= item
;
3068 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3069 return type_sig
->signature
;
3073 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
3075 const struct signatured_type
*lhs
= item_lhs
;
3076 const struct signatured_type
*rhs
= item_rhs
;
3078 return lhs
->signature
== rhs
->signature
;
3081 /* Allocate a hash table for signatured types. */
3084 allocate_signatured_type_table (struct objfile
*objfile
)
3086 return htab_create_alloc_ex (41,
3087 hash_type_signature
,
3090 &objfile
->objfile_obstack
,
3091 hashtab_obstack_allocate
,
3092 dummy_obstack_deallocate
);
3095 /* A helper function to add a signatured type CU to a list. */
3098 add_signatured_type_cu_to_list (void **slot
, void *datum
)
3100 struct signatured_type
*sigt
= *slot
;
3101 struct dwarf2_per_cu_data
***datap
= datum
;
3103 **datap
= &sigt
->per_cu
;
3109 /* Create the hash table of all entries in the .debug_types section.
3110 The result is zero if there is an error (e.g. missing .debug_types section),
3111 otherwise non-zero. */
3114 create_debug_types_hash_table (struct objfile
*objfile
)
3116 htab_t types_htab
= NULL
;
3117 struct dwarf2_per_cu_data
**iter
;
3119 struct dwarf2_section_info
*section
;
3121 if (VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
))
3123 dwarf2_per_objfile
->signatured_types
= NULL
;
3128 VEC_iterate (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
3132 gdb_byte
*info_ptr
, *end_ptr
;
3134 dwarf2_read_section (objfile
, section
);
3135 info_ptr
= section
->buffer
;
3137 if (info_ptr
== NULL
)
3140 if (types_htab
== NULL
)
3141 types_htab
= allocate_signatured_type_table (objfile
);
3143 if (dwarf2_die_debug
)
3144 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3146 end_ptr
= info_ptr
+ section
->size
;
3147 while (info_ptr
< end_ptr
)
3149 unsigned int offset
;
3150 unsigned int offset_size
;
3151 unsigned int type_offset
;
3152 unsigned int length
, initial_length_size
;
3153 unsigned short version
;
3155 struct signatured_type
*type_sig
;
3157 gdb_byte
*ptr
= info_ptr
;
3159 offset
= ptr
- section
->buffer
;
3161 /* We need to read the type's signature in order to build the hash
3162 table, but we don't need to read anything else just yet. */
3164 /* Sanity check to ensure entire cu is present. */
3165 length
= read_initial_length (objfile
->obfd
, ptr
,
3166 &initial_length_size
);
3167 if (ptr
+ length
+ initial_length_size
> end_ptr
)
3169 complaint (&symfile_complaints
,
3170 _("debug type entry runs off end "
3171 "of `.debug_types' section, ignored"));
3175 offset_size
= initial_length_size
== 4 ? 4 : 8;
3176 ptr
+= initial_length_size
;
3177 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3179 ptr
+= offset_size
; /* abbrev offset */
3180 ptr
+= 1; /* address size */
3181 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3183 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3185 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3186 memset (type_sig
, 0, sizeof (*type_sig
));
3187 type_sig
->signature
= signature
;
3188 type_sig
->type_offset
= type_offset
;
3189 type_sig
->per_cu
.objfile
= objfile
;
3190 type_sig
->per_cu
.debug_type_section
= section
;
3191 type_sig
->per_cu
.offset
= offset
;
3193 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3194 gdb_assert (slot
!= NULL
);
3197 const struct signatured_type
*dup_sig
= *slot
;
3199 complaint (&symfile_complaints
,
3200 _("debug type entry at offset 0x%x is duplicate to the "
3201 "entry at offset 0x%x, signature 0x%s"),
3202 offset
, dup_sig
->per_cu
.offset
,
3203 phex (signature
, sizeof (signature
)));
3204 gdb_assert (signature
== dup_sig
->signature
);
3208 if (dwarf2_die_debug
)
3209 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3210 offset
, phex (signature
, sizeof (signature
)));
3212 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3216 dwarf2_per_objfile
->signatured_types
= types_htab
;
3218 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3219 dwarf2_per_objfile
->type_comp_units
3220 = obstack_alloc (&objfile
->objfile_obstack
,
3221 dwarf2_per_objfile
->n_type_comp_units
3222 * sizeof (struct dwarf2_per_cu_data
*));
3223 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3224 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3225 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3226 == dwarf2_per_objfile
->n_type_comp_units
);
3231 /* Lookup a signature based type.
3232 Returns NULL if SIG is not present in the table. */
3234 static struct signatured_type
*
3235 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3237 struct signatured_type find_entry
, *entry
;
3239 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3241 complaint (&symfile_complaints
,
3242 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3246 find_entry
.signature
= sig
;
3247 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3251 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3254 init_cu_die_reader (struct die_reader_specs
*reader
,
3255 struct dwarf2_cu
*cu
)
3257 reader
->abfd
= cu
->objfile
->obfd
;
3259 if (cu
->per_cu
->debug_type_section
)
3261 gdb_assert (cu
->per_cu
->debug_type_section
->readin
);
3262 reader
->buffer
= cu
->per_cu
->debug_type_section
->buffer
;
3266 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3267 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3271 /* Find the base address of the compilation unit for range lists and
3272 location lists. It will normally be specified by DW_AT_low_pc.
3273 In DWARF-3 draft 4, the base address could be overridden by
3274 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3275 compilation units with discontinuous ranges. */
3278 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3280 struct attribute
*attr
;
3283 cu
->base_address
= 0;
3285 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3288 cu
->base_address
= DW_ADDR (attr
);
3293 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3296 cu
->base_address
= DW_ADDR (attr
);
3302 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3303 to combine the common parts.
3304 Process a compilation unit for a psymtab.
3305 BUFFER is a pointer to the beginning of the dwarf section buffer,
3306 either .debug_info or debug_types.
3307 INFO_PTR is a pointer to the start of the CU.
3308 Returns a pointer to the next CU. */
3311 process_psymtab_comp_unit (struct objfile
*objfile
,
3312 struct dwarf2_per_cu_data
*this_cu
,
3313 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3314 unsigned int buffer_size
)
3316 bfd
*abfd
= objfile
->obfd
;
3317 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3318 struct die_info
*comp_unit_die
;
3319 struct partial_symtab
*pst
;
3321 struct cleanup
*back_to_inner
;
3322 struct dwarf2_cu cu
;
3323 int has_children
, has_pc_info
;
3324 struct attribute
*attr
;
3325 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3326 struct die_reader_specs reader_specs
;
3327 const char *filename
;
3329 init_one_comp_unit (&cu
, objfile
);
3330 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3332 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3333 buffer
, buffer_size
,
3336 /* Complete the cu_header. */
3337 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3338 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3340 cu
.list_in_scope
= &file_symbols
;
3342 /* If this compilation unit was already read in, free the
3343 cached copy in order to read it in again. This is
3344 necessary because we skipped some symbols when we first
3345 read in the compilation unit (see load_partial_dies).
3346 This problem could be avoided, but the benefit is
3348 if (this_cu
->cu
!= NULL
)
3349 free_one_cached_comp_unit (this_cu
->cu
);
3351 /* Note that this is a pointer to our stack frame, being
3352 added to a global data structure. It will be cleaned up
3353 in free_stack_comp_unit when we finish with this
3354 compilation unit. */
3356 cu
.per_cu
= this_cu
;
3358 /* Read the abbrevs for this compilation unit into a table. */
3359 dwarf2_read_abbrevs (abfd
, &cu
);
3360 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3362 /* Read the compilation unit die. */
3363 if (this_cu
->debug_type_section
)
3364 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3365 init_cu_die_reader (&reader_specs
, &cu
);
3366 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3369 if (this_cu
->debug_type_section
)
3371 /* LENGTH has not been set yet for type units. */
3372 gdb_assert (this_cu
->offset
== cu
.header
.offset
);
3373 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3375 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3377 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3378 + cu
.header
.initial_length_size
);
3379 do_cleanups (back_to_inner
);
3383 prepare_one_comp_unit (&cu
, comp_unit_die
);
3385 /* Allocate a new partial symbol table structure. */
3386 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3387 if (attr
== NULL
|| !DW_STRING (attr
))
3390 filename
= DW_STRING (attr
);
3391 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3393 /* TEXTLOW and TEXTHIGH are set below. */
3395 objfile
->global_psymbols
.next
,
3396 objfile
->static_psymbols
.next
);
3398 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3400 pst
->dirname
= DW_STRING (attr
);
3402 pst
->read_symtab_private
= this_cu
;
3404 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3406 /* Store the function that reads in the rest of the symbol table. */
3407 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3409 this_cu
->v
.psymtab
= pst
;
3411 dwarf2_find_base_address (comp_unit_die
, &cu
);
3413 /* Possibly set the default values of LOWPC and HIGHPC from
3415 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3416 &best_highpc
, &cu
, pst
);
3417 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3418 /* Store the contiguous range if it is not empty; it can be empty for
3419 CUs with no code. */
3420 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3421 best_lowpc
+ baseaddr
,
3422 best_highpc
+ baseaddr
- 1, pst
);
3424 /* Check if comp unit has_children.
3425 If so, read the rest of the partial symbols from this comp unit.
3426 If not, there's no more debug_info for this comp unit. */
3429 struct partial_die_info
*first_die
;
3430 CORE_ADDR lowpc
, highpc
;
3432 lowpc
= ((CORE_ADDR
) -1);
3433 highpc
= ((CORE_ADDR
) 0);
3435 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3437 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3438 ! has_pc_info
, &cu
);
3440 /* If we didn't find a lowpc, set it to highpc to avoid
3441 complaints from `maint check'. */
3442 if (lowpc
== ((CORE_ADDR
) -1))
3445 /* If the compilation unit didn't have an explicit address range,
3446 then use the information extracted from its child dies. */
3450 best_highpc
= highpc
;
3453 pst
->textlow
= best_lowpc
+ baseaddr
;
3454 pst
->texthigh
= best_highpc
+ baseaddr
;
3456 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3457 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3458 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3459 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3460 sort_pst_symbols (pst
);
3462 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3463 + cu
.header
.initial_length_size
);
3465 if (this_cu
->debug_type_section
)
3467 /* It's not clear we want to do anything with stmt lists here.
3468 Waiting to see what gcc ultimately does. */
3472 /* Get the list of files included in the current compilation unit,
3473 and build a psymtab for each of them. */
3474 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3477 do_cleanups (back_to_inner
);
3482 /* Traversal function for htab_traverse_noresize.
3483 Process one .debug_types comp-unit. */
3486 process_type_comp_unit (void **slot
, void *info
)
3488 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3489 struct objfile
*objfile
= (struct objfile
*) info
;
3490 struct dwarf2_per_cu_data
*this_cu
;
3492 this_cu
= &entry
->per_cu
;
3494 gdb_assert (this_cu
->debug_type_section
->readin
);
3495 process_psymtab_comp_unit (objfile
, this_cu
,
3496 this_cu
->debug_type_section
->buffer
,
3497 (this_cu
->debug_type_section
->buffer
3499 this_cu
->debug_type_section
->size
);
3504 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3505 Build partial symbol tables for the .debug_types comp-units. */
3508 build_type_psymtabs (struct objfile
*objfile
)
3510 if (! create_debug_types_hash_table (objfile
))
3513 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3514 process_type_comp_unit
, objfile
);
3517 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3520 psymtabs_addrmap_cleanup (void *o
)
3522 struct objfile
*objfile
= o
;
3524 objfile
->psymtabs_addrmap
= NULL
;
3527 /* Build the partial symbol table by doing a quick pass through the
3528 .debug_info and .debug_abbrev sections. */
3531 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3534 struct cleanup
*back_to
, *addrmap_cleanup
;
3535 struct obstack temp_obstack
;
3537 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3539 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3540 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3542 /* Any cached compilation units will be linked by the per-objfile
3543 read_in_chain. Make sure to free them when we're done. */
3544 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3546 build_type_psymtabs (objfile
);
3548 create_all_comp_units (objfile
);
3550 /* Create a temporary address map on a temporary obstack. We later
3551 copy this to the final obstack. */
3552 obstack_init (&temp_obstack
);
3553 make_cleanup_obstack_free (&temp_obstack
);
3554 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3555 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3557 /* Since the objects we're extracting from .debug_info vary in
3558 length, only the individual functions to extract them (like
3559 read_comp_unit_head and load_partial_die) can really know whether
3560 the buffer is large enough to hold another complete object.
3562 At the moment, they don't actually check that. If .debug_info
3563 holds just one extra byte after the last compilation unit's dies,
3564 then read_comp_unit_head will happily read off the end of the
3565 buffer. read_partial_die is similarly casual. Those functions
3568 For this loop condition, simply checking whether there's any data
3569 left at all should be sufficient. */
3571 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3572 + dwarf2_per_objfile
->info
.size
))
3574 struct dwarf2_per_cu_data
*this_cu
;
3576 this_cu
= dwarf2_find_comp_unit (info_ptr
3577 - dwarf2_per_objfile
->info
.buffer
,
3580 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3581 dwarf2_per_objfile
->info
.buffer
,
3583 dwarf2_per_objfile
->info
.size
);
3586 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3587 &objfile
->objfile_obstack
);
3588 discard_cleanups (addrmap_cleanup
);
3590 do_cleanups (back_to
);
3593 /* Load the partial DIEs for a secondary CU into memory. */
3596 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3597 struct objfile
*objfile
)
3599 bfd
*abfd
= objfile
->obfd
;
3600 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3601 struct die_info
*comp_unit_die
;
3602 struct dwarf2_cu
*cu
;
3603 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3605 struct die_reader_specs reader_specs
;
3608 gdb_assert (! this_cu
->debug_type_section
);
3610 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3611 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3612 beg_of_comp_unit
= info_ptr
;
3614 if (this_cu
->cu
== NULL
)
3616 cu
= xmalloc (sizeof (*cu
));
3617 init_one_comp_unit (cu
, objfile
);
3621 /* If an error occurs while loading, release our storage. */
3622 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3624 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3625 dwarf2_per_objfile
->info
.buffer
,
3626 dwarf2_per_objfile
->info
.size
,
3629 /* Complete the cu_header. */
3630 cu
->header
.offset
= this_cu
->offset
;
3631 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3633 /* Link this compilation unit into the compilation unit tree. */
3635 cu
->per_cu
= this_cu
;
3637 /* Link this CU into read_in_chain. */
3638 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3639 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3644 info_ptr
+= cu
->header
.first_die_offset
;
3647 /* Read the abbrevs for this compilation unit into a table. */
3648 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3649 dwarf2_read_abbrevs (abfd
, cu
);
3650 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3652 /* Read the compilation unit die. */
3653 init_cu_die_reader (&reader_specs
, cu
);
3654 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3657 prepare_one_comp_unit (cu
, comp_unit_die
);
3659 /* Check if comp unit has_children.
3660 If so, read the rest of the partial symbols from this comp unit.
3661 If not, there's no more debug_info for this comp unit. */
3663 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3665 do_cleanups (free_abbrevs_cleanup
);
3669 /* We've successfully allocated this compilation unit. Let our
3670 caller clean it up when finished with it. */
3671 discard_cleanups (free_cu_cleanup
);
3675 /* Create a list of all compilation units in OBJFILE. We do this only
3676 if an inter-comp-unit reference is found; presumably if there is one,
3677 there will be many, and one will occur early in the .debug_info section.
3678 So there's no point in building this list incrementally. */
3681 create_all_comp_units (struct objfile
*objfile
)
3685 struct dwarf2_per_cu_data
**all_comp_units
;
3688 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3689 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3693 all_comp_units
= xmalloc (n_allocated
3694 * sizeof (struct dwarf2_per_cu_data
*));
3696 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3697 + dwarf2_per_objfile
->info
.size
)
3699 unsigned int length
, initial_length_size
;
3700 struct dwarf2_per_cu_data
*this_cu
;
3701 unsigned int offset
;
3703 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3705 /* Read just enough information to find out where the next
3706 compilation unit is. */
3707 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3708 &initial_length_size
);
3710 /* Save the compilation unit for later lookup. */
3711 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3712 sizeof (struct dwarf2_per_cu_data
));
3713 memset (this_cu
, 0, sizeof (*this_cu
));
3714 this_cu
->offset
= offset
;
3715 this_cu
->length
= length
+ initial_length_size
;
3716 this_cu
->objfile
= objfile
;
3718 if (n_comp_units
== n_allocated
)
3721 all_comp_units
= xrealloc (all_comp_units
,
3723 * sizeof (struct dwarf2_per_cu_data
*));
3725 all_comp_units
[n_comp_units
++] = this_cu
;
3727 info_ptr
= info_ptr
+ this_cu
->length
;
3730 dwarf2_per_objfile
->all_comp_units
3731 = obstack_alloc (&objfile
->objfile_obstack
,
3732 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3733 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3734 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3735 xfree (all_comp_units
);
3736 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3739 /* Process all loaded DIEs for compilation unit CU, starting at
3740 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3741 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3742 DW_AT_ranges). If NEED_PC is set, then this function will set
3743 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3744 and record the covered ranges in the addrmap. */
3747 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3748 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3750 struct partial_die_info
*pdi
;
3752 /* Now, march along the PDI's, descending into ones which have
3753 interesting children but skipping the children of the other ones,
3754 until we reach the end of the compilation unit. */
3760 fixup_partial_die (pdi
, cu
);
3762 /* Anonymous namespaces or modules have no name but have interesting
3763 children, so we need to look at them. Ditto for anonymous
3766 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3767 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3771 case DW_TAG_subprogram
:
3772 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3774 case DW_TAG_constant
:
3775 case DW_TAG_variable
:
3776 case DW_TAG_typedef
:
3777 case DW_TAG_union_type
:
3778 if (!pdi
->is_declaration
)
3780 add_partial_symbol (pdi
, cu
);
3783 case DW_TAG_class_type
:
3784 case DW_TAG_interface_type
:
3785 case DW_TAG_structure_type
:
3786 if (!pdi
->is_declaration
)
3788 add_partial_symbol (pdi
, cu
);
3791 case DW_TAG_enumeration_type
:
3792 if (!pdi
->is_declaration
)
3793 add_partial_enumeration (pdi
, cu
);
3795 case DW_TAG_base_type
:
3796 case DW_TAG_subrange_type
:
3797 /* File scope base type definitions are added to the partial
3799 add_partial_symbol (pdi
, cu
);
3801 case DW_TAG_namespace
:
3802 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3805 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3812 /* If the die has a sibling, skip to the sibling. */
3814 pdi
= pdi
->die_sibling
;
3818 /* Functions used to compute the fully scoped name of a partial DIE.
3820 Normally, this is simple. For C++, the parent DIE's fully scoped
3821 name is concatenated with "::" and the partial DIE's name. For
3822 Java, the same thing occurs except that "." is used instead of "::".
3823 Enumerators are an exception; they use the scope of their parent
3824 enumeration type, i.e. the name of the enumeration type is not
3825 prepended to the enumerator.
3827 There are two complexities. One is DW_AT_specification; in this
3828 case "parent" means the parent of the target of the specification,
3829 instead of the direct parent of the DIE. The other is compilers
3830 which do not emit DW_TAG_namespace; in this case we try to guess
3831 the fully qualified name of structure types from their members'
3832 linkage names. This must be done using the DIE's children rather
3833 than the children of any DW_AT_specification target. We only need
3834 to do this for structures at the top level, i.e. if the target of
3835 any DW_AT_specification (if any; otherwise the DIE itself) does not
3838 /* Compute the scope prefix associated with PDI's parent, in
3839 compilation unit CU. The result will be allocated on CU's
3840 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3841 field. NULL is returned if no prefix is necessary. */
3843 partial_die_parent_scope (struct partial_die_info
*pdi
,
3844 struct dwarf2_cu
*cu
)
3846 char *grandparent_scope
;
3847 struct partial_die_info
*parent
, *real_pdi
;
3849 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3850 then this means the parent of the specification DIE. */
3853 while (real_pdi
->has_specification
)
3854 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3856 parent
= real_pdi
->die_parent
;
3860 if (parent
->scope_set
)
3861 return parent
->scope
;
3863 fixup_partial_die (parent
, cu
);
3865 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3867 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3868 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3869 Work around this problem here. */
3870 if (cu
->language
== language_cplus
3871 && parent
->tag
== DW_TAG_namespace
3872 && strcmp (parent
->name
, "::") == 0
3873 && grandparent_scope
== NULL
)
3875 parent
->scope
= NULL
;
3876 parent
->scope_set
= 1;
3880 if (parent
->tag
== DW_TAG_namespace
3881 || parent
->tag
== DW_TAG_module
3882 || parent
->tag
== DW_TAG_structure_type
3883 || parent
->tag
== DW_TAG_class_type
3884 || parent
->tag
== DW_TAG_interface_type
3885 || parent
->tag
== DW_TAG_union_type
3886 || parent
->tag
== DW_TAG_enumeration_type
)
3888 if (grandparent_scope
== NULL
)
3889 parent
->scope
= parent
->name
;
3891 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3893 parent
->name
, 0, cu
);
3895 else if (parent
->tag
== DW_TAG_enumerator
)
3896 /* Enumerators should not get the name of the enumeration as a prefix. */
3897 parent
->scope
= grandparent_scope
;
3900 /* FIXME drow/2004-04-01: What should we be doing with
3901 function-local names? For partial symbols, we should probably be
3903 complaint (&symfile_complaints
,
3904 _("unhandled containing DIE tag %d for DIE at %d"),
3905 parent
->tag
, pdi
->offset
);
3906 parent
->scope
= grandparent_scope
;
3909 parent
->scope_set
= 1;
3910 return parent
->scope
;
3913 /* Return the fully scoped name associated with PDI, from compilation unit
3914 CU. The result will be allocated with malloc. */
3916 partial_die_full_name (struct partial_die_info
*pdi
,
3917 struct dwarf2_cu
*cu
)
3921 /* If this is a template instantiation, we can not work out the
3922 template arguments from partial DIEs. So, unfortunately, we have
3923 to go through the full DIEs. At least any work we do building
3924 types here will be reused if full symbols are loaded later. */
3925 if (pdi
->has_template_arguments
)
3927 fixup_partial_die (pdi
, cu
);
3929 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3931 struct die_info
*die
;
3932 struct attribute attr
;
3933 struct dwarf2_cu
*ref_cu
= cu
;
3936 attr
.form
= DW_FORM_ref_addr
;
3937 attr
.u
.addr
= pdi
->offset
;
3938 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3940 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3944 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3945 if (parent_scope
== NULL
)
3948 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3952 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3954 struct objfile
*objfile
= cu
->objfile
;
3956 char *actual_name
= NULL
;
3957 const struct partial_symbol
*psym
= NULL
;
3959 int built_actual_name
= 0;
3961 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3963 actual_name
= partial_die_full_name (pdi
, cu
);
3965 built_actual_name
= 1;
3967 if (actual_name
== NULL
)
3968 actual_name
= pdi
->name
;
3972 case DW_TAG_subprogram
:
3973 if (pdi
->is_external
|| cu
->language
== language_ada
)
3975 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3976 of the global scope. But in Ada, we want to be able to access
3977 nested procedures globally. So all Ada subprograms are stored
3978 in the global scope. */
3979 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3980 mst_text, objfile); */
3981 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3983 VAR_DOMAIN
, LOC_BLOCK
,
3984 &objfile
->global_psymbols
,
3985 0, pdi
->lowpc
+ baseaddr
,
3986 cu
->language
, objfile
);
3990 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3991 mst_file_text, objfile); */
3992 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3994 VAR_DOMAIN
, LOC_BLOCK
,
3995 &objfile
->static_psymbols
,
3996 0, pdi
->lowpc
+ baseaddr
,
3997 cu
->language
, objfile
);
4000 case DW_TAG_constant
:
4002 struct psymbol_allocation_list
*list
;
4004 if (pdi
->is_external
)
4005 list
= &objfile
->global_psymbols
;
4007 list
= &objfile
->static_psymbols
;
4008 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4009 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4010 list
, 0, 0, cu
->language
, objfile
);
4013 case DW_TAG_variable
:
4015 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4019 && !dwarf2_per_objfile
->has_section_at_zero
)
4021 /* A global or static variable may also have been stripped
4022 out by the linker if unused, in which case its address
4023 will be nullified; do not add such variables into partial
4024 symbol table then. */
4026 else if (pdi
->is_external
)
4029 Don't enter into the minimal symbol tables as there is
4030 a minimal symbol table entry from the ELF symbols already.
4031 Enter into partial symbol table if it has a location
4032 descriptor or a type.
4033 If the location descriptor is missing, new_symbol will create
4034 a LOC_UNRESOLVED symbol, the address of the variable will then
4035 be determined from the minimal symbol table whenever the variable
4037 The address for the partial symbol table entry is not
4038 used by GDB, but it comes in handy for debugging partial symbol
4041 if (pdi
->locdesc
|| pdi
->has_type
)
4042 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4044 VAR_DOMAIN
, LOC_STATIC
,
4045 &objfile
->global_psymbols
,
4047 cu
->language
, objfile
);
4051 /* Static Variable. Skip symbols without location descriptors. */
4052 if (pdi
->locdesc
== NULL
)
4054 if (built_actual_name
)
4055 xfree (actual_name
);
4058 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4059 mst_file_data, objfile); */
4060 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4062 VAR_DOMAIN
, LOC_STATIC
,
4063 &objfile
->static_psymbols
,
4065 cu
->language
, objfile
);
4068 case DW_TAG_typedef
:
4069 case DW_TAG_base_type
:
4070 case DW_TAG_subrange_type
:
4071 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4073 VAR_DOMAIN
, LOC_TYPEDEF
,
4074 &objfile
->static_psymbols
,
4075 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4077 case DW_TAG_namespace
:
4078 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4080 VAR_DOMAIN
, LOC_TYPEDEF
,
4081 &objfile
->global_psymbols
,
4082 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4084 case DW_TAG_class_type
:
4085 case DW_TAG_interface_type
:
4086 case DW_TAG_structure_type
:
4087 case DW_TAG_union_type
:
4088 case DW_TAG_enumeration_type
:
4089 /* Skip external references. The DWARF standard says in the section
4090 about "Structure, Union, and Class Type Entries": "An incomplete
4091 structure, union or class type is represented by a structure,
4092 union or class entry that does not have a byte size attribute
4093 and that has a DW_AT_declaration attribute." */
4094 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4096 if (built_actual_name
)
4097 xfree (actual_name
);
4101 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4102 static vs. global. */
4103 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4105 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4106 (cu
->language
== language_cplus
4107 || cu
->language
== language_java
)
4108 ? &objfile
->global_psymbols
4109 : &objfile
->static_psymbols
,
4110 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4113 case DW_TAG_enumerator
:
4114 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4116 VAR_DOMAIN
, LOC_CONST
,
4117 (cu
->language
== language_cplus
4118 || cu
->language
== language_java
)
4119 ? &objfile
->global_psymbols
4120 : &objfile
->static_psymbols
,
4121 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4127 if (built_actual_name
)
4128 xfree (actual_name
);
4131 /* Read a partial die corresponding to a namespace; also, add a symbol
4132 corresponding to that namespace to the symbol table. NAMESPACE is
4133 the name of the enclosing namespace. */
4136 add_partial_namespace (struct partial_die_info
*pdi
,
4137 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4138 int need_pc
, struct dwarf2_cu
*cu
)
4140 /* Add a symbol for the namespace. */
4142 add_partial_symbol (pdi
, cu
);
4144 /* Now scan partial symbols in that namespace. */
4146 if (pdi
->has_children
)
4147 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4150 /* Read a partial die corresponding to a Fortran module. */
4153 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4154 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4156 /* Now scan partial symbols in that module. */
4158 if (pdi
->has_children
)
4159 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4162 /* Read a partial die corresponding to a subprogram and create a partial
4163 symbol for that subprogram. When the CU language allows it, this
4164 routine also defines a partial symbol for each nested subprogram
4165 that this subprogram contains.
4167 DIE my also be a lexical block, in which case we simply search
4168 recursively for suprograms defined inside that lexical block.
4169 Again, this is only performed when the CU language allows this
4170 type of definitions. */
4173 add_partial_subprogram (struct partial_die_info
*pdi
,
4174 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4175 int need_pc
, struct dwarf2_cu
*cu
)
4177 if (pdi
->tag
== DW_TAG_subprogram
)
4179 if (pdi
->has_pc_info
)
4181 if (pdi
->lowpc
< *lowpc
)
4182 *lowpc
= pdi
->lowpc
;
4183 if (pdi
->highpc
> *highpc
)
4184 *highpc
= pdi
->highpc
;
4188 struct objfile
*objfile
= cu
->objfile
;
4190 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4191 SECT_OFF_TEXT (objfile
));
4192 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4193 pdi
->lowpc
+ baseaddr
,
4194 pdi
->highpc
- 1 + baseaddr
,
4195 cu
->per_cu
->v
.psymtab
);
4197 if (!pdi
->is_declaration
)
4198 /* Ignore subprogram DIEs that do not have a name, they are
4199 illegal. Do not emit a complaint at this point, we will
4200 do so when we convert this psymtab into a symtab. */
4202 add_partial_symbol (pdi
, cu
);
4206 if (! pdi
->has_children
)
4209 if (cu
->language
== language_ada
)
4211 pdi
= pdi
->die_child
;
4214 fixup_partial_die (pdi
, cu
);
4215 if (pdi
->tag
== DW_TAG_subprogram
4216 || pdi
->tag
== DW_TAG_lexical_block
)
4217 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4218 pdi
= pdi
->die_sibling
;
4223 /* Read a partial die corresponding to an enumeration type. */
4226 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4227 struct dwarf2_cu
*cu
)
4229 struct partial_die_info
*pdi
;
4231 if (enum_pdi
->name
!= NULL
)
4232 add_partial_symbol (enum_pdi
, cu
);
4234 pdi
= enum_pdi
->die_child
;
4237 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4238 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4240 add_partial_symbol (pdi
, cu
);
4241 pdi
= pdi
->die_sibling
;
4245 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4246 Return the corresponding abbrev, or NULL if the number is zero (indicating
4247 an empty DIE). In either case *BYTES_READ will be set to the length of
4248 the initial number. */
4250 static struct abbrev_info
*
4251 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4252 struct dwarf2_cu
*cu
)
4254 bfd
*abfd
= cu
->objfile
->obfd
;
4255 unsigned int abbrev_number
;
4256 struct abbrev_info
*abbrev
;
4258 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4260 if (abbrev_number
== 0)
4263 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4266 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4267 abbrev_number
, bfd_get_filename (abfd
));
4273 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4274 Returns a pointer to the end of a series of DIEs, terminated by an empty
4275 DIE. Any children of the skipped DIEs will also be skipped. */
4278 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4280 struct abbrev_info
*abbrev
;
4281 unsigned int bytes_read
;
4285 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4287 return info_ptr
+ bytes_read
;
4289 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4293 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4294 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4295 abbrev corresponding to that skipped uleb128 should be passed in
4296 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4300 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4301 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4303 unsigned int bytes_read
;
4304 struct attribute attr
;
4305 bfd
*abfd
= cu
->objfile
->obfd
;
4306 unsigned int form
, i
;
4308 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4310 /* The only abbrev we care about is DW_AT_sibling. */
4311 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4313 read_attribute (&attr
, &abbrev
->attrs
[i
],
4314 abfd
, info_ptr
, cu
);
4315 if (attr
.form
== DW_FORM_ref_addr
)
4316 complaint (&symfile_complaints
,
4317 _("ignoring absolute DW_AT_sibling"));
4319 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4322 /* If it isn't DW_AT_sibling, skip this attribute. */
4323 form
= abbrev
->attrs
[i
].form
;
4327 case DW_FORM_ref_addr
:
4328 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4329 and later it is offset sized. */
4330 if (cu
->header
.version
== 2)
4331 info_ptr
+= cu
->header
.addr_size
;
4333 info_ptr
+= cu
->header
.offset_size
;
4336 info_ptr
+= cu
->header
.addr_size
;
4343 case DW_FORM_flag_present
:
4355 case DW_FORM_ref_sig8
:
4358 case DW_FORM_string
:
4359 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4360 info_ptr
+= bytes_read
;
4362 case DW_FORM_sec_offset
:
4364 info_ptr
+= cu
->header
.offset_size
;
4366 case DW_FORM_exprloc
:
4368 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4369 info_ptr
+= bytes_read
;
4371 case DW_FORM_block1
:
4372 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4374 case DW_FORM_block2
:
4375 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4377 case DW_FORM_block4
:
4378 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4382 case DW_FORM_ref_udata
:
4383 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4385 case DW_FORM_indirect
:
4386 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4387 info_ptr
+= bytes_read
;
4388 /* We need to continue parsing from here, so just go back to
4390 goto skip_attribute
;
4393 error (_("Dwarf Error: Cannot handle %s "
4394 "in DWARF reader [in module %s]"),
4395 dwarf_form_name (form
),
4396 bfd_get_filename (abfd
));
4400 if (abbrev
->has_children
)
4401 return skip_children (buffer
, info_ptr
, cu
);
4406 /* Locate ORIG_PDI's sibling.
4407 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4411 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4412 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4413 bfd
*abfd
, struct dwarf2_cu
*cu
)
4415 /* Do we know the sibling already? */
4417 if (orig_pdi
->sibling
)
4418 return orig_pdi
->sibling
;
4420 /* Are there any children to deal with? */
4422 if (!orig_pdi
->has_children
)
4425 /* Skip the children the long way. */
4427 return skip_children (buffer
, info_ptr
, cu
);
4430 /* Expand this partial symbol table into a full symbol table. */
4433 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4439 warning (_("bug: psymtab for %s is already read in."),
4446 printf_filtered (_("Reading in symbols for %s..."),
4448 gdb_flush (gdb_stdout
);
4451 /* Restore our global data. */
4452 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4453 dwarf2_objfile_data_key
);
4455 /* If this psymtab is constructed from a debug-only objfile, the
4456 has_section_at_zero flag will not necessarily be correct. We
4457 can get the correct value for this flag by looking at the data
4458 associated with the (presumably stripped) associated objfile. */
4459 if (pst
->objfile
->separate_debug_objfile_backlink
)
4461 struct dwarf2_per_objfile
*dpo_backlink
4462 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4463 dwarf2_objfile_data_key
);
4465 dwarf2_per_objfile
->has_section_at_zero
4466 = dpo_backlink
->has_section_at_zero
;
4469 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4471 psymtab_to_symtab_1 (pst
);
4473 /* Finish up the debug error message. */
4475 printf_filtered (_("done.\n"));
4480 /* Add PER_CU to the queue. */
4483 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4485 struct dwarf2_queue_item
*item
;
4488 item
= xmalloc (sizeof (*item
));
4489 item
->per_cu
= per_cu
;
4492 if (dwarf2_queue
== NULL
)
4493 dwarf2_queue
= item
;
4495 dwarf2_queue_tail
->next
= item
;
4497 dwarf2_queue_tail
= item
;
4500 /* Process the queue. */
4503 process_queue (struct objfile
*objfile
)
4505 struct dwarf2_queue_item
*item
, *next_item
;
4507 /* The queue starts out with one item, but following a DIE reference
4508 may load a new CU, adding it to the end of the queue. */
4509 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4511 if (dwarf2_per_objfile
->using_index
4512 ? !item
->per_cu
->v
.quick
->symtab
4513 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4514 process_full_comp_unit (item
->per_cu
);
4516 item
->per_cu
->queued
= 0;
4517 next_item
= item
->next
;
4521 dwarf2_queue_tail
= NULL
;
4524 /* Free all allocated queue entries. This function only releases anything if
4525 an error was thrown; if the queue was processed then it would have been
4526 freed as we went along. */
4529 dwarf2_release_queue (void *dummy
)
4531 struct dwarf2_queue_item
*item
, *last
;
4533 item
= dwarf2_queue
;
4536 /* Anything still marked queued is likely to be in an
4537 inconsistent state, so discard it. */
4538 if (item
->per_cu
->queued
)
4540 if (item
->per_cu
->cu
!= NULL
)
4541 free_one_cached_comp_unit (item
->per_cu
->cu
);
4542 item
->per_cu
->queued
= 0;
4550 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4553 /* Read in full symbols for PST, and anything it depends on. */
4556 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4558 struct dwarf2_per_cu_data
*per_cu
;
4559 struct cleanup
*back_to
;
4562 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4563 if (!pst
->dependencies
[i
]->readin
)
4565 /* Inform about additional files that need to be read in. */
4568 /* FIXME: i18n: Need to make this a single string. */
4569 fputs_filtered (" ", gdb_stdout
);
4571 fputs_filtered ("and ", gdb_stdout
);
4573 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4574 wrap_here (""); /* Flush output. */
4575 gdb_flush (gdb_stdout
);
4577 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4580 per_cu
= pst
->read_symtab_private
;
4584 /* It's an include file, no symbols to read for it.
4585 Everything is in the parent symtab. */
4590 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4593 /* Load the DIEs associated with PER_CU into memory. */
4596 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
4597 struct objfile
*objfile
)
4599 bfd
*abfd
= objfile
->obfd
;
4600 struct dwarf2_cu
*cu
;
4601 unsigned int offset
;
4602 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4603 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4604 struct attribute
*attr
;
4607 gdb_assert (! per_cu
->debug_type_section
);
4609 /* Set local variables from the partial symbol table info. */
4610 offset
= per_cu
->offset
;
4612 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4613 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4614 beg_of_comp_unit
= info_ptr
;
4616 if (per_cu
->cu
== NULL
)
4618 cu
= xmalloc (sizeof (*cu
));
4619 init_one_comp_unit (cu
, objfile
);
4623 /* If an error occurs while loading, release our storage. */
4624 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4626 /* Read in the comp_unit header. */
4627 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4629 /* Complete the cu_header. */
4630 cu
->header
.offset
= offset
;
4631 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4633 /* Read the abbrevs for this compilation unit. */
4634 dwarf2_read_abbrevs (abfd
, cu
);
4635 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4637 /* Link this compilation unit into the compilation unit tree. */
4639 cu
->per_cu
= per_cu
;
4641 /* Link this CU into read_in_chain. */
4642 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4643 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4648 info_ptr
+= cu
->header
.first_die_offset
;
4651 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4653 /* We try not to read any attributes in this function, because not
4654 all objfiles needed for references have been loaded yet, and symbol
4655 table processing isn't initialized. But we have to set the CU language,
4656 or we won't be able to build types correctly. */
4657 prepare_one_comp_unit (cu
, cu
->dies
);
4659 /* Similarly, if we do not read the producer, we can not apply
4660 producer-specific interpretation. */
4661 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4663 cu
->producer
= DW_STRING (attr
);
4667 do_cleanups (free_abbrevs_cleanup
);
4669 /* We've successfully allocated this compilation unit. Let our
4670 caller clean it up when finished with it. */
4671 discard_cleanups (free_cu_cleanup
);
4675 /* Add a DIE to the delayed physname list. */
4678 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4679 const char *name
, struct die_info
*die
,
4680 struct dwarf2_cu
*cu
)
4682 struct delayed_method_info mi
;
4684 mi
.fnfield_index
= fnfield_index
;
4688 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4691 /* A cleanup for freeing the delayed method list. */
4694 free_delayed_list (void *ptr
)
4696 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4697 if (cu
->method_list
!= NULL
)
4699 VEC_free (delayed_method_info
, cu
->method_list
);
4700 cu
->method_list
= NULL
;
4704 /* Compute the physnames of any methods on the CU's method list.
4706 The computation of method physnames is delayed in order to avoid the
4707 (bad) condition that one of the method's formal parameters is of an as yet
4711 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4714 struct delayed_method_info
*mi
;
4715 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4717 const char *physname
;
4718 struct fn_fieldlist
*fn_flp
4719 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4720 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4721 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4725 /* Check for GCC >= 4.x. Return minor version (x) of 4.x in such case. If it
4726 is not GCC or it is GCC older than 4.x return -1. If it is GCC 5.x or
4727 higher return INT_MAX. */
4730 producer_is_gcc_ge_4 (struct dwarf2_cu
*cu
)
4735 if (cu
->producer
== NULL
)
4737 /* For unknown compilers expect their behavior is not compliant. For GCC
4738 this case can also happen for -gdwarf-4 type units supported since
4744 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
4746 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
4748 /* For non-GCC compilers expect their behavior is not compliant. */
4752 cs
= &cu
->producer
[strlen ("GNU ")];
4753 while (*cs
&& !isdigit (*cs
))
4755 if (sscanf (cs
, "%d.%d", &major
, &minor
) != 2)
4757 /* Not recognized as GCC. */
4769 /* Generate full symbol information for PST and CU, whose DIEs have
4770 already been loaded into memory. */
4773 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4775 struct dwarf2_cu
*cu
= per_cu
->cu
;
4776 struct objfile
*objfile
= per_cu
->objfile
;
4777 CORE_ADDR lowpc
, highpc
;
4778 struct symtab
*symtab
;
4779 struct cleanup
*back_to
, *delayed_list_cleanup
;
4782 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4785 back_to
= make_cleanup (really_free_pendings
, NULL
);
4786 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4788 cu
->list_in_scope
= &file_symbols
;
4790 /* Do line number decoding in read_file_scope () */
4791 process_die (cu
->dies
, cu
);
4793 /* Now that we have processed all the DIEs in the CU, all the types
4794 should be complete, and it should now be safe to compute all of the
4796 compute_delayed_physnames (cu
);
4797 do_cleanups (delayed_list_cleanup
);
4799 /* Some compilers don't define a DW_AT_high_pc attribute for the
4800 compilation unit. If the DW_AT_high_pc is missing, synthesize
4801 it, by scanning the DIE's below the compilation unit. */
4802 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4804 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4808 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
);
4810 /* Set symtab language to language from DW_AT_language. If the
4811 compilation is from a C file generated by language preprocessors, do
4812 not set the language if it was already deduced by start_subfile. */
4813 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4814 symtab
->language
= cu
->language
;
4816 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4817 produce DW_AT_location with location lists but it can be possibly
4818 invalid without -fvar-tracking.
4820 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4821 needed, it would be wrong due to missing DW_AT_producer there.
4823 Still one can confuse GDB by using non-standard GCC compilation
4824 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4826 if (cu
->has_loclist
&& gcc_4_minor
>= 0)
4827 symtab
->locations_valid
= 1;
4829 if (gcc_4_minor
>= 5)
4830 symtab
->epilogue_unwind_valid
= 1;
4833 if (dwarf2_per_objfile
->using_index
)
4834 per_cu
->v
.quick
->symtab
= symtab
;
4837 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4838 pst
->symtab
= symtab
;
4842 do_cleanups (back_to
);
4845 /* Process a die and its children. */
4848 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4852 case DW_TAG_padding
:
4854 case DW_TAG_compile_unit
:
4855 read_file_scope (die
, cu
);
4857 case DW_TAG_type_unit
:
4858 read_type_unit_scope (die
, cu
);
4860 case DW_TAG_subprogram
:
4861 case DW_TAG_inlined_subroutine
:
4862 read_func_scope (die
, cu
);
4864 case DW_TAG_lexical_block
:
4865 case DW_TAG_try_block
:
4866 case DW_TAG_catch_block
:
4867 read_lexical_block_scope (die
, cu
);
4869 case DW_TAG_class_type
:
4870 case DW_TAG_interface_type
:
4871 case DW_TAG_structure_type
:
4872 case DW_TAG_union_type
:
4873 process_structure_scope (die
, cu
);
4875 case DW_TAG_enumeration_type
:
4876 process_enumeration_scope (die
, cu
);
4879 /* These dies have a type, but processing them does not create
4880 a symbol or recurse to process the children. Therefore we can
4881 read them on-demand through read_type_die. */
4882 case DW_TAG_subroutine_type
:
4883 case DW_TAG_set_type
:
4884 case DW_TAG_array_type
:
4885 case DW_TAG_pointer_type
:
4886 case DW_TAG_ptr_to_member_type
:
4887 case DW_TAG_reference_type
:
4888 case DW_TAG_string_type
:
4891 case DW_TAG_base_type
:
4892 case DW_TAG_subrange_type
:
4893 case DW_TAG_typedef
:
4894 /* Add a typedef symbol for the type definition, if it has a
4896 new_symbol (die
, read_type_die (die
, cu
), cu
);
4898 case DW_TAG_common_block
:
4899 read_common_block (die
, cu
);
4901 case DW_TAG_common_inclusion
:
4903 case DW_TAG_namespace
:
4904 processing_has_namespace_info
= 1;
4905 read_namespace (die
, cu
);
4908 processing_has_namespace_info
= 1;
4909 read_module (die
, cu
);
4911 case DW_TAG_imported_declaration
:
4912 case DW_TAG_imported_module
:
4913 processing_has_namespace_info
= 1;
4914 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4915 || cu
->language
!= language_fortran
))
4916 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4917 dwarf_tag_name (die
->tag
));
4918 read_import_statement (die
, cu
);
4921 new_symbol (die
, NULL
, cu
);
4926 /* A helper function for dwarf2_compute_name which determines whether DIE
4927 needs to have the name of the scope prepended to the name listed in the
4931 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4933 struct attribute
*attr
;
4937 case DW_TAG_namespace
:
4938 case DW_TAG_typedef
:
4939 case DW_TAG_class_type
:
4940 case DW_TAG_interface_type
:
4941 case DW_TAG_structure_type
:
4942 case DW_TAG_union_type
:
4943 case DW_TAG_enumeration_type
:
4944 case DW_TAG_enumerator
:
4945 case DW_TAG_subprogram
:
4949 case DW_TAG_variable
:
4950 case DW_TAG_constant
:
4951 /* We only need to prefix "globally" visible variables. These include
4952 any variable marked with DW_AT_external or any variable that
4953 lives in a namespace. [Variables in anonymous namespaces
4954 require prefixing, but they are not DW_AT_external.] */
4956 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4958 struct dwarf2_cu
*spec_cu
= cu
;
4960 return die_needs_namespace (die_specification (die
, &spec_cu
),
4964 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4965 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4966 && die
->parent
->tag
!= DW_TAG_module
)
4968 /* A variable in a lexical block of some kind does not need a
4969 namespace, even though in C++ such variables may be external
4970 and have a mangled name. */
4971 if (die
->parent
->tag
== DW_TAG_lexical_block
4972 || die
->parent
->tag
== DW_TAG_try_block
4973 || die
->parent
->tag
== DW_TAG_catch_block
4974 || die
->parent
->tag
== DW_TAG_subprogram
)
4983 /* Retrieve the last character from a mem_file. */
4986 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4988 char *last_char_p
= (char *) object
;
4991 *last_char_p
= buffer
[length
- 1];
4994 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4995 compute the physname for the object, which include a method's
4996 formal parameters (C++/Java) and return type (Java).
4998 For Ada, return the DIE's linkage name rather than the fully qualified
4999 name. PHYSNAME is ignored..
5001 The result is allocated on the objfile_obstack and canonicalized. */
5004 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5008 name
= dwarf2_name (die
, cu
);
5010 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5011 compute it by typename_concat inside GDB. */
5012 if (cu
->language
== language_ada
5013 || (cu
->language
== language_fortran
&& physname
))
5015 /* For Ada unit, we prefer the linkage name over the name, as
5016 the former contains the exported name, which the user expects
5017 to be able to reference. Ideally, we want the user to be able
5018 to reference this entity using either natural or linkage name,
5019 but we haven't started looking at this enhancement yet. */
5020 struct attribute
*attr
;
5022 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5024 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5025 if (attr
&& DW_STRING (attr
))
5026 return DW_STRING (attr
);
5029 /* These are the only languages we know how to qualify names in. */
5031 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5032 || cu
->language
== language_fortran
))
5034 if (die_needs_namespace (die
, cu
))
5038 struct ui_file
*buf
;
5040 prefix
= determine_prefix (die
, cu
);
5041 buf
= mem_fileopen ();
5042 if (*prefix
!= '\0')
5044 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5047 fputs_unfiltered (prefixed_name
, buf
);
5048 xfree (prefixed_name
);
5051 fputs_unfiltered (name
, buf
);
5053 /* Template parameters may be specified in the DIE's DW_AT_name, or
5054 as children with DW_TAG_template_type_param or
5055 DW_TAG_value_type_param. If the latter, add them to the name
5056 here. If the name already has template parameters, then
5057 skip this step; some versions of GCC emit both, and
5058 it is more efficient to use the pre-computed name.
5060 Something to keep in mind about this process: it is very
5061 unlikely, or in some cases downright impossible, to produce
5062 something that will match the mangled name of a function.
5063 If the definition of the function has the same debug info,
5064 we should be able to match up with it anyway. But fallbacks
5065 using the minimal symbol, for instance to find a method
5066 implemented in a stripped copy of libstdc++, will not work.
5067 If we do not have debug info for the definition, we will have to
5068 match them up some other way.
5070 When we do name matching there is a related problem with function
5071 templates; two instantiated function templates are allowed to
5072 differ only by their return types, which we do not add here. */
5074 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5076 struct attribute
*attr
;
5077 struct die_info
*child
;
5080 die
->building_fullname
= 1;
5082 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5087 struct dwarf2_locexpr_baton
*baton
;
5090 if (child
->tag
!= DW_TAG_template_type_param
5091 && child
->tag
!= DW_TAG_template_value_param
)
5096 fputs_unfiltered ("<", buf
);
5100 fputs_unfiltered (", ", buf
);
5102 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5105 complaint (&symfile_complaints
,
5106 _("template parameter missing DW_AT_type"));
5107 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5110 type
= die_type (child
, cu
);
5112 if (child
->tag
== DW_TAG_template_type_param
)
5114 c_print_type (type
, "", buf
, -1, 0);
5118 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5121 complaint (&symfile_complaints
,
5122 _("template parameter missing "
5123 "DW_AT_const_value"));
5124 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5128 dwarf2_const_value_attr (attr
, type
, name
,
5129 &cu
->comp_unit_obstack
, cu
,
5130 &value
, &bytes
, &baton
);
5132 if (TYPE_NOSIGN (type
))
5133 /* GDB prints characters as NUMBER 'CHAR'. If that's
5134 changed, this can use value_print instead. */
5135 c_printchar (value
, type
, buf
);
5138 struct value_print_options opts
;
5141 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5145 else if (bytes
!= NULL
)
5147 v
= allocate_value (type
);
5148 memcpy (value_contents_writeable (v
), bytes
,
5149 TYPE_LENGTH (type
));
5152 v
= value_from_longest (type
, value
);
5154 /* Specify decimal so that we do not depend on
5156 get_formatted_print_options (&opts
, 'd');
5158 value_print (v
, buf
, &opts
);
5164 die
->building_fullname
= 0;
5168 /* Close the argument list, with a space if necessary
5169 (nested templates). */
5170 char last_char
= '\0';
5171 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5172 if (last_char
== '>')
5173 fputs_unfiltered (" >", buf
);
5175 fputs_unfiltered (">", buf
);
5179 /* For Java and C++ methods, append formal parameter type
5180 information, if PHYSNAME. */
5182 if (physname
&& die
->tag
== DW_TAG_subprogram
5183 && (cu
->language
== language_cplus
5184 || cu
->language
== language_java
))
5186 struct type
*type
= read_type_die (die
, cu
);
5188 c_type_print_args (type
, buf
, 1, cu
->language
);
5190 if (cu
->language
== language_java
)
5192 /* For java, we must append the return type to method
5194 if (die
->tag
== DW_TAG_subprogram
)
5195 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5198 else if (cu
->language
== language_cplus
)
5200 /* Assume that an artificial first parameter is
5201 "this", but do not crash if it is not. RealView
5202 marks unnamed (and thus unused) parameters as
5203 artificial; there is no way to differentiate
5205 if (TYPE_NFIELDS (type
) > 0
5206 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5207 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5208 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5210 fputs_unfiltered (" const", buf
);
5214 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
5216 ui_file_delete (buf
);
5218 if (cu
->language
== language_cplus
)
5221 = dwarf2_canonicalize_name (name
, cu
,
5222 &cu
->objfile
->objfile_obstack
);
5233 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5234 If scope qualifiers are appropriate they will be added. The result
5235 will be allocated on the objfile_obstack, or NULL if the DIE does
5236 not have a name. NAME may either be from a previous call to
5237 dwarf2_name or NULL.
5239 The output string will be canonicalized (if C++/Java). */
5242 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5244 return dwarf2_compute_name (name
, die
, cu
, 0);
5247 /* Construct a physname for the given DIE in CU. NAME may either be
5248 from a previous call to dwarf2_name or NULL. The result will be
5249 allocated on the objfile_objstack or NULL if the DIE does not have a
5252 The output string will be canonicalized (if C++/Java). */
5255 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5257 struct attribute
*attr
;
5258 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5259 struct cleanup
*back_to
;
5262 /* In this case dwarf2_compute_name is just a shortcut not building anything
5264 if (!die_needs_namespace (die
, cu
))
5265 return dwarf2_compute_name (name
, die
, cu
, 1);
5267 back_to
= make_cleanup (null_cleanup
, NULL
);
5269 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5271 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5273 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5275 if (attr
&& DW_STRING (attr
))
5279 mangled
= DW_STRING (attr
);
5281 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5282 type. It is easier for GDB users to search for such functions as
5283 `name(params)' than `long name(params)'. In such case the minimal
5284 symbol names do not match the full symbol names but for template
5285 functions there is never a need to look up their definition from their
5286 declaration so the only disadvantage remains the minimal symbol
5287 variant `long name(params)' does not have the proper inferior type.
5290 demangled
= cplus_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
5291 | (cu
->language
== language_java
5292 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5296 make_cleanup (xfree
, demangled
);
5306 if (canon
== NULL
|| check_physname
)
5308 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5310 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5312 /* It may not mean a bug in GDB. The compiler could also
5313 compute DW_AT_linkage_name incorrectly. But in such case
5314 GDB would need to be bug-to-bug compatible. */
5316 complaint (&symfile_complaints
,
5317 _("Computed physname <%s> does not match demangled <%s> "
5318 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5319 physname
, canon
, mangled
, die
->offset
, cu
->objfile
->name
);
5321 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5322 is available here - over computed PHYSNAME. It is safer
5323 against both buggy GDB and buggy compilers. */
5337 retval
= obsavestring (retval
, strlen (retval
),
5338 &cu
->objfile
->objfile_obstack
);
5340 do_cleanups (back_to
);
5344 /* Read the import statement specified by the given die and record it. */
5347 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5349 struct attribute
*import_attr
;
5350 struct die_info
*imported_die
, *child_die
;
5351 struct dwarf2_cu
*imported_cu
;
5352 const char *imported_name
;
5353 const char *imported_name_prefix
;
5354 const char *canonical_name
;
5355 const char *import_alias
;
5356 const char *imported_declaration
= NULL
;
5357 const char *import_prefix
;
5358 VEC (const_char_ptr
) *excludes
= NULL
;
5359 struct cleanup
*cleanups
;
5363 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5364 if (import_attr
== NULL
)
5366 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5367 dwarf_tag_name (die
->tag
));
5372 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5373 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5374 if (imported_name
== NULL
)
5376 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5378 The import in the following code:
5392 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5393 <52> DW_AT_decl_file : 1
5394 <53> DW_AT_decl_line : 6
5395 <54> DW_AT_import : <0x75>
5396 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5398 <5b> DW_AT_decl_file : 1
5399 <5c> DW_AT_decl_line : 2
5400 <5d> DW_AT_type : <0x6e>
5402 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5403 <76> DW_AT_byte_size : 4
5404 <77> DW_AT_encoding : 5 (signed)
5406 imports the wrong die ( 0x75 instead of 0x58 ).
5407 This case will be ignored until the gcc bug is fixed. */
5411 /* Figure out the local name after import. */
5412 import_alias
= dwarf2_name (die
, cu
);
5414 /* Figure out where the statement is being imported to. */
5415 import_prefix
= determine_prefix (die
, cu
);
5417 /* Figure out what the scope of the imported die is and prepend it
5418 to the name of the imported die. */
5419 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5421 if (imported_die
->tag
!= DW_TAG_namespace
5422 && imported_die
->tag
!= DW_TAG_module
)
5424 imported_declaration
= imported_name
;
5425 canonical_name
= imported_name_prefix
;
5427 else if (strlen (imported_name_prefix
) > 0)
5429 temp
= alloca (strlen (imported_name_prefix
)
5430 + 2 + strlen (imported_name
) + 1);
5431 strcpy (temp
, imported_name_prefix
);
5432 strcat (temp
, "::");
5433 strcat (temp
, imported_name
);
5434 canonical_name
= temp
;
5437 canonical_name
= imported_name
;
5439 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5441 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5442 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5443 child_die
= sibling_die (child_die
))
5445 /* DWARF-4: A Fortran use statement with a “rename list” may be
5446 represented by an imported module entry with an import attribute
5447 referring to the module and owned entries corresponding to those
5448 entities that are renamed as part of being imported. */
5450 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5452 complaint (&symfile_complaints
,
5453 _("child DW_TAG_imported_declaration expected "
5454 "- DIE at 0x%x [in module %s]"),
5455 child_die
->offset
, cu
->objfile
->name
);
5459 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5460 if (import_attr
== NULL
)
5462 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5463 dwarf_tag_name (child_die
->tag
));
5468 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5470 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5471 if (imported_name
== NULL
)
5473 complaint (&symfile_complaints
,
5474 _("child DW_TAG_imported_declaration has unknown "
5475 "imported name - DIE at 0x%x [in module %s]"),
5476 child_die
->offset
, cu
->objfile
->name
);
5480 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5482 process_die (child_die
, cu
);
5485 cp_add_using_directive (import_prefix
,
5488 imported_declaration
,
5490 &cu
->objfile
->objfile_obstack
);
5492 do_cleanups (cleanups
);
5496 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5498 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5501 /* Cleanup function for read_file_scope. */
5504 free_cu_line_header (void *arg
)
5506 struct dwarf2_cu
*cu
= arg
;
5508 free_line_header (cu
->line_header
);
5509 cu
->line_header
= NULL
;
5513 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5514 char **name
, char **comp_dir
)
5516 struct attribute
*attr
;
5521 /* Find the filename. Do not use dwarf2_name here, since the filename
5522 is not a source language identifier. */
5523 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5526 *name
= DW_STRING (attr
);
5529 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5531 *comp_dir
= DW_STRING (attr
);
5532 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5534 *comp_dir
= ldirname (*name
);
5535 if (*comp_dir
!= NULL
)
5536 make_cleanup (xfree
, *comp_dir
);
5538 if (*comp_dir
!= NULL
)
5540 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5541 directory, get rid of it. */
5542 char *cp
= strchr (*comp_dir
, ':');
5544 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5549 *name
= "<unknown>";
5552 /* Handle DW_AT_stmt_list for a compilation unit. */
5555 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
5556 const char *comp_dir
)
5558 struct attribute
*attr
;
5559 struct objfile
*objfile
= cu
->objfile
;
5560 bfd
*abfd
= objfile
->obfd
;
5562 /* Decode line number information if present. We do this before
5563 processing child DIEs, so that the line header table is available
5564 for DW_AT_decl_file. */
5565 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5568 unsigned int line_offset
= DW_UNSND (attr
);
5569 struct line_header
*line_header
5570 = dwarf_decode_line_header (line_offset
, abfd
, cu
);
5574 cu
->line_header
= line_header
;
5575 make_cleanup (free_cu_line_header
, cu
);
5576 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5581 /* Process DW_TAG_compile_unit. */
5584 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5586 struct objfile
*objfile
= cu
->objfile
;
5587 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5588 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5589 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5590 struct attribute
*attr
;
5592 char *comp_dir
= NULL
;
5593 struct die_info
*child_die
;
5594 bfd
*abfd
= objfile
->obfd
;
5597 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5599 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5601 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5602 from finish_block. */
5603 if (lowpc
== ((CORE_ADDR
) -1))
5608 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5610 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5613 set_cu_language (DW_UNSND (attr
), cu
);
5616 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5618 cu
->producer
= DW_STRING (attr
);
5620 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5621 standardised yet. As a workaround for the language detection we fall
5622 back to the DW_AT_producer string. */
5623 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5624 cu
->language
= language_opencl
;
5626 /* We assume that we're processing GCC output. */
5627 processing_gcc_compilation
= 2;
5629 processing_has_namespace_info
= 0;
5631 start_symtab (name
, comp_dir
, lowpc
);
5632 record_debugformat ("DWARF 2");
5633 record_producer (cu
->producer
);
5635 initialize_cu_func_list (cu
);
5637 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5639 /* Process all dies in compilation unit. */
5640 if (die
->child
!= NULL
)
5642 child_die
= die
->child
;
5643 while (child_die
&& child_die
->tag
)
5645 process_die (child_die
, cu
);
5646 child_die
= sibling_die (child_die
);
5650 /* Decode macro information, if present. Dwarf 2 macro information
5651 refers to information in the line number info statement program
5652 header, so we can only read it if we've read the header
5654 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
5655 if (attr
&& cu
->line_header
)
5657 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
5658 complaint (&symfile_complaints
,
5659 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5661 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
5663 &dwarf2_per_objfile
->macro
, 1);
5667 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5668 if (attr
&& cu
->line_header
)
5670 unsigned int macro_offset
= DW_UNSND (attr
);
5672 dwarf_decode_macros (cu
->line_header
, macro_offset
,
5674 &dwarf2_per_objfile
->macinfo
, 0);
5677 do_cleanups (back_to
);
5680 /* Process DW_TAG_type_unit.
5681 For TUs we want to skip the first top level sibling if it's not the
5682 actual type being defined by this TU. In this case the first top
5683 level sibling is there to provide context only. */
5686 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5688 struct objfile
*objfile
= cu
->objfile
;
5689 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5691 struct attribute
*attr
;
5693 char *comp_dir
= NULL
;
5694 struct die_info
*child_die
;
5695 bfd
*abfd
= objfile
->obfd
;
5697 /* start_symtab needs a low pc, but we don't really have one.
5698 Do what read_file_scope would do in the absence of such info. */
5699 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5701 /* Find the filename. Do not use dwarf2_name here, since the filename
5702 is not a source language identifier. */
5703 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5705 name
= DW_STRING (attr
);
5707 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5709 comp_dir
= DW_STRING (attr
);
5710 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5712 comp_dir
= ldirname (name
);
5713 if (comp_dir
!= NULL
)
5714 make_cleanup (xfree
, comp_dir
);
5720 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5722 set_cu_language (DW_UNSND (attr
), cu
);
5724 /* This isn't technically needed today. It is done for symmetry
5725 with read_file_scope. */
5726 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5728 cu
->producer
= DW_STRING (attr
);
5730 /* We assume that we're processing GCC output. */
5731 processing_gcc_compilation
= 2;
5733 processing_has_namespace_info
= 0;
5735 start_symtab (name
, comp_dir
, lowpc
);
5736 record_debugformat ("DWARF 2");
5737 record_producer (cu
->producer
);
5739 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5741 /* Process the dies in the type unit. */
5742 if (die
->child
== NULL
)
5744 dump_die_for_error (die
);
5745 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5746 bfd_get_filename (abfd
));
5749 child_die
= die
->child
;
5751 while (child_die
&& child_die
->tag
)
5753 process_die (child_die
, cu
);
5755 child_die
= sibling_die (child_die
);
5758 do_cleanups (back_to
);
5762 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5763 struct dwarf2_cu
*cu
)
5765 struct function_range
*thisfn
;
5767 thisfn
= (struct function_range
*)
5768 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5769 thisfn
->name
= name
;
5770 thisfn
->lowpc
= lowpc
;
5771 thisfn
->highpc
= highpc
;
5772 thisfn
->seen_line
= 0;
5773 thisfn
->next
= NULL
;
5775 if (cu
->last_fn
== NULL
)
5776 cu
->first_fn
= thisfn
;
5778 cu
->last_fn
->next
= thisfn
;
5780 cu
->last_fn
= thisfn
;
5783 /* qsort helper for inherit_abstract_dies. */
5786 unsigned_int_compar (const void *ap
, const void *bp
)
5788 unsigned int a
= *(unsigned int *) ap
;
5789 unsigned int b
= *(unsigned int *) bp
;
5791 return (a
> b
) - (b
> a
);
5794 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5795 Inherit only the children of the DW_AT_abstract_origin DIE not being
5796 already referenced by DW_AT_abstract_origin from the children of the
5800 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5802 struct die_info
*child_die
;
5803 unsigned die_children_count
;
5804 /* CU offsets which were referenced by children of the current DIE. */
5806 unsigned *offsets_end
, *offsetp
;
5807 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5808 struct die_info
*origin_die
;
5809 /* Iterator of the ORIGIN_DIE children. */
5810 struct die_info
*origin_child_die
;
5811 struct cleanup
*cleanups
;
5812 struct attribute
*attr
;
5813 struct dwarf2_cu
*origin_cu
;
5814 struct pending
**origin_previous_list_in_scope
;
5816 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5820 /* Note that following die references may follow to a die in a
5824 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5826 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5828 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5829 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5831 if (die
->tag
!= origin_die
->tag
5832 && !(die
->tag
== DW_TAG_inlined_subroutine
5833 && origin_die
->tag
== DW_TAG_subprogram
))
5834 complaint (&symfile_complaints
,
5835 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5836 die
->offset
, origin_die
->offset
);
5838 child_die
= die
->child
;
5839 die_children_count
= 0;
5840 while (child_die
&& child_die
->tag
)
5842 child_die
= sibling_die (child_die
);
5843 die_children_count
++;
5845 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5846 cleanups
= make_cleanup (xfree
, offsets
);
5848 offsets_end
= offsets
;
5849 child_die
= die
->child
;
5850 while (child_die
&& child_die
->tag
)
5852 /* For each CHILD_DIE, find the corresponding child of
5853 ORIGIN_DIE. If there is more than one layer of
5854 DW_AT_abstract_origin, follow them all; there shouldn't be,
5855 but GCC versions at least through 4.4 generate this (GCC PR
5857 struct die_info
*child_origin_die
= child_die
;
5858 struct dwarf2_cu
*child_origin_cu
= cu
;
5862 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5866 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5870 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5871 counterpart may exist. */
5872 if (child_origin_die
!= child_die
)
5874 if (child_die
->tag
!= child_origin_die
->tag
5875 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5876 && child_origin_die
->tag
== DW_TAG_subprogram
))
5877 complaint (&symfile_complaints
,
5878 _("Child DIE 0x%x and its abstract origin 0x%x have "
5879 "different tags"), child_die
->offset
,
5880 child_origin_die
->offset
);
5881 if (child_origin_die
->parent
!= origin_die
)
5882 complaint (&symfile_complaints
,
5883 _("Child DIE 0x%x and its abstract origin 0x%x have "
5884 "different parents"), child_die
->offset
,
5885 child_origin_die
->offset
);
5887 *offsets_end
++ = child_origin_die
->offset
;
5889 child_die
= sibling_die (child_die
);
5891 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5892 unsigned_int_compar
);
5893 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5894 if (offsetp
[-1] == *offsetp
)
5895 complaint (&symfile_complaints
,
5896 _("Multiple children of DIE 0x%x refer "
5897 "to DIE 0x%x as their abstract origin"),
5898 die
->offset
, *offsetp
);
5901 origin_child_die
= origin_die
->child
;
5902 while (origin_child_die
&& origin_child_die
->tag
)
5904 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5905 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5907 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5909 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5910 process_die (origin_child_die
, origin_cu
);
5912 origin_child_die
= sibling_die (origin_child_die
);
5914 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5916 do_cleanups (cleanups
);
5920 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5922 struct objfile
*objfile
= cu
->objfile
;
5923 struct context_stack
*new;
5926 struct die_info
*child_die
;
5927 struct attribute
*attr
, *call_line
, *call_file
;
5930 struct block
*block
;
5931 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5932 VEC (symbolp
) *template_args
= NULL
;
5933 struct template_symbol
*templ_func
= NULL
;
5937 /* If we do not have call site information, we can't show the
5938 caller of this inlined function. That's too confusing, so
5939 only use the scope for local variables. */
5940 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5941 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5942 if (call_line
== NULL
|| call_file
== NULL
)
5944 read_lexical_block_scope (die
, cu
);
5949 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5951 name
= dwarf2_name (die
, cu
);
5953 /* Ignore functions with missing or empty names. These are actually
5954 illegal according to the DWARF standard. */
5957 complaint (&symfile_complaints
,
5958 _("missing name for subprogram DIE at %d"), die
->offset
);
5962 /* Ignore functions with missing or invalid low and high pc attributes. */
5963 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5965 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5966 if (!attr
|| !DW_UNSND (attr
))
5967 complaint (&symfile_complaints
,
5968 _("cannot get low and high bounds "
5969 "for subprogram DIE at %d"),
5977 /* Record the function range for dwarf_decode_lines. */
5978 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5980 /* If we have any template arguments, then we must allocate a
5981 different sort of symbol. */
5982 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5984 if (child_die
->tag
== DW_TAG_template_type_param
5985 || child_die
->tag
== DW_TAG_template_value_param
)
5987 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5988 struct template_symbol
);
5989 templ_func
->base
.is_cplus_template_function
= 1;
5994 new = push_context (0, lowpc
);
5995 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5996 (struct symbol
*) templ_func
);
5998 /* If there is a location expression for DW_AT_frame_base, record
6000 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
6002 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
6003 expression is being recorded directly in the function's symbol
6004 and not in a separate frame-base object. I guess this hack is
6005 to avoid adding some sort of frame-base adjunct/annex to the
6006 function's symbol :-(. The problem with doing this is that it
6007 results in a function symbol with a location expression that
6008 has nothing to do with the location of the function, ouch! The
6009 relationship should be: a function's symbol has-a frame base; a
6010 frame-base has-a location expression. */
6011 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
6013 cu
->list_in_scope
= &local_symbols
;
6015 if (die
->child
!= NULL
)
6017 child_die
= die
->child
;
6018 while (child_die
&& child_die
->tag
)
6020 if (child_die
->tag
== DW_TAG_template_type_param
6021 || child_die
->tag
== DW_TAG_template_value_param
)
6023 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6026 VEC_safe_push (symbolp
, template_args
, arg
);
6029 process_die (child_die
, cu
);
6030 child_die
= sibling_die (child_die
);
6034 inherit_abstract_dies (die
, cu
);
6036 /* If we have a DW_AT_specification, we might need to import using
6037 directives from the context of the specification DIE. See the
6038 comment in determine_prefix. */
6039 if (cu
->language
== language_cplus
6040 && dwarf2_attr (die
, DW_AT_specification
, cu
))
6042 struct dwarf2_cu
*spec_cu
= cu
;
6043 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
6047 child_die
= spec_die
->child
;
6048 while (child_die
&& child_die
->tag
)
6050 if (child_die
->tag
== DW_TAG_imported_module
)
6051 process_die (child_die
, spec_cu
);
6052 child_die
= sibling_die (child_die
);
6055 /* In some cases, GCC generates specification DIEs that
6056 themselves contain DW_AT_specification attributes. */
6057 spec_die
= die_specification (spec_die
, &spec_cu
);
6061 new = pop_context ();
6062 /* Make a block for the local symbols within. */
6063 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
6064 lowpc
, highpc
, objfile
);
6066 /* For C++, set the block's scope. */
6067 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
6068 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
6069 determine_prefix (die
, cu
),
6070 processing_has_namespace_info
);
6072 /* If we have address ranges, record them. */
6073 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6075 /* Attach template arguments to function. */
6076 if (! VEC_empty (symbolp
, template_args
))
6078 gdb_assert (templ_func
!= NULL
);
6080 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
6081 templ_func
->template_arguments
6082 = obstack_alloc (&objfile
->objfile_obstack
,
6083 (templ_func
->n_template_arguments
6084 * sizeof (struct symbol
*)));
6085 memcpy (templ_func
->template_arguments
,
6086 VEC_address (symbolp
, template_args
),
6087 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
6088 VEC_free (symbolp
, template_args
);
6091 /* In C++, we can have functions nested inside functions (e.g., when
6092 a function declares a class that has methods). This means that
6093 when we finish processing a function scope, we may need to go
6094 back to building a containing block's symbol lists. */
6095 local_symbols
= new->locals
;
6096 param_symbols
= new->params
;
6097 using_directives
= new->using_directives
;
6099 /* If we've finished processing a top-level function, subsequent
6100 symbols go in the file symbol list. */
6101 if (outermost_context_p ())
6102 cu
->list_in_scope
= &file_symbols
;
6105 /* Process all the DIES contained within a lexical block scope. Start
6106 a new scope, process the dies, and then close the scope. */
6109 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6111 struct objfile
*objfile
= cu
->objfile
;
6112 struct context_stack
*new;
6113 CORE_ADDR lowpc
, highpc
;
6114 struct die_info
*child_die
;
6117 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6119 /* Ignore blocks with missing or invalid low and high pc attributes. */
6120 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6121 as multiple lexical blocks? Handling children in a sane way would
6122 be nasty. Might be easier to properly extend generic blocks to
6124 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6129 push_context (0, lowpc
);
6130 if (die
->child
!= NULL
)
6132 child_die
= die
->child
;
6133 while (child_die
&& child_die
->tag
)
6135 process_die (child_die
, cu
);
6136 child_die
= sibling_die (child_die
);
6139 new = pop_context ();
6141 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6144 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6147 /* Note that recording ranges after traversing children, as we
6148 do here, means that recording a parent's ranges entails
6149 walking across all its children's ranges as they appear in
6150 the address map, which is quadratic behavior.
6152 It would be nicer to record the parent's ranges before
6153 traversing its children, simply overriding whatever you find
6154 there. But since we don't even decide whether to create a
6155 block until after we've traversed its children, that's hard
6157 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6159 local_symbols
= new->locals
;
6160 using_directives
= new->using_directives
;
6163 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6164 Return 1 if the attributes are present and valid, otherwise, return 0.
6165 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6168 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6169 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6170 struct partial_symtab
*ranges_pst
)
6172 struct objfile
*objfile
= cu
->objfile
;
6173 struct comp_unit_head
*cu_header
= &cu
->header
;
6174 bfd
*obfd
= objfile
->obfd
;
6175 unsigned int addr_size
= cu_header
->addr_size
;
6176 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6177 /* Base address selection entry. */
6188 found_base
= cu
->base_known
;
6189 base
= cu
->base_address
;
6191 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6192 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6194 complaint (&symfile_complaints
,
6195 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6199 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6201 /* Read in the largest possible address. */
6202 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6203 if ((marker
& mask
) == mask
)
6205 /* If we found the largest possible address, then
6206 read the base address. */
6207 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6208 buffer
+= 2 * addr_size
;
6209 offset
+= 2 * addr_size
;
6215 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6219 CORE_ADDR range_beginning
, range_end
;
6221 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6222 buffer
+= addr_size
;
6223 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6224 buffer
+= addr_size
;
6225 offset
+= 2 * addr_size
;
6227 /* An end of list marker is a pair of zero addresses. */
6228 if (range_beginning
== 0 && range_end
== 0)
6229 /* Found the end of list entry. */
6232 /* Each base address selection entry is a pair of 2 values.
6233 The first is the largest possible address, the second is
6234 the base address. Check for a base address here. */
6235 if ((range_beginning
& mask
) == mask
)
6237 /* If we found the largest possible address, then
6238 read the base address. */
6239 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6246 /* We have no valid base address for the ranges
6248 complaint (&symfile_complaints
,
6249 _("Invalid .debug_ranges data (no base address)"));
6253 if (range_beginning
> range_end
)
6255 /* Inverted range entries are invalid. */
6256 complaint (&symfile_complaints
,
6257 _("Invalid .debug_ranges data (inverted range)"));
6261 /* Empty range entries have no effect. */
6262 if (range_beginning
== range_end
)
6265 range_beginning
+= base
;
6268 if (ranges_pst
!= NULL
)
6269 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6270 range_beginning
+ baseaddr
,
6271 range_end
- 1 + baseaddr
,
6274 /* FIXME: This is recording everything as a low-high
6275 segment of consecutive addresses. We should have a
6276 data structure for discontiguous block ranges
6280 low
= range_beginning
;
6286 if (range_beginning
< low
)
6287 low
= range_beginning
;
6288 if (range_end
> high
)
6294 /* If the first entry is an end-of-list marker, the range
6295 describes an empty scope, i.e. no instructions. */
6301 *high_return
= high
;
6305 /* Get low and high pc attributes from a die. Return 1 if the attributes
6306 are present and valid, otherwise, return 0. Return -1 if the range is
6307 discontinuous, i.e. derived from DW_AT_ranges information. */
6309 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6310 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6311 struct partial_symtab
*pst
)
6313 struct attribute
*attr
;
6318 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6321 high
= DW_ADDR (attr
);
6322 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6324 low
= DW_ADDR (attr
);
6326 /* Found high w/o low attribute. */
6329 /* Found consecutive range of addresses. */
6334 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6337 /* Value of the DW_AT_ranges attribute is the offset in the
6338 .debug_ranges section. */
6339 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6341 /* Found discontinuous range of addresses. */
6346 /* read_partial_die has also the strict LOW < HIGH requirement. */
6350 /* When using the GNU linker, .gnu.linkonce. sections are used to
6351 eliminate duplicate copies of functions and vtables and such.
6352 The linker will arbitrarily choose one and discard the others.
6353 The AT_*_pc values for such functions refer to local labels in
6354 these sections. If the section from that file was discarded, the
6355 labels are not in the output, so the relocs get a value of 0.
6356 If this is a discarded function, mark the pc bounds as invalid,
6357 so that GDB will ignore it. */
6358 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6366 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6367 its low and high PC addresses. Do nothing if these addresses could not
6368 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6369 and HIGHPC to the high address if greater than HIGHPC. */
6372 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6373 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6374 struct dwarf2_cu
*cu
)
6376 CORE_ADDR low
, high
;
6377 struct die_info
*child
= die
->child
;
6379 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6381 *lowpc
= min (*lowpc
, low
);
6382 *highpc
= max (*highpc
, high
);
6385 /* If the language does not allow nested subprograms (either inside
6386 subprograms or lexical blocks), we're done. */
6387 if (cu
->language
!= language_ada
)
6390 /* Check all the children of the given DIE. If it contains nested
6391 subprograms, then check their pc bounds. Likewise, we need to
6392 check lexical blocks as well, as they may also contain subprogram
6394 while (child
&& child
->tag
)
6396 if (child
->tag
== DW_TAG_subprogram
6397 || child
->tag
== DW_TAG_lexical_block
)
6398 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6399 child
= sibling_die (child
);
6403 /* Get the low and high pc's represented by the scope DIE, and store
6404 them in *LOWPC and *HIGHPC. If the correct values can't be
6405 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6408 get_scope_pc_bounds (struct die_info
*die
,
6409 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6410 struct dwarf2_cu
*cu
)
6412 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6413 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6414 CORE_ADDR current_low
, current_high
;
6416 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6418 best_low
= current_low
;
6419 best_high
= current_high
;
6423 struct die_info
*child
= die
->child
;
6425 while (child
&& child
->tag
)
6427 switch (child
->tag
) {
6428 case DW_TAG_subprogram
:
6429 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6431 case DW_TAG_namespace
:
6433 /* FIXME: carlton/2004-01-16: Should we do this for
6434 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6435 that current GCC's always emit the DIEs corresponding
6436 to definitions of methods of classes as children of a
6437 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6438 the DIEs giving the declarations, which could be
6439 anywhere). But I don't see any reason why the
6440 standards says that they have to be there. */
6441 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6443 if (current_low
!= ((CORE_ADDR
) -1))
6445 best_low
= min (best_low
, current_low
);
6446 best_high
= max (best_high
, current_high
);
6454 child
= sibling_die (child
);
6459 *highpc
= best_high
;
6462 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6465 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6466 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6468 struct attribute
*attr
;
6470 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6473 CORE_ADDR high
= DW_ADDR (attr
);
6475 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6478 CORE_ADDR low
= DW_ADDR (attr
);
6480 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6484 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6487 bfd
*obfd
= cu
->objfile
->obfd
;
6489 /* The value of the DW_AT_ranges attribute is the offset of the
6490 address range list in the .debug_ranges section. */
6491 unsigned long offset
= DW_UNSND (attr
);
6492 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6494 /* For some target architectures, but not others, the
6495 read_address function sign-extends the addresses it returns.
6496 To recognize base address selection entries, we need a
6498 unsigned int addr_size
= cu
->header
.addr_size
;
6499 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6501 /* The base address, to which the next pair is relative. Note
6502 that this 'base' is a DWARF concept: most entries in a range
6503 list are relative, to reduce the number of relocs against the
6504 debugging information. This is separate from this function's
6505 'baseaddr' argument, which GDB uses to relocate debugging
6506 information from a shared library based on the address at
6507 which the library was loaded. */
6508 CORE_ADDR base
= cu
->base_address
;
6509 int base_known
= cu
->base_known
;
6511 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6512 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6514 complaint (&symfile_complaints
,
6515 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6522 unsigned int bytes_read
;
6523 CORE_ADDR start
, end
;
6525 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6526 buffer
+= bytes_read
;
6527 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6528 buffer
+= bytes_read
;
6530 /* Did we find the end of the range list? */
6531 if (start
== 0 && end
== 0)
6534 /* Did we find a base address selection entry? */
6535 else if ((start
& base_select_mask
) == base_select_mask
)
6541 /* We found an ordinary address range. */
6546 complaint (&symfile_complaints
,
6547 _("Invalid .debug_ranges data "
6548 "(no base address)"));
6554 /* Inverted range entries are invalid. */
6555 complaint (&symfile_complaints
,
6556 _("Invalid .debug_ranges data "
6557 "(inverted range)"));
6561 /* Empty range entries have no effect. */
6565 record_block_range (block
,
6566 baseaddr
+ base
+ start
,
6567 baseaddr
+ base
+ end
- 1);
6573 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6574 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6575 during 4.6.0 experimental. */
6578 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6581 int major
, minor
, release
;
6583 if (cu
->producer
== NULL
)
6585 /* For unknown compilers expect their behavior is DWARF version
6588 GCC started to support .debug_types sections by -gdwarf-4 since
6589 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6590 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6591 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6592 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6597 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6599 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6601 /* For non-GCC compilers expect their behavior is DWARF version
6606 cs
= &cu
->producer
[strlen ("GNU ")];
6607 while (*cs
&& !isdigit (*cs
))
6609 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6611 /* Not recognized as GCC. */
6616 return major
< 4 || (major
== 4 && minor
< 6);
6619 /* Return the default accessibility type if it is not overriden by
6620 DW_AT_accessibility. */
6622 static enum dwarf_access_attribute
6623 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6625 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6627 /* The default DWARF 2 accessibility for members is public, the default
6628 accessibility for inheritance is private. */
6630 if (die
->tag
!= DW_TAG_inheritance
)
6631 return DW_ACCESS_public
;
6633 return DW_ACCESS_private
;
6637 /* DWARF 3+ defines the default accessibility a different way. The same
6638 rules apply now for DW_TAG_inheritance as for the members and it only
6639 depends on the container kind. */
6641 if (die
->parent
->tag
== DW_TAG_class_type
)
6642 return DW_ACCESS_private
;
6644 return DW_ACCESS_public
;
6648 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6649 offset. If the attribute was not found return 0, otherwise return
6650 1. If it was found but could not properly be handled, set *OFFSET
6654 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
6657 struct attribute
*attr
;
6659 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6664 /* Note that we do not check for a section offset first here.
6665 This is because DW_AT_data_member_location is new in DWARF 4,
6666 so if we see it, we can assume that a constant form is really
6667 a constant and not a section offset. */
6668 if (attr_form_is_constant (attr
))
6669 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
6670 else if (attr_form_is_section_offset (attr
))
6671 dwarf2_complex_location_expr_complaint ();
6672 else if (attr_form_is_block (attr
))
6673 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6675 dwarf2_complex_location_expr_complaint ();
6683 /* Add an aggregate field to the field list. */
6686 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6687 struct dwarf2_cu
*cu
)
6689 struct objfile
*objfile
= cu
->objfile
;
6690 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6691 struct nextfield
*new_field
;
6692 struct attribute
*attr
;
6694 char *fieldname
= "";
6696 /* Allocate a new field list entry and link it in. */
6697 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6698 make_cleanup (xfree
, new_field
);
6699 memset (new_field
, 0, sizeof (struct nextfield
));
6701 if (die
->tag
== DW_TAG_inheritance
)
6703 new_field
->next
= fip
->baseclasses
;
6704 fip
->baseclasses
= new_field
;
6708 new_field
->next
= fip
->fields
;
6709 fip
->fields
= new_field
;
6713 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6715 new_field
->accessibility
= DW_UNSND (attr
);
6717 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
6718 if (new_field
->accessibility
!= DW_ACCESS_public
)
6719 fip
->non_public_fields
= 1;
6721 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6723 new_field
->virtuality
= DW_UNSND (attr
);
6725 new_field
->virtuality
= DW_VIRTUALITY_none
;
6727 fp
= &new_field
->field
;
6729 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6733 /* Data member other than a C++ static data member. */
6735 /* Get type of field. */
6736 fp
->type
= die_type (die
, cu
);
6738 SET_FIELD_BITPOS (*fp
, 0);
6740 /* Get bit size of field (zero if none). */
6741 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6744 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6748 FIELD_BITSIZE (*fp
) = 0;
6751 /* Get bit offset of field. */
6752 if (handle_data_member_location (die
, cu
, &offset
))
6753 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
6754 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6757 if (gdbarch_bits_big_endian (gdbarch
))
6759 /* For big endian bits, the DW_AT_bit_offset gives the
6760 additional bit offset from the MSB of the containing
6761 anonymous object to the MSB of the field. We don't
6762 have to do anything special since we don't need to
6763 know the size of the anonymous object. */
6764 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6768 /* For little endian bits, compute the bit offset to the
6769 MSB of the anonymous object, subtract off the number of
6770 bits from the MSB of the field to the MSB of the
6771 object, and then subtract off the number of bits of
6772 the field itself. The result is the bit offset of
6773 the LSB of the field. */
6775 int bit_offset
= DW_UNSND (attr
);
6777 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6780 /* The size of the anonymous object containing
6781 the bit field is explicit, so use the
6782 indicated size (in bytes). */
6783 anonymous_size
= DW_UNSND (attr
);
6787 /* The size of the anonymous object containing
6788 the bit field must be inferred from the type
6789 attribute of the data member containing the
6791 anonymous_size
= TYPE_LENGTH (fp
->type
);
6793 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6794 - bit_offset
- FIELD_BITSIZE (*fp
);
6798 /* Get name of field. */
6799 fieldname
= dwarf2_name (die
, cu
);
6800 if (fieldname
== NULL
)
6803 /* The name is already allocated along with this objfile, so we don't
6804 need to duplicate it for the type. */
6805 fp
->name
= fieldname
;
6807 /* Change accessibility for artificial fields (e.g. virtual table
6808 pointer or virtual base class pointer) to private. */
6809 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6811 FIELD_ARTIFICIAL (*fp
) = 1;
6812 new_field
->accessibility
= DW_ACCESS_private
;
6813 fip
->non_public_fields
= 1;
6816 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6818 /* C++ static member. */
6820 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6821 is a declaration, but all versions of G++ as of this writing
6822 (so through at least 3.2.1) incorrectly generate
6823 DW_TAG_variable tags. */
6825 const char *physname
;
6827 /* Get name of field. */
6828 fieldname
= dwarf2_name (die
, cu
);
6829 if (fieldname
== NULL
)
6832 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6834 /* Only create a symbol if this is an external value.
6835 new_symbol checks this and puts the value in the global symbol
6836 table, which we want. If it is not external, new_symbol
6837 will try to put the value in cu->list_in_scope which is wrong. */
6838 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6840 /* A static const member, not much different than an enum as far as
6841 we're concerned, except that we can support more types. */
6842 new_symbol (die
, NULL
, cu
);
6845 /* Get physical name. */
6846 physname
= dwarf2_physname (fieldname
, die
, cu
);
6848 /* The name is already allocated along with this objfile, so we don't
6849 need to duplicate it for the type. */
6850 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6851 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6852 FIELD_NAME (*fp
) = fieldname
;
6854 else if (die
->tag
== DW_TAG_inheritance
)
6858 /* C++ base class field. */
6859 if (handle_data_member_location (die
, cu
, &offset
))
6860 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
6861 FIELD_BITSIZE (*fp
) = 0;
6862 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6863 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6864 fip
->nbaseclasses
++;
6868 /* Add a typedef defined in the scope of the FIP's class. */
6871 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6872 struct dwarf2_cu
*cu
)
6874 struct objfile
*objfile
= cu
->objfile
;
6875 struct typedef_field_list
*new_field
;
6876 struct attribute
*attr
;
6877 struct typedef_field
*fp
;
6878 char *fieldname
= "";
6880 /* Allocate a new field list entry and link it in. */
6881 new_field
= xzalloc (sizeof (*new_field
));
6882 make_cleanup (xfree
, new_field
);
6884 gdb_assert (die
->tag
== DW_TAG_typedef
);
6886 fp
= &new_field
->field
;
6888 /* Get name of field. */
6889 fp
->name
= dwarf2_name (die
, cu
);
6890 if (fp
->name
== NULL
)
6893 fp
->type
= read_type_die (die
, cu
);
6895 new_field
->next
= fip
->typedef_field_list
;
6896 fip
->typedef_field_list
= new_field
;
6897 fip
->typedef_field_list_count
++;
6900 /* Create the vector of fields, and attach it to the type. */
6903 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6904 struct dwarf2_cu
*cu
)
6906 int nfields
= fip
->nfields
;
6908 /* Record the field count, allocate space for the array of fields,
6909 and create blank accessibility bitfields if necessary. */
6910 TYPE_NFIELDS (type
) = nfields
;
6911 TYPE_FIELDS (type
) = (struct field
*)
6912 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6913 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6915 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6917 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6919 TYPE_FIELD_PRIVATE_BITS (type
) =
6920 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6921 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6923 TYPE_FIELD_PROTECTED_BITS (type
) =
6924 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6925 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6927 TYPE_FIELD_IGNORE_BITS (type
) =
6928 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6929 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6932 /* If the type has baseclasses, allocate and clear a bit vector for
6933 TYPE_FIELD_VIRTUAL_BITS. */
6934 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6936 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6937 unsigned char *pointer
;
6939 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6940 pointer
= TYPE_ALLOC (type
, num_bytes
);
6941 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6942 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6943 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6946 /* Copy the saved-up fields into the field vector. Start from the head of
6947 the list, adding to the tail of the field array, so that they end up in
6948 the same order in the array in which they were added to the list. */
6949 while (nfields
-- > 0)
6951 struct nextfield
*fieldp
;
6955 fieldp
= fip
->fields
;
6956 fip
->fields
= fieldp
->next
;
6960 fieldp
= fip
->baseclasses
;
6961 fip
->baseclasses
= fieldp
->next
;
6964 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6965 switch (fieldp
->accessibility
)
6967 case DW_ACCESS_private
:
6968 if (cu
->language
!= language_ada
)
6969 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6972 case DW_ACCESS_protected
:
6973 if (cu
->language
!= language_ada
)
6974 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6977 case DW_ACCESS_public
:
6981 /* Unknown accessibility. Complain and treat it as public. */
6983 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6984 fieldp
->accessibility
);
6988 if (nfields
< fip
->nbaseclasses
)
6990 switch (fieldp
->virtuality
)
6992 case DW_VIRTUALITY_virtual
:
6993 case DW_VIRTUALITY_pure_virtual
:
6994 if (cu
->language
== language_ada
)
6995 error (_("unexpected virtuality in component of Ada type"));
6996 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
7003 /* Add a member function to the proper fieldlist. */
7006 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
7007 struct type
*type
, struct dwarf2_cu
*cu
)
7009 struct objfile
*objfile
= cu
->objfile
;
7010 struct attribute
*attr
;
7011 struct fnfieldlist
*flp
;
7013 struct fn_field
*fnp
;
7015 struct nextfnfield
*new_fnfield
;
7016 struct type
*this_type
;
7017 enum dwarf_access_attribute accessibility
;
7019 if (cu
->language
== language_ada
)
7020 error (_("unexpected member function in Ada type"));
7022 /* Get name of member function. */
7023 fieldname
= dwarf2_name (die
, cu
);
7024 if (fieldname
== NULL
)
7027 /* Look up member function name in fieldlist. */
7028 for (i
= 0; i
< fip
->nfnfields
; i
++)
7030 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7034 /* Create new list element if necessary. */
7035 if (i
< fip
->nfnfields
)
7036 flp
= &fip
->fnfieldlists
[i
];
7039 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7041 fip
->fnfieldlists
= (struct fnfieldlist
*)
7042 xrealloc (fip
->fnfieldlists
,
7043 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7044 * sizeof (struct fnfieldlist
));
7045 if (fip
->nfnfields
== 0)
7046 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7048 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7049 flp
->name
= fieldname
;
7052 i
= fip
->nfnfields
++;
7055 /* Create a new member function field and chain it to the field list
7057 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7058 make_cleanup (xfree
, new_fnfield
);
7059 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7060 new_fnfield
->next
= flp
->head
;
7061 flp
->head
= new_fnfield
;
7064 /* Fill in the member function field info. */
7065 fnp
= &new_fnfield
->fnfield
;
7067 /* Delay processing of the physname until later. */
7068 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7070 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7075 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7076 fnp
->physname
= physname
? physname
: "";
7079 fnp
->type
= alloc_type (objfile
);
7080 this_type
= read_type_die (die
, cu
);
7081 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7083 int nparams
= TYPE_NFIELDS (this_type
);
7085 /* TYPE is the domain of this method, and THIS_TYPE is the type
7086 of the method itself (TYPE_CODE_METHOD). */
7087 smash_to_method_type (fnp
->type
, type
,
7088 TYPE_TARGET_TYPE (this_type
),
7089 TYPE_FIELDS (this_type
),
7090 TYPE_NFIELDS (this_type
),
7091 TYPE_VARARGS (this_type
));
7093 /* Handle static member functions.
7094 Dwarf2 has no clean way to discern C++ static and non-static
7095 member functions. G++ helps GDB by marking the first
7096 parameter for non-static member functions (which is the this
7097 pointer) as artificial. We obtain this information from
7098 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7099 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7100 fnp
->voffset
= VOFFSET_STATIC
;
7103 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7104 dwarf2_full_name (fieldname
, die
, cu
));
7106 /* Get fcontext from DW_AT_containing_type if present. */
7107 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7108 fnp
->fcontext
= die_containing_type (die
, cu
);
7110 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7111 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7113 /* Get accessibility. */
7114 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7116 accessibility
= DW_UNSND (attr
);
7118 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7119 switch (accessibility
)
7121 case DW_ACCESS_private
:
7122 fnp
->is_private
= 1;
7124 case DW_ACCESS_protected
:
7125 fnp
->is_protected
= 1;
7129 /* Check for artificial methods. */
7130 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7131 if (attr
&& DW_UNSND (attr
) != 0)
7132 fnp
->is_artificial
= 1;
7134 /* Get index in virtual function table if it is a virtual member
7135 function. For older versions of GCC, this is an offset in the
7136 appropriate virtual table, as specified by DW_AT_containing_type.
7137 For everyone else, it is an expression to be evaluated relative
7138 to the object address. */
7140 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7143 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7145 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7147 /* Old-style GCC. */
7148 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7150 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7151 || (DW_BLOCK (attr
)->size
> 1
7152 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7153 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7155 struct dwarf_block blk
;
7158 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7160 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7161 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7162 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7163 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7164 dwarf2_complex_location_expr_complaint ();
7166 fnp
->voffset
/= cu
->header
.addr_size
;
7170 dwarf2_complex_location_expr_complaint ();
7173 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7175 else if (attr_form_is_section_offset (attr
))
7177 dwarf2_complex_location_expr_complaint ();
7181 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7187 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7188 if (attr
&& DW_UNSND (attr
))
7190 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7191 complaint (&symfile_complaints
,
7192 _("Member function \"%s\" (offset %d) is virtual "
7193 "but the vtable offset is not specified"),
7194 fieldname
, die
->offset
);
7195 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7196 TYPE_CPLUS_DYNAMIC (type
) = 1;
7201 /* Create the vector of member function fields, and attach it to the type. */
7204 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7205 struct dwarf2_cu
*cu
)
7207 struct fnfieldlist
*flp
;
7208 int total_length
= 0;
7211 if (cu
->language
== language_ada
)
7212 error (_("unexpected member functions in Ada type"));
7214 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7215 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7216 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7218 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7220 struct nextfnfield
*nfp
= flp
->head
;
7221 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7224 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7225 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7226 fn_flp
->fn_fields
= (struct fn_field
*)
7227 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7228 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7229 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7231 total_length
+= flp
->length
;
7234 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7235 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
7238 /* Returns non-zero if NAME is the name of a vtable member in CU's
7239 language, zero otherwise. */
7241 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7243 static const char vptr
[] = "_vptr";
7244 static const char vtable
[] = "vtable";
7246 /* Look for the C++ and Java forms of the vtable. */
7247 if ((cu
->language
== language_java
7248 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7249 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7250 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7256 /* GCC outputs unnamed structures that are really pointers to member
7257 functions, with the ABI-specified layout. If TYPE describes
7258 such a structure, smash it into a member function type.
7260 GCC shouldn't do this; it should just output pointer to member DIEs.
7261 This is GCC PR debug/28767. */
7264 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7266 struct type
*pfn_type
, *domain_type
, *new_type
;
7268 /* Check for a structure with no name and two children. */
7269 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7272 /* Check for __pfn and __delta members. */
7273 if (TYPE_FIELD_NAME (type
, 0) == NULL
7274 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7275 || TYPE_FIELD_NAME (type
, 1) == NULL
7276 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7279 /* Find the type of the method. */
7280 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7281 if (pfn_type
== NULL
7282 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7283 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7286 /* Look for the "this" argument. */
7287 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7288 if (TYPE_NFIELDS (pfn_type
) == 0
7289 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7290 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7293 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7294 new_type
= alloc_type (objfile
);
7295 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7296 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7297 TYPE_VARARGS (pfn_type
));
7298 smash_to_methodptr_type (type
, new_type
);
7301 /* Called when we find the DIE that starts a structure or union scope
7302 (definition) to create a type for the structure or union. Fill in
7303 the type's name and general properties; the members will not be
7304 processed until process_structure_type.
7306 NOTE: we need to call these functions regardless of whether or not the
7307 DIE has a DW_AT_name attribute, since it might be an anonymous
7308 structure or union. This gets the type entered into our set of
7311 However, if the structure is incomplete (an opaque struct/union)
7312 then suppress creating a symbol table entry for it since gdb only
7313 wants to find the one with the complete definition. Note that if
7314 it is complete, we just call new_symbol, which does it's own
7315 checking about whether the struct/union is anonymous or not (and
7316 suppresses creating a symbol table entry itself). */
7318 static struct type
*
7319 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7321 struct objfile
*objfile
= cu
->objfile
;
7323 struct attribute
*attr
;
7326 /* If the definition of this type lives in .debug_types, read that type.
7327 Don't follow DW_AT_specification though, that will take us back up
7328 the chain and we want to go down. */
7329 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7332 struct dwarf2_cu
*type_cu
= cu
;
7333 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7335 /* We could just recurse on read_structure_type, but we need to call
7336 get_die_type to ensure only one type for this DIE is created.
7337 This is important, for example, because for c++ classes we need
7338 TYPE_NAME set which is only done by new_symbol. Blech. */
7339 type
= read_type_die (type_die
, type_cu
);
7341 /* TYPE_CU may not be the same as CU.
7342 Ensure TYPE is recorded in CU's type_hash table. */
7343 return set_die_type (die
, type
, cu
);
7346 type
= alloc_type (objfile
);
7347 INIT_CPLUS_SPECIFIC (type
);
7349 name
= dwarf2_name (die
, cu
);
7352 if (cu
->language
== language_cplus
7353 || cu
->language
== language_java
)
7355 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7357 /* dwarf2_full_name might have already finished building the DIE's
7358 type. If so, there is no need to continue. */
7359 if (get_die_type (die
, cu
) != NULL
)
7360 return get_die_type (die
, cu
);
7362 TYPE_TAG_NAME (type
) = full_name
;
7363 if (die
->tag
== DW_TAG_structure_type
7364 || die
->tag
== DW_TAG_class_type
)
7365 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7369 /* The name is already allocated along with this objfile, so
7370 we don't need to duplicate it for the type. */
7371 TYPE_TAG_NAME (type
) = (char *) name
;
7372 if (die
->tag
== DW_TAG_class_type
)
7373 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7377 if (die
->tag
== DW_TAG_structure_type
)
7379 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7381 else if (die
->tag
== DW_TAG_union_type
)
7383 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7387 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7390 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7391 TYPE_DECLARED_CLASS (type
) = 1;
7393 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7396 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7400 TYPE_LENGTH (type
) = 0;
7403 TYPE_STUB_SUPPORTED (type
) = 1;
7404 if (die_is_declaration (die
, cu
))
7405 TYPE_STUB (type
) = 1;
7406 else if (attr
== NULL
&& die
->child
== NULL
7407 && producer_is_realview (cu
->producer
))
7408 /* RealView does not output the required DW_AT_declaration
7409 on incomplete types. */
7410 TYPE_STUB (type
) = 1;
7412 /* We need to add the type field to the die immediately so we don't
7413 infinitely recurse when dealing with pointers to the structure
7414 type within the structure itself. */
7415 set_die_type (die
, type
, cu
);
7417 /* set_die_type should be already done. */
7418 set_descriptive_type (type
, die
, cu
);
7423 /* Finish creating a structure or union type, including filling in
7424 its members and creating a symbol for it. */
7427 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7429 struct objfile
*objfile
= cu
->objfile
;
7430 struct die_info
*child_die
= die
->child
;
7433 type
= get_die_type (die
, cu
);
7435 type
= read_structure_type (die
, cu
);
7437 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7439 struct field_info fi
;
7440 struct die_info
*child_die
;
7441 VEC (symbolp
) *template_args
= NULL
;
7442 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7444 memset (&fi
, 0, sizeof (struct field_info
));
7446 child_die
= die
->child
;
7448 while (child_die
&& child_die
->tag
)
7450 if (child_die
->tag
== DW_TAG_member
7451 || child_die
->tag
== DW_TAG_variable
)
7453 /* NOTE: carlton/2002-11-05: A C++ static data member
7454 should be a DW_TAG_member that is a declaration, but
7455 all versions of G++ as of this writing (so through at
7456 least 3.2.1) incorrectly generate DW_TAG_variable
7457 tags for them instead. */
7458 dwarf2_add_field (&fi
, child_die
, cu
);
7460 else if (child_die
->tag
== DW_TAG_subprogram
)
7462 /* C++ member function. */
7463 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7465 else if (child_die
->tag
== DW_TAG_inheritance
)
7467 /* C++ base class field. */
7468 dwarf2_add_field (&fi
, child_die
, cu
);
7470 else if (child_die
->tag
== DW_TAG_typedef
)
7471 dwarf2_add_typedef (&fi
, child_die
, cu
);
7472 else if (child_die
->tag
== DW_TAG_template_type_param
7473 || child_die
->tag
== DW_TAG_template_value_param
)
7475 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7478 VEC_safe_push (symbolp
, template_args
, arg
);
7481 child_die
= sibling_die (child_die
);
7484 /* Attach template arguments to type. */
7485 if (! VEC_empty (symbolp
, template_args
))
7487 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7488 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7489 = VEC_length (symbolp
, template_args
);
7490 TYPE_TEMPLATE_ARGUMENTS (type
)
7491 = obstack_alloc (&objfile
->objfile_obstack
,
7492 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7493 * sizeof (struct symbol
*)));
7494 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7495 VEC_address (symbolp
, template_args
),
7496 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7497 * sizeof (struct symbol
*)));
7498 VEC_free (symbolp
, template_args
);
7501 /* Attach fields and member functions to the type. */
7503 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7506 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7508 /* Get the type which refers to the base class (possibly this
7509 class itself) which contains the vtable pointer for the current
7510 class from the DW_AT_containing_type attribute. This use of
7511 DW_AT_containing_type is a GNU extension. */
7513 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7515 struct type
*t
= die_containing_type (die
, cu
);
7517 TYPE_VPTR_BASETYPE (type
) = t
;
7522 /* Our own class provides vtbl ptr. */
7523 for (i
= TYPE_NFIELDS (t
) - 1;
7524 i
>= TYPE_N_BASECLASSES (t
);
7527 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7529 if (is_vtable_name (fieldname
, cu
))
7531 TYPE_VPTR_FIELDNO (type
) = i
;
7536 /* Complain if virtual function table field not found. */
7537 if (i
< TYPE_N_BASECLASSES (t
))
7538 complaint (&symfile_complaints
,
7539 _("virtual function table pointer "
7540 "not found when defining class '%s'"),
7541 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7546 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7549 else if (cu
->producer
7550 && strncmp (cu
->producer
,
7551 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7553 /* The IBM XLC compiler does not provide direct indication
7554 of the containing type, but the vtable pointer is
7555 always named __vfp. */
7559 for (i
= TYPE_NFIELDS (type
) - 1;
7560 i
>= TYPE_N_BASECLASSES (type
);
7563 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7565 TYPE_VPTR_FIELDNO (type
) = i
;
7566 TYPE_VPTR_BASETYPE (type
) = type
;
7573 /* Copy fi.typedef_field_list linked list elements content into the
7574 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7575 if (fi
.typedef_field_list
)
7577 int i
= fi
.typedef_field_list_count
;
7579 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7580 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7581 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7582 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7584 /* Reverse the list order to keep the debug info elements order. */
7587 struct typedef_field
*dest
, *src
;
7589 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7590 src
= &fi
.typedef_field_list
->field
;
7591 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7596 do_cleanups (back_to
);
7598 if (HAVE_CPLUS_STRUCT (type
))
7599 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
7602 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
7604 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7605 snapshots) has been known to create a die giving a declaration
7606 for a class that has, as a child, a die giving a definition for a
7607 nested class. So we have to process our children even if the
7608 current die is a declaration. Normally, of course, a declaration
7609 won't have any children at all. */
7611 while (child_die
!= NULL
&& child_die
->tag
)
7613 if (child_die
->tag
== DW_TAG_member
7614 || child_die
->tag
== DW_TAG_variable
7615 || child_die
->tag
== DW_TAG_inheritance
7616 || child_die
->tag
== DW_TAG_template_value_param
7617 || child_die
->tag
== DW_TAG_template_type_param
)
7622 process_die (child_die
, cu
);
7624 child_die
= sibling_die (child_die
);
7627 /* Do not consider external references. According to the DWARF standard,
7628 these DIEs are identified by the fact that they have no byte_size
7629 attribute, and a declaration attribute. */
7630 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7631 || !die_is_declaration (die
, cu
))
7632 new_symbol (die
, type
, cu
);
7635 /* Given a DW_AT_enumeration_type die, set its type. We do not
7636 complete the type's fields yet, or create any symbols. */
7638 static struct type
*
7639 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7641 struct objfile
*objfile
= cu
->objfile
;
7643 struct attribute
*attr
;
7646 /* If the definition of this type lives in .debug_types, read that type.
7647 Don't follow DW_AT_specification though, that will take us back up
7648 the chain and we want to go down. */
7649 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7652 struct dwarf2_cu
*type_cu
= cu
;
7653 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7655 type
= read_type_die (type_die
, type_cu
);
7657 /* TYPE_CU may not be the same as CU.
7658 Ensure TYPE is recorded in CU's type_hash table. */
7659 return set_die_type (die
, type
, cu
);
7662 type
= alloc_type (objfile
);
7664 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7665 name
= dwarf2_full_name (NULL
, die
, cu
);
7667 TYPE_TAG_NAME (type
) = (char *) name
;
7669 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7672 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7676 TYPE_LENGTH (type
) = 0;
7679 /* The enumeration DIE can be incomplete. In Ada, any type can be
7680 declared as private in the package spec, and then defined only
7681 inside the package body. Such types are known as Taft Amendment
7682 Types. When another package uses such a type, an incomplete DIE
7683 may be generated by the compiler. */
7684 if (die_is_declaration (die
, cu
))
7685 TYPE_STUB (type
) = 1;
7687 return set_die_type (die
, type
, cu
);
7690 /* Given a pointer to a die which begins an enumeration, process all
7691 the dies that define the members of the enumeration, and create the
7692 symbol for the enumeration type.
7694 NOTE: We reverse the order of the element list. */
7697 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7699 struct type
*this_type
;
7701 this_type
= get_die_type (die
, cu
);
7702 if (this_type
== NULL
)
7703 this_type
= read_enumeration_type (die
, cu
);
7705 if (die
->child
!= NULL
)
7707 struct die_info
*child_die
;
7709 struct field
*fields
= NULL
;
7711 int unsigned_enum
= 1;
7714 child_die
= die
->child
;
7715 while (child_die
&& child_die
->tag
)
7717 if (child_die
->tag
!= DW_TAG_enumerator
)
7719 process_die (child_die
, cu
);
7723 name
= dwarf2_name (child_die
, cu
);
7726 sym
= new_symbol (child_die
, this_type
, cu
);
7727 if (SYMBOL_VALUE (sym
) < 0)
7730 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7732 fields
= (struct field
*)
7734 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7735 * sizeof (struct field
));
7738 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7739 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7740 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7741 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7747 child_die
= sibling_die (child_die
);
7752 TYPE_NFIELDS (this_type
) = num_fields
;
7753 TYPE_FIELDS (this_type
) = (struct field
*)
7754 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7755 memcpy (TYPE_FIELDS (this_type
), fields
,
7756 sizeof (struct field
) * num_fields
);
7760 TYPE_UNSIGNED (this_type
) = 1;
7763 /* If we are reading an enum from a .debug_types unit, and the enum
7764 is a declaration, and the enum is not the signatured type in the
7765 unit, then we do not want to add a symbol for it. Adding a
7766 symbol would in some cases obscure the true definition of the
7767 enum, giving users an incomplete type when the definition is
7768 actually available. Note that we do not want to do this for all
7769 enums which are just declarations, because C++0x allows forward
7770 enum declarations. */
7771 if (cu
->per_cu
->debug_type_section
7772 && die_is_declaration (die
, cu
))
7774 struct signatured_type
*type_sig
;
7777 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
7778 cu
->per_cu
->debug_type_section
,
7779 cu
->per_cu
->offset
);
7780 if (type_sig
->type_offset
!= die
->offset
)
7784 new_symbol (die
, this_type
, cu
);
7787 /* Extract all information from a DW_TAG_array_type DIE and put it in
7788 the DIE's type field. For now, this only handles one dimensional
7791 static struct type
*
7792 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7794 struct objfile
*objfile
= cu
->objfile
;
7795 struct die_info
*child_die
;
7797 struct type
*element_type
, *range_type
, *index_type
;
7798 struct type
**range_types
= NULL
;
7799 struct attribute
*attr
;
7801 struct cleanup
*back_to
;
7804 element_type
= die_type (die
, cu
);
7806 /* The die_type call above may have already set the type for this DIE. */
7807 type
= get_die_type (die
, cu
);
7811 /* Irix 6.2 native cc creates array types without children for
7812 arrays with unspecified length. */
7813 if (die
->child
== NULL
)
7815 index_type
= objfile_type (objfile
)->builtin_int
;
7816 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7817 type
= create_array_type (NULL
, element_type
, range_type
);
7818 return set_die_type (die
, type
, cu
);
7821 back_to
= make_cleanup (null_cleanup
, NULL
);
7822 child_die
= die
->child
;
7823 while (child_die
&& child_die
->tag
)
7825 if (child_die
->tag
== DW_TAG_subrange_type
)
7827 struct type
*child_type
= read_type_die (child_die
, cu
);
7829 if (child_type
!= NULL
)
7831 /* The range type was succesfully read. Save it for the
7832 array type creation. */
7833 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7835 range_types
= (struct type
**)
7836 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7837 * sizeof (struct type
*));
7839 make_cleanup (free_current_contents
, &range_types
);
7841 range_types
[ndim
++] = child_type
;
7844 child_die
= sibling_die (child_die
);
7847 /* Dwarf2 dimensions are output from left to right, create the
7848 necessary array types in backwards order. */
7850 type
= element_type
;
7852 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7857 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7862 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7865 /* Understand Dwarf2 support for vector types (like they occur on
7866 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7867 array type. This is not part of the Dwarf2/3 standard yet, but a
7868 custom vendor extension. The main difference between a regular
7869 array and the vector variant is that vectors are passed by value
7871 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7873 make_vector_type (type
);
7875 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7876 implementation may choose to implement triple vectors using this
7878 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7881 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
7882 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7884 complaint (&symfile_complaints
,
7885 _("DW_AT_byte_size for array type smaller "
7886 "than the total size of elements"));
7889 name
= dwarf2_name (die
, cu
);
7891 TYPE_NAME (type
) = name
;
7893 /* Install the type in the die. */
7894 set_die_type (die
, type
, cu
);
7896 /* set_die_type should be already done. */
7897 set_descriptive_type (type
, die
, cu
);
7899 do_cleanups (back_to
);
7904 static enum dwarf_array_dim_ordering
7905 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7907 struct attribute
*attr
;
7909 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7911 if (attr
) return DW_SND (attr
);
7913 /* GNU F77 is a special case, as at 08/2004 array type info is the
7914 opposite order to the dwarf2 specification, but data is still
7915 laid out as per normal fortran.
7917 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7918 version checking. */
7920 if (cu
->language
== language_fortran
7921 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7923 return DW_ORD_row_major
;
7926 switch (cu
->language_defn
->la_array_ordering
)
7928 case array_column_major
:
7929 return DW_ORD_col_major
;
7930 case array_row_major
:
7932 return DW_ORD_row_major
;
7936 /* Extract all information from a DW_TAG_set_type DIE and put it in
7937 the DIE's type field. */
7939 static struct type
*
7940 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7942 struct type
*domain_type
, *set_type
;
7943 struct attribute
*attr
;
7945 domain_type
= die_type (die
, cu
);
7947 /* The die_type call above may have already set the type for this DIE. */
7948 set_type
= get_die_type (die
, cu
);
7952 set_type
= create_set_type (NULL
, domain_type
);
7954 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7956 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7958 return set_die_type (die
, set_type
, cu
);
7961 /* First cut: install each common block member as a global variable. */
7964 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7966 struct die_info
*child_die
;
7967 struct attribute
*attr
;
7969 CORE_ADDR base
= (CORE_ADDR
) 0;
7971 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7974 /* Support the .debug_loc offsets. */
7975 if (attr_form_is_block (attr
))
7977 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7979 else if (attr_form_is_section_offset (attr
))
7981 dwarf2_complex_location_expr_complaint ();
7985 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7986 "common block member");
7989 if (die
->child
!= NULL
)
7991 child_die
= die
->child
;
7992 while (child_die
&& child_die
->tag
)
7996 sym
= new_symbol (child_die
, NULL
, cu
);
7998 && handle_data_member_location (child_die
, cu
, &offset
))
8000 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
8001 add_symbol_to_list (sym
, &global_symbols
);
8003 child_die
= sibling_die (child_die
);
8008 /* Create a type for a C++ namespace. */
8010 static struct type
*
8011 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8013 struct objfile
*objfile
= cu
->objfile
;
8014 const char *previous_prefix
, *name
;
8018 /* For extensions, reuse the type of the original namespace. */
8019 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
8021 struct die_info
*ext_die
;
8022 struct dwarf2_cu
*ext_cu
= cu
;
8024 ext_die
= dwarf2_extension (die
, &ext_cu
);
8025 type
= read_type_die (ext_die
, ext_cu
);
8027 /* EXT_CU may not be the same as CU.
8028 Ensure TYPE is recorded in CU's type_hash table. */
8029 return set_die_type (die
, type
, cu
);
8032 name
= namespace_name (die
, &is_anonymous
, cu
);
8034 /* Now build the name of the current namespace. */
8036 previous_prefix
= determine_prefix (die
, cu
);
8037 if (previous_prefix
[0] != '\0')
8038 name
= typename_concat (&objfile
->objfile_obstack
,
8039 previous_prefix
, name
, 0, cu
);
8041 /* Create the type. */
8042 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8044 TYPE_NAME (type
) = (char *) name
;
8045 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8047 return set_die_type (die
, type
, cu
);
8050 /* Read a C++ namespace. */
8053 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8055 struct objfile
*objfile
= cu
->objfile
;
8058 /* Add a symbol associated to this if we haven't seen the namespace
8059 before. Also, add a using directive if it's an anonymous
8062 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8066 type
= read_type_die (die
, cu
);
8067 new_symbol (die
, type
, cu
);
8069 namespace_name (die
, &is_anonymous
, cu
);
8072 const char *previous_prefix
= determine_prefix (die
, cu
);
8074 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8075 NULL
, NULL
, &objfile
->objfile_obstack
);
8079 if (die
->child
!= NULL
)
8081 struct die_info
*child_die
= die
->child
;
8083 while (child_die
&& child_die
->tag
)
8085 process_die (child_die
, cu
);
8086 child_die
= sibling_die (child_die
);
8091 /* Read a Fortran module as type. This DIE can be only a declaration used for
8092 imported module. Still we need that type as local Fortran "use ... only"
8093 declaration imports depend on the created type in determine_prefix. */
8095 static struct type
*
8096 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8098 struct objfile
*objfile
= cu
->objfile
;
8102 module_name
= dwarf2_name (die
, cu
);
8104 complaint (&symfile_complaints
,
8105 _("DW_TAG_module has no name, offset 0x%x"),
8107 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8109 /* determine_prefix uses TYPE_TAG_NAME. */
8110 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8112 return set_die_type (die
, type
, cu
);
8115 /* Read a Fortran module. */
8118 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8120 struct die_info
*child_die
= die
->child
;
8122 while (child_die
&& child_die
->tag
)
8124 process_die (child_die
, cu
);
8125 child_die
= sibling_die (child_die
);
8129 /* Return the name of the namespace represented by DIE. Set
8130 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8134 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8136 struct die_info
*current_die
;
8137 const char *name
= NULL
;
8139 /* Loop through the extensions until we find a name. */
8141 for (current_die
= die
;
8142 current_die
!= NULL
;
8143 current_die
= dwarf2_extension (die
, &cu
))
8145 name
= dwarf2_name (current_die
, cu
);
8150 /* Is it an anonymous namespace? */
8152 *is_anonymous
= (name
== NULL
);
8154 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8159 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8160 the user defined type vector. */
8162 static struct type
*
8163 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8165 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8166 struct comp_unit_head
*cu_header
= &cu
->header
;
8168 struct attribute
*attr_byte_size
;
8169 struct attribute
*attr_address_class
;
8170 int byte_size
, addr_class
;
8171 struct type
*target_type
;
8173 target_type
= die_type (die
, cu
);
8175 /* The die_type call above may have already set the type for this DIE. */
8176 type
= get_die_type (die
, cu
);
8180 type
= lookup_pointer_type (target_type
);
8182 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8184 byte_size
= DW_UNSND (attr_byte_size
);
8186 byte_size
= cu_header
->addr_size
;
8188 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8189 if (attr_address_class
)
8190 addr_class
= DW_UNSND (attr_address_class
);
8192 addr_class
= DW_ADDR_none
;
8194 /* If the pointer size or address class is different than the
8195 default, create a type variant marked as such and set the
8196 length accordingly. */
8197 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8199 if (gdbarch_address_class_type_flags_p (gdbarch
))
8203 type_flags
= gdbarch_address_class_type_flags
8204 (gdbarch
, byte_size
, addr_class
);
8205 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8207 type
= make_type_with_address_space (type
, type_flags
);
8209 else if (TYPE_LENGTH (type
) != byte_size
)
8211 complaint (&symfile_complaints
,
8212 _("invalid pointer size %d"), byte_size
);
8216 /* Should we also complain about unhandled address classes? */
8220 TYPE_LENGTH (type
) = byte_size
;
8221 return set_die_type (die
, type
, cu
);
8224 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8225 the user defined type vector. */
8227 static struct type
*
8228 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8231 struct type
*to_type
;
8232 struct type
*domain
;
8234 to_type
= die_type (die
, cu
);
8235 domain
= die_containing_type (die
, cu
);
8237 /* The calls above may have already set the type for this DIE. */
8238 type
= get_die_type (die
, cu
);
8242 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8243 type
= lookup_methodptr_type (to_type
);
8245 type
= lookup_memberptr_type (to_type
, domain
);
8247 return set_die_type (die
, type
, cu
);
8250 /* Extract all information from a DW_TAG_reference_type DIE and add to
8251 the user defined type vector. */
8253 static struct type
*
8254 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8256 struct comp_unit_head
*cu_header
= &cu
->header
;
8257 struct type
*type
, *target_type
;
8258 struct attribute
*attr
;
8260 target_type
= die_type (die
, cu
);
8262 /* The die_type call above may have already set the type for this DIE. */
8263 type
= get_die_type (die
, cu
);
8267 type
= lookup_reference_type (target_type
);
8268 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8271 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8275 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8277 return set_die_type (die
, type
, cu
);
8280 static struct type
*
8281 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8283 struct type
*base_type
, *cv_type
;
8285 base_type
= die_type (die
, cu
);
8287 /* The die_type call above may have already set the type for this DIE. */
8288 cv_type
= get_die_type (die
, cu
);
8292 /* In case the const qualifier is applied to an array type, the element type
8293 is so qualified, not the array type (section 6.7.3 of C99). */
8294 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8296 struct type
*el_type
, *inner_array
;
8298 base_type
= copy_type (base_type
);
8299 inner_array
= base_type
;
8301 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8303 TYPE_TARGET_TYPE (inner_array
) =
8304 copy_type (TYPE_TARGET_TYPE (inner_array
));
8305 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8308 el_type
= TYPE_TARGET_TYPE (inner_array
);
8309 TYPE_TARGET_TYPE (inner_array
) =
8310 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8312 return set_die_type (die
, base_type
, cu
);
8315 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8316 return set_die_type (die
, cv_type
, cu
);
8319 static struct type
*
8320 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8322 struct type
*base_type
, *cv_type
;
8324 base_type
= die_type (die
, cu
);
8326 /* The die_type call above may have already set the type for this DIE. */
8327 cv_type
= get_die_type (die
, cu
);
8331 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8332 return set_die_type (die
, cv_type
, cu
);
8335 /* Extract all information from a DW_TAG_string_type DIE and add to
8336 the user defined type vector. It isn't really a user defined type,
8337 but it behaves like one, with other DIE's using an AT_user_def_type
8338 attribute to reference it. */
8340 static struct type
*
8341 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8343 struct objfile
*objfile
= cu
->objfile
;
8344 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8345 struct type
*type
, *range_type
, *index_type
, *char_type
;
8346 struct attribute
*attr
;
8347 unsigned int length
;
8349 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8352 length
= DW_UNSND (attr
);
8356 /* Check for the DW_AT_byte_size attribute. */
8357 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8360 length
= DW_UNSND (attr
);
8368 index_type
= objfile_type (objfile
)->builtin_int
;
8369 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8370 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8371 type
= create_string_type (NULL
, char_type
, range_type
);
8373 return set_die_type (die
, type
, cu
);
8376 /* Handle DIES due to C code like:
8380 int (*funcp)(int a, long l);
8384 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8386 static struct type
*
8387 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8389 struct type
*type
; /* Type that this function returns. */
8390 struct type
*ftype
; /* Function that returns above type. */
8391 struct attribute
*attr
;
8393 type
= die_type (die
, cu
);
8395 /* The die_type call above may have already set the type for this DIE. */
8396 ftype
= get_die_type (die
, cu
);
8400 ftype
= lookup_function_type (type
);
8402 /* All functions in C++, Pascal and Java have prototypes. */
8403 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8404 if ((attr
&& (DW_UNSND (attr
) != 0))
8405 || cu
->language
== language_cplus
8406 || cu
->language
== language_java
8407 || cu
->language
== language_pascal
)
8408 TYPE_PROTOTYPED (ftype
) = 1;
8409 else if (producer_is_realview (cu
->producer
))
8410 /* RealView does not emit DW_AT_prototyped. We can not
8411 distinguish prototyped and unprototyped functions; default to
8412 prototyped, since that is more common in modern code (and
8413 RealView warns about unprototyped functions). */
8414 TYPE_PROTOTYPED (ftype
) = 1;
8416 /* Store the calling convention in the type if it's available in
8417 the subroutine die. Otherwise set the calling convention to
8418 the default value DW_CC_normal. */
8419 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8421 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8422 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8423 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8425 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8427 /* We need to add the subroutine type to the die immediately so
8428 we don't infinitely recurse when dealing with parameters
8429 declared as the same subroutine type. */
8430 set_die_type (die
, ftype
, cu
);
8432 if (die
->child
!= NULL
)
8434 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
8435 struct die_info
*child_die
;
8436 int nparams
, iparams
;
8438 /* Count the number of parameters.
8439 FIXME: GDB currently ignores vararg functions, but knows about
8440 vararg member functions. */
8442 child_die
= die
->child
;
8443 while (child_die
&& child_die
->tag
)
8445 if (child_die
->tag
== DW_TAG_formal_parameter
)
8447 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8448 TYPE_VARARGS (ftype
) = 1;
8449 child_die
= sibling_die (child_die
);
8452 /* Allocate storage for parameters and fill them in. */
8453 TYPE_NFIELDS (ftype
) = nparams
;
8454 TYPE_FIELDS (ftype
) = (struct field
*)
8455 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8457 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8458 even if we error out during the parameters reading below. */
8459 for (iparams
= 0; iparams
< nparams
; iparams
++)
8460 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8463 child_die
= die
->child
;
8464 while (child_die
&& child_die
->tag
)
8466 if (child_die
->tag
== DW_TAG_formal_parameter
)
8468 struct type
*arg_type
;
8470 /* DWARF version 2 has no clean way to discern C++
8471 static and non-static member functions. G++ helps
8472 GDB by marking the first parameter for non-static
8473 member functions (which is the this pointer) as
8474 artificial. We pass this information to
8475 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8477 DWARF version 3 added DW_AT_object_pointer, which GCC
8478 4.5 does not yet generate. */
8479 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8481 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8484 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8486 /* GCC/43521: In java, the formal parameter
8487 "this" is sometimes not marked with DW_AT_artificial. */
8488 if (cu
->language
== language_java
)
8490 const char *name
= dwarf2_name (child_die
, cu
);
8492 if (name
&& !strcmp (name
, "this"))
8493 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8496 arg_type
= die_type (child_die
, cu
);
8498 /* RealView does not mark THIS as const, which the testsuite
8499 expects. GCC marks THIS as const in method definitions,
8500 but not in the class specifications (GCC PR 43053). */
8501 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8502 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8505 struct dwarf2_cu
*arg_cu
= cu
;
8506 const char *name
= dwarf2_name (child_die
, cu
);
8508 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8511 /* If the compiler emits this, use it. */
8512 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8515 else if (name
&& strcmp (name
, "this") == 0)
8516 /* Function definitions will have the argument names. */
8518 else if (name
== NULL
&& iparams
== 0)
8519 /* Declarations may not have the names, so like
8520 elsewhere in GDB, assume an artificial first
8521 argument is "this". */
8525 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8529 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8532 child_die
= sibling_die (child_die
);
8539 static struct type
*
8540 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8542 struct objfile
*objfile
= cu
->objfile
;
8543 const char *name
= NULL
;
8544 struct type
*this_type
;
8546 name
= dwarf2_full_name (NULL
, die
, cu
);
8547 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8548 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8549 TYPE_NAME (this_type
) = (char *) name
;
8550 set_die_type (die
, this_type
, cu
);
8551 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
8555 /* Find a representation of a given base type and install
8556 it in the TYPE field of the die. */
8558 static struct type
*
8559 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8561 struct objfile
*objfile
= cu
->objfile
;
8563 struct attribute
*attr
;
8564 int encoding
= 0, size
= 0;
8566 enum type_code code
= TYPE_CODE_INT
;
8568 struct type
*target_type
= NULL
;
8570 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8573 encoding
= DW_UNSND (attr
);
8575 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8578 size
= DW_UNSND (attr
);
8580 name
= dwarf2_name (die
, cu
);
8583 complaint (&symfile_complaints
,
8584 _("DW_AT_name missing from DW_TAG_base_type"));
8589 case DW_ATE_address
:
8590 /* Turn DW_ATE_address into a void * pointer. */
8591 code
= TYPE_CODE_PTR
;
8592 type_flags
|= TYPE_FLAG_UNSIGNED
;
8593 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8595 case DW_ATE_boolean
:
8596 code
= TYPE_CODE_BOOL
;
8597 type_flags
|= TYPE_FLAG_UNSIGNED
;
8599 case DW_ATE_complex_float
:
8600 code
= TYPE_CODE_COMPLEX
;
8601 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8603 case DW_ATE_decimal_float
:
8604 code
= TYPE_CODE_DECFLOAT
;
8607 code
= TYPE_CODE_FLT
;
8611 case DW_ATE_unsigned
:
8612 type_flags
|= TYPE_FLAG_UNSIGNED
;
8613 if (cu
->language
== language_fortran
8615 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
8616 code
= TYPE_CODE_CHAR
;
8618 case DW_ATE_signed_char
:
8619 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8620 || cu
->language
== language_pascal
8621 || cu
->language
== language_fortran
)
8622 code
= TYPE_CODE_CHAR
;
8624 case DW_ATE_unsigned_char
:
8625 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8626 || cu
->language
== language_pascal
8627 || cu
->language
== language_fortran
)
8628 code
= TYPE_CODE_CHAR
;
8629 type_flags
|= TYPE_FLAG_UNSIGNED
;
8632 /* We just treat this as an integer and then recognize the
8633 type by name elsewhere. */
8637 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8638 dwarf_type_encoding_name (encoding
));
8642 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8643 TYPE_NAME (type
) = name
;
8644 TYPE_TARGET_TYPE (type
) = target_type
;
8646 if (name
&& strcmp (name
, "char") == 0)
8647 TYPE_NOSIGN (type
) = 1;
8649 return set_die_type (die
, type
, cu
);
8652 /* Read the given DW_AT_subrange DIE. */
8654 static struct type
*
8655 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8657 struct type
*base_type
;
8658 struct type
*range_type
;
8659 struct attribute
*attr
;
8663 LONGEST negative_mask
;
8665 base_type
= die_type (die
, cu
);
8666 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8667 check_typedef (base_type
);
8669 /* The die_type call above may have already set the type for this DIE. */
8670 range_type
= get_die_type (die
, cu
);
8674 if (cu
->language
== language_fortran
)
8676 /* FORTRAN implies a lower bound of 1, if not given. */
8680 /* FIXME: For variable sized arrays either of these could be
8681 a variable rather than a constant value. We'll allow it,
8682 but we don't know how to handle it. */
8683 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8685 low
= dwarf2_get_attr_constant_value (attr
, 0);
8687 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8690 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
8692 /* GCC encodes arrays with unspecified or dynamic length
8693 with a DW_FORM_block1 attribute or a reference attribute.
8694 FIXME: GDB does not yet know how to handle dynamic
8695 arrays properly, treat them as arrays with unspecified
8698 FIXME: jimb/2003-09-22: GDB does not really know
8699 how to handle arrays of unspecified length
8700 either; we just represent them as zero-length
8701 arrays. Choose an appropriate upper bound given
8702 the lower bound we've computed above. */
8706 high
= dwarf2_get_attr_constant_value (attr
, 1);
8710 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8713 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8714 high
= low
+ count
- 1;
8718 /* Unspecified array length. */
8723 /* Dwarf-2 specifications explicitly allows to create subrange types
8724 without specifying a base type.
8725 In that case, the base type must be set to the type of
8726 the lower bound, upper bound or count, in that order, if any of these
8727 three attributes references an object that has a type.
8728 If no base type is found, the Dwarf-2 specifications say that
8729 a signed integer type of size equal to the size of an address should
8731 For the following C code: `extern char gdb_int [];'
8732 GCC produces an empty range DIE.
8733 FIXME: muller/2010-05-28: Possible references to object for low bound,
8734 high bound or count are not yet handled by this code. */
8735 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8737 struct objfile
*objfile
= cu
->objfile
;
8738 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8739 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8740 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8742 /* Test "int", "long int", and "long long int" objfile types,
8743 and select the first one having a size above or equal to the
8744 architecture address size. */
8745 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8746 base_type
= int_type
;
8749 int_type
= objfile_type (objfile
)->builtin_long
;
8750 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8751 base_type
= int_type
;
8754 int_type
= objfile_type (objfile
)->builtin_long_long
;
8755 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8756 base_type
= int_type
;
8762 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8763 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8764 low
|= negative_mask
;
8765 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8766 high
|= negative_mask
;
8768 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8770 /* Mark arrays with dynamic length at least as an array of unspecified
8771 length. GDB could check the boundary but before it gets implemented at
8772 least allow accessing the array elements. */
8773 if (attr
&& attr_form_is_block (attr
))
8774 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8776 /* Ada expects an empty array on no boundary attributes. */
8777 if (attr
== NULL
&& cu
->language
!= language_ada
)
8778 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8780 name
= dwarf2_name (die
, cu
);
8782 TYPE_NAME (range_type
) = name
;
8784 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8786 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8788 set_die_type (die
, range_type
, cu
);
8790 /* set_die_type should be already done. */
8791 set_descriptive_type (range_type
, die
, cu
);
8796 static struct type
*
8797 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8801 /* For now, we only support the C meaning of an unspecified type: void. */
8803 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8804 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8806 return set_die_type (die
, type
, cu
);
8809 /* Trivial hash function for die_info: the hash value of a DIE
8810 is its offset in .debug_info for this objfile. */
8813 die_hash (const void *item
)
8815 const struct die_info
*die
= item
;
8820 /* Trivial comparison function for die_info structures: two DIEs
8821 are equal if they have the same offset. */
8824 die_eq (const void *item_lhs
, const void *item_rhs
)
8826 const struct die_info
*die_lhs
= item_lhs
;
8827 const struct die_info
*die_rhs
= item_rhs
;
8829 return die_lhs
->offset
== die_rhs
->offset
;
8832 /* Read a whole compilation unit into a linked list of dies. */
8834 static struct die_info
*
8835 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8837 struct die_reader_specs reader_specs
;
8838 int read_abbrevs
= 0;
8839 struct cleanup
*back_to
= NULL
;
8840 struct die_info
*die
;
8842 if (cu
->dwarf2_abbrevs
== NULL
)
8844 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8845 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8849 gdb_assert (cu
->die_hash
== NULL
);
8851 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8855 &cu
->comp_unit_obstack
,
8856 hashtab_obstack_allocate
,
8857 dummy_obstack_deallocate
);
8859 init_cu_die_reader (&reader_specs
, cu
);
8861 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8864 do_cleanups (back_to
);
8869 /* Main entry point for reading a DIE and all children.
8870 Read the DIE and dump it if requested. */
8872 static struct die_info
*
8873 read_die_and_children (const struct die_reader_specs
*reader
,
8875 gdb_byte
**new_info_ptr
,
8876 struct die_info
*parent
)
8878 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8879 new_info_ptr
, parent
);
8881 if (dwarf2_die_debug
)
8883 fprintf_unfiltered (gdb_stdlog
,
8884 "\nRead die from %s of %s:\n",
8885 (reader
->cu
->per_cu
->debug_type_section
8888 reader
->abfd
->filename
);
8889 dump_die (result
, dwarf2_die_debug
);
8895 /* Read a single die and all its descendents. Set the die's sibling
8896 field to NULL; set other fields in the die correctly, and set all
8897 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8898 location of the info_ptr after reading all of those dies. PARENT
8899 is the parent of the die in question. */
8901 static struct die_info
*
8902 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8904 gdb_byte
**new_info_ptr
,
8905 struct die_info
*parent
)
8907 struct die_info
*die
;
8911 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8914 *new_info_ptr
= cur_ptr
;
8917 store_in_ref_table (die
, reader
->cu
);
8920 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8924 *new_info_ptr
= cur_ptr
;
8927 die
->sibling
= NULL
;
8928 die
->parent
= parent
;
8932 /* Read a die, all of its descendents, and all of its siblings; set
8933 all of the fields of all of the dies correctly. Arguments are as
8934 in read_die_and_children. */
8936 static struct die_info
*
8937 read_die_and_siblings (const struct die_reader_specs
*reader
,
8939 gdb_byte
**new_info_ptr
,
8940 struct die_info
*parent
)
8942 struct die_info
*first_die
, *last_sibling
;
8946 first_die
= last_sibling
= NULL
;
8950 struct die_info
*die
8951 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8955 *new_info_ptr
= cur_ptr
;
8962 last_sibling
->sibling
= die
;
8968 /* Read the die from the .debug_info section buffer. Set DIEP to
8969 point to a newly allocated die with its information, except for its
8970 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8971 whether the die has children or not. */
8974 read_full_die (const struct die_reader_specs
*reader
,
8975 struct die_info
**diep
, gdb_byte
*info_ptr
,
8978 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8979 struct abbrev_info
*abbrev
;
8980 struct die_info
*die
;
8981 struct dwarf2_cu
*cu
= reader
->cu
;
8982 bfd
*abfd
= reader
->abfd
;
8984 offset
= info_ptr
- reader
->buffer
;
8985 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8986 info_ptr
+= bytes_read
;
8994 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8996 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8998 bfd_get_filename (abfd
));
9000 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
9001 die
->offset
= offset
;
9002 die
->tag
= abbrev
->tag
;
9003 die
->abbrev
= abbrev_number
;
9005 die
->num_attrs
= abbrev
->num_attrs
;
9007 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9008 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
9009 abfd
, info_ptr
, cu
);
9012 *has_children
= abbrev
->has_children
;
9016 /* In DWARF version 2, the description of the debugging information is
9017 stored in a separate .debug_abbrev section. Before we read any
9018 dies from a section we read in all abbreviations and install them
9019 in a hash table. This function also sets flags in CU describing
9020 the data found in the abbrev table. */
9023 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
9025 struct comp_unit_head
*cu_header
= &cu
->header
;
9026 gdb_byte
*abbrev_ptr
;
9027 struct abbrev_info
*cur_abbrev
;
9028 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9029 unsigned int abbrev_form
, hash_number
;
9030 struct attr_abbrev
*cur_attrs
;
9031 unsigned int allocated_attrs
;
9033 /* Initialize dwarf2 abbrevs. */
9034 obstack_init (&cu
->abbrev_obstack
);
9035 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9037 * sizeof (struct abbrev_info
*)));
9038 memset (cu
->dwarf2_abbrevs
, 0,
9039 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9041 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
9042 &dwarf2_per_objfile
->abbrev
);
9043 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
9044 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9045 abbrev_ptr
+= bytes_read
;
9047 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9048 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9050 /* Loop until we reach an abbrev number of 0. */
9051 while (abbrev_number
)
9053 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9055 /* read in abbrev header */
9056 cur_abbrev
->number
= abbrev_number
;
9057 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9058 abbrev_ptr
+= bytes_read
;
9059 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9062 if (cur_abbrev
->tag
== DW_TAG_namespace
)
9063 cu
->has_namespace_info
= 1;
9065 /* now read in declarations */
9066 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9067 abbrev_ptr
+= bytes_read
;
9068 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9069 abbrev_ptr
+= bytes_read
;
9072 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9074 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9076 = xrealloc (cur_attrs
, (allocated_attrs
9077 * sizeof (struct attr_abbrev
)));
9080 /* Record whether this compilation unit might have
9081 inter-compilation-unit references. If we don't know what form
9082 this attribute will have, then it might potentially be a
9083 DW_FORM_ref_addr, so we conservatively expect inter-CU
9086 if (abbrev_form
== DW_FORM_ref_addr
9087 || abbrev_form
== DW_FORM_indirect
)
9088 cu
->has_form_ref_addr
= 1;
9090 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9091 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9092 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9093 abbrev_ptr
+= bytes_read
;
9094 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9095 abbrev_ptr
+= bytes_read
;
9098 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9099 (cur_abbrev
->num_attrs
9100 * sizeof (struct attr_abbrev
)));
9101 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9102 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9104 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9105 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9106 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9108 /* Get next abbreviation.
9109 Under Irix6 the abbreviations for a compilation unit are not
9110 always properly terminated with an abbrev number of 0.
9111 Exit loop if we encounter an abbreviation which we have
9112 already read (which means we are about to read the abbreviations
9113 for the next compile unit) or if the end of the abbreviation
9114 table is reached. */
9115 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
9116 >= dwarf2_per_objfile
->abbrev
.size
)
9118 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9119 abbrev_ptr
+= bytes_read
;
9120 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9127 /* Release the memory used by the abbrev table for a compilation unit. */
9130 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9132 struct dwarf2_cu
*cu
= ptr_to_cu
;
9134 obstack_free (&cu
->abbrev_obstack
, NULL
);
9135 cu
->dwarf2_abbrevs
= NULL
;
9138 /* Lookup an abbrev_info structure in the abbrev hash table. */
9140 static struct abbrev_info
*
9141 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9143 unsigned int hash_number
;
9144 struct abbrev_info
*abbrev
;
9146 hash_number
= number
% ABBREV_HASH_SIZE
;
9147 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9151 if (abbrev
->number
== number
)
9154 abbrev
= abbrev
->next
;
9159 /* Returns nonzero if TAG represents a type that we might generate a partial
9163 is_type_tag_for_partial (int tag
)
9168 /* Some types that would be reasonable to generate partial symbols for,
9169 that we don't at present. */
9170 case DW_TAG_array_type
:
9171 case DW_TAG_file_type
:
9172 case DW_TAG_ptr_to_member_type
:
9173 case DW_TAG_set_type
:
9174 case DW_TAG_string_type
:
9175 case DW_TAG_subroutine_type
:
9177 case DW_TAG_base_type
:
9178 case DW_TAG_class_type
:
9179 case DW_TAG_interface_type
:
9180 case DW_TAG_enumeration_type
:
9181 case DW_TAG_structure_type
:
9182 case DW_TAG_subrange_type
:
9183 case DW_TAG_typedef
:
9184 case DW_TAG_union_type
:
9191 /* Load all DIEs that are interesting for partial symbols into memory. */
9193 static struct partial_die_info
*
9194 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9195 int building_psymtab
, struct dwarf2_cu
*cu
)
9197 struct partial_die_info
*part_die
;
9198 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9199 struct abbrev_info
*abbrev
;
9200 unsigned int bytes_read
;
9201 unsigned int load_all
= 0;
9203 int nesting_level
= 1;
9208 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
9212 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9216 &cu
->comp_unit_obstack
,
9217 hashtab_obstack_allocate
,
9218 dummy_obstack_deallocate
);
9220 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9221 sizeof (struct partial_die_info
));
9225 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9227 /* A NULL abbrev means the end of a series of children. */
9230 if (--nesting_level
== 0)
9232 /* PART_DIE was probably the last thing allocated on the
9233 comp_unit_obstack, so we could call obstack_free
9234 here. We don't do that because the waste is small,
9235 and will be cleaned up when we're done with this
9236 compilation unit. This way, we're also more robust
9237 against other users of the comp_unit_obstack. */
9240 info_ptr
+= bytes_read
;
9241 last_die
= parent_die
;
9242 parent_die
= parent_die
->die_parent
;
9246 /* Check for template arguments. We never save these; if
9247 they're seen, we just mark the parent, and go on our way. */
9248 if (parent_die
!= NULL
9249 && cu
->language
== language_cplus
9250 && (abbrev
->tag
== DW_TAG_template_type_param
9251 || abbrev
->tag
== DW_TAG_template_value_param
))
9253 parent_die
->has_template_arguments
= 1;
9257 /* We don't need a partial DIE for the template argument. */
9258 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9264 /* We only recurse into subprograms looking for template arguments.
9265 Skip their other children. */
9267 && cu
->language
== language_cplus
9268 && parent_die
!= NULL
9269 && parent_die
->tag
== DW_TAG_subprogram
)
9271 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9275 /* Check whether this DIE is interesting enough to save. Normally
9276 we would not be interested in members here, but there may be
9277 later variables referencing them via DW_AT_specification (for
9280 && !is_type_tag_for_partial (abbrev
->tag
)
9281 && abbrev
->tag
!= DW_TAG_constant
9282 && abbrev
->tag
!= DW_TAG_enumerator
9283 && abbrev
->tag
!= DW_TAG_subprogram
9284 && abbrev
->tag
!= DW_TAG_lexical_block
9285 && abbrev
->tag
!= DW_TAG_variable
9286 && abbrev
->tag
!= DW_TAG_namespace
9287 && abbrev
->tag
!= DW_TAG_module
9288 && abbrev
->tag
!= DW_TAG_member
)
9290 /* Otherwise we skip to the next sibling, if any. */
9291 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9295 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9296 buffer
, info_ptr
, cu
);
9298 /* This two-pass algorithm for processing partial symbols has a
9299 high cost in cache pressure. Thus, handle some simple cases
9300 here which cover the majority of C partial symbols. DIEs
9301 which neither have specification tags in them, nor could have
9302 specification tags elsewhere pointing at them, can simply be
9303 processed and discarded.
9305 This segment is also optional; scan_partial_symbols and
9306 add_partial_symbol will handle these DIEs if we chain
9307 them in normally. When compilers which do not emit large
9308 quantities of duplicate debug information are more common,
9309 this code can probably be removed. */
9311 /* Any complete simple types at the top level (pretty much all
9312 of them, for a language without namespaces), can be processed
9314 if (parent_die
== NULL
9315 && part_die
->has_specification
== 0
9316 && part_die
->is_declaration
== 0
9317 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9318 || part_die
->tag
== DW_TAG_base_type
9319 || part_die
->tag
== DW_TAG_subrange_type
))
9321 if (building_psymtab
&& part_die
->name
!= NULL
)
9322 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9323 VAR_DOMAIN
, LOC_TYPEDEF
,
9324 &cu
->objfile
->static_psymbols
,
9325 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9326 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9330 /* The exception for DW_TAG_typedef with has_children above is
9331 a workaround of GCC PR debug/47510. In the case of this complaint
9332 type_name_no_tag_or_error will error on such types later.
9334 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9335 it could not find the child DIEs referenced later, this is checked
9336 above. In correct DWARF DW_TAG_typedef should have no children. */
9338 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9339 complaint (&symfile_complaints
,
9340 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9341 "- DIE at 0x%x [in module %s]"),
9342 part_die
->offset
, cu
->objfile
->name
);
9344 /* If we're at the second level, and we're an enumerator, and
9345 our parent has no specification (meaning possibly lives in a
9346 namespace elsewhere), then we can add the partial symbol now
9347 instead of queueing it. */
9348 if (part_die
->tag
== DW_TAG_enumerator
9349 && parent_die
!= NULL
9350 && parent_die
->die_parent
== NULL
9351 && parent_die
->tag
== DW_TAG_enumeration_type
9352 && parent_die
->has_specification
== 0)
9354 if (part_die
->name
== NULL
)
9355 complaint (&symfile_complaints
,
9356 _("malformed enumerator DIE ignored"));
9357 else if (building_psymtab
)
9358 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9359 VAR_DOMAIN
, LOC_CONST
,
9360 (cu
->language
== language_cplus
9361 || cu
->language
== language_java
)
9362 ? &cu
->objfile
->global_psymbols
9363 : &cu
->objfile
->static_psymbols
,
9364 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9366 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9370 /* We'll save this DIE so link it in. */
9371 part_die
->die_parent
= parent_die
;
9372 part_die
->die_sibling
= NULL
;
9373 part_die
->die_child
= NULL
;
9375 if (last_die
&& last_die
== parent_die
)
9376 last_die
->die_child
= part_die
;
9378 last_die
->die_sibling
= part_die
;
9380 last_die
= part_die
;
9382 if (first_die
== NULL
)
9383 first_die
= part_die
;
9385 /* Maybe add the DIE to the hash table. Not all DIEs that we
9386 find interesting need to be in the hash table, because we
9387 also have the parent/sibling/child chains; only those that we
9388 might refer to by offset later during partial symbol reading.
9390 For now this means things that might have be the target of a
9391 DW_AT_specification, DW_AT_abstract_origin, or
9392 DW_AT_extension. DW_AT_extension will refer only to
9393 namespaces; DW_AT_abstract_origin refers to functions (and
9394 many things under the function DIE, but we do not recurse
9395 into function DIEs during partial symbol reading) and
9396 possibly variables as well; DW_AT_specification refers to
9397 declarations. Declarations ought to have the DW_AT_declaration
9398 flag. It happens that GCC forgets to put it in sometimes, but
9399 only for functions, not for types.
9401 Adding more things than necessary to the hash table is harmless
9402 except for the performance cost. Adding too few will result in
9403 wasted time in find_partial_die, when we reread the compilation
9404 unit with load_all_dies set. */
9407 || abbrev
->tag
== DW_TAG_constant
9408 || abbrev
->tag
== DW_TAG_subprogram
9409 || abbrev
->tag
== DW_TAG_variable
9410 || abbrev
->tag
== DW_TAG_namespace
9411 || part_die
->is_declaration
)
9415 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9416 part_die
->offset
, INSERT
);
9420 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9421 sizeof (struct partial_die_info
));
9423 /* For some DIEs we want to follow their children (if any). For C
9424 we have no reason to follow the children of structures; for other
9425 languages we have to, so that we can get at method physnames
9426 to infer fully qualified class names, for DW_AT_specification,
9427 and for C++ template arguments. For C++, we also look one level
9428 inside functions to find template arguments (if the name of the
9429 function does not already contain the template arguments).
9431 For Ada, we need to scan the children of subprograms and lexical
9432 blocks as well because Ada allows the definition of nested
9433 entities that could be interesting for the debugger, such as
9434 nested subprograms for instance. */
9435 if (last_die
->has_children
9437 || last_die
->tag
== DW_TAG_namespace
9438 || last_die
->tag
== DW_TAG_module
9439 || last_die
->tag
== DW_TAG_enumeration_type
9440 || (cu
->language
== language_cplus
9441 && last_die
->tag
== DW_TAG_subprogram
9442 && (last_die
->name
== NULL
9443 || strchr (last_die
->name
, '<') == NULL
))
9444 || (cu
->language
!= language_c
9445 && (last_die
->tag
== DW_TAG_class_type
9446 || last_die
->tag
== DW_TAG_interface_type
9447 || last_die
->tag
== DW_TAG_structure_type
9448 || last_die
->tag
== DW_TAG_union_type
))
9449 || (cu
->language
== language_ada
9450 && (last_die
->tag
== DW_TAG_subprogram
9451 || last_die
->tag
== DW_TAG_lexical_block
))))
9454 parent_die
= last_die
;
9458 /* Otherwise we skip to the next sibling, if any. */
9459 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9461 /* Back to the top, do it again. */
9465 /* Read a minimal amount of information into the minimal die structure. */
9468 read_partial_die (struct partial_die_info
*part_die
,
9469 struct abbrev_info
*abbrev
,
9470 unsigned int abbrev_len
, bfd
*abfd
,
9471 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9472 struct dwarf2_cu
*cu
)
9475 struct attribute attr
;
9476 int has_low_pc_attr
= 0;
9477 int has_high_pc_attr
= 0;
9479 memset (part_die
, 0, sizeof (struct partial_die_info
));
9481 part_die
->offset
= info_ptr
- buffer
;
9483 info_ptr
+= abbrev_len
;
9488 part_die
->tag
= abbrev
->tag
;
9489 part_die
->has_children
= abbrev
->has_children
;
9491 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9493 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9495 /* Store the data if it is of an attribute we want to keep in a
9496 partial symbol table. */
9500 switch (part_die
->tag
)
9502 case DW_TAG_compile_unit
:
9503 case DW_TAG_type_unit
:
9504 /* Compilation units have a DW_AT_name that is a filename, not
9505 a source language identifier. */
9506 case DW_TAG_enumeration_type
:
9507 case DW_TAG_enumerator
:
9508 /* These tags always have simple identifiers already; no need
9509 to canonicalize them. */
9510 part_die
->name
= DW_STRING (&attr
);
9514 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9515 &cu
->objfile
->objfile_obstack
);
9519 case DW_AT_linkage_name
:
9520 case DW_AT_MIPS_linkage_name
:
9521 /* Note that both forms of linkage name might appear. We
9522 assume they will be the same, and we only store the last
9524 if (cu
->language
== language_ada
)
9525 part_die
->name
= DW_STRING (&attr
);
9526 part_die
->linkage_name
= DW_STRING (&attr
);
9529 has_low_pc_attr
= 1;
9530 part_die
->lowpc
= DW_ADDR (&attr
);
9533 has_high_pc_attr
= 1;
9534 part_die
->highpc
= DW_ADDR (&attr
);
9536 case DW_AT_location
:
9537 /* Support the .debug_loc offsets. */
9538 if (attr_form_is_block (&attr
))
9540 part_die
->locdesc
= DW_BLOCK (&attr
);
9542 else if (attr_form_is_section_offset (&attr
))
9544 dwarf2_complex_location_expr_complaint ();
9548 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9549 "partial symbol information");
9552 case DW_AT_external
:
9553 part_die
->is_external
= DW_UNSND (&attr
);
9555 case DW_AT_declaration
:
9556 part_die
->is_declaration
= DW_UNSND (&attr
);
9559 part_die
->has_type
= 1;
9561 case DW_AT_abstract_origin
:
9562 case DW_AT_specification
:
9563 case DW_AT_extension
:
9564 part_die
->has_specification
= 1;
9565 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9568 /* Ignore absolute siblings, they might point outside of
9569 the current compile unit. */
9570 if (attr
.form
== DW_FORM_ref_addr
)
9571 complaint (&symfile_complaints
,
9572 _("ignoring absolute DW_AT_sibling"));
9574 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9576 case DW_AT_byte_size
:
9577 part_die
->has_byte_size
= 1;
9579 case DW_AT_calling_convention
:
9580 /* DWARF doesn't provide a way to identify a program's source-level
9581 entry point. DW_AT_calling_convention attributes are only meant
9582 to describe functions' calling conventions.
9584 However, because it's a necessary piece of information in
9585 Fortran, and because DW_CC_program is the only piece of debugging
9586 information whose definition refers to a 'main program' at all,
9587 several compilers have begun marking Fortran main programs with
9588 DW_CC_program --- even when those functions use the standard
9589 calling conventions.
9591 So until DWARF specifies a way to provide this information and
9592 compilers pick up the new representation, we'll support this
9594 if (DW_UNSND (&attr
) == DW_CC_program
9595 && cu
->language
== language_fortran
)
9597 set_main_name (part_die
->name
);
9599 /* As this DIE has a static linkage the name would be difficult
9600 to look up later. */
9601 language_of_main
= language_fortran
;
9609 if (has_low_pc_attr
&& has_high_pc_attr
)
9611 /* When using the GNU linker, .gnu.linkonce. sections are used to
9612 eliminate duplicate copies of functions and vtables and such.
9613 The linker will arbitrarily choose one and discard the others.
9614 The AT_*_pc values for such functions refer to local labels in
9615 these sections. If the section from that file was discarded, the
9616 labels are not in the output, so the relocs get a value of 0.
9617 If this is a discarded function, mark the pc bounds as invalid,
9618 so that GDB will ignore it. */
9619 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9621 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9623 complaint (&symfile_complaints
,
9624 _("DW_AT_low_pc %s is zero "
9625 "for DIE at 0x%x [in module %s]"),
9626 paddress (gdbarch
, part_die
->lowpc
),
9627 part_die
->offset
, cu
->objfile
->name
);
9629 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9630 else if (part_die
->lowpc
>= part_die
->highpc
)
9632 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9634 complaint (&symfile_complaints
,
9635 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9636 "for DIE at 0x%x [in module %s]"),
9637 paddress (gdbarch
, part_die
->lowpc
),
9638 paddress (gdbarch
, part_die
->highpc
),
9639 part_die
->offset
, cu
->objfile
->name
);
9642 part_die
->has_pc_info
= 1;
9648 /* Find a cached partial DIE at OFFSET in CU. */
9650 static struct partial_die_info
*
9651 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9653 struct partial_die_info
*lookup_die
= NULL
;
9654 struct partial_die_info part_die
;
9656 part_die
.offset
= offset
;
9657 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9662 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9663 except in the case of .debug_types DIEs which do not reference
9664 outside their CU (they do however referencing other types via
9665 DW_FORM_ref_sig8). */
9667 static struct partial_die_info
*
9668 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9670 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9671 struct partial_die_info
*pd
= NULL
;
9673 if (cu
->per_cu
->debug_type_section
)
9675 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9681 if (offset_in_cu_p (&cu
->header
, offset
))
9683 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9688 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9690 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9691 load_partial_comp_unit (per_cu
, cu
->objfile
);
9693 per_cu
->cu
->last_used
= 0;
9694 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9696 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9698 struct cleanup
*back_to
;
9699 struct partial_die_info comp_unit_die
;
9700 struct abbrev_info
*abbrev
;
9701 unsigned int bytes_read
;
9704 per_cu
->load_all_dies
= 1;
9706 /* Re-read the DIEs. */
9707 back_to
= make_cleanup (null_cleanup
, 0);
9708 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9710 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
9711 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9713 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9714 + per_cu
->cu
->header
.offset
9715 + per_cu
->cu
->header
.first_die_offset
);
9716 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9717 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9718 per_cu
->cu
->objfile
->obfd
,
9719 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9721 if (comp_unit_die
.has_children
)
9722 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
9723 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9725 do_cleanups (back_to
);
9727 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9733 internal_error (__FILE__
, __LINE__
,
9734 _("could not find partial DIE 0x%x "
9735 "in cache [from module %s]\n"),
9736 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9740 /* See if we can figure out if the class lives in a namespace. We do
9741 this by looking for a member function; its demangled name will
9742 contain namespace info, if there is any. */
9745 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9746 struct dwarf2_cu
*cu
)
9748 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9749 what template types look like, because the demangler
9750 frequently doesn't give the same name as the debug info. We
9751 could fix this by only using the demangled name to get the
9752 prefix (but see comment in read_structure_type). */
9754 struct partial_die_info
*real_pdi
;
9755 struct partial_die_info
*child_pdi
;
9757 /* If this DIE (this DIE's specification, if any) has a parent, then
9758 we should not do this. We'll prepend the parent's fully qualified
9759 name when we create the partial symbol. */
9761 real_pdi
= struct_pdi
;
9762 while (real_pdi
->has_specification
)
9763 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9765 if (real_pdi
->die_parent
!= NULL
)
9768 for (child_pdi
= struct_pdi
->die_child
;
9770 child_pdi
= child_pdi
->die_sibling
)
9772 if (child_pdi
->tag
== DW_TAG_subprogram
9773 && child_pdi
->linkage_name
!= NULL
)
9775 char *actual_class_name
9776 = language_class_name_from_physname (cu
->language_defn
,
9777 child_pdi
->linkage_name
);
9778 if (actual_class_name
!= NULL
)
9781 = obsavestring (actual_class_name
,
9782 strlen (actual_class_name
),
9783 &cu
->objfile
->objfile_obstack
);
9784 xfree (actual_class_name
);
9791 /* Adjust PART_DIE before generating a symbol for it. This function
9792 may set the is_external flag or change the DIE's name. */
9795 fixup_partial_die (struct partial_die_info
*part_die
,
9796 struct dwarf2_cu
*cu
)
9798 /* Once we've fixed up a die, there's no point in doing so again.
9799 This also avoids a memory leak if we were to call
9800 guess_partial_die_structure_name multiple times. */
9801 if (part_die
->fixup_called
)
9804 /* If we found a reference attribute and the DIE has no name, try
9805 to find a name in the referred to DIE. */
9807 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9809 struct partial_die_info
*spec_die
;
9811 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9813 fixup_partial_die (spec_die
, cu
);
9817 part_die
->name
= spec_die
->name
;
9819 /* Copy DW_AT_external attribute if it is set. */
9820 if (spec_die
->is_external
)
9821 part_die
->is_external
= spec_die
->is_external
;
9825 /* Set default names for some unnamed DIEs. */
9827 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9828 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
9830 /* If there is no parent die to provide a namespace, and there are
9831 children, see if we can determine the namespace from their linkage
9833 NOTE: We need to do this even if cu->has_namespace_info != 0.
9834 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9835 if (cu
->language
== language_cplus
9836 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
9837 && part_die
->die_parent
== NULL
9838 && part_die
->has_children
9839 && (part_die
->tag
== DW_TAG_class_type
9840 || part_die
->tag
== DW_TAG_structure_type
9841 || part_die
->tag
== DW_TAG_union_type
))
9842 guess_partial_die_structure_name (part_die
, cu
);
9844 /* GCC might emit a nameless struct or union that has a linkage
9845 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
9846 if (part_die
->name
== NULL
9847 && (part_die
->tag
== DW_TAG_structure_type
9848 || part_die
->tag
== DW_TAG_union_type
9849 || part_die
->tag
== DW_TAG_class_type
)
9850 && part_die
->linkage_name
!= NULL
)
9854 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
9857 part_die
->name
= obsavestring (demangled
, strlen (demangled
),
9858 &cu
->objfile
->objfile_obstack
);
9863 part_die
->fixup_called
= 1;
9866 /* Read an attribute value described by an attribute form. */
9869 read_attribute_value (struct attribute
*attr
, unsigned form
,
9870 bfd
*abfd
, gdb_byte
*info_ptr
,
9871 struct dwarf2_cu
*cu
)
9873 struct comp_unit_head
*cu_header
= &cu
->header
;
9874 unsigned int bytes_read
;
9875 struct dwarf_block
*blk
;
9880 case DW_FORM_ref_addr
:
9881 if (cu
->header
.version
== 2)
9882 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9884 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
9885 &cu
->header
, &bytes_read
);
9886 info_ptr
+= bytes_read
;
9889 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9890 info_ptr
+= bytes_read
;
9892 case DW_FORM_block2
:
9893 blk
= dwarf_alloc_block (cu
);
9894 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9896 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9897 info_ptr
+= blk
->size
;
9898 DW_BLOCK (attr
) = blk
;
9900 case DW_FORM_block4
:
9901 blk
= dwarf_alloc_block (cu
);
9902 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9904 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9905 info_ptr
+= blk
->size
;
9906 DW_BLOCK (attr
) = blk
;
9909 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9913 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9917 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9920 case DW_FORM_sec_offset
:
9921 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9922 info_ptr
+= bytes_read
;
9924 case DW_FORM_string
:
9925 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9926 DW_STRING_IS_CANONICAL (attr
) = 0;
9927 info_ptr
+= bytes_read
;
9930 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9932 DW_STRING_IS_CANONICAL (attr
) = 0;
9933 info_ptr
+= bytes_read
;
9935 case DW_FORM_exprloc
:
9937 blk
= dwarf_alloc_block (cu
);
9938 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9939 info_ptr
+= bytes_read
;
9940 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9941 info_ptr
+= blk
->size
;
9942 DW_BLOCK (attr
) = blk
;
9944 case DW_FORM_block1
:
9945 blk
= dwarf_alloc_block (cu
);
9946 blk
->size
= read_1_byte (abfd
, info_ptr
);
9948 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9949 info_ptr
+= blk
->size
;
9950 DW_BLOCK (attr
) = blk
;
9953 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9957 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9960 case DW_FORM_flag_present
:
9961 DW_UNSND (attr
) = 1;
9964 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9965 info_ptr
+= bytes_read
;
9968 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9969 info_ptr
+= bytes_read
;
9972 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9976 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9980 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9984 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9987 case DW_FORM_ref_sig8
:
9988 /* Convert the signature to something we can record in DW_UNSND
9990 NOTE: This is NULL if the type wasn't found. */
9991 DW_SIGNATURED_TYPE (attr
) =
9992 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9995 case DW_FORM_ref_udata
:
9996 DW_ADDR (attr
) = (cu
->header
.offset
9997 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9998 info_ptr
+= bytes_read
;
10000 case DW_FORM_indirect
:
10001 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10002 info_ptr
+= bytes_read
;
10003 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
10006 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10007 dwarf_form_name (form
),
10008 bfd_get_filename (abfd
));
10011 /* We have seen instances where the compiler tried to emit a byte
10012 size attribute of -1 which ended up being encoded as an unsigned
10013 0xffffffff. Although 0xffffffff is technically a valid size value,
10014 an object of this size seems pretty unlikely so we can relatively
10015 safely treat these cases as if the size attribute was invalid and
10016 treat them as zero by default. */
10017 if (attr
->name
== DW_AT_byte_size
10018 && form
== DW_FORM_data4
10019 && DW_UNSND (attr
) >= 0xffffffff)
10022 (&symfile_complaints
,
10023 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10024 hex_string (DW_UNSND (attr
)));
10025 DW_UNSND (attr
) = 0;
10031 /* Read an attribute described by an abbreviated attribute. */
10034 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10035 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
10037 attr
->name
= abbrev
->name
;
10038 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
10041 /* Read dwarf information from a buffer. */
10043 static unsigned int
10044 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10046 return bfd_get_8 (abfd
, buf
);
10050 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10052 return bfd_get_signed_8 (abfd
, buf
);
10055 static unsigned int
10056 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10058 return bfd_get_16 (abfd
, buf
);
10062 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10064 return bfd_get_signed_16 (abfd
, buf
);
10067 static unsigned int
10068 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10070 return bfd_get_32 (abfd
, buf
);
10074 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10076 return bfd_get_signed_32 (abfd
, buf
);
10080 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10082 return bfd_get_64 (abfd
, buf
);
10086 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10087 unsigned int *bytes_read
)
10089 struct comp_unit_head
*cu_header
= &cu
->header
;
10090 CORE_ADDR retval
= 0;
10092 if (cu_header
->signed_addr_p
)
10094 switch (cu_header
->addr_size
)
10097 retval
= bfd_get_signed_16 (abfd
, buf
);
10100 retval
= bfd_get_signed_32 (abfd
, buf
);
10103 retval
= bfd_get_signed_64 (abfd
, buf
);
10106 internal_error (__FILE__
, __LINE__
,
10107 _("read_address: bad switch, signed [in module %s]"),
10108 bfd_get_filename (abfd
));
10113 switch (cu_header
->addr_size
)
10116 retval
= bfd_get_16 (abfd
, buf
);
10119 retval
= bfd_get_32 (abfd
, buf
);
10122 retval
= bfd_get_64 (abfd
, buf
);
10125 internal_error (__FILE__
, __LINE__
,
10126 _("read_address: bad switch, "
10127 "unsigned [in module %s]"),
10128 bfd_get_filename (abfd
));
10132 *bytes_read
= cu_header
->addr_size
;
10136 /* Read the initial length from a section. The (draft) DWARF 3
10137 specification allows the initial length to take up either 4 bytes
10138 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10139 bytes describe the length and all offsets will be 8 bytes in length
10142 An older, non-standard 64-bit format is also handled by this
10143 function. The older format in question stores the initial length
10144 as an 8-byte quantity without an escape value. Lengths greater
10145 than 2^32 aren't very common which means that the initial 4 bytes
10146 is almost always zero. Since a length value of zero doesn't make
10147 sense for the 32-bit format, this initial zero can be considered to
10148 be an escape value which indicates the presence of the older 64-bit
10149 format. As written, the code can't detect (old format) lengths
10150 greater than 4GB. If it becomes necessary to handle lengths
10151 somewhat larger than 4GB, we could allow other small values (such
10152 as the non-sensical values of 1, 2, and 3) to also be used as
10153 escape values indicating the presence of the old format.
10155 The value returned via bytes_read should be used to increment the
10156 relevant pointer after calling read_initial_length().
10158 [ Note: read_initial_length() and read_offset() are based on the
10159 document entitled "DWARF Debugging Information Format", revision
10160 3, draft 8, dated November 19, 2001. This document was obtained
10163 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10165 This document is only a draft and is subject to change. (So beware.)
10167 Details regarding the older, non-standard 64-bit format were
10168 determined empirically by examining 64-bit ELF files produced by
10169 the SGI toolchain on an IRIX 6.5 machine.
10171 - Kevin, July 16, 2002
10175 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10177 LONGEST length
= bfd_get_32 (abfd
, buf
);
10179 if (length
== 0xffffffff)
10181 length
= bfd_get_64 (abfd
, buf
+ 4);
10184 else if (length
== 0)
10186 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10187 length
= bfd_get_64 (abfd
, buf
);
10198 /* Cover function for read_initial_length.
10199 Returns the length of the object at BUF, and stores the size of the
10200 initial length in *BYTES_READ and stores the size that offsets will be in
10202 If the initial length size is not equivalent to that specified in
10203 CU_HEADER then issue a complaint.
10204 This is useful when reading non-comp-unit headers. */
10207 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10208 const struct comp_unit_head
*cu_header
,
10209 unsigned int *bytes_read
,
10210 unsigned int *offset_size
)
10212 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10214 gdb_assert (cu_header
->initial_length_size
== 4
10215 || cu_header
->initial_length_size
== 8
10216 || cu_header
->initial_length_size
== 12);
10218 if (cu_header
->initial_length_size
!= *bytes_read
)
10219 complaint (&symfile_complaints
,
10220 _("intermixed 32-bit and 64-bit DWARF sections"));
10222 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10226 /* Read an offset from the data stream. The size of the offset is
10227 given by cu_header->offset_size. */
10230 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10231 unsigned int *bytes_read
)
10233 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10235 *bytes_read
= cu_header
->offset_size
;
10239 /* Read an offset from the data stream. */
10242 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10244 LONGEST retval
= 0;
10246 switch (offset_size
)
10249 retval
= bfd_get_32 (abfd
, buf
);
10252 retval
= bfd_get_64 (abfd
, buf
);
10255 internal_error (__FILE__
, __LINE__
,
10256 _("read_offset_1: bad switch [in module %s]"),
10257 bfd_get_filename (abfd
));
10264 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10266 /* If the size of a host char is 8 bits, we can return a pointer
10267 to the buffer, otherwise we have to copy the data to a buffer
10268 allocated on the temporary obstack. */
10269 gdb_assert (HOST_CHAR_BIT
== 8);
10274 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10276 /* If the size of a host char is 8 bits, we can return a pointer
10277 to the string, otherwise we have to copy the string to a buffer
10278 allocated on the temporary obstack. */
10279 gdb_assert (HOST_CHAR_BIT
== 8);
10282 *bytes_read_ptr
= 1;
10285 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10286 return (char *) buf
;
10290 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
10292 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10293 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10294 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10295 bfd_get_filename (abfd
));
10296 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10297 error (_("DW_FORM_strp pointing outside of "
10298 ".debug_str section [in module %s]"),
10299 bfd_get_filename (abfd
));
10300 gdb_assert (HOST_CHAR_BIT
== 8);
10301 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10303 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10307 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10308 const struct comp_unit_head
*cu_header
,
10309 unsigned int *bytes_read_ptr
)
10311 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10313 return read_indirect_string_at_offset (abfd
, str_offset
);
10316 static unsigned long
10317 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10319 unsigned long result
;
10320 unsigned int num_read
;
10322 unsigned char byte
;
10330 byte
= bfd_get_8 (abfd
, buf
);
10333 result
|= ((unsigned long)(byte
& 127) << shift
);
10334 if ((byte
& 128) == 0)
10340 *bytes_read_ptr
= num_read
;
10345 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10348 int i
, shift
, num_read
;
10349 unsigned char byte
;
10357 byte
= bfd_get_8 (abfd
, buf
);
10360 result
|= ((long)(byte
& 127) << shift
);
10362 if ((byte
& 128) == 0)
10367 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10368 result
|= -(((long)1) << shift
);
10369 *bytes_read_ptr
= num_read
;
10373 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10376 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10382 byte
= bfd_get_8 (abfd
, buf
);
10384 if ((byte
& 128) == 0)
10390 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10397 cu
->language
= language_c
;
10399 case DW_LANG_C_plus_plus
:
10400 cu
->language
= language_cplus
;
10403 cu
->language
= language_d
;
10405 case DW_LANG_Fortran77
:
10406 case DW_LANG_Fortran90
:
10407 case DW_LANG_Fortran95
:
10408 cu
->language
= language_fortran
;
10410 case DW_LANG_Mips_Assembler
:
10411 cu
->language
= language_asm
;
10414 cu
->language
= language_java
;
10416 case DW_LANG_Ada83
:
10417 case DW_LANG_Ada95
:
10418 cu
->language
= language_ada
;
10420 case DW_LANG_Modula2
:
10421 cu
->language
= language_m2
;
10423 case DW_LANG_Pascal83
:
10424 cu
->language
= language_pascal
;
10427 cu
->language
= language_objc
;
10429 case DW_LANG_Cobol74
:
10430 case DW_LANG_Cobol85
:
10432 cu
->language
= language_minimal
;
10435 cu
->language_defn
= language_def (cu
->language
);
10438 /* Return the named attribute or NULL if not there. */
10440 static struct attribute
*
10441 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10444 struct attribute
*spec
= NULL
;
10446 for (i
= 0; i
< die
->num_attrs
; ++i
)
10448 if (die
->attrs
[i
].name
== name
)
10449 return &die
->attrs
[i
];
10450 if (die
->attrs
[i
].name
== DW_AT_specification
10451 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10452 spec
= &die
->attrs
[i
];
10457 die
= follow_die_ref (die
, spec
, &cu
);
10458 return dwarf2_attr (die
, name
, cu
);
10464 /* Return the named attribute or NULL if not there,
10465 but do not follow DW_AT_specification, etc.
10466 This is for use in contexts where we're reading .debug_types dies.
10467 Following DW_AT_specification, DW_AT_abstract_origin will take us
10468 back up the chain, and we want to go down. */
10470 static struct attribute
*
10471 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10472 struct dwarf2_cu
*cu
)
10476 for (i
= 0; i
< die
->num_attrs
; ++i
)
10477 if (die
->attrs
[i
].name
== name
)
10478 return &die
->attrs
[i
];
10483 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10484 and holds a non-zero value. This function should only be used for
10485 DW_FORM_flag or DW_FORM_flag_present attributes. */
10488 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10490 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10492 return (attr
&& DW_UNSND (attr
));
10496 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10498 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10499 which value is non-zero. However, we have to be careful with
10500 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10501 (via dwarf2_flag_true_p) follows this attribute. So we may
10502 end up accidently finding a declaration attribute that belongs
10503 to a different DIE referenced by the specification attribute,
10504 even though the given DIE does not have a declaration attribute. */
10505 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10506 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10509 /* Return the die giving the specification for DIE, if there is
10510 one. *SPEC_CU is the CU containing DIE on input, and the CU
10511 containing the return value on output. If there is no
10512 specification, but there is an abstract origin, that is
10515 static struct die_info
*
10516 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10518 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10521 if (spec_attr
== NULL
)
10522 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10524 if (spec_attr
== NULL
)
10527 return follow_die_ref (die
, spec_attr
, spec_cu
);
10530 /* Free the line_header structure *LH, and any arrays and strings it
10532 NOTE: This is also used as a "cleanup" function. */
10535 free_line_header (struct line_header
*lh
)
10537 if (lh
->standard_opcode_lengths
)
10538 xfree (lh
->standard_opcode_lengths
);
10540 /* Remember that all the lh->file_names[i].name pointers are
10541 pointers into debug_line_buffer, and don't need to be freed. */
10542 if (lh
->file_names
)
10543 xfree (lh
->file_names
);
10545 /* Similarly for the include directory names. */
10546 if (lh
->include_dirs
)
10547 xfree (lh
->include_dirs
);
10552 /* Add an entry to LH's include directory table. */
10555 add_include_dir (struct line_header
*lh
, char *include_dir
)
10557 /* Grow the array if necessary. */
10558 if (lh
->include_dirs_size
== 0)
10560 lh
->include_dirs_size
= 1; /* for testing */
10561 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10562 * sizeof (*lh
->include_dirs
));
10564 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10566 lh
->include_dirs_size
*= 2;
10567 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10568 (lh
->include_dirs_size
10569 * sizeof (*lh
->include_dirs
)));
10572 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10575 /* Add an entry to LH's file name table. */
10578 add_file_name (struct line_header
*lh
,
10580 unsigned int dir_index
,
10581 unsigned int mod_time
,
10582 unsigned int length
)
10584 struct file_entry
*fe
;
10586 /* Grow the array if necessary. */
10587 if (lh
->file_names_size
== 0)
10589 lh
->file_names_size
= 1; /* for testing */
10590 lh
->file_names
= xmalloc (lh
->file_names_size
10591 * sizeof (*lh
->file_names
));
10593 else if (lh
->num_file_names
>= lh
->file_names_size
)
10595 lh
->file_names_size
*= 2;
10596 lh
->file_names
= xrealloc (lh
->file_names
,
10597 (lh
->file_names_size
10598 * sizeof (*lh
->file_names
)));
10601 fe
= &lh
->file_names
[lh
->num_file_names
++];
10603 fe
->dir_index
= dir_index
;
10604 fe
->mod_time
= mod_time
;
10605 fe
->length
= length
;
10606 fe
->included_p
= 0;
10610 /* Read the statement program header starting at OFFSET in
10611 .debug_line, according to the endianness of ABFD. Return a pointer
10612 to a struct line_header, allocated using xmalloc.
10614 NOTE: the strings in the include directory and file name tables of
10615 the returned object point into debug_line_buffer, and must not be
10618 static struct line_header
*
10619 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10620 struct dwarf2_cu
*cu
)
10622 struct cleanup
*back_to
;
10623 struct line_header
*lh
;
10624 gdb_byte
*line_ptr
;
10625 unsigned int bytes_read
, offset_size
;
10627 char *cur_dir
, *cur_file
;
10629 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10630 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10632 complaint (&symfile_complaints
, _("missing .debug_line section"));
10636 /* Make sure that at least there's room for the total_length field.
10637 That could be 12 bytes long, but we're just going to fudge that. */
10638 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10640 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10644 lh
= xmalloc (sizeof (*lh
));
10645 memset (lh
, 0, sizeof (*lh
));
10646 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10649 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10651 /* Read in the header. */
10653 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10654 &bytes_read
, &offset_size
);
10655 line_ptr
+= bytes_read
;
10656 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10657 + dwarf2_per_objfile
->line
.size
))
10659 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10662 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10663 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10665 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10666 line_ptr
+= offset_size
;
10667 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10669 if (lh
->version
>= 4)
10671 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10675 lh
->maximum_ops_per_instruction
= 1;
10677 if (lh
->maximum_ops_per_instruction
== 0)
10679 lh
->maximum_ops_per_instruction
= 1;
10680 complaint (&symfile_complaints
,
10681 _("invalid maximum_ops_per_instruction "
10682 "in `.debug_line' section"));
10685 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10687 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10689 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10691 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10693 lh
->standard_opcode_lengths
10694 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10696 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10697 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10699 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10703 /* Read directory table. */
10704 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10706 line_ptr
+= bytes_read
;
10707 add_include_dir (lh
, cur_dir
);
10709 line_ptr
+= bytes_read
;
10711 /* Read file name table. */
10712 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10714 unsigned int dir_index
, mod_time
, length
;
10716 line_ptr
+= bytes_read
;
10717 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10718 line_ptr
+= bytes_read
;
10719 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10720 line_ptr
+= bytes_read
;
10721 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10722 line_ptr
+= bytes_read
;
10724 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10726 line_ptr
+= bytes_read
;
10727 lh
->statement_program_start
= line_ptr
;
10729 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
10730 + dwarf2_per_objfile
->line
.size
))
10731 complaint (&symfile_complaints
,
10732 _("line number info header doesn't "
10733 "fit in `.debug_line' section"));
10735 discard_cleanups (back_to
);
10739 /* This function exists to work around a bug in certain compilers
10740 (particularly GCC 2.95), in which the first line number marker of a
10741 function does not show up until after the prologue, right before
10742 the second line number marker. This function shifts ADDRESS down
10743 to the beginning of the function if necessary, and is called on
10744 addresses passed to record_line. */
10747 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
10749 struct function_range
*fn
;
10751 /* Find the function_range containing address. */
10755 if (!cu
->cached_fn
)
10756 cu
->cached_fn
= cu
->first_fn
;
10758 fn
= cu
->cached_fn
;
10760 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10766 while (fn
&& fn
!= cu
->cached_fn
)
10767 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10777 if (address
!= fn
->lowpc
)
10778 complaint (&symfile_complaints
,
10779 _("misplaced first line number at 0x%lx for '%s'"),
10780 (unsigned long) address
, fn
->name
);
10785 /* Subroutine of dwarf_decode_lines to simplify it.
10786 Return the file name of the psymtab for included file FILE_INDEX
10787 in line header LH of PST.
10788 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10789 If space for the result is malloc'd, it will be freed by a cleanup.
10790 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10793 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10794 const struct partial_symtab
*pst
,
10795 const char *comp_dir
)
10797 const struct file_entry fe
= lh
->file_names
[file_index
];
10798 char *include_name
= fe
.name
;
10799 char *include_name_to_compare
= include_name
;
10800 char *dir_name
= NULL
;
10801 const char *pst_filename
;
10802 char *copied_name
= NULL
;
10806 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10808 if (!IS_ABSOLUTE_PATH (include_name
)
10809 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10811 /* Avoid creating a duplicate psymtab for PST.
10812 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10813 Before we do the comparison, however, we need to account
10814 for DIR_NAME and COMP_DIR.
10815 First prepend dir_name (if non-NULL). If we still don't
10816 have an absolute path prepend comp_dir (if non-NULL).
10817 However, the directory we record in the include-file's
10818 psymtab does not contain COMP_DIR (to match the
10819 corresponding symtab(s)).
10824 bash$ gcc -g ./hello.c
10825 include_name = "hello.c"
10827 DW_AT_comp_dir = comp_dir = "/tmp"
10828 DW_AT_name = "./hello.c" */
10830 if (dir_name
!= NULL
)
10832 include_name
= concat (dir_name
, SLASH_STRING
,
10833 include_name
, (char *)NULL
);
10834 include_name_to_compare
= include_name
;
10835 make_cleanup (xfree
, include_name
);
10837 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10839 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10840 include_name
, (char *)NULL
);
10844 pst_filename
= pst
->filename
;
10845 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10847 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
10848 pst_filename
, (char *)NULL
);
10849 pst_filename
= copied_name
;
10852 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
10854 if (include_name_to_compare
!= include_name
)
10855 xfree (include_name_to_compare
);
10856 if (copied_name
!= NULL
)
10857 xfree (copied_name
);
10861 return include_name
;
10864 /* Ignore this record_line request. */
10867 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10872 /* Decode the Line Number Program (LNP) for the given line_header
10873 structure and CU. The actual information extracted and the type
10874 of structures created from the LNP depends on the value of PST.
10876 1. If PST is NULL, then this procedure uses the data from the program
10877 to create all necessary symbol tables, and their linetables.
10879 2. If PST is not NULL, this procedure reads the program to determine
10880 the list of files included by the unit represented by PST, and
10881 builds all the associated partial symbol tables.
10883 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10884 It is used for relative paths in the line table.
10885 NOTE: When processing partial symtabs (pst != NULL),
10886 comp_dir == pst->dirname.
10888 NOTE: It is important that psymtabs have the same file name (via strcmp)
10889 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10890 symtab we don't use it in the name of the psymtabs we create.
10891 E.g. expand_line_sal requires this when finding psymtabs to expand.
10892 A good testcase for this is mb-inline.exp. */
10895 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
10896 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10898 gdb_byte
*line_ptr
, *extended_end
;
10899 gdb_byte
*line_end
;
10900 unsigned int bytes_read
, extended_len
;
10901 unsigned char op_code
, extended_op
, adj_opcode
;
10902 CORE_ADDR baseaddr
;
10903 struct objfile
*objfile
= cu
->objfile
;
10904 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10905 const int decode_for_pst_p
= (pst
!= NULL
);
10906 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10907 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10910 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10912 line_ptr
= lh
->statement_program_start
;
10913 line_end
= lh
->statement_program_end
;
10915 /* Read the statement sequences until there's nothing left. */
10916 while (line_ptr
< line_end
)
10918 /* state machine registers */
10919 CORE_ADDR address
= 0;
10920 unsigned int file
= 1;
10921 unsigned int line
= 1;
10922 unsigned int column
= 0;
10923 int is_stmt
= lh
->default_is_stmt
;
10924 int basic_block
= 0;
10925 int end_sequence
= 0;
10927 unsigned char op_index
= 0;
10929 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10931 /* Start a subfile for the current file of the state machine. */
10932 /* lh->include_dirs and lh->file_names are 0-based, but the
10933 directory and file name numbers in the statement program
10935 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10939 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10941 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10944 /* Decode the table. */
10945 while (!end_sequence
)
10947 op_code
= read_1_byte (abfd
, line_ptr
);
10949 if (line_ptr
> line_end
)
10951 dwarf2_debug_line_missing_end_sequence_complaint ();
10955 if (op_code
>= lh
->opcode_base
)
10957 /* Special operand. */
10958 adj_opcode
= op_code
- lh
->opcode_base
;
10959 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10960 / lh
->maximum_ops_per_instruction
)
10961 * lh
->minimum_instruction_length
);
10962 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10963 % lh
->maximum_ops_per_instruction
);
10964 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10965 if (lh
->num_file_names
< file
|| file
== 0)
10966 dwarf2_debug_line_missing_file_complaint ();
10967 /* For now we ignore lines not starting on an
10968 instruction boundary. */
10969 else if (op_index
== 0)
10971 lh
->file_names
[file
- 1].included_p
= 1;
10972 if (!decode_for_pst_p
&& is_stmt
)
10974 if (last_subfile
!= current_subfile
)
10976 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10978 (*p_record_line
) (last_subfile
, 0, addr
);
10979 last_subfile
= current_subfile
;
10981 /* Append row to matrix using current values. */
10982 addr
= check_cu_functions (address
, cu
);
10983 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10984 (*p_record_line
) (current_subfile
, line
, addr
);
10989 else switch (op_code
)
10991 case DW_LNS_extended_op
:
10992 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
10994 line_ptr
+= bytes_read
;
10995 extended_end
= line_ptr
+ extended_len
;
10996 extended_op
= read_1_byte (abfd
, line_ptr
);
10998 switch (extended_op
)
11000 case DW_LNE_end_sequence
:
11001 p_record_line
= record_line
;
11004 case DW_LNE_set_address
:
11005 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
11007 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11009 /* This line table is for a function which has been
11010 GCd by the linker. Ignore it. PR gdb/12528 */
11013 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
11015 complaint (&symfile_complaints
,
11016 _(".debug_line address at offset 0x%lx is 0 "
11018 line_offset
, cu
->objfile
->name
);
11019 p_record_line
= noop_record_line
;
11023 line_ptr
+= bytes_read
;
11024 address
+= baseaddr
;
11026 case DW_LNE_define_file
:
11029 unsigned int dir_index
, mod_time
, length
;
11031 cur_file
= read_direct_string (abfd
, line_ptr
,
11033 line_ptr
+= bytes_read
;
11035 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11036 line_ptr
+= bytes_read
;
11038 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11039 line_ptr
+= bytes_read
;
11041 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11042 line_ptr
+= bytes_read
;
11043 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11046 case DW_LNE_set_discriminator
:
11047 /* The discriminator is not interesting to the debugger;
11049 line_ptr
= extended_end
;
11052 complaint (&symfile_complaints
,
11053 _("mangled .debug_line section"));
11056 /* Make sure that we parsed the extended op correctly. If e.g.
11057 we expected a different address size than the producer used,
11058 we may have read the wrong number of bytes. */
11059 if (line_ptr
!= extended_end
)
11061 complaint (&symfile_complaints
,
11062 _("mangled .debug_line section"));
11067 if (lh
->num_file_names
< file
|| file
== 0)
11068 dwarf2_debug_line_missing_file_complaint ();
11071 lh
->file_names
[file
- 1].included_p
= 1;
11072 if (!decode_for_pst_p
&& is_stmt
)
11074 if (last_subfile
!= current_subfile
)
11076 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11078 (*p_record_line
) (last_subfile
, 0, addr
);
11079 last_subfile
= current_subfile
;
11081 addr
= check_cu_functions (address
, cu
);
11082 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
11083 (*p_record_line
) (current_subfile
, line
, addr
);
11088 case DW_LNS_advance_pc
:
11091 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11093 address
+= (((op_index
+ adjust
)
11094 / lh
->maximum_ops_per_instruction
)
11095 * lh
->minimum_instruction_length
);
11096 op_index
= ((op_index
+ adjust
)
11097 % lh
->maximum_ops_per_instruction
);
11098 line_ptr
+= bytes_read
;
11101 case DW_LNS_advance_line
:
11102 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11103 line_ptr
+= bytes_read
;
11105 case DW_LNS_set_file
:
11107 /* The arrays lh->include_dirs and lh->file_names are
11108 0-based, but the directory and file name numbers in
11109 the statement program are 1-based. */
11110 struct file_entry
*fe
;
11113 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11114 line_ptr
+= bytes_read
;
11115 if (lh
->num_file_names
< file
|| file
== 0)
11116 dwarf2_debug_line_missing_file_complaint ();
11119 fe
= &lh
->file_names
[file
- 1];
11121 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11122 if (!decode_for_pst_p
)
11124 last_subfile
= current_subfile
;
11125 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11130 case DW_LNS_set_column
:
11131 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11132 line_ptr
+= bytes_read
;
11134 case DW_LNS_negate_stmt
:
11135 is_stmt
= (!is_stmt
);
11137 case DW_LNS_set_basic_block
:
11140 /* Add to the address register of the state machine the
11141 address increment value corresponding to special opcode
11142 255. I.e., this value is scaled by the minimum
11143 instruction length since special opcode 255 would have
11144 scaled the increment. */
11145 case DW_LNS_const_add_pc
:
11147 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11149 address
+= (((op_index
+ adjust
)
11150 / lh
->maximum_ops_per_instruction
)
11151 * lh
->minimum_instruction_length
);
11152 op_index
= ((op_index
+ adjust
)
11153 % lh
->maximum_ops_per_instruction
);
11156 case DW_LNS_fixed_advance_pc
:
11157 address
+= read_2_bytes (abfd
, line_ptr
);
11163 /* Unknown standard opcode, ignore it. */
11166 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11168 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11169 line_ptr
+= bytes_read
;
11174 if (lh
->num_file_names
< file
|| file
== 0)
11175 dwarf2_debug_line_missing_file_complaint ();
11178 lh
->file_names
[file
- 1].included_p
= 1;
11179 if (!decode_for_pst_p
)
11181 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11182 (*p_record_line
) (current_subfile
, 0, addr
);
11187 if (decode_for_pst_p
)
11191 /* Now that we're done scanning the Line Header Program, we can
11192 create the psymtab of each included file. */
11193 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11194 if (lh
->file_names
[file_index
].included_p
== 1)
11196 char *include_name
=
11197 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11198 if (include_name
!= NULL
)
11199 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11204 /* Make sure a symtab is created for every file, even files
11205 which contain only variables (i.e. no code with associated
11209 struct file_entry
*fe
;
11211 for (i
= 0; i
< lh
->num_file_names
; i
++)
11215 fe
= &lh
->file_names
[i
];
11217 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11218 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11220 /* Skip the main file; we don't need it, and it must be
11221 allocated last, so that it will show up before the
11222 non-primary symtabs in the objfile's symtab list. */
11223 if (current_subfile
== first_subfile
)
11226 if (current_subfile
->symtab
== NULL
)
11227 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11229 fe
->symtab
= current_subfile
->symtab
;
11234 /* Start a subfile for DWARF. FILENAME is the name of the file and
11235 DIRNAME the name of the source directory which contains FILENAME
11236 or NULL if not known. COMP_DIR is the compilation directory for the
11237 linetable's compilation unit or NULL if not known.
11238 This routine tries to keep line numbers from identical absolute and
11239 relative file names in a common subfile.
11241 Using the `list' example from the GDB testsuite, which resides in
11242 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11243 of /srcdir/list0.c yields the following debugging information for list0.c:
11245 DW_AT_name: /srcdir/list0.c
11246 DW_AT_comp_dir: /compdir
11247 files.files[0].name: list0.h
11248 files.files[0].dir: /srcdir
11249 files.files[1].name: list0.c
11250 files.files[1].dir: /srcdir
11252 The line number information for list0.c has to end up in a single
11253 subfile, so that `break /srcdir/list0.c:1' works as expected.
11254 start_subfile will ensure that this happens provided that we pass the
11255 concatenation of files.files[1].dir and files.files[1].name as the
11259 dwarf2_start_subfile (char *filename
, const char *dirname
,
11260 const char *comp_dir
)
11264 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11265 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11266 second argument to start_subfile. To be consistent, we do the
11267 same here. In order not to lose the line information directory,
11268 we concatenate it to the filename when it makes sense.
11269 Note that the Dwarf3 standard says (speaking of filenames in line
11270 information): ``The directory index is ignored for file names
11271 that represent full path names''. Thus ignoring dirname in the
11272 `else' branch below isn't an issue. */
11274 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11275 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11277 fullname
= filename
;
11279 start_subfile (fullname
, comp_dir
);
11281 if (fullname
!= filename
)
11286 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11287 struct dwarf2_cu
*cu
)
11289 struct objfile
*objfile
= cu
->objfile
;
11290 struct comp_unit_head
*cu_header
= &cu
->header
;
11292 /* NOTE drow/2003-01-30: There used to be a comment and some special
11293 code here to turn a symbol with DW_AT_external and a
11294 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11295 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11296 with some versions of binutils) where shared libraries could have
11297 relocations against symbols in their debug information - the
11298 minimal symbol would have the right address, but the debug info
11299 would not. It's no longer necessary, because we will explicitly
11300 apply relocations when we read in the debug information now. */
11302 /* A DW_AT_location attribute with no contents indicates that a
11303 variable has been optimized away. */
11304 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11306 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11310 /* Handle one degenerate form of location expression specially, to
11311 preserve GDB's previous behavior when section offsets are
11312 specified. If this is just a DW_OP_addr then mark this symbol
11315 if (attr_form_is_block (attr
)
11316 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11317 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11319 unsigned int dummy
;
11321 SYMBOL_VALUE_ADDRESS (sym
) =
11322 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11323 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11324 fixup_symbol_section (sym
, objfile
);
11325 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11326 SYMBOL_SECTION (sym
));
11330 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11331 expression evaluator, and use LOC_COMPUTED only when necessary
11332 (i.e. when the value of a register or memory location is
11333 referenced, or a thread-local block, etc.). Then again, it might
11334 not be worthwhile. I'm assuming that it isn't unless performance
11335 or memory numbers show me otherwise. */
11337 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11338 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11340 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11341 cu
->has_loclist
= 1;
11344 /* Given a pointer to a DWARF information entry, figure out if we need
11345 to make a symbol table entry for it, and if so, create a new entry
11346 and return a pointer to it.
11347 If TYPE is NULL, determine symbol type from the die, otherwise
11348 used the passed type.
11349 If SPACE is not NULL, use it to hold the new symbol. If it is
11350 NULL, allocate a new symbol on the objfile's obstack. */
11352 static struct symbol
*
11353 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11354 struct symbol
*space
)
11356 struct objfile
*objfile
= cu
->objfile
;
11357 struct symbol
*sym
= NULL
;
11359 struct attribute
*attr
= NULL
;
11360 struct attribute
*attr2
= NULL
;
11361 CORE_ADDR baseaddr
;
11362 struct pending
**list_to_add
= NULL
;
11364 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11366 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11368 name
= dwarf2_name (die
, cu
);
11371 const char *linkagename
;
11372 int suppress_add
= 0;
11377 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11378 OBJSTAT (objfile
, n_syms
++);
11380 /* Cache this symbol's name and the name's demangled form (if any). */
11381 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11382 linkagename
= dwarf2_physname (name
, die
, cu
);
11383 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11385 /* Fortran does not have mangling standard and the mangling does differ
11386 between gfortran, iFort etc. */
11387 if (cu
->language
== language_fortran
11388 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11389 symbol_set_demangled_name (&(sym
->ginfo
),
11390 (char *) dwarf2_full_name (name
, die
, cu
),
11393 /* Default assumptions.
11394 Use the passed type or decode it from the die. */
11395 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11396 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11398 SYMBOL_TYPE (sym
) = type
;
11400 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11401 attr
= dwarf2_attr (die
,
11402 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11406 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11409 attr
= dwarf2_attr (die
,
11410 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11414 int file_index
= DW_UNSND (attr
);
11416 if (cu
->line_header
== NULL
11417 || file_index
> cu
->line_header
->num_file_names
)
11418 complaint (&symfile_complaints
,
11419 _("file index out of range"));
11420 else if (file_index
> 0)
11422 struct file_entry
*fe
;
11424 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11425 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11432 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11435 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11437 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11438 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11439 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11440 add_symbol_to_list (sym
, cu
->list_in_scope
);
11442 case DW_TAG_subprogram
:
11443 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11445 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11446 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11447 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11448 || cu
->language
== language_ada
)
11450 /* Subprograms marked external are stored as a global symbol.
11451 Ada subprograms, whether marked external or not, are always
11452 stored as a global symbol, because we want to be able to
11453 access them globally. For instance, we want to be able
11454 to break on a nested subprogram without having to
11455 specify the context. */
11456 list_to_add
= &global_symbols
;
11460 list_to_add
= cu
->list_in_scope
;
11463 case DW_TAG_inlined_subroutine
:
11464 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11466 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11467 SYMBOL_INLINED (sym
) = 1;
11468 /* Do not add the symbol to any lists. It will be found via
11469 BLOCK_FUNCTION from the blockvector. */
11471 case DW_TAG_template_value_param
:
11473 /* Fall through. */
11474 case DW_TAG_constant
:
11475 case DW_TAG_variable
:
11476 case DW_TAG_member
:
11477 /* Compilation with minimal debug info may result in
11478 variables with missing type entries. Change the
11479 misleading `void' type to something sensible. */
11480 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11482 = objfile_type (objfile
)->nodebug_data_symbol
;
11484 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11485 /* In the case of DW_TAG_member, we should only be called for
11486 static const members. */
11487 if (die
->tag
== DW_TAG_member
)
11489 /* dwarf2_add_field uses die_is_declaration,
11490 so we do the same. */
11491 gdb_assert (die_is_declaration (die
, cu
));
11496 dwarf2_const_value (attr
, sym
, cu
);
11497 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11500 if (attr2
&& (DW_UNSND (attr2
) != 0))
11501 list_to_add
= &global_symbols
;
11503 list_to_add
= cu
->list_in_scope
;
11507 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11510 var_decode_location (attr
, sym
, cu
);
11511 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11512 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11513 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11514 && !dwarf2_per_objfile
->has_section_at_zero
)
11516 /* When a static variable is eliminated by the linker,
11517 the corresponding debug information is not stripped
11518 out, but the variable address is set to null;
11519 do not add such variables into symbol table. */
11521 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11523 /* Workaround gfortran PR debug/40040 - it uses
11524 DW_AT_location for variables in -fPIC libraries which may
11525 get overriden by other libraries/executable and get
11526 a different address. Resolve it by the minimal symbol
11527 which may come from inferior's executable using copy
11528 relocation. Make this workaround only for gfortran as for
11529 other compilers GDB cannot guess the minimal symbol
11530 Fortran mangling kind. */
11531 if (cu
->language
== language_fortran
&& die
->parent
11532 && die
->parent
->tag
== DW_TAG_module
11534 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11535 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11537 /* A variable with DW_AT_external is never static,
11538 but it may be block-scoped. */
11539 list_to_add
= (cu
->list_in_scope
== &file_symbols
11540 ? &global_symbols
: cu
->list_in_scope
);
11543 list_to_add
= cu
->list_in_scope
;
11547 /* We do not know the address of this symbol.
11548 If it is an external symbol and we have type information
11549 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11550 The address of the variable will then be determined from
11551 the minimal symbol table whenever the variable is
11553 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11554 if (attr2
&& (DW_UNSND (attr2
) != 0)
11555 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11557 /* A variable with DW_AT_external is never static, but it
11558 may be block-scoped. */
11559 list_to_add
= (cu
->list_in_scope
== &file_symbols
11560 ? &global_symbols
: cu
->list_in_scope
);
11562 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11564 else if (!die_is_declaration (die
, cu
))
11566 /* Use the default LOC_OPTIMIZED_OUT class. */
11567 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11569 list_to_add
= cu
->list_in_scope
;
11573 case DW_TAG_formal_parameter
:
11574 /* If we are inside a function, mark this as an argument. If
11575 not, we might be looking at an argument to an inlined function
11576 when we do not have enough information to show inlined frames;
11577 pretend it's a local variable in that case so that the user can
11579 if (context_stack_depth
> 0
11580 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11581 SYMBOL_IS_ARGUMENT (sym
) = 1;
11582 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11585 var_decode_location (attr
, sym
, cu
);
11587 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11590 dwarf2_const_value (attr
, sym
, cu
);
11592 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
11593 if (attr
&& DW_UNSND (attr
))
11595 struct type
*ref_type
;
11597 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
11598 SYMBOL_TYPE (sym
) = ref_type
;
11601 list_to_add
= cu
->list_in_scope
;
11603 case DW_TAG_unspecified_parameters
:
11604 /* From varargs functions; gdb doesn't seem to have any
11605 interest in this information, so just ignore it for now.
11608 case DW_TAG_template_type_param
:
11610 /* Fall through. */
11611 case DW_TAG_class_type
:
11612 case DW_TAG_interface_type
:
11613 case DW_TAG_structure_type
:
11614 case DW_TAG_union_type
:
11615 case DW_TAG_set_type
:
11616 case DW_TAG_enumeration_type
:
11617 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11618 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11621 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11622 really ever be static objects: otherwise, if you try
11623 to, say, break of a class's method and you're in a file
11624 which doesn't mention that class, it won't work unless
11625 the check for all static symbols in lookup_symbol_aux
11626 saves you. See the OtherFileClass tests in
11627 gdb.c++/namespace.exp. */
11631 list_to_add
= (cu
->list_in_scope
== &file_symbols
11632 && (cu
->language
== language_cplus
11633 || cu
->language
== language_java
)
11634 ? &global_symbols
: cu
->list_in_scope
);
11636 /* The semantics of C++ state that "struct foo {
11637 ... }" also defines a typedef for "foo". A Java
11638 class declaration also defines a typedef for the
11640 if (cu
->language
== language_cplus
11641 || cu
->language
== language_java
11642 || cu
->language
== language_ada
)
11644 /* The symbol's name is already allocated along
11645 with this objfile, so we don't need to
11646 duplicate it for the type. */
11647 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11648 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11653 case DW_TAG_typedef
:
11654 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11655 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11656 list_to_add
= cu
->list_in_scope
;
11658 case DW_TAG_base_type
:
11659 case DW_TAG_subrange_type
:
11660 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11661 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11662 list_to_add
= cu
->list_in_scope
;
11664 case DW_TAG_enumerator
:
11665 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11668 dwarf2_const_value (attr
, sym
, cu
);
11671 /* NOTE: carlton/2003-11-10: See comment above in the
11672 DW_TAG_class_type, etc. block. */
11674 list_to_add
= (cu
->list_in_scope
== &file_symbols
11675 && (cu
->language
== language_cplus
11676 || cu
->language
== language_java
)
11677 ? &global_symbols
: cu
->list_in_scope
);
11680 case DW_TAG_namespace
:
11681 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11682 list_to_add
= &global_symbols
;
11685 /* Not a tag we recognize. Hopefully we aren't processing
11686 trash data, but since we must specifically ignore things
11687 we don't recognize, there is nothing else we should do at
11689 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11690 dwarf_tag_name (die
->tag
));
11696 sym
->hash_next
= objfile
->template_symbols
;
11697 objfile
->template_symbols
= sym
;
11698 list_to_add
= NULL
;
11701 if (list_to_add
!= NULL
)
11702 add_symbol_to_list (sym
, list_to_add
);
11704 /* For the benefit of old versions of GCC, check for anonymous
11705 namespaces based on the demangled name. */
11706 if (!processing_has_namespace_info
11707 && cu
->language
== language_cplus
)
11708 cp_scan_for_anonymous_namespaces (sym
);
11713 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11715 static struct symbol
*
11716 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11718 return new_symbol_full (die
, type
, cu
, NULL
);
11721 /* Given an attr with a DW_FORM_dataN value in host byte order,
11722 zero-extend it as appropriate for the symbol's type. The DWARF
11723 standard (v4) is not entirely clear about the meaning of using
11724 DW_FORM_dataN for a constant with a signed type, where the type is
11725 wider than the data. The conclusion of a discussion on the DWARF
11726 list was that this is unspecified. We choose to always zero-extend
11727 because that is the interpretation long in use by GCC. */
11730 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11731 const char *name
, struct obstack
*obstack
,
11732 struct dwarf2_cu
*cu
, long *value
, int bits
)
11734 struct objfile
*objfile
= cu
->objfile
;
11735 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11736 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11737 LONGEST l
= DW_UNSND (attr
);
11739 if (bits
< sizeof (*value
) * 8)
11741 l
&= ((LONGEST
) 1 << bits
) - 1;
11744 else if (bits
== sizeof (*value
) * 8)
11748 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11749 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11756 /* Read a constant value from an attribute. Either set *VALUE, or if
11757 the value does not fit in *VALUE, set *BYTES - either already
11758 allocated on the objfile obstack, or newly allocated on OBSTACK,
11759 or, set *BATON, if we translated the constant to a location
11763 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11764 const char *name
, struct obstack
*obstack
,
11765 struct dwarf2_cu
*cu
,
11766 long *value
, gdb_byte
**bytes
,
11767 struct dwarf2_locexpr_baton
**baton
)
11769 struct objfile
*objfile
= cu
->objfile
;
11770 struct comp_unit_head
*cu_header
= &cu
->header
;
11771 struct dwarf_block
*blk
;
11772 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
11773 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
11779 switch (attr
->form
)
11785 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
11786 dwarf2_const_value_length_mismatch_complaint (name
,
11787 cu_header
->addr_size
,
11788 TYPE_LENGTH (type
));
11789 /* Symbols of this form are reasonably rare, so we just
11790 piggyback on the existing location code rather than writing
11791 a new implementation of symbol_computed_ops. */
11792 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11793 sizeof (struct dwarf2_locexpr_baton
));
11794 (*baton
)->per_cu
= cu
->per_cu
;
11795 gdb_assert ((*baton
)->per_cu
);
11797 (*baton
)->size
= 2 + cu_header
->addr_size
;
11798 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11799 (*baton
)->data
= data
;
11801 data
[0] = DW_OP_addr
;
11802 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11803 byte_order
, DW_ADDR (attr
));
11804 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11807 case DW_FORM_string
:
11809 /* DW_STRING is already allocated on the objfile obstack, point
11811 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11813 case DW_FORM_block1
:
11814 case DW_FORM_block2
:
11815 case DW_FORM_block4
:
11816 case DW_FORM_block
:
11817 case DW_FORM_exprloc
:
11818 blk
= DW_BLOCK (attr
);
11819 if (TYPE_LENGTH (type
) != blk
->size
)
11820 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11821 TYPE_LENGTH (type
));
11822 *bytes
= blk
->data
;
11825 /* The DW_AT_const_value attributes are supposed to carry the
11826 symbol's value "represented as it would be on the target
11827 architecture." By the time we get here, it's already been
11828 converted to host endianness, so we just need to sign- or
11829 zero-extend it as appropriate. */
11830 case DW_FORM_data1
:
11831 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11832 obstack
, cu
, value
, 8);
11834 case DW_FORM_data2
:
11835 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11836 obstack
, cu
, value
, 16);
11838 case DW_FORM_data4
:
11839 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11840 obstack
, cu
, value
, 32);
11842 case DW_FORM_data8
:
11843 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11844 obstack
, cu
, value
, 64);
11847 case DW_FORM_sdata
:
11848 *value
= DW_SND (attr
);
11851 case DW_FORM_udata
:
11852 *value
= DW_UNSND (attr
);
11856 complaint (&symfile_complaints
,
11857 _("unsupported const value attribute form: '%s'"),
11858 dwarf_form_name (attr
->form
));
11865 /* Copy constant value from an attribute to a symbol. */
11868 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11869 struct dwarf2_cu
*cu
)
11871 struct objfile
*objfile
= cu
->objfile
;
11872 struct comp_unit_head
*cu_header
= &cu
->header
;
11875 struct dwarf2_locexpr_baton
*baton
;
11877 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11878 SYMBOL_PRINT_NAME (sym
),
11879 &objfile
->objfile_obstack
, cu
,
11880 &value
, &bytes
, &baton
);
11884 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11885 SYMBOL_LOCATION_BATON (sym
) = baton
;
11886 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11888 else if (bytes
!= NULL
)
11890 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11891 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11895 SYMBOL_VALUE (sym
) = value
;
11896 SYMBOL_CLASS (sym
) = LOC_CONST
;
11900 /* Return the type of the die in question using its DW_AT_type attribute. */
11902 static struct type
*
11903 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11905 struct attribute
*type_attr
;
11907 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11910 /* A missing DW_AT_type represents a void type. */
11911 return objfile_type (cu
->objfile
)->builtin_void
;
11914 return lookup_die_type (die
, type_attr
, cu
);
11917 /* True iff CU's producer generates GNAT Ada auxiliary information
11918 that allows to find parallel types through that information instead
11919 of having to do expensive parallel lookups by type name. */
11922 need_gnat_info (struct dwarf2_cu
*cu
)
11924 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11925 of GNAT produces this auxiliary information, without any indication
11926 that it is produced. Part of enhancing the FSF version of GNAT
11927 to produce that information will be to put in place an indicator
11928 that we can use in order to determine whether the descriptive type
11929 info is available or not. One suggestion that has been made is
11930 to use a new attribute, attached to the CU die. For now, assume
11931 that the descriptive type info is not available. */
11935 /* Return the auxiliary type of the die in question using its
11936 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11937 attribute is not present. */
11939 static struct type
*
11940 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11942 struct attribute
*type_attr
;
11944 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11948 return lookup_die_type (die
, type_attr
, cu
);
11951 /* If DIE has a descriptive_type attribute, then set the TYPE's
11952 descriptive type accordingly. */
11955 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11956 struct dwarf2_cu
*cu
)
11958 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11960 if (descriptive_type
)
11962 ALLOCATE_GNAT_AUX_TYPE (type
);
11963 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11967 /* Return the containing type of the die in question using its
11968 DW_AT_containing_type attribute. */
11970 static struct type
*
11971 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11973 struct attribute
*type_attr
;
11975 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11977 error (_("Dwarf Error: Problem turning containing type into gdb type "
11978 "[in module %s]"), cu
->objfile
->name
);
11980 return lookup_die_type (die
, type_attr
, cu
);
11983 /* Look up the type of DIE in CU using its type attribute ATTR.
11984 If there is no type substitute an error marker. */
11986 static struct type
*
11987 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11988 struct dwarf2_cu
*cu
)
11990 struct type
*this_type
;
11992 /* First see if we have it cached. */
11994 if (is_ref_attr (attr
))
11996 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11998 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
12000 else if (attr
->form
== DW_FORM_ref_sig8
)
12002 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12003 struct dwarf2_cu
*sig_cu
;
12004 unsigned int offset
;
12006 /* sig_type will be NULL if the signatured type is missing from
12008 if (sig_type
== NULL
)
12009 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12010 "at 0x%x [in module %s]"),
12011 die
->offset
, cu
->objfile
->name
);
12013 gdb_assert (sig_type
->per_cu
.debug_type_section
);
12014 offset
= sig_type
->per_cu
.offset
+ sig_type
->type_offset
;
12015 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
12019 dump_die_for_error (die
);
12020 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12021 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
12024 /* If not cached we need to read it in. */
12026 if (this_type
== NULL
)
12028 struct die_info
*type_die
;
12029 struct dwarf2_cu
*type_cu
= cu
;
12031 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
12032 /* If the type is cached, we should have found it above. */
12033 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
12034 this_type
= read_type_die_1 (type_die
, type_cu
);
12037 /* If we still don't have a type use an error marker. */
12039 if (this_type
== NULL
)
12041 char *message
, *saved
;
12043 /* read_type_die already issued a complaint. */
12044 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12048 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
12049 message
, strlen (message
));
12052 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
12058 /* Return the type in DIE, CU.
12059 Returns NULL for invalid types.
12061 This first does a lookup in the appropriate type_hash table,
12062 and only reads the die in if necessary.
12064 NOTE: This can be called when reading in partial or full symbols. */
12066 static struct type
*
12067 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12069 struct type
*this_type
;
12071 this_type
= get_die_type (die
, cu
);
12075 return read_type_die_1 (die
, cu
);
12078 /* Read the type in DIE, CU.
12079 Returns NULL for invalid types. */
12081 static struct type
*
12082 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12084 struct type
*this_type
= NULL
;
12088 case DW_TAG_class_type
:
12089 case DW_TAG_interface_type
:
12090 case DW_TAG_structure_type
:
12091 case DW_TAG_union_type
:
12092 this_type
= read_structure_type (die
, cu
);
12094 case DW_TAG_enumeration_type
:
12095 this_type
= read_enumeration_type (die
, cu
);
12097 case DW_TAG_subprogram
:
12098 case DW_TAG_subroutine_type
:
12099 case DW_TAG_inlined_subroutine
:
12100 this_type
= read_subroutine_type (die
, cu
);
12102 case DW_TAG_array_type
:
12103 this_type
= read_array_type (die
, cu
);
12105 case DW_TAG_set_type
:
12106 this_type
= read_set_type (die
, cu
);
12108 case DW_TAG_pointer_type
:
12109 this_type
= read_tag_pointer_type (die
, cu
);
12111 case DW_TAG_ptr_to_member_type
:
12112 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12114 case DW_TAG_reference_type
:
12115 this_type
= read_tag_reference_type (die
, cu
);
12117 case DW_TAG_const_type
:
12118 this_type
= read_tag_const_type (die
, cu
);
12120 case DW_TAG_volatile_type
:
12121 this_type
= read_tag_volatile_type (die
, cu
);
12123 case DW_TAG_string_type
:
12124 this_type
= read_tag_string_type (die
, cu
);
12126 case DW_TAG_typedef
:
12127 this_type
= read_typedef (die
, cu
);
12129 case DW_TAG_subrange_type
:
12130 this_type
= read_subrange_type (die
, cu
);
12132 case DW_TAG_base_type
:
12133 this_type
= read_base_type (die
, cu
);
12135 case DW_TAG_unspecified_type
:
12136 this_type
= read_unspecified_type (die
, cu
);
12138 case DW_TAG_namespace
:
12139 this_type
= read_namespace_type (die
, cu
);
12141 case DW_TAG_module
:
12142 this_type
= read_module_type (die
, cu
);
12145 complaint (&symfile_complaints
,
12146 _("unexpected tag in read_type_die: '%s'"),
12147 dwarf_tag_name (die
->tag
));
12154 /* See if we can figure out if the class lives in a namespace. We do
12155 this by looking for a member function; its demangled name will
12156 contain namespace info, if there is any.
12157 Return the computed name or NULL.
12158 Space for the result is allocated on the objfile's obstack.
12159 This is the full-die version of guess_partial_die_structure_name.
12160 In this case we know DIE has no useful parent. */
12163 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12165 struct die_info
*spec_die
;
12166 struct dwarf2_cu
*spec_cu
;
12167 struct die_info
*child
;
12170 spec_die
= die_specification (die
, &spec_cu
);
12171 if (spec_die
!= NULL
)
12177 for (child
= die
->child
;
12179 child
= child
->sibling
)
12181 if (child
->tag
== DW_TAG_subprogram
)
12183 struct attribute
*attr
;
12185 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12187 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12191 = language_class_name_from_physname (cu
->language_defn
,
12195 if (actual_name
!= NULL
)
12197 char *die_name
= dwarf2_name (die
, cu
);
12199 if (die_name
!= NULL
12200 && strcmp (die_name
, actual_name
) != 0)
12202 /* Strip off the class name from the full name.
12203 We want the prefix. */
12204 int die_name_len
= strlen (die_name
);
12205 int actual_name_len
= strlen (actual_name
);
12207 /* Test for '::' as a sanity check. */
12208 if (actual_name_len
> die_name_len
+ 2
12209 && actual_name
[actual_name_len
12210 - die_name_len
- 1] == ':')
12212 obsavestring (actual_name
,
12213 actual_name_len
- die_name_len
- 2,
12214 &cu
->objfile
->objfile_obstack
);
12217 xfree (actual_name
);
12226 /* Return the name of the namespace/class that DIE is defined within,
12227 or "" if we can't tell. The caller should not xfree the result.
12229 For example, if we're within the method foo() in the following
12239 then determine_prefix on foo's die will return "N::C". */
12242 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12244 struct die_info
*parent
, *spec_die
;
12245 struct dwarf2_cu
*spec_cu
;
12246 struct type
*parent_type
;
12248 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12249 && cu
->language
!= language_fortran
)
12252 /* We have to be careful in the presence of DW_AT_specification.
12253 For example, with GCC 3.4, given the code
12257 // Definition of N::foo.
12261 then we'll have a tree of DIEs like this:
12263 1: DW_TAG_compile_unit
12264 2: DW_TAG_namespace // N
12265 3: DW_TAG_subprogram // declaration of N::foo
12266 4: DW_TAG_subprogram // definition of N::foo
12267 DW_AT_specification // refers to die #3
12269 Thus, when processing die #4, we have to pretend that we're in
12270 the context of its DW_AT_specification, namely the contex of die
12273 spec_die
= die_specification (die
, &spec_cu
);
12274 if (spec_die
== NULL
)
12275 parent
= die
->parent
;
12278 parent
= spec_die
->parent
;
12282 if (parent
== NULL
)
12284 else if (parent
->building_fullname
)
12287 const char *parent_name
;
12289 /* It has been seen on RealView 2.2 built binaries,
12290 DW_TAG_template_type_param types actually _defined_ as
12291 children of the parent class:
12294 template class <class Enum> Class{};
12295 Class<enum E> class_e;
12297 1: DW_TAG_class_type (Class)
12298 2: DW_TAG_enumeration_type (E)
12299 3: DW_TAG_enumerator (enum1:0)
12300 3: DW_TAG_enumerator (enum2:1)
12302 2: DW_TAG_template_type_param
12303 DW_AT_type DW_FORM_ref_udata (E)
12305 Besides being broken debug info, it can put GDB into an
12306 infinite loop. Consider:
12308 When we're building the full name for Class<E>, we'll start
12309 at Class, and go look over its template type parameters,
12310 finding E. We'll then try to build the full name of E, and
12311 reach here. We're now trying to build the full name of E,
12312 and look over the parent DIE for containing scope. In the
12313 broken case, if we followed the parent DIE of E, we'd again
12314 find Class, and once again go look at its template type
12315 arguments, etc., etc. Simply don't consider such parent die
12316 as source-level parent of this die (it can't be, the language
12317 doesn't allow it), and break the loop here. */
12318 name
= dwarf2_name (die
, cu
);
12319 parent_name
= dwarf2_name (parent
, cu
);
12320 complaint (&symfile_complaints
,
12321 _("template param type '%s' defined within parent '%s'"),
12322 name
? name
: "<unknown>",
12323 parent_name
? parent_name
: "<unknown>");
12327 switch (parent
->tag
)
12329 case DW_TAG_namespace
:
12330 parent_type
= read_type_die (parent
, cu
);
12331 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12332 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12333 Work around this problem here. */
12334 if (cu
->language
== language_cplus
12335 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12337 /* We give a name to even anonymous namespaces. */
12338 return TYPE_TAG_NAME (parent_type
);
12339 case DW_TAG_class_type
:
12340 case DW_TAG_interface_type
:
12341 case DW_TAG_structure_type
:
12342 case DW_TAG_union_type
:
12343 case DW_TAG_module
:
12344 parent_type
= read_type_die (parent
, cu
);
12345 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12346 return TYPE_TAG_NAME (parent_type
);
12348 /* An anonymous structure is only allowed non-static data
12349 members; no typedefs, no member functions, et cetera.
12350 So it does not need a prefix. */
12352 case DW_TAG_compile_unit
:
12353 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12354 if (cu
->language
== language_cplus
12355 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12356 && die
->child
!= NULL
12357 && (die
->tag
== DW_TAG_class_type
12358 || die
->tag
== DW_TAG_structure_type
12359 || die
->tag
== DW_TAG_union_type
))
12361 char *name
= guess_full_die_structure_name (die
, cu
);
12367 return determine_prefix (parent
, cu
);
12371 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12372 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12373 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12374 an obconcat, otherwise allocate storage for the result. The CU argument is
12375 used to determine the language and hence, the appropriate separator. */
12377 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12380 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12381 int physname
, struct dwarf2_cu
*cu
)
12383 const char *lead
= "";
12386 if (suffix
== NULL
|| suffix
[0] == '\0'
12387 || prefix
== NULL
|| prefix
[0] == '\0')
12389 else if (cu
->language
== language_java
)
12391 else if (cu
->language
== language_fortran
&& physname
)
12393 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12394 DW_AT_MIPS_linkage_name is preferred and used instead. */
12402 if (prefix
== NULL
)
12404 if (suffix
== NULL
)
12410 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12412 strcpy (retval
, lead
);
12413 strcat (retval
, prefix
);
12414 strcat (retval
, sep
);
12415 strcat (retval
, suffix
);
12420 /* We have an obstack. */
12421 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12425 /* Return sibling of die, NULL if no sibling. */
12427 static struct die_info
*
12428 sibling_die (struct die_info
*die
)
12430 return die
->sibling
;
12433 /* Get name of a die, return NULL if not found. */
12436 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12437 struct obstack
*obstack
)
12439 if (name
&& cu
->language
== language_cplus
)
12441 char *canon_name
= cp_canonicalize_string (name
);
12443 if (canon_name
!= NULL
)
12445 if (strcmp (canon_name
, name
) != 0)
12446 name
= obsavestring (canon_name
, strlen (canon_name
),
12448 xfree (canon_name
);
12455 /* Get name of a die, return NULL if not found. */
12458 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12460 struct attribute
*attr
;
12462 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12463 if ((!attr
|| !DW_STRING (attr
))
12464 && die
->tag
!= DW_TAG_class_type
12465 && die
->tag
!= DW_TAG_interface_type
12466 && die
->tag
!= DW_TAG_structure_type
12467 && die
->tag
!= DW_TAG_union_type
)
12472 case DW_TAG_compile_unit
:
12473 /* Compilation units have a DW_AT_name that is a filename, not
12474 a source language identifier. */
12475 case DW_TAG_enumeration_type
:
12476 case DW_TAG_enumerator
:
12477 /* These tags always have simple identifiers already; no need
12478 to canonicalize them. */
12479 return DW_STRING (attr
);
12481 case DW_TAG_subprogram
:
12482 /* Java constructors will all be named "<init>", so return
12483 the class name when we see this special case. */
12484 if (cu
->language
== language_java
12485 && DW_STRING (attr
) != NULL
12486 && strcmp (DW_STRING (attr
), "<init>") == 0)
12488 struct dwarf2_cu
*spec_cu
= cu
;
12489 struct die_info
*spec_die
;
12491 /* GCJ will output '<init>' for Java constructor names.
12492 For this special case, return the name of the parent class. */
12494 /* GCJ may output suprogram DIEs with AT_specification set.
12495 If so, use the name of the specified DIE. */
12496 spec_die
= die_specification (die
, &spec_cu
);
12497 if (spec_die
!= NULL
)
12498 return dwarf2_name (spec_die
, spec_cu
);
12503 if (die
->tag
== DW_TAG_class_type
)
12504 return dwarf2_name (die
, cu
);
12506 while (die
->tag
!= DW_TAG_compile_unit
);
12510 case DW_TAG_class_type
:
12511 case DW_TAG_interface_type
:
12512 case DW_TAG_structure_type
:
12513 case DW_TAG_union_type
:
12514 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12515 structures or unions. These were of the form "._%d" in GCC 4.1,
12516 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12517 and GCC 4.4. We work around this problem by ignoring these. */
12518 if (attr
&& DW_STRING (attr
)
12519 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12520 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12523 /* GCC might emit a nameless typedef that has a linkage name. See
12524 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12525 if (!attr
|| DW_STRING (attr
) == NULL
)
12527 char *demangled
= NULL
;
12529 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12531 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12533 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12536 /* Avoid demangling DW_STRING (attr) the second time on a second
12537 call for the same DIE. */
12538 if (!DW_STRING_IS_CANONICAL (attr
))
12539 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12543 /* FIXME: we already did this for the partial symbol... */
12545 = obsavestring (demangled
, strlen (demangled
),
12546 &cu
->objfile
->objfile_obstack
);
12547 DW_STRING_IS_CANONICAL (attr
) = 1;
12557 if (!DW_STRING_IS_CANONICAL (attr
))
12560 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12561 &cu
->objfile
->objfile_obstack
);
12562 DW_STRING_IS_CANONICAL (attr
) = 1;
12564 return DW_STRING (attr
);
12567 /* Return the die that this die in an extension of, or NULL if there
12568 is none. *EXT_CU is the CU containing DIE on input, and the CU
12569 containing the return value on output. */
12571 static struct die_info
*
12572 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12574 struct attribute
*attr
;
12576 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12580 return follow_die_ref (die
, attr
, ext_cu
);
12583 /* Convert a DIE tag into its string name. */
12586 dwarf_tag_name (unsigned tag
)
12590 case DW_TAG_padding
:
12591 return "DW_TAG_padding";
12592 case DW_TAG_array_type
:
12593 return "DW_TAG_array_type";
12594 case DW_TAG_class_type
:
12595 return "DW_TAG_class_type";
12596 case DW_TAG_entry_point
:
12597 return "DW_TAG_entry_point";
12598 case DW_TAG_enumeration_type
:
12599 return "DW_TAG_enumeration_type";
12600 case DW_TAG_formal_parameter
:
12601 return "DW_TAG_formal_parameter";
12602 case DW_TAG_imported_declaration
:
12603 return "DW_TAG_imported_declaration";
12605 return "DW_TAG_label";
12606 case DW_TAG_lexical_block
:
12607 return "DW_TAG_lexical_block";
12608 case DW_TAG_member
:
12609 return "DW_TAG_member";
12610 case DW_TAG_pointer_type
:
12611 return "DW_TAG_pointer_type";
12612 case DW_TAG_reference_type
:
12613 return "DW_TAG_reference_type";
12614 case DW_TAG_compile_unit
:
12615 return "DW_TAG_compile_unit";
12616 case DW_TAG_string_type
:
12617 return "DW_TAG_string_type";
12618 case DW_TAG_structure_type
:
12619 return "DW_TAG_structure_type";
12620 case DW_TAG_subroutine_type
:
12621 return "DW_TAG_subroutine_type";
12622 case DW_TAG_typedef
:
12623 return "DW_TAG_typedef";
12624 case DW_TAG_union_type
:
12625 return "DW_TAG_union_type";
12626 case DW_TAG_unspecified_parameters
:
12627 return "DW_TAG_unspecified_parameters";
12628 case DW_TAG_variant
:
12629 return "DW_TAG_variant";
12630 case DW_TAG_common_block
:
12631 return "DW_TAG_common_block";
12632 case DW_TAG_common_inclusion
:
12633 return "DW_TAG_common_inclusion";
12634 case DW_TAG_inheritance
:
12635 return "DW_TAG_inheritance";
12636 case DW_TAG_inlined_subroutine
:
12637 return "DW_TAG_inlined_subroutine";
12638 case DW_TAG_module
:
12639 return "DW_TAG_module";
12640 case DW_TAG_ptr_to_member_type
:
12641 return "DW_TAG_ptr_to_member_type";
12642 case DW_TAG_set_type
:
12643 return "DW_TAG_set_type";
12644 case DW_TAG_subrange_type
:
12645 return "DW_TAG_subrange_type";
12646 case DW_TAG_with_stmt
:
12647 return "DW_TAG_with_stmt";
12648 case DW_TAG_access_declaration
:
12649 return "DW_TAG_access_declaration";
12650 case DW_TAG_base_type
:
12651 return "DW_TAG_base_type";
12652 case DW_TAG_catch_block
:
12653 return "DW_TAG_catch_block";
12654 case DW_TAG_const_type
:
12655 return "DW_TAG_const_type";
12656 case DW_TAG_constant
:
12657 return "DW_TAG_constant";
12658 case DW_TAG_enumerator
:
12659 return "DW_TAG_enumerator";
12660 case DW_TAG_file_type
:
12661 return "DW_TAG_file_type";
12662 case DW_TAG_friend
:
12663 return "DW_TAG_friend";
12664 case DW_TAG_namelist
:
12665 return "DW_TAG_namelist";
12666 case DW_TAG_namelist_item
:
12667 return "DW_TAG_namelist_item";
12668 case DW_TAG_packed_type
:
12669 return "DW_TAG_packed_type";
12670 case DW_TAG_subprogram
:
12671 return "DW_TAG_subprogram";
12672 case DW_TAG_template_type_param
:
12673 return "DW_TAG_template_type_param";
12674 case DW_TAG_template_value_param
:
12675 return "DW_TAG_template_value_param";
12676 case DW_TAG_thrown_type
:
12677 return "DW_TAG_thrown_type";
12678 case DW_TAG_try_block
:
12679 return "DW_TAG_try_block";
12680 case DW_TAG_variant_part
:
12681 return "DW_TAG_variant_part";
12682 case DW_TAG_variable
:
12683 return "DW_TAG_variable";
12684 case DW_TAG_volatile_type
:
12685 return "DW_TAG_volatile_type";
12686 case DW_TAG_dwarf_procedure
:
12687 return "DW_TAG_dwarf_procedure";
12688 case DW_TAG_restrict_type
:
12689 return "DW_TAG_restrict_type";
12690 case DW_TAG_interface_type
:
12691 return "DW_TAG_interface_type";
12692 case DW_TAG_namespace
:
12693 return "DW_TAG_namespace";
12694 case DW_TAG_imported_module
:
12695 return "DW_TAG_imported_module";
12696 case DW_TAG_unspecified_type
:
12697 return "DW_TAG_unspecified_type";
12698 case DW_TAG_partial_unit
:
12699 return "DW_TAG_partial_unit";
12700 case DW_TAG_imported_unit
:
12701 return "DW_TAG_imported_unit";
12702 case DW_TAG_condition
:
12703 return "DW_TAG_condition";
12704 case DW_TAG_shared_type
:
12705 return "DW_TAG_shared_type";
12706 case DW_TAG_type_unit
:
12707 return "DW_TAG_type_unit";
12708 case DW_TAG_MIPS_loop
:
12709 return "DW_TAG_MIPS_loop";
12710 case DW_TAG_HP_array_descriptor
:
12711 return "DW_TAG_HP_array_descriptor";
12712 case DW_TAG_format_label
:
12713 return "DW_TAG_format_label";
12714 case DW_TAG_function_template
:
12715 return "DW_TAG_function_template";
12716 case DW_TAG_class_template
:
12717 return "DW_TAG_class_template";
12718 case DW_TAG_GNU_BINCL
:
12719 return "DW_TAG_GNU_BINCL";
12720 case DW_TAG_GNU_EINCL
:
12721 return "DW_TAG_GNU_EINCL";
12722 case DW_TAG_upc_shared_type
:
12723 return "DW_TAG_upc_shared_type";
12724 case DW_TAG_upc_strict_type
:
12725 return "DW_TAG_upc_strict_type";
12726 case DW_TAG_upc_relaxed_type
:
12727 return "DW_TAG_upc_relaxed_type";
12728 case DW_TAG_PGI_kanji_type
:
12729 return "DW_TAG_PGI_kanji_type";
12730 case DW_TAG_PGI_interface_block
:
12731 return "DW_TAG_PGI_interface_block";
12733 return "DW_TAG_<unknown>";
12737 /* Convert a DWARF attribute code into its string name. */
12740 dwarf_attr_name (unsigned attr
)
12744 case DW_AT_sibling
:
12745 return "DW_AT_sibling";
12746 case DW_AT_location
:
12747 return "DW_AT_location";
12749 return "DW_AT_name";
12750 case DW_AT_ordering
:
12751 return "DW_AT_ordering";
12752 case DW_AT_subscr_data
:
12753 return "DW_AT_subscr_data";
12754 case DW_AT_byte_size
:
12755 return "DW_AT_byte_size";
12756 case DW_AT_bit_offset
:
12757 return "DW_AT_bit_offset";
12758 case DW_AT_bit_size
:
12759 return "DW_AT_bit_size";
12760 case DW_AT_element_list
:
12761 return "DW_AT_element_list";
12762 case DW_AT_stmt_list
:
12763 return "DW_AT_stmt_list";
12765 return "DW_AT_low_pc";
12766 case DW_AT_high_pc
:
12767 return "DW_AT_high_pc";
12768 case DW_AT_language
:
12769 return "DW_AT_language";
12771 return "DW_AT_member";
12773 return "DW_AT_discr";
12774 case DW_AT_discr_value
:
12775 return "DW_AT_discr_value";
12776 case DW_AT_visibility
:
12777 return "DW_AT_visibility";
12779 return "DW_AT_import";
12780 case DW_AT_string_length
:
12781 return "DW_AT_string_length";
12782 case DW_AT_common_reference
:
12783 return "DW_AT_common_reference";
12784 case DW_AT_comp_dir
:
12785 return "DW_AT_comp_dir";
12786 case DW_AT_const_value
:
12787 return "DW_AT_const_value";
12788 case DW_AT_containing_type
:
12789 return "DW_AT_containing_type";
12790 case DW_AT_default_value
:
12791 return "DW_AT_default_value";
12793 return "DW_AT_inline";
12794 case DW_AT_is_optional
:
12795 return "DW_AT_is_optional";
12796 case DW_AT_lower_bound
:
12797 return "DW_AT_lower_bound";
12798 case DW_AT_producer
:
12799 return "DW_AT_producer";
12800 case DW_AT_prototyped
:
12801 return "DW_AT_prototyped";
12802 case DW_AT_return_addr
:
12803 return "DW_AT_return_addr";
12804 case DW_AT_start_scope
:
12805 return "DW_AT_start_scope";
12806 case DW_AT_bit_stride
:
12807 return "DW_AT_bit_stride";
12808 case DW_AT_upper_bound
:
12809 return "DW_AT_upper_bound";
12810 case DW_AT_abstract_origin
:
12811 return "DW_AT_abstract_origin";
12812 case DW_AT_accessibility
:
12813 return "DW_AT_accessibility";
12814 case DW_AT_address_class
:
12815 return "DW_AT_address_class";
12816 case DW_AT_artificial
:
12817 return "DW_AT_artificial";
12818 case DW_AT_base_types
:
12819 return "DW_AT_base_types";
12820 case DW_AT_calling_convention
:
12821 return "DW_AT_calling_convention";
12823 return "DW_AT_count";
12824 case DW_AT_data_member_location
:
12825 return "DW_AT_data_member_location";
12826 case DW_AT_decl_column
:
12827 return "DW_AT_decl_column";
12828 case DW_AT_decl_file
:
12829 return "DW_AT_decl_file";
12830 case DW_AT_decl_line
:
12831 return "DW_AT_decl_line";
12832 case DW_AT_declaration
:
12833 return "DW_AT_declaration";
12834 case DW_AT_discr_list
:
12835 return "DW_AT_discr_list";
12836 case DW_AT_encoding
:
12837 return "DW_AT_encoding";
12838 case DW_AT_external
:
12839 return "DW_AT_external";
12840 case DW_AT_frame_base
:
12841 return "DW_AT_frame_base";
12843 return "DW_AT_friend";
12844 case DW_AT_identifier_case
:
12845 return "DW_AT_identifier_case";
12846 case DW_AT_macro_info
:
12847 return "DW_AT_macro_info";
12848 case DW_AT_namelist_items
:
12849 return "DW_AT_namelist_items";
12850 case DW_AT_priority
:
12851 return "DW_AT_priority";
12852 case DW_AT_segment
:
12853 return "DW_AT_segment";
12854 case DW_AT_specification
:
12855 return "DW_AT_specification";
12856 case DW_AT_static_link
:
12857 return "DW_AT_static_link";
12859 return "DW_AT_type";
12860 case DW_AT_use_location
:
12861 return "DW_AT_use_location";
12862 case DW_AT_variable_parameter
:
12863 return "DW_AT_variable_parameter";
12864 case DW_AT_virtuality
:
12865 return "DW_AT_virtuality";
12866 case DW_AT_vtable_elem_location
:
12867 return "DW_AT_vtable_elem_location";
12868 /* DWARF 3 values. */
12869 case DW_AT_allocated
:
12870 return "DW_AT_allocated";
12871 case DW_AT_associated
:
12872 return "DW_AT_associated";
12873 case DW_AT_data_location
:
12874 return "DW_AT_data_location";
12875 case DW_AT_byte_stride
:
12876 return "DW_AT_byte_stride";
12877 case DW_AT_entry_pc
:
12878 return "DW_AT_entry_pc";
12879 case DW_AT_use_UTF8
:
12880 return "DW_AT_use_UTF8";
12881 case DW_AT_extension
:
12882 return "DW_AT_extension";
12884 return "DW_AT_ranges";
12885 case DW_AT_trampoline
:
12886 return "DW_AT_trampoline";
12887 case DW_AT_call_column
:
12888 return "DW_AT_call_column";
12889 case DW_AT_call_file
:
12890 return "DW_AT_call_file";
12891 case DW_AT_call_line
:
12892 return "DW_AT_call_line";
12893 case DW_AT_description
:
12894 return "DW_AT_description";
12895 case DW_AT_binary_scale
:
12896 return "DW_AT_binary_scale";
12897 case DW_AT_decimal_scale
:
12898 return "DW_AT_decimal_scale";
12900 return "DW_AT_small";
12901 case DW_AT_decimal_sign
:
12902 return "DW_AT_decimal_sign";
12903 case DW_AT_digit_count
:
12904 return "DW_AT_digit_count";
12905 case DW_AT_picture_string
:
12906 return "DW_AT_picture_string";
12907 case DW_AT_mutable
:
12908 return "DW_AT_mutable";
12909 case DW_AT_threads_scaled
:
12910 return "DW_AT_threads_scaled";
12911 case DW_AT_explicit
:
12912 return "DW_AT_explicit";
12913 case DW_AT_object_pointer
:
12914 return "DW_AT_object_pointer";
12915 case DW_AT_endianity
:
12916 return "DW_AT_endianity";
12917 case DW_AT_elemental
:
12918 return "DW_AT_elemental";
12920 return "DW_AT_pure";
12921 case DW_AT_recursive
:
12922 return "DW_AT_recursive";
12923 /* DWARF 4 values. */
12924 case DW_AT_signature
:
12925 return "DW_AT_signature";
12926 case DW_AT_linkage_name
:
12927 return "DW_AT_linkage_name";
12928 /* SGI/MIPS extensions. */
12929 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12930 case DW_AT_MIPS_fde
:
12931 return "DW_AT_MIPS_fde";
12933 case DW_AT_MIPS_loop_begin
:
12934 return "DW_AT_MIPS_loop_begin";
12935 case DW_AT_MIPS_tail_loop_begin
:
12936 return "DW_AT_MIPS_tail_loop_begin";
12937 case DW_AT_MIPS_epilog_begin
:
12938 return "DW_AT_MIPS_epilog_begin";
12939 case DW_AT_MIPS_loop_unroll_factor
:
12940 return "DW_AT_MIPS_loop_unroll_factor";
12941 case DW_AT_MIPS_software_pipeline_depth
:
12942 return "DW_AT_MIPS_software_pipeline_depth";
12943 case DW_AT_MIPS_linkage_name
:
12944 return "DW_AT_MIPS_linkage_name";
12945 case DW_AT_MIPS_stride
:
12946 return "DW_AT_MIPS_stride";
12947 case DW_AT_MIPS_abstract_name
:
12948 return "DW_AT_MIPS_abstract_name";
12949 case DW_AT_MIPS_clone_origin
:
12950 return "DW_AT_MIPS_clone_origin";
12951 case DW_AT_MIPS_has_inlines
:
12952 return "DW_AT_MIPS_has_inlines";
12953 /* HP extensions. */
12954 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12955 case DW_AT_HP_block_index
:
12956 return "DW_AT_HP_block_index";
12958 case DW_AT_HP_unmodifiable
:
12959 return "DW_AT_HP_unmodifiable";
12960 case DW_AT_HP_actuals_stmt_list
:
12961 return "DW_AT_HP_actuals_stmt_list";
12962 case DW_AT_HP_proc_per_section
:
12963 return "DW_AT_HP_proc_per_section";
12964 case DW_AT_HP_raw_data_ptr
:
12965 return "DW_AT_HP_raw_data_ptr";
12966 case DW_AT_HP_pass_by_reference
:
12967 return "DW_AT_HP_pass_by_reference";
12968 case DW_AT_HP_opt_level
:
12969 return "DW_AT_HP_opt_level";
12970 case DW_AT_HP_prof_version_id
:
12971 return "DW_AT_HP_prof_version_id";
12972 case DW_AT_HP_opt_flags
:
12973 return "DW_AT_HP_opt_flags";
12974 case DW_AT_HP_cold_region_low_pc
:
12975 return "DW_AT_HP_cold_region_low_pc";
12976 case DW_AT_HP_cold_region_high_pc
:
12977 return "DW_AT_HP_cold_region_high_pc";
12978 case DW_AT_HP_all_variables_modifiable
:
12979 return "DW_AT_HP_all_variables_modifiable";
12980 case DW_AT_HP_linkage_name
:
12981 return "DW_AT_HP_linkage_name";
12982 case DW_AT_HP_prof_flags
:
12983 return "DW_AT_HP_prof_flags";
12984 /* GNU extensions. */
12985 case DW_AT_sf_names
:
12986 return "DW_AT_sf_names";
12987 case DW_AT_src_info
:
12988 return "DW_AT_src_info";
12989 case DW_AT_mac_info
:
12990 return "DW_AT_mac_info";
12991 case DW_AT_src_coords
:
12992 return "DW_AT_src_coords";
12993 case DW_AT_body_begin
:
12994 return "DW_AT_body_begin";
12995 case DW_AT_body_end
:
12996 return "DW_AT_body_end";
12997 case DW_AT_GNU_vector
:
12998 return "DW_AT_GNU_vector";
12999 case DW_AT_GNU_odr_signature
:
13000 return "DW_AT_GNU_odr_signature";
13001 /* VMS extensions. */
13002 case DW_AT_VMS_rtnbeg_pd_address
:
13003 return "DW_AT_VMS_rtnbeg_pd_address";
13004 /* UPC extension. */
13005 case DW_AT_upc_threads_scaled
:
13006 return "DW_AT_upc_threads_scaled";
13007 /* PGI (STMicroelectronics) extensions. */
13008 case DW_AT_PGI_lbase
:
13009 return "DW_AT_PGI_lbase";
13010 case DW_AT_PGI_soffset
:
13011 return "DW_AT_PGI_soffset";
13012 case DW_AT_PGI_lstride
:
13013 return "DW_AT_PGI_lstride";
13015 return "DW_AT_<unknown>";
13019 /* Convert a DWARF value form code into its string name. */
13022 dwarf_form_name (unsigned form
)
13027 return "DW_FORM_addr";
13028 case DW_FORM_block2
:
13029 return "DW_FORM_block2";
13030 case DW_FORM_block4
:
13031 return "DW_FORM_block4";
13032 case DW_FORM_data2
:
13033 return "DW_FORM_data2";
13034 case DW_FORM_data4
:
13035 return "DW_FORM_data4";
13036 case DW_FORM_data8
:
13037 return "DW_FORM_data8";
13038 case DW_FORM_string
:
13039 return "DW_FORM_string";
13040 case DW_FORM_block
:
13041 return "DW_FORM_block";
13042 case DW_FORM_block1
:
13043 return "DW_FORM_block1";
13044 case DW_FORM_data1
:
13045 return "DW_FORM_data1";
13047 return "DW_FORM_flag";
13048 case DW_FORM_sdata
:
13049 return "DW_FORM_sdata";
13051 return "DW_FORM_strp";
13052 case DW_FORM_udata
:
13053 return "DW_FORM_udata";
13054 case DW_FORM_ref_addr
:
13055 return "DW_FORM_ref_addr";
13057 return "DW_FORM_ref1";
13059 return "DW_FORM_ref2";
13061 return "DW_FORM_ref4";
13063 return "DW_FORM_ref8";
13064 case DW_FORM_ref_udata
:
13065 return "DW_FORM_ref_udata";
13066 case DW_FORM_indirect
:
13067 return "DW_FORM_indirect";
13068 case DW_FORM_sec_offset
:
13069 return "DW_FORM_sec_offset";
13070 case DW_FORM_exprloc
:
13071 return "DW_FORM_exprloc";
13072 case DW_FORM_flag_present
:
13073 return "DW_FORM_flag_present";
13074 case DW_FORM_ref_sig8
:
13075 return "DW_FORM_ref_sig8";
13077 return "DW_FORM_<unknown>";
13081 /* Convert a DWARF stack opcode into its string name. */
13084 dwarf_stack_op_name (unsigned op
)
13089 return "DW_OP_addr";
13091 return "DW_OP_deref";
13092 case DW_OP_const1u
:
13093 return "DW_OP_const1u";
13094 case DW_OP_const1s
:
13095 return "DW_OP_const1s";
13096 case DW_OP_const2u
:
13097 return "DW_OP_const2u";
13098 case DW_OP_const2s
:
13099 return "DW_OP_const2s";
13100 case DW_OP_const4u
:
13101 return "DW_OP_const4u";
13102 case DW_OP_const4s
:
13103 return "DW_OP_const4s";
13104 case DW_OP_const8u
:
13105 return "DW_OP_const8u";
13106 case DW_OP_const8s
:
13107 return "DW_OP_const8s";
13109 return "DW_OP_constu";
13111 return "DW_OP_consts";
13113 return "DW_OP_dup";
13115 return "DW_OP_drop";
13117 return "DW_OP_over";
13119 return "DW_OP_pick";
13121 return "DW_OP_swap";
13123 return "DW_OP_rot";
13125 return "DW_OP_xderef";
13127 return "DW_OP_abs";
13129 return "DW_OP_and";
13131 return "DW_OP_div";
13133 return "DW_OP_minus";
13135 return "DW_OP_mod";
13137 return "DW_OP_mul";
13139 return "DW_OP_neg";
13141 return "DW_OP_not";
13145 return "DW_OP_plus";
13146 case DW_OP_plus_uconst
:
13147 return "DW_OP_plus_uconst";
13149 return "DW_OP_shl";
13151 return "DW_OP_shr";
13153 return "DW_OP_shra";
13155 return "DW_OP_xor";
13157 return "DW_OP_bra";
13171 return "DW_OP_skip";
13173 return "DW_OP_lit0";
13175 return "DW_OP_lit1";
13177 return "DW_OP_lit2";
13179 return "DW_OP_lit3";
13181 return "DW_OP_lit4";
13183 return "DW_OP_lit5";
13185 return "DW_OP_lit6";
13187 return "DW_OP_lit7";
13189 return "DW_OP_lit8";
13191 return "DW_OP_lit9";
13193 return "DW_OP_lit10";
13195 return "DW_OP_lit11";
13197 return "DW_OP_lit12";
13199 return "DW_OP_lit13";
13201 return "DW_OP_lit14";
13203 return "DW_OP_lit15";
13205 return "DW_OP_lit16";
13207 return "DW_OP_lit17";
13209 return "DW_OP_lit18";
13211 return "DW_OP_lit19";
13213 return "DW_OP_lit20";
13215 return "DW_OP_lit21";
13217 return "DW_OP_lit22";
13219 return "DW_OP_lit23";
13221 return "DW_OP_lit24";
13223 return "DW_OP_lit25";
13225 return "DW_OP_lit26";
13227 return "DW_OP_lit27";
13229 return "DW_OP_lit28";
13231 return "DW_OP_lit29";
13233 return "DW_OP_lit30";
13235 return "DW_OP_lit31";
13237 return "DW_OP_reg0";
13239 return "DW_OP_reg1";
13241 return "DW_OP_reg2";
13243 return "DW_OP_reg3";
13245 return "DW_OP_reg4";
13247 return "DW_OP_reg5";
13249 return "DW_OP_reg6";
13251 return "DW_OP_reg7";
13253 return "DW_OP_reg8";
13255 return "DW_OP_reg9";
13257 return "DW_OP_reg10";
13259 return "DW_OP_reg11";
13261 return "DW_OP_reg12";
13263 return "DW_OP_reg13";
13265 return "DW_OP_reg14";
13267 return "DW_OP_reg15";
13269 return "DW_OP_reg16";
13271 return "DW_OP_reg17";
13273 return "DW_OP_reg18";
13275 return "DW_OP_reg19";
13277 return "DW_OP_reg20";
13279 return "DW_OP_reg21";
13281 return "DW_OP_reg22";
13283 return "DW_OP_reg23";
13285 return "DW_OP_reg24";
13287 return "DW_OP_reg25";
13289 return "DW_OP_reg26";
13291 return "DW_OP_reg27";
13293 return "DW_OP_reg28";
13295 return "DW_OP_reg29";
13297 return "DW_OP_reg30";
13299 return "DW_OP_reg31";
13301 return "DW_OP_breg0";
13303 return "DW_OP_breg1";
13305 return "DW_OP_breg2";
13307 return "DW_OP_breg3";
13309 return "DW_OP_breg4";
13311 return "DW_OP_breg5";
13313 return "DW_OP_breg6";
13315 return "DW_OP_breg7";
13317 return "DW_OP_breg8";
13319 return "DW_OP_breg9";
13321 return "DW_OP_breg10";
13323 return "DW_OP_breg11";
13325 return "DW_OP_breg12";
13327 return "DW_OP_breg13";
13329 return "DW_OP_breg14";
13331 return "DW_OP_breg15";
13333 return "DW_OP_breg16";
13335 return "DW_OP_breg17";
13337 return "DW_OP_breg18";
13339 return "DW_OP_breg19";
13341 return "DW_OP_breg20";
13343 return "DW_OP_breg21";
13345 return "DW_OP_breg22";
13347 return "DW_OP_breg23";
13349 return "DW_OP_breg24";
13351 return "DW_OP_breg25";
13353 return "DW_OP_breg26";
13355 return "DW_OP_breg27";
13357 return "DW_OP_breg28";
13359 return "DW_OP_breg29";
13361 return "DW_OP_breg30";
13363 return "DW_OP_breg31";
13365 return "DW_OP_regx";
13367 return "DW_OP_fbreg";
13369 return "DW_OP_bregx";
13371 return "DW_OP_piece";
13372 case DW_OP_deref_size
:
13373 return "DW_OP_deref_size";
13374 case DW_OP_xderef_size
:
13375 return "DW_OP_xderef_size";
13377 return "DW_OP_nop";
13378 /* DWARF 3 extensions. */
13379 case DW_OP_push_object_address
:
13380 return "DW_OP_push_object_address";
13382 return "DW_OP_call2";
13384 return "DW_OP_call4";
13385 case DW_OP_call_ref
:
13386 return "DW_OP_call_ref";
13387 case DW_OP_form_tls_address
:
13388 return "DW_OP_form_tls_address";
13389 case DW_OP_call_frame_cfa
:
13390 return "DW_OP_call_frame_cfa";
13391 case DW_OP_bit_piece
:
13392 return "DW_OP_bit_piece";
13393 /* DWARF 4 extensions. */
13394 case DW_OP_implicit_value
:
13395 return "DW_OP_implicit_value";
13396 case DW_OP_stack_value
:
13397 return "DW_OP_stack_value";
13398 /* GNU extensions. */
13399 case DW_OP_GNU_push_tls_address
:
13400 return "DW_OP_GNU_push_tls_address";
13401 case DW_OP_GNU_uninit
:
13402 return "DW_OP_GNU_uninit";
13403 case DW_OP_GNU_implicit_pointer
:
13404 return "DW_OP_GNU_implicit_pointer";
13405 case DW_OP_GNU_entry_value
:
13406 return "DW_OP_GNU_entry_value";
13407 case DW_OP_GNU_const_type
:
13408 return "DW_OP_GNU_const_type";
13409 case DW_OP_GNU_regval_type
:
13410 return "DW_OP_GNU_regval_type";
13411 case DW_OP_GNU_deref_type
:
13412 return "DW_OP_GNU_deref_type";
13413 case DW_OP_GNU_convert
:
13414 return "DW_OP_GNU_convert";
13415 case DW_OP_GNU_reinterpret
:
13416 return "DW_OP_GNU_reinterpret";
13423 dwarf_bool_name (unsigned mybool
)
13431 /* Convert a DWARF type code into its string name. */
13434 dwarf_type_encoding_name (unsigned enc
)
13439 return "DW_ATE_void";
13440 case DW_ATE_address
:
13441 return "DW_ATE_address";
13442 case DW_ATE_boolean
:
13443 return "DW_ATE_boolean";
13444 case DW_ATE_complex_float
:
13445 return "DW_ATE_complex_float";
13447 return "DW_ATE_float";
13448 case DW_ATE_signed
:
13449 return "DW_ATE_signed";
13450 case DW_ATE_signed_char
:
13451 return "DW_ATE_signed_char";
13452 case DW_ATE_unsigned
:
13453 return "DW_ATE_unsigned";
13454 case DW_ATE_unsigned_char
:
13455 return "DW_ATE_unsigned_char";
13457 case DW_ATE_imaginary_float
:
13458 return "DW_ATE_imaginary_float";
13459 case DW_ATE_packed_decimal
:
13460 return "DW_ATE_packed_decimal";
13461 case DW_ATE_numeric_string
:
13462 return "DW_ATE_numeric_string";
13463 case DW_ATE_edited
:
13464 return "DW_ATE_edited";
13465 case DW_ATE_signed_fixed
:
13466 return "DW_ATE_signed_fixed";
13467 case DW_ATE_unsigned_fixed
:
13468 return "DW_ATE_unsigned_fixed";
13469 case DW_ATE_decimal_float
:
13470 return "DW_ATE_decimal_float";
13473 return "DW_ATE_UTF";
13474 /* HP extensions. */
13475 case DW_ATE_HP_float80
:
13476 return "DW_ATE_HP_float80";
13477 case DW_ATE_HP_complex_float80
:
13478 return "DW_ATE_HP_complex_float80";
13479 case DW_ATE_HP_float128
:
13480 return "DW_ATE_HP_float128";
13481 case DW_ATE_HP_complex_float128
:
13482 return "DW_ATE_HP_complex_float128";
13483 case DW_ATE_HP_floathpintel
:
13484 return "DW_ATE_HP_floathpintel";
13485 case DW_ATE_HP_imaginary_float80
:
13486 return "DW_ATE_HP_imaginary_float80";
13487 case DW_ATE_HP_imaginary_float128
:
13488 return "DW_ATE_HP_imaginary_float128";
13490 return "DW_ATE_<unknown>";
13494 /* Convert a DWARF call frame info operation to its string name. */
13498 dwarf_cfi_name (unsigned cfi_opc
)
13502 case DW_CFA_advance_loc
:
13503 return "DW_CFA_advance_loc";
13504 case DW_CFA_offset
:
13505 return "DW_CFA_offset";
13506 case DW_CFA_restore
:
13507 return "DW_CFA_restore";
13509 return "DW_CFA_nop";
13510 case DW_CFA_set_loc
:
13511 return "DW_CFA_set_loc";
13512 case DW_CFA_advance_loc1
:
13513 return "DW_CFA_advance_loc1";
13514 case DW_CFA_advance_loc2
:
13515 return "DW_CFA_advance_loc2";
13516 case DW_CFA_advance_loc4
:
13517 return "DW_CFA_advance_loc4";
13518 case DW_CFA_offset_extended
:
13519 return "DW_CFA_offset_extended";
13520 case DW_CFA_restore_extended
:
13521 return "DW_CFA_restore_extended";
13522 case DW_CFA_undefined
:
13523 return "DW_CFA_undefined";
13524 case DW_CFA_same_value
:
13525 return "DW_CFA_same_value";
13526 case DW_CFA_register
:
13527 return "DW_CFA_register";
13528 case DW_CFA_remember_state
:
13529 return "DW_CFA_remember_state";
13530 case DW_CFA_restore_state
:
13531 return "DW_CFA_restore_state";
13532 case DW_CFA_def_cfa
:
13533 return "DW_CFA_def_cfa";
13534 case DW_CFA_def_cfa_register
:
13535 return "DW_CFA_def_cfa_register";
13536 case DW_CFA_def_cfa_offset
:
13537 return "DW_CFA_def_cfa_offset";
13539 case DW_CFA_def_cfa_expression
:
13540 return "DW_CFA_def_cfa_expression";
13541 case DW_CFA_expression
:
13542 return "DW_CFA_expression";
13543 case DW_CFA_offset_extended_sf
:
13544 return "DW_CFA_offset_extended_sf";
13545 case DW_CFA_def_cfa_sf
:
13546 return "DW_CFA_def_cfa_sf";
13547 case DW_CFA_def_cfa_offset_sf
:
13548 return "DW_CFA_def_cfa_offset_sf";
13549 case DW_CFA_val_offset
:
13550 return "DW_CFA_val_offset";
13551 case DW_CFA_val_offset_sf
:
13552 return "DW_CFA_val_offset_sf";
13553 case DW_CFA_val_expression
:
13554 return "DW_CFA_val_expression";
13555 /* SGI/MIPS specific. */
13556 case DW_CFA_MIPS_advance_loc8
:
13557 return "DW_CFA_MIPS_advance_loc8";
13558 /* GNU extensions. */
13559 case DW_CFA_GNU_window_save
:
13560 return "DW_CFA_GNU_window_save";
13561 case DW_CFA_GNU_args_size
:
13562 return "DW_CFA_GNU_args_size";
13563 case DW_CFA_GNU_negative_offset_extended
:
13564 return "DW_CFA_GNU_negative_offset_extended";
13566 return "DW_CFA_<unknown>";
13572 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13576 print_spaces (indent
, f
);
13577 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13578 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13580 if (die
->parent
!= NULL
)
13582 print_spaces (indent
, f
);
13583 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13584 die
->parent
->offset
);
13587 print_spaces (indent
, f
);
13588 fprintf_unfiltered (f
, " has children: %s\n",
13589 dwarf_bool_name (die
->child
!= NULL
));
13591 print_spaces (indent
, f
);
13592 fprintf_unfiltered (f
, " attributes:\n");
13594 for (i
= 0; i
< die
->num_attrs
; ++i
)
13596 print_spaces (indent
, f
);
13597 fprintf_unfiltered (f
, " %s (%s) ",
13598 dwarf_attr_name (die
->attrs
[i
].name
),
13599 dwarf_form_name (die
->attrs
[i
].form
));
13601 switch (die
->attrs
[i
].form
)
13603 case DW_FORM_ref_addr
:
13605 fprintf_unfiltered (f
, "address: ");
13606 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13608 case DW_FORM_block2
:
13609 case DW_FORM_block4
:
13610 case DW_FORM_block
:
13611 case DW_FORM_block1
:
13612 fprintf_unfiltered (f
, "block: size %d",
13613 DW_BLOCK (&die
->attrs
[i
])->size
);
13615 case DW_FORM_exprloc
:
13616 fprintf_unfiltered (f
, "expression: size %u",
13617 DW_BLOCK (&die
->attrs
[i
])->size
);
13622 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13623 (long) (DW_ADDR (&die
->attrs
[i
])));
13625 case DW_FORM_data1
:
13626 case DW_FORM_data2
:
13627 case DW_FORM_data4
:
13628 case DW_FORM_data8
:
13629 case DW_FORM_udata
:
13630 case DW_FORM_sdata
:
13631 fprintf_unfiltered (f
, "constant: %s",
13632 pulongest (DW_UNSND (&die
->attrs
[i
])));
13634 case DW_FORM_sec_offset
:
13635 fprintf_unfiltered (f
, "section offset: %s",
13636 pulongest (DW_UNSND (&die
->attrs
[i
])));
13638 case DW_FORM_ref_sig8
:
13639 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13640 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13641 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
);
13643 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13645 case DW_FORM_string
:
13647 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13648 DW_STRING (&die
->attrs
[i
])
13649 ? DW_STRING (&die
->attrs
[i
]) : "",
13650 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13653 if (DW_UNSND (&die
->attrs
[i
]))
13654 fprintf_unfiltered (f
, "flag: TRUE");
13656 fprintf_unfiltered (f
, "flag: FALSE");
13658 case DW_FORM_flag_present
:
13659 fprintf_unfiltered (f
, "flag: TRUE");
13661 case DW_FORM_indirect
:
13662 /* The reader will have reduced the indirect form to
13663 the "base form" so this form should not occur. */
13664 fprintf_unfiltered (f
,
13665 "unexpected attribute form: DW_FORM_indirect");
13668 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13669 die
->attrs
[i
].form
);
13672 fprintf_unfiltered (f
, "\n");
13677 dump_die_for_error (struct die_info
*die
)
13679 dump_die_shallow (gdb_stderr
, 0, die
);
13683 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13685 int indent
= level
* 4;
13687 gdb_assert (die
!= NULL
);
13689 if (level
>= max_level
)
13692 dump_die_shallow (f
, indent
, die
);
13694 if (die
->child
!= NULL
)
13696 print_spaces (indent
, f
);
13697 fprintf_unfiltered (f
, " Children:");
13698 if (level
+ 1 < max_level
)
13700 fprintf_unfiltered (f
, "\n");
13701 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13705 fprintf_unfiltered (f
,
13706 " [not printed, max nesting level reached]\n");
13710 if (die
->sibling
!= NULL
&& level
> 0)
13712 dump_die_1 (f
, level
, max_level
, die
->sibling
);
13716 /* This is called from the pdie macro in gdbinit.in.
13717 It's not static so gcc will keep a copy callable from gdb. */
13720 dump_die (struct die_info
*die
, int max_level
)
13722 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
13726 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
13730 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
13736 is_ref_attr (struct attribute
*attr
)
13738 switch (attr
->form
)
13740 case DW_FORM_ref_addr
:
13745 case DW_FORM_ref_udata
:
13752 static unsigned int
13753 dwarf2_get_ref_die_offset (struct attribute
*attr
)
13755 if (is_ref_attr (attr
))
13756 return DW_ADDR (attr
);
13758 complaint (&symfile_complaints
,
13759 _("unsupported die ref attribute form: '%s'"),
13760 dwarf_form_name (attr
->form
));
13764 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13765 * the value held by the attribute is not constant. */
13768 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
13770 if (attr
->form
== DW_FORM_sdata
)
13771 return DW_SND (attr
);
13772 else if (attr
->form
== DW_FORM_udata
13773 || attr
->form
== DW_FORM_data1
13774 || attr
->form
== DW_FORM_data2
13775 || attr
->form
== DW_FORM_data4
13776 || attr
->form
== DW_FORM_data8
)
13777 return DW_UNSND (attr
);
13780 complaint (&symfile_complaints
,
13781 _("Attribute value is not a constant (%s)"),
13782 dwarf_form_name (attr
->form
));
13783 return default_value
;
13787 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13788 unit and add it to our queue.
13789 The result is non-zero if PER_CU was queued, otherwise the result is zero
13790 meaning either PER_CU is already queued or it is already loaded. */
13793 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
13794 struct dwarf2_per_cu_data
*per_cu
)
13796 /* We may arrive here during partial symbol reading, if we need full
13797 DIEs to process an unusual case (e.g. template arguments). Do
13798 not queue PER_CU, just tell our caller to load its DIEs. */
13799 if (dwarf2_per_objfile
->reading_partial_symbols
)
13801 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
13806 /* Mark the dependence relation so that we don't flush PER_CU
13808 dwarf2_add_dependence (this_cu
, per_cu
);
13810 /* If it's already on the queue, we have nothing to do. */
13811 if (per_cu
->queued
)
13814 /* If the compilation unit is already loaded, just mark it as
13816 if (per_cu
->cu
!= NULL
)
13818 per_cu
->cu
->last_used
= 0;
13822 /* Add it to the queue. */
13823 queue_comp_unit (per_cu
, this_cu
->objfile
);
13828 /* Follow reference or signature attribute ATTR of SRC_DIE.
13829 On entry *REF_CU is the CU of SRC_DIE.
13830 On exit *REF_CU is the CU of the result. */
13832 static struct die_info
*
13833 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
13834 struct dwarf2_cu
**ref_cu
)
13836 struct die_info
*die
;
13838 if (is_ref_attr (attr
))
13839 die
= follow_die_ref (src_die
, attr
, ref_cu
);
13840 else if (attr
->form
== DW_FORM_ref_sig8
)
13841 die
= follow_die_sig (src_die
, attr
, ref_cu
);
13844 dump_die_for_error (src_die
);
13845 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13846 (*ref_cu
)->objfile
->name
);
13852 /* Follow reference OFFSET.
13853 On entry *REF_CU is the CU of the source die referencing OFFSET.
13854 On exit *REF_CU is the CU of the result.
13855 Returns NULL if OFFSET is invalid. */
13857 static struct die_info
*
13858 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
13860 struct die_info temp_die
;
13861 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
13863 gdb_assert (cu
->per_cu
!= NULL
);
13867 if (cu
->per_cu
->debug_type_section
)
13869 /* .debug_types CUs cannot reference anything outside their CU.
13870 If they need to, they have to reference a signatured type via
13871 DW_FORM_ref_sig8. */
13872 if (! offset_in_cu_p (&cu
->header
, offset
))
13875 else if (! offset_in_cu_p (&cu
->header
, offset
))
13877 struct dwarf2_per_cu_data
*per_cu
;
13879 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
13881 /* If necessary, add it to the queue and load its DIEs. */
13882 if (maybe_queue_comp_unit (cu
, per_cu
))
13883 load_full_comp_unit (per_cu
, cu
->objfile
);
13885 target_cu
= per_cu
->cu
;
13887 else if (cu
->dies
== NULL
)
13889 /* We're loading full DIEs during partial symbol reading. */
13890 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
13891 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
13894 *ref_cu
= target_cu
;
13895 temp_die
.offset
= offset
;
13896 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13899 /* Follow reference attribute ATTR of SRC_DIE.
13900 On entry *REF_CU is the CU of SRC_DIE.
13901 On exit *REF_CU is the CU of the result. */
13903 static struct die_info
*
13904 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13905 struct dwarf2_cu
**ref_cu
)
13907 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13908 struct dwarf2_cu
*cu
= *ref_cu
;
13909 struct die_info
*die
;
13911 die
= follow_die_offset (offset
, ref_cu
);
13913 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13914 "at 0x%x [in module %s]"),
13915 offset
, src_die
->offset
, cu
->objfile
->name
);
13920 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13921 value is intended for DW_OP_call*. You must call xfree on returned
13922 dwarf2_locexpr_baton->data. */
13924 struct dwarf2_locexpr_baton
13925 dwarf2_fetch_die_location_block (unsigned int offset
,
13926 struct dwarf2_per_cu_data
*per_cu
,
13927 CORE_ADDR (*get_frame_pc
) (void *baton
),
13930 struct dwarf2_cu
*cu
;
13931 struct die_info
*die
;
13932 struct attribute
*attr
;
13933 struct dwarf2_locexpr_baton retval
;
13935 dw2_setup (per_cu
->objfile
);
13937 if (per_cu
->cu
== NULL
)
13941 die
= follow_die_offset (offset
, &cu
);
13943 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13944 offset
, per_cu
->cu
->objfile
->name
);
13946 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13949 /* DWARF: "If there is no such attribute, then there is no effect.". */
13951 retval
.data
= NULL
;
13954 else if (attr_form_is_section_offset (attr
))
13956 struct dwarf2_loclist_baton loclist_baton
;
13957 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
13960 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
13962 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
13964 retval
.size
= size
;
13968 if (!attr_form_is_block (attr
))
13969 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13970 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13971 offset
, per_cu
->cu
->objfile
->name
);
13973 retval
.data
= DW_BLOCK (attr
)->data
;
13974 retval
.size
= DW_BLOCK (attr
)->size
;
13976 retval
.per_cu
= cu
->per_cu
;
13979 retval
.data
= xmemdup (retval
.data
, retval
.size
, retval
.size
);
13981 age_cached_comp_units ();
13986 /* Return the type of the DIE at DIE_OFFSET in the CU named by
13990 dwarf2_get_die_type (unsigned int die_offset
,
13991 struct dwarf2_per_cu_data
*per_cu
)
13993 dw2_setup (per_cu
->objfile
);
13994 return get_die_type_at_offset (die_offset
, per_cu
);
13997 /* Follow the signature attribute ATTR in SRC_DIE.
13998 On entry *REF_CU is the CU of SRC_DIE.
13999 On exit *REF_CU is the CU of the result. */
14001 static struct die_info
*
14002 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
14003 struct dwarf2_cu
**ref_cu
)
14005 struct objfile
*objfile
= (*ref_cu
)->objfile
;
14006 struct die_info temp_die
;
14007 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14008 struct dwarf2_cu
*sig_cu
;
14009 struct die_info
*die
;
14011 /* sig_type will be NULL if the signatured type is missing from
14013 if (sig_type
== NULL
)
14014 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14015 "at 0x%x [in module %s]"),
14016 src_die
->offset
, objfile
->name
);
14018 /* If necessary, add it to the queue and load its DIEs. */
14020 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14021 read_signatured_type (objfile
, sig_type
);
14023 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14025 sig_cu
= sig_type
->per_cu
.cu
;
14026 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
14027 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
14034 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14035 "from DIE at 0x%x [in module %s]"),
14036 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
14039 /* Given an offset of a signatured type, return its signatured_type. */
14041 static struct signatured_type
*
14042 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14043 struct dwarf2_section_info
*section
,
14044 unsigned int offset
)
14046 gdb_byte
*info_ptr
= section
->buffer
+ offset
;
14047 unsigned int length
, initial_length_size
;
14048 unsigned int sig_offset
;
14049 struct signatured_type find_entry
, *type_sig
;
14051 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14052 sig_offset
= (initial_length_size
14054 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14055 + 1 /*address_size*/);
14056 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14057 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14059 /* This is only used to lookup previously recorded types.
14060 If we didn't find it, it's our bug. */
14061 gdb_assert (type_sig
!= NULL
);
14062 gdb_assert (offset
== type_sig
->per_cu
.offset
);
14067 /* Read in signatured type at OFFSET and build its CU and die(s). */
14070 read_signatured_type_at_offset (struct objfile
*objfile
,
14071 struct dwarf2_section_info
*sect
,
14072 unsigned int offset
)
14074 struct signatured_type
*type_sig
;
14076 dwarf2_read_section (objfile
, sect
);
14078 /* We have the section offset, but we need the signature to do the
14079 hash table lookup. */
14080 type_sig
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14082 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14084 read_signatured_type (objfile
, type_sig
);
14086 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
14089 /* Read in a signatured type and build its CU and DIEs. */
14092 read_signatured_type (struct objfile
*objfile
,
14093 struct signatured_type
*type_sig
)
14095 gdb_byte
*types_ptr
;
14096 struct die_reader_specs reader_specs
;
14097 struct dwarf2_cu
*cu
;
14098 ULONGEST signature
;
14099 struct cleanup
*back_to
, *free_cu_cleanup
;
14100 struct dwarf2_section_info
*section
= type_sig
->per_cu
.debug_type_section
;
14102 dwarf2_read_section (objfile
, section
);
14103 types_ptr
= section
->buffer
+ type_sig
->per_cu
.offset
;
14105 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14107 cu
= xmalloc (sizeof (*cu
));
14108 init_one_comp_unit (cu
, objfile
);
14110 type_sig
->per_cu
.cu
= cu
;
14111 cu
->per_cu
= &type_sig
->per_cu
;
14113 /* If an error occurs while loading, release our storage. */
14114 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
14116 types_ptr
= read_type_comp_unit_head (&cu
->header
, section
, &signature
,
14117 types_ptr
, objfile
->obfd
);
14118 gdb_assert (signature
== type_sig
->signature
);
14121 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14125 &cu
->comp_unit_obstack
,
14126 hashtab_obstack_allocate
,
14127 dummy_obstack_deallocate
);
14129 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
14130 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
14132 init_cu_die_reader (&reader_specs
, cu
);
14134 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14137 /* We try not to read any attributes in this function, because not
14138 all objfiles needed for references have been loaded yet, and symbol
14139 table processing isn't initialized. But we have to set the CU language,
14140 or we won't be able to build types correctly. */
14141 prepare_one_comp_unit (cu
, cu
->dies
);
14143 do_cleanups (back_to
);
14145 /* We've successfully allocated this compilation unit. Let our caller
14146 clean it up when finished with it. */
14147 discard_cleanups (free_cu_cleanup
);
14149 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14150 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
14153 /* Decode simple location descriptions.
14154 Given a pointer to a dwarf block that defines a location, compute
14155 the location and return the value.
14157 NOTE drow/2003-11-18: This function is called in two situations
14158 now: for the address of static or global variables (partial symbols
14159 only) and for offsets into structures which are expected to be
14160 (more or less) constant. The partial symbol case should go away,
14161 and only the constant case should remain. That will let this
14162 function complain more accurately. A few special modes are allowed
14163 without complaint for global variables (for instance, global
14164 register values and thread-local values).
14166 A location description containing no operations indicates that the
14167 object is optimized out. The return value is 0 for that case.
14168 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14169 callers will only want a very basic result and this can become a
14172 Note that stack[0] is unused except as a default error return. */
14175 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14177 struct objfile
*objfile
= cu
->objfile
;
14179 int size
= blk
->size
;
14180 gdb_byte
*data
= blk
->data
;
14181 CORE_ADDR stack
[64];
14183 unsigned int bytes_read
, unsnd
;
14189 stack
[++stacki
] = 0;
14228 stack
[++stacki
] = op
- DW_OP_lit0
;
14263 stack
[++stacki
] = op
- DW_OP_reg0
;
14265 dwarf2_complex_location_expr_complaint ();
14269 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14271 stack
[++stacki
] = unsnd
;
14273 dwarf2_complex_location_expr_complaint ();
14277 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14282 case DW_OP_const1u
:
14283 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14287 case DW_OP_const1s
:
14288 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14292 case DW_OP_const2u
:
14293 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14297 case DW_OP_const2s
:
14298 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14302 case DW_OP_const4u
:
14303 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14307 case DW_OP_const4s
:
14308 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14313 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14319 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14324 stack
[stacki
+ 1] = stack
[stacki
];
14329 stack
[stacki
- 1] += stack
[stacki
];
14333 case DW_OP_plus_uconst
:
14334 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14340 stack
[stacki
- 1] -= stack
[stacki
];
14345 /* If we're not the last op, then we definitely can't encode
14346 this using GDB's address_class enum. This is valid for partial
14347 global symbols, although the variable's address will be bogus
14350 dwarf2_complex_location_expr_complaint ();
14353 case DW_OP_GNU_push_tls_address
:
14354 /* The top of the stack has the offset from the beginning
14355 of the thread control block at which the variable is located. */
14356 /* Nothing should follow this operator, so the top of stack would
14358 /* This is valid for partial global symbols, but the variable's
14359 address will be bogus in the psymtab. */
14361 dwarf2_complex_location_expr_complaint ();
14364 case DW_OP_GNU_uninit
:
14369 const char *name
= dwarf_stack_op_name (op
);
14372 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14375 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14379 return (stack
[stacki
]);
14382 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14383 outside of the allocated space. Also enforce minimum>0. */
14384 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14386 complaint (&symfile_complaints
,
14387 _("location description stack overflow"));
14393 complaint (&symfile_complaints
,
14394 _("location description stack underflow"));
14398 return (stack
[stacki
]);
14401 /* memory allocation interface */
14403 static struct dwarf_block
*
14404 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14406 struct dwarf_block
*blk
;
14408 blk
= (struct dwarf_block
*)
14409 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14413 static struct abbrev_info
*
14414 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14416 struct abbrev_info
*abbrev
;
14418 abbrev
= (struct abbrev_info
*)
14419 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14420 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14424 static struct die_info
*
14425 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14427 struct die_info
*die
;
14428 size_t size
= sizeof (struct die_info
);
14431 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14433 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14434 memset (die
, 0, sizeof (struct die_info
));
14439 /* Macro support. */
14441 /* Return the full name of file number I in *LH's file name table.
14442 Use COMP_DIR as the name of the current directory of the
14443 compilation. The result is allocated using xmalloc; the caller is
14444 responsible for freeing it. */
14446 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14448 /* Is the file number a valid index into the line header's file name
14449 table? Remember that file numbers start with one, not zero. */
14450 if (1 <= file
&& file
<= lh
->num_file_names
)
14452 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14454 if (IS_ABSOLUTE_PATH (fe
->name
))
14455 return xstrdup (fe
->name
);
14463 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14469 dir_len
= strlen (dir
);
14470 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14471 strcpy (full_name
, dir
);
14472 full_name
[dir_len
] = '/';
14473 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14477 return xstrdup (fe
->name
);
14482 /* The compiler produced a bogus file number. We can at least
14483 record the macro definitions made in the file, even if we
14484 won't be able to find the file by name. */
14485 char fake_name
[80];
14487 sprintf (fake_name
, "<bad macro file number %d>", file
);
14489 complaint (&symfile_complaints
,
14490 _("bad file number in macro information (%d)"),
14493 return xstrdup (fake_name
);
14498 static struct macro_source_file
*
14499 macro_start_file (int file
, int line
,
14500 struct macro_source_file
*current_file
,
14501 const char *comp_dir
,
14502 struct line_header
*lh
, struct objfile
*objfile
)
14504 /* The full name of this source file. */
14505 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14507 /* We don't create a macro table for this compilation unit
14508 at all until we actually get a filename. */
14509 if (! pending_macros
)
14510 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14511 objfile
->macro_cache
);
14513 if (! current_file
)
14514 /* If we have no current file, then this must be the start_file
14515 directive for the compilation unit's main source file. */
14516 current_file
= macro_set_main (pending_macros
, full_name
);
14518 current_file
= macro_include (current_file
, line
, full_name
);
14522 return current_file
;
14526 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14527 followed by a null byte. */
14529 copy_string (const char *buf
, int len
)
14531 char *s
= xmalloc (len
+ 1);
14533 memcpy (s
, buf
, len
);
14539 static const char *
14540 consume_improper_spaces (const char *p
, const char *body
)
14544 complaint (&symfile_complaints
,
14545 _("macro definition contains spaces "
14546 "in formal argument list:\n`%s'"),
14558 parse_macro_definition (struct macro_source_file
*file
, int line
,
14563 /* The body string takes one of two forms. For object-like macro
14564 definitions, it should be:
14566 <macro name> " " <definition>
14568 For function-like macro definitions, it should be:
14570 <macro name> "() " <definition>
14572 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14574 Spaces may appear only where explicitly indicated, and in the
14577 The Dwarf 2 spec says that an object-like macro's name is always
14578 followed by a space, but versions of GCC around March 2002 omit
14579 the space when the macro's definition is the empty string.
14581 The Dwarf 2 spec says that there should be no spaces between the
14582 formal arguments in a function-like macro's formal argument list,
14583 but versions of GCC around March 2002 include spaces after the
14587 /* Find the extent of the macro name. The macro name is terminated
14588 by either a space or null character (for an object-like macro) or
14589 an opening paren (for a function-like macro). */
14590 for (p
= body
; *p
; p
++)
14591 if (*p
== ' ' || *p
== '(')
14594 if (*p
== ' ' || *p
== '\0')
14596 /* It's an object-like macro. */
14597 int name_len
= p
- body
;
14598 char *name
= copy_string (body
, name_len
);
14599 const char *replacement
;
14602 replacement
= body
+ name_len
+ 1;
14605 dwarf2_macro_malformed_definition_complaint (body
);
14606 replacement
= body
+ name_len
;
14609 macro_define_object (file
, line
, name
, replacement
);
14613 else if (*p
== '(')
14615 /* It's a function-like macro. */
14616 char *name
= copy_string (body
, p
- body
);
14619 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14623 p
= consume_improper_spaces (p
, body
);
14625 /* Parse the formal argument list. */
14626 while (*p
&& *p
!= ')')
14628 /* Find the extent of the current argument name. */
14629 const char *arg_start
= p
;
14631 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14634 if (! *p
|| p
== arg_start
)
14635 dwarf2_macro_malformed_definition_complaint (body
);
14638 /* Make sure argv has room for the new argument. */
14639 if (argc
>= argv_size
)
14642 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14645 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14648 p
= consume_improper_spaces (p
, body
);
14650 /* Consume the comma, if present. */
14655 p
= consume_improper_spaces (p
, body
);
14664 /* Perfectly formed definition, no complaints. */
14665 macro_define_function (file
, line
, name
,
14666 argc
, (const char **) argv
,
14668 else if (*p
== '\0')
14670 /* Complain, but do define it. */
14671 dwarf2_macro_malformed_definition_complaint (body
);
14672 macro_define_function (file
, line
, name
,
14673 argc
, (const char **) argv
,
14677 /* Just complain. */
14678 dwarf2_macro_malformed_definition_complaint (body
);
14681 /* Just complain. */
14682 dwarf2_macro_malformed_definition_complaint (body
);
14688 for (i
= 0; i
< argc
; i
++)
14694 dwarf2_macro_malformed_definition_complaint (body
);
14697 /* Skip some bytes from BYTES according to the form given in FORM.
14698 Returns the new pointer. */
14701 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
14702 enum dwarf_form form
,
14703 unsigned int offset_size
,
14704 struct dwarf2_section_info
*section
)
14706 unsigned int bytes_read
;
14710 case DW_FORM_data1
:
14715 case DW_FORM_data2
:
14719 case DW_FORM_data4
:
14723 case DW_FORM_data8
:
14727 case DW_FORM_string
:
14728 read_direct_string (abfd
, bytes
, &bytes_read
);
14729 bytes
+= bytes_read
;
14732 case DW_FORM_sec_offset
:
14734 bytes
+= offset_size
;
14737 case DW_FORM_block
:
14738 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
14739 bytes
+= bytes_read
;
14742 case DW_FORM_block1
:
14743 bytes
+= 1 + read_1_byte (abfd
, bytes
);
14745 case DW_FORM_block2
:
14746 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
14748 case DW_FORM_block4
:
14749 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
14752 case DW_FORM_sdata
:
14753 case DW_FORM_udata
:
14754 bytes
= skip_leb128 (abfd
, bytes
);
14760 complaint (&symfile_complaints
,
14761 _("invalid form 0x%x in `%s'"),
14763 section
->asection
->name
);
14771 /* A helper for dwarf_decode_macros that handles skipping an unknown
14772 opcode. Returns an updated pointer to the macro data buffer; or,
14773 on error, issues a complaint and returns NULL. */
14776 skip_unknown_opcode (unsigned int opcode
,
14777 gdb_byte
**opcode_definitions
,
14780 unsigned int offset_size
,
14781 struct dwarf2_section_info
*section
)
14783 unsigned int bytes_read
, i
;
14787 if (opcode_definitions
[opcode
] == NULL
)
14789 complaint (&symfile_complaints
,
14790 _("unrecognized DW_MACFINO opcode 0x%x"),
14795 defn
= opcode_definitions
[opcode
];
14796 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
14797 defn
+= bytes_read
;
14799 for (i
= 0; i
< arg
; ++i
)
14801 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
14802 if (mac_ptr
== NULL
)
14804 /* skip_form_bytes already issued the complaint. */
14812 /* A helper function which parses the header of a macro section.
14813 If the macro section is the extended (for now called "GNU") type,
14814 then this updates *OFFSET_SIZE. Returns a pointer to just after
14815 the header, or issues a complaint and returns NULL on error. */
14818 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
14821 unsigned int *offset_size
,
14822 int section_is_gnu
)
14824 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
14826 if (section_is_gnu
)
14828 unsigned int version
, flags
;
14830 version
= read_2_bytes (abfd
, mac_ptr
);
14833 complaint (&symfile_complaints
,
14834 _("unrecognized version `%d' in .debug_macro section"),
14840 flags
= read_1_byte (abfd
, mac_ptr
);
14842 *offset_size
= (flags
& 1) ? 8 : 4;
14844 if ((flags
& 2) != 0)
14845 /* We don't need the line table offset. */
14846 mac_ptr
+= *offset_size
;
14848 /* Vendor opcode descriptions. */
14849 if ((flags
& 4) != 0)
14851 unsigned int i
, count
;
14853 count
= read_1_byte (abfd
, mac_ptr
);
14855 for (i
= 0; i
< count
; ++i
)
14857 unsigned int opcode
, bytes_read
;
14860 opcode
= read_1_byte (abfd
, mac_ptr
);
14862 opcode_definitions
[opcode
] = mac_ptr
;
14863 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14864 mac_ptr
+= bytes_read
;
14873 /* A helper for dwarf_decode_macros that handles the GNU extensions,
14874 including DW_GNU_MACINFO_transparent_include. */
14877 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
14878 struct macro_source_file
*current_file
,
14879 struct line_header
*lh
, char *comp_dir
,
14880 struct dwarf2_section_info
*section
,
14881 int section_is_gnu
,
14882 unsigned int offset_size
,
14883 struct objfile
*objfile
)
14885 enum dwarf_macro_record_type macinfo_type
;
14886 int at_commandline
;
14887 gdb_byte
*opcode_definitions
[256];
14889 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
14890 &offset_size
, section_is_gnu
);
14891 if (mac_ptr
== NULL
)
14893 /* We already issued a complaint. */
14897 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14898 GDB is still reading the definitions from command line. First
14899 DW_MACINFO_start_file will need to be ignored as it was already executed
14900 to create CURRENT_FILE for the main source holding also the command line
14901 definitions. On first met DW_MACINFO_start_file this flag is reset to
14902 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14904 at_commandline
= 1;
14908 /* Do we at least have room for a macinfo type byte? */
14909 if (mac_ptr
>= mac_end
)
14911 dwarf2_macros_too_long_complaint (section
);
14915 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14918 /* Note that we rely on the fact that the corresponding GNU and
14919 DWARF constants are the same. */
14920 switch (macinfo_type
)
14922 /* A zero macinfo type indicates the end of the macro
14927 case DW_MACRO_GNU_define
:
14928 case DW_MACRO_GNU_undef
:
14929 case DW_MACRO_GNU_define_indirect
:
14930 case DW_MACRO_GNU_undef_indirect
:
14932 unsigned int bytes_read
;
14937 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14938 mac_ptr
+= bytes_read
;
14940 if (macinfo_type
== DW_MACRO_GNU_define
14941 || macinfo_type
== DW_MACRO_GNU_undef
)
14943 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14944 mac_ptr
+= bytes_read
;
14948 LONGEST str_offset
;
14950 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
14951 mac_ptr
+= offset_size
;
14953 body
= read_indirect_string_at_offset (abfd
, str_offset
);
14956 is_define
= (macinfo_type
== DW_MACRO_GNU_define
14957 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
14958 if (! current_file
)
14960 /* DWARF violation as no main source is present. */
14961 complaint (&symfile_complaints
,
14962 _("debug info with no main source gives macro %s "
14964 is_define
? _("definition") : _("undefinition"),
14968 if ((line
== 0 && !at_commandline
)
14969 || (line
!= 0 && at_commandline
))
14970 complaint (&symfile_complaints
,
14971 _("debug info gives %s macro %s with %s line %d: %s"),
14972 at_commandline
? _("command-line") : _("in-file"),
14973 is_define
? _("definition") : _("undefinition"),
14974 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
14977 parse_macro_definition (current_file
, line
, body
);
14980 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
14981 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
14982 macro_undef (current_file
, line
, body
);
14987 case DW_MACRO_GNU_start_file
:
14989 unsigned int bytes_read
;
14992 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14993 mac_ptr
+= bytes_read
;
14994 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14995 mac_ptr
+= bytes_read
;
14997 if ((line
== 0 && !at_commandline
)
14998 || (line
!= 0 && at_commandline
))
14999 complaint (&symfile_complaints
,
15000 _("debug info gives source %d included "
15001 "from %s at %s line %d"),
15002 file
, at_commandline
? _("command-line") : _("file"),
15003 line
== 0 ? _("zero") : _("non-zero"), line
);
15005 if (at_commandline
)
15007 /* This DW_MACRO_GNU_start_file was executed in the
15009 at_commandline
= 0;
15012 current_file
= macro_start_file (file
, line
,
15013 current_file
, comp_dir
,
15018 case DW_MACRO_GNU_end_file
:
15019 if (! current_file
)
15020 complaint (&symfile_complaints
,
15021 _("macro debug info has an unmatched "
15022 "`close_file' directive"));
15025 current_file
= current_file
->included_by
;
15026 if (! current_file
)
15028 enum dwarf_macro_record_type next_type
;
15030 /* GCC circa March 2002 doesn't produce the zero
15031 type byte marking the end of the compilation
15032 unit. Complain if it's not there, but exit no
15035 /* Do we at least have room for a macinfo type byte? */
15036 if (mac_ptr
>= mac_end
)
15038 dwarf2_macros_too_long_complaint (section
);
15042 /* We don't increment mac_ptr here, so this is just
15044 next_type
= read_1_byte (abfd
, mac_ptr
);
15045 if (next_type
!= 0)
15046 complaint (&symfile_complaints
,
15047 _("no terminating 0-type entry for "
15048 "macros in `.debug_macinfo' section"));
15055 case DW_MACRO_GNU_transparent_include
:
15059 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15060 mac_ptr
+= offset_size
;
15062 dwarf_decode_macro_bytes (abfd
,
15063 section
->buffer
+ offset
,
15064 mac_end
, current_file
,
15066 section
, section_is_gnu
,
15067 offset_size
, objfile
);
15071 case DW_MACINFO_vendor_ext
:
15072 if (!section_is_gnu
)
15074 unsigned int bytes_read
;
15077 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15078 mac_ptr
+= bytes_read
;
15079 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15080 mac_ptr
+= bytes_read
;
15082 /* We don't recognize any vendor extensions. */
15088 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15089 mac_ptr
, abfd
, offset_size
,
15091 if (mac_ptr
== NULL
)
15095 } while (macinfo_type
!= 0);
15099 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
15100 char *comp_dir
, bfd
*abfd
,
15101 struct dwarf2_cu
*cu
,
15102 struct dwarf2_section_info
*section
,
15103 int section_is_gnu
)
15105 gdb_byte
*mac_ptr
, *mac_end
;
15106 struct macro_source_file
*current_file
= 0;
15107 enum dwarf_macro_record_type macinfo_type
;
15108 unsigned int offset_size
= cu
->header
.offset_size
;
15109 gdb_byte
*opcode_definitions
[256];
15111 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
15112 if (section
->buffer
== NULL
)
15114 complaint (&symfile_complaints
, _("missing %s section"),
15115 section
->asection
->name
);
15119 /* First pass: Find the name of the base filename.
15120 This filename is needed in order to process all macros whose definition
15121 (or undefinition) comes from the command line. These macros are defined
15122 before the first DW_MACINFO_start_file entry, and yet still need to be
15123 associated to the base file.
15125 To determine the base file name, we scan the macro definitions until we
15126 reach the first DW_MACINFO_start_file entry. We then initialize
15127 CURRENT_FILE accordingly so that any macro definition found before the
15128 first DW_MACINFO_start_file can still be associated to the base file. */
15130 mac_ptr
= section
->buffer
+ offset
;
15131 mac_end
= section
->buffer
+ section
->size
;
15133 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15134 &offset_size
, section_is_gnu
);
15135 if (mac_ptr
== NULL
)
15137 /* We already issued a complaint. */
15143 /* Do we at least have room for a macinfo type byte? */
15144 if (mac_ptr
>= mac_end
)
15146 /* Complaint is printed during the second pass as GDB will probably
15147 stop the first pass earlier upon finding
15148 DW_MACINFO_start_file. */
15152 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15155 /* Note that we rely on the fact that the corresponding GNU and
15156 DWARF constants are the same. */
15157 switch (macinfo_type
)
15159 /* A zero macinfo type indicates the end of the macro
15164 case DW_MACRO_GNU_define
:
15165 case DW_MACRO_GNU_undef
:
15166 /* Only skip the data by MAC_PTR. */
15168 unsigned int bytes_read
;
15170 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15171 mac_ptr
+= bytes_read
;
15172 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15173 mac_ptr
+= bytes_read
;
15177 case DW_MACRO_GNU_start_file
:
15179 unsigned int bytes_read
;
15182 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15183 mac_ptr
+= bytes_read
;
15184 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15185 mac_ptr
+= bytes_read
;
15187 current_file
= macro_start_file (file
, line
, current_file
,
15188 comp_dir
, lh
, cu
->objfile
);
15192 case DW_MACRO_GNU_end_file
:
15193 /* No data to skip by MAC_PTR. */
15196 case DW_MACRO_GNU_define_indirect
:
15197 case DW_MACRO_GNU_undef_indirect
:
15199 unsigned int bytes_read
;
15201 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15202 mac_ptr
+= bytes_read
;
15203 mac_ptr
+= offset_size
;
15207 case DW_MACRO_GNU_transparent_include
:
15208 /* Note that, according to the spec, a transparent include
15209 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15210 skip this opcode. */
15211 mac_ptr
+= offset_size
;
15214 case DW_MACINFO_vendor_ext
:
15215 /* Only skip the data by MAC_PTR. */
15216 if (!section_is_gnu
)
15218 unsigned int bytes_read
;
15220 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15221 mac_ptr
+= bytes_read
;
15222 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15223 mac_ptr
+= bytes_read
;
15228 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15229 mac_ptr
, abfd
, offset_size
,
15231 if (mac_ptr
== NULL
)
15235 } while (macinfo_type
!= 0 && current_file
== NULL
);
15237 /* Second pass: Process all entries.
15239 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15240 command-line macro definitions/undefinitions. This flag is unset when we
15241 reach the first DW_MACINFO_start_file entry. */
15243 dwarf_decode_macro_bytes (abfd
, section
->buffer
+ offset
, mac_end
,
15244 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
15245 offset_size
, cu
->objfile
);
15248 /* Check if the attribute's form is a DW_FORM_block*
15249 if so return true else false. */
15251 attr_form_is_block (struct attribute
*attr
)
15253 return (attr
== NULL
? 0 :
15254 attr
->form
== DW_FORM_block1
15255 || attr
->form
== DW_FORM_block2
15256 || attr
->form
== DW_FORM_block4
15257 || attr
->form
== DW_FORM_block
15258 || attr
->form
== DW_FORM_exprloc
);
15261 /* Return non-zero if ATTR's value is a section offset --- classes
15262 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15263 You may use DW_UNSND (attr) to retrieve such offsets.
15265 Section 7.5.4, "Attribute Encodings", explains that no attribute
15266 may have a value that belongs to more than one of these classes; it
15267 would be ambiguous if we did, because we use the same forms for all
15270 attr_form_is_section_offset (struct attribute
*attr
)
15272 return (attr
->form
== DW_FORM_data4
15273 || attr
->form
== DW_FORM_data8
15274 || attr
->form
== DW_FORM_sec_offset
);
15278 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15279 zero otherwise. When this function returns true, you can apply
15280 dwarf2_get_attr_constant_value to it.
15282 However, note that for some attributes you must check
15283 attr_form_is_section_offset before using this test. DW_FORM_data4
15284 and DW_FORM_data8 are members of both the constant class, and of
15285 the classes that contain offsets into other debug sections
15286 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15287 that, if an attribute's can be either a constant or one of the
15288 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15289 taken as section offsets, not constants. */
15291 attr_form_is_constant (struct attribute
*attr
)
15293 switch (attr
->form
)
15295 case DW_FORM_sdata
:
15296 case DW_FORM_udata
:
15297 case DW_FORM_data1
:
15298 case DW_FORM_data2
:
15299 case DW_FORM_data4
:
15300 case DW_FORM_data8
:
15307 /* A helper function that fills in a dwarf2_loclist_baton. */
15310 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15311 struct dwarf2_loclist_baton
*baton
,
15312 struct attribute
*attr
)
15314 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15315 &dwarf2_per_objfile
->loc
);
15317 baton
->per_cu
= cu
->per_cu
;
15318 gdb_assert (baton
->per_cu
);
15319 /* We don't know how long the location list is, but make sure we
15320 don't run off the edge of the section. */
15321 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15322 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15323 baton
->base_address
= cu
->base_address
;
15327 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15328 struct dwarf2_cu
*cu
)
15330 if (attr_form_is_section_offset (attr
)
15331 /* ".debug_loc" may not exist at all, or the offset may be outside
15332 the section. If so, fall through to the complaint in the
15334 && DW_UNSND (attr
) < dwarf2_section_size (dwarf2_per_objfile
->objfile
,
15335 &dwarf2_per_objfile
->loc
))
15337 struct dwarf2_loclist_baton
*baton
;
15339 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
15340 sizeof (struct dwarf2_loclist_baton
));
15342 fill_in_loclist_baton (cu
, baton
, attr
);
15344 if (cu
->base_known
== 0)
15345 complaint (&symfile_complaints
,
15346 _("Location list used without "
15347 "specifying the CU base address."));
15349 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15350 SYMBOL_LOCATION_BATON (sym
) = baton
;
15354 struct dwarf2_locexpr_baton
*baton
;
15356 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
15357 sizeof (struct dwarf2_locexpr_baton
));
15358 baton
->per_cu
= cu
->per_cu
;
15359 gdb_assert (baton
->per_cu
);
15361 if (attr_form_is_block (attr
))
15363 /* Note that we're just copying the block's data pointer
15364 here, not the actual data. We're still pointing into the
15365 info_buffer for SYM's objfile; right now we never release
15366 that buffer, but when we do clean up properly this may
15368 baton
->size
= DW_BLOCK (attr
)->size
;
15369 baton
->data
= DW_BLOCK (attr
)->data
;
15373 dwarf2_invalid_attrib_class_complaint ("location description",
15374 SYMBOL_NATURAL_NAME (sym
));
15376 baton
->data
= NULL
;
15379 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15380 SYMBOL_LOCATION_BATON (sym
) = baton
;
15384 /* Return the OBJFILE associated with the compilation unit CU. If CU
15385 came from a separate debuginfo file, then the master objfile is
15389 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
15391 struct objfile
*objfile
= per_cu
->objfile
;
15393 /* Return the master objfile, so that we can report and look up the
15394 correct file containing this variable. */
15395 if (objfile
->separate_debug_objfile_backlink
)
15396 objfile
= objfile
->separate_debug_objfile_backlink
;
15401 /* Return the address size given in the compilation unit header for CU. */
15404 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15407 return per_cu
->cu
->header
.addr_size
;
15410 /* If the CU is not currently read in, we re-read its header. */
15411 struct objfile
*objfile
= per_cu
->objfile
;
15412 struct dwarf2_per_objfile
*per_objfile
15413 = objfile_data (objfile
, dwarf2_objfile_data_key
);
15414 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
15415 struct comp_unit_head cu_header
;
15417 memset (&cu_header
, 0, sizeof cu_header
);
15418 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
15419 return cu_header
.addr_size
;
15423 /* Return the offset size given in the compilation unit header for CU. */
15426 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
15429 return per_cu
->cu
->header
.offset_size
;
15432 /* If the CU is not currently read in, we re-read its header. */
15433 struct objfile
*objfile
= per_cu
->objfile
;
15434 struct dwarf2_per_objfile
*per_objfile
15435 = objfile_data (objfile
, dwarf2_objfile_data_key
);
15436 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
15437 struct comp_unit_head cu_header
;
15439 memset (&cu_header
, 0, sizeof cu_header
);
15440 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
15441 return cu_header
.offset_size
;
15445 /* Return the text offset of the CU. The returned offset comes from
15446 this CU's objfile. If this objfile came from a separate debuginfo
15447 file, then the offset may be different from the corresponding
15448 offset in the parent objfile. */
15451 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
15453 struct objfile
*objfile
= per_cu
->objfile
;
15455 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15458 /* Locate the .debug_info compilation unit from CU's objfile which contains
15459 the DIE at OFFSET. Raises an error on failure. */
15461 static struct dwarf2_per_cu_data
*
15462 dwarf2_find_containing_comp_unit (unsigned int offset
,
15463 struct objfile
*objfile
)
15465 struct dwarf2_per_cu_data
*this_cu
;
15469 high
= dwarf2_per_objfile
->n_comp_units
- 1;
15472 int mid
= low
+ (high
- low
) / 2;
15474 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
15479 gdb_assert (low
== high
);
15480 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
15483 error (_("Dwarf Error: could not find partial DIE containing "
15484 "offset 0x%lx [in module %s]"),
15485 (long) offset
, bfd_get_filename (objfile
->obfd
));
15487 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
15488 return dwarf2_per_objfile
->all_comp_units
[low
-1];
15492 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
15493 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
15494 && offset
>= this_cu
->offset
+ this_cu
->length
)
15495 error (_("invalid dwarf2 offset %u"), offset
);
15496 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
15501 /* Locate the compilation unit from OBJFILE which is located at exactly
15502 OFFSET. Raises an error on failure. */
15504 static struct dwarf2_per_cu_data
*
15505 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
15507 struct dwarf2_per_cu_data
*this_cu
;
15509 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
15510 if (this_cu
->offset
!= offset
)
15511 error (_("no compilation unit with offset %u."), offset
);
15515 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
15518 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
15520 memset (cu
, 0, sizeof (*cu
));
15521 cu
->objfile
= objfile
;
15522 obstack_init (&cu
->comp_unit_obstack
);
15525 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15528 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
15530 struct attribute
*attr
;
15532 /* Set the language we're debugging. */
15533 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
15535 set_cu_language (DW_UNSND (attr
), cu
);
15538 cu
->language
= language_minimal
;
15539 cu
->language_defn
= language_def (cu
->language
);
15543 /* Release one cached compilation unit, CU. We unlink it from the tree
15544 of compilation units, but we don't remove it from the read_in_chain;
15545 the caller is responsible for that.
15546 NOTE: DATA is a void * because this function is also used as a
15547 cleanup routine. */
15550 free_one_comp_unit (void *data
)
15552 struct dwarf2_cu
*cu
= data
;
15554 if (cu
->per_cu
!= NULL
)
15555 cu
->per_cu
->cu
= NULL
;
15558 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15563 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15564 when we're finished with it. We can't free the pointer itself, but be
15565 sure to unlink it from the cache. Also release any associated storage
15566 and perform cache maintenance.
15568 Only used during partial symbol parsing. */
15571 free_stack_comp_unit (void *data
)
15573 struct dwarf2_cu
*cu
= data
;
15575 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15576 cu
->partial_dies
= NULL
;
15578 if (cu
->per_cu
!= NULL
)
15580 /* This compilation unit is on the stack in our caller, so we
15581 should not xfree it. Just unlink it. */
15582 cu
->per_cu
->cu
= NULL
;
15585 /* If we had a per-cu pointer, then we may have other compilation
15586 units loaded, so age them now. */
15587 age_cached_comp_units ();
15591 /* Free all cached compilation units. */
15594 free_cached_comp_units (void *data
)
15596 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15598 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15599 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15600 while (per_cu
!= NULL
)
15602 struct dwarf2_per_cu_data
*next_cu
;
15604 next_cu
= per_cu
->cu
->read_in_chain
;
15606 free_one_comp_unit (per_cu
->cu
);
15607 *last_chain
= next_cu
;
15613 /* Increase the age counter on each cached compilation unit, and free
15614 any that are too old. */
15617 age_cached_comp_units (void)
15619 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15621 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
15622 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15623 while (per_cu
!= NULL
)
15625 per_cu
->cu
->last_used
++;
15626 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
15627 dwarf2_mark (per_cu
->cu
);
15628 per_cu
= per_cu
->cu
->read_in_chain
;
15631 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15632 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15633 while (per_cu
!= NULL
)
15635 struct dwarf2_per_cu_data
*next_cu
;
15637 next_cu
= per_cu
->cu
->read_in_chain
;
15639 if (!per_cu
->cu
->mark
)
15641 free_one_comp_unit (per_cu
->cu
);
15642 *last_chain
= next_cu
;
15645 last_chain
= &per_cu
->cu
->read_in_chain
;
15651 /* Remove a single compilation unit from the cache. */
15654 free_one_cached_comp_unit (void *target_cu
)
15656 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15658 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15659 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15660 while (per_cu
!= NULL
)
15662 struct dwarf2_per_cu_data
*next_cu
;
15664 next_cu
= per_cu
->cu
->read_in_chain
;
15666 if (per_cu
->cu
== target_cu
)
15668 free_one_comp_unit (per_cu
->cu
);
15669 *last_chain
= next_cu
;
15673 last_chain
= &per_cu
->cu
->read_in_chain
;
15679 /* Release all extra memory associated with OBJFILE. */
15682 dwarf2_free_objfile (struct objfile
*objfile
)
15684 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15686 if (dwarf2_per_objfile
== NULL
)
15689 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
15690 free_cached_comp_units (NULL
);
15692 if (dwarf2_per_objfile
->quick_file_names_table
)
15693 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
15695 /* Everything else should be on the objfile obstack. */
15698 /* A pair of DIE offset and GDB type pointer. We store these
15699 in a hash table separate from the DIEs, and preserve them
15700 when the DIEs are flushed out of cache. */
15702 struct dwarf2_offset_and_type
15704 unsigned int offset
;
15708 /* Hash function for a dwarf2_offset_and_type. */
15711 offset_and_type_hash (const void *item
)
15713 const struct dwarf2_offset_and_type
*ofs
= item
;
15715 return ofs
->offset
;
15718 /* Equality function for a dwarf2_offset_and_type. */
15721 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
15723 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
15724 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
15726 return ofs_lhs
->offset
== ofs_rhs
->offset
;
15729 /* Set the type associated with DIE to TYPE. Save it in CU's hash
15730 table if necessary. For convenience, return TYPE.
15732 The DIEs reading must have careful ordering to:
15733 * Not cause infite loops trying to read in DIEs as a prerequisite for
15734 reading current DIE.
15735 * Not trying to dereference contents of still incompletely read in types
15736 while reading in other DIEs.
15737 * Enable referencing still incompletely read in types just by a pointer to
15738 the type without accessing its fields.
15740 Therefore caller should follow these rules:
15741 * Try to fetch any prerequisite types we may need to build this DIE type
15742 before building the type and calling set_die_type.
15743 * After building type call set_die_type for current DIE as soon as
15744 possible before fetching more types to complete the current type.
15745 * Make the type as complete as possible before fetching more types. */
15747 static struct type
*
15748 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
15750 struct dwarf2_offset_and_type
**slot
, ofs
;
15751 struct objfile
*objfile
= cu
->objfile
;
15752 htab_t
*type_hash_ptr
;
15754 /* For Ada types, make sure that the gnat-specific data is always
15755 initialized (if not already set). There are a few types where
15756 we should not be doing so, because the type-specific area is
15757 already used to hold some other piece of info (eg: TYPE_CODE_FLT
15758 where the type-specific area is used to store the floatformat).
15759 But this is not a problem, because the gnat-specific information
15760 is actually not needed for these types. */
15761 if (need_gnat_info (cu
)
15762 && TYPE_CODE (type
) != TYPE_CODE_FUNC
15763 && TYPE_CODE (type
) != TYPE_CODE_FLT
15764 && !HAVE_GNAT_AUX_INFO (type
))
15765 INIT_GNAT_SPECIFIC (type
);
15767 if (cu
->per_cu
->debug_type_section
)
15768 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
15770 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
15772 if (*type_hash_ptr
== NULL
)
15775 = htab_create_alloc_ex (127,
15776 offset_and_type_hash
,
15777 offset_and_type_eq
,
15779 &objfile
->objfile_obstack
,
15780 hashtab_obstack_allocate
,
15781 dummy_obstack_deallocate
);
15784 ofs
.offset
= die
->offset
;
15786 slot
= (struct dwarf2_offset_and_type
**)
15787 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
15789 complaint (&symfile_complaints
,
15790 _("A problem internal to GDB: DIE 0x%x has type already set"),
15792 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
15797 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
15798 table, or return NULL if the die does not have a saved type. */
15800 static struct type
*
15801 get_die_type_at_offset (unsigned int offset
,
15802 struct dwarf2_per_cu_data
*per_cu
)
15804 struct dwarf2_offset_and_type
*slot
, ofs
;
15807 if (per_cu
->debug_type_section
)
15808 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
15810 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
15811 if (type_hash
== NULL
)
15814 ofs
.offset
= offset
;
15815 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
15822 /* Look up the type for DIE in the appropriate type_hash table,
15823 or return NULL if DIE does not have a saved type. */
15825 static struct type
*
15826 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15828 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
15831 /* Add a dependence relationship from CU to REF_PER_CU. */
15834 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
15835 struct dwarf2_per_cu_data
*ref_per_cu
)
15839 if (cu
->dependencies
== NULL
)
15841 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
15842 NULL
, &cu
->comp_unit_obstack
,
15843 hashtab_obstack_allocate
,
15844 dummy_obstack_deallocate
);
15846 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
15848 *slot
= ref_per_cu
;
15851 /* Subroutine of dwarf2_mark to pass to htab_traverse.
15852 Set the mark field in every compilation unit in the
15853 cache that we must keep because we are keeping CU. */
15856 dwarf2_mark_helper (void **slot
, void *data
)
15858 struct dwarf2_per_cu_data
*per_cu
;
15860 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
15862 /* cu->dependencies references may not yet have been ever read if QUIT aborts
15863 reading of the chain. As such dependencies remain valid it is not much
15864 useful to track and undo them during QUIT cleanups. */
15865 if (per_cu
->cu
== NULL
)
15868 if (per_cu
->cu
->mark
)
15870 per_cu
->cu
->mark
= 1;
15872 if (per_cu
->cu
->dependencies
!= NULL
)
15873 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15878 /* Set the mark field in CU and in every other compilation unit in the
15879 cache that we must keep because we are keeping CU. */
15882 dwarf2_mark (struct dwarf2_cu
*cu
)
15887 if (cu
->dependencies
!= NULL
)
15888 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15892 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
15896 per_cu
->cu
->mark
= 0;
15897 per_cu
= per_cu
->cu
->read_in_chain
;
15901 /* Trivial hash function for partial_die_info: the hash value of a DIE
15902 is its offset in .debug_info for this objfile. */
15905 partial_die_hash (const void *item
)
15907 const struct partial_die_info
*part_die
= item
;
15909 return part_die
->offset
;
15912 /* Trivial comparison function for partial_die_info structures: two DIEs
15913 are equal if they have the same offset. */
15916 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
15918 const struct partial_die_info
*part_die_lhs
= item_lhs
;
15919 const struct partial_die_info
*part_die_rhs
= item_rhs
;
15921 return part_die_lhs
->offset
== part_die_rhs
->offset
;
15924 static struct cmd_list_element
*set_dwarf2_cmdlist
;
15925 static struct cmd_list_element
*show_dwarf2_cmdlist
;
15928 set_dwarf2_cmd (char *args
, int from_tty
)
15930 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
15934 show_dwarf2_cmd (char *args
, int from_tty
)
15936 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
15939 /* If section described by INFO was mmapped, munmap it now. */
15942 munmap_section_buffer (struct dwarf2_section_info
*info
)
15944 if (info
->map_addr
!= NULL
)
15949 res
= munmap (info
->map_addr
, info
->map_len
);
15950 gdb_assert (res
== 0);
15952 /* Without HAVE_MMAP, we should never be here to begin with. */
15953 gdb_assert_not_reached ("no mmap support");
15958 /* munmap debug sections for OBJFILE, if necessary. */
15961 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
15963 struct dwarf2_per_objfile
*data
= d
;
15965 struct dwarf2_section_info
*section
;
15967 /* This is sorted according to the order they're defined in to make it easier
15968 to keep in sync. */
15969 munmap_section_buffer (&data
->info
);
15970 munmap_section_buffer (&data
->abbrev
);
15971 munmap_section_buffer (&data
->line
);
15972 munmap_section_buffer (&data
->loc
);
15973 munmap_section_buffer (&data
->macinfo
);
15974 munmap_section_buffer (&data
->macro
);
15975 munmap_section_buffer (&data
->str
);
15976 munmap_section_buffer (&data
->ranges
);
15977 munmap_section_buffer (&data
->frame
);
15978 munmap_section_buffer (&data
->eh_frame
);
15979 munmap_section_buffer (&data
->gdb_index
);
15982 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
15984 munmap_section_buffer (section
);
15986 VEC_free (dwarf2_section_info_def
, data
->types
);
15990 /* The "save gdb-index" command. */
15992 /* The contents of the hash table we create when building the string
15994 struct strtab_entry
15996 offset_type offset
;
16000 /* Hash function for a strtab_entry.
16002 Function is used only during write_hash_table so no index format backward
16003 compatibility is needed. */
16006 hash_strtab_entry (const void *e
)
16008 const struct strtab_entry
*entry
= e
;
16009 return mapped_index_string_hash (INT_MAX
, entry
->str
);
16012 /* Equality function for a strtab_entry. */
16015 eq_strtab_entry (const void *a
, const void *b
)
16017 const struct strtab_entry
*ea
= a
;
16018 const struct strtab_entry
*eb
= b
;
16019 return !strcmp (ea
->str
, eb
->str
);
16022 /* Create a strtab_entry hash table. */
16025 create_strtab (void)
16027 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
16028 xfree
, xcalloc
, xfree
);
16031 /* Add a string to the constant pool. Return the string's offset in
16035 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
16038 struct strtab_entry entry
;
16039 struct strtab_entry
*result
;
16042 slot
= htab_find_slot (table
, &entry
, INSERT
);
16047 result
= XNEW (struct strtab_entry
);
16048 result
->offset
= obstack_object_size (cpool
);
16050 obstack_grow_str0 (cpool
, str
);
16053 return result
->offset
;
16056 /* An entry in the symbol table. */
16057 struct symtab_index_entry
16059 /* The name of the symbol. */
16061 /* The offset of the name in the constant pool. */
16062 offset_type index_offset
;
16063 /* A sorted vector of the indices of all the CUs that hold an object
16065 VEC (offset_type
) *cu_indices
;
16068 /* The symbol table. This is a power-of-2-sized hash table. */
16069 struct mapped_symtab
16071 offset_type n_elements
;
16073 struct symtab_index_entry
**data
;
16076 /* Hash function for a symtab_index_entry. */
16079 hash_symtab_entry (const void *e
)
16081 const struct symtab_index_entry
*entry
= e
;
16082 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
16083 sizeof (offset_type
) * VEC_length (offset_type
,
16084 entry
->cu_indices
),
16088 /* Equality function for a symtab_index_entry. */
16091 eq_symtab_entry (const void *a
, const void *b
)
16093 const struct symtab_index_entry
*ea
= a
;
16094 const struct symtab_index_entry
*eb
= b
;
16095 int len
= VEC_length (offset_type
, ea
->cu_indices
);
16096 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
16098 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
16099 VEC_address (offset_type
, eb
->cu_indices
),
16100 sizeof (offset_type
) * len
);
16103 /* Destroy a symtab_index_entry. */
16106 delete_symtab_entry (void *p
)
16108 struct symtab_index_entry
*entry
= p
;
16109 VEC_free (offset_type
, entry
->cu_indices
);
16113 /* Create a hash table holding symtab_index_entry objects. */
16116 create_symbol_hash_table (void)
16118 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
16119 delete_symtab_entry
, xcalloc
, xfree
);
16122 /* Create a new mapped symtab object. */
16124 static struct mapped_symtab
*
16125 create_mapped_symtab (void)
16127 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
16128 symtab
->n_elements
= 0;
16129 symtab
->size
= 1024;
16130 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16134 /* Destroy a mapped_symtab. */
16137 cleanup_mapped_symtab (void *p
)
16139 struct mapped_symtab
*symtab
= p
;
16140 /* The contents of the array are freed when the other hash table is
16142 xfree (symtab
->data
);
16146 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16149 Function is used only during write_hash_table so no index format backward
16150 compatibility is needed. */
16152 static struct symtab_index_entry
**
16153 find_slot (struct mapped_symtab
*symtab
, const char *name
)
16155 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
16157 index
= hash
& (symtab
->size
- 1);
16158 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
16162 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
16163 return &symtab
->data
[index
];
16164 index
= (index
+ step
) & (symtab
->size
- 1);
16168 /* Expand SYMTAB's hash table. */
16171 hash_expand (struct mapped_symtab
*symtab
)
16173 offset_type old_size
= symtab
->size
;
16175 struct symtab_index_entry
**old_entries
= symtab
->data
;
16178 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16180 for (i
= 0; i
< old_size
; ++i
)
16182 if (old_entries
[i
])
16184 struct symtab_index_entry
**slot
= find_slot (symtab
,
16185 old_entries
[i
]->name
);
16186 *slot
= old_entries
[i
];
16190 xfree (old_entries
);
16193 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16194 is the index of the CU in which the symbol appears. */
16197 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
16198 offset_type cu_index
)
16200 struct symtab_index_entry
**slot
;
16202 ++symtab
->n_elements
;
16203 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
16204 hash_expand (symtab
);
16206 slot
= find_slot (symtab
, name
);
16209 *slot
= XNEW (struct symtab_index_entry
);
16210 (*slot
)->name
= name
;
16211 (*slot
)->cu_indices
= NULL
;
16213 /* Don't push an index twice. Due to how we add entries we only
16214 have to check the last one. */
16215 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
16216 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
16217 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
16220 /* Add a vector of indices to the constant pool. */
16223 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
16224 struct symtab_index_entry
*entry
)
16228 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
16231 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
16232 offset_type val
= MAYBE_SWAP (len
);
16237 entry
->index_offset
= obstack_object_size (cpool
);
16239 obstack_grow (cpool
, &val
, sizeof (val
));
16241 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
16244 val
= MAYBE_SWAP (iter
);
16245 obstack_grow (cpool
, &val
, sizeof (val
));
16250 struct symtab_index_entry
*old_entry
= *slot
;
16251 entry
->index_offset
= old_entry
->index_offset
;
16254 return entry
->index_offset
;
16257 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16258 constant pool entries going into the obstack CPOOL. */
16261 write_hash_table (struct mapped_symtab
*symtab
,
16262 struct obstack
*output
, struct obstack
*cpool
)
16265 htab_t symbol_hash_table
;
16268 symbol_hash_table
= create_symbol_hash_table ();
16269 str_table
= create_strtab ();
16271 /* We add all the index vectors to the constant pool first, to
16272 ensure alignment is ok. */
16273 for (i
= 0; i
< symtab
->size
; ++i
)
16275 if (symtab
->data
[i
])
16276 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
16279 /* Now write out the hash table. */
16280 for (i
= 0; i
< symtab
->size
; ++i
)
16282 offset_type str_off
, vec_off
;
16284 if (symtab
->data
[i
])
16286 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
16287 vec_off
= symtab
->data
[i
]->index_offset
;
16291 /* While 0 is a valid constant pool index, it is not valid
16292 to have 0 for both offsets. */
16297 str_off
= MAYBE_SWAP (str_off
);
16298 vec_off
= MAYBE_SWAP (vec_off
);
16300 obstack_grow (output
, &str_off
, sizeof (str_off
));
16301 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
16304 htab_delete (str_table
);
16305 htab_delete (symbol_hash_table
);
16308 /* Struct to map psymtab to CU index in the index file. */
16309 struct psymtab_cu_index_map
16311 struct partial_symtab
*psymtab
;
16312 unsigned int cu_index
;
16316 hash_psymtab_cu_index (const void *item
)
16318 const struct psymtab_cu_index_map
*map
= item
;
16320 return htab_hash_pointer (map
->psymtab
);
16324 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16326 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16327 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16329 return lhs
->psymtab
== rhs
->psymtab
;
16332 /* Helper struct for building the address table. */
16333 struct addrmap_index_data
16335 struct objfile
*objfile
;
16336 struct obstack
*addr_obstack
;
16337 htab_t cu_index_htab
;
16339 /* Non-zero if the previous_* fields are valid.
16340 We can't write an entry until we see the next entry (since it is only then
16341 that we know the end of the entry). */
16342 int previous_valid
;
16343 /* Index of the CU in the table of all CUs in the index file. */
16344 unsigned int previous_cu_index
;
16345 /* Start address of the CU. */
16346 CORE_ADDR previous_cu_start
;
16349 /* Write an address entry to OBSTACK. */
16352 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16353 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16355 offset_type cu_index_to_write
;
16357 CORE_ADDR baseaddr
;
16359 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16361 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16362 obstack_grow (obstack
, addr
, 8);
16363 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16364 obstack_grow (obstack
, addr
, 8);
16365 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16366 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16369 /* Worker function for traversing an addrmap to build the address table. */
16372 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
16374 struct addrmap_index_data
*data
= datap
;
16375 struct partial_symtab
*pst
= obj
;
16376 offset_type cu_index
;
16379 if (data
->previous_valid
)
16380 add_address_entry (data
->objfile
, data
->addr_obstack
,
16381 data
->previous_cu_start
, start_addr
,
16382 data
->previous_cu_index
);
16384 data
->previous_cu_start
= start_addr
;
16387 struct psymtab_cu_index_map find_map
, *map
;
16388 find_map
.psymtab
= pst
;
16389 map
= htab_find (data
->cu_index_htab
, &find_map
);
16390 gdb_assert (map
!= NULL
);
16391 data
->previous_cu_index
= map
->cu_index
;
16392 data
->previous_valid
= 1;
16395 data
->previous_valid
= 0;
16400 /* Write OBJFILE's address map to OBSTACK.
16401 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16402 in the index file. */
16405 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
16406 htab_t cu_index_htab
)
16408 struct addrmap_index_data addrmap_index_data
;
16410 /* When writing the address table, we have to cope with the fact that
16411 the addrmap iterator only provides the start of a region; we have to
16412 wait until the next invocation to get the start of the next region. */
16414 addrmap_index_data
.objfile
= objfile
;
16415 addrmap_index_data
.addr_obstack
= obstack
;
16416 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
16417 addrmap_index_data
.previous_valid
= 0;
16419 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
16420 &addrmap_index_data
);
16422 /* It's highly unlikely the last entry (end address = 0xff...ff)
16423 is valid, but we should still handle it.
16424 The end address is recorded as the start of the next region, but that
16425 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16427 if (addrmap_index_data
.previous_valid
)
16428 add_address_entry (objfile
, obstack
,
16429 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
16430 addrmap_index_data
.previous_cu_index
);
16433 /* Add a list of partial symbols to SYMTAB. */
16436 write_psymbols (struct mapped_symtab
*symtab
,
16438 struct partial_symbol
**psymp
,
16440 offset_type cu_index
,
16443 for (; count
-- > 0; ++psymp
)
16445 void **slot
, *lookup
;
16447 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
16448 error (_("Ada is not currently supported by the index"));
16450 /* We only want to add a given psymbol once. However, we also
16451 want to account for whether it is global or static. So, we
16452 may add it twice, using slightly different values. */
16455 uintptr_t val
= 1 | (uintptr_t) *psymp
;
16457 lookup
= (void *) val
;
16462 /* Only add a given psymbol once. */
16463 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
16467 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
16472 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16473 exception if there is an error. */
16476 write_obstack (FILE *file
, struct obstack
*obstack
)
16478 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
16480 != obstack_object_size (obstack
))
16481 error (_("couldn't data write to file"));
16484 /* Unlink a file if the argument is not NULL. */
16487 unlink_if_set (void *p
)
16489 char **filename
= p
;
16491 unlink (*filename
);
16494 /* A helper struct used when iterating over debug_types. */
16495 struct signatured_type_index_data
16497 struct objfile
*objfile
;
16498 struct mapped_symtab
*symtab
;
16499 struct obstack
*types_list
;
16504 /* A helper function that writes a single signatured_type to an
16508 write_one_signatured_type (void **slot
, void *d
)
16510 struct signatured_type_index_data
*info
= d
;
16511 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
16512 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
16513 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16516 write_psymbols (info
->symtab
,
16518 info
->objfile
->global_psymbols
.list
16519 + psymtab
->globals_offset
,
16520 psymtab
->n_global_syms
, info
->cu_index
,
16522 write_psymbols (info
->symtab
,
16524 info
->objfile
->static_psymbols
.list
16525 + psymtab
->statics_offset
,
16526 psymtab
->n_static_syms
, info
->cu_index
,
16529 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->per_cu
.offset
);
16530 obstack_grow (info
->types_list
, val
, 8);
16531 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
16532 obstack_grow (info
->types_list
, val
, 8);
16533 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
16534 obstack_grow (info
->types_list
, val
, 8);
16541 /* A cleanup function for an htab_t. */
16544 cleanup_htab (void *arg
)
16549 /* Create an index file for OBJFILE in the directory DIR. */
16552 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
16554 struct cleanup
*cleanup
;
16555 char *filename
, *cleanup_filename
;
16556 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
16557 struct obstack cu_list
, types_cu_list
;
16560 struct mapped_symtab
*symtab
;
16561 offset_type val
, size_of_contents
, total_len
;
16565 htab_t cu_index_htab
;
16566 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
16568 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
16571 if (dwarf2_per_objfile
->using_index
)
16572 error (_("Cannot use an index to create the index"));
16574 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
16575 error (_("Cannot make an index when the file has multiple .debug_types sections"));
16577 if (stat (objfile
->name
, &st
) < 0)
16578 perror_with_name (objfile
->name
);
16580 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
16581 INDEX_SUFFIX
, (char *) NULL
);
16582 cleanup
= make_cleanup (xfree
, filename
);
16584 out_file
= fopen (filename
, "wb");
16586 error (_("Can't open `%s' for writing"), filename
);
16588 cleanup_filename
= filename
;
16589 make_cleanup (unlink_if_set
, &cleanup_filename
);
16591 symtab
= create_mapped_symtab ();
16592 make_cleanup (cleanup_mapped_symtab
, symtab
);
16594 obstack_init (&addr_obstack
);
16595 make_cleanup_obstack_free (&addr_obstack
);
16597 obstack_init (&cu_list
);
16598 make_cleanup_obstack_free (&cu_list
);
16600 obstack_init (&types_cu_list
);
16601 make_cleanup_obstack_free (&types_cu_list
);
16603 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
16604 NULL
, xcalloc
, xfree
);
16605 make_cleanup (cleanup_htab
, psyms_seen
);
16607 /* While we're scanning CU's create a table that maps a psymtab pointer
16608 (which is what addrmap records) to its index (which is what is recorded
16609 in the index file). This will later be needed to write the address
16611 cu_index_htab
= htab_create_alloc (100,
16612 hash_psymtab_cu_index
,
16613 eq_psymtab_cu_index
,
16614 NULL
, xcalloc
, xfree
);
16615 make_cleanup (cleanup_htab
, cu_index_htab
);
16616 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
16617 xmalloc (sizeof (struct psymtab_cu_index_map
)
16618 * dwarf2_per_objfile
->n_comp_units
);
16619 make_cleanup (xfree
, psymtab_cu_index_map
);
16621 /* The CU list is already sorted, so we don't need to do additional
16622 work here. Also, the debug_types entries do not appear in
16623 all_comp_units, but only in their own hash table. */
16624 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
16626 struct dwarf2_per_cu_data
*per_cu
16627 = dwarf2_per_objfile
->all_comp_units
[i
];
16628 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16630 struct psymtab_cu_index_map
*map
;
16633 write_psymbols (symtab
,
16635 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
16636 psymtab
->n_global_syms
, i
,
16638 write_psymbols (symtab
,
16640 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
16641 psymtab
->n_static_syms
, i
,
16644 map
= &psymtab_cu_index_map
[i
];
16645 map
->psymtab
= psymtab
;
16647 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
16648 gdb_assert (slot
!= NULL
);
16649 gdb_assert (*slot
== NULL
);
16652 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
16653 obstack_grow (&cu_list
, val
, 8);
16654 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
16655 obstack_grow (&cu_list
, val
, 8);
16658 /* Dump the address map. */
16659 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
16661 /* Write out the .debug_type entries, if any. */
16662 if (dwarf2_per_objfile
->signatured_types
)
16664 struct signatured_type_index_data sig_data
;
16666 sig_data
.objfile
= objfile
;
16667 sig_data
.symtab
= symtab
;
16668 sig_data
.types_list
= &types_cu_list
;
16669 sig_data
.psyms_seen
= psyms_seen
;
16670 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
16671 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
16672 write_one_signatured_type
, &sig_data
);
16675 obstack_init (&constant_pool
);
16676 make_cleanup_obstack_free (&constant_pool
);
16677 obstack_init (&symtab_obstack
);
16678 make_cleanup_obstack_free (&symtab_obstack
);
16679 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
16681 obstack_init (&contents
);
16682 make_cleanup_obstack_free (&contents
);
16683 size_of_contents
= 6 * sizeof (offset_type
);
16684 total_len
= size_of_contents
;
16686 /* The version number. */
16687 val
= MAYBE_SWAP (5);
16688 obstack_grow (&contents
, &val
, sizeof (val
));
16690 /* The offset of the CU list from the start of the file. */
16691 val
= MAYBE_SWAP (total_len
);
16692 obstack_grow (&contents
, &val
, sizeof (val
));
16693 total_len
+= obstack_object_size (&cu_list
);
16695 /* The offset of the types CU list from the start of the file. */
16696 val
= MAYBE_SWAP (total_len
);
16697 obstack_grow (&contents
, &val
, sizeof (val
));
16698 total_len
+= obstack_object_size (&types_cu_list
);
16700 /* The offset of the address table from the start of the file. */
16701 val
= MAYBE_SWAP (total_len
);
16702 obstack_grow (&contents
, &val
, sizeof (val
));
16703 total_len
+= obstack_object_size (&addr_obstack
);
16705 /* The offset of the symbol table from the start of the file. */
16706 val
= MAYBE_SWAP (total_len
);
16707 obstack_grow (&contents
, &val
, sizeof (val
));
16708 total_len
+= obstack_object_size (&symtab_obstack
);
16710 /* The offset of the constant pool from the start of the file. */
16711 val
= MAYBE_SWAP (total_len
);
16712 obstack_grow (&contents
, &val
, sizeof (val
));
16713 total_len
+= obstack_object_size (&constant_pool
);
16715 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
16717 write_obstack (out_file
, &contents
);
16718 write_obstack (out_file
, &cu_list
);
16719 write_obstack (out_file
, &types_cu_list
);
16720 write_obstack (out_file
, &addr_obstack
);
16721 write_obstack (out_file
, &symtab_obstack
);
16722 write_obstack (out_file
, &constant_pool
);
16726 /* We want to keep the file, so we set cleanup_filename to NULL
16727 here. See unlink_if_set. */
16728 cleanup_filename
= NULL
;
16730 do_cleanups (cleanup
);
16733 /* Implementation of the `save gdb-index' command.
16735 Note that the file format used by this command is documented in the
16736 GDB manual. Any changes here must be documented there. */
16739 save_gdb_index_command (char *arg
, int from_tty
)
16741 struct objfile
*objfile
;
16744 error (_("usage: save gdb-index DIRECTORY"));
16746 ALL_OBJFILES (objfile
)
16750 /* If the objfile does not correspond to an actual file, skip it. */
16751 if (stat (objfile
->name
, &st
) < 0)
16754 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16755 if (dwarf2_per_objfile
)
16757 volatile struct gdb_exception except
;
16759 TRY_CATCH (except
, RETURN_MASK_ERROR
)
16761 write_psymtabs_to_index (objfile
, arg
);
16763 if (except
.reason
< 0)
16764 exception_fprintf (gdb_stderr
, except
,
16765 _("Error while writing index for `%s': "),
16773 int dwarf2_always_disassemble
;
16776 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
16777 struct cmd_list_element
*c
, const char *value
)
16779 fprintf_filtered (file
,
16780 _("Whether to always disassemble "
16781 "DWARF expressions is %s.\n"),
16786 show_check_physname (struct ui_file
*file
, int from_tty
,
16787 struct cmd_list_element
*c
, const char *value
)
16789 fprintf_filtered (file
,
16790 _("Whether to check \"physname\" is %s.\n"),
16794 void _initialize_dwarf2_read (void);
16797 _initialize_dwarf2_read (void)
16799 struct cmd_list_element
*c
;
16801 dwarf2_objfile_data_key
16802 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
16804 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
16805 Set DWARF 2 specific variables.\n\
16806 Configure DWARF 2 variables such as the cache size"),
16807 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
16808 0/*allow-unknown*/, &maintenance_set_cmdlist
);
16810 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
16811 Show DWARF 2 specific variables\n\
16812 Show DWARF 2 variables such as the cache size"),
16813 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
16814 0/*allow-unknown*/, &maintenance_show_cmdlist
);
16816 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
16817 &dwarf2_max_cache_age
, _("\
16818 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
16819 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
16820 A higher limit means that cached compilation units will be stored\n\
16821 in memory longer, and more total memory will be used. Zero disables\n\
16822 caching, which can slow down startup."),
16824 show_dwarf2_max_cache_age
,
16825 &set_dwarf2_cmdlist
,
16826 &show_dwarf2_cmdlist
);
16828 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
16829 &dwarf2_always_disassemble
, _("\
16830 Set whether `info address' always disassembles DWARF expressions."), _("\
16831 Show whether `info address' always disassembles DWARF expressions."), _("\
16832 When enabled, DWARF expressions are always printed in an assembly-like\n\
16833 syntax. When disabled, expressions will be printed in a more\n\
16834 conversational style, when possible."),
16836 show_dwarf2_always_disassemble
,
16837 &set_dwarf2_cmdlist
,
16838 &show_dwarf2_cmdlist
);
16840 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
16841 Set debugging of the dwarf2 DIE reader."), _("\
16842 Show debugging of the dwarf2 DIE reader."), _("\
16843 When enabled (non-zero), DIEs are dumped after they are read in.\n\
16844 The value is the maximum depth to print."),
16847 &setdebuglist
, &showdebuglist
);
16849 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
16850 Set cross-checking of \"physname\" code against demangler."), _("\
16851 Show cross-checking of \"physname\" code against demangler."), _("\
16852 When enabled, GDB's internal \"physname\" code is checked against\n\
16854 NULL
, show_check_physname
,
16855 &setdebuglist
, &showdebuglist
);
16857 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
16859 Save a gdb-index file.\n\
16860 Usage: save gdb-index DIRECTORY"),
16862 set_cmd_completer (c
, filename_completer
);