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 /* All offsets in the index are of this type. It must be
149 architecture-independent. */
150 typedef uint32_t offset_type
;
152 DEF_VEC_I (offset_type
);
154 /* A description of the mapped index. The file format is described in
155 a comment by the code that writes the index. */
158 /* Index data format version. */
161 /* The total length of the buffer. */
164 /* A pointer to the address table data. */
165 const gdb_byte
*address_table
;
167 /* Size of the address table data in bytes. */
168 offset_type address_table_size
;
170 /* The symbol table, implemented as a hash table. */
171 const offset_type
*symbol_table
;
173 /* Size in slots, each slot is 2 offset_types. */
174 offset_type symbol_table_slots
;
176 /* A pointer to the constant pool. */
177 const char *constant_pool
;
180 struct dwarf2_per_objfile
182 struct dwarf2_section_info info
;
183 struct dwarf2_section_info abbrev
;
184 struct dwarf2_section_info line
;
185 struct dwarf2_section_info loc
;
186 struct dwarf2_section_info macinfo
;
187 struct dwarf2_section_info str
;
188 struct dwarf2_section_info ranges
;
189 struct dwarf2_section_info types
;
190 struct dwarf2_section_info frame
;
191 struct dwarf2_section_info eh_frame
;
192 struct dwarf2_section_info gdb_index
;
195 struct objfile
*objfile
;
197 /* A list of all the compilation units. This is used to locate
198 the target compilation unit of a particular reference. */
199 struct dwarf2_per_cu_data
**all_comp_units
;
201 /* The number of compilation units in ALL_COMP_UNITS. */
204 /* The number of .debug_types-related CUs. */
205 int n_type_comp_units
;
207 /* The .debug_types-related CUs. */
208 struct dwarf2_per_cu_data
**type_comp_units
;
210 /* A chain of compilation units that are currently read in, so that
211 they can be freed later. */
212 struct dwarf2_per_cu_data
*read_in_chain
;
214 /* A table mapping .debug_types signatures to its signatured_type entry.
215 This is NULL if the .debug_types section hasn't been read in yet. */
216 htab_t signatured_types
;
218 /* A flag indicating wether this objfile has a section loaded at a
220 int has_section_at_zero
;
222 /* True if we are using the mapped index,
223 or we are faking it for OBJF_READNOW's sake. */
224 unsigned char using_index
;
226 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
227 struct mapped_index
*index_table
;
229 /* When using index_table, this keeps track of all quick_file_names entries.
230 TUs can share line table entries with CUs or other TUs, and there can be
231 a lot more TUs than unique line tables, so we maintain a separate table
232 of all line table entries to support the sharing. */
233 htab_t quick_file_names_table
;
235 /* Set during partial symbol reading, to prevent queueing of full
237 int reading_partial_symbols
;
239 /* Table mapping type .debug_info DIE offsets to types.
240 This is NULL if not allocated yet.
241 It (currently) makes sense to allocate debug_types_type_hash lazily.
242 To keep things simple we allocate both lazily. */
243 htab_t debug_info_type_hash
;
245 /* Table mapping type .debug_types DIE offsets to types.
246 This is NULL if not allocated yet. */
247 htab_t debug_types_type_hash
;
250 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
252 /* Default names of the debugging sections. */
254 /* Note that if the debugging section has been compressed, it might
255 have a name like .zdebug_info. */
257 static const struct dwarf2_debug_sections dwarf2_elf_names
= {
258 { ".debug_info", ".zdebug_info" },
259 { ".debug_abbrev", ".zdebug_abbrev" },
260 { ".debug_line", ".zdebug_line" },
261 { ".debug_loc", ".zdebug_loc" },
262 { ".debug_macinfo", ".zdebug_macinfo" },
263 { ".debug_str", ".zdebug_str" },
264 { ".debug_ranges", ".zdebug_ranges" },
265 { ".debug_types", ".zdebug_types" },
266 { ".debug_frame", ".zdebug_frame" },
267 { ".eh_frame", NULL
},
268 { ".gdb_index", ".zgdb_index" }
271 /* local data types */
273 /* We hold several abbreviation tables in memory at the same time. */
274 #ifndef ABBREV_HASH_SIZE
275 #define ABBREV_HASH_SIZE 121
278 /* The data in a compilation unit header, after target2host
279 translation, looks like this. */
280 struct comp_unit_head
284 unsigned char addr_size
;
285 unsigned char signed_addr_p
;
286 unsigned int abbrev_offset
;
288 /* Size of file offsets; either 4 or 8. */
289 unsigned int offset_size
;
291 /* Size of the length field; either 4 or 12. */
292 unsigned int initial_length_size
;
294 /* Offset to the first byte of this compilation unit header in the
295 .debug_info section, for resolving relative reference dies. */
298 /* Offset to first die in this cu from the start of the cu.
299 This will be the first byte following the compilation unit header. */
300 unsigned int first_die_offset
;
303 /* Type used for delaying computation of method physnames.
304 See comments for compute_delayed_physnames. */
305 struct delayed_method_info
307 /* The type to which the method is attached, i.e., its parent class. */
310 /* The index of the method in the type's function fieldlists. */
313 /* The index of the method in the fieldlist. */
316 /* The name of the DIE. */
319 /* The DIE associated with this method. */
320 struct die_info
*die
;
323 typedef struct delayed_method_info delayed_method_info
;
324 DEF_VEC_O (delayed_method_info
);
326 /* Internal state when decoding a particular compilation unit. */
329 /* The objfile containing this compilation unit. */
330 struct objfile
*objfile
;
332 /* The header of the compilation unit. */
333 struct comp_unit_head header
;
335 /* Base address of this compilation unit. */
336 CORE_ADDR base_address
;
338 /* Non-zero if base_address has been set. */
341 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
343 /* The language we are debugging. */
344 enum language language
;
345 const struct language_defn
*language_defn
;
347 const char *producer
;
349 /* The generic symbol table building routines have separate lists for
350 file scope symbols and all all other scopes (local scopes). So
351 we need to select the right one to pass to add_symbol_to_list().
352 We do it by keeping a pointer to the correct list in list_in_scope.
354 FIXME: The original dwarf code just treated the file scope as the
355 first local scope, and all other local scopes as nested local
356 scopes, and worked fine. Check to see if we really need to
357 distinguish these in buildsym.c. */
358 struct pending
**list_in_scope
;
360 /* DWARF abbreviation table associated with this compilation unit. */
361 struct abbrev_info
**dwarf2_abbrevs
;
363 /* Storage for the abbrev table. */
364 struct obstack abbrev_obstack
;
366 /* Hash table holding all the loaded partial DIEs. */
369 /* Storage for things with the same lifetime as this read-in compilation
370 unit, including partial DIEs. */
371 struct obstack comp_unit_obstack
;
373 /* When multiple dwarf2_cu structures are living in memory, this field
374 chains them all together, so that they can be released efficiently.
375 We will probably also want a generation counter so that most-recently-used
376 compilation units are cached... */
377 struct dwarf2_per_cu_data
*read_in_chain
;
379 /* Backchain to our per_cu entry if the tree has been built. */
380 struct dwarf2_per_cu_data
*per_cu
;
382 /* How many compilation units ago was this CU last referenced? */
385 /* A hash table of die offsets for following references. */
388 /* Full DIEs if read in. */
389 struct die_info
*dies
;
391 /* A set of pointers to dwarf2_per_cu_data objects for compilation
392 units referenced by this one. Only set during full symbol processing;
393 partial symbol tables do not have dependencies. */
396 /* Header data from the line table, during full symbol processing. */
397 struct line_header
*line_header
;
399 /* A list of methods which need to have physnames computed
400 after all type information has been read. */
401 VEC (delayed_method_info
) *method_list
;
403 /* Mark used when releasing cached dies. */
404 unsigned int mark
: 1;
406 /* This flag will be set if this compilation unit might include
407 inter-compilation-unit references. */
408 unsigned int has_form_ref_addr
: 1;
410 /* This flag will be set if this compilation unit includes any
411 DW_TAG_namespace DIEs. If we know that there are explicit
412 DIEs for namespaces, we don't need to try to infer them
413 from mangled names. */
414 unsigned int has_namespace_info
: 1;
416 /* This CU references .debug_loc. See the symtab->locations_valid field.
417 This test is imperfect as there may exist optimized debug code not using
418 any location list and still facing inlining issues if handled as
419 unoptimized code. For a future better test see GCC PR other/32998. */
421 unsigned int has_loclist
: 1;
424 /* Persistent data held for a compilation unit, even when not
425 processing it. We put a pointer to this structure in the
426 read_symtab_private field of the psymtab. If we encounter
427 inter-compilation-unit references, we also maintain a sorted
428 list of all compilation units. */
430 struct dwarf2_per_cu_data
432 /* The start offset and length of this compilation unit. 2**29-1
433 bytes should suffice to store the length of any compilation unit
434 - if it doesn't, GDB will fall over anyway.
435 NOTE: Unlike comp_unit_head.length, this length includes
436 initial_length_size. */
438 unsigned int length
: 29;
440 /* Flag indicating this compilation unit will be read in before
441 any of the current compilation units are processed. */
442 unsigned int queued
: 1;
444 /* This flag will be set if we need to load absolutely all DIEs
445 for this compilation unit, instead of just the ones we think
446 are interesting. It gets set if we look for a DIE in the
447 hash table and don't find it. */
448 unsigned int load_all_dies
: 1;
450 /* Non-zero if this CU is from .debug_types.
451 Otherwise it's from .debug_info. */
452 unsigned int from_debug_types
: 1;
454 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
455 of the CU cache it gets reset to NULL again. */
456 struct dwarf2_cu
*cu
;
458 /* The corresponding objfile. */
459 struct objfile
*objfile
;
461 /* When using partial symbol tables, the 'psymtab' field is active.
462 Otherwise the 'quick' field is active. */
465 /* The partial symbol table associated with this compilation unit,
466 or NULL for partial units (which do not have an associated
468 struct partial_symtab
*psymtab
;
470 /* Data needed by the "quick" functions. */
471 struct dwarf2_per_cu_quick_data
*quick
;
475 /* Entry in the signatured_types hash table. */
477 struct signatured_type
481 /* Offset in .debug_types of the type defined by this TU. */
482 unsigned int type_offset
;
484 /* The CU(/TU) of this type. */
485 struct dwarf2_per_cu_data per_cu
;
488 /* Struct used to pass misc. parameters to read_die_and_children, et
489 al. which are used for both .debug_info and .debug_types dies.
490 All parameters here are unchanging for the life of the call. This
491 struct exists to abstract away the constant parameters of die
494 struct die_reader_specs
496 /* The bfd of this objfile. */
499 /* The CU of the DIE we are parsing. */
500 struct dwarf2_cu
*cu
;
502 /* Pointer to start of section buffer.
503 This is either the start of .debug_info or .debug_types. */
504 const gdb_byte
*buffer
;
507 /* The line number information for a compilation unit (found in the
508 .debug_line section) begins with a "statement program header",
509 which contains the following information. */
512 unsigned int total_length
;
513 unsigned short version
;
514 unsigned int header_length
;
515 unsigned char minimum_instruction_length
;
516 unsigned char maximum_ops_per_instruction
;
517 unsigned char default_is_stmt
;
519 unsigned char line_range
;
520 unsigned char opcode_base
;
522 /* standard_opcode_lengths[i] is the number of operands for the
523 standard opcode whose value is i. This means that
524 standard_opcode_lengths[0] is unused, and the last meaningful
525 element is standard_opcode_lengths[opcode_base - 1]. */
526 unsigned char *standard_opcode_lengths
;
528 /* The include_directories table. NOTE! These strings are not
529 allocated with xmalloc; instead, they are pointers into
530 debug_line_buffer. If you try to free them, `free' will get
532 unsigned int num_include_dirs
, include_dirs_size
;
535 /* The file_names table. NOTE! These strings are not allocated
536 with xmalloc; instead, they are pointers into debug_line_buffer.
537 Don't try to free them directly. */
538 unsigned int num_file_names
, file_names_size
;
542 unsigned int dir_index
;
543 unsigned int mod_time
;
545 int included_p
; /* Non-zero if referenced by the Line Number Program. */
546 struct symtab
*symtab
; /* The associated symbol table, if any. */
549 /* The start and end of the statement program following this
550 header. These point into dwarf2_per_objfile->line_buffer. */
551 gdb_byte
*statement_program_start
, *statement_program_end
;
554 /* When we construct a partial symbol table entry we only
555 need this much information. */
556 struct partial_die_info
558 /* Offset of this DIE. */
561 /* DWARF-2 tag for this DIE. */
562 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
564 /* Assorted flags describing the data found in this DIE. */
565 unsigned int has_children
: 1;
566 unsigned int is_external
: 1;
567 unsigned int is_declaration
: 1;
568 unsigned int has_type
: 1;
569 unsigned int has_specification
: 1;
570 unsigned int has_pc_info
: 1;
572 /* Flag set if the SCOPE field of this structure has been
574 unsigned int scope_set
: 1;
576 /* Flag set if the DIE has a byte_size attribute. */
577 unsigned int has_byte_size
: 1;
579 /* Flag set if any of the DIE's children are template arguments. */
580 unsigned int has_template_arguments
: 1;
582 /* Flag set if fixup_partial_die has been called on this die. */
583 unsigned int fixup_called
: 1;
585 /* The name of this DIE. Normally the value of DW_AT_name, but
586 sometimes a default name for unnamed DIEs. */
589 /* The linkage name, if present. */
590 const char *linkage_name
;
592 /* The scope to prepend to our children. This is generally
593 allocated on the comp_unit_obstack, so will disappear
594 when this compilation unit leaves the cache. */
597 /* The location description associated with this DIE, if any. */
598 struct dwarf_block
*locdesc
;
600 /* If HAS_PC_INFO, the PC range associated with this DIE. */
604 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
605 DW_AT_sibling, if any. */
606 /* NOTE: This member isn't strictly necessary, read_partial_die could
607 return DW_AT_sibling values to its caller load_partial_dies. */
610 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
611 DW_AT_specification (or DW_AT_abstract_origin or
613 unsigned int spec_offset
;
615 /* Pointers to this DIE's parent, first child, and next sibling,
617 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
620 /* This data structure holds the information of an abbrev. */
623 unsigned int number
; /* number identifying abbrev */
624 enum dwarf_tag tag
; /* dwarf tag */
625 unsigned short has_children
; /* boolean */
626 unsigned short num_attrs
; /* number of attributes */
627 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
628 struct abbrev_info
*next
; /* next in chain */
633 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
634 ENUM_BITFIELD(dwarf_form
) form
: 16;
637 /* Attributes have a name and a value. */
640 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
641 ENUM_BITFIELD(dwarf_form
) form
: 15;
643 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
644 field should be in u.str (existing only for DW_STRING) but it is kept
645 here for better struct attribute alignment. */
646 unsigned int string_is_canonical
: 1;
651 struct dwarf_block
*blk
;
655 struct signatured_type
*signatured_type
;
660 /* This data structure holds a complete die structure. */
663 /* DWARF-2 tag for this DIE. */
664 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
666 /* Number of attributes */
667 unsigned char num_attrs
;
669 /* True if we're presently building the full type name for the
670 type derived from this DIE. */
671 unsigned char building_fullname
: 1;
676 /* Offset in .debug_info or .debug_types section. */
679 /* The dies in a compilation unit form an n-ary tree. PARENT
680 points to this die's parent; CHILD points to the first child of
681 this node; and all the children of a given node are chained
682 together via their SIBLING fields. */
683 struct die_info
*child
; /* Its first child, if any. */
684 struct die_info
*sibling
; /* Its next sibling, if any. */
685 struct die_info
*parent
; /* Its parent, if any. */
687 /* An array of attributes, with NUM_ATTRS elements. There may be
688 zero, but it's not common and zero-sized arrays are not
689 sufficiently portable C. */
690 struct attribute attrs
[1];
693 struct function_range
696 CORE_ADDR lowpc
, highpc
;
698 struct function_range
*next
;
701 /* Get at parts of an attribute structure. */
703 #define DW_STRING(attr) ((attr)->u.str)
704 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
705 #define DW_UNSND(attr) ((attr)->u.unsnd)
706 #define DW_BLOCK(attr) ((attr)->u.blk)
707 #define DW_SND(attr) ((attr)->u.snd)
708 #define DW_ADDR(attr) ((attr)->u.addr)
709 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
711 /* Blocks are a bunch of untyped bytes. */
718 #ifndef ATTR_ALLOC_CHUNK
719 #define ATTR_ALLOC_CHUNK 4
722 /* Allocate fields for structs, unions and enums in this size. */
723 #ifndef DW_FIELD_ALLOC_CHUNK
724 #define DW_FIELD_ALLOC_CHUNK 4
727 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
728 but this would require a corresponding change in unpack_field_as_long
730 static int bits_per_byte
= 8;
732 /* The routines that read and process dies for a C struct or C++ class
733 pass lists of data member fields and lists of member function fields
734 in an instance of a field_info structure, as defined below. */
737 /* List of data member and baseclasses fields. */
740 struct nextfield
*next
;
745 *fields
, *baseclasses
;
747 /* Number of fields (including baseclasses). */
750 /* Number of baseclasses. */
753 /* Set if the accesibility of one of the fields is not public. */
754 int non_public_fields
;
756 /* Member function fields array, entries are allocated in the order they
757 are encountered in the object file. */
760 struct nextfnfield
*next
;
761 struct fn_field fnfield
;
765 /* Member function fieldlist array, contains name of possibly overloaded
766 member function, number of overloaded member functions and a pointer
767 to the head of the member function field chain. */
772 struct nextfnfield
*head
;
776 /* Number of entries in the fnfieldlists array. */
779 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
780 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
781 struct typedef_field_list
783 struct typedef_field field
;
784 struct typedef_field_list
*next
;
787 unsigned typedef_field_list_count
;
790 /* One item on the queue of compilation units to read in full symbols
792 struct dwarf2_queue_item
794 struct dwarf2_per_cu_data
*per_cu
;
795 struct dwarf2_queue_item
*next
;
798 /* The current queue. */
799 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
801 /* Loaded secondary compilation units are kept in memory until they
802 have not been referenced for the processing of this many
803 compilation units. Set this to zero to disable caching. Cache
804 sizes of up to at least twenty will improve startup time for
805 typical inter-CU-reference binaries, at an obvious memory cost. */
806 static int dwarf2_max_cache_age
= 5;
808 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
809 struct cmd_list_element
*c
, const char *value
)
811 fprintf_filtered (file
, _("The upper bound on the age of cached "
812 "dwarf2 compilation units is %s.\n"),
817 /* Various complaints about symbol reading that don't abort the process. */
820 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
822 complaint (&symfile_complaints
,
823 _("statement list doesn't fit in .debug_line section"));
827 dwarf2_debug_line_missing_file_complaint (void)
829 complaint (&symfile_complaints
,
830 _(".debug_line section has line data without a file"));
834 dwarf2_debug_line_missing_end_sequence_complaint (void)
836 complaint (&symfile_complaints
,
837 _(".debug_line section has line "
838 "program sequence without an end"));
842 dwarf2_complex_location_expr_complaint (void)
844 complaint (&symfile_complaints
, _("location expression too complex"));
848 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
851 complaint (&symfile_complaints
,
852 _("const value length mismatch for '%s', got %d, expected %d"),
857 dwarf2_macros_too_long_complaint (void)
859 complaint (&symfile_complaints
,
860 _("macro info runs off end of `.debug_macinfo' section"));
864 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
866 complaint (&symfile_complaints
,
867 _("macro debug info contains a "
868 "malformed macro definition:\n`%s'"),
873 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
875 complaint (&symfile_complaints
,
876 _("invalid attribute class or form for '%s' in '%s'"),
880 /* local function prototypes */
882 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
884 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
887 static void dwarf2_build_psymtabs_hard (struct objfile
*);
889 static void scan_partial_symbols (struct partial_die_info
*,
890 CORE_ADDR
*, CORE_ADDR
*,
891 int, struct dwarf2_cu
*);
893 static void add_partial_symbol (struct partial_die_info
*,
896 static void add_partial_namespace (struct partial_die_info
*pdi
,
897 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
898 int need_pc
, struct dwarf2_cu
*cu
);
900 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
901 CORE_ADDR
*highpc
, int need_pc
,
902 struct dwarf2_cu
*cu
);
904 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
905 struct dwarf2_cu
*cu
);
907 static void add_partial_subprogram (struct partial_die_info
*pdi
,
908 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
909 int need_pc
, struct dwarf2_cu
*cu
);
911 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
912 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
913 bfd
*abfd
, struct dwarf2_cu
*cu
);
915 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
917 static void psymtab_to_symtab_1 (struct partial_symtab
*);
919 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
921 static void dwarf2_free_abbrev_table (void *);
923 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
926 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
929 static struct partial_die_info
*load_partial_dies (bfd
*,
930 gdb_byte
*, gdb_byte
*,
931 int, struct dwarf2_cu
*);
933 static gdb_byte
*read_partial_die (struct partial_die_info
*,
934 struct abbrev_info
*abbrev
,
936 gdb_byte
*, gdb_byte
*,
939 static struct partial_die_info
*find_partial_die (unsigned int,
942 static void fixup_partial_die (struct partial_die_info
*,
945 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
946 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
948 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
949 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
951 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
953 static int read_1_signed_byte (bfd
*, gdb_byte
*);
955 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
957 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
959 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
961 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
964 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
966 static LONGEST read_checked_initial_length_and_offset
967 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
968 unsigned int *, unsigned int *);
970 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
973 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
975 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
977 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
979 static char *read_indirect_string (bfd
*, gdb_byte
*,
980 const struct comp_unit_head
*,
983 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
985 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
987 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
989 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
991 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
994 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
998 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
999 struct dwarf2_cu
*cu
);
1001 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1003 static struct die_info
*die_specification (struct die_info
*die
,
1004 struct dwarf2_cu
**);
1006 static void free_line_header (struct line_header
*lh
);
1008 static void add_file_name (struct line_header
*, char *, unsigned int,
1009 unsigned int, unsigned int);
1011 static struct line_header
*(dwarf_decode_line_header
1012 (unsigned int offset
,
1013 bfd
*abfd
, struct dwarf2_cu
*cu
));
1015 static void dwarf_decode_lines (struct line_header
*, const char *, bfd
*,
1016 struct dwarf2_cu
*, struct partial_symtab
*);
1018 static void dwarf2_start_subfile (char *, const char *, const char *);
1020 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1021 struct dwarf2_cu
*);
1023 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1024 struct dwarf2_cu
*, struct symbol
*);
1026 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1027 struct dwarf2_cu
*);
1029 static void dwarf2_const_value_attr (struct attribute
*attr
,
1032 struct obstack
*obstack
,
1033 struct dwarf2_cu
*cu
, long *value
,
1035 struct dwarf2_locexpr_baton
**baton
);
1037 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1039 static int need_gnat_info (struct dwarf2_cu
*);
1041 static struct type
*die_descriptive_type (struct die_info
*,
1042 struct dwarf2_cu
*);
1044 static void set_descriptive_type (struct type
*, struct die_info
*,
1045 struct dwarf2_cu
*);
1047 static struct type
*die_containing_type (struct die_info
*,
1048 struct dwarf2_cu
*);
1050 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1051 struct dwarf2_cu
*);
1053 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1055 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1057 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1059 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1060 const char *suffix
, int physname
,
1061 struct dwarf2_cu
*cu
);
1063 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1065 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1067 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1069 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1071 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1072 struct dwarf2_cu
*, struct partial_symtab
*);
1074 static int dwarf2_get_pc_bounds (struct die_info
*,
1075 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1076 struct partial_symtab
*);
1078 static void get_scope_pc_bounds (struct die_info
*,
1079 CORE_ADDR
*, CORE_ADDR
*,
1080 struct dwarf2_cu
*);
1082 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1083 CORE_ADDR
, struct dwarf2_cu
*);
1085 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1086 struct dwarf2_cu
*);
1088 static void dwarf2_attach_fields_to_type (struct field_info
*,
1089 struct type
*, struct dwarf2_cu
*);
1091 static void dwarf2_add_member_fn (struct field_info
*,
1092 struct die_info
*, struct type
*,
1093 struct dwarf2_cu
*);
1095 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1097 struct dwarf2_cu
*);
1099 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1101 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1103 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1105 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1107 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1109 static struct type
*read_module_type (struct die_info
*die
,
1110 struct dwarf2_cu
*cu
);
1112 static const char *namespace_name (struct die_info
*die
,
1113 int *is_anonymous
, struct dwarf2_cu
*);
1115 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1117 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1119 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1120 struct dwarf2_cu
*);
1122 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1124 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1126 gdb_byte
**new_info_ptr
,
1127 struct die_info
*parent
);
1129 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1131 gdb_byte
**new_info_ptr
,
1132 struct die_info
*parent
);
1134 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1136 gdb_byte
**new_info_ptr
,
1137 struct die_info
*parent
);
1139 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1140 struct die_info
**, gdb_byte
*,
1143 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1145 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1148 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1150 static const char *dwarf2_full_name (char *name
,
1151 struct die_info
*die
,
1152 struct dwarf2_cu
*cu
);
1154 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1155 struct dwarf2_cu
**);
1157 static char *dwarf_tag_name (unsigned int);
1159 static char *dwarf_attr_name (unsigned int);
1161 static char *dwarf_form_name (unsigned int);
1163 static char *dwarf_bool_name (unsigned int);
1165 static char *dwarf_type_encoding_name (unsigned int);
1168 static char *dwarf_cfi_name (unsigned int);
1171 static struct die_info
*sibling_die (struct die_info
*);
1173 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1175 static void dump_die_for_error (struct die_info
*);
1177 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1180 /*static*/ void dump_die (struct die_info
*, int max_level
);
1182 static void store_in_ref_table (struct die_info
*,
1183 struct dwarf2_cu
*);
1185 static int is_ref_attr (struct attribute
*);
1187 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1189 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1191 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1193 struct dwarf2_cu
**);
1195 static struct die_info
*follow_die_ref (struct die_info
*,
1197 struct dwarf2_cu
**);
1199 static struct die_info
*follow_die_sig (struct die_info
*,
1201 struct dwarf2_cu
**);
1203 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1204 unsigned int offset
);
1206 static void read_signatured_type (struct objfile
*,
1207 struct signatured_type
*type_sig
);
1209 /* memory allocation interface */
1211 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1213 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1215 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1217 static void initialize_cu_func_list (struct dwarf2_cu
*);
1219 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1220 struct dwarf2_cu
*);
1222 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1223 char *, bfd
*, struct dwarf2_cu
*);
1225 static int attr_form_is_block (struct attribute
*);
1227 static int attr_form_is_section_offset (struct attribute
*);
1229 static int attr_form_is_constant (struct attribute
*);
1231 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1232 struct dwarf2_loclist_baton
*baton
,
1233 struct attribute
*attr
);
1235 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1237 struct dwarf2_cu
*cu
);
1239 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1240 struct abbrev_info
*abbrev
,
1241 struct dwarf2_cu
*cu
);
1243 static void free_stack_comp_unit (void *);
1245 static hashval_t
partial_die_hash (const void *item
);
1247 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1249 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1250 (unsigned int offset
, struct objfile
*objfile
);
1252 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1253 (unsigned int offset
, struct objfile
*objfile
);
1255 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1256 struct objfile
*objfile
);
1258 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1259 struct die_info
*comp_unit_die
);
1261 static void free_one_comp_unit (void *);
1263 static void free_cached_comp_units (void *);
1265 static void age_cached_comp_units (void);
1267 static void free_one_cached_comp_unit (void *);
1269 static struct type
*set_die_type (struct die_info
*, struct type
*,
1270 struct dwarf2_cu
*);
1272 static void create_all_comp_units (struct objfile
*);
1274 static int create_debug_types_hash_table (struct objfile
*objfile
);
1276 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1279 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1281 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1282 struct dwarf2_per_cu_data
*);
1284 static void dwarf2_mark (struct dwarf2_cu
*);
1286 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1288 static struct type
*get_die_type_at_offset (unsigned int,
1289 struct dwarf2_per_cu_data
*per_cu
);
1291 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1293 static void dwarf2_release_queue (void *dummy
);
1295 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1296 struct objfile
*objfile
);
1298 static void process_queue (struct objfile
*objfile
);
1300 static void find_file_and_directory (struct die_info
*die
,
1301 struct dwarf2_cu
*cu
,
1302 char **name
, char **comp_dir
);
1304 static char *file_full_name (int file
, struct line_header
*lh
,
1305 const char *comp_dir
);
1307 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1310 unsigned int buffer_size
,
1313 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1314 struct dwarf2_cu
*cu
);
1316 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1320 /* Convert VALUE between big- and little-endian. */
1322 byte_swap (offset_type value
)
1326 result
= (value
& 0xff) << 24;
1327 result
|= (value
& 0xff00) << 8;
1328 result
|= (value
& 0xff0000) >> 8;
1329 result
|= (value
& 0xff000000) >> 24;
1333 #define MAYBE_SWAP(V) byte_swap (V)
1336 #define MAYBE_SWAP(V) (V)
1337 #endif /* WORDS_BIGENDIAN */
1339 /* The suffix for an index file. */
1340 #define INDEX_SUFFIX ".gdb-index"
1342 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1343 struct dwarf2_cu
*cu
);
1345 /* Try to locate the sections we need for DWARF 2 debugging
1346 information and return true if we have enough to do something.
1347 NAMES points to the dwarf2 section names, or is NULL if the standard
1348 ELF names are used. */
1351 dwarf2_has_info (struct objfile
*objfile
,
1352 const struct dwarf2_debug_sections
*names
)
1354 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1355 if (!dwarf2_per_objfile
)
1357 /* Initialize per-objfile state. */
1358 struct dwarf2_per_objfile
*data
1359 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1361 memset (data
, 0, sizeof (*data
));
1362 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1363 dwarf2_per_objfile
= data
;
1365 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1367 dwarf2_per_objfile
->objfile
= objfile
;
1369 return (dwarf2_per_objfile
->info
.asection
!= NULL
1370 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1373 /* When loading sections, we look either for uncompressed section or for
1374 compressed section names. */
1377 section_is_p (const char *section_name
,
1378 const struct dwarf2_section_names
*names
)
1380 if (names
->normal
!= NULL
1381 && strcmp (section_name
, names
->normal
) == 0)
1383 if (names
->compressed
!= NULL
1384 && strcmp (section_name
, names
->compressed
) == 0)
1389 /* This function is mapped across the sections and remembers the
1390 offset and size of each of the debugging sections we are interested
1394 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1396 const struct dwarf2_debug_sections
*names
;
1399 names
= &dwarf2_elf_names
;
1401 names
= (const struct dwarf2_debug_sections
*) vnames
;
1403 if (section_is_p (sectp
->name
, &names
->info
))
1405 dwarf2_per_objfile
->info
.asection
= sectp
;
1406 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1408 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1410 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1411 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1413 else if (section_is_p (sectp
->name
, &names
->line
))
1415 dwarf2_per_objfile
->line
.asection
= sectp
;
1416 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1418 else if (section_is_p (sectp
->name
, &names
->loc
))
1420 dwarf2_per_objfile
->loc
.asection
= sectp
;
1421 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1423 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1425 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1426 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1428 else if (section_is_p (sectp
->name
, &names
->str
))
1430 dwarf2_per_objfile
->str
.asection
= sectp
;
1431 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1433 else if (section_is_p (sectp
->name
, &names
->frame
))
1435 dwarf2_per_objfile
->frame
.asection
= sectp
;
1436 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1438 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1440 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1442 if (aflag
& SEC_HAS_CONTENTS
)
1444 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1445 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1448 else if (section_is_p (sectp
->name
, &names
->ranges
))
1450 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1451 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1453 else if (section_is_p (sectp
->name
, &names
->types
))
1455 dwarf2_per_objfile
->types
.asection
= sectp
;
1456 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1458 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1460 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1461 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1464 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1465 && bfd_section_vma (abfd
, sectp
) == 0)
1466 dwarf2_per_objfile
->has_section_at_zero
= 1;
1469 /* Decompress a section that was compressed using zlib. Store the
1470 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1473 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1474 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1476 bfd
*abfd
= objfile
->obfd
;
1478 error (_("Support for zlib-compressed DWARF data (from '%s') "
1479 "is disabled in this copy of GDB"),
1480 bfd_get_filename (abfd
));
1482 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1483 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1484 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1485 bfd_size_type uncompressed_size
;
1486 gdb_byte
*uncompressed_buffer
;
1489 int header_size
= 12;
1491 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1492 || bfd_bread (compressed_buffer
,
1493 compressed_size
, abfd
) != compressed_size
)
1494 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1495 bfd_get_filename (abfd
));
1497 /* Read the zlib header. In this case, it should be "ZLIB" followed
1498 by the uncompressed section size, 8 bytes in big-endian order. */
1499 if (compressed_size
< header_size
1500 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1501 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1502 bfd_get_filename (abfd
));
1503 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1504 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1505 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1506 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1507 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1508 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1509 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1510 uncompressed_size
+= compressed_buffer
[11];
1512 /* It is possible the section consists of several compressed
1513 buffers concatenated together, so we uncompress in a loop. */
1517 strm
.avail_in
= compressed_size
- header_size
;
1518 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1519 strm
.avail_out
= uncompressed_size
;
1520 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1522 rc
= inflateInit (&strm
);
1523 while (strm
.avail_in
> 0)
1526 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1527 bfd_get_filename (abfd
), rc
);
1528 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1529 + (uncompressed_size
- strm
.avail_out
));
1530 rc
= inflate (&strm
, Z_FINISH
);
1531 if (rc
!= Z_STREAM_END
)
1532 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1533 bfd_get_filename (abfd
), rc
);
1534 rc
= inflateReset (&strm
);
1536 rc
= inflateEnd (&strm
);
1538 || strm
.avail_out
!= 0)
1539 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1540 bfd_get_filename (abfd
), rc
);
1542 do_cleanups (cleanup
);
1543 *outbuf
= uncompressed_buffer
;
1544 *outsize
= uncompressed_size
;
1548 /* A helper function that decides whether a section is empty. */
1551 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1553 return info
->asection
== NULL
|| info
->size
== 0;
1556 /* Read the contents of the section SECTP from object file specified by
1557 OBJFILE, store info about the section into INFO.
1558 If the section is compressed, uncompress it before returning. */
1561 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1563 bfd
*abfd
= objfile
->obfd
;
1564 asection
*sectp
= info
->asection
;
1565 gdb_byte
*buf
, *retbuf
;
1566 unsigned char header
[4];
1570 info
->buffer
= NULL
;
1571 info
->map_addr
= NULL
;
1574 if (dwarf2_section_empty_p (info
))
1577 /* Check if the file has a 4-byte header indicating compression. */
1578 if (info
->size
> sizeof (header
)
1579 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1580 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1582 /* Upon decompression, update the buffer and its size. */
1583 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1585 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1593 pagesize
= getpagesize ();
1595 /* Only try to mmap sections which are large enough: we don't want to
1596 waste space due to fragmentation. Also, only try mmap for sections
1597 without relocations. */
1599 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1601 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1602 MAP_PRIVATE
, sectp
->filepos
,
1603 &info
->map_addr
, &info
->map_len
);
1605 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1607 #if HAVE_POSIX_MADVISE
1608 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1615 /* If we get here, we are a normal, not-compressed section. */
1617 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1619 /* When debugging .o files, we may need to apply relocations; see
1620 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1621 We never compress sections in .o files, so we only need to
1622 try this when the section is not compressed. */
1623 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1626 info
->buffer
= retbuf
;
1630 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1631 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1632 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1633 bfd_get_filename (abfd
));
1636 /* A helper function that returns the size of a section in a safe way.
1637 If you are positive that the section has been read before using the
1638 size, then it is safe to refer to the dwarf2_section_info object's
1639 "size" field directly. In other cases, you must call this
1640 function, because for compressed sections the size field is not set
1641 correctly until the section has been read. */
1643 static bfd_size_type
1644 dwarf2_section_size (struct objfile
*objfile
,
1645 struct dwarf2_section_info
*info
)
1648 dwarf2_read_section (objfile
, info
);
1652 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1656 dwarf2_get_section_info (struct objfile
*objfile
,
1657 enum dwarf2_section_enum sect
,
1658 asection
**sectp
, gdb_byte
**bufp
,
1659 bfd_size_type
*sizep
)
1661 struct dwarf2_per_objfile
*data
1662 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1663 struct dwarf2_section_info
*info
;
1665 /* We may see an objfile without any DWARF, in which case we just
1676 case DWARF2_DEBUG_FRAME
:
1677 info
= &data
->frame
;
1679 case DWARF2_EH_FRAME
:
1680 info
= &data
->eh_frame
;
1683 gdb_assert_not_reached ("unexpected section");
1686 dwarf2_read_section (objfile
, info
);
1688 *sectp
= info
->asection
;
1689 *bufp
= info
->buffer
;
1690 *sizep
= info
->size
;
1694 /* DWARF quick_symbols_functions support. */
1696 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1697 unique line tables, so we maintain a separate table of all .debug_line
1698 derived entries to support the sharing.
1699 All the quick functions need is the list of file names. We discard the
1700 line_header when we're done and don't need to record it here. */
1701 struct quick_file_names
1703 /* The offset in .debug_line of the line table. We hash on this. */
1704 unsigned int offset
;
1706 /* The number of entries in file_names, real_names. */
1707 unsigned int num_file_names
;
1709 /* The file names from the line table, after being run through
1711 const char **file_names
;
1713 /* The file names from the line table after being run through
1714 gdb_realpath. These are computed lazily. */
1715 const char **real_names
;
1718 /* When using the index (and thus not using psymtabs), each CU has an
1719 object of this type. This is used to hold information needed by
1720 the various "quick" methods. */
1721 struct dwarf2_per_cu_quick_data
1723 /* The file table. This can be NULL if there was no file table
1724 or it's currently not read in.
1725 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1726 struct quick_file_names
*file_names
;
1728 /* The corresponding symbol table. This is NULL if symbols for this
1729 CU have not yet been read. */
1730 struct symtab
*symtab
;
1732 /* A temporary mark bit used when iterating over all CUs in
1733 expand_symtabs_matching. */
1734 unsigned int mark
: 1;
1736 /* True if we've tried to read the file table and found there isn't one.
1737 There will be no point in trying to read it again next time. */
1738 unsigned int no_file_data
: 1;
1741 /* Hash function for a quick_file_names. */
1744 hash_file_name_entry (const void *e
)
1746 const struct quick_file_names
*file_data
= e
;
1748 return file_data
->offset
;
1751 /* Equality function for a quick_file_names. */
1754 eq_file_name_entry (const void *a
, const void *b
)
1756 const struct quick_file_names
*ea
= a
;
1757 const struct quick_file_names
*eb
= b
;
1759 return ea
->offset
== eb
->offset
;
1762 /* Delete function for a quick_file_names. */
1765 delete_file_name_entry (void *e
)
1767 struct quick_file_names
*file_data
= e
;
1770 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1772 xfree ((void*) file_data
->file_names
[i
]);
1773 if (file_data
->real_names
)
1774 xfree ((void*) file_data
->real_names
[i
]);
1777 /* The space for the struct itself lives on objfile_obstack,
1778 so we don't free it here. */
1781 /* Create a quick_file_names hash table. */
1784 create_quick_file_names_table (unsigned int nr_initial_entries
)
1786 return htab_create_alloc (nr_initial_entries
,
1787 hash_file_name_entry
, eq_file_name_entry
,
1788 delete_file_name_entry
, xcalloc
, xfree
);
1791 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1795 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1796 struct dwarf2_per_cu_data
*per_cu
)
1798 struct cleanup
*back_to
;
1800 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1802 queue_comp_unit (per_cu
, objfile
);
1804 if (per_cu
->from_debug_types
)
1805 read_signatured_type_at_offset (objfile
, per_cu
->offset
);
1807 load_full_comp_unit (per_cu
, objfile
);
1809 process_queue (objfile
);
1811 /* Age the cache, releasing compilation units that have not
1812 been used recently. */
1813 age_cached_comp_units ();
1815 do_cleanups (back_to
);
1818 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1819 the objfile from which this CU came. Returns the resulting symbol
1822 static struct symtab
*
1823 dw2_instantiate_symtab (struct objfile
*objfile
,
1824 struct dwarf2_per_cu_data
*per_cu
)
1826 if (!per_cu
->v
.quick
->symtab
)
1828 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1829 increment_reading_symtab ();
1830 dw2_do_instantiate_symtab (objfile
, per_cu
);
1831 do_cleanups (back_to
);
1833 return per_cu
->v
.quick
->symtab
;
1836 /* Return the CU given its index. */
1838 static struct dwarf2_per_cu_data
*
1839 dw2_get_cu (int index
)
1841 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1843 index
-= dwarf2_per_objfile
->n_comp_units
;
1844 return dwarf2_per_objfile
->type_comp_units
[index
];
1846 return dwarf2_per_objfile
->all_comp_units
[index
];
1849 /* A helper function that knows how to read a 64-bit value in a way
1850 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1854 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1856 if (sizeof (ULONGEST
) < 8)
1860 /* Ignore the upper 4 bytes if they are all zero. */
1861 for (i
= 0; i
< 4; ++i
)
1862 if (bytes
[i
+ 4] != 0)
1865 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1868 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1872 /* Read the CU list from the mapped index, and use it to create all
1873 the CU objects for this objfile. Return 0 if something went wrong,
1874 1 if everything went ok. */
1877 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1878 offset_type cu_list_elements
)
1882 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1883 dwarf2_per_objfile
->all_comp_units
1884 = obstack_alloc (&objfile
->objfile_obstack
,
1885 dwarf2_per_objfile
->n_comp_units
1886 * sizeof (struct dwarf2_per_cu_data
*));
1888 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1890 struct dwarf2_per_cu_data
*the_cu
;
1891 ULONGEST offset
, length
;
1893 if (!extract_cu_value (cu_list
, &offset
)
1894 || !extract_cu_value (cu_list
+ 8, &length
))
1898 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1899 struct dwarf2_per_cu_data
);
1900 the_cu
->offset
= offset
;
1901 the_cu
->length
= length
;
1902 the_cu
->objfile
= objfile
;
1903 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1904 struct dwarf2_per_cu_quick_data
);
1905 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1911 /* Create the signatured type hash table from the index. */
1914 create_signatured_type_table_from_index (struct objfile
*objfile
,
1915 const gdb_byte
*bytes
,
1916 offset_type elements
)
1919 htab_t sig_types_hash
;
1921 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1922 dwarf2_per_objfile
->type_comp_units
1923 = obstack_alloc (&objfile
->objfile_obstack
,
1924 dwarf2_per_objfile
->n_type_comp_units
1925 * sizeof (struct dwarf2_per_cu_data
*));
1927 sig_types_hash
= allocate_signatured_type_table (objfile
);
1929 for (i
= 0; i
< elements
; i
+= 3)
1931 struct signatured_type
*type_sig
;
1932 ULONGEST offset
, type_offset
, signature
;
1935 if (!extract_cu_value (bytes
, &offset
)
1936 || !extract_cu_value (bytes
+ 8, &type_offset
))
1938 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1941 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1942 struct signatured_type
);
1943 type_sig
->signature
= signature
;
1944 type_sig
->type_offset
= type_offset
;
1945 type_sig
->per_cu
.from_debug_types
= 1;
1946 type_sig
->per_cu
.offset
= offset
;
1947 type_sig
->per_cu
.objfile
= objfile
;
1948 type_sig
->per_cu
.v
.quick
1949 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1950 struct dwarf2_per_cu_quick_data
);
1952 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1955 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1958 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1963 /* Read the address map data from the mapped index, and use it to
1964 populate the objfile's psymtabs_addrmap. */
1967 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1969 const gdb_byte
*iter
, *end
;
1970 struct obstack temp_obstack
;
1971 struct addrmap
*mutable_map
;
1972 struct cleanup
*cleanup
;
1975 obstack_init (&temp_obstack
);
1976 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1977 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1979 iter
= index
->address_table
;
1980 end
= iter
+ index
->address_table_size
;
1982 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1986 ULONGEST hi
, lo
, cu_index
;
1987 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1989 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1991 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1994 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1995 dw2_get_cu (cu_index
));
1998 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1999 &objfile
->objfile_obstack
);
2000 do_cleanups (cleanup
);
2003 /* The hash function for strings in the mapped index. This is the same as
2004 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2005 implementation. This is necessary because the hash function is tied to the
2006 format of the mapped index file. The hash values do not have to match with
2009 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2012 mapped_index_string_hash (int index_version
, const void *p
)
2014 const unsigned char *str
= (const unsigned char *) p
;
2018 while ((c
= *str
++) != 0)
2020 if (index_version
>= 5)
2022 r
= r
* 67 + c
- 113;
2028 /* Find a slot in the mapped index INDEX for the object named NAME.
2029 If NAME is found, set *VEC_OUT to point to the CU vector in the
2030 constant pool and return 1. If NAME cannot be found, return 0. */
2033 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2034 offset_type
**vec_out
)
2036 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2038 offset_type slot
, step
;
2039 int (*cmp
) (const char *, const char *);
2041 if (current_language
->la_language
== language_cplus
2042 || current_language
->la_language
== language_java
2043 || current_language
->la_language
== language_fortran
)
2045 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2047 const char *paren
= strchr (name
, '(');
2053 dup
= xmalloc (paren
- name
+ 1);
2054 memcpy (dup
, name
, paren
- name
);
2055 dup
[paren
- name
] = 0;
2057 make_cleanup (xfree
, dup
);
2062 /* Index version 4 did not support case insensitive searches. But the
2063 indexes for case insensitive languages are built in lowercase, therefore
2064 simulate our NAME being searched is also lowercased. */
2065 hash
= mapped_index_string_hash ((index
->version
== 4
2066 && case_sensitivity
== case_sensitive_off
2067 ? 5 : index
->version
),
2070 slot
= hash
& (index
->symbol_table_slots
- 1);
2071 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2072 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2076 /* Convert a slot number to an offset into the table. */
2077 offset_type i
= 2 * slot
;
2079 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2081 do_cleanups (back_to
);
2085 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2086 if (!cmp (name
, str
))
2088 *vec_out
= (offset_type
*) (index
->constant_pool
2089 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2090 do_cleanups (back_to
);
2094 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2098 /* Read the index file. If everything went ok, initialize the "quick"
2099 elements of all the CUs and return 1. Otherwise, return 0. */
2102 dwarf2_read_index (struct objfile
*objfile
)
2105 struct mapped_index
*map
;
2106 offset_type
*metadata
;
2107 const gdb_byte
*cu_list
;
2108 const gdb_byte
*types_list
= NULL
;
2109 offset_type version
, cu_list_elements
;
2110 offset_type types_list_elements
= 0;
2113 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2116 /* Older elfutils strip versions could keep the section in the main
2117 executable while splitting it for the separate debug info file. */
2118 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2119 & SEC_HAS_CONTENTS
) == 0)
2122 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2124 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2125 /* Version check. */
2126 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2127 /* Versions earlier than 3 emitted every copy of a psymbol. This
2128 causes the index to behave very poorly for certain requests. Version 3
2129 contained incomplete addrmap. So, it seems better to just ignore such
2130 indices. Index version 4 uses a different hash function than index
2131 version 5 and later. */
2134 /* Indexes with higher version than the one supported by GDB may be no
2135 longer backward compatible. */
2139 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2140 map
->version
= version
;
2141 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2143 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2146 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2147 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2151 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2152 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2153 - MAYBE_SWAP (metadata
[i
]))
2157 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2158 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2159 - MAYBE_SWAP (metadata
[i
]));
2162 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2163 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2164 - MAYBE_SWAP (metadata
[i
]))
2165 / (2 * sizeof (offset_type
)));
2168 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2170 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2173 if (types_list_elements
2174 && !create_signatured_type_table_from_index (objfile
, types_list
,
2175 types_list_elements
))
2178 create_addrmap_from_index (objfile
, map
);
2180 dwarf2_per_objfile
->index_table
= map
;
2181 dwarf2_per_objfile
->using_index
= 1;
2182 dwarf2_per_objfile
->quick_file_names_table
=
2183 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2188 /* A helper for the "quick" functions which sets the global
2189 dwarf2_per_objfile according to OBJFILE. */
2192 dw2_setup (struct objfile
*objfile
)
2194 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2195 gdb_assert (dwarf2_per_objfile
);
2198 /* A helper for the "quick" functions which attempts to read the line
2199 table for THIS_CU. */
2201 static struct quick_file_names
*
2202 dw2_get_file_names (struct objfile
*objfile
,
2203 struct dwarf2_per_cu_data
*this_cu
)
2205 bfd
*abfd
= objfile
->obfd
;
2206 struct line_header
*lh
;
2207 struct attribute
*attr
;
2208 struct cleanup
*cleanups
;
2209 struct die_info
*comp_unit_die
;
2210 struct dwarf2_section_info
* sec
;
2211 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2212 int has_children
, i
;
2213 struct dwarf2_cu cu
;
2214 unsigned int bytes_read
, buffer_size
;
2215 struct die_reader_specs reader_specs
;
2216 char *name
, *comp_dir
;
2218 struct quick_file_names
*qfn
;
2219 unsigned int line_offset
;
2221 if (this_cu
->v
.quick
->file_names
!= NULL
)
2222 return this_cu
->v
.quick
->file_names
;
2223 /* If we know there is no line data, no point in looking again. */
2224 if (this_cu
->v
.quick
->no_file_data
)
2227 init_one_comp_unit (&cu
, objfile
);
2228 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2230 if (this_cu
->from_debug_types
)
2231 sec
= &dwarf2_per_objfile
->types
;
2233 sec
= &dwarf2_per_objfile
->info
;
2234 dwarf2_read_section (objfile
, sec
);
2235 buffer_size
= sec
->size
;
2236 buffer
= sec
->buffer
;
2237 info_ptr
= buffer
+ this_cu
->offset
;
2238 beg_of_comp_unit
= info_ptr
;
2240 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2241 buffer
, buffer_size
,
2244 /* Complete the cu_header. */
2245 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2246 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2249 cu
.per_cu
= this_cu
;
2251 dwarf2_read_abbrevs (abfd
, &cu
);
2252 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2254 if (this_cu
->from_debug_types
)
2255 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2256 init_cu_die_reader (&reader_specs
, &cu
);
2257 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2263 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2266 struct quick_file_names find_entry
;
2268 line_offset
= DW_UNSND (attr
);
2270 /* We may have already read in this line header (TU line header sharing).
2271 If we have we're done. */
2272 find_entry
.offset
= line_offset
;
2273 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2274 &find_entry
, INSERT
);
2277 do_cleanups (cleanups
);
2278 this_cu
->v
.quick
->file_names
= *slot
;
2282 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2286 do_cleanups (cleanups
);
2287 this_cu
->v
.quick
->no_file_data
= 1;
2291 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2292 qfn
->offset
= line_offset
;
2293 gdb_assert (slot
!= NULL
);
2296 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2298 qfn
->num_file_names
= lh
->num_file_names
;
2299 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2300 lh
->num_file_names
* sizeof (char *));
2301 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2302 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2303 qfn
->real_names
= NULL
;
2305 free_line_header (lh
);
2306 do_cleanups (cleanups
);
2308 this_cu
->v
.quick
->file_names
= qfn
;
2312 /* A helper for the "quick" functions which computes and caches the
2313 real path for a given file name from the line table. */
2316 dw2_get_real_path (struct objfile
*objfile
,
2317 struct quick_file_names
*qfn
, int index
)
2319 if (qfn
->real_names
== NULL
)
2320 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2321 qfn
->num_file_names
, sizeof (char *));
2323 if (qfn
->real_names
[index
] == NULL
)
2324 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2326 return qfn
->real_names
[index
];
2329 static struct symtab
*
2330 dw2_find_last_source_symtab (struct objfile
*objfile
)
2334 dw2_setup (objfile
);
2335 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2336 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2339 /* Traversal function for dw2_forget_cached_source_info. */
2342 dw2_free_cached_file_names (void **slot
, void *info
)
2344 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2346 if (file_data
->real_names
)
2350 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2352 xfree ((void*) file_data
->real_names
[i
]);
2353 file_data
->real_names
[i
] = NULL
;
2361 dw2_forget_cached_source_info (struct objfile
*objfile
)
2363 dw2_setup (objfile
);
2365 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2366 dw2_free_cached_file_names
, NULL
);
2370 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2371 const char *full_path
, const char *real_path
,
2372 struct symtab
**result
)
2375 int check_basename
= lbasename (name
) == name
;
2376 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2378 dw2_setup (objfile
);
2380 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2381 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2384 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2385 struct quick_file_names
*file_data
;
2387 if (per_cu
->v
.quick
->symtab
)
2390 file_data
= dw2_get_file_names (objfile
, per_cu
);
2391 if (file_data
== NULL
)
2394 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2396 const char *this_name
= file_data
->file_names
[j
];
2398 if (FILENAME_CMP (name
, this_name
) == 0)
2400 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2404 if (check_basename
&& ! base_cu
2405 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2408 if (full_path
!= NULL
)
2410 const char *this_real_name
= dw2_get_real_path (objfile
,
2413 if (this_real_name
!= NULL
2414 && FILENAME_CMP (full_path
, this_real_name
) == 0)
2416 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2421 if (real_path
!= NULL
)
2423 const char *this_real_name
= dw2_get_real_path (objfile
,
2426 if (this_real_name
!= NULL
2427 && FILENAME_CMP (real_path
, this_real_name
) == 0)
2429 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2438 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2445 static struct symtab
*
2446 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2447 const char *name
, domain_enum domain
)
2449 /* We do all the work in the pre_expand_symtabs_matching hook
2454 /* A helper function that expands all symtabs that hold an object
2458 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2460 dw2_setup (objfile
);
2462 /* index_table is NULL if OBJF_READNOW. */
2463 if (dwarf2_per_objfile
->index_table
)
2467 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2470 offset_type i
, len
= MAYBE_SWAP (*vec
);
2471 for (i
= 0; i
< len
; ++i
)
2473 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2474 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2476 dw2_instantiate_symtab (objfile
, per_cu
);
2483 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2484 enum block_enum block_kind
, const char *name
,
2487 dw2_do_expand_symtabs_matching (objfile
, name
);
2491 dw2_print_stats (struct objfile
*objfile
)
2495 dw2_setup (objfile
);
2497 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2498 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2500 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2502 if (!per_cu
->v
.quick
->symtab
)
2505 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2509 dw2_dump (struct objfile
*objfile
)
2511 /* Nothing worth printing. */
2515 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2516 struct section_offsets
*delta
)
2518 /* There's nothing to relocate here. */
2522 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2523 const char *func_name
)
2525 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2529 dw2_expand_all_symtabs (struct objfile
*objfile
)
2533 dw2_setup (objfile
);
2535 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2536 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2538 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2540 dw2_instantiate_symtab (objfile
, per_cu
);
2545 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2546 const char *filename
)
2550 dw2_setup (objfile
);
2552 /* We don't need to consider type units here.
2553 This is only called for examining code, e.g. expand_line_sal.
2554 There can be an order of magnitude (or more) more type units
2555 than comp units, and we avoid them if we can. */
2557 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2560 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2561 struct quick_file_names
*file_data
;
2563 if (per_cu
->v
.quick
->symtab
)
2566 file_data
= dw2_get_file_names (objfile
, per_cu
);
2567 if (file_data
== NULL
)
2570 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2572 const char *this_name
= file_data
->file_names
[j
];
2573 if (FILENAME_CMP (this_name
, filename
) == 0)
2575 dw2_instantiate_symtab (objfile
, per_cu
);
2583 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2585 struct dwarf2_per_cu_data
*per_cu
;
2587 struct quick_file_names
*file_data
;
2589 dw2_setup (objfile
);
2591 /* index_table is NULL if OBJF_READNOW. */
2592 if (!dwarf2_per_objfile
->index_table
)
2595 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2599 /* Note that this just looks at the very first one named NAME -- but
2600 actually we are looking for a function. find_main_filename
2601 should be rewritten so that it doesn't require a custom hook. It
2602 could just use the ordinary symbol tables. */
2603 /* vec[0] is the length, which must always be >0. */
2604 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2606 file_data
= dw2_get_file_names (objfile
, per_cu
);
2607 if (file_data
== NULL
)
2610 return file_data
->file_names
[file_data
->num_file_names
- 1];
2614 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2615 struct objfile
*objfile
, int global
,
2616 int (*callback
) (struct block
*,
2617 struct symbol
*, void *),
2618 void *data
, symbol_compare_ftype
*match
,
2619 symbol_compare_ftype
*ordered_compare
)
2621 /* Currently unimplemented; used for Ada. The function can be called if the
2622 current language is Ada for a non-Ada objfile using GNU index. As Ada
2623 does not look for non-Ada symbols this function should just return. */
2627 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2628 int (*file_matcher
) (const char *, void *),
2629 int (*name_matcher
) (const char *, void *),
2630 enum search_domain kind
,
2635 struct mapped_index
*index
;
2637 dw2_setup (objfile
);
2639 /* index_table is NULL if OBJF_READNOW. */
2640 if (!dwarf2_per_objfile
->index_table
)
2642 index
= dwarf2_per_objfile
->index_table
;
2644 if (file_matcher
!= NULL
)
2645 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2646 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2649 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2650 struct quick_file_names
*file_data
;
2652 per_cu
->v
.quick
->mark
= 0;
2653 if (per_cu
->v
.quick
->symtab
)
2656 file_data
= dw2_get_file_names (objfile
, per_cu
);
2657 if (file_data
== NULL
)
2660 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2662 if (file_matcher (file_data
->file_names
[j
], data
))
2664 per_cu
->v
.quick
->mark
= 1;
2670 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2672 offset_type idx
= 2 * iter
;
2674 offset_type
*vec
, vec_len
, vec_idx
;
2676 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2679 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2681 if (! (*name_matcher
) (name
, data
))
2684 /* The name was matched, now expand corresponding CUs that were
2686 vec
= (offset_type
*) (index
->constant_pool
2687 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2688 vec_len
= MAYBE_SWAP (vec
[0]);
2689 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2691 struct dwarf2_per_cu_data
*per_cu
;
2693 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2694 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2695 dw2_instantiate_symtab (objfile
, per_cu
);
2700 static struct symtab
*
2701 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2702 struct minimal_symbol
*msymbol
,
2704 struct obj_section
*section
,
2707 struct dwarf2_per_cu_data
*data
;
2709 dw2_setup (objfile
);
2711 if (!objfile
->psymtabs_addrmap
)
2714 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2718 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2719 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2720 paddress (get_objfile_arch (objfile
), pc
));
2722 return dw2_instantiate_symtab (objfile
, data
);
2726 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2731 dw2_setup (objfile
);
2733 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2734 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2737 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2738 struct quick_file_names
*file_data
;
2740 if (per_cu
->v
.quick
->symtab
)
2743 file_data
= dw2_get_file_names (objfile
, per_cu
);
2744 if (file_data
== NULL
)
2747 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2749 const char *this_real_name
= dw2_get_real_path (objfile
, file_data
,
2751 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2757 dw2_has_symbols (struct objfile
*objfile
)
2762 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2765 dw2_find_last_source_symtab
,
2766 dw2_forget_cached_source_info
,
2769 dw2_pre_expand_symtabs_matching
,
2773 dw2_expand_symtabs_for_function
,
2774 dw2_expand_all_symtabs
,
2775 dw2_expand_symtabs_with_filename
,
2776 dw2_find_symbol_file
,
2777 dw2_map_matching_symbols
,
2778 dw2_expand_symtabs_matching
,
2779 dw2_find_pc_sect_symtab
,
2780 dw2_map_symbol_filenames
2783 /* Initialize for reading DWARF for this objfile. Return 0 if this
2784 file will use psymtabs, or 1 if using the GNU index. */
2787 dwarf2_initialize_objfile (struct objfile
*objfile
)
2789 /* If we're about to read full symbols, don't bother with the
2790 indices. In this case we also don't care if some other debug
2791 format is making psymtabs, because they are all about to be
2793 if ((objfile
->flags
& OBJF_READNOW
))
2797 dwarf2_per_objfile
->using_index
= 1;
2798 create_all_comp_units (objfile
);
2799 create_debug_types_hash_table (objfile
);
2800 dwarf2_per_objfile
->quick_file_names_table
=
2801 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2803 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2804 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2806 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2808 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2809 struct dwarf2_per_cu_quick_data
);
2812 /* Return 1 so that gdb sees the "quick" functions. However,
2813 these functions will be no-ops because we will have expanded
2818 if (dwarf2_read_index (objfile
))
2826 /* Build a partial symbol table. */
2829 dwarf2_build_psymtabs (struct objfile
*objfile
)
2831 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2833 init_psymbol_list (objfile
, 1024);
2836 dwarf2_build_psymtabs_hard (objfile
);
2839 /* Return TRUE if OFFSET is within CU_HEADER. */
2842 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2844 unsigned int bottom
= cu_header
->offset
;
2845 unsigned int top
= (cu_header
->offset
2847 + cu_header
->initial_length_size
);
2849 return (offset
>= bottom
&& offset
< top
);
2852 /* Read in the comp unit header information from the debug_info at info_ptr.
2853 NOTE: This leaves members offset, first_die_offset to be filled in
2857 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2858 gdb_byte
*info_ptr
, bfd
*abfd
)
2861 unsigned int bytes_read
;
2863 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2864 cu_header
->initial_length_size
= bytes_read
;
2865 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2866 info_ptr
+= bytes_read
;
2867 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2869 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2871 info_ptr
+= bytes_read
;
2872 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2874 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2875 if (signed_addr
< 0)
2876 internal_error (__FILE__
, __LINE__
,
2877 _("read_comp_unit_head: dwarf from non elf file"));
2878 cu_header
->signed_addr_p
= signed_addr
;
2884 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2885 gdb_byte
*buffer
, unsigned int buffer_size
,
2888 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2890 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2892 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2893 error (_("Dwarf Error: wrong version in compilation unit header "
2894 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2895 bfd_get_filename (abfd
));
2897 if (header
->abbrev_offset
2898 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
2899 &dwarf2_per_objfile
->abbrev
))
2900 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2901 "(offset 0x%lx + 6) [in module %s]"),
2902 (long) header
->abbrev_offset
,
2903 (long) (beg_of_comp_unit
- buffer
),
2904 bfd_get_filename (abfd
));
2906 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2907 > buffer
+ buffer_size
)
2908 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2909 "(offset 0x%lx + 0) [in module %s]"),
2910 (long) header
->length
,
2911 (long) (beg_of_comp_unit
- buffer
),
2912 bfd_get_filename (abfd
));
2917 /* Read in the types comp unit header information from .debug_types entry at
2918 types_ptr. The result is a pointer to one past the end of the header. */
2921 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2922 ULONGEST
*signature
,
2923 gdb_byte
*types_ptr
, bfd
*abfd
)
2925 gdb_byte
*initial_types_ptr
= types_ptr
;
2927 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2928 &dwarf2_per_objfile
->types
);
2929 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2931 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2933 *signature
= read_8_bytes (abfd
, types_ptr
);
2935 types_ptr
+= cu_header
->offset_size
;
2936 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2941 /* Allocate a new partial symtab for file named NAME and mark this new
2942 partial symtab as being an include of PST. */
2945 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2946 struct objfile
*objfile
)
2948 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2950 subpst
->section_offsets
= pst
->section_offsets
;
2951 subpst
->textlow
= 0;
2952 subpst
->texthigh
= 0;
2954 subpst
->dependencies
= (struct partial_symtab
**)
2955 obstack_alloc (&objfile
->objfile_obstack
,
2956 sizeof (struct partial_symtab
*));
2957 subpst
->dependencies
[0] = pst
;
2958 subpst
->number_of_dependencies
= 1;
2960 subpst
->globals_offset
= 0;
2961 subpst
->n_global_syms
= 0;
2962 subpst
->statics_offset
= 0;
2963 subpst
->n_static_syms
= 0;
2964 subpst
->symtab
= NULL
;
2965 subpst
->read_symtab
= pst
->read_symtab
;
2968 /* No private part is necessary for include psymtabs. This property
2969 can be used to differentiate between such include psymtabs and
2970 the regular ones. */
2971 subpst
->read_symtab_private
= NULL
;
2974 /* Read the Line Number Program data and extract the list of files
2975 included by the source file represented by PST. Build an include
2976 partial symtab for each of these included files. */
2979 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2980 struct die_info
*die
,
2981 struct partial_symtab
*pst
)
2983 struct objfile
*objfile
= cu
->objfile
;
2984 bfd
*abfd
= objfile
->obfd
;
2985 struct line_header
*lh
= NULL
;
2986 struct attribute
*attr
;
2988 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2991 unsigned int line_offset
= DW_UNSND (attr
);
2993 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2996 return; /* No linetable, so no includes. */
2998 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2999 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
3001 free_line_header (lh
);
3005 hash_type_signature (const void *item
)
3007 const struct signatured_type
*type_sig
= item
;
3009 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3010 return type_sig
->signature
;
3014 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
3016 const struct signatured_type
*lhs
= item_lhs
;
3017 const struct signatured_type
*rhs
= item_rhs
;
3019 return lhs
->signature
== rhs
->signature
;
3022 /* Allocate a hash table for signatured types. */
3025 allocate_signatured_type_table (struct objfile
*objfile
)
3027 return htab_create_alloc_ex (41,
3028 hash_type_signature
,
3031 &objfile
->objfile_obstack
,
3032 hashtab_obstack_allocate
,
3033 dummy_obstack_deallocate
);
3036 /* A helper function to add a signatured type CU to a list. */
3039 add_signatured_type_cu_to_list (void **slot
, void *datum
)
3041 struct signatured_type
*sigt
= *slot
;
3042 struct dwarf2_per_cu_data
***datap
= datum
;
3044 **datap
= &sigt
->per_cu
;
3050 /* Create the hash table of all entries in the .debug_types section.
3051 The result is zero if there is an error (e.g. missing .debug_types section),
3052 otherwise non-zero. */
3055 create_debug_types_hash_table (struct objfile
*objfile
)
3059 struct dwarf2_per_cu_data
**iter
;
3061 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
3062 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
3064 if (info_ptr
== NULL
)
3066 dwarf2_per_objfile
->signatured_types
= NULL
;
3070 types_htab
= allocate_signatured_type_table (objfile
);
3072 if (dwarf2_die_debug
)
3073 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3075 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
3076 + dwarf2_per_objfile
->types
.size
)
3078 unsigned int offset
;
3079 unsigned int offset_size
;
3080 unsigned int type_offset
;
3081 unsigned int length
, initial_length_size
;
3082 unsigned short version
;
3084 struct signatured_type
*type_sig
;
3086 gdb_byte
*ptr
= info_ptr
;
3088 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
3090 /* We need to read the type's signature in order to build the hash
3091 table, but we don't need to read anything else just yet. */
3093 /* Sanity check to ensure entire cu is present. */
3094 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
3095 if (ptr
+ length
+ initial_length_size
3096 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
3098 complaint (&symfile_complaints
,
3099 _("debug type entry runs off end "
3100 "of `.debug_types' section, ignored"));
3104 offset_size
= initial_length_size
== 4 ? 4 : 8;
3105 ptr
+= initial_length_size
;
3106 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3108 ptr
+= offset_size
; /* abbrev offset */
3109 ptr
+= 1; /* address size */
3110 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3112 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3114 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3115 memset (type_sig
, 0, sizeof (*type_sig
));
3116 type_sig
->signature
= signature
;
3117 type_sig
->type_offset
= type_offset
;
3118 type_sig
->per_cu
.objfile
= objfile
;
3119 type_sig
->per_cu
.from_debug_types
= 1;
3120 type_sig
->per_cu
.offset
= offset
;
3122 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3123 gdb_assert (slot
!= NULL
);
3126 const struct signatured_type
*dup_sig
= *slot
;
3128 complaint (&symfile_complaints
,
3129 _("debug type entry at offset 0x%x is duplicate to the "
3130 "entry at offset 0x%x, signature 0x%s"),
3131 offset
, dup_sig
->per_cu
.offset
,
3132 phex (signature
, sizeof (signature
)));
3133 gdb_assert (signature
== dup_sig
->signature
);
3137 if (dwarf2_die_debug
)
3138 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3139 offset
, phex (signature
, sizeof (signature
)));
3141 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3144 dwarf2_per_objfile
->signatured_types
= types_htab
;
3146 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3147 dwarf2_per_objfile
->type_comp_units
3148 = obstack_alloc (&objfile
->objfile_obstack
,
3149 dwarf2_per_objfile
->n_type_comp_units
3150 * sizeof (struct dwarf2_per_cu_data
*));
3151 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3152 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3153 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3154 == dwarf2_per_objfile
->n_type_comp_units
);
3159 /* Lookup a signature based type.
3160 Returns NULL if SIG is not present in the table. */
3162 static struct signatured_type
*
3163 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3165 struct signatured_type find_entry
, *entry
;
3167 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3169 complaint (&symfile_complaints
,
3170 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3174 find_entry
.signature
= sig
;
3175 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3179 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3182 init_cu_die_reader (struct die_reader_specs
*reader
,
3183 struct dwarf2_cu
*cu
)
3185 reader
->abfd
= cu
->objfile
->obfd
;
3187 if (cu
->per_cu
->from_debug_types
)
3189 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3190 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
3194 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3195 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3199 /* Find the base address of the compilation unit for range lists and
3200 location lists. It will normally be specified by DW_AT_low_pc.
3201 In DWARF-3 draft 4, the base address could be overridden by
3202 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3203 compilation units with discontinuous ranges. */
3206 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3208 struct attribute
*attr
;
3211 cu
->base_address
= 0;
3213 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3216 cu
->base_address
= DW_ADDR (attr
);
3221 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3224 cu
->base_address
= DW_ADDR (attr
);
3230 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3231 to combine the common parts.
3232 Process a compilation unit for a psymtab.
3233 BUFFER is a pointer to the beginning of the dwarf section buffer,
3234 either .debug_info or debug_types.
3235 INFO_PTR is a pointer to the start of the CU.
3236 Returns a pointer to the next CU. */
3239 process_psymtab_comp_unit (struct objfile
*objfile
,
3240 struct dwarf2_per_cu_data
*this_cu
,
3241 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3242 unsigned int buffer_size
)
3244 bfd
*abfd
= objfile
->obfd
;
3245 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3246 struct die_info
*comp_unit_die
;
3247 struct partial_symtab
*pst
;
3249 struct cleanup
*back_to_inner
;
3250 struct dwarf2_cu cu
;
3251 int has_children
, has_pc_info
;
3252 struct attribute
*attr
;
3253 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3254 struct die_reader_specs reader_specs
;
3255 const char *filename
;
3257 init_one_comp_unit (&cu
, objfile
);
3258 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3260 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3261 buffer
, buffer_size
,
3264 /* Complete the cu_header. */
3265 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3266 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3268 cu
.list_in_scope
= &file_symbols
;
3270 /* If this compilation unit was already read in, free the
3271 cached copy in order to read it in again. This is
3272 necessary because we skipped some symbols when we first
3273 read in the compilation unit (see load_partial_dies).
3274 This problem could be avoided, but the benefit is
3276 if (this_cu
->cu
!= NULL
)
3277 free_one_cached_comp_unit (this_cu
->cu
);
3279 /* Note that this is a pointer to our stack frame, being
3280 added to a global data structure. It will be cleaned up
3281 in free_stack_comp_unit when we finish with this
3282 compilation unit. */
3284 cu
.per_cu
= this_cu
;
3286 /* Read the abbrevs for this compilation unit into a table. */
3287 dwarf2_read_abbrevs (abfd
, &cu
);
3288 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3290 /* Read the compilation unit die. */
3291 if (this_cu
->from_debug_types
)
3292 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3293 init_cu_die_reader (&reader_specs
, &cu
);
3294 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3297 if (this_cu
->from_debug_types
)
3299 /* LENGTH has not been set yet for type units. */
3300 gdb_assert (this_cu
->offset
== cu
.header
.offset
);
3301 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3303 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3305 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3306 + cu
.header
.initial_length_size
);
3307 do_cleanups (back_to_inner
);
3311 prepare_one_comp_unit (&cu
, comp_unit_die
);
3313 /* Allocate a new partial symbol table structure. */
3314 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3315 if (attr
== NULL
|| !DW_STRING (attr
))
3318 filename
= DW_STRING (attr
);
3319 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3321 /* TEXTLOW and TEXTHIGH are set below. */
3323 objfile
->global_psymbols
.next
,
3324 objfile
->static_psymbols
.next
);
3326 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3328 pst
->dirname
= DW_STRING (attr
);
3330 pst
->read_symtab_private
= this_cu
;
3332 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3334 /* Store the function that reads in the rest of the symbol table. */
3335 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3337 this_cu
->v
.psymtab
= pst
;
3339 dwarf2_find_base_address (comp_unit_die
, &cu
);
3341 /* Possibly set the default values of LOWPC and HIGHPC from
3343 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3344 &best_highpc
, &cu
, pst
);
3345 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3346 /* Store the contiguous range if it is not empty; it can be empty for
3347 CUs with no code. */
3348 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3349 best_lowpc
+ baseaddr
,
3350 best_highpc
+ baseaddr
- 1, pst
);
3352 /* Check if comp unit has_children.
3353 If so, read the rest of the partial symbols from this comp unit.
3354 If not, there's no more debug_info for this comp unit. */
3357 struct partial_die_info
*first_die
;
3358 CORE_ADDR lowpc
, highpc
;
3360 lowpc
= ((CORE_ADDR
) -1);
3361 highpc
= ((CORE_ADDR
) 0);
3363 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3365 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3366 ! has_pc_info
, &cu
);
3368 /* If we didn't find a lowpc, set it to highpc to avoid
3369 complaints from `maint check'. */
3370 if (lowpc
== ((CORE_ADDR
) -1))
3373 /* If the compilation unit didn't have an explicit address range,
3374 then use the information extracted from its child dies. */
3378 best_highpc
= highpc
;
3381 pst
->textlow
= best_lowpc
+ baseaddr
;
3382 pst
->texthigh
= best_highpc
+ baseaddr
;
3384 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3385 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3386 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3387 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3388 sort_pst_symbols (pst
);
3390 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3391 + cu
.header
.initial_length_size
);
3393 if (this_cu
->from_debug_types
)
3395 /* It's not clear we want to do anything with stmt lists here.
3396 Waiting to see what gcc ultimately does. */
3400 /* Get the list of files included in the current compilation unit,
3401 and build a psymtab for each of them. */
3402 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3405 do_cleanups (back_to_inner
);
3410 /* Traversal function for htab_traverse_noresize.
3411 Process one .debug_types comp-unit. */
3414 process_type_comp_unit (void **slot
, void *info
)
3416 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3417 struct objfile
*objfile
= (struct objfile
*) info
;
3418 struct dwarf2_per_cu_data
*this_cu
;
3420 this_cu
= &entry
->per_cu
;
3422 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3423 process_psymtab_comp_unit (objfile
, this_cu
,
3424 dwarf2_per_objfile
->types
.buffer
,
3425 dwarf2_per_objfile
->types
.buffer
+ this_cu
->offset
,
3426 dwarf2_per_objfile
->types
.size
);
3431 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3432 Build partial symbol tables for the .debug_types comp-units. */
3435 build_type_psymtabs (struct objfile
*objfile
)
3437 if (! create_debug_types_hash_table (objfile
))
3440 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3441 process_type_comp_unit
, objfile
);
3444 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3447 psymtabs_addrmap_cleanup (void *o
)
3449 struct objfile
*objfile
= o
;
3451 objfile
->psymtabs_addrmap
= NULL
;
3454 /* Build the partial symbol table by doing a quick pass through the
3455 .debug_info and .debug_abbrev sections. */
3458 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3461 struct cleanup
*back_to
, *addrmap_cleanup
;
3462 struct obstack temp_obstack
;
3464 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3466 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3467 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3469 /* Any cached compilation units will be linked by the per-objfile
3470 read_in_chain. Make sure to free them when we're done. */
3471 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3473 build_type_psymtabs (objfile
);
3475 create_all_comp_units (objfile
);
3477 /* Create a temporary address map on a temporary obstack. We later
3478 copy this to the final obstack. */
3479 obstack_init (&temp_obstack
);
3480 make_cleanup_obstack_free (&temp_obstack
);
3481 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3482 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3484 /* Since the objects we're extracting from .debug_info vary in
3485 length, only the individual functions to extract them (like
3486 read_comp_unit_head and load_partial_die) can really know whether
3487 the buffer is large enough to hold another complete object.
3489 At the moment, they don't actually check that. If .debug_info
3490 holds just one extra byte after the last compilation unit's dies,
3491 then read_comp_unit_head will happily read off the end of the
3492 buffer. read_partial_die is similarly casual. Those functions
3495 For this loop condition, simply checking whether there's any data
3496 left at all should be sufficient. */
3498 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3499 + dwarf2_per_objfile
->info
.size
))
3501 struct dwarf2_per_cu_data
*this_cu
;
3503 this_cu
= dwarf2_find_comp_unit (info_ptr
3504 - dwarf2_per_objfile
->info
.buffer
,
3507 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3508 dwarf2_per_objfile
->info
.buffer
,
3510 dwarf2_per_objfile
->info
.size
);
3513 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3514 &objfile
->objfile_obstack
);
3515 discard_cleanups (addrmap_cleanup
);
3517 do_cleanups (back_to
);
3520 /* Load the partial DIEs for a secondary CU into memory. */
3523 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3524 struct objfile
*objfile
)
3526 bfd
*abfd
= objfile
->obfd
;
3527 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3528 struct die_info
*comp_unit_die
;
3529 struct dwarf2_cu
*cu
;
3530 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3532 struct die_reader_specs reader_specs
;
3535 gdb_assert (! this_cu
->from_debug_types
);
3537 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3538 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3539 beg_of_comp_unit
= info_ptr
;
3541 if (this_cu
->cu
== NULL
)
3543 cu
= xmalloc (sizeof (*cu
));
3544 init_one_comp_unit (cu
, objfile
);
3548 /* If an error occurs while loading, release our storage. */
3549 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3551 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3552 dwarf2_per_objfile
->info
.buffer
,
3553 dwarf2_per_objfile
->info
.size
,
3556 /* Complete the cu_header. */
3557 cu
->header
.offset
= this_cu
->offset
;
3558 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3560 /* Link this compilation unit into the compilation unit tree. */
3562 cu
->per_cu
= this_cu
;
3564 /* Link this CU into read_in_chain. */
3565 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3566 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3571 info_ptr
+= cu
->header
.first_die_offset
;
3574 /* Read the abbrevs for this compilation unit into a table. */
3575 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3576 dwarf2_read_abbrevs (abfd
, cu
);
3577 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3579 /* Read the compilation unit die. */
3580 init_cu_die_reader (&reader_specs
, cu
);
3581 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3584 prepare_one_comp_unit (cu
, comp_unit_die
);
3586 /* Check if comp unit has_children.
3587 If so, read the rest of the partial symbols from this comp unit.
3588 If not, there's no more debug_info for this comp unit. */
3590 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3592 do_cleanups (free_abbrevs_cleanup
);
3596 /* We've successfully allocated this compilation unit. Let our
3597 caller clean it up when finished with it. */
3598 discard_cleanups (free_cu_cleanup
);
3602 /* Create a list of all compilation units in OBJFILE. We do this only
3603 if an inter-comp-unit reference is found; presumably if there is one,
3604 there will be many, and one will occur early in the .debug_info section.
3605 So there's no point in building this list incrementally. */
3608 create_all_comp_units (struct objfile
*objfile
)
3612 struct dwarf2_per_cu_data
**all_comp_units
;
3615 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3616 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3620 all_comp_units
= xmalloc (n_allocated
3621 * sizeof (struct dwarf2_per_cu_data
*));
3623 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3624 + dwarf2_per_objfile
->info
.size
)
3626 unsigned int length
, initial_length_size
;
3627 struct dwarf2_per_cu_data
*this_cu
;
3628 unsigned int offset
;
3630 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3632 /* Read just enough information to find out where the next
3633 compilation unit is. */
3634 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3635 &initial_length_size
);
3637 /* Save the compilation unit for later lookup. */
3638 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3639 sizeof (struct dwarf2_per_cu_data
));
3640 memset (this_cu
, 0, sizeof (*this_cu
));
3641 this_cu
->offset
= offset
;
3642 this_cu
->length
= length
+ initial_length_size
;
3643 this_cu
->objfile
= objfile
;
3645 if (n_comp_units
== n_allocated
)
3648 all_comp_units
= xrealloc (all_comp_units
,
3650 * sizeof (struct dwarf2_per_cu_data
*));
3652 all_comp_units
[n_comp_units
++] = this_cu
;
3654 info_ptr
= info_ptr
+ this_cu
->length
;
3657 dwarf2_per_objfile
->all_comp_units
3658 = obstack_alloc (&objfile
->objfile_obstack
,
3659 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3660 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3661 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3662 xfree (all_comp_units
);
3663 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3666 /* Process all loaded DIEs for compilation unit CU, starting at
3667 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3668 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3669 DW_AT_ranges). If NEED_PC is set, then this function will set
3670 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3671 and record the covered ranges in the addrmap. */
3674 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3675 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3677 struct partial_die_info
*pdi
;
3679 /* Now, march along the PDI's, descending into ones which have
3680 interesting children but skipping the children of the other ones,
3681 until we reach the end of the compilation unit. */
3687 fixup_partial_die (pdi
, cu
);
3689 /* Anonymous namespaces or modules have no name but have interesting
3690 children, so we need to look at them. Ditto for anonymous
3693 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3694 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3698 case DW_TAG_subprogram
:
3699 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3701 case DW_TAG_constant
:
3702 case DW_TAG_variable
:
3703 case DW_TAG_typedef
:
3704 case DW_TAG_union_type
:
3705 if (!pdi
->is_declaration
)
3707 add_partial_symbol (pdi
, cu
);
3710 case DW_TAG_class_type
:
3711 case DW_TAG_interface_type
:
3712 case DW_TAG_structure_type
:
3713 if (!pdi
->is_declaration
)
3715 add_partial_symbol (pdi
, cu
);
3718 case DW_TAG_enumeration_type
:
3719 if (!pdi
->is_declaration
)
3720 add_partial_enumeration (pdi
, cu
);
3722 case DW_TAG_base_type
:
3723 case DW_TAG_subrange_type
:
3724 /* File scope base type definitions are added to the partial
3726 add_partial_symbol (pdi
, cu
);
3728 case DW_TAG_namespace
:
3729 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3732 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3739 /* If the die has a sibling, skip to the sibling. */
3741 pdi
= pdi
->die_sibling
;
3745 /* Functions used to compute the fully scoped name of a partial DIE.
3747 Normally, this is simple. For C++, the parent DIE's fully scoped
3748 name is concatenated with "::" and the partial DIE's name. For
3749 Java, the same thing occurs except that "." is used instead of "::".
3750 Enumerators are an exception; they use the scope of their parent
3751 enumeration type, i.e. the name of the enumeration type is not
3752 prepended to the enumerator.
3754 There are two complexities. One is DW_AT_specification; in this
3755 case "parent" means the parent of the target of the specification,
3756 instead of the direct parent of the DIE. The other is compilers
3757 which do not emit DW_TAG_namespace; in this case we try to guess
3758 the fully qualified name of structure types from their members'
3759 linkage names. This must be done using the DIE's children rather
3760 than the children of any DW_AT_specification target. We only need
3761 to do this for structures at the top level, i.e. if the target of
3762 any DW_AT_specification (if any; otherwise the DIE itself) does not
3765 /* Compute the scope prefix associated with PDI's parent, in
3766 compilation unit CU. The result will be allocated on CU's
3767 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3768 field. NULL is returned if no prefix is necessary. */
3770 partial_die_parent_scope (struct partial_die_info
*pdi
,
3771 struct dwarf2_cu
*cu
)
3773 char *grandparent_scope
;
3774 struct partial_die_info
*parent
, *real_pdi
;
3776 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3777 then this means the parent of the specification DIE. */
3780 while (real_pdi
->has_specification
)
3781 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3783 parent
= real_pdi
->die_parent
;
3787 if (parent
->scope_set
)
3788 return parent
->scope
;
3790 fixup_partial_die (parent
, cu
);
3792 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3794 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3795 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3796 Work around this problem here. */
3797 if (cu
->language
== language_cplus
3798 && parent
->tag
== DW_TAG_namespace
3799 && strcmp (parent
->name
, "::") == 0
3800 && grandparent_scope
== NULL
)
3802 parent
->scope
= NULL
;
3803 parent
->scope_set
= 1;
3807 if (parent
->tag
== DW_TAG_namespace
3808 || parent
->tag
== DW_TAG_module
3809 || parent
->tag
== DW_TAG_structure_type
3810 || parent
->tag
== DW_TAG_class_type
3811 || parent
->tag
== DW_TAG_interface_type
3812 || parent
->tag
== DW_TAG_union_type
3813 || parent
->tag
== DW_TAG_enumeration_type
)
3815 if (grandparent_scope
== NULL
)
3816 parent
->scope
= parent
->name
;
3818 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3820 parent
->name
, 0, cu
);
3822 else if (parent
->tag
== DW_TAG_enumerator
)
3823 /* Enumerators should not get the name of the enumeration as a prefix. */
3824 parent
->scope
= grandparent_scope
;
3827 /* FIXME drow/2004-04-01: What should we be doing with
3828 function-local names? For partial symbols, we should probably be
3830 complaint (&symfile_complaints
,
3831 _("unhandled containing DIE tag %d for DIE at %d"),
3832 parent
->tag
, pdi
->offset
);
3833 parent
->scope
= grandparent_scope
;
3836 parent
->scope_set
= 1;
3837 return parent
->scope
;
3840 /* Return the fully scoped name associated with PDI, from compilation unit
3841 CU. The result will be allocated with malloc. */
3843 partial_die_full_name (struct partial_die_info
*pdi
,
3844 struct dwarf2_cu
*cu
)
3848 /* If this is a template instantiation, we can not work out the
3849 template arguments from partial DIEs. So, unfortunately, we have
3850 to go through the full DIEs. At least any work we do building
3851 types here will be reused if full symbols are loaded later. */
3852 if (pdi
->has_template_arguments
)
3854 fixup_partial_die (pdi
, cu
);
3856 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3858 struct die_info
*die
;
3859 struct attribute attr
;
3860 struct dwarf2_cu
*ref_cu
= cu
;
3863 attr
.form
= DW_FORM_ref_addr
;
3864 attr
.u
.addr
= pdi
->offset
;
3865 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3867 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3871 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3872 if (parent_scope
== NULL
)
3875 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3879 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3881 struct objfile
*objfile
= cu
->objfile
;
3883 char *actual_name
= NULL
;
3884 const struct partial_symbol
*psym
= NULL
;
3886 int built_actual_name
= 0;
3888 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3890 actual_name
= partial_die_full_name (pdi
, cu
);
3892 built_actual_name
= 1;
3894 if (actual_name
== NULL
)
3895 actual_name
= pdi
->name
;
3899 case DW_TAG_subprogram
:
3900 if (pdi
->is_external
|| cu
->language
== language_ada
)
3902 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3903 of the global scope. But in Ada, we want to be able to access
3904 nested procedures globally. So all Ada subprograms are stored
3905 in the global scope. */
3906 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3907 mst_text, objfile); */
3908 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3910 VAR_DOMAIN
, LOC_BLOCK
,
3911 &objfile
->global_psymbols
,
3912 0, pdi
->lowpc
+ baseaddr
,
3913 cu
->language
, objfile
);
3917 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3918 mst_file_text, objfile); */
3919 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3921 VAR_DOMAIN
, LOC_BLOCK
,
3922 &objfile
->static_psymbols
,
3923 0, pdi
->lowpc
+ baseaddr
,
3924 cu
->language
, objfile
);
3927 case DW_TAG_constant
:
3929 struct psymbol_allocation_list
*list
;
3931 if (pdi
->is_external
)
3932 list
= &objfile
->global_psymbols
;
3934 list
= &objfile
->static_psymbols
;
3935 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3936 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
3937 list
, 0, 0, cu
->language
, objfile
);
3940 case DW_TAG_variable
:
3942 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3946 && !dwarf2_per_objfile
->has_section_at_zero
)
3948 /* A global or static variable may also have been stripped
3949 out by the linker if unused, in which case its address
3950 will be nullified; do not add such variables into partial
3951 symbol table then. */
3953 else if (pdi
->is_external
)
3956 Don't enter into the minimal symbol tables as there is
3957 a minimal symbol table entry from the ELF symbols already.
3958 Enter into partial symbol table if it has a location
3959 descriptor or a type.
3960 If the location descriptor is missing, new_symbol will create
3961 a LOC_UNRESOLVED symbol, the address of the variable will then
3962 be determined from the minimal symbol table whenever the variable
3964 The address for the partial symbol table entry is not
3965 used by GDB, but it comes in handy for debugging partial symbol
3968 if (pdi
->locdesc
|| pdi
->has_type
)
3969 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3971 VAR_DOMAIN
, LOC_STATIC
,
3972 &objfile
->global_psymbols
,
3974 cu
->language
, objfile
);
3978 /* Static Variable. Skip symbols without location descriptors. */
3979 if (pdi
->locdesc
== NULL
)
3981 if (built_actual_name
)
3982 xfree (actual_name
);
3985 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
3986 mst_file_data, objfile); */
3987 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3989 VAR_DOMAIN
, LOC_STATIC
,
3990 &objfile
->static_psymbols
,
3992 cu
->language
, objfile
);
3995 case DW_TAG_typedef
:
3996 case DW_TAG_base_type
:
3997 case DW_TAG_subrange_type
:
3998 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4000 VAR_DOMAIN
, LOC_TYPEDEF
,
4001 &objfile
->static_psymbols
,
4002 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4004 case DW_TAG_namespace
:
4005 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4007 VAR_DOMAIN
, LOC_TYPEDEF
,
4008 &objfile
->global_psymbols
,
4009 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4011 case DW_TAG_class_type
:
4012 case DW_TAG_interface_type
:
4013 case DW_TAG_structure_type
:
4014 case DW_TAG_union_type
:
4015 case DW_TAG_enumeration_type
:
4016 /* Skip external references. The DWARF standard says in the section
4017 about "Structure, Union, and Class Type Entries": "An incomplete
4018 structure, union or class type is represented by a structure,
4019 union or class entry that does not have a byte size attribute
4020 and that has a DW_AT_declaration attribute." */
4021 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4023 if (built_actual_name
)
4024 xfree (actual_name
);
4028 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4029 static vs. global. */
4030 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4032 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4033 (cu
->language
== language_cplus
4034 || cu
->language
== language_java
)
4035 ? &objfile
->global_psymbols
4036 : &objfile
->static_psymbols
,
4037 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4040 case DW_TAG_enumerator
:
4041 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4043 VAR_DOMAIN
, LOC_CONST
,
4044 (cu
->language
== language_cplus
4045 || cu
->language
== language_java
)
4046 ? &objfile
->global_psymbols
4047 : &objfile
->static_psymbols
,
4048 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4054 if (built_actual_name
)
4055 xfree (actual_name
);
4058 /* Read a partial die corresponding to a namespace; also, add a symbol
4059 corresponding to that namespace to the symbol table. NAMESPACE is
4060 the name of the enclosing namespace. */
4063 add_partial_namespace (struct partial_die_info
*pdi
,
4064 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4065 int need_pc
, struct dwarf2_cu
*cu
)
4067 /* Add a symbol for the namespace. */
4069 add_partial_symbol (pdi
, cu
);
4071 /* Now scan partial symbols in that namespace. */
4073 if (pdi
->has_children
)
4074 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4077 /* Read a partial die corresponding to a Fortran module. */
4080 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4081 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4083 /* Now scan partial symbols in that module. */
4085 if (pdi
->has_children
)
4086 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4089 /* Read a partial die corresponding to a subprogram and create a partial
4090 symbol for that subprogram. When the CU language allows it, this
4091 routine also defines a partial symbol for each nested subprogram
4092 that this subprogram contains.
4094 DIE my also be a lexical block, in which case we simply search
4095 recursively for suprograms defined inside that lexical block.
4096 Again, this is only performed when the CU language allows this
4097 type of definitions. */
4100 add_partial_subprogram (struct partial_die_info
*pdi
,
4101 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4102 int need_pc
, struct dwarf2_cu
*cu
)
4104 if (pdi
->tag
== DW_TAG_subprogram
)
4106 if (pdi
->has_pc_info
)
4108 if (pdi
->lowpc
< *lowpc
)
4109 *lowpc
= pdi
->lowpc
;
4110 if (pdi
->highpc
> *highpc
)
4111 *highpc
= pdi
->highpc
;
4115 struct objfile
*objfile
= cu
->objfile
;
4117 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4118 SECT_OFF_TEXT (objfile
));
4119 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4120 pdi
->lowpc
+ baseaddr
,
4121 pdi
->highpc
- 1 + baseaddr
,
4122 cu
->per_cu
->v
.psymtab
);
4124 if (!pdi
->is_declaration
)
4125 /* Ignore subprogram DIEs that do not have a name, they are
4126 illegal. Do not emit a complaint at this point, we will
4127 do so when we convert this psymtab into a symtab. */
4129 add_partial_symbol (pdi
, cu
);
4133 if (! pdi
->has_children
)
4136 if (cu
->language
== language_ada
)
4138 pdi
= pdi
->die_child
;
4141 fixup_partial_die (pdi
, cu
);
4142 if (pdi
->tag
== DW_TAG_subprogram
4143 || pdi
->tag
== DW_TAG_lexical_block
)
4144 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4145 pdi
= pdi
->die_sibling
;
4150 /* Read a partial die corresponding to an enumeration type. */
4153 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4154 struct dwarf2_cu
*cu
)
4156 struct partial_die_info
*pdi
;
4158 if (enum_pdi
->name
!= NULL
)
4159 add_partial_symbol (enum_pdi
, cu
);
4161 pdi
= enum_pdi
->die_child
;
4164 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4165 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4167 add_partial_symbol (pdi
, cu
);
4168 pdi
= pdi
->die_sibling
;
4172 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4173 Return the corresponding abbrev, or NULL if the number is zero (indicating
4174 an empty DIE). In either case *BYTES_READ will be set to the length of
4175 the initial number. */
4177 static struct abbrev_info
*
4178 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4179 struct dwarf2_cu
*cu
)
4181 bfd
*abfd
= cu
->objfile
->obfd
;
4182 unsigned int abbrev_number
;
4183 struct abbrev_info
*abbrev
;
4185 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4187 if (abbrev_number
== 0)
4190 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4193 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4194 abbrev_number
, bfd_get_filename (abfd
));
4200 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4201 Returns a pointer to the end of a series of DIEs, terminated by an empty
4202 DIE. Any children of the skipped DIEs will also be skipped. */
4205 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4207 struct abbrev_info
*abbrev
;
4208 unsigned int bytes_read
;
4212 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4214 return info_ptr
+ bytes_read
;
4216 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4220 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4221 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4222 abbrev corresponding to that skipped uleb128 should be passed in
4223 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4227 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4228 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4230 unsigned int bytes_read
;
4231 struct attribute attr
;
4232 bfd
*abfd
= cu
->objfile
->obfd
;
4233 unsigned int form
, i
;
4235 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4237 /* The only abbrev we care about is DW_AT_sibling. */
4238 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4240 read_attribute (&attr
, &abbrev
->attrs
[i
],
4241 abfd
, info_ptr
, cu
);
4242 if (attr
.form
== DW_FORM_ref_addr
)
4243 complaint (&symfile_complaints
,
4244 _("ignoring absolute DW_AT_sibling"));
4246 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4249 /* If it isn't DW_AT_sibling, skip this attribute. */
4250 form
= abbrev
->attrs
[i
].form
;
4254 case DW_FORM_ref_addr
:
4255 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4256 and later it is offset sized. */
4257 if (cu
->header
.version
== 2)
4258 info_ptr
+= cu
->header
.addr_size
;
4260 info_ptr
+= cu
->header
.offset_size
;
4263 info_ptr
+= cu
->header
.addr_size
;
4270 case DW_FORM_flag_present
:
4282 case DW_FORM_ref_sig8
:
4285 case DW_FORM_string
:
4286 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4287 info_ptr
+= bytes_read
;
4289 case DW_FORM_sec_offset
:
4291 info_ptr
+= cu
->header
.offset_size
;
4293 case DW_FORM_exprloc
:
4295 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4296 info_ptr
+= bytes_read
;
4298 case DW_FORM_block1
:
4299 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4301 case DW_FORM_block2
:
4302 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4304 case DW_FORM_block4
:
4305 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4309 case DW_FORM_ref_udata
:
4310 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4312 case DW_FORM_indirect
:
4313 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4314 info_ptr
+= bytes_read
;
4315 /* We need to continue parsing from here, so just go back to
4317 goto skip_attribute
;
4320 error (_("Dwarf Error: Cannot handle %s "
4321 "in DWARF reader [in module %s]"),
4322 dwarf_form_name (form
),
4323 bfd_get_filename (abfd
));
4327 if (abbrev
->has_children
)
4328 return skip_children (buffer
, info_ptr
, cu
);
4333 /* Locate ORIG_PDI's sibling.
4334 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4338 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4339 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4340 bfd
*abfd
, struct dwarf2_cu
*cu
)
4342 /* Do we know the sibling already? */
4344 if (orig_pdi
->sibling
)
4345 return orig_pdi
->sibling
;
4347 /* Are there any children to deal with? */
4349 if (!orig_pdi
->has_children
)
4352 /* Skip the children the long way. */
4354 return skip_children (buffer
, info_ptr
, cu
);
4357 /* Expand this partial symbol table into a full symbol table. */
4360 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4366 warning (_("bug: psymtab for %s is already read in."),
4373 printf_filtered (_("Reading in symbols for %s..."),
4375 gdb_flush (gdb_stdout
);
4378 /* Restore our global data. */
4379 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4380 dwarf2_objfile_data_key
);
4382 /* If this psymtab is constructed from a debug-only objfile, the
4383 has_section_at_zero flag will not necessarily be correct. We
4384 can get the correct value for this flag by looking at the data
4385 associated with the (presumably stripped) associated objfile. */
4386 if (pst
->objfile
->separate_debug_objfile_backlink
)
4388 struct dwarf2_per_objfile
*dpo_backlink
4389 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4390 dwarf2_objfile_data_key
);
4392 dwarf2_per_objfile
->has_section_at_zero
4393 = dpo_backlink
->has_section_at_zero
;
4396 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4398 psymtab_to_symtab_1 (pst
);
4400 /* Finish up the debug error message. */
4402 printf_filtered (_("done.\n"));
4407 /* Add PER_CU to the queue. */
4410 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4412 struct dwarf2_queue_item
*item
;
4415 item
= xmalloc (sizeof (*item
));
4416 item
->per_cu
= per_cu
;
4419 if (dwarf2_queue
== NULL
)
4420 dwarf2_queue
= item
;
4422 dwarf2_queue_tail
->next
= item
;
4424 dwarf2_queue_tail
= item
;
4427 /* Process the queue. */
4430 process_queue (struct objfile
*objfile
)
4432 struct dwarf2_queue_item
*item
, *next_item
;
4434 /* The queue starts out with one item, but following a DIE reference
4435 may load a new CU, adding it to the end of the queue. */
4436 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4438 if (dwarf2_per_objfile
->using_index
4439 ? !item
->per_cu
->v
.quick
->symtab
4440 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4441 process_full_comp_unit (item
->per_cu
);
4443 item
->per_cu
->queued
= 0;
4444 next_item
= item
->next
;
4448 dwarf2_queue_tail
= NULL
;
4451 /* Free all allocated queue entries. This function only releases anything if
4452 an error was thrown; if the queue was processed then it would have been
4453 freed as we went along. */
4456 dwarf2_release_queue (void *dummy
)
4458 struct dwarf2_queue_item
*item
, *last
;
4460 item
= dwarf2_queue
;
4463 /* Anything still marked queued is likely to be in an
4464 inconsistent state, so discard it. */
4465 if (item
->per_cu
->queued
)
4467 if (item
->per_cu
->cu
!= NULL
)
4468 free_one_cached_comp_unit (item
->per_cu
->cu
);
4469 item
->per_cu
->queued
= 0;
4477 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4480 /* Read in full symbols for PST, and anything it depends on. */
4483 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4485 struct dwarf2_per_cu_data
*per_cu
;
4486 struct cleanup
*back_to
;
4489 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4490 if (!pst
->dependencies
[i
]->readin
)
4492 /* Inform about additional files that need to be read in. */
4495 /* FIXME: i18n: Need to make this a single string. */
4496 fputs_filtered (" ", gdb_stdout
);
4498 fputs_filtered ("and ", gdb_stdout
);
4500 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4501 wrap_here (""); /* Flush output. */
4502 gdb_flush (gdb_stdout
);
4504 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4507 per_cu
= pst
->read_symtab_private
;
4511 /* It's an include file, no symbols to read for it.
4512 Everything is in the parent symtab. */
4517 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4520 /* Load the DIEs associated with PER_CU into memory. */
4523 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
4524 struct objfile
*objfile
)
4526 bfd
*abfd
= objfile
->obfd
;
4527 struct dwarf2_cu
*cu
;
4528 unsigned int offset
;
4529 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4530 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4531 struct attribute
*attr
;
4534 gdb_assert (! per_cu
->from_debug_types
);
4536 /* Set local variables from the partial symbol table info. */
4537 offset
= per_cu
->offset
;
4539 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4540 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4541 beg_of_comp_unit
= info_ptr
;
4543 if (per_cu
->cu
== NULL
)
4545 cu
= xmalloc (sizeof (*cu
));
4546 init_one_comp_unit (cu
, objfile
);
4550 /* If an error occurs while loading, release our storage. */
4551 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4553 /* Read in the comp_unit header. */
4554 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4556 /* Complete the cu_header. */
4557 cu
->header
.offset
= offset
;
4558 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4560 /* Read the abbrevs for this compilation unit. */
4561 dwarf2_read_abbrevs (abfd
, cu
);
4562 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4564 /* Link this compilation unit into the compilation unit tree. */
4566 cu
->per_cu
= per_cu
;
4568 /* Link this CU into read_in_chain. */
4569 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4570 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4575 info_ptr
+= cu
->header
.first_die_offset
;
4578 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4580 /* We try not to read any attributes in this function, because not
4581 all objfiles needed for references have been loaded yet, and symbol
4582 table processing isn't initialized. But we have to set the CU language,
4583 or we won't be able to build types correctly. */
4584 prepare_one_comp_unit (cu
, cu
->dies
);
4586 /* Similarly, if we do not read the producer, we can not apply
4587 producer-specific interpretation. */
4588 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4590 cu
->producer
= DW_STRING (attr
);
4594 do_cleanups (free_abbrevs_cleanup
);
4596 /* We've successfully allocated this compilation unit. Let our
4597 caller clean it up when finished with it. */
4598 discard_cleanups (free_cu_cleanup
);
4602 /* Add a DIE to the delayed physname list. */
4605 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4606 const char *name
, struct die_info
*die
,
4607 struct dwarf2_cu
*cu
)
4609 struct delayed_method_info mi
;
4611 mi
.fnfield_index
= fnfield_index
;
4615 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4618 /* A cleanup for freeing the delayed method list. */
4621 free_delayed_list (void *ptr
)
4623 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4624 if (cu
->method_list
!= NULL
)
4626 VEC_free (delayed_method_info
, cu
->method_list
);
4627 cu
->method_list
= NULL
;
4631 /* Compute the physnames of any methods on the CU's method list.
4633 The computation of method physnames is delayed in order to avoid the
4634 (bad) condition that one of the method's formal parameters is of an as yet
4638 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4641 struct delayed_method_info
*mi
;
4642 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4644 const char *physname
;
4645 struct fn_fieldlist
*fn_flp
4646 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4647 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4648 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4652 /* Check for GCC >= 4.x. Return minor version (x) of 4.x in such case. If it
4653 is not GCC or it is GCC older than 4.x return -1. If it is GCC 5.x or
4654 higher return INT_MAX. */
4657 producer_is_gcc_ge_4 (struct dwarf2_cu
*cu
)
4662 if (cu
->producer
== NULL
)
4664 /* For unknown compilers expect their behavior is not compliant. For GCC
4665 this case can also happen for -gdwarf-4 type units supported since
4671 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
4673 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
4675 /* For non-GCC compilers expect their behavior is not compliant. */
4679 cs
= &cu
->producer
[strlen ("GNU ")];
4680 while (*cs
&& !isdigit (*cs
))
4682 if (sscanf (cs
, "%d.%d", &major
, &minor
) != 2)
4684 /* Not recognized as GCC. */
4696 /* Generate full symbol information for PST and CU, whose DIEs have
4697 already been loaded into memory. */
4700 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4702 struct dwarf2_cu
*cu
= per_cu
->cu
;
4703 struct objfile
*objfile
= per_cu
->objfile
;
4704 CORE_ADDR lowpc
, highpc
;
4705 struct symtab
*symtab
;
4706 struct cleanup
*back_to
, *delayed_list_cleanup
;
4709 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4712 back_to
= make_cleanup (really_free_pendings
, NULL
);
4713 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4715 cu
->list_in_scope
= &file_symbols
;
4717 dwarf2_find_base_address (cu
->dies
, cu
);
4719 /* Do line number decoding in read_file_scope () */
4720 process_die (cu
->dies
, cu
);
4722 /* Now that we have processed all the DIEs in the CU, all the types
4723 should be complete, and it should now be safe to compute all of the
4725 compute_delayed_physnames (cu
);
4726 do_cleanups (delayed_list_cleanup
);
4728 /* Some compilers don't define a DW_AT_high_pc attribute for the
4729 compilation unit. If the DW_AT_high_pc is missing, synthesize
4730 it, by scanning the DIE's below the compilation unit. */
4731 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4733 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4737 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
);
4739 /* Set symtab language to language from DW_AT_language. If the
4740 compilation is from a C file generated by language preprocessors, do
4741 not set the language if it was already deduced by start_subfile. */
4742 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4743 symtab
->language
= cu
->language
;
4745 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4746 produce DW_AT_location with location lists but it can be possibly
4747 invalid without -fvar-tracking.
4749 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4750 needed, it would be wrong due to missing DW_AT_producer there.
4752 Still one can confuse GDB by using non-standard GCC compilation
4753 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4755 if (cu
->has_loclist
&& gcc_4_minor
>= 0)
4756 symtab
->locations_valid
= 1;
4758 if (gcc_4_minor
>= 5)
4759 symtab
->epilogue_unwind_valid
= 1;
4762 if (dwarf2_per_objfile
->using_index
)
4763 per_cu
->v
.quick
->symtab
= symtab
;
4766 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4767 pst
->symtab
= symtab
;
4771 do_cleanups (back_to
);
4774 /* Process a die and its children. */
4777 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4781 case DW_TAG_padding
:
4783 case DW_TAG_compile_unit
:
4784 read_file_scope (die
, cu
);
4786 case DW_TAG_type_unit
:
4787 read_type_unit_scope (die
, cu
);
4789 case DW_TAG_subprogram
:
4790 case DW_TAG_inlined_subroutine
:
4791 read_func_scope (die
, cu
);
4793 case DW_TAG_lexical_block
:
4794 case DW_TAG_try_block
:
4795 case DW_TAG_catch_block
:
4796 read_lexical_block_scope (die
, cu
);
4798 case DW_TAG_class_type
:
4799 case DW_TAG_interface_type
:
4800 case DW_TAG_structure_type
:
4801 case DW_TAG_union_type
:
4802 process_structure_scope (die
, cu
);
4804 case DW_TAG_enumeration_type
:
4805 process_enumeration_scope (die
, cu
);
4808 /* These dies have a type, but processing them does not create
4809 a symbol or recurse to process the children. Therefore we can
4810 read them on-demand through read_type_die. */
4811 case DW_TAG_subroutine_type
:
4812 case DW_TAG_set_type
:
4813 case DW_TAG_array_type
:
4814 case DW_TAG_pointer_type
:
4815 case DW_TAG_ptr_to_member_type
:
4816 case DW_TAG_reference_type
:
4817 case DW_TAG_string_type
:
4820 case DW_TAG_base_type
:
4821 case DW_TAG_subrange_type
:
4822 case DW_TAG_typedef
:
4823 /* Add a typedef symbol for the type definition, if it has a
4825 new_symbol (die
, read_type_die (die
, cu
), cu
);
4827 case DW_TAG_common_block
:
4828 read_common_block (die
, cu
);
4830 case DW_TAG_common_inclusion
:
4832 case DW_TAG_namespace
:
4833 processing_has_namespace_info
= 1;
4834 read_namespace (die
, cu
);
4837 processing_has_namespace_info
= 1;
4838 read_module (die
, cu
);
4840 case DW_TAG_imported_declaration
:
4841 case DW_TAG_imported_module
:
4842 processing_has_namespace_info
= 1;
4843 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4844 || cu
->language
!= language_fortran
))
4845 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4846 dwarf_tag_name (die
->tag
));
4847 read_import_statement (die
, cu
);
4850 new_symbol (die
, NULL
, cu
);
4855 /* A helper function for dwarf2_compute_name which determines whether DIE
4856 needs to have the name of the scope prepended to the name listed in the
4860 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4862 struct attribute
*attr
;
4866 case DW_TAG_namespace
:
4867 case DW_TAG_typedef
:
4868 case DW_TAG_class_type
:
4869 case DW_TAG_interface_type
:
4870 case DW_TAG_structure_type
:
4871 case DW_TAG_union_type
:
4872 case DW_TAG_enumeration_type
:
4873 case DW_TAG_enumerator
:
4874 case DW_TAG_subprogram
:
4878 case DW_TAG_variable
:
4879 case DW_TAG_constant
:
4880 /* We only need to prefix "globally" visible variables. These include
4881 any variable marked with DW_AT_external or any variable that
4882 lives in a namespace. [Variables in anonymous namespaces
4883 require prefixing, but they are not DW_AT_external.] */
4885 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4887 struct dwarf2_cu
*spec_cu
= cu
;
4889 return die_needs_namespace (die_specification (die
, &spec_cu
),
4893 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4894 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4895 && die
->parent
->tag
!= DW_TAG_module
)
4897 /* A variable in a lexical block of some kind does not need a
4898 namespace, even though in C++ such variables may be external
4899 and have a mangled name. */
4900 if (die
->parent
->tag
== DW_TAG_lexical_block
4901 || die
->parent
->tag
== DW_TAG_try_block
4902 || die
->parent
->tag
== DW_TAG_catch_block
4903 || die
->parent
->tag
== DW_TAG_subprogram
)
4912 /* Retrieve the last character from a mem_file. */
4915 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4917 char *last_char_p
= (char *) object
;
4920 *last_char_p
= buffer
[length
- 1];
4923 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4924 compute the physname for the object, which include a method's
4925 formal parameters (C++/Java) and return type (Java).
4927 For Ada, return the DIE's linkage name rather than the fully qualified
4928 name. PHYSNAME is ignored..
4930 The result is allocated on the objfile_obstack and canonicalized. */
4933 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4937 name
= dwarf2_name (die
, cu
);
4939 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4940 compute it by typename_concat inside GDB. */
4941 if (cu
->language
== language_ada
4942 || (cu
->language
== language_fortran
&& physname
))
4944 /* For Ada unit, we prefer the linkage name over the name, as
4945 the former contains the exported name, which the user expects
4946 to be able to reference. Ideally, we want the user to be able
4947 to reference this entity using either natural or linkage name,
4948 but we haven't started looking at this enhancement yet. */
4949 struct attribute
*attr
;
4951 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4953 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4954 if (attr
&& DW_STRING (attr
))
4955 return DW_STRING (attr
);
4958 /* These are the only languages we know how to qualify names in. */
4960 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4961 || cu
->language
== language_fortran
))
4963 if (die_needs_namespace (die
, cu
))
4967 struct ui_file
*buf
;
4969 prefix
= determine_prefix (die
, cu
);
4970 buf
= mem_fileopen ();
4971 if (*prefix
!= '\0')
4973 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4976 fputs_unfiltered (prefixed_name
, buf
);
4977 xfree (prefixed_name
);
4980 fputs_unfiltered (name
, buf
);
4982 /* Template parameters may be specified in the DIE's DW_AT_name, or
4983 as children with DW_TAG_template_type_param or
4984 DW_TAG_value_type_param. If the latter, add them to the name
4985 here. If the name already has template parameters, then
4986 skip this step; some versions of GCC emit both, and
4987 it is more efficient to use the pre-computed name.
4989 Something to keep in mind about this process: it is very
4990 unlikely, or in some cases downright impossible, to produce
4991 something that will match the mangled name of a function.
4992 If the definition of the function has the same debug info,
4993 we should be able to match up with it anyway. But fallbacks
4994 using the minimal symbol, for instance to find a method
4995 implemented in a stripped copy of libstdc++, will not work.
4996 If we do not have debug info for the definition, we will have to
4997 match them up some other way.
4999 When we do name matching there is a related problem with function
5000 templates; two instantiated function templates are allowed to
5001 differ only by their return types, which we do not add here. */
5003 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5005 struct attribute
*attr
;
5006 struct die_info
*child
;
5009 die
->building_fullname
= 1;
5011 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5016 struct dwarf2_locexpr_baton
*baton
;
5019 if (child
->tag
!= DW_TAG_template_type_param
5020 && child
->tag
!= DW_TAG_template_value_param
)
5025 fputs_unfiltered ("<", buf
);
5029 fputs_unfiltered (", ", buf
);
5031 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5034 complaint (&symfile_complaints
,
5035 _("template parameter missing DW_AT_type"));
5036 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5039 type
= die_type (child
, cu
);
5041 if (child
->tag
== DW_TAG_template_type_param
)
5043 c_print_type (type
, "", buf
, -1, 0);
5047 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5050 complaint (&symfile_complaints
,
5051 _("template parameter missing "
5052 "DW_AT_const_value"));
5053 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5057 dwarf2_const_value_attr (attr
, type
, name
,
5058 &cu
->comp_unit_obstack
, cu
,
5059 &value
, &bytes
, &baton
);
5061 if (TYPE_NOSIGN (type
))
5062 /* GDB prints characters as NUMBER 'CHAR'. If that's
5063 changed, this can use value_print instead. */
5064 c_printchar (value
, type
, buf
);
5067 struct value_print_options opts
;
5070 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5074 else if (bytes
!= NULL
)
5076 v
= allocate_value (type
);
5077 memcpy (value_contents_writeable (v
), bytes
,
5078 TYPE_LENGTH (type
));
5081 v
= value_from_longest (type
, value
);
5083 /* Specify decimal so that we do not depend on
5085 get_formatted_print_options (&opts
, 'd');
5087 value_print (v
, buf
, &opts
);
5093 die
->building_fullname
= 0;
5097 /* Close the argument list, with a space if necessary
5098 (nested templates). */
5099 char last_char
= '\0';
5100 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5101 if (last_char
== '>')
5102 fputs_unfiltered (" >", buf
);
5104 fputs_unfiltered (">", buf
);
5108 /* For Java and C++ methods, append formal parameter type
5109 information, if PHYSNAME. */
5111 if (physname
&& die
->tag
== DW_TAG_subprogram
5112 && (cu
->language
== language_cplus
5113 || cu
->language
== language_java
))
5115 struct type
*type
= read_type_die (die
, cu
);
5117 c_type_print_args (type
, buf
, 1, cu
->language
);
5119 if (cu
->language
== language_java
)
5121 /* For java, we must append the return type to method
5123 if (die
->tag
== DW_TAG_subprogram
)
5124 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5127 else if (cu
->language
== language_cplus
)
5129 /* Assume that an artificial first parameter is
5130 "this", but do not crash if it is not. RealView
5131 marks unnamed (and thus unused) parameters as
5132 artificial; there is no way to differentiate
5134 if (TYPE_NFIELDS (type
) > 0
5135 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5136 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5137 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5139 fputs_unfiltered (" const", buf
);
5143 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
5145 ui_file_delete (buf
);
5147 if (cu
->language
== language_cplus
)
5150 = dwarf2_canonicalize_name (name
, cu
,
5151 &cu
->objfile
->objfile_obstack
);
5162 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5163 If scope qualifiers are appropriate they will be added. The result
5164 will be allocated on the objfile_obstack, or NULL if the DIE does
5165 not have a name. NAME may either be from a previous call to
5166 dwarf2_name or NULL.
5168 The output string will be canonicalized (if C++/Java). */
5171 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5173 return dwarf2_compute_name (name
, die
, cu
, 0);
5176 /* Construct a physname for the given DIE in CU. NAME may either be
5177 from a previous call to dwarf2_name or NULL. The result will be
5178 allocated on the objfile_objstack or NULL if the DIE does not have a
5181 The output string will be canonicalized (if C++/Java). */
5184 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5186 struct attribute
*attr
;
5187 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5188 struct cleanup
*back_to
;
5191 /* In this case dwarf2_compute_name is just a shortcut not building anything
5193 if (!die_needs_namespace (die
, cu
))
5194 return dwarf2_compute_name (name
, die
, cu
, 1);
5196 back_to
= make_cleanup (null_cleanup
, NULL
);
5198 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5200 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5202 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5204 if (attr
&& DW_STRING (attr
))
5208 mangled
= DW_STRING (attr
);
5210 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5211 type. It is easier for GDB users to search for such functions as
5212 `name(params)' than `long name(params)'. In such case the minimal
5213 symbol names do not match the full symbol names but for template
5214 functions there is never a need to look up their definition from their
5215 declaration so the only disadvantage remains the minimal symbol
5216 variant `long name(params)' does not have the proper inferior type.
5219 demangled
= cplus_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
5220 | (cu
->language
== language_java
5221 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5225 make_cleanup (xfree
, demangled
);
5235 if (canon
== NULL
|| check_physname
)
5237 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5239 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5241 /* It may not mean a bug in GDB. The compiler could also
5242 compute DW_AT_linkage_name incorrectly. But in such case
5243 GDB would need to be bug-to-bug compatible. */
5245 complaint (&symfile_complaints
,
5246 _("Computed physname <%s> does not match demangled <%s> "
5247 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5248 physname
, canon
, mangled
, die
->offset
, cu
->objfile
->name
);
5250 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5251 is available here - over computed PHYSNAME. It is safer
5252 against both buggy GDB and buggy compilers. */
5266 retval
= obsavestring (retval
, strlen (retval
),
5267 &cu
->objfile
->objfile_obstack
);
5269 do_cleanups (back_to
);
5273 /* Read the import statement specified by the given die and record it. */
5276 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5278 struct attribute
*import_attr
;
5279 struct die_info
*imported_die
, *child_die
;
5280 struct dwarf2_cu
*imported_cu
;
5281 const char *imported_name
;
5282 const char *imported_name_prefix
;
5283 const char *canonical_name
;
5284 const char *import_alias
;
5285 const char *imported_declaration
= NULL
;
5286 const char *import_prefix
;
5287 VEC (const_char_ptr
) *excludes
= NULL
;
5288 struct cleanup
*cleanups
;
5292 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5293 if (import_attr
== NULL
)
5295 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5296 dwarf_tag_name (die
->tag
));
5301 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5302 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5303 if (imported_name
== NULL
)
5305 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5307 The import in the following code:
5321 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5322 <52> DW_AT_decl_file : 1
5323 <53> DW_AT_decl_line : 6
5324 <54> DW_AT_import : <0x75>
5325 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5327 <5b> DW_AT_decl_file : 1
5328 <5c> DW_AT_decl_line : 2
5329 <5d> DW_AT_type : <0x6e>
5331 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5332 <76> DW_AT_byte_size : 4
5333 <77> DW_AT_encoding : 5 (signed)
5335 imports the wrong die ( 0x75 instead of 0x58 ).
5336 This case will be ignored until the gcc bug is fixed. */
5340 /* Figure out the local name after import. */
5341 import_alias
= dwarf2_name (die
, cu
);
5343 /* Figure out where the statement is being imported to. */
5344 import_prefix
= determine_prefix (die
, cu
);
5346 /* Figure out what the scope of the imported die is and prepend it
5347 to the name of the imported die. */
5348 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5350 if (imported_die
->tag
!= DW_TAG_namespace
5351 && imported_die
->tag
!= DW_TAG_module
)
5353 imported_declaration
= imported_name
;
5354 canonical_name
= imported_name_prefix
;
5356 else if (strlen (imported_name_prefix
) > 0)
5358 temp
= alloca (strlen (imported_name_prefix
)
5359 + 2 + strlen (imported_name
) + 1);
5360 strcpy (temp
, imported_name_prefix
);
5361 strcat (temp
, "::");
5362 strcat (temp
, imported_name
);
5363 canonical_name
= temp
;
5366 canonical_name
= imported_name
;
5368 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5370 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5371 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5372 child_die
= sibling_die (child_die
))
5374 /* DWARF-4: A Fortran use statement with a “rename list” may be
5375 represented by an imported module entry with an import attribute
5376 referring to the module and owned entries corresponding to those
5377 entities that are renamed as part of being imported. */
5379 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5381 complaint (&symfile_complaints
,
5382 _("child DW_TAG_imported_declaration expected "
5383 "- DIE at 0x%x [in module %s]"),
5384 child_die
->offset
, cu
->objfile
->name
);
5388 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5389 if (import_attr
== NULL
)
5391 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5392 dwarf_tag_name (child_die
->tag
));
5397 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5399 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5400 if (imported_name
== NULL
)
5402 complaint (&symfile_complaints
,
5403 _("child DW_TAG_imported_declaration has unknown "
5404 "imported name - DIE at 0x%x [in module %s]"),
5405 child_die
->offset
, cu
->objfile
->name
);
5409 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5411 process_die (child_die
, cu
);
5414 cp_add_using_directive (import_prefix
,
5417 imported_declaration
,
5419 &cu
->objfile
->objfile_obstack
);
5421 do_cleanups (cleanups
);
5425 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5427 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5430 /* Cleanup function for read_file_scope. */
5433 free_cu_line_header (void *arg
)
5435 struct dwarf2_cu
*cu
= arg
;
5437 free_line_header (cu
->line_header
);
5438 cu
->line_header
= NULL
;
5442 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5443 char **name
, char **comp_dir
)
5445 struct attribute
*attr
;
5450 /* Find the filename. Do not use dwarf2_name here, since the filename
5451 is not a source language identifier. */
5452 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5455 *name
= DW_STRING (attr
);
5458 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5460 *comp_dir
= DW_STRING (attr
);
5461 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5463 *comp_dir
= ldirname (*name
);
5464 if (*comp_dir
!= NULL
)
5465 make_cleanup (xfree
, *comp_dir
);
5467 if (*comp_dir
!= NULL
)
5469 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5470 directory, get rid of it. */
5471 char *cp
= strchr (*comp_dir
, ':');
5473 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5478 *name
= "<unknown>";
5481 /* Process DW_TAG_compile_unit. */
5484 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5486 struct objfile
*objfile
= cu
->objfile
;
5487 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5488 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5489 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5490 struct attribute
*attr
;
5492 char *comp_dir
= NULL
;
5493 struct die_info
*child_die
;
5494 bfd
*abfd
= objfile
->obfd
;
5495 struct line_header
*line_header
= 0;
5498 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5500 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5502 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5503 from finish_block. */
5504 if (lowpc
== ((CORE_ADDR
) -1))
5509 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5511 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5514 set_cu_language (DW_UNSND (attr
), cu
);
5517 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5519 cu
->producer
= DW_STRING (attr
);
5521 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5522 standardised yet. As a workaround for the language detection we fall
5523 back to the DW_AT_producer string. */
5524 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5525 cu
->language
= language_opencl
;
5527 /* We assume that we're processing GCC output. */
5528 processing_gcc_compilation
= 2;
5530 processing_has_namespace_info
= 0;
5532 start_symtab (name
, comp_dir
, lowpc
);
5533 record_debugformat ("DWARF 2");
5534 record_producer (cu
->producer
);
5536 initialize_cu_func_list (cu
);
5538 /* Decode line number information if present. We do this before
5539 processing child DIEs, so that the line header table is available
5540 for DW_AT_decl_file. */
5541 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5544 unsigned int line_offset
= DW_UNSND (attr
);
5545 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5548 cu
->line_header
= line_header
;
5549 make_cleanup (free_cu_line_header
, cu
);
5550 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5554 /* Process all dies in compilation unit. */
5555 if (die
->child
!= NULL
)
5557 child_die
= die
->child
;
5558 while (child_die
&& child_die
->tag
)
5560 process_die (child_die
, cu
);
5561 child_die
= sibling_die (child_die
);
5565 /* Decode macro information, if present. Dwarf 2 macro information
5566 refers to information in the line number info statement program
5567 header, so we can only read it if we've read the header
5569 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5570 if (attr
&& line_header
)
5572 unsigned int macro_offset
= DW_UNSND (attr
);
5574 dwarf_decode_macros (line_header
, macro_offset
,
5575 comp_dir
, abfd
, cu
);
5577 do_cleanups (back_to
);
5580 /* Process DW_TAG_type_unit.
5581 For TUs we want to skip the first top level sibling if it's not the
5582 actual type being defined by this TU. In this case the first top
5583 level sibling is there to provide context only. */
5586 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5588 struct objfile
*objfile
= cu
->objfile
;
5589 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5591 struct attribute
*attr
;
5593 char *comp_dir
= NULL
;
5594 struct die_info
*child_die
;
5595 bfd
*abfd
= objfile
->obfd
;
5597 /* start_symtab needs a low pc, but we don't really have one.
5598 Do what read_file_scope would do in the absence of such info. */
5599 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5601 /* Find the filename. Do not use dwarf2_name here, since the filename
5602 is not a source language identifier. */
5603 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5605 name
= DW_STRING (attr
);
5607 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5609 comp_dir
= DW_STRING (attr
);
5610 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5612 comp_dir
= ldirname (name
);
5613 if (comp_dir
!= NULL
)
5614 make_cleanup (xfree
, comp_dir
);
5620 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5622 set_cu_language (DW_UNSND (attr
), cu
);
5624 /* This isn't technically needed today. It is done for symmetry
5625 with read_file_scope. */
5626 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5628 cu
->producer
= DW_STRING (attr
);
5630 /* We assume that we're processing GCC output. */
5631 processing_gcc_compilation
= 2;
5633 processing_has_namespace_info
= 0;
5635 start_symtab (name
, comp_dir
, lowpc
);
5636 record_debugformat ("DWARF 2");
5637 record_producer (cu
->producer
);
5639 /* Process the dies in the type unit. */
5640 if (die
->child
== NULL
)
5642 dump_die_for_error (die
);
5643 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5644 bfd_get_filename (abfd
));
5647 child_die
= die
->child
;
5649 while (child_die
&& child_die
->tag
)
5651 process_die (child_die
, cu
);
5653 child_die
= sibling_die (child_die
);
5656 do_cleanups (back_to
);
5660 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5661 struct dwarf2_cu
*cu
)
5663 struct function_range
*thisfn
;
5665 thisfn
= (struct function_range
*)
5666 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5667 thisfn
->name
= name
;
5668 thisfn
->lowpc
= lowpc
;
5669 thisfn
->highpc
= highpc
;
5670 thisfn
->seen_line
= 0;
5671 thisfn
->next
= NULL
;
5673 if (cu
->last_fn
== NULL
)
5674 cu
->first_fn
= thisfn
;
5676 cu
->last_fn
->next
= thisfn
;
5678 cu
->last_fn
= thisfn
;
5681 /* qsort helper for inherit_abstract_dies. */
5684 unsigned_int_compar (const void *ap
, const void *bp
)
5686 unsigned int a
= *(unsigned int *) ap
;
5687 unsigned int b
= *(unsigned int *) bp
;
5689 return (a
> b
) - (b
> a
);
5692 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5693 Inherit only the children of the DW_AT_abstract_origin DIE not being
5694 already referenced by DW_AT_abstract_origin from the children of the
5698 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5700 struct die_info
*child_die
;
5701 unsigned die_children_count
;
5702 /* CU offsets which were referenced by children of the current DIE. */
5704 unsigned *offsets_end
, *offsetp
;
5705 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5706 struct die_info
*origin_die
;
5707 /* Iterator of the ORIGIN_DIE children. */
5708 struct die_info
*origin_child_die
;
5709 struct cleanup
*cleanups
;
5710 struct attribute
*attr
;
5711 struct dwarf2_cu
*origin_cu
;
5712 struct pending
**origin_previous_list_in_scope
;
5714 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5718 /* Note that following die references may follow to a die in a
5722 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5724 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5726 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5727 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5729 if (die
->tag
!= origin_die
->tag
5730 && !(die
->tag
== DW_TAG_inlined_subroutine
5731 && origin_die
->tag
== DW_TAG_subprogram
))
5732 complaint (&symfile_complaints
,
5733 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5734 die
->offset
, origin_die
->offset
);
5736 child_die
= die
->child
;
5737 die_children_count
= 0;
5738 while (child_die
&& child_die
->tag
)
5740 child_die
= sibling_die (child_die
);
5741 die_children_count
++;
5743 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5744 cleanups
= make_cleanup (xfree
, offsets
);
5746 offsets_end
= offsets
;
5747 child_die
= die
->child
;
5748 while (child_die
&& child_die
->tag
)
5750 /* For each CHILD_DIE, find the corresponding child of
5751 ORIGIN_DIE. If there is more than one layer of
5752 DW_AT_abstract_origin, follow them all; there shouldn't be,
5753 but GCC versions at least through 4.4 generate this (GCC PR
5755 struct die_info
*child_origin_die
= child_die
;
5756 struct dwarf2_cu
*child_origin_cu
= cu
;
5760 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5764 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5768 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5769 counterpart may exist. */
5770 if (child_origin_die
!= child_die
)
5772 if (child_die
->tag
!= child_origin_die
->tag
5773 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5774 && child_origin_die
->tag
== DW_TAG_subprogram
))
5775 complaint (&symfile_complaints
,
5776 _("Child DIE 0x%x and its abstract origin 0x%x have "
5777 "different tags"), child_die
->offset
,
5778 child_origin_die
->offset
);
5779 if (child_origin_die
->parent
!= origin_die
)
5780 complaint (&symfile_complaints
,
5781 _("Child DIE 0x%x and its abstract origin 0x%x have "
5782 "different parents"), child_die
->offset
,
5783 child_origin_die
->offset
);
5785 *offsets_end
++ = child_origin_die
->offset
;
5787 child_die
= sibling_die (child_die
);
5789 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5790 unsigned_int_compar
);
5791 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5792 if (offsetp
[-1] == *offsetp
)
5793 complaint (&symfile_complaints
,
5794 _("Multiple children of DIE 0x%x refer "
5795 "to DIE 0x%x as their abstract origin"),
5796 die
->offset
, *offsetp
);
5799 origin_child_die
= origin_die
->child
;
5800 while (origin_child_die
&& origin_child_die
->tag
)
5802 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5803 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5805 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5807 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5808 process_die (origin_child_die
, origin_cu
);
5810 origin_child_die
= sibling_die (origin_child_die
);
5812 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5814 do_cleanups (cleanups
);
5818 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5820 struct objfile
*objfile
= cu
->objfile
;
5821 struct context_stack
*new;
5824 struct die_info
*child_die
;
5825 struct attribute
*attr
, *call_line
, *call_file
;
5828 struct block
*block
;
5829 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5830 VEC (symbolp
) *template_args
= NULL
;
5831 struct template_symbol
*templ_func
= NULL
;
5835 /* If we do not have call site information, we can't show the
5836 caller of this inlined function. That's too confusing, so
5837 only use the scope for local variables. */
5838 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5839 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5840 if (call_line
== NULL
|| call_file
== NULL
)
5842 read_lexical_block_scope (die
, cu
);
5847 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5849 name
= dwarf2_name (die
, cu
);
5851 /* Ignore functions with missing or empty names. These are actually
5852 illegal according to the DWARF standard. */
5855 complaint (&symfile_complaints
,
5856 _("missing name for subprogram DIE at %d"), die
->offset
);
5860 /* Ignore functions with missing or invalid low and high pc attributes. */
5861 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5863 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5864 if (!attr
|| !DW_UNSND (attr
))
5865 complaint (&symfile_complaints
,
5866 _("cannot get low and high bounds "
5867 "for subprogram DIE at %d"),
5875 /* Record the function range for dwarf_decode_lines. */
5876 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5878 /* If we have any template arguments, then we must allocate a
5879 different sort of symbol. */
5880 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5882 if (child_die
->tag
== DW_TAG_template_type_param
5883 || child_die
->tag
== DW_TAG_template_value_param
)
5885 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5886 struct template_symbol
);
5887 templ_func
->base
.is_cplus_template_function
= 1;
5892 new = push_context (0, lowpc
);
5893 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5894 (struct symbol
*) templ_func
);
5896 /* If there is a location expression for DW_AT_frame_base, record
5898 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5900 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5901 expression is being recorded directly in the function's symbol
5902 and not in a separate frame-base object. I guess this hack is
5903 to avoid adding some sort of frame-base adjunct/annex to the
5904 function's symbol :-(. The problem with doing this is that it
5905 results in a function symbol with a location expression that
5906 has nothing to do with the location of the function, ouch! The
5907 relationship should be: a function's symbol has-a frame base; a
5908 frame-base has-a location expression. */
5909 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5911 cu
->list_in_scope
= &local_symbols
;
5913 if (die
->child
!= NULL
)
5915 child_die
= die
->child
;
5916 while (child_die
&& child_die
->tag
)
5918 if (child_die
->tag
== DW_TAG_template_type_param
5919 || child_die
->tag
== DW_TAG_template_value_param
)
5921 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5924 VEC_safe_push (symbolp
, template_args
, arg
);
5927 process_die (child_die
, cu
);
5928 child_die
= sibling_die (child_die
);
5932 inherit_abstract_dies (die
, cu
);
5934 /* If we have a DW_AT_specification, we might need to import using
5935 directives from the context of the specification DIE. See the
5936 comment in determine_prefix. */
5937 if (cu
->language
== language_cplus
5938 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5940 struct dwarf2_cu
*spec_cu
= cu
;
5941 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5945 child_die
= spec_die
->child
;
5946 while (child_die
&& child_die
->tag
)
5948 if (child_die
->tag
== DW_TAG_imported_module
)
5949 process_die (child_die
, spec_cu
);
5950 child_die
= sibling_die (child_die
);
5953 /* In some cases, GCC generates specification DIEs that
5954 themselves contain DW_AT_specification attributes. */
5955 spec_die
= die_specification (spec_die
, &spec_cu
);
5959 new = pop_context ();
5960 /* Make a block for the local symbols within. */
5961 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5962 lowpc
, highpc
, objfile
);
5964 /* For C++, set the block's scope. */
5965 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5966 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5967 determine_prefix (die
, cu
),
5968 processing_has_namespace_info
);
5970 /* If we have address ranges, record them. */
5971 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5973 /* Attach template arguments to function. */
5974 if (! VEC_empty (symbolp
, template_args
))
5976 gdb_assert (templ_func
!= NULL
);
5978 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5979 templ_func
->template_arguments
5980 = obstack_alloc (&objfile
->objfile_obstack
,
5981 (templ_func
->n_template_arguments
5982 * sizeof (struct symbol
*)));
5983 memcpy (templ_func
->template_arguments
,
5984 VEC_address (symbolp
, template_args
),
5985 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5986 VEC_free (symbolp
, template_args
);
5989 /* In C++, we can have functions nested inside functions (e.g., when
5990 a function declares a class that has methods). This means that
5991 when we finish processing a function scope, we may need to go
5992 back to building a containing block's symbol lists. */
5993 local_symbols
= new->locals
;
5994 param_symbols
= new->params
;
5995 using_directives
= new->using_directives
;
5997 /* If we've finished processing a top-level function, subsequent
5998 symbols go in the file symbol list. */
5999 if (outermost_context_p ())
6000 cu
->list_in_scope
= &file_symbols
;
6003 /* Process all the DIES contained within a lexical block scope. Start
6004 a new scope, process the dies, and then close the scope. */
6007 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6009 struct objfile
*objfile
= cu
->objfile
;
6010 struct context_stack
*new;
6011 CORE_ADDR lowpc
, highpc
;
6012 struct die_info
*child_die
;
6015 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6017 /* Ignore blocks with missing or invalid low and high pc attributes. */
6018 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6019 as multiple lexical blocks? Handling children in a sane way would
6020 be nasty. Might be easier to properly extend generic blocks to
6022 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6027 push_context (0, lowpc
);
6028 if (die
->child
!= NULL
)
6030 child_die
= die
->child
;
6031 while (child_die
&& child_die
->tag
)
6033 process_die (child_die
, cu
);
6034 child_die
= sibling_die (child_die
);
6037 new = pop_context ();
6039 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6042 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6045 /* Note that recording ranges after traversing children, as we
6046 do here, means that recording a parent's ranges entails
6047 walking across all its children's ranges as they appear in
6048 the address map, which is quadratic behavior.
6050 It would be nicer to record the parent's ranges before
6051 traversing its children, simply overriding whatever you find
6052 there. But since we don't even decide whether to create a
6053 block until after we've traversed its children, that's hard
6055 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6057 local_symbols
= new->locals
;
6058 using_directives
= new->using_directives
;
6061 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6062 Return 1 if the attributes are present and valid, otherwise, return 0.
6063 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6066 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6067 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6068 struct partial_symtab
*ranges_pst
)
6070 struct objfile
*objfile
= cu
->objfile
;
6071 struct comp_unit_head
*cu_header
= &cu
->header
;
6072 bfd
*obfd
= objfile
->obfd
;
6073 unsigned int addr_size
= cu_header
->addr_size
;
6074 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6075 /* Base address selection entry. */
6086 found_base
= cu
->base_known
;
6087 base
= cu
->base_address
;
6089 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6090 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6092 complaint (&symfile_complaints
,
6093 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6097 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6099 /* Read in the largest possible address. */
6100 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6101 if ((marker
& mask
) == mask
)
6103 /* If we found the largest possible address, then
6104 read the base address. */
6105 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6106 buffer
+= 2 * addr_size
;
6107 offset
+= 2 * addr_size
;
6113 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6117 CORE_ADDR range_beginning
, range_end
;
6119 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6120 buffer
+= addr_size
;
6121 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6122 buffer
+= addr_size
;
6123 offset
+= 2 * addr_size
;
6125 /* An end of list marker is a pair of zero addresses. */
6126 if (range_beginning
== 0 && range_end
== 0)
6127 /* Found the end of list entry. */
6130 /* Each base address selection entry is a pair of 2 values.
6131 The first is the largest possible address, the second is
6132 the base address. Check for a base address here. */
6133 if ((range_beginning
& mask
) == mask
)
6135 /* If we found the largest possible address, then
6136 read the base address. */
6137 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6144 /* We have no valid base address for the ranges
6146 complaint (&symfile_complaints
,
6147 _("Invalid .debug_ranges data (no base address)"));
6151 if (range_beginning
> range_end
)
6153 /* Inverted range entries are invalid. */
6154 complaint (&symfile_complaints
,
6155 _("Invalid .debug_ranges data (inverted range)"));
6159 /* Empty range entries have no effect. */
6160 if (range_beginning
== range_end
)
6163 range_beginning
+= base
;
6166 if (ranges_pst
!= NULL
)
6167 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6168 range_beginning
+ baseaddr
,
6169 range_end
- 1 + baseaddr
,
6172 /* FIXME: This is recording everything as a low-high
6173 segment of consecutive addresses. We should have a
6174 data structure for discontiguous block ranges
6178 low
= range_beginning
;
6184 if (range_beginning
< low
)
6185 low
= range_beginning
;
6186 if (range_end
> high
)
6192 /* If the first entry is an end-of-list marker, the range
6193 describes an empty scope, i.e. no instructions. */
6199 *high_return
= high
;
6203 /* Get low and high pc attributes from a die. Return 1 if the attributes
6204 are present and valid, otherwise, return 0. Return -1 if the range is
6205 discontinuous, i.e. derived from DW_AT_ranges information. */
6207 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6208 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6209 struct partial_symtab
*pst
)
6211 struct attribute
*attr
;
6216 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6219 high
= DW_ADDR (attr
);
6220 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6222 low
= DW_ADDR (attr
);
6224 /* Found high w/o low attribute. */
6227 /* Found consecutive range of addresses. */
6232 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6235 /* Value of the DW_AT_ranges attribute is the offset in the
6236 .debug_ranges section. */
6237 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6239 /* Found discontinuous range of addresses. */
6244 /* read_partial_die has also the strict LOW < HIGH requirement. */
6248 /* When using the GNU linker, .gnu.linkonce. sections are used to
6249 eliminate duplicate copies of functions and vtables and such.
6250 The linker will arbitrarily choose one and discard the others.
6251 The AT_*_pc values for such functions refer to local labels in
6252 these sections. If the section from that file was discarded, the
6253 labels are not in the output, so the relocs get a value of 0.
6254 If this is a discarded function, mark the pc bounds as invalid,
6255 so that GDB will ignore it. */
6256 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6264 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6265 its low and high PC addresses. Do nothing if these addresses could not
6266 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6267 and HIGHPC to the high address if greater than HIGHPC. */
6270 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6271 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6272 struct dwarf2_cu
*cu
)
6274 CORE_ADDR low
, high
;
6275 struct die_info
*child
= die
->child
;
6277 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6279 *lowpc
= min (*lowpc
, low
);
6280 *highpc
= max (*highpc
, high
);
6283 /* If the language does not allow nested subprograms (either inside
6284 subprograms or lexical blocks), we're done. */
6285 if (cu
->language
!= language_ada
)
6288 /* Check all the children of the given DIE. If it contains nested
6289 subprograms, then check their pc bounds. Likewise, we need to
6290 check lexical blocks as well, as they may also contain subprogram
6292 while (child
&& child
->tag
)
6294 if (child
->tag
== DW_TAG_subprogram
6295 || child
->tag
== DW_TAG_lexical_block
)
6296 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6297 child
= sibling_die (child
);
6301 /* Get the low and high pc's represented by the scope DIE, and store
6302 them in *LOWPC and *HIGHPC. If the correct values can't be
6303 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6306 get_scope_pc_bounds (struct die_info
*die
,
6307 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6308 struct dwarf2_cu
*cu
)
6310 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6311 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6312 CORE_ADDR current_low
, current_high
;
6314 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6316 best_low
= current_low
;
6317 best_high
= current_high
;
6321 struct die_info
*child
= die
->child
;
6323 while (child
&& child
->tag
)
6325 switch (child
->tag
) {
6326 case DW_TAG_subprogram
:
6327 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6329 case DW_TAG_namespace
:
6331 /* FIXME: carlton/2004-01-16: Should we do this for
6332 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6333 that current GCC's always emit the DIEs corresponding
6334 to definitions of methods of classes as children of a
6335 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6336 the DIEs giving the declarations, which could be
6337 anywhere). But I don't see any reason why the
6338 standards says that they have to be there. */
6339 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6341 if (current_low
!= ((CORE_ADDR
) -1))
6343 best_low
= min (best_low
, current_low
);
6344 best_high
= max (best_high
, current_high
);
6352 child
= sibling_die (child
);
6357 *highpc
= best_high
;
6360 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6363 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6364 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6366 struct attribute
*attr
;
6368 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6371 CORE_ADDR high
= DW_ADDR (attr
);
6373 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6376 CORE_ADDR low
= DW_ADDR (attr
);
6378 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6382 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6385 bfd
*obfd
= cu
->objfile
->obfd
;
6387 /* The value of the DW_AT_ranges attribute is the offset of the
6388 address range list in the .debug_ranges section. */
6389 unsigned long offset
= DW_UNSND (attr
);
6390 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6392 /* For some target architectures, but not others, the
6393 read_address function sign-extends the addresses it returns.
6394 To recognize base address selection entries, we need a
6396 unsigned int addr_size
= cu
->header
.addr_size
;
6397 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6399 /* The base address, to which the next pair is relative. Note
6400 that this 'base' is a DWARF concept: most entries in a range
6401 list are relative, to reduce the number of relocs against the
6402 debugging information. This is separate from this function's
6403 'baseaddr' argument, which GDB uses to relocate debugging
6404 information from a shared library based on the address at
6405 which the library was loaded. */
6406 CORE_ADDR base
= cu
->base_address
;
6407 int base_known
= cu
->base_known
;
6409 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6410 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6412 complaint (&symfile_complaints
,
6413 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6420 unsigned int bytes_read
;
6421 CORE_ADDR start
, end
;
6423 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6424 buffer
+= bytes_read
;
6425 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6426 buffer
+= bytes_read
;
6428 /* Did we find the end of the range list? */
6429 if (start
== 0 && end
== 0)
6432 /* Did we find a base address selection entry? */
6433 else if ((start
& base_select_mask
) == base_select_mask
)
6439 /* We found an ordinary address range. */
6444 complaint (&symfile_complaints
,
6445 _("Invalid .debug_ranges data "
6446 "(no base address)"));
6452 /* Inverted range entries are invalid. */
6453 complaint (&symfile_complaints
,
6454 _("Invalid .debug_ranges data "
6455 "(inverted range)"));
6459 /* Empty range entries have no effect. */
6463 record_block_range (block
,
6464 baseaddr
+ base
+ start
,
6465 baseaddr
+ base
+ end
- 1);
6471 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6472 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6473 during 4.6.0 experimental. */
6476 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6479 int major
, minor
, release
;
6481 if (cu
->producer
== NULL
)
6483 /* For unknown compilers expect their behavior is DWARF version
6486 GCC started to support .debug_types sections by -gdwarf-4 since
6487 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6488 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6489 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6490 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6495 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6497 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6499 /* For non-GCC compilers expect their behavior is DWARF version
6504 cs
= &cu
->producer
[strlen ("GNU ")];
6505 while (*cs
&& !isdigit (*cs
))
6507 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6509 /* Not recognized as GCC. */
6514 return major
< 4 || (major
== 4 && minor
< 6);
6517 /* Return the default accessibility type if it is not overriden by
6518 DW_AT_accessibility. */
6520 static enum dwarf_access_attribute
6521 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6523 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6525 /* The default DWARF 2 accessibility for members is public, the default
6526 accessibility for inheritance is private. */
6528 if (die
->tag
!= DW_TAG_inheritance
)
6529 return DW_ACCESS_public
;
6531 return DW_ACCESS_private
;
6535 /* DWARF 3+ defines the default accessibility a different way. The same
6536 rules apply now for DW_TAG_inheritance as for the members and it only
6537 depends on the container kind. */
6539 if (die
->parent
->tag
== DW_TAG_class_type
)
6540 return DW_ACCESS_private
;
6542 return DW_ACCESS_public
;
6546 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6547 offset. If the attribute was not found return 0, otherwise return
6548 1. If it was found but could not properly be handled, set *OFFSET
6552 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
6555 struct attribute
*attr
;
6557 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6562 /* Note that we do not check for a section offset first here.
6563 This is because DW_AT_data_member_location is new in DWARF 4,
6564 so if we see it, we can assume that a constant form is really
6565 a constant and not a section offset. */
6566 if (attr_form_is_constant (attr
))
6567 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
6568 else if (attr_form_is_section_offset (attr
))
6569 dwarf2_complex_location_expr_complaint ();
6570 else if (attr_form_is_block (attr
))
6571 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6573 dwarf2_complex_location_expr_complaint ();
6581 /* Add an aggregate field to the field list. */
6584 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6585 struct dwarf2_cu
*cu
)
6587 struct objfile
*objfile
= cu
->objfile
;
6588 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6589 struct nextfield
*new_field
;
6590 struct attribute
*attr
;
6592 char *fieldname
= "";
6594 /* Allocate a new field list entry and link it in. */
6595 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6596 make_cleanup (xfree
, new_field
);
6597 memset (new_field
, 0, sizeof (struct nextfield
));
6599 if (die
->tag
== DW_TAG_inheritance
)
6601 new_field
->next
= fip
->baseclasses
;
6602 fip
->baseclasses
= new_field
;
6606 new_field
->next
= fip
->fields
;
6607 fip
->fields
= new_field
;
6611 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6613 new_field
->accessibility
= DW_UNSND (attr
);
6615 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
6616 if (new_field
->accessibility
!= DW_ACCESS_public
)
6617 fip
->non_public_fields
= 1;
6619 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6621 new_field
->virtuality
= DW_UNSND (attr
);
6623 new_field
->virtuality
= DW_VIRTUALITY_none
;
6625 fp
= &new_field
->field
;
6627 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6631 /* Data member other than a C++ static data member. */
6633 /* Get type of field. */
6634 fp
->type
= die_type (die
, cu
);
6636 SET_FIELD_BITPOS (*fp
, 0);
6638 /* Get bit size of field (zero if none). */
6639 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6642 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6646 FIELD_BITSIZE (*fp
) = 0;
6649 /* Get bit offset of field. */
6650 if (handle_data_member_location (die
, cu
, &offset
))
6651 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
6652 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6655 if (gdbarch_bits_big_endian (gdbarch
))
6657 /* For big endian bits, the DW_AT_bit_offset gives the
6658 additional bit offset from the MSB of the containing
6659 anonymous object to the MSB of the field. We don't
6660 have to do anything special since we don't need to
6661 know the size of the anonymous object. */
6662 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6666 /* For little endian bits, compute the bit offset to the
6667 MSB of the anonymous object, subtract off the number of
6668 bits from the MSB of the field to the MSB of the
6669 object, and then subtract off the number of bits of
6670 the field itself. The result is the bit offset of
6671 the LSB of the field. */
6673 int bit_offset
= DW_UNSND (attr
);
6675 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6678 /* The size of the anonymous object containing
6679 the bit field is explicit, so use the
6680 indicated size (in bytes). */
6681 anonymous_size
= DW_UNSND (attr
);
6685 /* The size of the anonymous object containing
6686 the bit field must be inferred from the type
6687 attribute of the data member containing the
6689 anonymous_size
= TYPE_LENGTH (fp
->type
);
6691 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6692 - bit_offset
- FIELD_BITSIZE (*fp
);
6696 /* Get name of field. */
6697 fieldname
= dwarf2_name (die
, cu
);
6698 if (fieldname
== NULL
)
6701 /* The name is already allocated along with this objfile, so we don't
6702 need to duplicate it for the type. */
6703 fp
->name
= fieldname
;
6705 /* Change accessibility for artificial fields (e.g. virtual table
6706 pointer or virtual base class pointer) to private. */
6707 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6709 FIELD_ARTIFICIAL (*fp
) = 1;
6710 new_field
->accessibility
= DW_ACCESS_private
;
6711 fip
->non_public_fields
= 1;
6714 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6716 /* C++ static member. */
6718 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6719 is a declaration, but all versions of G++ as of this writing
6720 (so through at least 3.2.1) incorrectly generate
6721 DW_TAG_variable tags. */
6723 const char *physname
;
6725 /* Get name of field. */
6726 fieldname
= dwarf2_name (die
, cu
);
6727 if (fieldname
== NULL
)
6730 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6732 /* Only create a symbol if this is an external value.
6733 new_symbol checks this and puts the value in the global symbol
6734 table, which we want. If it is not external, new_symbol
6735 will try to put the value in cu->list_in_scope which is wrong. */
6736 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6738 /* A static const member, not much different than an enum as far as
6739 we're concerned, except that we can support more types. */
6740 new_symbol (die
, NULL
, cu
);
6743 /* Get physical name. */
6744 physname
= dwarf2_physname (fieldname
, die
, cu
);
6746 /* The name is already allocated along with this objfile, so we don't
6747 need to duplicate it for the type. */
6748 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6749 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6750 FIELD_NAME (*fp
) = fieldname
;
6752 else if (die
->tag
== DW_TAG_inheritance
)
6756 /* C++ base class field. */
6757 if (handle_data_member_location (die
, cu
, &offset
))
6758 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
6759 FIELD_BITSIZE (*fp
) = 0;
6760 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6761 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6762 fip
->nbaseclasses
++;
6766 /* Add a typedef defined in the scope of the FIP's class. */
6769 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6770 struct dwarf2_cu
*cu
)
6772 struct objfile
*objfile
= cu
->objfile
;
6773 struct typedef_field_list
*new_field
;
6774 struct attribute
*attr
;
6775 struct typedef_field
*fp
;
6776 char *fieldname
= "";
6778 /* Allocate a new field list entry and link it in. */
6779 new_field
= xzalloc (sizeof (*new_field
));
6780 make_cleanup (xfree
, new_field
);
6782 gdb_assert (die
->tag
== DW_TAG_typedef
);
6784 fp
= &new_field
->field
;
6786 /* Get name of field. */
6787 fp
->name
= dwarf2_name (die
, cu
);
6788 if (fp
->name
== NULL
)
6791 fp
->type
= read_type_die (die
, cu
);
6793 new_field
->next
= fip
->typedef_field_list
;
6794 fip
->typedef_field_list
= new_field
;
6795 fip
->typedef_field_list_count
++;
6798 /* Create the vector of fields, and attach it to the type. */
6801 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6802 struct dwarf2_cu
*cu
)
6804 int nfields
= fip
->nfields
;
6806 /* Record the field count, allocate space for the array of fields,
6807 and create blank accessibility bitfields if necessary. */
6808 TYPE_NFIELDS (type
) = nfields
;
6809 TYPE_FIELDS (type
) = (struct field
*)
6810 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6811 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6813 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6815 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6817 TYPE_FIELD_PRIVATE_BITS (type
) =
6818 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6819 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6821 TYPE_FIELD_PROTECTED_BITS (type
) =
6822 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6823 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6825 TYPE_FIELD_IGNORE_BITS (type
) =
6826 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6827 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6830 /* If the type has baseclasses, allocate and clear a bit vector for
6831 TYPE_FIELD_VIRTUAL_BITS. */
6832 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6834 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6835 unsigned char *pointer
;
6837 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6838 pointer
= TYPE_ALLOC (type
, num_bytes
);
6839 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6840 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6841 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6844 /* Copy the saved-up fields into the field vector. Start from the head of
6845 the list, adding to the tail of the field array, so that they end up in
6846 the same order in the array in which they were added to the list. */
6847 while (nfields
-- > 0)
6849 struct nextfield
*fieldp
;
6853 fieldp
= fip
->fields
;
6854 fip
->fields
= fieldp
->next
;
6858 fieldp
= fip
->baseclasses
;
6859 fip
->baseclasses
= fieldp
->next
;
6862 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6863 switch (fieldp
->accessibility
)
6865 case DW_ACCESS_private
:
6866 if (cu
->language
!= language_ada
)
6867 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6870 case DW_ACCESS_protected
:
6871 if (cu
->language
!= language_ada
)
6872 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6875 case DW_ACCESS_public
:
6879 /* Unknown accessibility. Complain and treat it as public. */
6881 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6882 fieldp
->accessibility
);
6886 if (nfields
< fip
->nbaseclasses
)
6888 switch (fieldp
->virtuality
)
6890 case DW_VIRTUALITY_virtual
:
6891 case DW_VIRTUALITY_pure_virtual
:
6892 if (cu
->language
== language_ada
)
6893 error (_("unexpected virtuality in component of Ada type"));
6894 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6901 /* Add a member function to the proper fieldlist. */
6904 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6905 struct type
*type
, struct dwarf2_cu
*cu
)
6907 struct objfile
*objfile
= cu
->objfile
;
6908 struct attribute
*attr
;
6909 struct fnfieldlist
*flp
;
6911 struct fn_field
*fnp
;
6913 struct nextfnfield
*new_fnfield
;
6914 struct type
*this_type
;
6915 enum dwarf_access_attribute accessibility
;
6917 if (cu
->language
== language_ada
)
6918 error (_("unexpected member function in Ada type"));
6920 /* Get name of member function. */
6921 fieldname
= dwarf2_name (die
, cu
);
6922 if (fieldname
== NULL
)
6925 /* Look up member function name in fieldlist. */
6926 for (i
= 0; i
< fip
->nfnfields
; i
++)
6928 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6932 /* Create new list element if necessary. */
6933 if (i
< fip
->nfnfields
)
6934 flp
= &fip
->fnfieldlists
[i
];
6937 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6939 fip
->fnfieldlists
= (struct fnfieldlist
*)
6940 xrealloc (fip
->fnfieldlists
,
6941 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6942 * sizeof (struct fnfieldlist
));
6943 if (fip
->nfnfields
== 0)
6944 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6946 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6947 flp
->name
= fieldname
;
6950 i
= fip
->nfnfields
++;
6953 /* Create a new member function field and chain it to the field list
6955 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6956 make_cleanup (xfree
, new_fnfield
);
6957 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6958 new_fnfield
->next
= flp
->head
;
6959 flp
->head
= new_fnfield
;
6962 /* Fill in the member function field info. */
6963 fnp
= &new_fnfield
->fnfield
;
6965 /* Delay processing of the physname until later. */
6966 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
6968 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
6973 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
6974 fnp
->physname
= physname
? physname
: "";
6977 fnp
->type
= alloc_type (objfile
);
6978 this_type
= read_type_die (die
, cu
);
6979 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6981 int nparams
= TYPE_NFIELDS (this_type
);
6983 /* TYPE is the domain of this method, and THIS_TYPE is the type
6984 of the method itself (TYPE_CODE_METHOD). */
6985 smash_to_method_type (fnp
->type
, type
,
6986 TYPE_TARGET_TYPE (this_type
),
6987 TYPE_FIELDS (this_type
),
6988 TYPE_NFIELDS (this_type
),
6989 TYPE_VARARGS (this_type
));
6991 /* Handle static member functions.
6992 Dwarf2 has no clean way to discern C++ static and non-static
6993 member functions. G++ helps GDB by marking the first
6994 parameter for non-static member functions (which is the this
6995 pointer) as artificial. We obtain this information from
6996 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6997 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6998 fnp
->voffset
= VOFFSET_STATIC
;
7001 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7002 dwarf2_full_name (fieldname
, die
, cu
));
7004 /* Get fcontext from DW_AT_containing_type if present. */
7005 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7006 fnp
->fcontext
= die_containing_type (die
, cu
);
7008 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7009 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7011 /* Get accessibility. */
7012 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7014 accessibility
= DW_UNSND (attr
);
7016 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7017 switch (accessibility
)
7019 case DW_ACCESS_private
:
7020 fnp
->is_private
= 1;
7022 case DW_ACCESS_protected
:
7023 fnp
->is_protected
= 1;
7027 /* Check for artificial methods. */
7028 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7029 if (attr
&& DW_UNSND (attr
) != 0)
7030 fnp
->is_artificial
= 1;
7032 /* Get index in virtual function table if it is a virtual member
7033 function. For older versions of GCC, this is an offset in the
7034 appropriate virtual table, as specified by DW_AT_containing_type.
7035 For everyone else, it is an expression to be evaluated relative
7036 to the object address. */
7038 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7041 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7043 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7045 /* Old-style GCC. */
7046 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7048 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7049 || (DW_BLOCK (attr
)->size
> 1
7050 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7051 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7053 struct dwarf_block blk
;
7056 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7058 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7059 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7060 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7061 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7062 dwarf2_complex_location_expr_complaint ();
7064 fnp
->voffset
/= cu
->header
.addr_size
;
7068 dwarf2_complex_location_expr_complaint ();
7071 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7073 else if (attr_form_is_section_offset (attr
))
7075 dwarf2_complex_location_expr_complaint ();
7079 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7085 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7086 if (attr
&& DW_UNSND (attr
))
7088 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7089 complaint (&symfile_complaints
,
7090 _("Member function \"%s\" (offset %d) is virtual "
7091 "but the vtable offset is not specified"),
7092 fieldname
, die
->offset
);
7093 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7094 TYPE_CPLUS_DYNAMIC (type
) = 1;
7099 /* Create the vector of member function fields, and attach it to the type. */
7102 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7103 struct dwarf2_cu
*cu
)
7105 struct fnfieldlist
*flp
;
7106 int total_length
= 0;
7109 if (cu
->language
== language_ada
)
7110 error (_("unexpected member functions in Ada type"));
7112 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7113 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7114 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7116 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7118 struct nextfnfield
*nfp
= flp
->head
;
7119 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7122 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7123 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7124 fn_flp
->fn_fields
= (struct fn_field
*)
7125 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7126 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7127 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7129 total_length
+= flp
->length
;
7132 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7133 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
7136 /* Returns non-zero if NAME is the name of a vtable member in CU's
7137 language, zero otherwise. */
7139 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7141 static const char vptr
[] = "_vptr";
7142 static const char vtable
[] = "vtable";
7144 /* Look for the C++ and Java forms of the vtable. */
7145 if ((cu
->language
== language_java
7146 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7147 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7148 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7154 /* GCC outputs unnamed structures that are really pointers to member
7155 functions, with the ABI-specified layout. If TYPE describes
7156 such a structure, smash it into a member function type.
7158 GCC shouldn't do this; it should just output pointer to member DIEs.
7159 This is GCC PR debug/28767. */
7162 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7164 struct type
*pfn_type
, *domain_type
, *new_type
;
7166 /* Check for a structure with no name and two children. */
7167 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7170 /* Check for __pfn and __delta members. */
7171 if (TYPE_FIELD_NAME (type
, 0) == NULL
7172 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7173 || TYPE_FIELD_NAME (type
, 1) == NULL
7174 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7177 /* Find the type of the method. */
7178 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7179 if (pfn_type
== NULL
7180 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7181 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7184 /* Look for the "this" argument. */
7185 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7186 if (TYPE_NFIELDS (pfn_type
) == 0
7187 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7188 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7191 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7192 new_type
= alloc_type (objfile
);
7193 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7194 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7195 TYPE_VARARGS (pfn_type
));
7196 smash_to_methodptr_type (type
, new_type
);
7199 /* Called when we find the DIE that starts a structure or union scope
7200 (definition) to create a type for the structure or union. Fill in
7201 the type's name and general properties; the members will not be
7202 processed until process_structure_type.
7204 NOTE: we need to call these functions regardless of whether or not the
7205 DIE has a DW_AT_name attribute, since it might be an anonymous
7206 structure or union. This gets the type entered into our set of
7209 However, if the structure is incomplete (an opaque struct/union)
7210 then suppress creating a symbol table entry for it since gdb only
7211 wants to find the one with the complete definition. Note that if
7212 it is complete, we just call new_symbol, which does it's own
7213 checking about whether the struct/union is anonymous or not (and
7214 suppresses creating a symbol table entry itself). */
7216 static struct type
*
7217 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7219 struct objfile
*objfile
= cu
->objfile
;
7221 struct attribute
*attr
;
7224 /* If the definition of this type lives in .debug_types, read that type.
7225 Don't follow DW_AT_specification though, that will take us back up
7226 the chain and we want to go down. */
7227 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7230 struct dwarf2_cu
*type_cu
= cu
;
7231 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7233 /* We could just recurse on read_structure_type, but we need to call
7234 get_die_type to ensure only one type for this DIE is created.
7235 This is important, for example, because for c++ classes we need
7236 TYPE_NAME set which is only done by new_symbol. Blech. */
7237 type
= read_type_die (type_die
, type_cu
);
7239 /* TYPE_CU may not be the same as CU.
7240 Ensure TYPE is recorded in CU's type_hash table. */
7241 return set_die_type (die
, type
, cu
);
7244 type
= alloc_type (objfile
);
7245 INIT_CPLUS_SPECIFIC (type
);
7247 name
= dwarf2_name (die
, cu
);
7250 if (cu
->language
== language_cplus
7251 || cu
->language
== language_java
)
7253 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7255 /* dwarf2_full_name might have already finished building the DIE's
7256 type. If so, there is no need to continue. */
7257 if (get_die_type (die
, cu
) != NULL
)
7258 return get_die_type (die
, cu
);
7260 TYPE_TAG_NAME (type
) = full_name
;
7261 if (die
->tag
== DW_TAG_structure_type
7262 || die
->tag
== DW_TAG_class_type
)
7263 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7267 /* The name is already allocated along with this objfile, so
7268 we don't need to duplicate it for the type. */
7269 TYPE_TAG_NAME (type
) = (char *) name
;
7270 if (die
->tag
== DW_TAG_class_type
)
7271 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7275 if (die
->tag
== DW_TAG_structure_type
)
7277 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7279 else if (die
->tag
== DW_TAG_union_type
)
7281 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7285 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7288 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7289 TYPE_DECLARED_CLASS (type
) = 1;
7291 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7294 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7298 TYPE_LENGTH (type
) = 0;
7301 TYPE_STUB_SUPPORTED (type
) = 1;
7302 if (die_is_declaration (die
, cu
))
7303 TYPE_STUB (type
) = 1;
7304 else if (attr
== NULL
&& die
->child
== NULL
7305 && producer_is_realview (cu
->producer
))
7306 /* RealView does not output the required DW_AT_declaration
7307 on incomplete types. */
7308 TYPE_STUB (type
) = 1;
7310 /* We need to add the type field to the die immediately so we don't
7311 infinitely recurse when dealing with pointers to the structure
7312 type within the structure itself. */
7313 set_die_type (die
, type
, cu
);
7315 /* set_die_type should be already done. */
7316 set_descriptive_type (type
, die
, cu
);
7321 /* Finish creating a structure or union type, including filling in
7322 its members and creating a symbol for it. */
7325 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7327 struct objfile
*objfile
= cu
->objfile
;
7328 struct die_info
*child_die
= die
->child
;
7331 type
= get_die_type (die
, cu
);
7333 type
= read_structure_type (die
, cu
);
7335 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7337 struct field_info fi
;
7338 struct die_info
*child_die
;
7339 VEC (symbolp
) *template_args
= NULL
;
7340 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7342 memset (&fi
, 0, sizeof (struct field_info
));
7344 child_die
= die
->child
;
7346 while (child_die
&& child_die
->tag
)
7348 if (child_die
->tag
== DW_TAG_member
7349 || child_die
->tag
== DW_TAG_variable
)
7351 /* NOTE: carlton/2002-11-05: A C++ static data member
7352 should be a DW_TAG_member that is a declaration, but
7353 all versions of G++ as of this writing (so through at
7354 least 3.2.1) incorrectly generate DW_TAG_variable
7355 tags for them instead. */
7356 dwarf2_add_field (&fi
, child_die
, cu
);
7358 else if (child_die
->tag
== DW_TAG_subprogram
)
7360 /* C++ member function. */
7361 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7363 else if (child_die
->tag
== DW_TAG_inheritance
)
7365 /* C++ base class field. */
7366 dwarf2_add_field (&fi
, child_die
, cu
);
7368 else if (child_die
->tag
== DW_TAG_typedef
)
7369 dwarf2_add_typedef (&fi
, child_die
, cu
);
7370 else if (child_die
->tag
== DW_TAG_template_type_param
7371 || child_die
->tag
== DW_TAG_template_value_param
)
7373 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7376 VEC_safe_push (symbolp
, template_args
, arg
);
7379 child_die
= sibling_die (child_die
);
7382 /* Attach template arguments to type. */
7383 if (! VEC_empty (symbolp
, template_args
))
7385 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7386 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7387 = VEC_length (symbolp
, template_args
);
7388 TYPE_TEMPLATE_ARGUMENTS (type
)
7389 = obstack_alloc (&objfile
->objfile_obstack
,
7390 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7391 * sizeof (struct symbol
*)));
7392 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7393 VEC_address (symbolp
, template_args
),
7394 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7395 * sizeof (struct symbol
*)));
7396 VEC_free (symbolp
, template_args
);
7399 /* Attach fields and member functions to the type. */
7401 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7404 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7406 /* Get the type which refers to the base class (possibly this
7407 class itself) which contains the vtable pointer for the current
7408 class from the DW_AT_containing_type attribute. This use of
7409 DW_AT_containing_type is a GNU extension. */
7411 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7413 struct type
*t
= die_containing_type (die
, cu
);
7415 TYPE_VPTR_BASETYPE (type
) = t
;
7420 /* Our own class provides vtbl ptr. */
7421 for (i
= TYPE_NFIELDS (t
) - 1;
7422 i
>= TYPE_N_BASECLASSES (t
);
7425 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7427 if (is_vtable_name (fieldname
, cu
))
7429 TYPE_VPTR_FIELDNO (type
) = i
;
7434 /* Complain if virtual function table field not found. */
7435 if (i
< TYPE_N_BASECLASSES (t
))
7436 complaint (&symfile_complaints
,
7437 _("virtual function table pointer "
7438 "not found when defining class '%s'"),
7439 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7444 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7447 else if (cu
->producer
7448 && strncmp (cu
->producer
,
7449 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7451 /* The IBM XLC compiler does not provide direct indication
7452 of the containing type, but the vtable pointer is
7453 always named __vfp. */
7457 for (i
= TYPE_NFIELDS (type
) - 1;
7458 i
>= TYPE_N_BASECLASSES (type
);
7461 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7463 TYPE_VPTR_FIELDNO (type
) = i
;
7464 TYPE_VPTR_BASETYPE (type
) = type
;
7471 /* Copy fi.typedef_field_list linked list elements content into the
7472 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7473 if (fi
.typedef_field_list
)
7475 int i
= fi
.typedef_field_list_count
;
7477 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7478 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7479 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7480 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7482 /* Reverse the list order to keep the debug info elements order. */
7485 struct typedef_field
*dest
, *src
;
7487 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7488 src
= &fi
.typedef_field_list
->field
;
7489 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7494 do_cleanups (back_to
);
7496 if (HAVE_CPLUS_STRUCT (type
))
7497 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
7500 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
7502 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7503 snapshots) has been known to create a die giving a declaration
7504 for a class that has, as a child, a die giving a definition for a
7505 nested class. So we have to process our children even if the
7506 current die is a declaration. Normally, of course, a declaration
7507 won't have any children at all. */
7509 while (child_die
!= NULL
&& child_die
->tag
)
7511 if (child_die
->tag
== DW_TAG_member
7512 || child_die
->tag
== DW_TAG_variable
7513 || child_die
->tag
== DW_TAG_inheritance
7514 || child_die
->tag
== DW_TAG_template_value_param
7515 || child_die
->tag
== DW_TAG_template_type_param
)
7520 process_die (child_die
, cu
);
7522 child_die
= sibling_die (child_die
);
7525 /* Do not consider external references. According to the DWARF standard,
7526 these DIEs are identified by the fact that they have no byte_size
7527 attribute, and a declaration attribute. */
7528 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7529 || !die_is_declaration (die
, cu
))
7530 new_symbol (die
, type
, cu
);
7533 /* Given a DW_AT_enumeration_type die, set its type. We do not
7534 complete the type's fields yet, or create any symbols. */
7536 static struct type
*
7537 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7539 struct objfile
*objfile
= cu
->objfile
;
7541 struct attribute
*attr
;
7544 /* If the definition of this type lives in .debug_types, read that type.
7545 Don't follow DW_AT_specification though, that will take us back up
7546 the chain and we want to go down. */
7547 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7550 struct dwarf2_cu
*type_cu
= cu
;
7551 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7553 type
= read_type_die (type_die
, type_cu
);
7555 /* TYPE_CU may not be the same as CU.
7556 Ensure TYPE is recorded in CU's type_hash table. */
7557 return set_die_type (die
, type
, cu
);
7560 type
= alloc_type (objfile
);
7562 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7563 name
= dwarf2_full_name (NULL
, die
, cu
);
7565 TYPE_TAG_NAME (type
) = (char *) name
;
7567 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7570 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7574 TYPE_LENGTH (type
) = 0;
7577 /* The enumeration DIE can be incomplete. In Ada, any type can be
7578 declared as private in the package spec, and then defined only
7579 inside the package body. Such types are known as Taft Amendment
7580 Types. When another package uses such a type, an incomplete DIE
7581 may be generated by the compiler. */
7582 if (die_is_declaration (die
, cu
))
7583 TYPE_STUB (type
) = 1;
7585 return set_die_type (die
, type
, cu
);
7588 /* Given a pointer to a die which begins an enumeration, process all
7589 the dies that define the members of the enumeration, and create the
7590 symbol for the enumeration type.
7592 NOTE: We reverse the order of the element list. */
7595 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7597 struct type
*this_type
;
7599 this_type
= get_die_type (die
, cu
);
7600 if (this_type
== NULL
)
7601 this_type
= read_enumeration_type (die
, cu
);
7603 if (die
->child
!= NULL
)
7605 struct die_info
*child_die
;
7607 struct field
*fields
= NULL
;
7609 int unsigned_enum
= 1;
7612 child_die
= die
->child
;
7613 while (child_die
&& child_die
->tag
)
7615 if (child_die
->tag
!= DW_TAG_enumerator
)
7617 process_die (child_die
, cu
);
7621 name
= dwarf2_name (child_die
, cu
);
7624 sym
= new_symbol (child_die
, this_type
, cu
);
7625 if (SYMBOL_VALUE (sym
) < 0)
7628 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7630 fields
= (struct field
*)
7632 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7633 * sizeof (struct field
));
7636 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7637 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7638 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7639 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7645 child_die
= sibling_die (child_die
);
7650 TYPE_NFIELDS (this_type
) = num_fields
;
7651 TYPE_FIELDS (this_type
) = (struct field
*)
7652 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7653 memcpy (TYPE_FIELDS (this_type
), fields
,
7654 sizeof (struct field
) * num_fields
);
7658 TYPE_UNSIGNED (this_type
) = 1;
7661 new_symbol (die
, this_type
, cu
);
7664 /* Extract all information from a DW_TAG_array_type DIE and put it in
7665 the DIE's type field. For now, this only handles one dimensional
7668 static struct type
*
7669 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7671 struct objfile
*objfile
= cu
->objfile
;
7672 struct die_info
*child_die
;
7674 struct type
*element_type
, *range_type
, *index_type
;
7675 struct type
**range_types
= NULL
;
7676 struct attribute
*attr
;
7678 struct cleanup
*back_to
;
7681 element_type
= die_type (die
, cu
);
7683 /* The die_type call above may have already set the type for this DIE. */
7684 type
= get_die_type (die
, cu
);
7688 /* Irix 6.2 native cc creates array types without children for
7689 arrays with unspecified length. */
7690 if (die
->child
== NULL
)
7692 index_type
= objfile_type (objfile
)->builtin_int
;
7693 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7694 type
= create_array_type (NULL
, element_type
, range_type
);
7695 return set_die_type (die
, type
, cu
);
7698 back_to
= make_cleanup (null_cleanup
, NULL
);
7699 child_die
= die
->child
;
7700 while (child_die
&& child_die
->tag
)
7702 if (child_die
->tag
== DW_TAG_subrange_type
)
7704 struct type
*child_type
= read_type_die (child_die
, cu
);
7706 if (child_type
!= NULL
)
7708 /* The range type was succesfully read. Save it for the
7709 array type creation. */
7710 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7712 range_types
= (struct type
**)
7713 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7714 * sizeof (struct type
*));
7716 make_cleanup (free_current_contents
, &range_types
);
7718 range_types
[ndim
++] = child_type
;
7721 child_die
= sibling_die (child_die
);
7724 /* Dwarf2 dimensions are output from left to right, create the
7725 necessary array types in backwards order. */
7727 type
= element_type
;
7729 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7734 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7739 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7742 /* Understand Dwarf2 support for vector types (like they occur on
7743 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7744 array type. This is not part of the Dwarf2/3 standard yet, but a
7745 custom vendor extension. The main difference between a regular
7746 array and the vector variant is that vectors are passed by value
7748 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7750 make_vector_type (type
);
7752 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7753 implementation may choose to implement triple vectors using this
7755 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7758 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
7759 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7761 complaint (&symfile_complaints
,
7762 _("DW_AT_byte_size for array type smaller "
7763 "than the total size of elements"));
7766 name
= dwarf2_name (die
, cu
);
7768 TYPE_NAME (type
) = name
;
7770 /* Install the type in the die. */
7771 set_die_type (die
, type
, cu
);
7773 /* set_die_type should be already done. */
7774 set_descriptive_type (type
, die
, cu
);
7776 do_cleanups (back_to
);
7781 static enum dwarf_array_dim_ordering
7782 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7784 struct attribute
*attr
;
7786 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7788 if (attr
) return DW_SND (attr
);
7790 /* GNU F77 is a special case, as at 08/2004 array type info is the
7791 opposite order to the dwarf2 specification, but data is still
7792 laid out as per normal fortran.
7794 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7795 version checking. */
7797 if (cu
->language
== language_fortran
7798 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7800 return DW_ORD_row_major
;
7803 switch (cu
->language_defn
->la_array_ordering
)
7805 case array_column_major
:
7806 return DW_ORD_col_major
;
7807 case array_row_major
:
7809 return DW_ORD_row_major
;
7813 /* Extract all information from a DW_TAG_set_type DIE and put it in
7814 the DIE's type field. */
7816 static struct type
*
7817 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7819 struct type
*domain_type
, *set_type
;
7820 struct attribute
*attr
;
7822 domain_type
= die_type (die
, cu
);
7824 /* The die_type call above may have already set the type for this DIE. */
7825 set_type
= get_die_type (die
, cu
);
7829 set_type
= create_set_type (NULL
, domain_type
);
7831 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7833 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7835 return set_die_type (die
, set_type
, cu
);
7838 /* First cut: install each common block member as a global variable. */
7841 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7843 struct die_info
*child_die
;
7844 struct attribute
*attr
;
7846 CORE_ADDR base
= (CORE_ADDR
) 0;
7848 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7851 /* Support the .debug_loc offsets. */
7852 if (attr_form_is_block (attr
))
7854 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7856 else if (attr_form_is_section_offset (attr
))
7858 dwarf2_complex_location_expr_complaint ();
7862 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7863 "common block member");
7866 if (die
->child
!= NULL
)
7868 child_die
= die
->child
;
7869 while (child_die
&& child_die
->tag
)
7873 sym
= new_symbol (child_die
, NULL
, cu
);
7875 && handle_data_member_location (child_die
, cu
, &offset
))
7877 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
7878 add_symbol_to_list (sym
, &global_symbols
);
7880 child_die
= sibling_die (child_die
);
7885 /* Create a type for a C++ namespace. */
7887 static struct type
*
7888 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7890 struct objfile
*objfile
= cu
->objfile
;
7891 const char *previous_prefix
, *name
;
7895 /* For extensions, reuse the type of the original namespace. */
7896 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7898 struct die_info
*ext_die
;
7899 struct dwarf2_cu
*ext_cu
= cu
;
7901 ext_die
= dwarf2_extension (die
, &ext_cu
);
7902 type
= read_type_die (ext_die
, ext_cu
);
7904 /* EXT_CU may not be the same as CU.
7905 Ensure TYPE is recorded in CU's type_hash table. */
7906 return set_die_type (die
, type
, cu
);
7909 name
= namespace_name (die
, &is_anonymous
, cu
);
7911 /* Now build the name of the current namespace. */
7913 previous_prefix
= determine_prefix (die
, cu
);
7914 if (previous_prefix
[0] != '\0')
7915 name
= typename_concat (&objfile
->objfile_obstack
,
7916 previous_prefix
, name
, 0, cu
);
7918 /* Create the type. */
7919 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7921 TYPE_NAME (type
) = (char *) name
;
7922 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7924 return set_die_type (die
, type
, cu
);
7927 /* Read a C++ namespace. */
7930 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7932 struct objfile
*objfile
= cu
->objfile
;
7935 /* Add a symbol associated to this if we haven't seen the namespace
7936 before. Also, add a using directive if it's an anonymous
7939 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7943 type
= read_type_die (die
, cu
);
7944 new_symbol (die
, type
, cu
);
7946 namespace_name (die
, &is_anonymous
, cu
);
7949 const char *previous_prefix
= determine_prefix (die
, cu
);
7951 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7952 NULL
, NULL
, &objfile
->objfile_obstack
);
7956 if (die
->child
!= NULL
)
7958 struct die_info
*child_die
= die
->child
;
7960 while (child_die
&& child_die
->tag
)
7962 process_die (child_die
, cu
);
7963 child_die
= sibling_die (child_die
);
7968 /* Read a Fortran module as type. This DIE can be only a declaration used for
7969 imported module. Still we need that type as local Fortran "use ... only"
7970 declaration imports depend on the created type in determine_prefix. */
7972 static struct type
*
7973 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7975 struct objfile
*objfile
= cu
->objfile
;
7979 module_name
= dwarf2_name (die
, cu
);
7981 complaint (&symfile_complaints
,
7982 _("DW_TAG_module has no name, offset 0x%x"),
7984 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7986 /* determine_prefix uses TYPE_TAG_NAME. */
7987 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7989 return set_die_type (die
, type
, cu
);
7992 /* Read a Fortran module. */
7995 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7997 struct die_info
*child_die
= die
->child
;
7999 while (child_die
&& child_die
->tag
)
8001 process_die (child_die
, cu
);
8002 child_die
= sibling_die (child_die
);
8006 /* Return the name of the namespace represented by DIE. Set
8007 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8011 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8013 struct die_info
*current_die
;
8014 const char *name
= NULL
;
8016 /* Loop through the extensions until we find a name. */
8018 for (current_die
= die
;
8019 current_die
!= NULL
;
8020 current_die
= dwarf2_extension (die
, &cu
))
8022 name
= dwarf2_name (current_die
, cu
);
8027 /* Is it an anonymous namespace? */
8029 *is_anonymous
= (name
== NULL
);
8031 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8036 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8037 the user defined type vector. */
8039 static struct type
*
8040 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8042 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8043 struct comp_unit_head
*cu_header
= &cu
->header
;
8045 struct attribute
*attr_byte_size
;
8046 struct attribute
*attr_address_class
;
8047 int byte_size
, addr_class
;
8048 struct type
*target_type
;
8050 target_type
= die_type (die
, cu
);
8052 /* The die_type call above may have already set the type for this DIE. */
8053 type
= get_die_type (die
, cu
);
8057 type
= lookup_pointer_type (target_type
);
8059 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8061 byte_size
= DW_UNSND (attr_byte_size
);
8063 byte_size
= cu_header
->addr_size
;
8065 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8066 if (attr_address_class
)
8067 addr_class
= DW_UNSND (attr_address_class
);
8069 addr_class
= DW_ADDR_none
;
8071 /* If the pointer size or address class is different than the
8072 default, create a type variant marked as such and set the
8073 length accordingly. */
8074 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8076 if (gdbarch_address_class_type_flags_p (gdbarch
))
8080 type_flags
= gdbarch_address_class_type_flags
8081 (gdbarch
, byte_size
, addr_class
);
8082 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8084 type
= make_type_with_address_space (type
, type_flags
);
8086 else if (TYPE_LENGTH (type
) != byte_size
)
8088 complaint (&symfile_complaints
,
8089 _("invalid pointer size %d"), byte_size
);
8093 /* Should we also complain about unhandled address classes? */
8097 TYPE_LENGTH (type
) = byte_size
;
8098 return set_die_type (die
, type
, cu
);
8101 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8102 the user defined type vector. */
8104 static struct type
*
8105 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8108 struct type
*to_type
;
8109 struct type
*domain
;
8111 to_type
= die_type (die
, cu
);
8112 domain
= die_containing_type (die
, cu
);
8114 /* The calls above may have already set the type for this DIE. */
8115 type
= get_die_type (die
, cu
);
8119 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8120 type
= lookup_methodptr_type (to_type
);
8122 type
= lookup_memberptr_type (to_type
, domain
);
8124 return set_die_type (die
, type
, cu
);
8127 /* Extract all information from a DW_TAG_reference_type DIE and add to
8128 the user defined type vector. */
8130 static struct type
*
8131 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8133 struct comp_unit_head
*cu_header
= &cu
->header
;
8134 struct type
*type
, *target_type
;
8135 struct attribute
*attr
;
8137 target_type
= die_type (die
, cu
);
8139 /* The die_type call above may have already set the type for this DIE. */
8140 type
= get_die_type (die
, cu
);
8144 type
= lookup_reference_type (target_type
);
8145 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8148 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8152 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8154 return set_die_type (die
, type
, cu
);
8157 static struct type
*
8158 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8160 struct type
*base_type
, *cv_type
;
8162 base_type
= die_type (die
, cu
);
8164 /* The die_type call above may have already set the type for this DIE. */
8165 cv_type
= get_die_type (die
, cu
);
8169 /* In case the const qualifier is applied to an array type, the element type
8170 is so qualified, not the array type (section 6.7.3 of C99). */
8171 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8173 struct type
*el_type
, *inner_array
;
8175 base_type
= copy_type (base_type
);
8176 inner_array
= base_type
;
8178 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8180 TYPE_TARGET_TYPE (inner_array
) =
8181 copy_type (TYPE_TARGET_TYPE (inner_array
));
8182 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8185 el_type
= TYPE_TARGET_TYPE (inner_array
);
8186 TYPE_TARGET_TYPE (inner_array
) =
8187 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8189 return set_die_type (die
, base_type
, cu
);
8192 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8193 return set_die_type (die
, cv_type
, cu
);
8196 static struct type
*
8197 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8199 struct type
*base_type
, *cv_type
;
8201 base_type
= die_type (die
, cu
);
8203 /* The die_type call above may have already set the type for this DIE. */
8204 cv_type
= get_die_type (die
, cu
);
8208 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8209 return set_die_type (die
, cv_type
, cu
);
8212 /* Extract all information from a DW_TAG_string_type DIE and add to
8213 the user defined type vector. It isn't really a user defined type,
8214 but it behaves like one, with other DIE's using an AT_user_def_type
8215 attribute to reference it. */
8217 static struct type
*
8218 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8220 struct objfile
*objfile
= cu
->objfile
;
8221 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8222 struct type
*type
, *range_type
, *index_type
, *char_type
;
8223 struct attribute
*attr
;
8224 unsigned int length
;
8226 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8229 length
= DW_UNSND (attr
);
8233 /* Check for the DW_AT_byte_size attribute. */
8234 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8237 length
= DW_UNSND (attr
);
8245 index_type
= objfile_type (objfile
)->builtin_int
;
8246 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8247 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8248 type
= create_string_type (NULL
, char_type
, range_type
);
8250 return set_die_type (die
, type
, cu
);
8253 /* Handle DIES due to C code like:
8257 int (*funcp)(int a, long l);
8261 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8263 static struct type
*
8264 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8266 struct type
*type
; /* Type that this function returns. */
8267 struct type
*ftype
; /* Function that returns above type. */
8268 struct attribute
*attr
;
8270 type
= die_type (die
, cu
);
8272 /* The die_type call above may have already set the type for this DIE. */
8273 ftype
= get_die_type (die
, cu
);
8277 ftype
= lookup_function_type (type
);
8279 /* All functions in C++, Pascal and Java have prototypes. */
8280 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8281 if ((attr
&& (DW_UNSND (attr
) != 0))
8282 || cu
->language
== language_cplus
8283 || cu
->language
== language_java
8284 || cu
->language
== language_pascal
)
8285 TYPE_PROTOTYPED (ftype
) = 1;
8286 else if (producer_is_realview (cu
->producer
))
8287 /* RealView does not emit DW_AT_prototyped. We can not
8288 distinguish prototyped and unprototyped functions; default to
8289 prototyped, since that is more common in modern code (and
8290 RealView warns about unprototyped functions). */
8291 TYPE_PROTOTYPED (ftype
) = 1;
8293 /* Store the calling convention in the type if it's available in
8294 the subroutine die. Otherwise set the calling convention to
8295 the default value DW_CC_normal. */
8296 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8298 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8299 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8300 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8302 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8304 /* We need to add the subroutine type to the die immediately so
8305 we don't infinitely recurse when dealing with parameters
8306 declared as the same subroutine type. */
8307 set_die_type (die
, ftype
, cu
);
8309 if (die
->child
!= NULL
)
8311 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
8312 struct die_info
*child_die
;
8313 int nparams
, iparams
;
8315 /* Count the number of parameters.
8316 FIXME: GDB currently ignores vararg functions, but knows about
8317 vararg member functions. */
8319 child_die
= die
->child
;
8320 while (child_die
&& child_die
->tag
)
8322 if (child_die
->tag
== DW_TAG_formal_parameter
)
8324 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8325 TYPE_VARARGS (ftype
) = 1;
8326 child_die
= sibling_die (child_die
);
8329 /* Allocate storage for parameters and fill them in. */
8330 TYPE_NFIELDS (ftype
) = nparams
;
8331 TYPE_FIELDS (ftype
) = (struct field
*)
8332 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8334 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8335 even if we error out during the parameters reading below. */
8336 for (iparams
= 0; iparams
< nparams
; iparams
++)
8337 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8340 child_die
= die
->child
;
8341 while (child_die
&& child_die
->tag
)
8343 if (child_die
->tag
== DW_TAG_formal_parameter
)
8345 struct type
*arg_type
;
8347 /* DWARF version 2 has no clean way to discern C++
8348 static and non-static member functions. G++ helps
8349 GDB by marking the first parameter for non-static
8350 member functions (which is the this pointer) as
8351 artificial. We pass this information to
8352 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8354 DWARF version 3 added DW_AT_object_pointer, which GCC
8355 4.5 does not yet generate. */
8356 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8358 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8361 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8363 /* GCC/43521: In java, the formal parameter
8364 "this" is sometimes not marked with DW_AT_artificial. */
8365 if (cu
->language
== language_java
)
8367 const char *name
= dwarf2_name (child_die
, cu
);
8369 if (name
&& !strcmp (name
, "this"))
8370 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8373 arg_type
= die_type (child_die
, cu
);
8375 /* RealView does not mark THIS as const, which the testsuite
8376 expects. GCC marks THIS as const in method definitions,
8377 but not in the class specifications (GCC PR 43053). */
8378 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8379 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8382 struct dwarf2_cu
*arg_cu
= cu
;
8383 const char *name
= dwarf2_name (child_die
, cu
);
8385 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8388 /* If the compiler emits this, use it. */
8389 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8392 else if (name
&& strcmp (name
, "this") == 0)
8393 /* Function definitions will have the argument names. */
8395 else if (name
== NULL
&& iparams
== 0)
8396 /* Declarations may not have the names, so like
8397 elsewhere in GDB, assume an artificial first
8398 argument is "this". */
8402 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8406 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8409 child_die
= sibling_die (child_die
);
8416 static struct type
*
8417 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8419 struct objfile
*objfile
= cu
->objfile
;
8420 const char *name
= NULL
;
8421 struct type
*this_type
;
8423 name
= dwarf2_full_name (NULL
, die
, cu
);
8424 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8425 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8426 TYPE_NAME (this_type
) = (char *) name
;
8427 set_die_type (die
, this_type
, cu
);
8428 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
8432 /* Find a representation of a given base type and install
8433 it in the TYPE field of the die. */
8435 static struct type
*
8436 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8438 struct objfile
*objfile
= cu
->objfile
;
8440 struct attribute
*attr
;
8441 int encoding
= 0, size
= 0;
8443 enum type_code code
= TYPE_CODE_INT
;
8445 struct type
*target_type
= NULL
;
8447 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8450 encoding
= DW_UNSND (attr
);
8452 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8455 size
= DW_UNSND (attr
);
8457 name
= dwarf2_name (die
, cu
);
8460 complaint (&symfile_complaints
,
8461 _("DW_AT_name missing from DW_TAG_base_type"));
8466 case DW_ATE_address
:
8467 /* Turn DW_ATE_address into a void * pointer. */
8468 code
= TYPE_CODE_PTR
;
8469 type_flags
|= TYPE_FLAG_UNSIGNED
;
8470 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8472 case DW_ATE_boolean
:
8473 code
= TYPE_CODE_BOOL
;
8474 type_flags
|= TYPE_FLAG_UNSIGNED
;
8476 case DW_ATE_complex_float
:
8477 code
= TYPE_CODE_COMPLEX
;
8478 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8480 case DW_ATE_decimal_float
:
8481 code
= TYPE_CODE_DECFLOAT
;
8484 code
= TYPE_CODE_FLT
;
8488 case DW_ATE_unsigned
:
8489 type_flags
|= TYPE_FLAG_UNSIGNED
;
8490 if (cu
->language
== language_fortran
8492 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
8493 code
= TYPE_CODE_CHAR
;
8495 case DW_ATE_signed_char
:
8496 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8497 || cu
->language
== language_pascal
8498 || cu
->language
== language_fortran
)
8499 code
= TYPE_CODE_CHAR
;
8501 case DW_ATE_unsigned_char
:
8502 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8503 || cu
->language
== language_pascal
8504 || cu
->language
== language_fortran
)
8505 code
= TYPE_CODE_CHAR
;
8506 type_flags
|= TYPE_FLAG_UNSIGNED
;
8509 /* We just treat this as an integer and then recognize the
8510 type by name elsewhere. */
8514 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8515 dwarf_type_encoding_name (encoding
));
8519 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8520 TYPE_NAME (type
) = name
;
8521 TYPE_TARGET_TYPE (type
) = target_type
;
8523 if (name
&& strcmp (name
, "char") == 0)
8524 TYPE_NOSIGN (type
) = 1;
8526 return set_die_type (die
, type
, cu
);
8529 /* Read the given DW_AT_subrange DIE. */
8531 static struct type
*
8532 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8534 struct type
*base_type
;
8535 struct type
*range_type
;
8536 struct attribute
*attr
;
8540 LONGEST negative_mask
;
8542 base_type
= die_type (die
, cu
);
8543 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8544 check_typedef (base_type
);
8546 /* The die_type call above may have already set the type for this DIE. */
8547 range_type
= get_die_type (die
, cu
);
8551 if (cu
->language
== language_fortran
)
8553 /* FORTRAN implies a lower bound of 1, if not given. */
8557 /* FIXME: For variable sized arrays either of these could be
8558 a variable rather than a constant value. We'll allow it,
8559 but we don't know how to handle it. */
8560 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8562 low
= dwarf2_get_attr_constant_value (attr
, 0);
8564 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8567 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
8569 /* GCC encodes arrays with unspecified or dynamic length
8570 with a DW_FORM_block1 attribute or a reference attribute.
8571 FIXME: GDB does not yet know how to handle dynamic
8572 arrays properly, treat them as arrays with unspecified
8575 FIXME: jimb/2003-09-22: GDB does not really know
8576 how to handle arrays of unspecified length
8577 either; we just represent them as zero-length
8578 arrays. Choose an appropriate upper bound given
8579 the lower bound we've computed above. */
8583 high
= dwarf2_get_attr_constant_value (attr
, 1);
8587 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8590 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8591 high
= low
+ count
- 1;
8595 /* Unspecified array length. */
8600 /* Dwarf-2 specifications explicitly allows to create subrange types
8601 without specifying a base type.
8602 In that case, the base type must be set to the type of
8603 the lower bound, upper bound or count, in that order, if any of these
8604 three attributes references an object that has a type.
8605 If no base type is found, the Dwarf-2 specifications say that
8606 a signed integer type of size equal to the size of an address should
8608 For the following C code: `extern char gdb_int [];'
8609 GCC produces an empty range DIE.
8610 FIXME: muller/2010-05-28: Possible references to object for low bound,
8611 high bound or count are not yet handled by this code. */
8612 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8614 struct objfile
*objfile
= cu
->objfile
;
8615 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8616 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8617 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8619 /* Test "int", "long int", and "long long int" objfile types,
8620 and select the first one having a size above or equal to the
8621 architecture address size. */
8622 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8623 base_type
= int_type
;
8626 int_type
= objfile_type (objfile
)->builtin_long
;
8627 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8628 base_type
= int_type
;
8631 int_type
= objfile_type (objfile
)->builtin_long_long
;
8632 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8633 base_type
= int_type
;
8639 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8640 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8641 low
|= negative_mask
;
8642 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8643 high
|= negative_mask
;
8645 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8647 /* Mark arrays with dynamic length at least as an array of unspecified
8648 length. GDB could check the boundary but before it gets implemented at
8649 least allow accessing the array elements. */
8650 if (attr
&& attr
->form
== DW_FORM_block1
)
8651 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8653 /* Ada expects an empty array on no boundary attributes. */
8654 if (attr
== NULL
&& cu
->language
!= language_ada
)
8655 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8657 name
= dwarf2_name (die
, cu
);
8659 TYPE_NAME (range_type
) = name
;
8661 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8663 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8665 set_die_type (die
, range_type
, cu
);
8667 /* set_die_type should be already done. */
8668 set_descriptive_type (range_type
, die
, cu
);
8673 static struct type
*
8674 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8678 /* For now, we only support the C meaning of an unspecified type: void. */
8680 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8681 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8683 return set_die_type (die
, type
, cu
);
8686 /* Trivial hash function for die_info: the hash value of a DIE
8687 is its offset in .debug_info for this objfile. */
8690 die_hash (const void *item
)
8692 const struct die_info
*die
= item
;
8697 /* Trivial comparison function for die_info structures: two DIEs
8698 are equal if they have the same offset. */
8701 die_eq (const void *item_lhs
, const void *item_rhs
)
8703 const struct die_info
*die_lhs
= item_lhs
;
8704 const struct die_info
*die_rhs
= item_rhs
;
8706 return die_lhs
->offset
== die_rhs
->offset
;
8709 /* Read a whole compilation unit into a linked list of dies. */
8711 static struct die_info
*
8712 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8714 struct die_reader_specs reader_specs
;
8715 int read_abbrevs
= 0;
8716 struct cleanup
*back_to
= NULL
;
8717 struct die_info
*die
;
8719 if (cu
->dwarf2_abbrevs
== NULL
)
8721 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8722 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8726 gdb_assert (cu
->die_hash
== NULL
);
8728 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8732 &cu
->comp_unit_obstack
,
8733 hashtab_obstack_allocate
,
8734 dummy_obstack_deallocate
);
8736 init_cu_die_reader (&reader_specs
, cu
);
8738 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8741 do_cleanups (back_to
);
8746 /* Main entry point for reading a DIE and all children.
8747 Read the DIE and dump it if requested. */
8749 static struct die_info
*
8750 read_die_and_children (const struct die_reader_specs
*reader
,
8752 gdb_byte
**new_info_ptr
,
8753 struct die_info
*parent
)
8755 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8756 new_info_ptr
, parent
);
8758 if (dwarf2_die_debug
)
8760 fprintf_unfiltered (gdb_stdlog
,
8761 "\nRead die from %s of %s:\n",
8762 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8764 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8766 : "unknown section",
8767 reader
->abfd
->filename
);
8768 dump_die (result
, dwarf2_die_debug
);
8774 /* Read a single die and all its descendents. Set the die's sibling
8775 field to NULL; set other fields in the die correctly, and set all
8776 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8777 location of the info_ptr after reading all of those dies. PARENT
8778 is the parent of the die in question. */
8780 static struct die_info
*
8781 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8783 gdb_byte
**new_info_ptr
,
8784 struct die_info
*parent
)
8786 struct die_info
*die
;
8790 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8793 *new_info_ptr
= cur_ptr
;
8796 store_in_ref_table (die
, reader
->cu
);
8799 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8803 *new_info_ptr
= cur_ptr
;
8806 die
->sibling
= NULL
;
8807 die
->parent
= parent
;
8811 /* Read a die, all of its descendents, and all of its siblings; set
8812 all of the fields of all of the dies correctly. Arguments are as
8813 in read_die_and_children. */
8815 static struct die_info
*
8816 read_die_and_siblings (const struct die_reader_specs
*reader
,
8818 gdb_byte
**new_info_ptr
,
8819 struct die_info
*parent
)
8821 struct die_info
*first_die
, *last_sibling
;
8825 first_die
= last_sibling
= NULL
;
8829 struct die_info
*die
8830 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8834 *new_info_ptr
= cur_ptr
;
8841 last_sibling
->sibling
= die
;
8847 /* Read the die from the .debug_info section buffer. Set DIEP to
8848 point to a newly allocated die with its information, except for its
8849 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8850 whether the die has children or not. */
8853 read_full_die (const struct die_reader_specs
*reader
,
8854 struct die_info
**diep
, gdb_byte
*info_ptr
,
8857 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8858 struct abbrev_info
*abbrev
;
8859 struct die_info
*die
;
8860 struct dwarf2_cu
*cu
= reader
->cu
;
8861 bfd
*abfd
= reader
->abfd
;
8863 offset
= info_ptr
- reader
->buffer
;
8864 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8865 info_ptr
+= bytes_read
;
8873 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8875 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8877 bfd_get_filename (abfd
));
8879 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8880 die
->offset
= offset
;
8881 die
->tag
= abbrev
->tag
;
8882 die
->abbrev
= abbrev_number
;
8884 die
->num_attrs
= abbrev
->num_attrs
;
8886 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8887 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8888 abfd
, info_ptr
, cu
);
8891 *has_children
= abbrev
->has_children
;
8895 /* In DWARF version 2, the description of the debugging information is
8896 stored in a separate .debug_abbrev section. Before we read any
8897 dies from a section we read in all abbreviations and install them
8898 in a hash table. This function also sets flags in CU describing
8899 the data found in the abbrev table. */
8902 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8904 struct comp_unit_head
*cu_header
= &cu
->header
;
8905 gdb_byte
*abbrev_ptr
;
8906 struct abbrev_info
*cur_abbrev
;
8907 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8908 unsigned int abbrev_form
, hash_number
;
8909 struct attr_abbrev
*cur_attrs
;
8910 unsigned int allocated_attrs
;
8912 /* Initialize dwarf2 abbrevs. */
8913 obstack_init (&cu
->abbrev_obstack
);
8914 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8916 * sizeof (struct abbrev_info
*)));
8917 memset (cu
->dwarf2_abbrevs
, 0,
8918 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8920 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8921 &dwarf2_per_objfile
->abbrev
);
8922 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8923 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8924 abbrev_ptr
+= bytes_read
;
8926 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8927 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8929 /* Loop until we reach an abbrev number of 0. */
8930 while (abbrev_number
)
8932 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8934 /* read in abbrev header */
8935 cur_abbrev
->number
= abbrev_number
;
8936 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8937 abbrev_ptr
+= bytes_read
;
8938 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8941 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8942 cu
->has_namespace_info
= 1;
8944 /* now read in declarations */
8945 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8946 abbrev_ptr
+= bytes_read
;
8947 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8948 abbrev_ptr
+= bytes_read
;
8951 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8953 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8955 = xrealloc (cur_attrs
, (allocated_attrs
8956 * sizeof (struct attr_abbrev
)));
8959 /* Record whether this compilation unit might have
8960 inter-compilation-unit references. If we don't know what form
8961 this attribute will have, then it might potentially be a
8962 DW_FORM_ref_addr, so we conservatively expect inter-CU
8965 if (abbrev_form
== DW_FORM_ref_addr
8966 || abbrev_form
== DW_FORM_indirect
)
8967 cu
->has_form_ref_addr
= 1;
8969 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8970 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8971 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8972 abbrev_ptr
+= bytes_read
;
8973 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8974 abbrev_ptr
+= bytes_read
;
8977 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8978 (cur_abbrev
->num_attrs
8979 * sizeof (struct attr_abbrev
)));
8980 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8981 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8983 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8984 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8985 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8987 /* Get next abbreviation.
8988 Under Irix6 the abbreviations for a compilation unit are not
8989 always properly terminated with an abbrev number of 0.
8990 Exit loop if we encounter an abbreviation which we have
8991 already read (which means we are about to read the abbreviations
8992 for the next compile unit) or if the end of the abbreviation
8993 table is reached. */
8994 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8995 >= dwarf2_per_objfile
->abbrev
.size
)
8997 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8998 abbrev_ptr
+= bytes_read
;
8999 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9006 /* Release the memory used by the abbrev table for a compilation unit. */
9009 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9011 struct dwarf2_cu
*cu
= ptr_to_cu
;
9013 obstack_free (&cu
->abbrev_obstack
, NULL
);
9014 cu
->dwarf2_abbrevs
= NULL
;
9017 /* Lookup an abbrev_info structure in the abbrev hash table. */
9019 static struct abbrev_info
*
9020 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9022 unsigned int hash_number
;
9023 struct abbrev_info
*abbrev
;
9025 hash_number
= number
% ABBREV_HASH_SIZE
;
9026 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9030 if (abbrev
->number
== number
)
9033 abbrev
= abbrev
->next
;
9038 /* Returns nonzero if TAG represents a type that we might generate a partial
9042 is_type_tag_for_partial (int tag
)
9047 /* Some types that would be reasonable to generate partial symbols for,
9048 that we don't at present. */
9049 case DW_TAG_array_type
:
9050 case DW_TAG_file_type
:
9051 case DW_TAG_ptr_to_member_type
:
9052 case DW_TAG_set_type
:
9053 case DW_TAG_string_type
:
9054 case DW_TAG_subroutine_type
:
9056 case DW_TAG_base_type
:
9057 case DW_TAG_class_type
:
9058 case DW_TAG_interface_type
:
9059 case DW_TAG_enumeration_type
:
9060 case DW_TAG_structure_type
:
9061 case DW_TAG_subrange_type
:
9062 case DW_TAG_typedef
:
9063 case DW_TAG_union_type
:
9070 /* Load all DIEs that are interesting for partial symbols into memory. */
9072 static struct partial_die_info
*
9073 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9074 int building_psymtab
, struct dwarf2_cu
*cu
)
9076 struct partial_die_info
*part_die
;
9077 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9078 struct abbrev_info
*abbrev
;
9079 unsigned int bytes_read
;
9080 unsigned int load_all
= 0;
9082 int nesting_level
= 1;
9087 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
9091 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9095 &cu
->comp_unit_obstack
,
9096 hashtab_obstack_allocate
,
9097 dummy_obstack_deallocate
);
9099 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9100 sizeof (struct partial_die_info
));
9104 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9106 /* A NULL abbrev means the end of a series of children. */
9109 if (--nesting_level
== 0)
9111 /* PART_DIE was probably the last thing allocated on the
9112 comp_unit_obstack, so we could call obstack_free
9113 here. We don't do that because the waste is small,
9114 and will be cleaned up when we're done with this
9115 compilation unit. This way, we're also more robust
9116 against other users of the comp_unit_obstack. */
9119 info_ptr
+= bytes_read
;
9120 last_die
= parent_die
;
9121 parent_die
= parent_die
->die_parent
;
9125 /* Check for template arguments. We never save these; if
9126 they're seen, we just mark the parent, and go on our way. */
9127 if (parent_die
!= NULL
9128 && cu
->language
== language_cplus
9129 && (abbrev
->tag
== DW_TAG_template_type_param
9130 || abbrev
->tag
== DW_TAG_template_value_param
))
9132 parent_die
->has_template_arguments
= 1;
9136 /* We don't need a partial DIE for the template argument. */
9137 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9143 /* We only recurse into subprograms looking for template arguments.
9144 Skip their other children. */
9146 && cu
->language
== language_cplus
9147 && parent_die
!= NULL
9148 && parent_die
->tag
== DW_TAG_subprogram
)
9150 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9154 /* Check whether this DIE is interesting enough to save. Normally
9155 we would not be interested in members here, but there may be
9156 later variables referencing them via DW_AT_specification (for
9159 && !is_type_tag_for_partial (abbrev
->tag
)
9160 && abbrev
->tag
!= DW_TAG_constant
9161 && abbrev
->tag
!= DW_TAG_enumerator
9162 && abbrev
->tag
!= DW_TAG_subprogram
9163 && abbrev
->tag
!= DW_TAG_lexical_block
9164 && abbrev
->tag
!= DW_TAG_variable
9165 && abbrev
->tag
!= DW_TAG_namespace
9166 && abbrev
->tag
!= DW_TAG_module
9167 && abbrev
->tag
!= DW_TAG_member
)
9169 /* Otherwise we skip to the next sibling, if any. */
9170 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9174 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9175 buffer
, info_ptr
, cu
);
9177 /* This two-pass algorithm for processing partial symbols has a
9178 high cost in cache pressure. Thus, handle some simple cases
9179 here which cover the majority of C partial symbols. DIEs
9180 which neither have specification tags in them, nor could have
9181 specification tags elsewhere pointing at them, can simply be
9182 processed and discarded.
9184 This segment is also optional; scan_partial_symbols and
9185 add_partial_symbol will handle these DIEs if we chain
9186 them in normally. When compilers which do not emit large
9187 quantities of duplicate debug information are more common,
9188 this code can probably be removed. */
9190 /* Any complete simple types at the top level (pretty much all
9191 of them, for a language without namespaces), can be processed
9193 if (parent_die
== NULL
9194 && part_die
->has_specification
== 0
9195 && part_die
->is_declaration
== 0
9196 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9197 || part_die
->tag
== DW_TAG_base_type
9198 || part_die
->tag
== DW_TAG_subrange_type
))
9200 if (building_psymtab
&& part_die
->name
!= NULL
)
9201 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9202 VAR_DOMAIN
, LOC_TYPEDEF
,
9203 &cu
->objfile
->static_psymbols
,
9204 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9205 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9209 /* The exception for DW_TAG_typedef with has_children above is
9210 a workaround of GCC PR debug/47510. In the case of this complaint
9211 type_name_no_tag_or_error will error on such types later.
9213 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9214 it could not find the child DIEs referenced later, this is checked
9215 above. In correct DWARF DW_TAG_typedef should have no children. */
9217 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9218 complaint (&symfile_complaints
,
9219 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9220 "- DIE at 0x%x [in module %s]"),
9221 part_die
->offset
, cu
->objfile
->name
);
9223 /* If we're at the second level, and we're an enumerator, and
9224 our parent has no specification (meaning possibly lives in a
9225 namespace elsewhere), then we can add the partial symbol now
9226 instead of queueing it. */
9227 if (part_die
->tag
== DW_TAG_enumerator
9228 && parent_die
!= NULL
9229 && parent_die
->die_parent
== NULL
9230 && parent_die
->tag
== DW_TAG_enumeration_type
9231 && parent_die
->has_specification
== 0)
9233 if (part_die
->name
== NULL
)
9234 complaint (&symfile_complaints
,
9235 _("malformed enumerator DIE ignored"));
9236 else if (building_psymtab
)
9237 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9238 VAR_DOMAIN
, LOC_CONST
,
9239 (cu
->language
== language_cplus
9240 || cu
->language
== language_java
)
9241 ? &cu
->objfile
->global_psymbols
9242 : &cu
->objfile
->static_psymbols
,
9243 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9245 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9249 /* We'll save this DIE so link it in. */
9250 part_die
->die_parent
= parent_die
;
9251 part_die
->die_sibling
= NULL
;
9252 part_die
->die_child
= NULL
;
9254 if (last_die
&& last_die
== parent_die
)
9255 last_die
->die_child
= part_die
;
9257 last_die
->die_sibling
= part_die
;
9259 last_die
= part_die
;
9261 if (first_die
== NULL
)
9262 first_die
= part_die
;
9264 /* Maybe add the DIE to the hash table. Not all DIEs that we
9265 find interesting need to be in the hash table, because we
9266 also have the parent/sibling/child chains; only those that we
9267 might refer to by offset later during partial symbol reading.
9269 For now this means things that might have be the target of a
9270 DW_AT_specification, DW_AT_abstract_origin, or
9271 DW_AT_extension. DW_AT_extension will refer only to
9272 namespaces; DW_AT_abstract_origin refers to functions (and
9273 many things under the function DIE, but we do not recurse
9274 into function DIEs during partial symbol reading) and
9275 possibly variables as well; DW_AT_specification refers to
9276 declarations. Declarations ought to have the DW_AT_declaration
9277 flag. It happens that GCC forgets to put it in sometimes, but
9278 only for functions, not for types.
9280 Adding more things than necessary to the hash table is harmless
9281 except for the performance cost. Adding too few will result in
9282 wasted time in find_partial_die, when we reread the compilation
9283 unit with load_all_dies set. */
9286 || abbrev
->tag
== DW_TAG_constant
9287 || abbrev
->tag
== DW_TAG_subprogram
9288 || abbrev
->tag
== DW_TAG_variable
9289 || abbrev
->tag
== DW_TAG_namespace
9290 || part_die
->is_declaration
)
9294 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9295 part_die
->offset
, INSERT
);
9299 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9300 sizeof (struct partial_die_info
));
9302 /* For some DIEs we want to follow their children (if any). For C
9303 we have no reason to follow the children of structures; for other
9304 languages we have to, so that we can get at method physnames
9305 to infer fully qualified class names, for DW_AT_specification,
9306 and for C++ template arguments. For C++, we also look one level
9307 inside functions to find template arguments (if the name of the
9308 function does not already contain the template arguments).
9310 For Ada, we need to scan the children of subprograms and lexical
9311 blocks as well because Ada allows the definition of nested
9312 entities that could be interesting for the debugger, such as
9313 nested subprograms for instance. */
9314 if (last_die
->has_children
9316 || last_die
->tag
== DW_TAG_namespace
9317 || last_die
->tag
== DW_TAG_module
9318 || last_die
->tag
== DW_TAG_enumeration_type
9319 || (cu
->language
== language_cplus
9320 && last_die
->tag
== DW_TAG_subprogram
9321 && (last_die
->name
== NULL
9322 || strchr (last_die
->name
, '<') == NULL
))
9323 || (cu
->language
!= language_c
9324 && (last_die
->tag
== DW_TAG_class_type
9325 || last_die
->tag
== DW_TAG_interface_type
9326 || last_die
->tag
== DW_TAG_structure_type
9327 || last_die
->tag
== DW_TAG_union_type
))
9328 || (cu
->language
== language_ada
9329 && (last_die
->tag
== DW_TAG_subprogram
9330 || last_die
->tag
== DW_TAG_lexical_block
))))
9333 parent_die
= last_die
;
9337 /* Otherwise we skip to the next sibling, if any. */
9338 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9340 /* Back to the top, do it again. */
9344 /* Read a minimal amount of information into the minimal die structure. */
9347 read_partial_die (struct partial_die_info
*part_die
,
9348 struct abbrev_info
*abbrev
,
9349 unsigned int abbrev_len
, bfd
*abfd
,
9350 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9351 struct dwarf2_cu
*cu
)
9354 struct attribute attr
;
9355 int has_low_pc_attr
= 0;
9356 int has_high_pc_attr
= 0;
9358 memset (part_die
, 0, sizeof (struct partial_die_info
));
9360 part_die
->offset
= info_ptr
- buffer
;
9362 info_ptr
+= abbrev_len
;
9367 part_die
->tag
= abbrev
->tag
;
9368 part_die
->has_children
= abbrev
->has_children
;
9370 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9372 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9374 /* Store the data if it is of an attribute we want to keep in a
9375 partial symbol table. */
9379 switch (part_die
->tag
)
9381 case DW_TAG_compile_unit
:
9382 case DW_TAG_type_unit
:
9383 /* Compilation units have a DW_AT_name that is a filename, not
9384 a source language identifier. */
9385 case DW_TAG_enumeration_type
:
9386 case DW_TAG_enumerator
:
9387 /* These tags always have simple identifiers already; no need
9388 to canonicalize them. */
9389 part_die
->name
= DW_STRING (&attr
);
9393 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9394 &cu
->objfile
->objfile_obstack
);
9398 case DW_AT_linkage_name
:
9399 case DW_AT_MIPS_linkage_name
:
9400 /* Note that both forms of linkage name might appear. We
9401 assume they will be the same, and we only store the last
9403 if (cu
->language
== language_ada
)
9404 part_die
->name
= DW_STRING (&attr
);
9405 part_die
->linkage_name
= DW_STRING (&attr
);
9408 has_low_pc_attr
= 1;
9409 part_die
->lowpc
= DW_ADDR (&attr
);
9412 has_high_pc_attr
= 1;
9413 part_die
->highpc
= DW_ADDR (&attr
);
9415 case DW_AT_location
:
9416 /* Support the .debug_loc offsets. */
9417 if (attr_form_is_block (&attr
))
9419 part_die
->locdesc
= DW_BLOCK (&attr
);
9421 else if (attr_form_is_section_offset (&attr
))
9423 dwarf2_complex_location_expr_complaint ();
9427 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9428 "partial symbol information");
9431 case DW_AT_external
:
9432 part_die
->is_external
= DW_UNSND (&attr
);
9434 case DW_AT_declaration
:
9435 part_die
->is_declaration
= DW_UNSND (&attr
);
9438 part_die
->has_type
= 1;
9440 case DW_AT_abstract_origin
:
9441 case DW_AT_specification
:
9442 case DW_AT_extension
:
9443 part_die
->has_specification
= 1;
9444 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9447 /* Ignore absolute siblings, they might point outside of
9448 the current compile unit. */
9449 if (attr
.form
== DW_FORM_ref_addr
)
9450 complaint (&symfile_complaints
,
9451 _("ignoring absolute DW_AT_sibling"));
9453 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9455 case DW_AT_byte_size
:
9456 part_die
->has_byte_size
= 1;
9458 case DW_AT_calling_convention
:
9459 /* DWARF doesn't provide a way to identify a program's source-level
9460 entry point. DW_AT_calling_convention attributes are only meant
9461 to describe functions' calling conventions.
9463 However, because it's a necessary piece of information in
9464 Fortran, and because DW_CC_program is the only piece of debugging
9465 information whose definition refers to a 'main program' at all,
9466 several compilers have begun marking Fortran main programs with
9467 DW_CC_program --- even when those functions use the standard
9468 calling conventions.
9470 So until DWARF specifies a way to provide this information and
9471 compilers pick up the new representation, we'll support this
9473 if (DW_UNSND (&attr
) == DW_CC_program
9474 && cu
->language
== language_fortran
)
9476 set_main_name (part_die
->name
);
9478 /* As this DIE has a static linkage the name would be difficult
9479 to look up later. */
9480 language_of_main
= language_fortran
;
9488 if (has_low_pc_attr
&& has_high_pc_attr
)
9490 /* When using the GNU linker, .gnu.linkonce. sections are used to
9491 eliminate duplicate copies of functions and vtables and such.
9492 The linker will arbitrarily choose one and discard the others.
9493 The AT_*_pc values for such functions refer to local labels in
9494 these sections. If the section from that file was discarded, the
9495 labels are not in the output, so the relocs get a value of 0.
9496 If this is a discarded function, mark the pc bounds as invalid,
9497 so that GDB will ignore it. */
9498 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9500 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9502 complaint (&symfile_complaints
,
9503 _("DW_AT_low_pc %s is zero "
9504 "for DIE at 0x%x [in module %s]"),
9505 paddress (gdbarch
, part_die
->lowpc
),
9506 part_die
->offset
, cu
->objfile
->name
);
9508 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9509 else if (part_die
->lowpc
>= part_die
->highpc
)
9511 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9513 complaint (&symfile_complaints
,
9514 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9515 "for DIE at 0x%x [in module %s]"),
9516 paddress (gdbarch
, part_die
->lowpc
),
9517 paddress (gdbarch
, part_die
->highpc
),
9518 part_die
->offset
, cu
->objfile
->name
);
9521 part_die
->has_pc_info
= 1;
9527 /* Find a cached partial DIE at OFFSET in CU. */
9529 static struct partial_die_info
*
9530 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9532 struct partial_die_info
*lookup_die
= NULL
;
9533 struct partial_die_info part_die
;
9535 part_die
.offset
= offset
;
9536 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9541 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9542 except in the case of .debug_types DIEs which do not reference
9543 outside their CU (they do however referencing other types via
9544 DW_FORM_ref_sig8). */
9546 static struct partial_die_info
*
9547 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9549 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9550 struct partial_die_info
*pd
= NULL
;
9552 if (cu
->per_cu
->from_debug_types
)
9554 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9560 if (offset_in_cu_p (&cu
->header
, offset
))
9562 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9567 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9569 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9570 load_partial_comp_unit (per_cu
, cu
->objfile
);
9572 per_cu
->cu
->last_used
= 0;
9573 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9575 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9577 struct cleanup
*back_to
;
9578 struct partial_die_info comp_unit_die
;
9579 struct abbrev_info
*abbrev
;
9580 unsigned int bytes_read
;
9583 per_cu
->load_all_dies
= 1;
9585 /* Re-read the DIEs. */
9586 back_to
= make_cleanup (null_cleanup
, 0);
9587 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9589 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
9590 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9592 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9593 + per_cu
->cu
->header
.offset
9594 + per_cu
->cu
->header
.first_die_offset
);
9595 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9596 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9597 per_cu
->cu
->objfile
->obfd
,
9598 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9600 if (comp_unit_die
.has_children
)
9601 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
9602 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9604 do_cleanups (back_to
);
9606 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9612 internal_error (__FILE__
, __LINE__
,
9613 _("could not find partial DIE 0x%x "
9614 "in cache [from module %s]\n"),
9615 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9619 /* See if we can figure out if the class lives in a namespace. We do
9620 this by looking for a member function; its demangled name will
9621 contain namespace info, if there is any. */
9624 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9625 struct dwarf2_cu
*cu
)
9627 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9628 what template types look like, because the demangler
9629 frequently doesn't give the same name as the debug info. We
9630 could fix this by only using the demangled name to get the
9631 prefix (but see comment in read_structure_type). */
9633 struct partial_die_info
*real_pdi
;
9634 struct partial_die_info
*child_pdi
;
9636 /* If this DIE (this DIE's specification, if any) has a parent, then
9637 we should not do this. We'll prepend the parent's fully qualified
9638 name when we create the partial symbol. */
9640 real_pdi
= struct_pdi
;
9641 while (real_pdi
->has_specification
)
9642 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9644 if (real_pdi
->die_parent
!= NULL
)
9647 for (child_pdi
= struct_pdi
->die_child
;
9649 child_pdi
= child_pdi
->die_sibling
)
9651 if (child_pdi
->tag
== DW_TAG_subprogram
9652 && child_pdi
->linkage_name
!= NULL
)
9654 char *actual_class_name
9655 = language_class_name_from_physname (cu
->language_defn
,
9656 child_pdi
->linkage_name
);
9657 if (actual_class_name
!= NULL
)
9660 = obsavestring (actual_class_name
,
9661 strlen (actual_class_name
),
9662 &cu
->objfile
->objfile_obstack
);
9663 xfree (actual_class_name
);
9670 /* Adjust PART_DIE before generating a symbol for it. This function
9671 may set the is_external flag or change the DIE's name. */
9674 fixup_partial_die (struct partial_die_info
*part_die
,
9675 struct dwarf2_cu
*cu
)
9677 /* Once we've fixed up a die, there's no point in doing so again.
9678 This also avoids a memory leak if we were to call
9679 guess_partial_die_structure_name multiple times. */
9680 if (part_die
->fixup_called
)
9683 /* If we found a reference attribute and the DIE has no name, try
9684 to find a name in the referred to DIE. */
9686 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9688 struct partial_die_info
*spec_die
;
9690 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9692 fixup_partial_die (spec_die
, cu
);
9696 part_die
->name
= spec_die
->name
;
9698 /* Copy DW_AT_external attribute if it is set. */
9699 if (spec_die
->is_external
)
9700 part_die
->is_external
= spec_die
->is_external
;
9704 /* Set default names for some unnamed DIEs. */
9706 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9707 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
9709 /* If there is no parent die to provide a namespace, and there are
9710 children, see if we can determine the namespace from their linkage
9712 NOTE: We need to do this even if cu->has_namespace_info != 0.
9713 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9714 if (cu
->language
== language_cplus
9715 && dwarf2_per_objfile
->types
.asection
!= NULL
9716 && part_die
->die_parent
== NULL
9717 && part_die
->has_children
9718 && (part_die
->tag
== DW_TAG_class_type
9719 || part_die
->tag
== DW_TAG_structure_type
9720 || part_die
->tag
== DW_TAG_union_type
))
9721 guess_partial_die_structure_name (part_die
, cu
);
9723 /* GCC might emit a nameless struct or union that has a linkage
9724 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
9725 if (part_die
->name
== NULL
9726 && (part_die
->tag
== DW_TAG_structure_type
9727 || part_die
->tag
== DW_TAG_union_type
9728 || part_die
->tag
== DW_TAG_class_type
)
9729 && part_die
->linkage_name
!= NULL
)
9733 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
9736 part_die
->name
= obsavestring (demangled
, strlen (demangled
),
9737 &cu
->objfile
->objfile_obstack
);
9742 part_die
->fixup_called
= 1;
9745 /* Read an attribute value described by an attribute form. */
9748 read_attribute_value (struct attribute
*attr
, unsigned form
,
9749 bfd
*abfd
, gdb_byte
*info_ptr
,
9750 struct dwarf2_cu
*cu
)
9752 struct comp_unit_head
*cu_header
= &cu
->header
;
9753 unsigned int bytes_read
;
9754 struct dwarf_block
*blk
;
9759 case DW_FORM_ref_addr
:
9760 if (cu
->header
.version
== 2)
9761 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9763 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
9764 &cu
->header
, &bytes_read
);
9765 info_ptr
+= bytes_read
;
9768 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9769 info_ptr
+= bytes_read
;
9771 case DW_FORM_block2
:
9772 blk
= dwarf_alloc_block (cu
);
9773 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9775 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9776 info_ptr
+= blk
->size
;
9777 DW_BLOCK (attr
) = blk
;
9779 case DW_FORM_block4
:
9780 blk
= dwarf_alloc_block (cu
);
9781 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9783 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9784 info_ptr
+= blk
->size
;
9785 DW_BLOCK (attr
) = blk
;
9788 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9792 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9796 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9799 case DW_FORM_sec_offset
:
9800 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9801 info_ptr
+= bytes_read
;
9803 case DW_FORM_string
:
9804 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9805 DW_STRING_IS_CANONICAL (attr
) = 0;
9806 info_ptr
+= bytes_read
;
9809 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9811 DW_STRING_IS_CANONICAL (attr
) = 0;
9812 info_ptr
+= bytes_read
;
9814 case DW_FORM_exprloc
:
9816 blk
= dwarf_alloc_block (cu
);
9817 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9818 info_ptr
+= bytes_read
;
9819 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9820 info_ptr
+= blk
->size
;
9821 DW_BLOCK (attr
) = blk
;
9823 case DW_FORM_block1
:
9824 blk
= dwarf_alloc_block (cu
);
9825 blk
->size
= read_1_byte (abfd
, info_ptr
);
9827 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9828 info_ptr
+= blk
->size
;
9829 DW_BLOCK (attr
) = blk
;
9832 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9836 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9839 case DW_FORM_flag_present
:
9840 DW_UNSND (attr
) = 1;
9843 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9844 info_ptr
+= bytes_read
;
9847 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9848 info_ptr
+= bytes_read
;
9851 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9855 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9859 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9863 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9866 case DW_FORM_ref_sig8
:
9867 /* Convert the signature to something we can record in DW_UNSND
9869 NOTE: This is NULL if the type wasn't found. */
9870 DW_SIGNATURED_TYPE (attr
) =
9871 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9874 case DW_FORM_ref_udata
:
9875 DW_ADDR (attr
) = (cu
->header
.offset
9876 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9877 info_ptr
+= bytes_read
;
9879 case DW_FORM_indirect
:
9880 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9881 info_ptr
+= bytes_read
;
9882 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9885 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9886 dwarf_form_name (form
),
9887 bfd_get_filename (abfd
));
9890 /* We have seen instances where the compiler tried to emit a byte
9891 size attribute of -1 which ended up being encoded as an unsigned
9892 0xffffffff. Although 0xffffffff is technically a valid size value,
9893 an object of this size seems pretty unlikely so we can relatively
9894 safely treat these cases as if the size attribute was invalid and
9895 treat them as zero by default. */
9896 if (attr
->name
== DW_AT_byte_size
9897 && form
== DW_FORM_data4
9898 && DW_UNSND (attr
) >= 0xffffffff)
9901 (&symfile_complaints
,
9902 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9903 hex_string (DW_UNSND (attr
)));
9904 DW_UNSND (attr
) = 0;
9910 /* Read an attribute described by an abbreviated attribute. */
9913 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9914 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9916 attr
->name
= abbrev
->name
;
9917 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9920 /* Read dwarf information from a buffer. */
9923 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9925 return bfd_get_8 (abfd
, buf
);
9929 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9931 return bfd_get_signed_8 (abfd
, buf
);
9935 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9937 return bfd_get_16 (abfd
, buf
);
9941 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9943 return bfd_get_signed_16 (abfd
, buf
);
9947 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9949 return bfd_get_32 (abfd
, buf
);
9953 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9955 return bfd_get_signed_32 (abfd
, buf
);
9959 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9961 return bfd_get_64 (abfd
, buf
);
9965 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9966 unsigned int *bytes_read
)
9968 struct comp_unit_head
*cu_header
= &cu
->header
;
9969 CORE_ADDR retval
= 0;
9971 if (cu_header
->signed_addr_p
)
9973 switch (cu_header
->addr_size
)
9976 retval
= bfd_get_signed_16 (abfd
, buf
);
9979 retval
= bfd_get_signed_32 (abfd
, buf
);
9982 retval
= bfd_get_signed_64 (abfd
, buf
);
9985 internal_error (__FILE__
, __LINE__
,
9986 _("read_address: bad switch, signed [in module %s]"),
9987 bfd_get_filename (abfd
));
9992 switch (cu_header
->addr_size
)
9995 retval
= bfd_get_16 (abfd
, buf
);
9998 retval
= bfd_get_32 (abfd
, buf
);
10001 retval
= bfd_get_64 (abfd
, buf
);
10004 internal_error (__FILE__
, __LINE__
,
10005 _("read_address: bad switch, "
10006 "unsigned [in module %s]"),
10007 bfd_get_filename (abfd
));
10011 *bytes_read
= cu_header
->addr_size
;
10015 /* Read the initial length from a section. The (draft) DWARF 3
10016 specification allows the initial length to take up either 4 bytes
10017 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10018 bytes describe the length and all offsets will be 8 bytes in length
10021 An older, non-standard 64-bit format is also handled by this
10022 function. The older format in question stores the initial length
10023 as an 8-byte quantity without an escape value. Lengths greater
10024 than 2^32 aren't very common which means that the initial 4 bytes
10025 is almost always zero. Since a length value of zero doesn't make
10026 sense for the 32-bit format, this initial zero can be considered to
10027 be an escape value which indicates the presence of the older 64-bit
10028 format. As written, the code can't detect (old format) lengths
10029 greater than 4GB. If it becomes necessary to handle lengths
10030 somewhat larger than 4GB, we could allow other small values (such
10031 as the non-sensical values of 1, 2, and 3) to also be used as
10032 escape values indicating the presence of the old format.
10034 The value returned via bytes_read should be used to increment the
10035 relevant pointer after calling read_initial_length().
10037 [ Note: read_initial_length() and read_offset() are based on the
10038 document entitled "DWARF Debugging Information Format", revision
10039 3, draft 8, dated November 19, 2001. This document was obtained
10042 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10044 This document is only a draft and is subject to change. (So beware.)
10046 Details regarding the older, non-standard 64-bit format were
10047 determined empirically by examining 64-bit ELF files produced by
10048 the SGI toolchain on an IRIX 6.5 machine.
10050 - Kevin, July 16, 2002
10054 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10056 LONGEST length
= bfd_get_32 (abfd
, buf
);
10058 if (length
== 0xffffffff)
10060 length
= bfd_get_64 (abfd
, buf
+ 4);
10063 else if (length
== 0)
10065 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10066 length
= bfd_get_64 (abfd
, buf
);
10077 /* Cover function for read_initial_length.
10078 Returns the length of the object at BUF, and stores the size of the
10079 initial length in *BYTES_READ and stores the size that offsets will be in
10081 If the initial length size is not equivalent to that specified in
10082 CU_HEADER then issue a complaint.
10083 This is useful when reading non-comp-unit headers. */
10086 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10087 const struct comp_unit_head
*cu_header
,
10088 unsigned int *bytes_read
,
10089 unsigned int *offset_size
)
10091 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10093 gdb_assert (cu_header
->initial_length_size
== 4
10094 || cu_header
->initial_length_size
== 8
10095 || cu_header
->initial_length_size
== 12);
10097 if (cu_header
->initial_length_size
!= *bytes_read
)
10098 complaint (&symfile_complaints
,
10099 _("intermixed 32-bit and 64-bit DWARF sections"));
10101 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10105 /* Read an offset from the data stream. The size of the offset is
10106 given by cu_header->offset_size. */
10109 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10110 unsigned int *bytes_read
)
10112 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10114 *bytes_read
= cu_header
->offset_size
;
10118 /* Read an offset from the data stream. */
10121 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10123 LONGEST retval
= 0;
10125 switch (offset_size
)
10128 retval
= bfd_get_32 (abfd
, buf
);
10131 retval
= bfd_get_64 (abfd
, buf
);
10134 internal_error (__FILE__
, __LINE__
,
10135 _("read_offset_1: bad switch [in module %s]"),
10136 bfd_get_filename (abfd
));
10143 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10145 /* If the size of a host char is 8 bits, we can return a pointer
10146 to the buffer, otherwise we have to copy the data to a buffer
10147 allocated on the temporary obstack. */
10148 gdb_assert (HOST_CHAR_BIT
== 8);
10153 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10155 /* If the size of a host char is 8 bits, we can return a pointer
10156 to the string, otherwise we have to copy the string to a buffer
10157 allocated on the temporary obstack. */
10158 gdb_assert (HOST_CHAR_BIT
== 8);
10161 *bytes_read_ptr
= 1;
10164 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10165 return (char *) buf
;
10169 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10170 const struct comp_unit_head
*cu_header
,
10171 unsigned int *bytes_read_ptr
)
10173 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10175 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10176 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10178 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10179 bfd_get_filename (abfd
));
10182 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10184 error (_("DW_FORM_strp pointing outside of "
10185 ".debug_str section [in module %s]"),
10186 bfd_get_filename (abfd
));
10189 gdb_assert (HOST_CHAR_BIT
== 8);
10190 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10192 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10195 static unsigned long
10196 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10198 unsigned long result
;
10199 unsigned int num_read
;
10201 unsigned char byte
;
10209 byte
= bfd_get_8 (abfd
, buf
);
10212 result
|= ((unsigned long)(byte
& 127) << shift
);
10213 if ((byte
& 128) == 0)
10219 *bytes_read_ptr
= num_read
;
10224 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10227 int i
, shift
, num_read
;
10228 unsigned char byte
;
10236 byte
= bfd_get_8 (abfd
, buf
);
10239 result
|= ((long)(byte
& 127) << shift
);
10241 if ((byte
& 128) == 0)
10246 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10247 result
|= -(((long)1) << shift
);
10248 *bytes_read_ptr
= num_read
;
10252 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10255 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10261 byte
= bfd_get_8 (abfd
, buf
);
10263 if ((byte
& 128) == 0)
10269 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10276 cu
->language
= language_c
;
10278 case DW_LANG_C_plus_plus
:
10279 cu
->language
= language_cplus
;
10282 cu
->language
= language_d
;
10284 case DW_LANG_Fortran77
:
10285 case DW_LANG_Fortran90
:
10286 case DW_LANG_Fortran95
:
10287 cu
->language
= language_fortran
;
10289 case DW_LANG_Mips_Assembler
:
10290 cu
->language
= language_asm
;
10293 cu
->language
= language_java
;
10295 case DW_LANG_Ada83
:
10296 case DW_LANG_Ada95
:
10297 cu
->language
= language_ada
;
10299 case DW_LANG_Modula2
:
10300 cu
->language
= language_m2
;
10302 case DW_LANG_Pascal83
:
10303 cu
->language
= language_pascal
;
10306 cu
->language
= language_objc
;
10308 case DW_LANG_Cobol74
:
10309 case DW_LANG_Cobol85
:
10311 cu
->language
= language_minimal
;
10314 cu
->language_defn
= language_def (cu
->language
);
10317 /* Return the named attribute or NULL if not there. */
10319 static struct attribute
*
10320 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10323 struct attribute
*spec
= NULL
;
10325 for (i
= 0; i
< die
->num_attrs
; ++i
)
10327 if (die
->attrs
[i
].name
== name
)
10328 return &die
->attrs
[i
];
10329 if (die
->attrs
[i
].name
== DW_AT_specification
10330 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10331 spec
= &die
->attrs
[i
];
10336 die
= follow_die_ref (die
, spec
, &cu
);
10337 return dwarf2_attr (die
, name
, cu
);
10343 /* Return the named attribute or NULL if not there,
10344 but do not follow DW_AT_specification, etc.
10345 This is for use in contexts where we're reading .debug_types dies.
10346 Following DW_AT_specification, DW_AT_abstract_origin will take us
10347 back up the chain, and we want to go down. */
10349 static struct attribute
*
10350 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10351 struct dwarf2_cu
*cu
)
10355 for (i
= 0; i
< die
->num_attrs
; ++i
)
10356 if (die
->attrs
[i
].name
== name
)
10357 return &die
->attrs
[i
];
10362 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10363 and holds a non-zero value. This function should only be used for
10364 DW_FORM_flag or DW_FORM_flag_present attributes. */
10367 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10369 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10371 return (attr
&& DW_UNSND (attr
));
10375 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10377 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10378 which value is non-zero. However, we have to be careful with
10379 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10380 (via dwarf2_flag_true_p) follows this attribute. So we may
10381 end up accidently finding a declaration attribute that belongs
10382 to a different DIE referenced by the specification attribute,
10383 even though the given DIE does not have a declaration attribute. */
10384 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10385 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10388 /* Return the die giving the specification for DIE, if there is
10389 one. *SPEC_CU is the CU containing DIE on input, and the CU
10390 containing the return value on output. If there is no
10391 specification, but there is an abstract origin, that is
10394 static struct die_info
*
10395 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10397 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10400 if (spec_attr
== NULL
)
10401 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10403 if (spec_attr
== NULL
)
10406 return follow_die_ref (die
, spec_attr
, spec_cu
);
10409 /* Free the line_header structure *LH, and any arrays and strings it
10411 NOTE: This is also used as a "cleanup" function. */
10414 free_line_header (struct line_header
*lh
)
10416 if (lh
->standard_opcode_lengths
)
10417 xfree (lh
->standard_opcode_lengths
);
10419 /* Remember that all the lh->file_names[i].name pointers are
10420 pointers into debug_line_buffer, and don't need to be freed. */
10421 if (lh
->file_names
)
10422 xfree (lh
->file_names
);
10424 /* Similarly for the include directory names. */
10425 if (lh
->include_dirs
)
10426 xfree (lh
->include_dirs
);
10431 /* Add an entry to LH's include directory table. */
10434 add_include_dir (struct line_header
*lh
, char *include_dir
)
10436 /* Grow the array if necessary. */
10437 if (lh
->include_dirs_size
== 0)
10439 lh
->include_dirs_size
= 1; /* for testing */
10440 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10441 * sizeof (*lh
->include_dirs
));
10443 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10445 lh
->include_dirs_size
*= 2;
10446 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10447 (lh
->include_dirs_size
10448 * sizeof (*lh
->include_dirs
)));
10451 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10454 /* Add an entry to LH's file name table. */
10457 add_file_name (struct line_header
*lh
,
10459 unsigned int dir_index
,
10460 unsigned int mod_time
,
10461 unsigned int length
)
10463 struct file_entry
*fe
;
10465 /* Grow the array if necessary. */
10466 if (lh
->file_names_size
== 0)
10468 lh
->file_names_size
= 1; /* for testing */
10469 lh
->file_names
= xmalloc (lh
->file_names_size
10470 * sizeof (*lh
->file_names
));
10472 else if (lh
->num_file_names
>= lh
->file_names_size
)
10474 lh
->file_names_size
*= 2;
10475 lh
->file_names
= xrealloc (lh
->file_names
,
10476 (lh
->file_names_size
10477 * sizeof (*lh
->file_names
)));
10480 fe
= &lh
->file_names
[lh
->num_file_names
++];
10482 fe
->dir_index
= dir_index
;
10483 fe
->mod_time
= mod_time
;
10484 fe
->length
= length
;
10485 fe
->included_p
= 0;
10489 /* Read the statement program header starting at OFFSET in
10490 .debug_line, according to the endianness of ABFD. Return a pointer
10491 to a struct line_header, allocated using xmalloc.
10493 NOTE: the strings in the include directory and file name tables of
10494 the returned object point into debug_line_buffer, and must not be
10497 static struct line_header
*
10498 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10499 struct dwarf2_cu
*cu
)
10501 struct cleanup
*back_to
;
10502 struct line_header
*lh
;
10503 gdb_byte
*line_ptr
;
10504 unsigned int bytes_read
, offset_size
;
10506 char *cur_dir
, *cur_file
;
10508 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10509 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10511 complaint (&symfile_complaints
, _("missing .debug_line section"));
10515 /* Make sure that at least there's room for the total_length field.
10516 That could be 12 bytes long, but we're just going to fudge that. */
10517 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10519 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10523 lh
= xmalloc (sizeof (*lh
));
10524 memset (lh
, 0, sizeof (*lh
));
10525 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10528 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10530 /* Read in the header. */
10532 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10533 &bytes_read
, &offset_size
);
10534 line_ptr
+= bytes_read
;
10535 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10536 + dwarf2_per_objfile
->line
.size
))
10538 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10541 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10542 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10544 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10545 line_ptr
+= offset_size
;
10546 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10548 if (lh
->version
>= 4)
10550 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10554 lh
->maximum_ops_per_instruction
= 1;
10556 if (lh
->maximum_ops_per_instruction
== 0)
10558 lh
->maximum_ops_per_instruction
= 1;
10559 complaint (&symfile_complaints
,
10560 _("invalid maximum_ops_per_instruction "
10561 "in `.debug_line' section"));
10564 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10566 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10568 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10570 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10572 lh
->standard_opcode_lengths
10573 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10575 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10576 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10578 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10582 /* Read directory table. */
10583 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10585 line_ptr
+= bytes_read
;
10586 add_include_dir (lh
, cur_dir
);
10588 line_ptr
+= bytes_read
;
10590 /* Read file name table. */
10591 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10593 unsigned int dir_index
, mod_time
, length
;
10595 line_ptr
+= bytes_read
;
10596 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10597 line_ptr
+= bytes_read
;
10598 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10599 line_ptr
+= bytes_read
;
10600 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10601 line_ptr
+= bytes_read
;
10603 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10605 line_ptr
+= bytes_read
;
10606 lh
->statement_program_start
= line_ptr
;
10608 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
10609 + dwarf2_per_objfile
->line
.size
))
10610 complaint (&symfile_complaints
,
10611 _("line number info header doesn't "
10612 "fit in `.debug_line' section"));
10614 discard_cleanups (back_to
);
10618 /* This function exists to work around a bug in certain compilers
10619 (particularly GCC 2.95), in which the first line number marker of a
10620 function does not show up until after the prologue, right before
10621 the second line number marker. This function shifts ADDRESS down
10622 to the beginning of the function if necessary, and is called on
10623 addresses passed to record_line. */
10626 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
10628 struct function_range
*fn
;
10630 /* Find the function_range containing address. */
10634 if (!cu
->cached_fn
)
10635 cu
->cached_fn
= cu
->first_fn
;
10637 fn
= cu
->cached_fn
;
10639 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10645 while (fn
&& fn
!= cu
->cached_fn
)
10646 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10656 if (address
!= fn
->lowpc
)
10657 complaint (&symfile_complaints
,
10658 _("misplaced first line number at 0x%lx for '%s'"),
10659 (unsigned long) address
, fn
->name
);
10664 /* Subroutine of dwarf_decode_lines to simplify it.
10665 Return the file name of the psymtab for included file FILE_INDEX
10666 in line header LH of PST.
10667 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10668 If space for the result is malloc'd, it will be freed by a cleanup.
10669 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10672 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10673 const struct partial_symtab
*pst
,
10674 const char *comp_dir
)
10676 const struct file_entry fe
= lh
->file_names
[file_index
];
10677 char *include_name
= fe
.name
;
10678 char *include_name_to_compare
= include_name
;
10679 char *dir_name
= NULL
;
10680 const char *pst_filename
;
10681 char *copied_name
= NULL
;
10685 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10687 if (!IS_ABSOLUTE_PATH (include_name
)
10688 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10690 /* Avoid creating a duplicate psymtab for PST.
10691 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10692 Before we do the comparison, however, we need to account
10693 for DIR_NAME and COMP_DIR.
10694 First prepend dir_name (if non-NULL). If we still don't
10695 have an absolute path prepend comp_dir (if non-NULL).
10696 However, the directory we record in the include-file's
10697 psymtab does not contain COMP_DIR (to match the
10698 corresponding symtab(s)).
10703 bash$ gcc -g ./hello.c
10704 include_name = "hello.c"
10706 DW_AT_comp_dir = comp_dir = "/tmp"
10707 DW_AT_name = "./hello.c" */
10709 if (dir_name
!= NULL
)
10711 include_name
= concat (dir_name
, SLASH_STRING
,
10712 include_name
, (char *)NULL
);
10713 include_name_to_compare
= include_name
;
10714 make_cleanup (xfree
, include_name
);
10716 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10718 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10719 include_name
, (char *)NULL
);
10723 pst_filename
= pst
->filename
;
10724 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10726 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
10727 pst_filename
, (char *)NULL
);
10728 pst_filename
= copied_name
;
10731 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
10733 if (include_name_to_compare
!= include_name
)
10734 xfree (include_name_to_compare
);
10735 if (copied_name
!= NULL
)
10736 xfree (copied_name
);
10740 return include_name
;
10743 /* Ignore this record_line request. */
10746 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10751 /* Decode the Line Number Program (LNP) for the given line_header
10752 structure and CU. The actual information extracted and the type
10753 of structures created from the LNP depends on the value of PST.
10755 1. If PST is NULL, then this procedure uses the data from the program
10756 to create all necessary symbol tables, and their linetables.
10758 2. If PST is not NULL, this procedure reads the program to determine
10759 the list of files included by the unit represented by PST, and
10760 builds all the associated partial symbol tables.
10762 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10763 It is used for relative paths in the line table.
10764 NOTE: When processing partial symtabs (pst != NULL),
10765 comp_dir == pst->dirname.
10767 NOTE: It is important that psymtabs have the same file name (via strcmp)
10768 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10769 symtab we don't use it in the name of the psymtabs we create.
10770 E.g. expand_line_sal requires this when finding psymtabs to expand.
10771 A good testcase for this is mb-inline.exp. */
10774 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
10775 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10777 gdb_byte
*line_ptr
, *extended_end
;
10778 gdb_byte
*line_end
;
10779 unsigned int bytes_read
, extended_len
;
10780 unsigned char op_code
, extended_op
, adj_opcode
;
10781 CORE_ADDR baseaddr
;
10782 struct objfile
*objfile
= cu
->objfile
;
10783 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10784 const int decode_for_pst_p
= (pst
!= NULL
);
10785 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10786 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10789 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10791 line_ptr
= lh
->statement_program_start
;
10792 line_end
= lh
->statement_program_end
;
10794 /* Read the statement sequences until there's nothing left. */
10795 while (line_ptr
< line_end
)
10797 /* state machine registers */
10798 CORE_ADDR address
= 0;
10799 unsigned int file
= 1;
10800 unsigned int line
= 1;
10801 unsigned int column
= 0;
10802 int is_stmt
= lh
->default_is_stmt
;
10803 int basic_block
= 0;
10804 int end_sequence
= 0;
10806 unsigned char op_index
= 0;
10808 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10810 /* Start a subfile for the current file of the state machine. */
10811 /* lh->include_dirs and lh->file_names are 0-based, but the
10812 directory and file name numbers in the statement program
10814 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10818 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10820 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10823 /* Decode the table. */
10824 while (!end_sequence
)
10826 op_code
= read_1_byte (abfd
, line_ptr
);
10828 if (line_ptr
> line_end
)
10830 dwarf2_debug_line_missing_end_sequence_complaint ();
10834 if (op_code
>= lh
->opcode_base
)
10836 /* Special operand. */
10837 adj_opcode
= op_code
- lh
->opcode_base
;
10838 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10839 / lh
->maximum_ops_per_instruction
)
10840 * lh
->minimum_instruction_length
);
10841 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10842 % lh
->maximum_ops_per_instruction
);
10843 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10844 if (lh
->num_file_names
< file
|| file
== 0)
10845 dwarf2_debug_line_missing_file_complaint ();
10846 /* For now we ignore lines not starting on an
10847 instruction boundary. */
10848 else if (op_index
== 0)
10850 lh
->file_names
[file
- 1].included_p
= 1;
10851 if (!decode_for_pst_p
&& is_stmt
)
10853 if (last_subfile
!= current_subfile
)
10855 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10857 (*p_record_line
) (last_subfile
, 0, addr
);
10858 last_subfile
= current_subfile
;
10860 /* Append row to matrix using current values. */
10861 addr
= check_cu_functions (address
, cu
);
10862 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10863 (*p_record_line
) (current_subfile
, line
, addr
);
10868 else switch (op_code
)
10870 case DW_LNS_extended_op
:
10871 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
10873 line_ptr
+= bytes_read
;
10874 extended_end
= line_ptr
+ extended_len
;
10875 extended_op
= read_1_byte (abfd
, line_ptr
);
10877 switch (extended_op
)
10879 case DW_LNE_end_sequence
:
10880 p_record_line
= record_line
;
10883 case DW_LNE_set_address
:
10884 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10886 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10888 /* This line table is for a function which has been
10889 GCd by the linker. Ignore it. PR gdb/12528 */
10892 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
10894 complaint (&symfile_complaints
,
10895 _(".debug_line address at offset 0x%lx is 0 "
10897 line_offset
, cu
->objfile
->name
);
10898 p_record_line
= noop_record_line
;
10902 line_ptr
+= bytes_read
;
10903 address
+= baseaddr
;
10905 case DW_LNE_define_file
:
10908 unsigned int dir_index
, mod_time
, length
;
10910 cur_file
= read_direct_string (abfd
, line_ptr
,
10912 line_ptr
+= bytes_read
;
10914 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10915 line_ptr
+= bytes_read
;
10917 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10918 line_ptr
+= bytes_read
;
10920 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10921 line_ptr
+= bytes_read
;
10922 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10925 case DW_LNE_set_discriminator
:
10926 /* The discriminator is not interesting to the debugger;
10928 line_ptr
= extended_end
;
10931 complaint (&symfile_complaints
,
10932 _("mangled .debug_line section"));
10935 /* Make sure that we parsed the extended op correctly. If e.g.
10936 we expected a different address size than the producer used,
10937 we may have read the wrong number of bytes. */
10938 if (line_ptr
!= extended_end
)
10940 complaint (&symfile_complaints
,
10941 _("mangled .debug_line section"));
10946 if (lh
->num_file_names
< file
|| file
== 0)
10947 dwarf2_debug_line_missing_file_complaint ();
10950 lh
->file_names
[file
- 1].included_p
= 1;
10951 if (!decode_for_pst_p
&& is_stmt
)
10953 if (last_subfile
!= current_subfile
)
10955 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10957 (*p_record_line
) (last_subfile
, 0, addr
);
10958 last_subfile
= current_subfile
;
10960 addr
= check_cu_functions (address
, cu
);
10961 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10962 (*p_record_line
) (current_subfile
, line
, addr
);
10967 case DW_LNS_advance_pc
:
10970 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10972 address
+= (((op_index
+ adjust
)
10973 / lh
->maximum_ops_per_instruction
)
10974 * lh
->minimum_instruction_length
);
10975 op_index
= ((op_index
+ adjust
)
10976 % lh
->maximum_ops_per_instruction
);
10977 line_ptr
+= bytes_read
;
10980 case DW_LNS_advance_line
:
10981 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
10982 line_ptr
+= bytes_read
;
10984 case DW_LNS_set_file
:
10986 /* The arrays lh->include_dirs and lh->file_names are
10987 0-based, but the directory and file name numbers in
10988 the statement program are 1-based. */
10989 struct file_entry
*fe
;
10992 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10993 line_ptr
+= bytes_read
;
10994 if (lh
->num_file_names
< file
|| file
== 0)
10995 dwarf2_debug_line_missing_file_complaint ();
10998 fe
= &lh
->file_names
[file
- 1];
11000 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11001 if (!decode_for_pst_p
)
11003 last_subfile
= current_subfile
;
11004 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11009 case DW_LNS_set_column
:
11010 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11011 line_ptr
+= bytes_read
;
11013 case DW_LNS_negate_stmt
:
11014 is_stmt
= (!is_stmt
);
11016 case DW_LNS_set_basic_block
:
11019 /* Add to the address register of the state machine the
11020 address increment value corresponding to special opcode
11021 255. I.e., this value is scaled by the minimum
11022 instruction length since special opcode 255 would have
11023 scaled the increment. */
11024 case DW_LNS_const_add_pc
:
11026 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11028 address
+= (((op_index
+ adjust
)
11029 / lh
->maximum_ops_per_instruction
)
11030 * lh
->minimum_instruction_length
);
11031 op_index
= ((op_index
+ adjust
)
11032 % lh
->maximum_ops_per_instruction
);
11035 case DW_LNS_fixed_advance_pc
:
11036 address
+= read_2_bytes (abfd
, line_ptr
);
11042 /* Unknown standard opcode, ignore it. */
11045 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11047 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11048 line_ptr
+= bytes_read
;
11053 if (lh
->num_file_names
< file
|| file
== 0)
11054 dwarf2_debug_line_missing_file_complaint ();
11057 lh
->file_names
[file
- 1].included_p
= 1;
11058 if (!decode_for_pst_p
)
11060 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11061 (*p_record_line
) (current_subfile
, 0, addr
);
11066 if (decode_for_pst_p
)
11070 /* Now that we're done scanning the Line Header Program, we can
11071 create the psymtab of each included file. */
11072 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11073 if (lh
->file_names
[file_index
].included_p
== 1)
11075 char *include_name
=
11076 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11077 if (include_name
!= NULL
)
11078 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11083 /* Make sure a symtab is created for every file, even files
11084 which contain only variables (i.e. no code with associated
11088 struct file_entry
*fe
;
11090 for (i
= 0; i
< lh
->num_file_names
; i
++)
11094 fe
= &lh
->file_names
[i
];
11096 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11097 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11099 /* Skip the main file; we don't need it, and it must be
11100 allocated last, so that it will show up before the
11101 non-primary symtabs in the objfile's symtab list. */
11102 if (current_subfile
== first_subfile
)
11105 if (current_subfile
->symtab
== NULL
)
11106 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11108 fe
->symtab
= current_subfile
->symtab
;
11113 /* Start a subfile for DWARF. FILENAME is the name of the file and
11114 DIRNAME the name of the source directory which contains FILENAME
11115 or NULL if not known. COMP_DIR is the compilation directory for the
11116 linetable's compilation unit or NULL if not known.
11117 This routine tries to keep line numbers from identical absolute and
11118 relative file names in a common subfile.
11120 Using the `list' example from the GDB testsuite, which resides in
11121 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11122 of /srcdir/list0.c yields the following debugging information for list0.c:
11124 DW_AT_name: /srcdir/list0.c
11125 DW_AT_comp_dir: /compdir
11126 files.files[0].name: list0.h
11127 files.files[0].dir: /srcdir
11128 files.files[1].name: list0.c
11129 files.files[1].dir: /srcdir
11131 The line number information for list0.c has to end up in a single
11132 subfile, so that `break /srcdir/list0.c:1' works as expected.
11133 start_subfile will ensure that this happens provided that we pass the
11134 concatenation of files.files[1].dir and files.files[1].name as the
11138 dwarf2_start_subfile (char *filename
, const char *dirname
,
11139 const char *comp_dir
)
11143 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11144 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11145 second argument to start_subfile. To be consistent, we do the
11146 same here. In order not to lose the line information directory,
11147 we concatenate it to the filename when it makes sense.
11148 Note that the Dwarf3 standard says (speaking of filenames in line
11149 information): ``The directory index is ignored for file names
11150 that represent full path names''. Thus ignoring dirname in the
11151 `else' branch below isn't an issue. */
11153 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11154 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11156 fullname
= filename
;
11158 start_subfile (fullname
, comp_dir
);
11160 if (fullname
!= filename
)
11165 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11166 struct dwarf2_cu
*cu
)
11168 struct objfile
*objfile
= cu
->objfile
;
11169 struct comp_unit_head
*cu_header
= &cu
->header
;
11171 /* NOTE drow/2003-01-30: There used to be a comment and some special
11172 code here to turn a symbol with DW_AT_external and a
11173 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11174 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11175 with some versions of binutils) where shared libraries could have
11176 relocations against symbols in their debug information - the
11177 minimal symbol would have the right address, but the debug info
11178 would not. It's no longer necessary, because we will explicitly
11179 apply relocations when we read in the debug information now. */
11181 /* A DW_AT_location attribute with no contents indicates that a
11182 variable has been optimized away. */
11183 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11185 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11189 /* Handle one degenerate form of location expression specially, to
11190 preserve GDB's previous behavior when section offsets are
11191 specified. If this is just a DW_OP_addr then mark this symbol
11194 if (attr_form_is_block (attr
)
11195 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11196 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11198 unsigned int dummy
;
11200 SYMBOL_VALUE_ADDRESS (sym
) =
11201 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11202 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11203 fixup_symbol_section (sym
, objfile
);
11204 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11205 SYMBOL_SECTION (sym
));
11209 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11210 expression evaluator, and use LOC_COMPUTED only when necessary
11211 (i.e. when the value of a register or memory location is
11212 referenced, or a thread-local block, etc.). Then again, it might
11213 not be worthwhile. I'm assuming that it isn't unless performance
11214 or memory numbers show me otherwise. */
11216 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11217 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11219 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11220 cu
->has_loclist
= 1;
11223 /* Given a pointer to a DWARF information entry, figure out if we need
11224 to make a symbol table entry for it, and if so, create a new entry
11225 and return a pointer to it.
11226 If TYPE is NULL, determine symbol type from the die, otherwise
11227 used the passed type.
11228 If SPACE is not NULL, use it to hold the new symbol. If it is
11229 NULL, allocate a new symbol on the objfile's obstack. */
11231 static struct symbol
*
11232 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11233 struct symbol
*space
)
11235 struct objfile
*objfile
= cu
->objfile
;
11236 struct symbol
*sym
= NULL
;
11238 struct attribute
*attr
= NULL
;
11239 struct attribute
*attr2
= NULL
;
11240 CORE_ADDR baseaddr
;
11241 struct pending
**list_to_add
= NULL
;
11243 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11245 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11247 name
= dwarf2_name (die
, cu
);
11250 const char *linkagename
;
11251 int suppress_add
= 0;
11256 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11257 OBJSTAT (objfile
, n_syms
++);
11259 /* Cache this symbol's name and the name's demangled form (if any). */
11260 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11261 linkagename
= dwarf2_physname (name
, die
, cu
);
11262 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11264 /* Fortran does not have mangling standard and the mangling does differ
11265 between gfortran, iFort etc. */
11266 if (cu
->language
== language_fortran
11267 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11268 symbol_set_demangled_name (&(sym
->ginfo
),
11269 (char *) dwarf2_full_name (name
, die
, cu
),
11272 /* Default assumptions.
11273 Use the passed type or decode it from the die. */
11274 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11275 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11277 SYMBOL_TYPE (sym
) = type
;
11279 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11280 attr
= dwarf2_attr (die
,
11281 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11285 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11288 attr
= dwarf2_attr (die
,
11289 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11293 int file_index
= DW_UNSND (attr
);
11295 if (cu
->line_header
== NULL
11296 || file_index
> cu
->line_header
->num_file_names
)
11297 complaint (&symfile_complaints
,
11298 _("file index out of range"));
11299 else if (file_index
> 0)
11301 struct file_entry
*fe
;
11303 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11304 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11311 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11314 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11316 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11317 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11318 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11319 add_symbol_to_list (sym
, cu
->list_in_scope
);
11321 case DW_TAG_subprogram
:
11322 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11324 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11325 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11326 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11327 || cu
->language
== language_ada
)
11329 /* Subprograms marked external are stored as a global symbol.
11330 Ada subprograms, whether marked external or not, are always
11331 stored as a global symbol, because we want to be able to
11332 access them globally. For instance, we want to be able
11333 to break on a nested subprogram without having to
11334 specify the context. */
11335 list_to_add
= &global_symbols
;
11339 list_to_add
= cu
->list_in_scope
;
11342 case DW_TAG_inlined_subroutine
:
11343 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11345 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11346 SYMBOL_INLINED (sym
) = 1;
11347 /* Do not add the symbol to any lists. It will be found via
11348 BLOCK_FUNCTION from the blockvector. */
11350 case DW_TAG_template_value_param
:
11352 /* Fall through. */
11353 case DW_TAG_constant
:
11354 case DW_TAG_variable
:
11355 case DW_TAG_member
:
11356 /* Compilation with minimal debug info may result in
11357 variables with missing type entries. Change the
11358 misleading `void' type to something sensible. */
11359 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11361 = objfile_type (objfile
)->nodebug_data_symbol
;
11363 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11364 /* In the case of DW_TAG_member, we should only be called for
11365 static const members. */
11366 if (die
->tag
== DW_TAG_member
)
11368 /* dwarf2_add_field uses die_is_declaration,
11369 so we do the same. */
11370 gdb_assert (die_is_declaration (die
, cu
));
11375 dwarf2_const_value (attr
, sym
, cu
);
11376 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11379 if (attr2
&& (DW_UNSND (attr2
) != 0))
11380 list_to_add
= &global_symbols
;
11382 list_to_add
= cu
->list_in_scope
;
11386 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11389 var_decode_location (attr
, sym
, cu
);
11390 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11391 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11392 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11393 && !dwarf2_per_objfile
->has_section_at_zero
)
11395 /* When a static variable is eliminated by the linker,
11396 the corresponding debug information is not stripped
11397 out, but the variable address is set to null;
11398 do not add such variables into symbol table. */
11400 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11402 /* Workaround gfortran PR debug/40040 - it uses
11403 DW_AT_location for variables in -fPIC libraries which may
11404 get overriden by other libraries/executable and get
11405 a different address. Resolve it by the minimal symbol
11406 which may come from inferior's executable using copy
11407 relocation. Make this workaround only for gfortran as for
11408 other compilers GDB cannot guess the minimal symbol
11409 Fortran mangling kind. */
11410 if (cu
->language
== language_fortran
&& die
->parent
11411 && die
->parent
->tag
== DW_TAG_module
11413 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11414 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11416 /* A variable with DW_AT_external is never static,
11417 but it may be block-scoped. */
11418 list_to_add
= (cu
->list_in_scope
== &file_symbols
11419 ? &global_symbols
: cu
->list_in_scope
);
11422 list_to_add
= cu
->list_in_scope
;
11426 /* We do not know the address of this symbol.
11427 If it is an external symbol and we have type information
11428 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11429 The address of the variable will then be determined from
11430 the minimal symbol table whenever the variable is
11432 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11433 if (attr2
&& (DW_UNSND (attr2
) != 0)
11434 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11436 /* A variable with DW_AT_external is never static, but it
11437 may be block-scoped. */
11438 list_to_add
= (cu
->list_in_scope
== &file_symbols
11439 ? &global_symbols
: cu
->list_in_scope
);
11441 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11443 else if (!die_is_declaration (die
, cu
))
11445 /* Use the default LOC_OPTIMIZED_OUT class. */
11446 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11448 list_to_add
= cu
->list_in_scope
;
11452 case DW_TAG_formal_parameter
:
11453 /* If we are inside a function, mark this as an argument. If
11454 not, we might be looking at an argument to an inlined function
11455 when we do not have enough information to show inlined frames;
11456 pretend it's a local variable in that case so that the user can
11458 if (context_stack_depth
> 0
11459 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11460 SYMBOL_IS_ARGUMENT (sym
) = 1;
11461 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11464 var_decode_location (attr
, sym
, cu
);
11466 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11469 dwarf2_const_value (attr
, sym
, cu
);
11471 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
11472 if (attr
&& DW_UNSND (attr
))
11474 struct type
*ref_type
;
11476 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
11477 SYMBOL_TYPE (sym
) = ref_type
;
11480 list_to_add
= cu
->list_in_scope
;
11482 case DW_TAG_unspecified_parameters
:
11483 /* From varargs functions; gdb doesn't seem to have any
11484 interest in this information, so just ignore it for now.
11487 case DW_TAG_template_type_param
:
11489 /* Fall through. */
11490 case DW_TAG_class_type
:
11491 case DW_TAG_interface_type
:
11492 case DW_TAG_structure_type
:
11493 case DW_TAG_union_type
:
11494 case DW_TAG_set_type
:
11495 case DW_TAG_enumeration_type
:
11496 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11497 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11500 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11501 really ever be static objects: otherwise, if you try
11502 to, say, break of a class's method and you're in a file
11503 which doesn't mention that class, it won't work unless
11504 the check for all static symbols in lookup_symbol_aux
11505 saves you. See the OtherFileClass tests in
11506 gdb.c++/namespace.exp. */
11510 list_to_add
= (cu
->list_in_scope
== &file_symbols
11511 && (cu
->language
== language_cplus
11512 || cu
->language
== language_java
)
11513 ? &global_symbols
: cu
->list_in_scope
);
11515 /* The semantics of C++ state that "struct foo {
11516 ... }" also defines a typedef for "foo". A Java
11517 class declaration also defines a typedef for the
11519 if (cu
->language
== language_cplus
11520 || cu
->language
== language_java
11521 || cu
->language
== language_ada
)
11523 /* The symbol's name is already allocated along
11524 with this objfile, so we don't need to
11525 duplicate it for the type. */
11526 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11527 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11532 case DW_TAG_typedef
:
11533 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11534 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11535 list_to_add
= cu
->list_in_scope
;
11537 case DW_TAG_base_type
:
11538 case DW_TAG_subrange_type
:
11539 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11540 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11541 list_to_add
= cu
->list_in_scope
;
11543 case DW_TAG_enumerator
:
11544 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11547 dwarf2_const_value (attr
, sym
, cu
);
11550 /* NOTE: carlton/2003-11-10: See comment above in the
11551 DW_TAG_class_type, etc. block. */
11553 list_to_add
= (cu
->list_in_scope
== &file_symbols
11554 && (cu
->language
== language_cplus
11555 || cu
->language
== language_java
)
11556 ? &global_symbols
: cu
->list_in_scope
);
11559 case DW_TAG_namespace
:
11560 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11561 list_to_add
= &global_symbols
;
11564 /* Not a tag we recognize. Hopefully we aren't processing
11565 trash data, but since we must specifically ignore things
11566 we don't recognize, there is nothing else we should do at
11568 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11569 dwarf_tag_name (die
->tag
));
11575 sym
->hash_next
= objfile
->template_symbols
;
11576 objfile
->template_symbols
= sym
;
11577 list_to_add
= NULL
;
11580 if (list_to_add
!= NULL
)
11581 add_symbol_to_list (sym
, list_to_add
);
11583 /* For the benefit of old versions of GCC, check for anonymous
11584 namespaces based on the demangled name. */
11585 if (!processing_has_namespace_info
11586 && cu
->language
== language_cplus
)
11587 cp_scan_for_anonymous_namespaces (sym
);
11592 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11594 static struct symbol
*
11595 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11597 return new_symbol_full (die
, type
, cu
, NULL
);
11600 /* Given an attr with a DW_FORM_dataN value in host byte order,
11601 zero-extend it as appropriate for the symbol's type. The DWARF
11602 standard (v4) is not entirely clear about the meaning of using
11603 DW_FORM_dataN for a constant with a signed type, where the type is
11604 wider than the data. The conclusion of a discussion on the DWARF
11605 list was that this is unspecified. We choose to always zero-extend
11606 because that is the interpretation long in use by GCC. */
11609 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11610 const char *name
, struct obstack
*obstack
,
11611 struct dwarf2_cu
*cu
, long *value
, int bits
)
11613 struct objfile
*objfile
= cu
->objfile
;
11614 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11615 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11616 LONGEST l
= DW_UNSND (attr
);
11618 if (bits
< sizeof (*value
) * 8)
11620 l
&= ((LONGEST
) 1 << bits
) - 1;
11623 else if (bits
== sizeof (*value
) * 8)
11627 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11628 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11635 /* Read a constant value from an attribute. Either set *VALUE, or if
11636 the value does not fit in *VALUE, set *BYTES - either already
11637 allocated on the objfile obstack, or newly allocated on OBSTACK,
11638 or, set *BATON, if we translated the constant to a location
11642 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11643 const char *name
, struct obstack
*obstack
,
11644 struct dwarf2_cu
*cu
,
11645 long *value
, gdb_byte
**bytes
,
11646 struct dwarf2_locexpr_baton
**baton
)
11648 struct objfile
*objfile
= cu
->objfile
;
11649 struct comp_unit_head
*cu_header
= &cu
->header
;
11650 struct dwarf_block
*blk
;
11651 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
11652 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
11658 switch (attr
->form
)
11664 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
11665 dwarf2_const_value_length_mismatch_complaint (name
,
11666 cu_header
->addr_size
,
11667 TYPE_LENGTH (type
));
11668 /* Symbols of this form are reasonably rare, so we just
11669 piggyback on the existing location code rather than writing
11670 a new implementation of symbol_computed_ops. */
11671 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11672 sizeof (struct dwarf2_locexpr_baton
));
11673 (*baton
)->per_cu
= cu
->per_cu
;
11674 gdb_assert ((*baton
)->per_cu
);
11676 (*baton
)->size
= 2 + cu_header
->addr_size
;
11677 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11678 (*baton
)->data
= data
;
11680 data
[0] = DW_OP_addr
;
11681 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11682 byte_order
, DW_ADDR (attr
));
11683 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11686 case DW_FORM_string
:
11688 /* DW_STRING is already allocated on the objfile obstack, point
11690 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11692 case DW_FORM_block1
:
11693 case DW_FORM_block2
:
11694 case DW_FORM_block4
:
11695 case DW_FORM_block
:
11696 case DW_FORM_exprloc
:
11697 blk
= DW_BLOCK (attr
);
11698 if (TYPE_LENGTH (type
) != blk
->size
)
11699 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11700 TYPE_LENGTH (type
));
11701 *bytes
= blk
->data
;
11704 /* The DW_AT_const_value attributes are supposed to carry the
11705 symbol's value "represented as it would be on the target
11706 architecture." By the time we get here, it's already been
11707 converted to host endianness, so we just need to sign- or
11708 zero-extend it as appropriate. */
11709 case DW_FORM_data1
:
11710 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11711 obstack
, cu
, value
, 8);
11713 case DW_FORM_data2
:
11714 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11715 obstack
, cu
, value
, 16);
11717 case DW_FORM_data4
:
11718 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11719 obstack
, cu
, value
, 32);
11721 case DW_FORM_data8
:
11722 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11723 obstack
, cu
, value
, 64);
11726 case DW_FORM_sdata
:
11727 *value
= DW_SND (attr
);
11730 case DW_FORM_udata
:
11731 *value
= DW_UNSND (attr
);
11735 complaint (&symfile_complaints
,
11736 _("unsupported const value attribute form: '%s'"),
11737 dwarf_form_name (attr
->form
));
11744 /* Copy constant value from an attribute to a symbol. */
11747 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11748 struct dwarf2_cu
*cu
)
11750 struct objfile
*objfile
= cu
->objfile
;
11751 struct comp_unit_head
*cu_header
= &cu
->header
;
11754 struct dwarf2_locexpr_baton
*baton
;
11756 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11757 SYMBOL_PRINT_NAME (sym
),
11758 &objfile
->objfile_obstack
, cu
,
11759 &value
, &bytes
, &baton
);
11763 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11764 SYMBOL_LOCATION_BATON (sym
) = baton
;
11765 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11767 else if (bytes
!= NULL
)
11769 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11770 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11774 SYMBOL_VALUE (sym
) = value
;
11775 SYMBOL_CLASS (sym
) = LOC_CONST
;
11779 /* Return the type of the die in question using its DW_AT_type attribute. */
11781 static struct type
*
11782 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11784 struct attribute
*type_attr
;
11786 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11789 /* A missing DW_AT_type represents a void type. */
11790 return objfile_type (cu
->objfile
)->builtin_void
;
11793 return lookup_die_type (die
, type_attr
, cu
);
11796 /* True iff CU's producer generates GNAT Ada auxiliary information
11797 that allows to find parallel types through that information instead
11798 of having to do expensive parallel lookups by type name. */
11801 need_gnat_info (struct dwarf2_cu
*cu
)
11803 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11804 of GNAT produces this auxiliary information, without any indication
11805 that it is produced. Part of enhancing the FSF version of GNAT
11806 to produce that information will be to put in place an indicator
11807 that we can use in order to determine whether the descriptive type
11808 info is available or not. One suggestion that has been made is
11809 to use a new attribute, attached to the CU die. For now, assume
11810 that the descriptive type info is not available. */
11814 /* Return the auxiliary type of the die in question using its
11815 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11816 attribute is not present. */
11818 static struct type
*
11819 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11821 struct attribute
*type_attr
;
11823 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11827 return lookup_die_type (die
, type_attr
, cu
);
11830 /* If DIE has a descriptive_type attribute, then set the TYPE's
11831 descriptive type accordingly. */
11834 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11835 struct dwarf2_cu
*cu
)
11837 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11839 if (descriptive_type
)
11841 ALLOCATE_GNAT_AUX_TYPE (type
);
11842 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11846 /* Return the containing type of the die in question using its
11847 DW_AT_containing_type attribute. */
11849 static struct type
*
11850 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11852 struct attribute
*type_attr
;
11854 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11856 error (_("Dwarf Error: Problem turning containing type into gdb type "
11857 "[in module %s]"), cu
->objfile
->name
);
11859 return lookup_die_type (die
, type_attr
, cu
);
11862 /* Look up the type of DIE in CU using its type attribute ATTR.
11863 If there is no type substitute an error marker. */
11865 static struct type
*
11866 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11867 struct dwarf2_cu
*cu
)
11869 struct type
*this_type
;
11871 /* First see if we have it cached. */
11873 if (is_ref_attr (attr
))
11875 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11877 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11879 else if (attr
->form
== DW_FORM_ref_sig8
)
11881 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11882 struct dwarf2_cu
*sig_cu
;
11883 unsigned int offset
;
11885 /* sig_type will be NULL if the signatured type is missing from
11887 if (sig_type
== NULL
)
11888 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11889 "at 0x%x [in module %s]"),
11890 die
->offset
, cu
->objfile
->name
);
11892 gdb_assert (sig_type
->per_cu
.from_debug_types
);
11893 offset
= sig_type
->per_cu
.offset
+ sig_type
->type_offset
;
11894 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11898 dump_die_for_error (die
);
11899 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11900 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11903 /* If not cached we need to read it in. */
11905 if (this_type
== NULL
)
11907 struct die_info
*type_die
;
11908 struct dwarf2_cu
*type_cu
= cu
;
11910 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11911 /* If the type is cached, we should have found it above. */
11912 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
11913 this_type
= read_type_die_1 (type_die
, type_cu
);
11916 /* If we still don't have a type use an error marker. */
11918 if (this_type
== NULL
)
11920 char *message
, *saved
;
11922 /* read_type_die already issued a complaint. */
11923 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11927 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
11928 message
, strlen (message
));
11931 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
11937 /* Return the type in DIE, CU.
11938 Returns NULL for invalid types.
11940 This first does a lookup in the appropriate type_hash table,
11941 and only reads the die in if necessary.
11943 NOTE: This can be called when reading in partial or full symbols. */
11945 static struct type
*
11946 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11948 struct type
*this_type
;
11950 this_type
= get_die_type (die
, cu
);
11954 return read_type_die_1 (die
, cu
);
11957 /* Read the type in DIE, CU.
11958 Returns NULL for invalid types. */
11960 static struct type
*
11961 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
11963 struct type
*this_type
= NULL
;
11967 case DW_TAG_class_type
:
11968 case DW_TAG_interface_type
:
11969 case DW_TAG_structure_type
:
11970 case DW_TAG_union_type
:
11971 this_type
= read_structure_type (die
, cu
);
11973 case DW_TAG_enumeration_type
:
11974 this_type
= read_enumeration_type (die
, cu
);
11976 case DW_TAG_subprogram
:
11977 case DW_TAG_subroutine_type
:
11978 case DW_TAG_inlined_subroutine
:
11979 this_type
= read_subroutine_type (die
, cu
);
11981 case DW_TAG_array_type
:
11982 this_type
= read_array_type (die
, cu
);
11984 case DW_TAG_set_type
:
11985 this_type
= read_set_type (die
, cu
);
11987 case DW_TAG_pointer_type
:
11988 this_type
= read_tag_pointer_type (die
, cu
);
11990 case DW_TAG_ptr_to_member_type
:
11991 this_type
= read_tag_ptr_to_member_type (die
, cu
);
11993 case DW_TAG_reference_type
:
11994 this_type
= read_tag_reference_type (die
, cu
);
11996 case DW_TAG_const_type
:
11997 this_type
= read_tag_const_type (die
, cu
);
11999 case DW_TAG_volatile_type
:
12000 this_type
= read_tag_volatile_type (die
, cu
);
12002 case DW_TAG_string_type
:
12003 this_type
= read_tag_string_type (die
, cu
);
12005 case DW_TAG_typedef
:
12006 this_type
= read_typedef (die
, cu
);
12008 case DW_TAG_subrange_type
:
12009 this_type
= read_subrange_type (die
, cu
);
12011 case DW_TAG_base_type
:
12012 this_type
= read_base_type (die
, cu
);
12014 case DW_TAG_unspecified_type
:
12015 this_type
= read_unspecified_type (die
, cu
);
12017 case DW_TAG_namespace
:
12018 this_type
= read_namespace_type (die
, cu
);
12020 case DW_TAG_module
:
12021 this_type
= read_module_type (die
, cu
);
12024 complaint (&symfile_complaints
,
12025 _("unexpected tag in read_type_die: '%s'"),
12026 dwarf_tag_name (die
->tag
));
12033 /* See if we can figure out if the class lives in a namespace. We do
12034 this by looking for a member function; its demangled name will
12035 contain namespace info, if there is any.
12036 Return the computed name or NULL.
12037 Space for the result is allocated on the objfile's obstack.
12038 This is the full-die version of guess_partial_die_structure_name.
12039 In this case we know DIE has no useful parent. */
12042 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12044 struct die_info
*spec_die
;
12045 struct dwarf2_cu
*spec_cu
;
12046 struct die_info
*child
;
12049 spec_die
= die_specification (die
, &spec_cu
);
12050 if (spec_die
!= NULL
)
12056 for (child
= die
->child
;
12058 child
= child
->sibling
)
12060 if (child
->tag
== DW_TAG_subprogram
)
12062 struct attribute
*attr
;
12064 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12066 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12070 = language_class_name_from_physname (cu
->language_defn
,
12074 if (actual_name
!= NULL
)
12076 char *die_name
= dwarf2_name (die
, cu
);
12078 if (die_name
!= NULL
12079 && strcmp (die_name
, actual_name
) != 0)
12081 /* Strip off the class name from the full name.
12082 We want the prefix. */
12083 int die_name_len
= strlen (die_name
);
12084 int actual_name_len
= strlen (actual_name
);
12086 /* Test for '::' as a sanity check. */
12087 if (actual_name_len
> die_name_len
+ 2
12088 && actual_name
[actual_name_len
12089 - die_name_len
- 1] == ':')
12091 obsavestring (actual_name
,
12092 actual_name_len
- die_name_len
- 2,
12093 &cu
->objfile
->objfile_obstack
);
12096 xfree (actual_name
);
12105 /* Return the name of the namespace/class that DIE is defined within,
12106 or "" if we can't tell. The caller should not xfree the result.
12108 For example, if we're within the method foo() in the following
12118 then determine_prefix on foo's die will return "N::C". */
12121 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12123 struct die_info
*parent
, *spec_die
;
12124 struct dwarf2_cu
*spec_cu
;
12125 struct type
*parent_type
;
12127 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12128 && cu
->language
!= language_fortran
)
12131 /* We have to be careful in the presence of DW_AT_specification.
12132 For example, with GCC 3.4, given the code
12136 // Definition of N::foo.
12140 then we'll have a tree of DIEs like this:
12142 1: DW_TAG_compile_unit
12143 2: DW_TAG_namespace // N
12144 3: DW_TAG_subprogram // declaration of N::foo
12145 4: DW_TAG_subprogram // definition of N::foo
12146 DW_AT_specification // refers to die #3
12148 Thus, when processing die #4, we have to pretend that we're in
12149 the context of its DW_AT_specification, namely the contex of die
12152 spec_die
= die_specification (die
, &spec_cu
);
12153 if (spec_die
== NULL
)
12154 parent
= die
->parent
;
12157 parent
= spec_die
->parent
;
12161 if (parent
== NULL
)
12163 else if (parent
->building_fullname
)
12166 const char *parent_name
;
12168 /* It has been seen on RealView 2.2 built binaries,
12169 DW_TAG_template_type_param types actually _defined_ as
12170 children of the parent class:
12173 template class <class Enum> Class{};
12174 Class<enum E> class_e;
12176 1: DW_TAG_class_type (Class)
12177 2: DW_TAG_enumeration_type (E)
12178 3: DW_TAG_enumerator (enum1:0)
12179 3: DW_TAG_enumerator (enum2:1)
12181 2: DW_TAG_template_type_param
12182 DW_AT_type DW_FORM_ref_udata (E)
12184 Besides being broken debug info, it can put GDB into an
12185 infinite loop. Consider:
12187 When we're building the full name for Class<E>, we'll start
12188 at Class, and go look over its template type parameters,
12189 finding E. We'll then try to build the full name of E, and
12190 reach here. We're now trying to build the full name of E,
12191 and look over the parent DIE for containing scope. In the
12192 broken case, if we followed the parent DIE of E, we'd again
12193 find Class, and once again go look at its template type
12194 arguments, etc., etc. Simply don't consider such parent die
12195 as source-level parent of this die (it can't be, the language
12196 doesn't allow it), and break the loop here. */
12197 name
= dwarf2_name (die
, cu
);
12198 parent_name
= dwarf2_name (parent
, cu
);
12199 complaint (&symfile_complaints
,
12200 _("template param type '%s' defined within parent '%s'"),
12201 name
? name
: "<unknown>",
12202 parent_name
? parent_name
: "<unknown>");
12206 switch (parent
->tag
)
12208 case DW_TAG_namespace
:
12209 parent_type
= read_type_die (parent
, cu
);
12210 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12211 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12212 Work around this problem here. */
12213 if (cu
->language
== language_cplus
12214 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12216 /* We give a name to even anonymous namespaces. */
12217 return TYPE_TAG_NAME (parent_type
);
12218 case DW_TAG_class_type
:
12219 case DW_TAG_interface_type
:
12220 case DW_TAG_structure_type
:
12221 case DW_TAG_union_type
:
12222 case DW_TAG_module
:
12223 parent_type
= read_type_die (parent
, cu
);
12224 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12225 return TYPE_TAG_NAME (parent_type
);
12227 /* An anonymous structure is only allowed non-static data
12228 members; no typedefs, no member functions, et cetera.
12229 So it does not need a prefix. */
12231 case DW_TAG_compile_unit
:
12232 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12233 if (cu
->language
== language_cplus
12234 && dwarf2_per_objfile
->types
.asection
!= NULL
12235 && die
->child
!= NULL
12236 && (die
->tag
== DW_TAG_class_type
12237 || die
->tag
== DW_TAG_structure_type
12238 || die
->tag
== DW_TAG_union_type
))
12240 char *name
= guess_full_die_structure_name (die
, cu
);
12246 return determine_prefix (parent
, cu
);
12250 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12251 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12252 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12253 an obconcat, otherwise allocate storage for the result. The CU argument is
12254 used to determine the language and hence, the appropriate separator. */
12256 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12259 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12260 int physname
, struct dwarf2_cu
*cu
)
12262 const char *lead
= "";
12265 if (suffix
== NULL
|| suffix
[0] == '\0'
12266 || prefix
== NULL
|| prefix
[0] == '\0')
12268 else if (cu
->language
== language_java
)
12270 else if (cu
->language
== language_fortran
&& physname
)
12272 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12273 DW_AT_MIPS_linkage_name is preferred and used instead. */
12281 if (prefix
== NULL
)
12283 if (suffix
== NULL
)
12289 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12291 strcpy (retval
, lead
);
12292 strcat (retval
, prefix
);
12293 strcat (retval
, sep
);
12294 strcat (retval
, suffix
);
12299 /* We have an obstack. */
12300 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12304 /* Return sibling of die, NULL if no sibling. */
12306 static struct die_info
*
12307 sibling_die (struct die_info
*die
)
12309 return die
->sibling
;
12312 /* Get name of a die, return NULL if not found. */
12315 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12316 struct obstack
*obstack
)
12318 if (name
&& cu
->language
== language_cplus
)
12320 char *canon_name
= cp_canonicalize_string (name
);
12322 if (canon_name
!= NULL
)
12324 if (strcmp (canon_name
, name
) != 0)
12325 name
= obsavestring (canon_name
, strlen (canon_name
),
12327 xfree (canon_name
);
12334 /* Get name of a die, return NULL if not found. */
12337 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12339 struct attribute
*attr
;
12341 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12342 if ((!attr
|| !DW_STRING (attr
))
12343 && die
->tag
!= DW_TAG_class_type
12344 && die
->tag
!= DW_TAG_interface_type
12345 && die
->tag
!= DW_TAG_structure_type
12346 && die
->tag
!= DW_TAG_union_type
)
12351 case DW_TAG_compile_unit
:
12352 /* Compilation units have a DW_AT_name that is a filename, not
12353 a source language identifier. */
12354 case DW_TAG_enumeration_type
:
12355 case DW_TAG_enumerator
:
12356 /* These tags always have simple identifiers already; no need
12357 to canonicalize them. */
12358 return DW_STRING (attr
);
12360 case DW_TAG_subprogram
:
12361 /* Java constructors will all be named "<init>", so return
12362 the class name when we see this special case. */
12363 if (cu
->language
== language_java
12364 && DW_STRING (attr
) != NULL
12365 && strcmp (DW_STRING (attr
), "<init>") == 0)
12367 struct dwarf2_cu
*spec_cu
= cu
;
12368 struct die_info
*spec_die
;
12370 /* GCJ will output '<init>' for Java constructor names.
12371 For this special case, return the name of the parent class. */
12373 /* GCJ may output suprogram DIEs with AT_specification set.
12374 If so, use the name of the specified DIE. */
12375 spec_die
= die_specification (die
, &spec_cu
);
12376 if (spec_die
!= NULL
)
12377 return dwarf2_name (spec_die
, spec_cu
);
12382 if (die
->tag
== DW_TAG_class_type
)
12383 return dwarf2_name (die
, cu
);
12385 while (die
->tag
!= DW_TAG_compile_unit
);
12389 case DW_TAG_class_type
:
12390 case DW_TAG_interface_type
:
12391 case DW_TAG_structure_type
:
12392 case DW_TAG_union_type
:
12393 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12394 structures or unions. These were of the form "._%d" in GCC 4.1,
12395 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12396 and GCC 4.4. We work around this problem by ignoring these. */
12397 if (attr
&& DW_STRING (attr
)
12398 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12399 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12402 /* GCC might emit a nameless typedef that has a linkage name. See
12403 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12404 if (!attr
|| DW_STRING (attr
) == NULL
)
12406 char *demangled
= NULL
;
12408 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12410 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12412 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12415 /* Avoid demangling DW_STRING (attr) the second time on a second
12416 call for the same DIE. */
12417 if (!DW_STRING_IS_CANONICAL (attr
))
12418 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12422 /* FIXME: we already did this for the partial symbol... */
12424 = obsavestring (demangled
, strlen (demangled
),
12425 &cu
->objfile
->objfile_obstack
);
12426 DW_STRING_IS_CANONICAL (attr
) = 1;
12436 if (!DW_STRING_IS_CANONICAL (attr
))
12439 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12440 &cu
->objfile
->objfile_obstack
);
12441 DW_STRING_IS_CANONICAL (attr
) = 1;
12443 return DW_STRING (attr
);
12446 /* Return the die that this die in an extension of, or NULL if there
12447 is none. *EXT_CU is the CU containing DIE on input, and the CU
12448 containing the return value on output. */
12450 static struct die_info
*
12451 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12453 struct attribute
*attr
;
12455 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12459 return follow_die_ref (die
, attr
, ext_cu
);
12462 /* Convert a DIE tag into its string name. */
12465 dwarf_tag_name (unsigned tag
)
12469 case DW_TAG_padding
:
12470 return "DW_TAG_padding";
12471 case DW_TAG_array_type
:
12472 return "DW_TAG_array_type";
12473 case DW_TAG_class_type
:
12474 return "DW_TAG_class_type";
12475 case DW_TAG_entry_point
:
12476 return "DW_TAG_entry_point";
12477 case DW_TAG_enumeration_type
:
12478 return "DW_TAG_enumeration_type";
12479 case DW_TAG_formal_parameter
:
12480 return "DW_TAG_formal_parameter";
12481 case DW_TAG_imported_declaration
:
12482 return "DW_TAG_imported_declaration";
12484 return "DW_TAG_label";
12485 case DW_TAG_lexical_block
:
12486 return "DW_TAG_lexical_block";
12487 case DW_TAG_member
:
12488 return "DW_TAG_member";
12489 case DW_TAG_pointer_type
:
12490 return "DW_TAG_pointer_type";
12491 case DW_TAG_reference_type
:
12492 return "DW_TAG_reference_type";
12493 case DW_TAG_compile_unit
:
12494 return "DW_TAG_compile_unit";
12495 case DW_TAG_string_type
:
12496 return "DW_TAG_string_type";
12497 case DW_TAG_structure_type
:
12498 return "DW_TAG_structure_type";
12499 case DW_TAG_subroutine_type
:
12500 return "DW_TAG_subroutine_type";
12501 case DW_TAG_typedef
:
12502 return "DW_TAG_typedef";
12503 case DW_TAG_union_type
:
12504 return "DW_TAG_union_type";
12505 case DW_TAG_unspecified_parameters
:
12506 return "DW_TAG_unspecified_parameters";
12507 case DW_TAG_variant
:
12508 return "DW_TAG_variant";
12509 case DW_TAG_common_block
:
12510 return "DW_TAG_common_block";
12511 case DW_TAG_common_inclusion
:
12512 return "DW_TAG_common_inclusion";
12513 case DW_TAG_inheritance
:
12514 return "DW_TAG_inheritance";
12515 case DW_TAG_inlined_subroutine
:
12516 return "DW_TAG_inlined_subroutine";
12517 case DW_TAG_module
:
12518 return "DW_TAG_module";
12519 case DW_TAG_ptr_to_member_type
:
12520 return "DW_TAG_ptr_to_member_type";
12521 case DW_TAG_set_type
:
12522 return "DW_TAG_set_type";
12523 case DW_TAG_subrange_type
:
12524 return "DW_TAG_subrange_type";
12525 case DW_TAG_with_stmt
:
12526 return "DW_TAG_with_stmt";
12527 case DW_TAG_access_declaration
:
12528 return "DW_TAG_access_declaration";
12529 case DW_TAG_base_type
:
12530 return "DW_TAG_base_type";
12531 case DW_TAG_catch_block
:
12532 return "DW_TAG_catch_block";
12533 case DW_TAG_const_type
:
12534 return "DW_TAG_const_type";
12535 case DW_TAG_constant
:
12536 return "DW_TAG_constant";
12537 case DW_TAG_enumerator
:
12538 return "DW_TAG_enumerator";
12539 case DW_TAG_file_type
:
12540 return "DW_TAG_file_type";
12541 case DW_TAG_friend
:
12542 return "DW_TAG_friend";
12543 case DW_TAG_namelist
:
12544 return "DW_TAG_namelist";
12545 case DW_TAG_namelist_item
:
12546 return "DW_TAG_namelist_item";
12547 case DW_TAG_packed_type
:
12548 return "DW_TAG_packed_type";
12549 case DW_TAG_subprogram
:
12550 return "DW_TAG_subprogram";
12551 case DW_TAG_template_type_param
:
12552 return "DW_TAG_template_type_param";
12553 case DW_TAG_template_value_param
:
12554 return "DW_TAG_template_value_param";
12555 case DW_TAG_thrown_type
:
12556 return "DW_TAG_thrown_type";
12557 case DW_TAG_try_block
:
12558 return "DW_TAG_try_block";
12559 case DW_TAG_variant_part
:
12560 return "DW_TAG_variant_part";
12561 case DW_TAG_variable
:
12562 return "DW_TAG_variable";
12563 case DW_TAG_volatile_type
:
12564 return "DW_TAG_volatile_type";
12565 case DW_TAG_dwarf_procedure
:
12566 return "DW_TAG_dwarf_procedure";
12567 case DW_TAG_restrict_type
:
12568 return "DW_TAG_restrict_type";
12569 case DW_TAG_interface_type
:
12570 return "DW_TAG_interface_type";
12571 case DW_TAG_namespace
:
12572 return "DW_TAG_namespace";
12573 case DW_TAG_imported_module
:
12574 return "DW_TAG_imported_module";
12575 case DW_TAG_unspecified_type
:
12576 return "DW_TAG_unspecified_type";
12577 case DW_TAG_partial_unit
:
12578 return "DW_TAG_partial_unit";
12579 case DW_TAG_imported_unit
:
12580 return "DW_TAG_imported_unit";
12581 case DW_TAG_condition
:
12582 return "DW_TAG_condition";
12583 case DW_TAG_shared_type
:
12584 return "DW_TAG_shared_type";
12585 case DW_TAG_type_unit
:
12586 return "DW_TAG_type_unit";
12587 case DW_TAG_MIPS_loop
:
12588 return "DW_TAG_MIPS_loop";
12589 case DW_TAG_HP_array_descriptor
:
12590 return "DW_TAG_HP_array_descriptor";
12591 case DW_TAG_format_label
:
12592 return "DW_TAG_format_label";
12593 case DW_TAG_function_template
:
12594 return "DW_TAG_function_template";
12595 case DW_TAG_class_template
:
12596 return "DW_TAG_class_template";
12597 case DW_TAG_GNU_BINCL
:
12598 return "DW_TAG_GNU_BINCL";
12599 case DW_TAG_GNU_EINCL
:
12600 return "DW_TAG_GNU_EINCL";
12601 case DW_TAG_upc_shared_type
:
12602 return "DW_TAG_upc_shared_type";
12603 case DW_TAG_upc_strict_type
:
12604 return "DW_TAG_upc_strict_type";
12605 case DW_TAG_upc_relaxed_type
:
12606 return "DW_TAG_upc_relaxed_type";
12607 case DW_TAG_PGI_kanji_type
:
12608 return "DW_TAG_PGI_kanji_type";
12609 case DW_TAG_PGI_interface_block
:
12610 return "DW_TAG_PGI_interface_block";
12612 return "DW_TAG_<unknown>";
12616 /* Convert a DWARF attribute code into its string name. */
12619 dwarf_attr_name (unsigned attr
)
12623 case DW_AT_sibling
:
12624 return "DW_AT_sibling";
12625 case DW_AT_location
:
12626 return "DW_AT_location";
12628 return "DW_AT_name";
12629 case DW_AT_ordering
:
12630 return "DW_AT_ordering";
12631 case DW_AT_subscr_data
:
12632 return "DW_AT_subscr_data";
12633 case DW_AT_byte_size
:
12634 return "DW_AT_byte_size";
12635 case DW_AT_bit_offset
:
12636 return "DW_AT_bit_offset";
12637 case DW_AT_bit_size
:
12638 return "DW_AT_bit_size";
12639 case DW_AT_element_list
:
12640 return "DW_AT_element_list";
12641 case DW_AT_stmt_list
:
12642 return "DW_AT_stmt_list";
12644 return "DW_AT_low_pc";
12645 case DW_AT_high_pc
:
12646 return "DW_AT_high_pc";
12647 case DW_AT_language
:
12648 return "DW_AT_language";
12650 return "DW_AT_member";
12652 return "DW_AT_discr";
12653 case DW_AT_discr_value
:
12654 return "DW_AT_discr_value";
12655 case DW_AT_visibility
:
12656 return "DW_AT_visibility";
12658 return "DW_AT_import";
12659 case DW_AT_string_length
:
12660 return "DW_AT_string_length";
12661 case DW_AT_common_reference
:
12662 return "DW_AT_common_reference";
12663 case DW_AT_comp_dir
:
12664 return "DW_AT_comp_dir";
12665 case DW_AT_const_value
:
12666 return "DW_AT_const_value";
12667 case DW_AT_containing_type
:
12668 return "DW_AT_containing_type";
12669 case DW_AT_default_value
:
12670 return "DW_AT_default_value";
12672 return "DW_AT_inline";
12673 case DW_AT_is_optional
:
12674 return "DW_AT_is_optional";
12675 case DW_AT_lower_bound
:
12676 return "DW_AT_lower_bound";
12677 case DW_AT_producer
:
12678 return "DW_AT_producer";
12679 case DW_AT_prototyped
:
12680 return "DW_AT_prototyped";
12681 case DW_AT_return_addr
:
12682 return "DW_AT_return_addr";
12683 case DW_AT_start_scope
:
12684 return "DW_AT_start_scope";
12685 case DW_AT_bit_stride
:
12686 return "DW_AT_bit_stride";
12687 case DW_AT_upper_bound
:
12688 return "DW_AT_upper_bound";
12689 case DW_AT_abstract_origin
:
12690 return "DW_AT_abstract_origin";
12691 case DW_AT_accessibility
:
12692 return "DW_AT_accessibility";
12693 case DW_AT_address_class
:
12694 return "DW_AT_address_class";
12695 case DW_AT_artificial
:
12696 return "DW_AT_artificial";
12697 case DW_AT_base_types
:
12698 return "DW_AT_base_types";
12699 case DW_AT_calling_convention
:
12700 return "DW_AT_calling_convention";
12702 return "DW_AT_count";
12703 case DW_AT_data_member_location
:
12704 return "DW_AT_data_member_location";
12705 case DW_AT_decl_column
:
12706 return "DW_AT_decl_column";
12707 case DW_AT_decl_file
:
12708 return "DW_AT_decl_file";
12709 case DW_AT_decl_line
:
12710 return "DW_AT_decl_line";
12711 case DW_AT_declaration
:
12712 return "DW_AT_declaration";
12713 case DW_AT_discr_list
:
12714 return "DW_AT_discr_list";
12715 case DW_AT_encoding
:
12716 return "DW_AT_encoding";
12717 case DW_AT_external
:
12718 return "DW_AT_external";
12719 case DW_AT_frame_base
:
12720 return "DW_AT_frame_base";
12722 return "DW_AT_friend";
12723 case DW_AT_identifier_case
:
12724 return "DW_AT_identifier_case";
12725 case DW_AT_macro_info
:
12726 return "DW_AT_macro_info";
12727 case DW_AT_namelist_items
:
12728 return "DW_AT_namelist_items";
12729 case DW_AT_priority
:
12730 return "DW_AT_priority";
12731 case DW_AT_segment
:
12732 return "DW_AT_segment";
12733 case DW_AT_specification
:
12734 return "DW_AT_specification";
12735 case DW_AT_static_link
:
12736 return "DW_AT_static_link";
12738 return "DW_AT_type";
12739 case DW_AT_use_location
:
12740 return "DW_AT_use_location";
12741 case DW_AT_variable_parameter
:
12742 return "DW_AT_variable_parameter";
12743 case DW_AT_virtuality
:
12744 return "DW_AT_virtuality";
12745 case DW_AT_vtable_elem_location
:
12746 return "DW_AT_vtable_elem_location";
12747 /* DWARF 3 values. */
12748 case DW_AT_allocated
:
12749 return "DW_AT_allocated";
12750 case DW_AT_associated
:
12751 return "DW_AT_associated";
12752 case DW_AT_data_location
:
12753 return "DW_AT_data_location";
12754 case DW_AT_byte_stride
:
12755 return "DW_AT_byte_stride";
12756 case DW_AT_entry_pc
:
12757 return "DW_AT_entry_pc";
12758 case DW_AT_use_UTF8
:
12759 return "DW_AT_use_UTF8";
12760 case DW_AT_extension
:
12761 return "DW_AT_extension";
12763 return "DW_AT_ranges";
12764 case DW_AT_trampoline
:
12765 return "DW_AT_trampoline";
12766 case DW_AT_call_column
:
12767 return "DW_AT_call_column";
12768 case DW_AT_call_file
:
12769 return "DW_AT_call_file";
12770 case DW_AT_call_line
:
12771 return "DW_AT_call_line";
12772 case DW_AT_description
:
12773 return "DW_AT_description";
12774 case DW_AT_binary_scale
:
12775 return "DW_AT_binary_scale";
12776 case DW_AT_decimal_scale
:
12777 return "DW_AT_decimal_scale";
12779 return "DW_AT_small";
12780 case DW_AT_decimal_sign
:
12781 return "DW_AT_decimal_sign";
12782 case DW_AT_digit_count
:
12783 return "DW_AT_digit_count";
12784 case DW_AT_picture_string
:
12785 return "DW_AT_picture_string";
12786 case DW_AT_mutable
:
12787 return "DW_AT_mutable";
12788 case DW_AT_threads_scaled
:
12789 return "DW_AT_threads_scaled";
12790 case DW_AT_explicit
:
12791 return "DW_AT_explicit";
12792 case DW_AT_object_pointer
:
12793 return "DW_AT_object_pointer";
12794 case DW_AT_endianity
:
12795 return "DW_AT_endianity";
12796 case DW_AT_elemental
:
12797 return "DW_AT_elemental";
12799 return "DW_AT_pure";
12800 case DW_AT_recursive
:
12801 return "DW_AT_recursive";
12802 /* DWARF 4 values. */
12803 case DW_AT_signature
:
12804 return "DW_AT_signature";
12805 case DW_AT_linkage_name
:
12806 return "DW_AT_linkage_name";
12807 /* SGI/MIPS extensions. */
12808 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12809 case DW_AT_MIPS_fde
:
12810 return "DW_AT_MIPS_fde";
12812 case DW_AT_MIPS_loop_begin
:
12813 return "DW_AT_MIPS_loop_begin";
12814 case DW_AT_MIPS_tail_loop_begin
:
12815 return "DW_AT_MIPS_tail_loop_begin";
12816 case DW_AT_MIPS_epilog_begin
:
12817 return "DW_AT_MIPS_epilog_begin";
12818 case DW_AT_MIPS_loop_unroll_factor
:
12819 return "DW_AT_MIPS_loop_unroll_factor";
12820 case DW_AT_MIPS_software_pipeline_depth
:
12821 return "DW_AT_MIPS_software_pipeline_depth";
12822 case DW_AT_MIPS_linkage_name
:
12823 return "DW_AT_MIPS_linkage_name";
12824 case DW_AT_MIPS_stride
:
12825 return "DW_AT_MIPS_stride";
12826 case DW_AT_MIPS_abstract_name
:
12827 return "DW_AT_MIPS_abstract_name";
12828 case DW_AT_MIPS_clone_origin
:
12829 return "DW_AT_MIPS_clone_origin";
12830 case DW_AT_MIPS_has_inlines
:
12831 return "DW_AT_MIPS_has_inlines";
12832 /* HP extensions. */
12833 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12834 case DW_AT_HP_block_index
:
12835 return "DW_AT_HP_block_index";
12837 case DW_AT_HP_unmodifiable
:
12838 return "DW_AT_HP_unmodifiable";
12839 case DW_AT_HP_actuals_stmt_list
:
12840 return "DW_AT_HP_actuals_stmt_list";
12841 case DW_AT_HP_proc_per_section
:
12842 return "DW_AT_HP_proc_per_section";
12843 case DW_AT_HP_raw_data_ptr
:
12844 return "DW_AT_HP_raw_data_ptr";
12845 case DW_AT_HP_pass_by_reference
:
12846 return "DW_AT_HP_pass_by_reference";
12847 case DW_AT_HP_opt_level
:
12848 return "DW_AT_HP_opt_level";
12849 case DW_AT_HP_prof_version_id
:
12850 return "DW_AT_HP_prof_version_id";
12851 case DW_AT_HP_opt_flags
:
12852 return "DW_AT_HP_opt_flags";
12853 case DW_AT_HP_cold_region_low_pc
:
12854 return "DW_AT_HP_cold_region_low_pc";
12855 case DW_AT_HP_cold_region_high_pc
:
12856 return "DW_AT_HP_cold_region_high_pc";
12857 case DW_AT_HP_all_variables_modifiable
:
12858 return "DW_AT_HP_all_variables_modifiable";
12859 case DW_AT_HP_linkage_name
:
12860 return "DW_AT_HP_linkage_name";
12861 case DW_AT_HP_prof_flags
:
12862 return "DW_AT_HP_prof_flags";
12863 /* GNU extensions. */
12864 case DW_AT_sf_names
:
12865 return "DW_AT_sf_names";
12866 case DW_AT_src_info
:
12867 return "DW_AT_src_info";
12868 case DW_AT_mac_info
:
12869 return "DW_AT_mac_info";
12870 case DW_AT_src_coords
:
12871 return "DW_AT_src_coords";
12872 case DW_AT_body_begin
:
12873 return "DW_AT_body_begin";
12874 case DW_AT_body_end
:
12875 return "DW_AT_body_end";
12876 case DW_AT_GNU_vector
:
12877 return "DW_AT_GNU_vector";
12878 case DW_AT_GNU_odr_signature
:
12879 return "DW_AT_GNU_odr_signature";
12880 /* VMS extensions. */
12881 case DW_AT_VMS_rtnbeg_pd_address
:
12882 return "DW_AT_VMS_rtnbeg_pd_address";
12883 /* UPC extension. */
12884 case DW_AT_upc_threads_scaled
:
12885 return "DW_AT_upc_threads_scaled";
12886 /* PGI (STMicroelectronics) extensions. */
12887 case DW_AT_PGI_lbase
:
12888 return "DW_AT_PGI_lbase";
12889 case DW_AT_PGI_soffset
:
12890 return "DW_AT_PGI_soffset";
12891 case DW_AT_PGI_lstride
:
12892 return "DW_AT_PGI_lstride";
12894 return "DW_AT_<unknown>";
12898 /* Convert a DWARF value form code into its string name. */
12901 dwarf_form_name (unsigned form
)
12906 return "DW_FORM_addr";
12907 case DW_FORM_block2
:
12908 return "DW_FORM_block2";
12909 case DW_FORM_block4
:
12910 return "DW_FORM_block4";
12911 case DW_FORM_data2
:
12912 return "DW_FORM_data2";
12913 case DW_FORM_data4
:
12914 return "DW_FORM_data4";
12915 case DW_FORM_data8
:
12916 return "DW_FORM_data8";
12917 case DW_FORM_string
:
12918 return "DW_FORM_string";
12919 case DW_FORM_block
:
12920 return "DW_FORM_block";
12921 case DW_FORM_block1
:
12922 return "DW_FORM_block1";
12923 case DW_FORM_data1
:
12924 return "DW_FORM_data1";
12926 return "DW_FORM_flag";
12927 case DW_FORM_sdata
:
12928 return "DW_FORM_sdata";
12930 return "DW_FORM_strp";
12931 case DW_FORM_udata
:
12932 return "DW_FORM_udata";
12933 case DW_FORM_ref_addr
:
12934 return "DW_FORM_ref_addr";
12936 return "DW_FORM_ref1";
12938 return "DW_FORM_ref2";
12940 return "DW_FORM_ref4";
12942 return "DW_FORM_ref8";
12943 case DW_FORM_ref_udata
:
12944 return "DW_FORM_ref_udata";
12945 case DW_FORM_indirect
:
12946 return "DW_FORM_indirect";
12947 case DW_FORM_sec_offset
:
12948 return "DW_FORM_sec_offset";
12949 case DW_FORM_exprloc
:
12950 return "DW_FORM_exprloc";
12951 case DW_FORM_flag_present
:
12952 return "DW_FORM_flag_present";
12953 case DW_FORM_ref_sig8
:
12954 return "DW_FORM_ref_sig8";
12956 return "DW_FORM_<unknown>";
12960 /* Convert a DWARF stack opcode into its string name. */
12963 dwarf_stack_op_name (unsigned op
)
12968 return "DW_OP_addr";
12970 return "DW_OP_deref";
12971 case DW_OP_const1u
:
12972 return "DW_OP_const1u";
12973 case DW_OP_const1s
:
12974 return "DW_OP_const1s";
12975 case DW_OP_const2u
:
12976 return "DW_OP_const2u";
12977 case DW_OP_const2s
:
12978 return "DW_OP_const2s";
12979 case DW_OP_const4u
:
12980 return "DW_OP_const4u";
12981 case DW_OP_const4s
:
12982 return "DW_OP_const4s";
12983 case DW_OP_const8u
:
12984 return "DW_OP_const8u";
12985 case DW_OP_const8s
:
12986 return "DW_OP_const8s";
12988 return "DW_OP_constu";
12990 return "DW_OP_consts";
12992 return "DW_OP_dup";
12994 return "DW_OP_drop";
12996 return "DW_OP_over";
12998 return "DW_OP_pick";
13000 return "DW_OP_swap";
13002 return "DW_OP_rot";
13004 return "DW_OP_xderef";
13006 return "DW_OP_abs";
13008 return "DW_OP_and";
13010 return "DW_OP_div";
13012 return "DW_OP_minus";
13014 return "DW_OP_mod";
13016 return "DW_OP_mul";
13018 return "DW_OP_neg";
13020 return "DW_OP_not";
13024 return "DW_OP_plus";
13025 case DW_OP_plus_uconst
:
13026 return "DW_OP_plus_uconst";
13028 return "DW_OP_shl";
13030 return "DW_OP_shr";
13032 return "DW_OP_shra";
13034 return "DW_OP_xor";
13036 return "DW_OP_bra";
13050 return "DW_OP_skip";
13052 return "DW_OP_lit0";
13054 return "DW_OP_lit1";
13056 return "DW_OP_lit2";
13058 return "DW_OP_lit3";
13060 return "DW_OP_lit4";
13062 return "DW_OP_lit5";
13064 return "DW_OP_lit6";
13066 return "DW_OP_lit7";
13068 return "DW_OP_lit8";
13070 return "DW_OP_lit9";
13072 return "DW_OP_lit10";
13074 return "DW_OP_lit11";
13076 return "DW_OP_lit12";
13078 return "DW_OP_lit13";
13080 return "DW_OP_lit14";
13082 return "DW_OP_lit15";
13084 return "DW_OP_lit16";
13086 return "DW_OP_lit17";
13088 return "DW_OP_lit18";
13090 return "DW_OP_lit19";
13092 return "DW_OP_lit20";
13094 return "DW_OP_lit21";
13096 return "DW_OP_lit22";
13098 return "DW_OP_lit23";
13100 return "DW_OP_lit24";
13102 return "DW_OP_lit25";
13104 return "DW_OP_lit26";
13106 return "DW_OP_lit27";
13108 return "DW_OP_lit28";
13110 return "DW_OP_lit29";
13112 return "DW_OP_lit30";
13114 return "DW_OP_lit31";
13116 return "DW_OP_reg0";
13118 return "DW_OP_reg1";
13120 return "DW_OP_reg2";
13122 return "DW_OP_reg3";
13124 return "DW_OP_reg4";
13126 return "DW_OP_reg5";
13128 return "DW_OP_reg6";
13130 return "DW_OP_reg7";
13132 return "DW_OP_reg8";
13134 return "DW_OP_reg9";
13136 return "DW_OP_reg10";
13138 return "DW_OP_reg11";
13140 return "DW_OP_reg12";
13142 return "DW_OP_reg13";
13144 return "DW_OP_reg14";
13146 return "DW_OP_reg15";
13148 return "DW_OP_reg16";
13150 return "DW_OP_reg17";
13152 return "DW_OP_reg18";
13154 return "DW_OP_reg19";
13156 return "DW_OP_reg20";
13158 return "DW_OP_reg21";
13160 return "DW_OP_reg22";
13162 return "DW_OP_reg23";
13164 return "DW_OP_reg24";
13166 return "DW_OP_reg25";
13168 return "DW_OP_reg26";
13170 return "DW_OP_reg27";
13172 return "DW_OP_reg28";
13174 return "DW_OP_reg29";
13176 return "DW_OP_reg30";
13178 return "DW_OP_reg31";
13180 return "DW_OP_breg0";
13182 return "DW_OP_breg1";
13184 return "DW_OP_breg2";
13186 return "DW_OP_breg3";
13188 return "DW_OP_breg4";
13190 return "DW_OP_breg5";
13192 return "DW_OP_breg6";
13194 return "DW_OP_breg7";
13196 return "DW_OP_breg8";
13198 return "DW_OP_breg9";
13200 return "DW_OP_breg10";
13202 return "DW_OP_breg11";
13204 return "DW_OP_breg12";
13206 return "DW_OP_breg13";
13208 return "DW_OP_breg14";
13210 return "DW_OP_breg15";
13212 return "DW_OP_breg16";
13214 return "DW_OP_breg17";
13216 return "DW_OP_breg18";
13218 return "DW_OP_breg19";
13220 return "DW_OP_breg20";
13222 return "DW_OP_breg21";
13224 return "DW_OP_breg22";
13226 return "DW_OP_breg23";
13228 return "DW_OP_breg24";
13230 return "DW_OP_breg25";
13232 return "DW_OP_breg26";
13234 return "DW_OP_breg27";
13236 return "DW_OP_breg28";
13238 return "DW_OP_breg29";
13240 return "DW_OP_breg30";
13242 return "DW_OP_breg31";
13244 return "DW_OP_regx";
13246 return "DW_OP_fbreg";
13248 return "DW_OP_bregx";
13250 return "DW_OP_piece";
13251 case DW_OP_deref_size
:
13252 return "DW_OP_deref_size";
13253 case DW_OP_xderef_size
:
13254 return "DW_OP_xderef_size";
13256 return "DW_OP_nop";
13257 /* DWARF 3 extensions. */
13258 case DW_OP_push_object_address
:
13259 return "DW_OP_push_object_address";
13261 return "DW_OP_call2";
13263 return "DW_OP_call4";
13264 case DW_OP_call_ref
:
13265 return "DW_OP_call_ref";
13266 case DW_OP_form_tls_address
:
13267 return "DW_OP_form_tls_address";
13268 case DW_OP_call_frame_cfa
:
13269 return "DW_OP_call_frame_cfa";
13270 case DW_OP_bit_piece
:
13271 return "DW_OP_bit_piece";
13272 /* DWARF 4 extensions. */
13273 case DW_OP_implicit_value
:
13274 return "DW_OP_implicit_value";
13275 case DW_OP_stack_value
:
13276 return "DW_OP_stack_value";
13277 /* GNU extensions. */
13278 case DW_OP_GNU_push_tls_address
:
13279 return "DW_OP_GNU_push_tls_address";
13280 case DW_OP_GNU_uninit
:
13281 return "DW_OP_GNU_uninit";
13282 case DW_OP_GNU_implicit_pointer
:
13283 return "DW_OP_GNU_implicit_pointer";
13284 case DW_OP_GNU_entry_value
:
13285 return "DW_OP_GNU_entry_value";
13286 case DW_OP_GNU_const_type
:
13287 return "DW_OP_GNU_const_type";
13288 case DW_OP_GNU_regval_type
:
13289 return "DW_OP_GNU_regval_type";
13290 case DW_OP_GNU_deref_type
:
13291 return "DW_OP_GNU_deref_type";
13292 case DW_OP_GNU_convert
:
13293 return "DW_OP_GNU_convert";
13294 case DW_OP_GNU_reinterpret
:
13295 return "DW_OP_GNU_reinterpret";
13302 dwarf_bool_name (unsigned mybool
)
13310 /* Convert a DWARF type code into its string name. */
13313 dwarf_type_encoding_name (unsigned enc
)
13318 return "DW_ATE_void";
13319 case DW_ATE_address
:
13320 return "DW_ATE_address";
13321 case DW_ATE_boolean
:
13322 return "DW_ATE_boolean";
13323 case DW_ATE_complex_float
:
13324 return "DW_ATE_complex_float";
13326 return "DW_ATE_float";
13327 case DW_ATE_signed
:
13328 return "DW_ATE_signed";
13329 case DW_ATE_signed_char
:
13330 return "DW_ATE_signed_char";
13331 case DW_ATE_unsigned
:
13332 return "DW_ATE_unsigned";
13333 case DW_ATE_unsigned_char
:
13334 return "DW_ATE_unsigned_char";
13336 case DW_ATE_imaginary_float
:
13337 return "DW_ATE_imaginary_float";
13338 case DW_ATE_packed_decimal
:
13339 return "DW_ATE_packed_decimal";
13340 case DW_ATE_numeric_string
:
13341 return "DW_ATE_numeric_string";
13342 case DW_ATE_edited
:
13343 return "DW_ATE_edited";
13344 case DW_ATE_signed_fixed
:
13345 return "DW_ATE_signed_fixed";
13346 case DW_ATE_unsigned_fixed
:
13347 return "DW_ATE_unsigned_fixed";
13348 case DW_ATE_decimal_float
:
13349 return "DW_ATE_decimal_float";
13352 return "DW_ATE_UTF";
13353 /* HP extensions. */
13354 case DW_ATE_HP_float80
:
13355 return "DW_ATE_HP_float80";
13356 case DW_ATE_HP_complex_float80
:
13357 return "DW_ATE_HP_complex_float80";
13358 case DW_ATE_HP_float128
:
13359 return "DW_ATE_HP_float128";
13360 case DW_ATE_HP_complex_float128
:
13361 return "DW_ATE_HP_complex_float128";
13362 case DW_ATE_HP_floathpintel
:
13363 return "DW_ATE_HP_floathpintel";
13364 case DW_ATE_HP_imaginary_float80
:
13365 return "DW_ATE_HP_imaginary_float80";
13366 case DW_ATE_HP_imaginary_float128
:
13367 return "DW_ATE_HP_imaginary_float128";
13369 return "DW_ATE_<unknown>";
13373 /* Convert a DWARF call frame info operation to its string name. */
13377 dwarf_cfi_name (unsigned cfi_opc
)
13381 case DW_CFA_advance_loc
:
13382 return "DW_CFA_advance_loc";
13383 case DW_CFA_offset
:
13384 return "DW_CFA_offset";
13385 case DW_CFA_restore
:
13386 return "DW_CFA_restore";
13388 return "DW_CFA_nop";
13389 case DW_CFA_set_loc
:
13390 return "DW_CFA_set_loc";
13391 case DW_CFA_advance_loc1
:
13392 return "DW_CFA_advance_loc1";
13393 case DW_CFA_advance_loc2
:
13394 return "DW_CFA_advance_loc2";
13395 case DW_CFA_advance_loc4
:
13396 return "DW_CFA_advance_loc4";
13397 case DW_CFA_offset_extended
:
13398 return "DW_CFA_offset_extended";
13399 case DW_CFA_restore_extended
:
13400 return "DW_CFA_restore_extended";
13401 case DW_CFA_undefined
:
13402 return "DW_CFA_undefined";
13403 case DW_CFA_same_value
:
13404 return "DW_CFA_same_value";
13405 case DW_CFA_register
:
13406 return "DW_CFA_register";
13407 case DW_CFA_remember_state
:
13408 return "DW_CFA_remember_state";
13409 case DW_CFA_restore_state
:
13410 return "DW_CFA_restore_state";
13411 case DW_CFA_def_cfa
:
13412 return "DW_CFA_def_cfa";
13413 case DW_CFA_def_cfa_register
:
13414 return "DW_CFA_def_cfa_register";
13415 case DW_CFA_def_cfa_offset
:
13416 return "DW_CFA_def_cfa_offset";
13418 case DW_CFA_def_cfa_expression
:
13419 return "DW_CFA_def_cfa_expression";
13420 case DW_CFA_expression
:
13421 return "DW_CFA_expression";
13422 case DW_CFA_offset_extended_sf
:
13423 return "DW_CFA_offset_extended_sf";
13424 case DW_CFA_def_cfa_sf
:
13425 return "DW_CFA_def_cfa_sf";
13426 case DW_CFA_def_cfa_offset_sf
:
13427 return "DW_CFA_def_cfa_offset_sf";
13428 case DW_CFA_val_offset
:
13429 return "DW_CFA_val_offset";
13430 case DW_CFA_val_offset_sf
:
13431 return "DW_CFA_val_offset_sf";
13432 case DW_CFA_val_expression
:
13433 return "DW_CFA_val_expression";
13434 /* SGI/MIPS specific. */
13435 case DW_CFA_MIPS_advance_loc8
:
13436 return "DW_CFA_MIPS_advance_loc8";
13437 /* GNU extensions. */
13438 case DW_CFA_GNU_window_save
:
13439 return "DW_CFA_GNU_window_save";
13440 case DW_CFA_GNU_args_size
:
13441 return "DW_CFA_GNU_args_size";
13442 case DW_CFA_GNU_negative_offset_extended
:
13443 return "DW_CFA_GNU_negative_offset_extended";
13445 return "DW_CFA_<unknown>";
13451 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13455 print_spaces (indent
, f
);
13456 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13457 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13459 if (die
->parent
!= NULL
)
13461 print_spaces (indent
, f
);
13462 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13463 die
->parent
->offset
);
13466 print_spaces (indent
, f
);
13467 fprintf_unfiltered (f
, " has children: %s\n",
13468 dwarf_bool_name (die
->child
!= NULL
));
13470 print_spaces (indent
, f
);
13471 fprintf_unfiltered (f
, " attributes:\n");
13473 for (i
= 0; i
< die
->num_attrs
; ++i
)
13475 print_spaces (indent
, f
);
13476 fprintf_unfiltered (f
, " %s (%s) ",
13477 dwarf_attr_name (die
->attrs
[i
].name
),
13478 dwarf_form_name (die
->attrs
[i
].form
));
13480 switch (die
->attrs
[i
].form
)
13482 case DW_FORM_ref_addr
:
13484 fprintf_unfiltered (f
, "address: ");
13485 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13487 case DW_FORM_block2
:
13488 case DW_FORM_block4
:
13489 case DW_FORM_block
:
13490 case DW_FORM_block1
:
13491 fprintf_unfiltered (f
, "block: size %d",
13492 DW_BLOCK (&die
->attrs
[i
])->size
);
13494 case DW_FORM_exprloc
:
13495 fprintf_unfiltered (f
, "expression: size %u",
13496 DW_BLOCK (&die
->attrs
[i
])->size
);
13501 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13502 (long) (DW_ADDR (&die
->attrs
[i
])));
13504 case DW_FORM_data1
:
13505 case DW_FORM_data2
:
13506 case DW_FORM_data4
:
13507 case DW_FORM_data8
:
13508 case DW_FORM_udata
:
13509 case DW_FORM_sdata
:
13510 fprintf_unfiltered (f
, "constant: %s",
13511 pulongest (DW_UNSND (&die
->attrs
[i
])));
13513 case DW_FORM_sec_offset
:
13514 fprintf_unfiltered (f
, "section offset: %s",
13515 pulongest (DW_UNSND (&die
->attrs
[i
])));
13517 case DW_FORM_ref_sig8
:
13518 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13519 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13520 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
);
13522 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13524 case DW_FORM_string
:
13526 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13527 DW_STRING (&die
->attrs
[i
])
13528 ? DW_STRING (&die
->attrs
[i
]) : "",
13529 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13532 if (DW_UNSND (&die
->attrs
[i
]))
13533 fprintf_unfiltered (f
, "flag: TRUE");
13535 fprintf_unfiltered (f
, "flag: FALSE");
13537 case DW_FORM_flag_present
:
13538 fprintf_unfiltered (f
, "flag: TRUE");
13540 case DW_FORM_indirect
:
13541 /* The reader will have reduced the indirect form to
13542 the "base form" so this form should not occur. */
13543 fprintf_unfiltered (f
,
13544 "unexpected attribute form: DW_FORM_indirect");
13547 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13548 die
->attrs
[i
].form
);
13551 fprintf_unfiltered (f
, "\n");
13556 dump_die_for_error (struct die_info
*die
)
13558 dump_die_shallow (gdb_stderr
, 0, die
);
13562 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13564 int indent
= level
* 4;
13566 gdb_assert (die
!= NULL
);
13568 if (level
>= max_level
)
13571 dump_die_shallow (f
, indent
, die
);
13573 if (die
->child
!= NULL
)
13575 print_spaces (indent
, f
);
13576 fprintf_unfiltered (f
, " Children:");
13577 if (level
+ 1 < max_level
)
13579 fprintf_unfiltered (f
, "\n");
13580 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13584 fprintf_unfiltered (f
,
13585 " [not printed, max nesting level reached]\n");
13589 if (die
->sibling
!= NULL
&& level
> 0)
13591 dump_die_1 (f
, level
, max_level
, die
->sibling
);
13595 /* This is called from the pdie macro in gdbinit.in.
13596 It's not static so gcc will keep a copy callable from gdb. */
13599 dump_die (struct die_info
*die
, int max_level
)
13601 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
13605 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
13609 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
13615 is_ref_attr (struct attribute
*attr
)
13617 switch (attr
->form
)
13619 case DW_FORM_ref_addr
:
13624 case DW_FORM_ref_udata
:
13631 static unsigned int
13632 dwarf2_get_ref_die_offset (struct attribute
*attr
)
13634 if (is_ref_attr (attr
))
13635 return DW_ADDR (attr
);
13637 complaint (&symfile_complaints
,
13638 _("unsupported die ref attribute form: '%s'"),
13639 dwarf_form_name (attr
->form
));
13643 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13644 * the value held by the attribute is not constant. */
13647 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
13649 if (attr
->form
== DW_FORM_sdata
)
13650 return DW_SND (attr
);
13651 else if (attr
->form
== DW_FORM_udata
13652 || attr
->form
== DW_FORM_data1
13653 || attr
->form
== DW_FORM_data2
13654 || attr
->form
== DW_FORM_data4
13655 || attr
->form
== DW_FORM_data8
)
13656 return DW_UNSND (attr
);
13659 complaint (&symfile_complaints
,
13660 _("Attribute value is not a constant (%s)"),
13661 dwarf_form_name (attr
->form
));
13662 return default_value
;
13666 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13667 unit and add it to our queue.
13668 The result is non-zero if PER_CU was queued, otherwise the result is zero
13669 meaning either PER_CU is already queued or it is already loaded. */
13672 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
13673 struct dwarf2_per_cu_data
*per_cu
)
13675 /* We may arrive here during partial symbol reading, if we need full
13676 DIEs to process an unusual case (e.g. template arguments). Do
13677 not queue PER_CU, just tell our caller to load its DIEs. */
13678 if (dwarf2_per_objfile
->reading_partial_symbols
)
13680 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
13685 /* Mark the dependence relation so that we don't flush PER_CU
13687 dwarf2_add_dependence (this_cu
, per_cu
);
13689 /* If it's already on the queue, we have nothing to do. */
13690 if (per_cu
->queued
)
13693 /* If the compilation unit is already loaded, just mark it as
13695 if (per_cu
->cu
!= NULL
)
13697 per_cu
->cu
->last_used
= 0;
13701 /* Add it to the queue. */
13702 queue_comp_unit (per_cu
, this_cu
->objfile
);
13707 /* Follow reference or signature attribute ATTR of SRC_DIE.
13708 On entry *REF_CU is the CU of SRC_DIE.
13709 On exit *REF_CU is the CU of the result. */
13711 static struct die_info
*
13712 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
13713 struct dwarf2_cu
**ref_cu
)
13715 struct die_info
*die
;
13717 if (is_ref_attr (attr
))
13718 die
= follow_die_ref (src_die
, attr
, ref_cu
);
13719 else if (attr
->form
== DW_FORM_ref_sig8
)
13720 die
= follow_die_sig (src_die
, attr
, ref_cu
);
13723 dump_die_for_error (src_die
);
13724 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13725 (*ref_cu
)->objfile
->name
);
13731 /* Follow reference OFFSET.
13732 On entry *REF_CU is the CU of the source die referencing OFFSET.
13733 On exit *REF_CU is the CU of the result.
13734 Returns NULL if OFFSET is invalid. */
13736 static struct die_info
*
13737 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
13739 struct die_info temp_die
;
13740 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
13742 gdb_assert (cu
->per_cu
!= NULL
);
13746 if (cu
->per_cu
->from_debug_types
)
13748 /* .debug_types CUs cannot reference anything outside their CU.
13749 If they need to, they have to reference a signatured type via
13750 DW_FORM_ref_sig8. */
13751 if (! offset_in_cu_p (&cu
->header
, offset
))
13754 else if (! offset_in_cu_p (&cu
->header
, offset
))
13756 struct dwarf2_per_cu_data
*per_cu
;
13758 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
13760 /* If necessary, add it to the queue and load its DIEs. */
13761 if (maybe_queue_comp_unit (cu
, per_cu
))
13762 load_full_comp_unit (per_cu
, cu
->objfile
);
13764 target_cu
= per_cu
->cu
;
13766 else if (cu
->dies
== NULL
)
13768 /* We're loading full DIEs during partial symbol reading. */
13769 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
13770 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
13773 *ref_cu
= target_cu
;
13774 temp_die
.offset
= offset
;
13775 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13778 /* Follow reference attribute ATTR of SRC_DIE.
13779 On entry *REF_CU is the CU of SRC_DIE.
13780 On exit *REF_CU is the CU of the result. */
13782 static struct die_info
*
13783 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13784 struct dwarf2_cu
**ref_cu
)
13786 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13787 struct dwarf2_cu
*cu
= *ref_cu
;
13788 struct die_info
*die
;
13790 die
= follow_die_offset (offset
, ref_cu
);
13792 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13793 "at 0x%x [in module %s]"),
13794 offset
, src_die
->offset
, cu
->objfile
->name
);
13799 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13800 value is intended for DW_OP_call*. */
13802 struct dwarf2_locexpr_baton
13803 dwarf2_fetch_die_location_block (unsigned int offset
,
13804 struct dwarf2_per_cu_data
*per_cu
,
13805 CORE_ADDR (*get_frame_pc
) (void *baton
),
13808 struct dwarf2_cu
*cu
= per_cu
->cu
;
13809 struct die_info
*die
;
13810 struct attribute
*attr
;
13811 struct dwarf2_locexpr_baton retval
;
13813 dw2_setup (per_cu
->objfile
);
13815 die
= follow_die_offset (offset
, &cu
);
13817 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13818 offset
, per_cu
->cu
->objfile
->name
);
13820 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13823 /* DWARF: "If there is no such attribute, then there is no effect.". */
13825 retval
.data
= NULL
;
13828 else if (attr_form_is_section_offset (attr
))
13830 struct dwarf2_loclist_baton loclist_baton
;
13831 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
13834 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
13836 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
13838 retval
.size
= size
;
13842 if (!attr_form_is_block (attr
))
13843 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13844 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13845 offset
, per_cu
->cu
->objfile
->name
);
13847 retval
.data
= DW_BLOCK (attr
)->data
;
13848 retval
.size
= DW_BLOCK (attr
)->size
;
13850 retval
.per_cu
= cu
->per_cu
;
13854 /* Return the type of the DIE at DIE_OFFSET in the CU named by
13858 dwarf2_get_die_type (unsigned int die_offset
,
13859 struct dwarf2_per_cu_data
*per_cu
)
13861 dw2_setup (per_cu
->objfile
);
13862 return get_die_type_at_offset (die_offset
, per_cu
);
13865 /* Follow the signature attribute ATTR in SRC_DIE.
13866 On entry *REF_CU is the CU of SRC_DIE.
13867 On exit *REF_CU is the CU of the result. */
13869 static struct die_info
*
13870 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
13871 struct dwarf2_cu
**ref_cu
)
13873 struct objfile
*objfile
= (*ref_cu
)->objfile
;
13874 struct die_info temp_die
;
13875 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13876 struct dwarf2_cu
*sig_cu
;
13877 struct die_info
*die
;
13879 /* sig_type will be NULL if the signatured type is missing from
13881 if (sig_type
== NULL
)
13882 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13883 "at 0x%x [in module %s]"),
13884 src_die
->offset
, objfile
->name
);
13886 /* If necessary, add it to the queue and load its DIEs. */
13888 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
13889 read_signatured_type (objfile
, sig_type
);
13891 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
13893 sig_cu
= sig_type
->per_cu
.cu
;
13894 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
13895 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
13902 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
13903 "from DIE at 0x%x [in module %s]"),
13904 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
13907 /* Given an offset of a signatured type, return its signatured_type. */
13909 static struct signatured_type
*
13910 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
13912 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
13913 unsigned int length
, initial_length_size
;
13914 unsigned int sig_offset
;
13915 struct signatured_type find_entry
, *type_sig
;
13917 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
13918 sig_offset
= (initial_length_size
13920 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
13921 + 1 /*address_size*/);
13922 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
13923 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
13925 /* This is only used to lookup previously recorded types.
13926 If we didn't find it, it's our bug. */
13927 gdb_assert (type_sig
!= NULL
);
13928 gdb_assert (offset
== type_sig
->per_cu
.offset
);
13933 /* Read in signatured type at OFFSET and build its CU and die(s). */
13936 read_signatured_type_at_offset (struct objfile
*objfile
,
13937 unsigned int offset
)
13939 struct signatured_type
*type_sig
;
13941 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13943 /* We have the section offset, but we need the signature to do the
13944 hash table lookup. */
13945 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
13947 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13949 read_signatured_type (objfile
, type_sig
);
13951 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
13954 /* Read in a signatured type and build its CU and DIEs. */
13957 read_signatured_type (struct objfile
*objfile
,
13958 struct signatured_type
*type_sig
)
13960 gdb_byte
*types_ptr
;
13961 struct die_reader_specs reader_specs
;
13962 struct dwarf2_cu
*cu
;
13963 ULONGEST signature
;
13964 struct cleanup
*back_to
, *free_cu_cleanup
;
13966 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13967 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->per_cu
.offset
;
13969 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13971 cu
= xmalloc (sizeof (*cu
));
13972 init_one_comp_unit (cu
, objfile
);
13974 type_sig
->per_cu
.cu
= cu
;
13975 cu
->per_cu
= &type_sig
->per_cu
;
13977 /* If an error occurs while loading, release our storage. */
13978 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
13980 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
13981 types_ptr
, objfile
->obfd
);
13982 gdb_assert (signature
== type_sig
->signature
);
13985 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13989 &cu
->comp_unit_obstack
,
13990 hashtab_obstack_allocate
,
13991 dummy_obstack_deallocate
);
13993 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
13994 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
13996 init_cu_die_reader (&reader_specs
, cu
);
13998 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14001 /* We try not to read any attributes in this function, because not
14002 all objfiles needed for references have been loaded yet, and symbol
14003 table processing isn't initialized. But we have to set the CU language,
14004 or we won't be able to build types correctly. */
14005 prepare_one_comp_unit (cu
, cu
->dies
);
14007 do_cleanups (back_to
);
14009 /* We've successfully allocated this compilation unit. Let our caller
14010 clean it up when finished with it. */
14011 discard_cleanups (free_cu_cleanup
);
14013 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14014 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
14017 /* Decode simple location descriptions.
14018 Given a pointer to a dwarf block that defines a location, compute
14019 the location and return the value.
14021 NOTE drow/2003-11-18: This function is called in two situations
14022 now: for the address of static or global variables (partial symbols
14023 only) and for offsets into structures which are expected to be
14024 (more or less) constant. The partial symbol case should go away,
14025 and only the constant case should remain. That will let this
14026 function complain more accurately. A few special modes are allowed
14027 without complaint for global variables (for instance, global
14028 register values and thread-local values).
14030 A location description containing no operations indicates that the
14031 object is optimized out. The return value is 0 for that case.
14032 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14033 callers will only want a very basic result and this can become a
14036 Note that stack[0] is unused except as a default error return. */
14039 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14041 struct objfile
*objfile
= cu
->objfile
;
14043 int size
= blk
->size
;
14044 gdb_byte
*data
= blk
->data
;
14045 CORE_ADDR stack
[64];
14047 unsigned int bytes_read
, unsnd
;
14053 stack
[++stacki
] = 0;
14092 stack
[++stacki
] = op
- DW_OP_lit0
;
14127 stack
[++stacki
] = op
- DW_OP_reg0
;
14129 dwarf2_complex_location_expr_complaint ();
14133 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14135 stack
[++stacki
] = unsnd
;
14137 dwarf2_complex_location_expr_complaint ();
14141 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14146 case DW_OP_const1u
:
14147 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14151 case DW_OP_const1s
:
14152 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14156 case DW_OP_const2u
:
14157 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14161 case DW_OP_const2s
:
14162 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14166 case DW_OP_const4u
:
14167 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14171 case DW_OP_const4s
:
14172 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14177 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14183 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14188 stack
[stacki
+ 1] = stack
[stacki
];
14193 stack
[stacki
- 1] += stack
[stacki
];
14197 case DW_OP_plus_uconst
:
14198 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14204 stack
[stacki
- 1] -= stack
[stacki
];
14209 /* If we're not the last op, then we definitely can't encode
14210 this using GDB's address_class enum. This is valid for partial
14211 global symbols, although the variable's address will be bogus
14214 dwarf2_complex_location_expr_complaint ();
14217 case DW_OP_GNU_push_tls_address
:
14218 /* The top of the stack has the offset from the beginning
14219 of the thread control block at which the variable is located. */
14220 /* Nothing should follow this operator, so the top of stack would
14222 /* This is valid for partial global symbols, but the variable's
14223 address will be bogus in the psymtab. */
14225 dwarf2_complex_location_expr_complaint ();
14228 case DW_OP_GNU_uninit
:
14233 const char *name
= dwarf_stack_op_name (op
);
14236 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14239 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14243 return (stack
[stacki
]);
14246 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14247 outside of the allocated space. Also enforce minimum>0. */
14248 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14250 complaint (&symfile_complaints
,
14251 _("location description stack overflow"));
14257 complaint (&symfile_complaints
,
14258 _("location description stack underflow"));
14262 return (stack
[stacki
]);
14265 /* memory allocation interface */
14267 static struct dwarf_block
*
14268 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14270 struct dwarf_block
*blk
;
14272 blk
= (struct dwarf_block
*)
14273 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14277 static struct abbrev_info
*
14278 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14280 struct abbrev_info
*abbrev
;
14282 abbrev
= (struct abbrev_info
*)
14283 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14284 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14288 static struct die_info
*
14289 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14291 struct die_info
*die
;
14292 size_t size
= sizeof (struct die_info
);
14295 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14297 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14298 memset (die
, 0, sizeof (struct die_info
));
14303 /* Macro support. */
14305 /* Return the full name of file number I in *LH's file name table.
14306 Use COMP_DIR as the name of the current directory of the
14307 compilation. The result is allocated using xmalloc; the caller is
14308 responsible for freeing it. */
14310 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14312 /* Is the file number a valid index into the line header's file name
14313 table? Remember that file numbers start with one, not zero. */
14314 if (1 <= file
&& file
<= lh
->num_file_names
)
14316 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14318 if (IS_ABSOLUTE_PATH (fe
->name
))
14319 return xstrdup (fe
->name
);
14327 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14333 dir_len
= strlen (dir
);
14334 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14335 strcpy (full_name
, dir
);
14336 full_name
[dir_len
] = '/';
14337 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14341 return xstrdup (fe
->name
);
14346 /* The compiler produced a bogus file number. We can at least
14347 record the macro definitions made in the file, even if we
14348 won't be able to find the file by name. */
14349 char fake_name
[80];
14351 sprintf (fake_name
, "<bad macro file number %d>", file
);
14353 complaint (&symfile_complaints
,
14354 _("bad file number in macro information (%d)"),
14357 return xstrdup (fake_name
);
14362 static struct macro_source_file
*
14363 macro_start_file (int file
, int line
,
14364 struct macro_source_file
*current_file
,
14365 const char *comp_dir
,
14366 struct line_header
*lh
, struct objfile
*objfile
)
14368 /* The full name of this source file. */
14369 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14371 /* We don't create a macro table for this compilation unit
14372 at all until we actually get a filename. */
14373 if (! pending_macros
)
14374 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14375 objfile
->macro_cache
);
14377 if (! current_file
)
14378 /* If we have no current file, then this must be the start_file
14379 directive for the compilation unit's main source file. */
14380 current_file
= macro_set_main (pending_macros
, full_name
);
14382 current_file
= macro_include (current_file
, line
, full_name
);
14386 return current_file
;
14390 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14391 followed by a null byte. */
14393 copy_string (const char *buf
, int len
)
14395 char *s
= xmalloc (len
+ 1);
14397 memcpy (s
, buf
, len
);
14403 static const char *
14404 consume_improper_spaces (const char *p
, const char *body
)
14408 complaint (&symfile_complaints
,
14409 _("macro definition contains spaces "
14410 "in formal argument list:\n`%s'"),
14422 parse_macro_definition (struct macro_source_file
*file
, int line
,
14427 /* The body string takes one of two forms. For object-like macro
14428 definitions, it should be:
14430 <macro name> " " <definition>
14432 For function-like macro definitions, it should be:
14434 <macro name> "() " <definition>
14436 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14438 Spaces may appear only where explicitly indicated, and in the
14441 The Dwarf 2 spec says that an object-like macro's name is always
14442 followed by a space, but versions of GCC around March 2002 omit
14443 the space when the macro's definition is the empty string.
14445 The Dwarf 2 spec says that there should be no spaces between the
14446 formal arguments in a function-like macro's formal argument list,
14447 but versions of GCC around March 2002 include spaces after the
14451 /* Find the extent of the macro name. The macro name is terminated
14452 by either a space or null character (for an object-like macro) or
14453 an opening paren (for a function-like macro). */
14454 for (p
= body
; *p
; p
++)
14455 if (*p
== ' ' || *p
== '(')
14458 if (*p
== ' ' || *p
== '\0')
14460 /* It's an object-like macro. */
14461 int name_len
= p
- body
;
14462 char *name
= copy_string (body
, name_len
);
14463 const char *replacement
;
14466 replacement
= body
+ name_len
+ 1;
14469 dwarf2_macro_malformed_definition_complaint (body
);
14470 replacement
= body
+ name_len
;
14473 macro_define_object (file
, line
, name
, replacement
);
14477 else if (*p
== '(')
14479 /* It's a function-like macro. */
14480 char *name
= copy_string (body
, p
- body
);
14483 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14487 p
= consume_improper_spaces (p
, body
);
14489 /* Parse the formal argument list. */
14490 while (*p
&& *p
!= ')')
14492 /* Find the extent of the current argument name. */
14493 const char *arg_start
= p
;
14495 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14498 if (! *p
|| p
== arg_start
)
14499 dwarf2_macro_malformed_definition_complaint (body
);
14502 /* Make sure argv has room for the new argument. */
14503 if (argc
>= argv_size
)
14506 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14509 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14512 p
= consume_improper_spaces (p
, body
);
14514 /* Consume the comma, if present. */
14519 p
= consume_improper_spaces (p
, body
);
14528 /* Perfectly formed definition, no complaints. */
14529 macro_define_function (file
, line
, name
,
14530 argc
, (const char **) argv
,
14532 else if (*p
== '\0')
14534 /* Complain, but do define it. */
14535 dwarf2_macro_malformed_definition_complaint (body
);
14536 macro_define_function (file
, line
, name
,
14537 argc
, (const char **) argv
,
14541 /* Just complain. */
14542 dwarf2_macro_malformed_definition_complaint (body
);
14545 /* Just complain. */
14546 dwarf2_macro_malformed_definition_complaint (body
);
14552 for (i
= 0; i
< argc
; i
++)
14558 dwarf2_macro_malformed_definition_complaint (body
);
14563 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
14564 char *comp_dir
, bfd
*abfd
,
14565 struct dwarf2_cu
*cu
)
14567 gdb_byte
*mac_ptr
, *mac_end
;
14568 struct macro_source_file
*current_file
= 0;
14569 enum dwarf_macinfo_record_type macinfo_type
;
14570 int at_commandline
;
14572 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14573 &dwarf2_per_objfile
->macinfo
);
14574 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
14576 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
14580 /* First pass: Find the name of the base filename.
14581 This filename is needed in order to process all macros whose definition
14582 (or undefinition) comes from the command line. These macros are defined
14583 before the first DW_MACINFO_start_file entry, and yet still need to be
14584 associated to the base file.
14586 To determine the base file name, we scan the macro definitions until we
14587 reach the first DW_MACINFO_start_file entry. We then initialize
14588 CURRENT_FILE accordingly so that any macro definition found before the
14589 first DW_MACINFO_start_file can still be associated to the base file. */
14591 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14592 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
14593 + dwarf2_per_objfile
->macinfo
.size
;
14597 /* Do we at least have room for a macinfo type byte? */
14598 if (mac_ptr
>= mac_end
)
14600 /* Complaint is printed during the second pass as GDB will probably
14601 stop the first pass earlier upon finding
14602 DW_MACINFO_start_file. */
14606 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14609 switch (macinfo_type
)
14611 /* A zero macinfo type indicates the end of the macro
14616 case DW_MACINFO_define
:
14617 case DW_MACINFO_undef
:
14618 /* Only skip the data by MAC_PTR. */
14620 unsigned int bytes_read
;
14622 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14623 mac_ptr
+= bytes_read
;
14624 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14625 mac_ptr
+= bytes_read
;
14629 case DW_MACINFO_start_file
:
14631 unsigned int bytes_read
;
14634 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14635 mac_ptr
+= bytes_read
;
14636 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14637 mac_ptr
+= bytes_read
;
14639 current_file
= macro_start_file (file
, line
, current_file
,
14640 comp_dir
, lh
, cu
->objfile
);
14644 case DW_MACINFO_end_file
:
14645 /* No data to skip by MAC_PTR. */
14648 case DW_MACINFO_vendor_ext
:
14649 /* Only skip the data by MAC_PTR. */
14651 unsigned int bytes_read
;
14653 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14654 mac_ptr
+= bytes_read
;
14655 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14656 mac_ptr
+= bytes_read
;
14663 } while (macinfo_type
!= 0 && current_file
== NULL
);
14665 /* Second pass: Process all entries.
14667 Use the AT_COMMAND_LINE flag to determine whether we are still processing
14668 command-line macro definitions/undefinitions. This flag is unset when we
14669 reach the first DW_MACINFO_start_file entry. */
14671 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14673 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14674 GDB is still reading the definitions from command line. First
14675 DW_MACINFO_start_file will need to be ignored as it was already executed
14676 to create CURRENT_FILE for the main source holding also the command line
14677 definitions. On first met DW_MACINFO_start_file this flag is reset to
14678 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14680 at_commandline
= 1;
14684 /* Do we at least have room for a macinfo type byte? */
14685 if (mac_ptr
>= mac_end
)
14687 dwarf2_macros_too_long_complaint ();
14691 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14694 switch (macinfo_type
)
14696 /* A zero macinfo type indicates the end of the macro
14701 case DW_MACINFO_define
:
14702 case DW_MACINFO_undef
:
14704 unsigned int bytes_read
;
14708 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14709 mac_ptr
+= bytes_read
;
14710 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14711 mac_ptr
+= bytes_read
;
14713 if (! current_file
)
14715 /* DWARF violation as no main source is present. */
14716 complaint (&symfile_complaints
,
14717 _("debug info with no main source gives macro %s "
14719 macinfo_type
== DW_MACINFO_define
?
14721 macinfo_type
== DW_MACINFO_undef
?
14722 _("undefinition") :
14723 _("something-or-other"), line
, body
);
14726 if ((line
== 0 && !at_commandline
)
14727 || (line
!= 0 && at_commandline
))
14728 complaint (&symfile_complaints
,
14729 _("debug info gives %s macro %s with %s line %d: %s"),
14730 at_commandline
? _("command-line") : _("in-file"),
14731 macinfo_type
== DW_MACINFO_define
?
14733 macinfo_type
== DW_MACINFO_undef
?
14734 _("undefinition") :
14735 _("something-or-other"),
14736 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
14738 if (macinfo_type
== DW_MACINFO_define
)
14739 parse_macro_definition (current_file
, line
, body
);
14740 else if (macinfo_type
== DW_MACINFO_undef
)
14741 macro_undef (current_file
, line
, body
);
14745 case DW_MACINFO_start_file
:
14747 unsigned int bytes_read
;
14750 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14751 mac_ptr
+= bytes_read
;
14752 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14753 mac_ptr
+= bytes_read
;
14755 if ((line
== 0 && !at_commandline
)
14756 || (line
!= 0 && at_commandline
))
14757 complaint (&symfile_complaints
,
14758 _("debug info gives source %d included "
14759 "from %s at %s line %d"),
14760 file
, at_commandline
? _("command-line") : _("file"),
14761 line
== 0 ? _("zero") : _("non-zero"), line
);
14763 if (at_commandline
)
14765 /* This DW_MACINFO_start_file was executed in the pass one. */
14766 at_commandline
= 0;
14769 current_file
= macro_start_file (file
, line
,
14770 current_file
, comp_dir
,
14775 case DW_MACINFO_end_file
:
14776 if (! current_file
)
14777 complaint (&symfile_complaints
,
14778 _("macro debug info has an unmatched "
14779 "`close_file' directive"));
14782 current_file
= current_file
->included_by
;
14783 if (! current_file
)
14785 enum dwarf_macinfo_record_type next_type
;
14787 /* GCC circa March 2002 doesn't produce the zero
14788 type byte marking the end of the compilation
14789 unit. Complain if it's not there, but exit no
14792 /* Do we at least have room for a macinfo type byte? */
14793 if (mac_ptr
>= mac_end
)
14795 dwarf2_macros_too_long_complaint ();
14799 /* We don't increment mac_ptr here, so this is just
14801 next_type
= read_1_byte (abfd
, mac_ptr
);
14802 if (next_type
!= 0)
14803 complaint (&symfile_complaints
,
14804 _("no terminating 0-type entry for "
14805 "macros in `.debug_macinfo' section"));
14812 case DW_MACINFO_vendor_ext
:
14814 unsigned int bytes_read
;
14817 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14818 mac_ptr
+= bytes_read
;
14819 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14820 mac_ptr
+= bytes_read
;
14822 /* We don't recognize any vendor extensions. */
14826 } while (macinfo_type
!= 0);
14829 /* Check if the attribute's form is a DW_FORM_block*
14830 if so return true else false. */
14832 attr_form_is_block (struct attribute
*attr
)
14834 return (attr
== NULL
? 0 :
14835 attr
->form
== DW_FORM_block1
14836 || attr
->form
== DW_FORM_block2
14837 || attr
->form
== DW_FORM_block4
14838 || attr
->form
== DW_FORM_block
14839 || attr
->form
== DW_FORM_exprloc
);
14842 /* Return non-zero if ATTR's value is a section offset --- classes
14843 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14844 You may use DW_UNSND (attr) to retrieve such offsets.
14846 Section 7.5.4, "Attribute Encodings", explains that no attribute
14847 may have a value that belongs to more than one of these classes; it
14848 would be ambiguous if we did, because we use the same forms for all
14851 attr_form_is_section_offset (struct attribute
*attr
)
14853 return (attr
->form
== DW_FORM_data4
14854 || attr
->form
== DW_FORM_data8
14855 || attr
->form
== DW_FORM_sec_offset
);
14859 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14860 zero otherwise. When this function returns true, you can apply
14861 dwarf2_get_attr_constant_value to it.
14863 However, note that for some attributes you must check
14864 attr_form_is_section_offset before using this test. DW_FORM_data4
14865 and DW_FORM_data8 are members of both the constant class, and of
14866 the classes that contain offsets into other debug sections
14867 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14868 that, if an attribute's can be either a constant or one of the
14869 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14870 taken as section offsets, not constants. */
14872 attr_form_is_constant (struct attribute
*attr
)
14874 switch (attr
->form
)
14876 case DW_FORM_sdata
:
14877 case DW_FORM_udata
:
14878 case DW_FORM_data1
:
14879 case DW_FORM_data2
:
14880 case DW_FORM_data4
:
14881 case DW_FORM_data8
:
14888 /* A helper function that fills in a dwarf2_loclist_baton. */
14891 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
14892 struct dwarf2_loclist_baton
*baton
,
14893 struct attribute
*attr
)
14895 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14896 &dwarf2_per_objfile
->loc
);
14898 baton
->per_cu
= cu
->per_cu
;
14899 gdb_assert (baton
->per_cu
);
14900 /* We don't know how long the location list is, but make sure we
14901 don't run off the edge of the section. */
14902 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
14903 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
14904 baton
->base_address
= cu
->base_address
;
14908 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
14909 struct dwarf2_cu
*cu
)
14911 if (attr_form_is_section_offset (attr
)
14912 /* ".debug_loc" may not exist at all, or the offset may be outside
14913 the section. If so, fall through to the complaint in the
14915 && DW_UNSND (attr
) < dwarf2_section_size (dwarf2_per_objfile
->objfile
,
14916 &dwarf2_per_objfile
->loc
))
14918 struct dwarf2_loclist_baton
*baton
;
14920 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14921 sizeof (struct dwarf2_loclist_baton
));
14923 fill_in_loclist_baton (cu
, baton
, attr
);
14925 if (cu
->base_known
== 0)
14926 complaint (&symfile_complaints
,
14927 _("Location list used without "
14928 "specifying the CU base address."));
14930 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
14931 SYMBOL_LOCATION_BATON (sym
) = baton
;
14935 struct dwarf2_locexpr_baton
*baton
;
14937 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14938 sizeof (struct dwarf2_locexpr_baton
));
14939 baton
->per_cu
= cu
->per_cu
;
14940 gdb_assert (baton
->per_cu
);
14942 if (attr_form_is_block (attr
))
14944 /* Note that we're just copying the block's data pointer
14945 here, not the actual data. We're still pointing into the
14946 info_buffer for SYM's objfile; right now we never release
14947 that buffer, but when we do clean up properly this may
14949 baton
->size
= DW_BLOCK (attr
)->size
;
14950 baton
->data
= DW_BLOCK (attr
)->data
;
14954 dwarf2_invalid_attrib_class_complaint ("location description",
14955 SYMBOL_NATURAL_NAME (sym
));
14957 baton
->data
= NULL
;
14960 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14961 SYMBOL_LOCATION_BATON (sym
) = baton
;
14965 /* Return the OBJFILE associated with the compilation unit CU. If CU
14966 came from a separate debuginfo file, then the master objfile is
14970 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
14972 struct objfile
*objfile
= per_cu
->objfile
;
14974 /* Return the master objfile, so that we can report and look up the
14975 correct file containing this variable. */
14976 if (objfile
->separate_debug_objfile_backlink
)
14977 objfile
= objfile
->separate_debug_objfile_backlink
;
14982 /* Return the address size given in the compilation unit header for CU. */
14985 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
14988 return per_cu
->cu
->header
.addr_size
;
14991 /* If the CU is not currently read in, we re-read its header. */
14992 struct objfile
*objfile
= per_cu
->objfile
;
14993 struct dwarf2_per_objfile
*per_objfile
14994 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14995 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14996 struct comp_unit_head cu_header
;
14998 memset (&cu_header
, 0, sizeof cu_header
);
14999 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
15000 return cu_header
.addr_size
;
15004 /* Return the offset size given in the compilation unit header for CU. */
15007 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
15010 return per_cu
->cu
->header
.offset_size
;
15013 /* If the CU is not currently read in, we re-read its header. */
15014 struct objfile
*objfile
= per_cu
->objfile
;
15015 struct dwarf2_per_objfile
*per_objfile
15016 = objfile_data (objfile
, dwarf2_objfile_data_key
);
15017 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
15018 struct comp_unit_head cu_header
;
15020 memset (&cu_header
, 0, sizeof cu_header
);
15021 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
15022 return cu_header
.offset_size
;
15026 /* Return the text offset of the CU. The returned offset comes from
15027 this CU's objfile. If this objfile came from a separate debuginfo
15028 file, then the offset may be different from the corresponding
15029 offset in the parent objfile. */
15032 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
15034 struct objfile
*objfile
= per_cu
->objfile
;
15036 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15039 /* Locate the .debug_info compilation unit from CU's objfile which contains
15040 the DIE at OFFSET. Raises an error on failure. */
15042 static struct dwarf2_per_cu_data
*
15043 dwarf2_find_containing_comp_unit (unsigned int offset
,
15044 struct objfile
*objfile
)
15046 struct dwarf2_per_cu_data
*this_cu
;
15050 high
= dwarf2_per_objfile
->n_comp_units
- 1;
15053 int mid
= low
+ (high
- low
) / 2;
15055 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
15060 gdb_assert (low
== high
);
15061 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
15064 error (_("Dwarf Error: could not find partial DIE containing "
15065 "offset 0x%lx [in module %s]"),
15066 (long) offset
, bfd_get_filename (objfile
->obfd
));
15068 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
15069 return dwarf2_per_objfile
->all_comp_units
[low
-1];
15073 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
15074 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
15075 && offset
>= this_cu
->offset
+ this_cu
->length
)
15076 error (_("invalid dwarf2 offset %u"), offset
);
15077 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
15082 /* Locate the compilation unit from OBJFILE which is located at exactly
15083 OFFSET. Raises an error on failure. */
15085 static struct dwarf2_per_cu_data
*
15086 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
15088 struct dwarf2_per_cu_data
*this_cu
;
15090 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
15091 if (this_cu
->offset
!= offset
)
15092 error (_("no compilation unit with offset %u."), offset
);
15096 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
15099 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
15101 memset (cu
, 0, sizeof (*cu
));
15102 cu
->objfile
= objfile
;
15103 obstack_init (&cu
->comp_unit_obstack
);
15106 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15109 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
15111 struct attribute
*attr
;
15113 /* Set the language we're debugging. */
15114 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
15116 set_cu_language (DW_UNSND (attr
), cu
);
15119 cu
->language
= language_minimal
;
15120 cu
->language_defn
= language_def (cu
->language
);
15124 /* Release one cached compilation unit, CU. We unlink it from the tree
15125 of compilation units, but we don't remove it from the read_in_chain;
15126 the caller is responsible for that.
15127 NOTE: DATA is a void * because this function is also used as a
15128 cleanup routine. */
15131 free_one_comp_unit (void *data
)
15133 struct dwarf2_cu
*cu
= data
;
15135 if (cu
->per_cu
!= NULL
)
15136 cu
->per_cu
->cu
= NULL
;
15139 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15144 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15145 when we're finished with it. We can't free the pointer itself, but be
15146 sure to unlink it from the cache. Also release any associated storage
15147 and perform cache maintenance.
15149 Only used during partial symbol parsing. */
15152 free_stack_comp_unit (void *data
)
15154 struct dwarf2_cu
*cu
= data
;
15156 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15157 cu
->partial_dies
= NULL
;
15159 if (cu
->per_cu
!= NULL
)
15161 /* This compilation unit is on the stack in our caller, so we
15162 should not xfree it. Just unlink it. */
15163 cu
->per_cu
->cu
= NULL
;
15166 /* If we had a per-cu pointer, then we may have other compilation
15167 units loaded, so age them now. */
15168 age_cached_comp_units ();
15172 /* Free all cached compilation units. */
15175 free_cached_comp_units (void *data
)
15177 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15179 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15180 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15181 while (per_cu
!= NULL
)
15183 struct dwarf2_per_cu_data
*next_cu
;
15185 next_cu
= per_cu
->cu
->read_in_chain
;
15187 free_one_comp_unit (per_cu
->cu
);
15188 *last_chain
= next_cu
;
15194 /* Increase the age counter on each cached compilation unit, and free
15195 any that are too old. */
15198 age_cached_comp_units (void)
15200 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15202 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
15203 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15204 while (per_cu
!= NULL
)
15206 per_cu
->cu
->last_used
++;
15207 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
15208 dwarf2_mark (per_cu
->cu
);
15209 per_cu
= per_cu
->cu
->read_in_chain
;
15212 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15213 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15214 while (per_cu
!= NULL
)
15216 struct dwarf2_per_cu_data
*next_cu
;
15218 next_cu
= per_cu
->cu
->read_in_chain
;
15220 if (!per_cu
->cu
->mark
)
15222 free_one_comp_unit (per_cu
->cu
);
15223 *last_chain
= next_cu
;
15226 last_chain
= &per_cu
->cu
->read_in_chain
;
15232 /* Remove a single compilation unit from the cache. */
15235 free_one_cached_comp_unit (void *target_cu
)
15237 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15239 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15240 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15241 while (per_cu
!= NULL
)
15243 struct dwarf2_per_cu_data
*next_cu
;
15245 next_cu
= per_cu
->cu
->read_in_chain
;
15247 if (per_cu
->cu
== target_cu
)
15249 free_one_comp_unit (per_cu
->cu
);
15250 *last_chain
= next_cu
;
15254 last_chain
= &per_cu
->cu
->read_in_chain
;
15260 /* Release all extra memory associated with OBJFILE. */
15263 dwarf2_free_objfile (struct objfile
*objfile
)
15265 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15267 if (dwarf2_per_objfile
== NULL
)
15270 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
15271 free_cached_comp_units (NULL
);
15273 if (dwarf2_per_objfile
->quick_file_names_table
)
15274 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
15276 /* Everything else should be on the objfile obstack. */
15279 /* A pair of DIE offset and GDB type pointer. We store these
15280 in a hash table separate from the DIEs, and preserve them
15281 when the DIEs are flushed out of cache. */
15283 struct dwarf2_offset_and_type
15285 unsigned int offset
;
15289 /* Hash function for a dwarf2_offset_and_type. */
15292 offset_and_type_hash (const void *item
)
15294 const struct dwarf2_offset_and_type
*ofs
= item
;
15296 return ofs
->offset
;
15299 /* Equality function for a dwarf2_offset_and_type. */
15302 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
15304 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
15305 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
15307 return ofs_lhs
->offset
== ofs_rhs
->offset
;
15310 /* Set the type associated with DIE to TYPE. Save it in CU's hash
15311 table if necessary. For convenience, return TYPE.
15313 The DIEs reading must have careful ordering to:
15314 * Not cause infite loops trying to read in DIEs as a prerequisite for
15315 reading current DIE.
15316 * Not trying to dereference contents of still incompletely read in types
15317 while reading in other DIEs.
15318 * Enable referencing still incompletely read in types just by a pointer to
15319 the type without accessing its fields.
15321 Therefore caller should follow these rules:
15322 * Try to fetch any prerequisite types we may need to build this DIE type
15323 before building the type and calling set_die_type.
15324 * After building type call set_die_type for current DIE as soon as
15325 possible before fetching more types to complete the current type.
15326 * Make the type as complete as possible before fetching more types. */
15328 static struct type
*
15329 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
15331 struct dwarf2_offset_and_type
**slot
, ofs
;
15332 struct objfile
*objfile
= cu
->objfile
;
15333 htab_t
*type_hash_ptr
;
15335 /* For Ada types, make sure that the gnat-specific data is always
15336 initialized (if not already set). There are a few types where
15337 we should not be doing so, because the type-specific area is
15338 already used to hold some other piece of info (eg: TYPE_CODE_FLT
15339 where the type-specific area is used to store the floatformat).
15340 But this is not a problem, because the gnat-specific information
15341 is actually not needed for these types. */
15342 if (need_gnat_info (cu
)
15343 && TYPE_CODE (type
) != TYPE_CODE_FUNC
15344 && TYPE_CODE (type
) != TYPE_CODE_FLT
15345 && !HAVE_GNAT_AUX_INFO (type
))
15346 INIT_GNAT_SPECIFIC (type
);
15348 if (cu
->per_cu
->from_debug_types
)
15349 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
15351 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
15353 if (*type_hash_ptr
== NULL
)
15356 = htab_create_alloc_ex (127,
15357 offset_and_type_hash
,
15358 offset_and_type_eq
,
15360 &objfile
->objfile_obstack
,
15361 hashtab_obstack_allocate
,
15362 dummy_obstack_deallocate
);
15365 ofs
.offset
= die
->offset
;
15367 slot
= (struct dwarf2_offset_and_type
**)
15368 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
15370 complaint (&symfile_complaints
,
15371 _("A problem internal to GDB: DIE 0x%x has type already set"),
15373 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
15378 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
15379 table, or return NULL if the die does not have a saved type. */
15381 static struct type
*
15382 get_die_type_at_offset (unsigned int offset
,
15383 struct dwarf2_per_cu_data
*per_cu
)
15385 struct dwarf2_offset_and_type
*slot
, ofs
;
15388 if (per_cu
->from_debug_types
)
15389 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
15391 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
15392 if (type_hash
== NULL
)
15395 ofs
.offset
= offset
;
15396 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
15403 /* Look up the type for DIE in the appropriate type_hash table,
15404 or return NULL if DIE does not have a saved type. */
15406 static struct type
*
15407 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15409 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
15412 /* Add a dependence relationship from CU to REF_PER_CU. */
15415 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
15416 struct dwarf2_per_cu_data
*ref_per_cu
)
15420 if (cu
->dependencies
== NULL
)
15422 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
15423 NULL
, &cu
->comp_unit_obstack
,
15424 hashtab_obstack_allocate
,
15425 dummy_obstack_deallocate
);
15427 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
15429 *slot
= ref_per_cu
;
15432 /* Subroutine of dwarf2_mark to pass to htab_traverse.
15433 Set the mark field in every compilation unit in the
15434 cache that we must keep because we are keeping CU. */
15437 dwarf2_mark_helper (void **slot
, void *data
)
15439 struct dwarf2_per_cu_data
*per_cu
;
15441 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
15442 if (per_cu
->cu
->mark
)
15444 per_cu
->cu
->mark
= 1;
15446 if (per_cu
->cu
->dependencies
!= NULL
)
15447 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15452 /* Set the mark field in CU and in every other compilation unit in the
15453 cache that we must keep because we are keeping CU. */
15456 dwarf2_mark (struct dwarf2_cu
*cu
)
15461 if (cu
->dependencies
!= NULL
)
15462 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15466 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
15470 per_cu
->cu
->mark
= 0;
15471 per_cu
= per_cu
->cu
->read_in_chain
;
15475 /* Trivial hash function for partial_die_info: the hash value of a DIE
15476 is its offset in .debug_info for this objfile. */
15479 partial_die_hash (const void *item
)
15481 const struct partial_die_info
*part_die
= item
;
15483 return part_die
->offset
;
15486 /* Trivial comparison function for partial_die_info structures: two DIEs
15487 are equal if they have the same offset. */
15490 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
15492 const struct partial_die_info
*part_die_lhs
= item_lhs
;
15493 const struct partial_die_info
*part_die_rhs
= item_rhs
;
15495 return part_die_lhs
->offset
== part_die_rhs
->offset
;
15498 static struct cmd_list_element
*set_dwarf2_cmdlist
;
15499 static struct cmd_list_element
*show_dwarf2_cmdlist
;
15502 set_dwarf2_cmd (char *args
, int from_tty
)
15504 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
15508 show_dwarf2_cmd (char *args
, int from_tty
)
15510 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
15513 /* If section described by INFO was mmapped, munmap it now. */
15516 munmap_section_buffer (struct dwarf2_section_info
*info
)
15518 if (info
->map_addr
!= NULL
)
15523 res
= munmap (info
->map_addr
, info
->map_len
);
15524 gdb_assert (res
== 0);
15526 /* Without HAVE_MMAP, we should never be here to begin with. */
15527 gdb_assert_not_reached ("no mmap support");
15532 /* munmap debug sections for OBJFILE, if necessary. */
15535 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
15537 struct dwarf2_per_objfile
*data
= d
;
15539 /* This is sorted according to the order they're defined in to make it easier
15540 to keep in sync. */
15541 munmap_section_buffer (&data
->info
);
15542 munmap_section_buffer (&data
->abbrev
);
15543 munmap_section_buffer (&data
->line
);
15544 munmap_section_buffer (&data
->loc
);
15545 munmap_section_buffer (&data
->macinfo
);
15546 munmap_section_buffer (&data
->str
);
15547 munmap_section_buffer (&data
->ranges
);
15548 munmap_section_buffer (&data
->types
);
15549 munmap_section_buffer (&data
->frame
);
15550 munmap_section_buffer (&data
->eh_frame
);
15551 munmap_section_buffer (&data
->gdb_index
);
15555 /* The "save gdb-index" command. */
15557 /* The contents of the hash table we create when building the string
15559 struct strtab_entry
15561 offset_type offset
;
15565 /* Hash function for a strtab_entry.
15567 Function is used only during write_hash_table so no index format backward
15568 compatibility is needed. */
15571 hash_strtab_entry (const void *e
)
15573 const struct strtab_entry
*entry
= e
;
15574 return mapped_index_string_hash (INT_MAX
, entry
->str
);
15577 /* Equality function for a strtab_entry. */
15580 eq_strtab_entry (const void *a
, const void *b
)
15582 const struct strtab_entry
*ea
= a
;
15583 const struct strtab_entry
*eb
= b
;
15584 return !strcmp (ea
->str
, eb
->str
);
15587 /* Create a strtab_entry hash table. */
15590 create_strtab (void)
15592 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
15593 xfree
, xcalloc
, xfree
);
15596 /* Add a string to the constant pool. Return the string's offset in
15600 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
15603 struct strtab_entry entry
;
15604 struct strtab_entry
*result
;
15607 slot
= htab_find_slot (table
, &entry
, INSERT
);
15612 result
= XNEW (struct strtab_entry
);
15613 result
->offset
= obstack_object_size (cpool
);
15615 obstack_grow_str0 (cpool
, str
);
15618 return result
->offset
;
15621 /* An entry in the symbol table. */
15622 struct symtab_index_entry
15624 /* The name of the symbol. */
15626 /* The offset of the name in the constant pool. */
15627 offset_type index_offset
;
15628 /* A sorted vector of the indices of all the CUs that hold an object
15630 VEC (offset_type
) *cu_indices
;
15633 /* The symbol table. This is a power-of-2-sized hash table. */
15634 struct mapped_symtab
15636 offset_type n_elements
;
15638 struct symtab_index_entry
**data
;
15641 /* Hash function for a symtab_index_entry. */
15644 hash_symtab_entry (const void *e
)
15646 const struct symtab_index_entry
*entry
= e
;
15647 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
15648 sizeof (offset_type
) * VEC_length (offset_type
,
15649 entry
->cu_indices
),
15653 /* Equality function for a symtab_index_entry. */
15656 eq_symtab_entry (const void *a
, const void *b
)
15658 const struct symtab_index_entry
*ea
= a
;
15659 const struct symtab_index_entry
*eb
= b
;
15660 int len
= VEC_length (offset_type
, ea
->cu_indices
);
15661 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
15663 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
15664 VEC_address (offset_type
, eb
->cu_indices
),
15665 sizeof (offset_type
) * len
);
15668 /* Destroy a symtab_index_entry. */
15671 delete_symtab_entry (void *p
)
15673 struct symtab_index_entry
*entry
= p
;
15674 VEC_free (offset_type
, entry
->cu_indices
);
15678 /* Create a hash table holding symtab_index_entry objects. */
15681 create_symbol_hash_table (void)
15683 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
15684 delete_symtab_entry
, xcalloc
, xfree
);
15687 /* Create a new mapped symtab object. */
15689 static struct mapped_symtab
*
15690 create_mapped_symtab (void)
15692 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
15693 symtab
->n_elements
= 0;
15694 symtab
->size
= 1024;
15695 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15699 /* Destroy a mapped_symtab. */
15702 cleanup_mapped_symtab (void *p
)
15704 struct mapped_symtab
*symtab
= p
;
15705 /* The contents of the array are freed when the other hash table is
15707 xfree (symtab
->data
);
15711 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
15714 Function is used only during write_hash_table so no index format backward
15715 compatibility is needed. */
15717 static struct symtab_index_entry
**
15718 find_slot (struct mapped_symtab
*symtab
, const char *name
)
15720 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
15722 index
= hash
& (symtab
->size
- 1);
15723 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
15727 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
15728 return &symtab
->data
[index
];
15729 index
= (index
+ step
) & (symtab
->size
- 1);
15733 /* Expand SYMTAB's hash table. */
15736 hash_expand (struct mapped_symtab
*symtab
)
15738 offset_type old_size
= symtab
->size
;
15740 struct symtab_index_entry
**old_entries
= symtab
->data
;
15743 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15745 for (i
= 0; i
< old_size
; ++i
)
15747 if (old_entries
[i
])
15749 struct symtab_index_entry
**slot
= find_slot (symtab
,
15750 old_entries
[i
]->name
);
15751 *slot
= old_entries
[i
];
15755 xfree (old_entries
);
15758 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
15759 is the index of the CU in which the symbol appears. */
15762 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
15763 offset_type cu_index
)
15765 struct symtab_index_entry
**slot
;
15767 ++symtab
->n_elements
;
15768 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
15769 hash_expand (symtab
);
15771 slot
= find_slot (symtab
, name
);
15774 *slot
= XNEW (struct symtab_index_entry
);
15775 (*slot
)->name
= name
;
15776 (*slot
)->cu_indices
= NULL
;
15778 /* Don't push an index twice. Due to how we add entries we only
15779 have to check the last one. */
15780 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
15781 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
15782 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
15785 /* Add a vector of indices to the constant pool. */
15788 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
15789 struct symtab_index_entry
*entry
)
15793 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
15796 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
15797 offset_type val
= MAYBE_SWAP (len
);
15802 entry
->index_offset
= obstack_object_size (cpool
);
15804 obstack_grow (cpool
, &val
, sizeof (val
));
15806 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
15809 val
= MAYBE_SWAP (iter
);
15810 obstack_grow (cpool
, &val
, sizeof (val
));
15815 struct symtab_index_entry
*old_entry
= *slot
;
15816 entry
->index_offset
= old_entry
->index_offset
;
15819 return entry
->index_offset
;
15822 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15823 constant pool entries going into the obstack CPOOL. */
15826 write_hash_table (struct mapped_symtab
*symtab
,
15827 struct obstack
*output
, struct obstack
*cpool
)
15830 htab_t symbol_hash_table
;
15833 symbol_hash_table
= create_symbol_hash_table ();
15834 str_table
= create_strtab ();
15836 /* We add all the index vectors to the constant pool first, to
15837 ensure alignment is ok. */
15838 for (i
= 0; i
< symtab
->size
; ++i
)
15840 if (symtab
->data
[i
])
15841 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
15844 /* Now write out the hash table. */
15845 for (i
= 0; i
< symtab
->size
; ++i
)
15847 offset_type str_off
, vec_off
;
15849 if (symtab
->data
[i
])
15851 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
15852 vec_off
= symtab
->data
[i
]->index_offset
;
15856 /* While 0 is a valid constant pool index, it is not valid
15857 to have 0 for both offsets. */
15862 str_off
= MAYBE_SWAP (str_off
);
15863 vec_off
= MAYBE_SWAP (vec_off
);
15865 obstack_grow (output
, &str_off
, sizeof (str_off
));
15866 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
15869 htab_delete (str_table
);
15870 htab_delete (symbol_hash_table
);
15873 /* Struct to map psymtab to CU index in the index file. */
15874 struct psymtab_cu_index_map
15876 struct partial_symtab
*psymtab
;
15877 unsigned int cu_index
;
15881 hash_psymtab_cu_index (const void *item
)
15883 const struct psymtab_cu_index_map
*map
= item
;
15885 return htab_hash_pointer (map
->psymtab
);
15889 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
15891 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
15892 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
15894 return lhs
->psymtab
== rhs
->psymtab
;
15897 /* Helper struct for building the address table. */
15898 struct addrmap_index_data
15900 struct objfile
*objfile
;
15901 struct obstack
*addr_obstack
;
15902 htab_t cu_index_htab
;
15904 /* Non-zero if the previous_* fields are valid.
15905 We can't write an entry until we see the next entry (since it is only then
15906 that we know the end of the entry). */
15907 int previous_valid
;
15908 /* Index of the CU in the table of all CUs in the index file. */
15909 unsigned int previous_cu_index
;
15910 /* Start address of the CU. */
15911 CORE_ADDR previous_cu_start
;
15914 /* Write an address entry to OBSTACK. */
15917 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
15918 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
15920 offset_type cu_index_to_write
;
15922 CORE_ADDR baseaddr
;
15924 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15926 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
15927 obstack_grow (obstack
, addr
, 8);
15928 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
15929 obstack_grow (obstack
, addr
, 8);
15930 cu_index_to_write
= MAYBE_SWAP (cu_index
);
15931 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
15934 /* Worker function for traversing an addrmap to build the address table. */
15937 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
15939 struct addrmap_index_data
*data
= datap
;
15940 struct partial_symtab
*pst
= obj
;
15941 offset_type cu_index
;
15944 if (data
->previous_valid
)
15945 add_address_entry (data
->objfile
, data
->addr_obstack
,
15946 data
->previous_cu_start
, start_addr
,
15947 data
->previous_cu_index
);
15949 data
->previous_cu_start
= start_addr
;
15952 struct psymtab_cu_index_map find_map
, *map
;
15953 find_map
.psymtab
= pst
;
15954 map
= htab_find (data
->cu_index_htab
, &find_map
);
15955 gdb_assert (map
!= NULL
);
15956 data
->previous_cu_index
= map
->cu_index
;
15957 data
->previous_valid
= 1;
15960 data
->previous_valid
= 0;
15965 /* Write OBJFILE's address map to OBSTACK.
15966 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
15967 in the index file. */
15970 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
15971 htab_t cu_index_htab
)
15973 struct addrmap_index_data addrmap_index_data
;
15975 /* When writing the address table, we have to cope with the fact that
15976 the addrmap iterator only provides the start of a region; we have to
15977 wait until the next invocation to get the start of the next region. */
15979 addrmap_index_data
.objfile
= objfile
;
15980 addrmap_index_data
.addr_obstack
= obstack
;
15981 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
15982 addrmap_index_data
.previous_valid
= 0;
15984 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
15985 &addrmap_index_data
);
15987 /* It's highly unlikely the last entry (end address = 0xff...ff)
15988 is valid, but we should still handle it.
15989 The end address is recorded as the start of the next region, but that
15990 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
15992 if (addrmap_index_data
.previous_valid
)
15993 add_address_entry (objfile
, obstack
,
15994 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
15995 addrmap_index_data
.previous_cu_index
);
15998 /* Add a list of partial symbols to SYMTAB. */
16001 write_psymbols (struct mapped_symtab
*symtab
,
16003 struct partial_symbol
**psymp
,
16005 offset_type cu_index
,
16008 for (; count
-- > 0; ++psymp
)
16010 void **slot
, *lookup
;
16012 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
16013 error (_("Ada is not currently supported by the index"));
16015 /* We only want to add a given psymbol once. However, we also
16016 want to account for whether it is global or static. So, we
16017 may add it twice, using slightly different values. */
16020 uintptr_t val
= 1 | (uintptr_t) *psymp
;
16022 lookup
= (void *) val
;
16027 /* Only add a given psymbol once. */
16028 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
16032 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
16037 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16038 exception if there is an error. */
16041 write_obstack (FILE *file
, struct obstack
*obstack
)
16043 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
16045 != obstack_object_size (obstack
))
16046 error (_("couldn't data write to file"));
16049 /* Unlink a file if the argument is not NULL. */
16052 unlink_if_set (void *p
)
16054 char **filename
= p
;
16056 unlink (*filename
);
16059 /* A helper struct used when iterating over debug_types. */
16060 struct signatured_type_index_data
16062 struct objfile
*objfile
;
16063 struct mapped_symtab
*symtab
;
16064 struct obstack
*types_list
;
16069 /* A helper function that writes a single signatured_type to an
16073 write_one_signatured_type (void **slot
, void *d
)
16075 struct signatured_type_index_data
*info
= d
;
16076 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
16077 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
16078 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16081 write_psymbols (info
->symtab
,
16083 info
->objfile
->global_psymbols
.list
16084 + psymtab
->globals_offset
,
16085 psymtab
->n_global_syms
, info
->cu_index
,
16087 write_psymbols (info
->symtab
,
16089 info
->objfile
->static_psymbols
.list
16090 + psymtab
->statics_offset
,
16091 psymtab
->n_static_syms
, info
->cu_index
,
16094 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->per_cu
.offset
);
16095 obstack_grow (info
->types_list
, val
, 8);
16096 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
16097 obstack_grow (info
->types_list
, val
, 8);
16098 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
16099 obstack_grow (info
->types_list
, val
, 8);
16106 /* A cleanup function for an htab_t. */
16109 cleanup_htab (void *arg
)
16114 /* Create an index file for OBJFILE in the directory DIR. */
16117 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
16119 struct cleanup
*cleanup
;
16120 char *filename
, *cleanup_filename
;
16121 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
16122 struct obstack cu_list
, types_cu_list
;
16125 struct mapped_symtab
*symtab
;
16126 offset_type val
, size_of_contents
, total_len
;
16130 htab_t cu_index_htab
;
16131 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
16133 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
16136 if (dwarf2_per_objfile
->using_index
)
16137 error (_("Cannot use an index to create the index"));
16139 if (stat (objfile
->name
, &st
) < 0)
16140 perror_with_name (objfile
->name
);
16142 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
16143 INDEX_SUFFIX
, (char *) NULL
);
16144 cleanup
= make_cleanup (xfree
, filename
);
16146 out_file
= fopen (filename
, "wb");
16148 error (_("Can't open `%s' for writing"), filename
);
16150 cleanup_filename
= filename
;
16151 make_cleanup (unlink_if_set
, &cleanup_filename
);
16153 symtab
= create_mapped_symtab ();
16154 make_cleanup (cleanup_mapped_symtab
, symtab
);
16156 obstack_init (&addr_obstack
);
16157 make_cleanup_obstack_free (&addr_obstack
);
16159 obstack_init (&cu_list
);
16160 make_cleanup_obstack_free (&cu_list
);
16162 obstack_init (&types_cu_list
);
16163 make_cleanup_obstack_free (&types_cu_list
);
16165 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
16166 NULL
, xcalloc
, xfree
);
16167 make_cleanup (cleanup_htab
, psyms_seen
);
16169 /* While we're scanning CU's create a table that maps a psymtab pointer
16170 (which is what addrmap records) to its index (which is what is recorded
16171 in the index file). This will later be needed to write the address
16173 cu_index_htab
= htab_create_alloc (100,
16174 hash_psymtab_cu_index
,
16175 eq_psymtab_cu_index
,
16176 NULL
, xcalloc
, xfree
);
16177 make_cleanup (cleanup_htab
, cu_index_htab
);
16178 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
16179 xmalloc (sizeof (struct psymtab_cu_index_map
)
16180 * dwarf2_per_objfile
->n_comp_units
);
16181 make_cleanup (xfree
, psymtab_cu_index_map
);
16183 /* The CU list is already sorted, so we don't need to do additional
16184 work here. Also, the debug_types entries do not appear in
16185 all_comp_units, but only in their own hash table. */
16186 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
16188 struct dwarf2_per_cu_data
*per_cu
16189 = dwarf2_per_objfile
->all_comp_units
[i
];
16190 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16192 struct psymtab_cu_index_map
*map
;
16195 write_psymbols (symtab
,
16197 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
16198 psymtab
->n_global_syms
, i
,
16200 write_psymbols (symtab
,
16202 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
16203 psymtab
->n_static_syms
, i
,
16206 map
= &psymtab_cu_index_map
[i
];
16207 map
->psymtab
= psymtab
;
16209 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
16210 gdb_assert (slot
!= NULL
);
16211 gdb_assert (*slot
== NULL
);
16214 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
16215 obstack_grow (&cu_list
, val
, 8);
16216 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
16217 obstack_grow (&cu_list
, val
, 8);
16220 /* Dump the address map. */
16221 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
16223 /* Write out the .debug_type entries, if any. */
16224 if (dwarf2_per_objfile
->signatured_types
)
16226 struct signatured_type_index_data sig_data
;
16228 sig_data
.objfile
= objfile
;
16229 sig_data
.symtab
= symtab
;
16230 sig_data
.types_list
= &types_cu_list
;
16231 sig_data
.psyms_seen
= psyms_seen
;
16232 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
16233 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
16234 write_one_signatured_type
, &sig_data
);
16237 obstack_init (&constant_pool
);
16238 make_cleanup_obstack_free (&constant_pool
);
16239 obstack_init (&symtab_obstack
);
16240 make_cleanup_obstack_free (&symtab_obstack
);
16241 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
16243 obstack_init (&contents
);
16244 make_cleanup_obstack_free (&contents
);
16245 size_of_contents
= 6 * sizeof (offset_type
);
16246 total_len
= size_of_contents
;
16248 /* The version number. */
16249 val
= MAYBE_SWAP (5);
16250 obstack_grow (&contents
, &val
, sizeof (val
));
16252 /* The offset of the CU list from the start of the file. */
16253 val
= MAYBE_SWAP (total_len
);
16254 obstack_grow (&contents
, &val
, sizeof (val
));
16255 total_len
+= obstack_object_size (&cu_list
);
16257 /* The offset of the types CU list from the start of the file. */
16258 val
= MAYBE_SWAP (total_len
);
16259 obstack_grow (&contents
, &val
, sizeof (val
));
16260 total_len
+= obstack_object_size (&types_cu_list
);
16262 /* The offset of the address table from the start of the file. */
16263 val
= MAYBE_SWAP (total_len
);
16264 obstack_grow (&contents
, &val
, sizeof (val
));
16265 total_len
+= obstack_object_size (&addr_obstack
);
16267 /* The offset of the symbol table from the start of the file. */
16268 val
= MAYBE_SWAP (total_len
);
16269 obstack_grow (&contents
, &val
, sizeof (val
));
16270 total_len
+= obstack_object_size (&symtab_obstack
);
16272 /* The offset of the constant pool from the start of the file. */
16273 val
= MAYBE_SWAP (total_len
);
16274 obstack_grow (&contents
, &val
, sizeof (val
));
16275 total_len
+= obstack_object_size (&constant_pool
);
16277 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
16279 write_obstack (out_file
, &contents
);
16280 write_obstack (out_file
, &cu_list
);
16281 write_obstack (out_file
, &types_cu_list
);
16282 write_obstack (out_file
, &addr_obstack
);
16283 write_obstack (out_file
, &symtab_obstack
);
16284 write_obstack (out_file
, &constant_pool
);
16288 /* We want to keep the file, so we set cleanup_filename to NULL
16289 here. See unlink_if_set. */
16290 cleanup_filename
= NULL
;
16292 do_cleanups (cleanup
);
16295 /* Implementation of the `save gdb-index' command.
16297 Note that the file format used by this command is documented in the
16298 GDB manual. Any changes here must be documented there. */
16301 save_gdb_index_command (char *arg
, int from_tty
)
16303 struct objfile
*objfile
;
16306 error (_("usage: save gdb-index DIRECTORY"));
16308 ALL_OBJFILES (objfile
)
16312 /* If the objfile does not correspond to an actual file, skip it. */
16313 if (stat (objfile
->name
, &st
) < 0)
16316 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16317 if (dwarf2_per_objfile
)
16319 volatile struct gdb_exception except
;
16321 TRY_CATCH (except
, RETURN_MASK_ERROR
)
16323 write_psymtabs_to_index (objfile
, arg
);
16325 if (except
.reason
< 0)
16326 exception_fprintf (gdb_stderr
, except
,
16327 _("Error while writing index for `%s': "),
16335 int dwarf2_always_disassemble
;
16338 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
16339 struct cmd_list_element
*c
, const char *value
)
16341 fprintf_filtered (file
,
16342 _("Whether to always disassemble "
16343 "DWARF expressions is %s.\n"),
16348 show_check_physname (struct ui_file
*file
, int from_tty
,
16349 struct cmd_list_element
*c
, const char *value
)
16351 fprintf_filtered (file
,
16352 _("Whether to check \"physname\" is %s.\n"),
16356 void _initialize_dwarf2_read (void);
16359 _initialize_dwarf2_read (void)
16361 struct cmd_list_element
*c
;
16363 dwarf2_objfile_data_key
16364 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
16366 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
16367 Set DWARF 2 specific variables.\n\
16368 Configure DWARF 2 variables such as the cache size"),
16369 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
16370 0/*allow-unknown*/, &maintenance_set_cmdlist
);
16372 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
16373 Show DWARF 2 specific variables\n\
16374 Show DWARF 2 variables such as the cache size"),
16375 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
16376 0/*allow-unknown*/, &maintenance_show_cmdlist
);
16378 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
16379 &dwarf2_max_cache_age
, _("\
16380 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
16381 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
16382 A higher limit means that cached compilation units will be stored\n\
16383 in memory longer, and more total memory will be used. Zero disables\n\
16384 caching, which can slow down startup."),
16386 show_dwarf2_max_cache_age
,
16387 &set_dwarf2_cmdlist
,
16388 &show_dwarf2_cmdlist
);
16390 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
16391 &dwarf2_always_disassemble
, _("\
16392 Set whether `info address' always disassembles DWARF expressions."), _("\
16393 Show whether `info address' always disassembles DWARF expressions."), _("\
16394 When enabled, DWARF expressions are always printed in an assembly-like\n\
16395 syntax. When disabled, expressions will be printed in a more\n\
16396 conversational style, when possible."),
16398 show_dwarf2_always_disassemble
,
16399 &set_dwarf2_cmdlist
,
16400 &show_dwarf2_cmdlist
);
16402 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
16403 Set debugging of the dwarf2 DIE reader."), _("\
16404 Show debugging of the dwarf2 DIE reader."), _("\
16405 When enabled (non-zero), DIEs are dumped after they are read in.\n\
16406 The value is the maximum depth to print."),
16409 &setdebuglist
, &showdebuglist
);
16411 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
16412 Set cross-checking of \"physname\" code against demangler."), _("\
16413 Show cross-checking of \"physname\" code against demangler."), _("\
16414 When enabled, GDB's internal \"physname\" code is checked against\n\
16416 NULL
, show_check_physname
,
16417 &setdebuglist
, &showdebuglist
);
16419 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
16421 Save a gdb-index file.\n\
16422 Usage: save gdb-index DIRECTORY"),
16424 set_cmd_completer (c
, filename_completer
);