1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
51 #include "typeprint.h"
54 #include "exceptions.h"
56 #include "completer.h"
63 #include "gdb_string.h"
64 #include "gdb_assert.h"
65 #include <sys/types.h>
72 #define MAP_FAILED ((void *) -1)
76 typedef struct symbol
*symbolp
;
80 /* .debug_info header for a compilation unit
81 Because of alignment constraints, this structure has padding and cannot
82 be mapped directly onto the beginning of the .debug_info section. */
83 typedef struct comp_unit_header
85 unsigned int length
; /* length of the .debug_info
87 unsigned short version
; /* version number -- 2 for DWARF
89 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
90 unsigned char addr_size
; /* byte size of an address -- 4 */
93 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
96 /* .debug_line statement program prologue
97 Because of alignment constraints, this structure has padding and cannot
98 be mapped directly onto the beginning of the .debug_info section. */
99 typedef struct statement_prologue
101 unsigned int total_length
; /* byte length of the statement
103 unsigned short version
; /* version number -- 2 for DWARF
105 unsigned int prologue_length
; /* # bytes between prologue &
107 unsigned char minimum_instruction_length
; /* byte size of
109 unsigned char default_is_stmt
; /* initial value of is_stmt
112 unsigned char line_range
;
113 unsigned char opcode_base
; /* number assigned to first special
115 unsigned char *standard_opcode_lengths
;
119 /* When non-zero, dump DIEs after they are read in. */
120 static int dwarf2_die_debug
= 0;
122 /* When non-zero, cross-check physname against demangler. */
123 static int check_physname
= 0;
127 /* When set, the file that we're processing is known to have debugging
128 info for C++ namespaces. GCC 3.3.x did not produce this information,
129 but later versions do. */
131 static int processing_has_namespace_info
;
133 static const struct objfile_data
*dwarf2_objfile_data_key
;
135 struct dwarf2_section_info
140 /* Not NULL if the section was actually mmapped. */
142 /* Page aligned size of mmapped area. */
143 bfd_size_type map_len
;
144 /* True if we have tried to read this section. */
148 typedef struct dwarf2_section_info dwarf2_section_info_def
;
149 DEF_VEC_O (dwarf2_section_info_def
);
151 /* All offsets in the index are of this type. It must be
152 architecture-independent. */
153 typedef uint32_t offset_type
;
155 DEF_VEC_I (offset_type
);
157 /* A description of the mapped index. The file format is described in
158 a comment by the code that writes the index. */
161 /* Index data format version. */
164 /* The total length of the buffer. */
167 /* A pointer to the address table data. */
168 const gdb_byte
*address_table
;
170 /* Size of the address table data in bytes. */
171 offset_type address_table_size
;
173 /* The symbol table, implemented as a hash table. */
174 const offset_type
*symbol_table
;
176 /* Size in slots, each slot is 2 offset_types. */
177 offset_type symbol_table_slots
;
179 /* A pointer to the constant pool. */
180 const char *constant_pool
;
183 struct dwarf2_per_objfile
185 struct dwarf2_section_info info
;
186 struct dwarf2_section_info abbrev
;
187 struct dwarf2_section_info line
;
188 struct dwarf2_section_info loc
;
189 struct dwarf2_section_info macinfo
;
190 struct dwarf2_section_info macro
;
191 struct dwarf2_section_info str
;
192 struct dwarf2_section_info ranges
;
193 struct dwarf2_section_info frame
;
194 struct dwarf2_section_info eh_frame
;
195 struct dwarf2_section_info gdb_index
;
197 VEC (dwarf2_section_info_def
) *types
;
200 struct objfile
*objfile
;
202 /* A list of all the compilation units. This is used to locate
203 the target compilation unit of a particular reference. */
204 struct dwarf2_per_cu_data
**all_comp_units
;
206 /* The number of compilation units in ALL_COMP_UNITS. */
209 /* The number of .debug_types-related CUs. */
210 int n_type_comp_units
;
212 /* The .debug_types-related CUs. */
213 struct dwarf2_per_cu_data
**type_comp_units
;
215 /* A chain of compilation units that are currently read in, so that
216 they can be freed later. */
217 struct dwarf2_per_cu_data
*read_in_chain
;
219 /* A table mapping .debug_types signatures to its signatured_type entry.
220 This is NULL if the .debug_types section hasn't been read in yet. */
221 htab_t signatured_types
;
223 /* A flag indicating wether this objfile has a section loaded at a
225 int has_section_at_zero
;
227 /* True if we are using the mapped index,
228 or we are faking it for OBJF_READNOW's sake. */
229 unsigned char using_index
;
231 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
232 struct mapped_index
*index_table
;
234 /* When using index_table, this keeps track of all quick_file_names entries.
235 TUs can share line table entries with CUs or other TUs, and there can be
236 a lot more TUs than unique line tables, so we maintain a separate table
237 of all line table entries to support the sharing. */
238 htab_t quick_file_names_table
;
240 /* Set during partial symbol reading, to prevent queueing of full
242 int reading_partial_symbols
;
244 /* Table mapping type .debug_info DIE offsets to types.
245 This is NULL if not allocated yet.
246 It (currently) makes sense to allocate debug_types_type_hash lazily.
247 To keep things simple we allocate both lazily. */
248 htab_t debug_info_type_hash
;
250 /* Table mapping type .debug_types DIE offsets to types.
251 This is NULL if not allocated yet. */
252 htab_t debug_types_type_hash
;
255 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
257 /* Default names of the debugging sections. */
259 /* Note that if the debugging section has been compressed, it might
260 have a name like .zdebug_info. */
262 static const struct dwarf2_debug_sections dwarf2_elf_names
= {
263 { ".debug_info", ".zdebug_info" },
264 { ".debug_abbrev", ".zdebug_abbrev" },
265 { ".debug_line", ".zdebug_line" },
266 { ".debug_loc", ".zdebug_loc" },
267 { ".debug_macinfo", ".zdebug_macinfo" },
268 { ".debug_macro", ".zdebug_macro" },
269 { ".debug_str", ".zdebug_str" },
270 { ".debug_ranges", ".zdebug_ranges" },
271 { ".debug_types", ".zdebug_types" },
272 { ".debug_frame", ".zdebug_frame" },
273 { ".eh_frame", NULL
},
274 { ".gdb_index", ".zgdb_index" },
278 /* local data types */
280 /* We hold several abbreviation tables in memory at the same time. */
281 #ifndef ABBREV_HASH_SIZE
282 #define ABBREV_HASH_SIZE 121
285 /* The data in a compilation unit header, after target2host
286 translation, looks like this. */
287 struct comp_unit_head
291 unsigned char addr_size
;
292 unsigned char signed_addr_p
;
293 unsigned int abbrev_offset
;
295 /* Size of file offsets; either 4 or 8. */
296 unsigned int offset_size
;
298 /* Size of the length field; either 4 or 12. */
299 unsigned int initial_length_size
;
301 /* Offset to the first byte of this compilation unit header in the
302 .debug_info section, for resolving relative reference dies. */
305 /* Offset to first die in this cu from the start of the cu.
306 This will be the first byte following the compilation unit header. */
307 unsigned int first_die_offset
;
310 /* Type used for delaying computation of method physnames.
311 See comments for compute_delayed_physnames. */
312 struct delayed_method_info
314 /* The type to which the method is attached, i.e., its parent class. */
317 /* The index of the method in the type's function fieldlists. */
320 /* The index of the method in the fieldlist. */
323 /* The name of the DIE. */
326 /* The DIE associated with this method. */
327 struct die_info
*die
;
330 typedef struct delayed_method_info delayed_method_info
;
331 DEF_VEC_O (delayed_method_info
);
333 /* Internal state when decoding a particular compilation unit. */
336 /* The objfile containing this compilation unit. */
337 struct objfile
*objfile
;
339 /* The header of the compilation unit. */
340 struct comp_unit_head header
;
342 /* Base address of this compilation unit. */
343 CORE_ADDR base_address
;
345 /* Non-zero if base_address has been set. */
348 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
350 /* The language we are debugging. */
351 enum language language
;
352 const struct language_defn
*language_defn
;
354 const char *producer
;
356 /* The generic symbol table building routines have separate lists for
357 file scope symbols and all all other scopes (local scopes). So
358 we need to select the right one to pass to add_symbol_to_list().
359 We do it by keeping a pointer to the correct list in list_in_scope.
361 FIXME: The original dwarf code just treated the file scope as the
362 first local scope, and all other local scopes as nested local
363 scopes, and worked fine. Check to see if we really need to
364 distinguish these in buildsym.c. */
365 struct pending
**list_in_scope
;
367 /* DWARF abbreviation table associated with this compilation unit. */
368 struct abbrev_info
**dwarf2_abbrevs
;
370 /* Storage for the abbrev table. */
371 struct obstack abbrev_obstack
;
373 /* Hash table holding all the loaded partial DIEs. */
376 /* Storage for things with the same lifetime as this read-in compilation
377 unit, including partial DIEs. */
378 struct obstack comp_unit_obstack
;
380 /* When multiple dwarf2_cu structures are living in memory, this field
381 chains them all together, so that they can be released efficiently.
382 We will probably also want a generation counter so that most-recently-used
383 compilation units are cached... */
384 struct dwarf2_per_cu_data
*read_in_chain
;
386 /* Backchain to our per_cu entry if the tree has been built. */
387 struct dwarf2_per_cu_data
*per_cu
;
389 /* How many compilation units ago was this CU last referenced? */
392 /* A hash table of die offsets for following references. */
395 /* Full DIEs if read in. */
396 struct die_info
*dies
;
398 /* A set of pointers to dwarf2_per_cu_data objects for compilation
399 units referenced by this one. Only set during full symbol processing;
400 partial symbol tables do not have dependencies. */
403 /* Header data from the line table, during full symbol processing. */
404 struct line_header
*line_header
;
406 /* A list of methods which need to have physnames computed
407 after all type information has been read. */
408 VEC (delayed_method_info
) *method_list
;
410 /* Mark used when releasing cached dies. */
411 unsigned int mark
: 1;
413 /* This flag will be set if this compilation unit might include
414 inter-compilation-unit references. */
415 unsigned int has_form_ref_addr
: 1;
417 /* This flag will be set if this compilation unit includes any
418 DW_TAG_namespace DIEs. If we know that there are explicit
419 DIEs for namespaces, we don't need to try to infer them
420 from mangled names. */
421 unsigned int has_namespace_info
: 1;
423 /* This CU references .debug_loc. See the symtab->locations_valid field.
424 This test is imperfect as there may exist optimized debug code not using
425 any location list and still facing inlining issues if handled as
426 unoptimized code. For a future better test see GCC PR other/32998. */
428 unsigned int has_loclist
: 1;
431 /* Persistent data held for a compilation unit, even when not
432 processing it. We put a pointer to this structure in the
433 read_symtab_private field of the psymtab. If we encounter
434 inter-compilation-unit references, we also maintain a sorted
435 list of all compilation units. */
437 struct dwarf2_per_cu_data
439 /* The start offset and length of this compilation unit. 2**29-1
440 bytes should suffice to store the length of any compilation unit
441 - if it doesn't, GDB will fall over anyway.
442 NOTE: Unlike comp_unit_head.length, this length includes
443 initial_length_size. */
445 unsigned int length
: 29;
447 /* Flag indicating this compilation unit will be read in before
448 any of the current compilation units are processed. */
449 unsigned int queued
: 1;
451 /* This flag will be set if we need to load absolutely all DIEs
452 for this compilation unit, instead of just the ones we think
453 are interesting. It gets set if we look for a DIE in the
454 hash table and don't find it. */
455 unsigned int load_all_dies
: 1;
457 /* Non-null if this CU is from .debug_types; in which case it points
458 to the section. Otherwise it's from .debug_info. */
459 struct dwarf2_section_info
*debug_type_section
;
461 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
462 of the CU cache it gets reset to NULL again. */
463 struct dwarf2_cu
*cu
;
465 /* The corresponding objfile. */
466 struct objfile
*objfile
;
468 /* When using partial symbol tables, the 'psymtab' field is active.
469 Otherwise the 'quick' field is active. */
472 /* The partial symbol table associated with this compilation unit,
473 or NULL for partial units (which do not have an associated
475 struct partial_symtab
*psymtab
;
477 /* Data needed by the "quick" functions. */
478 struct dwarf2_per_cu_quick_data
*quick
;
482 /* Entry in the signatured_types hash table. */
484 struct signatured_type
488 /* Offset in .debug_types of the type defined by this TU. */
489 unsigned int type_offset
;
491 /* The CU(/TU) of this type. */
492 struct dwarf2_per_cu_data per_cu
;
495 /* Struct used to pass misc. parameters to read_die_and_children, et
496 al. which are used for both .debug_info and .debug_types dies.
497 All parameters here are unchanging for the life of the call. This
498 struct exists to abstract away the constant parameters of die
501 struct die_reader_specs
503 /* The bfd of this objfile. */
506 /* The CU of the DIE we are parsing. */
507 struct dwarf2_cu
*cu
;
509 /* Pointer to start of section buffer.
510 This is either the start of .debug_info or .debug_types. */
511 const gdb_byte
*buffer
;
514 /* The line number information for a compilation unit (found in the
515 .debug_line section) begins with a "statement program header",
516 which contains the following information. */
519 unsigned int total_length
;
520 unsigned short version
;
521 unsigned int header_length
;
522 unsigned char minimum_instruction_length
;
523 unsigned char maximum_ops_per_instruction
;
524 unsigned char default_is_stmt
;
526 unsigned char line_range
;
527 unsigned char opcode_base
;
529 /* standard_opcode_lengths[i] is the number of operands for the
530 standard opcode whose value is i. This means that
531 standard_opcode_lengths[0] is unused, and the last meaningful
532 element is standard_opcode_lengths[opcode_base - 1]. */
533 unsigned char *standard_opcode_lengths
;
535 /* The include_directories table. NOTE! These strings are not
536 allocated with xmalloc; instead, they are pointers into
537 debug_line_buffer. If you try to free them, `free' will get
539 unsigned int num_include_dirs
, include_dirs_size
;
542 /* The file_names table. NOTE! These strings are not allocated
543 with xmalloc; instead, they are pointers into debug_line_buffer.
544 Don't try to free them directly. */
545 unsigned int num_file_names
, file_names_size
;
549 unsigned int dir_index
;
550 unsigned int mod_time
;
552 int included_p
; /* Non-zero if referenced by the Line Number Program. */
553 struct symtab
*symtab
; /* The associated symbol table, if any. */
556 /* The start and end of the statement program following this
557 header. These point into dwarf2_per_objfile->line_buffer. */
558 gdb_byte
*statement_program_start
, *statement_program_end
;
561 /* When we construct a partial symbol table entry we only
562 need this much information. */
563 struct partial_die_info
565 /* Offset of this DIE. */
568 /* DWARF-2 tag for this DIE. */
569 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
571 /* Assorted flags describing the data found in this DIE. */
572 unsigned int has_children
: 1;
573 unsigned int is_external
: 1;
574 unsigned int is_declaration
: 1;
575 unsigned int has_type
: 1;
576 unsigned int has_specification
: 1;
577 unsigned int has_pc_info
: 1;
579 /* Flag set if the SCOPE field of this structure has been
581 unsigned int scope_set
: 1;
583 /* Flag set if the DIE has a byte_size attribute. */
584 unsigned int has_byte_size
: 1;
586 /* Flag set if any of the DIE's children are template arguments. */
587 unsigned int has_template_arguments
: 1;
589 /* Flag set if fixup_partial_die has been called on this die. */
590 unsigned int fixup_called
: 1;
592 /* The name of this DIE. Normally the value of DW_AT_name, but
593 sometimes a default name for unnamed DIEs. */
596 /* The linkage name, if present. */
597 const char *linkage_name
;
599 /* The scope to prepend to our children. This is generally
600 allocated on the comp_unit_obstack, so will disappear
601 when this compilation unit leaves the cache. */
604 /* The location description associated with this DIE, if any. */
605 struct dwarf_block
*locdesc
;
607 /* If HAS_PC_INFO, the PC range associated with this DIE. */
611 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
612 DW_AT_sibling, if any. */
613 /* NOTE: This member isn't strictly necessary, read_partial_die could
614 return DW_AT_sibling values to its caller load_partial_dies. */
617 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
618 DW_AT_specification (or DW_AT_abstract_origin or
620 unsigned int spec_offset
;
622 /* Pointers to this DIE's parent, first child, and next sibling,
624 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
627 /* This data structure holds the information of an abbrev. */
630 unsigned int number
; /* number identifying abbrev */
631 enum dwarf_tag tag
; /* dwarf tag */
632 unsigned short has_children
; /* boolean */
633 unsigned short num_attrs
; /* number of attributes */
634 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
635 struct abbrev_info
*next
; /* next in chain */
640 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
641 ENUM_BITFIELD(dwarf_form
) form
: 16;
644 /* Attributes have a name and a value. */
647 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
648 ENUM_BITFIELD(dwarf_form
) form
: 15;
650 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
651 field should be in u.str (existing only for DW_STRING) but it is kept
652 here for better struct attribute alignment. */
653 unsigned int string_is_canonical
: 1;
658 struct dwarf_block
*blk
;
662 struct signatured_type
*signatured_type
;
667 /* This data structure holds a complete die structure. */
670 /* DWARF-2 tag for this DIE. */
671 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
673 /* Number of attributes */
674 unsigned char num_attrs
;
676 /* True if we're presently building the full type name for the
677 type derived from this DIE. */
678 unsigned char building_fullname
: 1;
683 /* Offset in .debug_info or .debug_types section. */
686 /* The dies in a compilation unit form an n-ary tree. PARENT
687 points to this die's parent; CHILD points to the first child of
688 this node; and all the children of a given node are chained
689 together via their SIBLING fields. */
690 struct die_info
*child
; /* Its first child, if any. */
691 struct die_info
*sibling
; /* Its next sibling, if any. */
692 struct die_info
*parent
; /* Its parent, if any. */
694 /* An array of attributes, with NUM_ATTRS elements. There may be
695 zero, but it's not common and zero-sized arrays are not
696 sufficiently portable C. */
697 struct attribute attrs
[1];
700 struct function_range
703 CORE_ADDR lowpc
, highpc
;
705 struct function_range
*next
;
708 /* Get at parts of an attribute structure. */
710 #define DW_STRING(attr) ((attr)->u.str)
711 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
712 #define DW_UNSND(attr) ((attr)->u.unsnd)
713 #define DW_BLOCK(attr) ((attr)->u.blk)
714 #define DW_SND(attr) ((attr)->u.snd)
715 #define DW_ADDR(attr) ((attr)->u.addr)
716 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
718 /* Blocks are a bunch of untyped bytes. */
725 #ifndef ATTR_ALLOC_CHUNK
726 #define ATTR_ALLOC_CHUNK 4
729 /* Allocate fields for structs, unions and enums in this size. */
730 #ifndef DW_FIELD_ALLOC_CHUNK
731 #define DW_FIELD_ALLOC_CHUNK 4
734 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
735 but this would require a corresponding change in unpack_field_as_long
737 static int bits_per_byte
= 8;
739 /* The routines that read and process dies for a C struct or C++ class
740 pass lists of data member fields and lists of member function fields
741 in an instance of a field_info structure, as defined below. */
744 /* List of data member and baseclasses fields. */
747 struct nextfield
*next
;
752 *fields
, *baseclasses
;
754 /* Number of fields (including baseclasses). */
757 /* Number of baseclasses. */
760 /* Set if the accesibility of one of the fields is not public. */
761 int non_public_fields
;
763 /* Member function fields array, entries are allocated in the order they
764 are encountered in the object file. */
767 struct nextfnfield
*next
;
768 struct fn_field fnfield
;
772 /* Member function fieldlist array, contains name of possibly overloaded
773 member function, number of overloaded member functions and a pointer
774 to the head of the member function field chain. */
779 struct nextfnfield
*head
;
783 /* Number of entries in the fnfieldlists array. */
786 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
787 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
788 struct typedef_field_list
790 struct typedef_field field
;
791 struct typedef_field_list
*next
;
794 unsigned typedef_field_list_count
;
797 /* One item on the queue of compilation units to read in full symbols
799 struct dwarf2_queue_item
801 struct dwarf2_per_cu_data
*per_cu
;
802 struct dwarf2_queue_item
*next
;
805 /* The current queue. */
806 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
808 /* Loaded secondary compilation units are kept in memory until they
809 have not been referenced for the processing of this many
810 compilation units. Set this to zero to disable caching. Cache
811 sizes of up to at least twenty will improve startup time for
812 typical inter-CU-reference binaries, at an obvious memory cost. */
813 static int dwarf2_max_cache_age
= 5;
815 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
816 struct cmd_list_element
*c
, const char *value
)
818 fprintf_filtered (file
, _("The upper bound on the age of cached "
819 "dwarf2 compilation units is %s.\n"),
824 /* Various complaints about symbol reading that don't abort the process. */
827 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
829 complaint (&symfile_complaints
,
830 _("statement list doesn't fit in .debug_line section"));
834 dwarf2_debug_line_missing_file_complaint (void)
836 complaint (&symfile_complaints
,
837 _(".debug_line section has line data without a file"));
841 dwarf2_debug_line_missing_end_sequence_complaint (void)
843 complaint (&symfile_complaints
,
844 _(".debug_line section has line "
845 "program sequence without an end"));
849 dwarf2_complex_location_expr_complaint (void)
851 complaint (&symfile_complaints
, _("location expression too complex"));
855 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
858 complaint (&symfile_complaints
,
859 _("const value length mismatch for '%s', got %d, expected %d"),
864 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
866 complaint (&symfile_complaints
,
867 _("macro info runs off end of `%s' section"),
868 section
->asection
->name
);
872 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
874 complaint (&symfile_complaints
,
875 _("macro debug info contains a "
876 "malformed macro definition:\n`%s'"),
881 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
883 complaint (&symfile_complaints
,
884 _("invalid attribute class or form for '%s' in '%s'"),
888 /* local function prototypes */
890 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
892 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
895 static void dwarf2_find_base_address (struct die_info
*die
,
896 struct dwarf2_cu
*cu
);
898 static void dwarf2_build_psymtabs_hard (struct objfile
*);
900 static void scan_partial_symbols (struct partial_die_info
*,
901 CORE_ADDR
*, CORE_ADDR
*,
902 int, struct dwarf2_cu
*);
904 static void add_partial_symbol (struct partial_die_info
*,
907 static void add_partial_namespace (struct partial_die_info
*pdi
,
908 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
909 int need_pc
, struct dwarf2_cu
*cu
);
911 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
912 CORE_ADDR
*highpc
, int need_pc
,
913 struct dwarf2_cu
*cu
);
915 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
916 struct dwarf2_cu
*cu
);
918 static void add_partial_subprogram (struct partial_die_info
*pdi
,
919 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
920 int need_pc
, struct dwarf2_cu
*cu
);
922 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
923 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
924 bfd
*abfd
, struct dwarf2_cu
*cu
);
926 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
928 static void psymtab_to_symtab_1 (struct partial_symtab
*);
930 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
932 static void dwarf2_free_abbrev_table (void *);
934 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
937 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
940 static struct partial_die_info
*load_partial_dies (bfd
*,
941 gdb_byte
*, gdb_byte
*,
942 int, struct dwarf2_cu
*);
944 static gdb_byte
*read_partial_die (struct partial_die_info
*,
945 struct abbrev_info
*abbrev
,
947 gdb_byte
*, gdb_byte
*,
950 static struct partial_die_info
*find_partial_die (unsigned int,
953 static void fixup_partial_die (struct partial_die_info
*,
956 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
957 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
959 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
960 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
962 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
964 static int read_1_signed_byte (bfd
*, gdb_byte
*);
966 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
968 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
970 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
972 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
975 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
977 static LONGEST read_checked_initial_length_and_offset
978 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
979 unsigned int *, unsigned int *);
981 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
984 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
986 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
988 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
990 static char *read_indirect_string (bfd
*, gdb_byte
*,
991 const struct comp_unit_head
*,
994 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
996 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
998 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
1000 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1002 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1003 struct dwarf2_cu
*);
1005 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1007 struct dwarf2_cu
*);
1009 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1010 struct dwarf2_cu
*cu
);
1012 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1014 static struct die_info
*die_specification (struct die_info
*die
,
1015 struct dwarf2_cu
**);
1017 static void free_line_header (struct line_header
*lh
);
1019 static void add_file_name (struct line_header
*, char *, unsigned int,
1020 unsigned int, unsigned int);
1022 static struct line_header
*(dwarf_decode_line_header
1023 (unsigned int offset
,
1024 bfd
*abfd
, struct dwarf2_cu
*cu
));
1026 static void dwarf_decode_lines (struct line_header
*, const char *, bfd
*,
1027 struct dwarf2_cu
*, struct partial_symtab
*);
1029 static void dwarf2_start_subfile (char *, const char *, const char *);
1031 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1032 struct dwarf2_cu
*);
1034 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1035 struct dwarf2_cu
*, struct symbol
*);
1037 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1038 struct dwarf2_cu
*);
1040 static void dwarf2_const_value_attr (struct attribute
*attr
,
1043 struct obstack
*obstack
,
1044 struct dwarf2_cu
*cu
, long *value
,
1046 struct dwarf2_locexpr_baton
**baton
);
1048 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1050 static int need_gnat_info (struct dwarf2_cu
*);
1052 static struct type
*die_descriptive_type (struct die_info
*,
1053 struct dwarf2_cu
*);
1055 static void set_descriptive_type (struct type
*, struct die_info
*,
1056 struct dwarf2_cu
*);
1058 static struct type
*die_containing_type (struct die_info
*,
1059 struct dwarf2_cu
*);
1061 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1062 struct dwarf2_cu
*);
1064 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1066 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1068 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1070 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1071 const char *suffix
, int physname
,
1072 struct dwarf2_cu
*cu
);
1074 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1076 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1078 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1080 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1082 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1083 struct dwarf2_cu
*, struct partial_symtab
*);
1085 static int dwarf2_get_pc_bounds (struct die_info
*,
1086 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1087 struct partial_symtab
*);
1089 static void get_scope_pc_bounds (struct die_info
*,
1090 CORE_ADDR
*, CORE_ADDR
*,
1091 struct dwarf2_cu
*);
1093 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1094 CORE_ADDR
, struct dwarf2_cu
*);
1096 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1097 struct dwarf2_cu
*);
1099 static void dwarf2_attach_fields_to_type (struct field_info
*,
1100 struct type
*, struct dwarf2_cu
*);
1102 static void dwarf2_add_member_fn (struct field_info
*,
1103 struct die_info
*, struct type
*,
1104 struct dwarf2_cu
*);
1106 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1108 struct dwarf2_cu
*);
1110 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1112 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1114 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1116 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1118 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1120 static struct type
*read_module_type (struct die_info
*die
,
1121 struct dwarf2_cu
*cu
);
1123 static const char *namespace_name (struct die_info
*die
,
1124 int *is_anonymous
, struct dwarf2_cu
*);
1126 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1128 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1130 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1131 struct dwarf2_cu
*);
1133 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1135 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1137 gdb_byte
**new_info_ptr
,
1138 struct die_info
*parent
);
1140 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1142 gdb_byte
**new_info_ptr
,
1143 struct die_info
*parent
);
1145 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1147 gdb_byte
**new_info_ptr
,
1148 struct die_info
*parent
);
1150 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1151 struct die_info
**, gdb_byte
*,
1154 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1156 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1159 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1161 static const char *dwarf2_full_name (char *name
,
1162 struct die_info
*die
,
1163 struct dwarf2_cu
*cu
);
1165 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1166 struct dwarf2_cu
**);
1168 static char *dwarf_tag_name (unsigned int);
1170 static char *dwarf_attr_name (unsigned int);
1172 static char *dwarf_form_name (unsigned int);
1174 static char *dwarf_bool_name (unsigned int);
1176 static char *dwarf_type_encoding_name (unsigned int);
1179 static char *dwarf_cfi_name (unsigned int);
1182 static struct die_info
*sibling_die (struct die_info
*);
1184 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1186 static void dump_die_for_error (struct die_info
*);
1188 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1191 /*static*/ void dump_die (struct die_info
*, int max_level
);
1193 static void store_in_ref_table (struct die_info
*,
1194 struct dwarf2_cu
*);
1196 static int is_ref_attr (struct attribute
*);
1198 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1200 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1202 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1204 struct dwarf2_cu
**);
1206 static struct die_info
*follow_die_ref (struct die_info
*,
1208 struct dwarf2_cu
**);
1210 static struct die_info
*follow_die_sig (struct die_info
*,
1212 struct dwarf2_cu
**);
1214 static struct signatured_type
*lookup_signatured_type_at_offset
1215 (struct objfile
*objfile
,
1216 struct dwarf2_section_info
*section
,
1217 unsigned int offset
);
1219 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1220 struct dwarf2_section_info
*sect
,
1221 unsigned int offset
);
1223 static void read_signatured_type (struct objfile
*,
1224 struct signatured_type
*type_sig
);
1226 /* memory allocation interface */
1228 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1230 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1232 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1234 static void initialize_cu_func_list (struct dwarf2_cu
*);
1236 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1237 struct dwarf2_cu
*);
1239 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1240 char *, bfd
*, struct dwarf2_cu
*,
1241 struct dwarf2_section_info
*,
1244 static int attr_form_is_block (struct attribute
*);
1246 static int attr_form_is_section_offset (struct attribute
*);
1248 static int attr_form_is_constant (struct attribute
*);
1250 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1251 struct dwarf2_loclist_baton
*baton
,
1252 struct attribute
*attr
);
1254 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1256 struct dwarf2_cu
*cu
);
1258 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1259 struct abbrev_info
*abbrev
,
1260 struct dwarf2_cu
*cu
);
1262 static void free_stack_comp_unit (void *);
1264 static hashval_t
partial_die_hash (const void *item
);
1266 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1268 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1269 (unsigned int offset
, struct objfile
*objfile
);
1271 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1272 (unsigned int offset
, struct objfile
*objfile
);
1274 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1275 struct objfile
*objfile
);
1277 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1278 struct die_info
*comp_unit_die
);
1280 static void free_one_comp_unit (void *);
1282 static void free_cached_comp_units (void *);
1284 static void age_cached_comp_units (void);
1286 static void free_one_cached_comp_unit (void *);
1288 static struct type
*set_die_type (struct die_info
*, struct type
*,
1289 struct dwarf2_cu
*);
1291 static void create_all_comp_units (struct objfile
*);
1293 static int create_debug_types_hash_table (struct objfile
*objfile
);
1295 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1298 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1300 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1301 struct dwarf2_per_cu_data
*);
1303 static void dwarf2_mark (struct dwarf2_cu
*);
1305 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1307 static struct type
*get_die_type_at_offset (unsigned int,
1308 struct dwarf2_per_cu_data
*per_cu
);
1310 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1312 static void dwarf2_release_queue (void *dummy
);
1314 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1315 struct objfile
*objfile
);
1317 static void process_queue (struct objfile
*objfile
);
1319 static void find_file_and_directory (struct die_info
*die
,
1320 struct dwarf2_cu
*cu
,
1321 char **name
, char **comp_dir
);
1323 static char *file_full_name (int file
, struct line_header
*lh
,
1324 const char *comp_dir
);
1326 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1329 unsigned int buffer_size
,
1332 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1333 struct dwarf2_cu
*cu
);
1335 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1339 /* Convert VALUE between big- and little-endian. */
1341 byte_swap (offset_type value
)
1345 result
= (value
& 0xff) << 24;
1346 result
|= (value
& 0xff00) << 8;
1347 result
|= (value
& 0xff0000) >> 8;
1348 result
|= (value
& 0xff000000) >> 24;
1352 #define MAYBE_SWAP(V) byte_swap (V)
1355 #define MAYBE_SWAP(V) (V)
1356 #endif /* WORDS_BIGENDIAN */
1358 /* The suffix for an index file. */
1359 #define INDEX_SUFFIX ".gdb-index"
1361 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1362 struct dwarf2_cu
*cu
);
1364 /* Try to locate the sections we need for DWARF 2 debugging
1365 information and return true if we have enough to do something.
1366 NAMES points to the dwarf2 section names, or is NULL if the standard
1367 ELF names are used. */
1370 dwarf2_has_info (struct objfile
*objfile
,
1371 const struct dwarf2_debug_sections
*names
)
1373 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1374 if (!dwarf2_per_objfile
)
1376 /* Initialize per-objfile state. */
1377 struct dwarf2_per_objfile
*data
1378 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1380 memset (data
, 0, sizeof (*data
));
1381 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1382 dwarf2_per_objfile
= data
;
1384 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1386 dwarf2_per_objfile
->objfile
= objfile
;
1388 return (dwarf2_per_objfile
->info
.asection
!= NULL
1389 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1392 /* When loading sections, we look either for uncompressed section or for
1393 compressed section names. */
1396 section_is_p (const char *section_name
,
1397 const struct dwarf2_section_names
*names
)
1399 if (names
->normal
!= NULL
1400 && strcmp (section_name
, names
->normal
) == 0)
1402 if (names
->compressed
!= NULL
1403 && strcmp (section_name
, names
->compressed
) == 0)
1408 /* This function is mapped across the sections and remembers the
1409 offset and size of each of the debugging sections we are interested
1413 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1415 const struct dwarf2_debug_sections
*names
;
1418 names
= &dwarf2_elf_names
;
1420 names
= (const struct dwarf2_debug_sections
*) vnames
;
1422 if (section_is_p (sectp
->name
, &names
->info
))
1424 dwarf2_per_objfile
->info
.asection
= sectp
;
1425 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1427 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1429 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1430 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1432 else if (section_is_p (sectp
->name
, &names
->line
))
1434 dwarf2_per_objfile
->line
.asection
= sectp
;
1435 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1437 else if (section_is_p (sectp
->name
, &names
->loc
))
1439 dwarf2_per_objfile
->loc
.asection
= sectp
;
1440 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1442 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1444 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1445 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1447 else if (section_is_p (sectp
->name
, &names
->macro
))
1449 dwarf2_per_objfile
->macro
.asection
= sectp
;
1450 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1452 else if (section_is_p (sectp
->name
, &names
->str
))
1454 dwarf2_per_objfile
->str
.asection
= sectp
;
1455 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1457 else if (section_is_p (sectp
->name
, &names
->frame
))
1459 dwarf2_per_objfile
->frame
.asection
= sectp
;
1460 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1462 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1464 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1466 if (aflag
& SEC_HAS_CONTENTS
)
1468 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1469 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1472 else if (section_is_p (sectp
->name
, &names
->ranges
))
1474 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1475 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1477 else if (section_is_p (sectp
->name
, &names
->types
))
1479 struct dwarf2_section_info type_section
;
1481 memset (&type_section
, 0, sizeof (type_section
));
1482 type_section
.asection
= sectp
;
1483 type_section
.size
= bfd_get_section_size (sectp
);
1485 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1488 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1490 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1491 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1494 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1495 && bfd_section_vma (abfd
, sectp
) == 0)
1496 dwarf2_per_objfile
->has_section_at_zero
= 1;
1499 /* Decompress a section that was compressed using zlib. Store the
1500 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1503 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1504 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1506 bfd
*abfd
= objfile
->obfd
;
1508 error (_("Support for zlib-compressed DWARF data (from '%s') "
1509 "is disabled in this copy of GDB"),
1510 bfd_get_filename (abfd
));
1512 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1513 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1514 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1515 bfd_size_type uncompressed_size
;
1516 gdb_byte
*uncompressed_buffer
;
1519 int header_size
= 12;
1521 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1522 || bfd_bread (compressed_buffer
,
1523 compressed_size
, abfd
) != compressed_size
)
1524 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1525 bfd_get_filename (abfd
));
1527 /* Read the zlib header. In this case, it should be "ZLIB" followed
1528 by the uncompressed section size, 8 bytes in big-endian order. */
1529 if (compressed_size
< header_size
1530 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1531 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1532 bfd_get_filename (abfd
));
1533 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1534 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1535 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1536 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1537 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1538 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1539 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1540 uncompressed_size
+= compressed_buffer
[11];
1542 /* It is possible the section consists of several compressed
1543 buffers concatenated together, so we uncompress in a loop. */
1547 strm
.avail_in
= compressed_size
- header_size
;
1548 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1549 strm
.avail_out
= uncompressed_size
;
1550 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1552 rc
= inflateInit (&strm
);
1553 while (strm
.avail_in
> 0)
1556 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1557 bfd_get_filename (abfd
), rc
);
1558 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1559 + (uncompressed_size
- strm
.avail_out
));
1560 rc
= inflate (&strm
, Z_FINISH
);
1561 if (rc
!= Z_STREAM_END
)
1562 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1563 bfd_get_filename (abfd
), rc
);
1564 rc
= inflateReset (&strm
);
1566 rc
= inflateEnd (&strm
);
1568 || strm
.avail_out
!= 0)
1569 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1570 bfd_get_filename (abfd
), rc
);
1572 do_cleanups (cleanup
);
1573 *outbuf
= uncompressed_buffer
;
1574 *outsize
= uncompressed_size
;
1578 /* A helper function that decides whether a section is empty. */
1581 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1583 return info
->asection
== NULL
|| info
->size
== 0;
1586 /* Read the contents of the section SECTP from object file specified by
1587 OBJFILE, store info about the section into INFO.
1588 If the section is compressed, uncompress it before returning. */
1591 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1593 bfd
*abfd
= objfile
->obfd
;
1594 asection
*sectp
= info
->asection
;
1595 gdb_byte
*buf
, *retbuf
;
1596 unsigned char header
[4];
1600 info
->buffer
= NULL
;
1601 info
->map_addr
= NULL
;
1604 if (dwarf2_section_empty_p (info
))
1607 /* Check if the file has a 4-byte header indicating compression. */
1608 if (info
->size
> sizeof (header
)
1609 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1610 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1612 /* Upon decompression, update the buffer and its size. */
1613 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1615 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1623 pagesize
= getpagesize ();
1625 /* Only try to mmap sections which are large enough: we don't want to
1626 waste space due to fragmentation. Also, only try mmap for sections
1627 without relocations. */
1629 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1631 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1632 MAP_PRIVATE
, sectp
->filepos
,
1633 &info
->map_addr
, &info
->map_len
);
1635 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1637 #if HAVE_POSIX_MADVISE
1638 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1645 /* If we get here, we are a normal, not-compressed section. */
1647 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1649 /* When debugging .o files, we may need to apply relocations; see
1650 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1651 We never compress sections in .o files, so we only need to
1652 try this when the section is not compressed. */
1653 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1656 info
->buffer
= retbuf
;
1660 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1661 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1662 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1663 bfd_get_filename (abfd
));
1666 /* A helper function that returns the size of a section in a safe way.
1667 If you are positive that the section has been read before using the
1668 size, then it is safe to refer to the dwarf2_section_info object's
1669 "size" field directly. In other cases, you must call this
1670 function, because for compressed sections the size field is not set
1671 correctly until the section has been read. */
1673 static bfd_size_type
1674 dwarf2_section_size (struct objfile
*objfile
,
1675 struct dwarf2_section_info
*info
)
1678 dwarf2_read_section (objfile
, info
);
1682 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1686 dwarf2_get_section_info (struct objfile
*objfile
,
1687 enum dwarf2_section_enum sect
,
1688 asection
**sectp
, gdb_byte
**bufp
,
1689 bfd_size_type
*sizep
)
1691 struct dwarf2_per_objfile
*data
1692 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1693 struct dwarf2_section_info
*info
;
1695 /* We may see an objfile without any DWARF, in which case we just
1706 case DWARF2_DEBUG_FRAME
:
1707 info
= &data
->frame
;
1709 case DWARF2_EH_FRAME
:
1710 info
= &data
->eh_frame
;
1713 gdb_assert_not_reached ("unexpected section");
1716 dwarf2_read_section (objfile
, info
);
1718 *sectp
= info
->asection
;
1719 *bufp
= info
->buffer
;
1720 *sizep
= info
->size
;
1724 /* DWARF quick_symbols_functions support. */
1726 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1727 unique line tables, so we maintain a separate table of all .debug_line
1728 derived entries to support the sharing.
1729 All the quick functions need is the list of file names. We discard the
1730 line_header when we're done and don't need to record it here. */
1731 struct quick_file_names
1733 /* The offset in .debug_line of the line table. We hash on this. */
1734 unsigned int offset
;
1736 /* The number of entries in file_names, real_names. */
1737 unsigned int num_file_names
;
1739 /* The file names from the line table, after being run through
1741 const char **file_names
;
1743 /* The file names from the line table after being run through
1744 gdb_realpath. These are computed lazily. */
1745 const char **real_names
;
1748 /* When using the index (and thus not using psymtabs), each CU has an
1749 object of this type. This is used to hold information needed by
1750 the various "quick" methods. */
1751 struct dwarf2_per_cu_quick_data
1753 /* The file table. This can be NULL if there was no file table
1754 or it's currently not read in.
1755 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1756 struct quick_file_names
*file_names
;
1758 /* The corresponding symbol table. This is NULL if symbols for this
1759 CU have not yet been read. */
1760 struct symtab
*symtab
;
1762 /* A temporary mark bit used when iterating over all CUs in
1763 expand_symtabs_matching. */
1764 unsigned int mark
: 1;
1766 /* True if we've tried to read the file table and found there isn't one.
1767 There will be no point in trying to read it again next time. */
1768 unsigned int no_file_data
: 1;
1771 /* Hash function for a quick_file_names. */
1774 hash_file_name_entry (const void *e
)
1776 const struct quick_file_names
*file_data
= e
;
1778 return file_data
->offset
;
1781 /* Equality function for a quick_file_names. */
1784 eq_file_name_entry (const void *a
, const void *b
)
1786 const struct quick_file_names
*ea
= a
;
1787 const struct quick_file_names
*eb
= b
;
1789 return ea
->offset
== eb
->offset
;
1792 /* Delete function for a quick_file_names. */
1795 delete_file_name_entry (void *e
)
1797 struct quick_file_names
*file_data
= e
;
1800 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1802 xfree ((void*) file_data
->file_names
[i
]);
1803 if (file_data
->real_names
)
1804 xfree ((void*) file_data
->real_names
[i
]);
1807 /* The space for the struct itself lives on objfile_obstack,
1808 so we don't free it here. */
1811 /* Create a quick_file_names hash table. */
1814 create_quick_file_names_table (unsigned int nr_initial_entries
)
1816 return htab_create_alloc (nr_initial_entries
,
1817 hash_file_name_entry
, eq_file_name_entry
,
1818 delete_file_name_entry
, xcalloc
, xfree
);
1821 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1822 have to be created afterwards. You should call age_cached_comp_units after
1823 processing PER_CU->CU. dw2_setup must have been already called. */
1826 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1828 if (per_cu
->debug_type_section
)
1829 read_signatured_type_at_offset (per_cu
->objfile
,
1830 per_cu
->debug_type_section
,
1833 load_full_comp_unit (per_cu
, per_cu
->objfile
);
1835 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1837 gdb_assert (per_cu
->cu
!= NULL
);
1840 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1844 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1845 struct dwarf2_per_cu_data
*per_cu
)
1847 struct cleanup
*back_to
;
1849 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1851 queue_comp_unit (per_cu
, objfile
);
1855 process_queue (objfile
);
1857 /* Age the cache, releasing compilation units that have not
1858 been used recently. */
1859 age_cached_comp_units ();
1861 do_cleanups (back_to
);
1864 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1865 the objfile from which this CU came. Returns the resulting symbol
1868 static struct symtab
*
1869 dw2_instantiate_symtab (struct objfile
*objfile
,
1870 struct dwarf2_per_cu_data
*per_cu
)
1872 if (!per_cu
->v
.quick
->symtab
)
1874 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1875 increment_reading_symtab ();
1876 dw2_do_instantiate_symtab (objfile
, per_cu
);
1877 do_cleanups (back_to
);
1879 return per_cu
->v
.quick
->symtab
;
1882 /* Return the CU given its index. */
1884 static struct dwarf2_per_cu_data
*
1885 dw2_get_cu (int index
)
1887 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1889 index
-= dwarf2_per_objfile
->n_comp_units
;
1890 return dwarf2_per_objfile
->type_comp_units
[index
];
1892 return dwarf2_per_objfile
->all_comp_units
[index
];
1895 /* A helper function that knows how to read a 64-bit value in a way
1896 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1900 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1902 if (sizeof (ULONGEST
) < 8)
1906 /* Ignore the upper 4 bytes if they are all zero. */
1907 for (i
= 0; i
< 4; ++i
)
1908 if (bytes
[i
+ 4] != 0)
1911 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1914 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1918 /* Read the CU list from the mapped index, and use it to create all
1919 the CU objects for this objfile. Return 0 if something went wrong,
1920 1 if everything went ok. */
1923 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1924 offset_type cu_list_elements
)
1928 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1929 dwarf2_per_objfile
->all_comp_units
1930 = obstack_alloc (&objfile
->objfile_obstack
,
1931 dwarf2_per_objfile
->n_comp_units
1932 * sizeof (struct dwarf2_per_cu_data
*));
1934 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1936 struct dwarf2_per_cu_data
*the_cu
;
1937 ULONGEST offset
, length
;
1939 if (!extract_cu_value (cu_list
, &offset
)
1940 || !extract_cu_value (cu_list
+ 8, &length
))
1944 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1945 struct dwarf2_per_cu_data
);
1946 the_cu
->offset
= offset
;
1947 the_cu
->length
= length
;
1948 the_cu
->objfile
= objfile
;
1949 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1950 struct dwarf2_per_cu_quick_data
);
1951 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1957 /* Create the signatured type hash table from the index. */
1960 create_signatured_type_table_from_index (struct objfile
*objfile
,
1961 struct dwarf2_section_info
*section
,
1962 const gdb_byte
*bytes
,
1963 offset_type elements
)
1966 htab_t sig_types_hash
;
1968 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1969 dwarf2_per_objfile
->type_comp_units
1970 = obstack_alloc (&objfile
->objfile_obstack
,
1971 dwarf2_per_objfile
->n_type_comp_units
1972 * sizeof (struct dwarf2_per_cu_data
*));
1974 sig_types_hash
= allocate_signatured_type_table (objfile
);
1976 for (i
= 0; i
< elements
; i
+= 3)
1978 struct signatured_type
*type_sig
;
1979 ULONGEST offset
, type_offset
, signature
;
1982 if (!extract_cu_value (bytes
, &offset
)
1983 || !extract_cu_value (bytes
+ 8, &type_offset
))
1985 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1988 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1989 struct signatured_type
);
1990 type_sig
->signature
= signature
;
1991 type_sig
->type_offset
= type_offset
;
1992 type_sig
->per_cu
.debug_type_section
= section
;
1993 type_sig
->per_cu
.offset
= offset
;
1994 type_sig
->per_cu
.objfile
= objfile
;
1995 type_sig
->per_cu
.v
.quick
1996 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1997 struct dwarf2_per_cu_quick_data
);
1999 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
2002 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
2005 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2010 /* Read the address map data from the mapped index, and use it to
2011 populate the objfile's psymtabs_addrmap. */
2014 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2016 const gdb_byte
*iter
, *end
;
2017 struct obstack temp_obstack
;
2018 struct addrmap
*mutable_map
;
2019 struct cleanup
*cleanup
;
2022 obstack_init (&temp_obstack
);
2023 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2024 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2026 iter
= index
->address_table
;
2027 end
= iter
+ index
->address_table_size
;
2029 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2033 ULONGEST hi
, lo
, cu_index
;
2034 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2036 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2038 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2041 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2042 dw2_get_cu (cu_index
));
2045 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2046 &objfile
->objfile_obstack
);
2047 do_cleanups (cleanup
);
2050 /* The hash function for strings in the mapped index. This is the same as
2051 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2052 implementation. This is necessary because the hash function is tied to the
2053 format of the mapped index file. The hash values do not have to match with
2056 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2059 mapped_index_string_hash (int index_version
, const void *p
)
2061 const unsigned char *str
= (const unsigned char *) p
;
2065 while ((c
= *str
++) != 0)
2067 if (index_version
>= 5)
2069 r
= r
* 67 + c
- 113;
2075 /* Find a slot in the mapped index INDEX for the object named NAME.
2076 If NAME is found, set *VEC_OUT to point to the CU vector in the
2077 constant pool and return 1. If NAME cannot be found, return 0. */
2080 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2081 offset_type
**vec_out
)
2083 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2085 offset_type slot
, step
;
2086 int (*cmp
) (const char *, const char *);
2088 if (current_language
->la_language
== language_cplus
2089 || current_language
->la_language
== language_java
2090 || current_language
->la_language
== language_fortran
)
2092 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2094 const char *paren
= strchr (name
, '(');
2100 dup
= xmalloc (paren
- name
+ 1);
2101 memcpy (dup
, name
, paren
- name
);
2102 dup
[paren
- name
] = 0;
2104 make_cleanup (xfree
, dup
);
2109 /* Index version 4 did not support case insensitive searches. But the
2110 indexes for case insensitive languages are built in lowercase, therefore
2111 simulate our NAME being searched is also lowercased. */
2112 hash
= mapped_index_string_hash ((index
->version
== 4
2113 && case_sensitivity
== case_sensitive_off
2114 ? 5 : index
->version
),
2117 slot
= hash
& (index
->symbol_table_slots
- 1);
2118 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2119 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2123 /* Convert a slot number to an offset into the table. */
2124 offset_type i
= 2 * slot
;
2126 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2128 do_cleanups (back_to
);
2132 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2133 if (!cmp (name
, str
))
2135 *vec_out
= (offset_type
*) (index
->constant_pool
2136 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2137 do_cleanups (back_to
);
2141 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2145 /* Read the index file. If everything went ok, initialize the "quick"
2146 elements of all the CUs and return 1. Otherwise, return 0. */
2149 dwarf2_read_index (struct objfile
*objfile
)
2152 struct mapped_index
*map
;
2153 offset_type
*metadata
;
2154 const gdb_byte
*cu_list
;
2155 const gdb_byte
*types_list
= NULL
;
2156 offset_type version
, cu_list_elements
;
2157 offset_type types_list_elements
= 0;
2160 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2163 /* Older elfutils strip versions could keep the section in the main
2164 executable while splitting it for the separate debug info file. */
2165 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2166 & SEC_HAS_CONTENTS
) == 0)
2169 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2171 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2172 /* Version check. */
2173 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2174 /* Versions earlier than 3 emitted every copy of a psymbol. This
2175 causes the index to behave very poorly for certain requests. Version 3
2176 contained incomplete addrmap. So, it seems better to just ignore such
2177 indices. Index version 4 uses a different hash function than index
2178 version 5 and later. */
2181 /* Indexes with higher version than the one supported by GDB may be no
2182 longer backward compatible. */
2186 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2187 map
->version
= version
;
2188 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2190 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2193 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2194 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2198 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2199 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2200 - MAYBE_SWAP (metadata
[i
]))
2204 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2205 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2206 - MAYBE_SWAP (metadata
[i
]));
2209 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2210 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2211 - MAYBE_SWAP (metadata
[i
]))
2212 / (2 * sizeof (offset_type
)));
2215 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2217 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2220 if (types_list_elements
)
2222 struct dwarf2_section_info
*section
;
2224 /* We can only handle a single .debug_types when we have an
2226 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2229 section
= VEC_index (dwarf2_section_info_def
,
2230 dwarf2_per_objfile
->types
, 0);
2232 if (!create_signatured_type_table_from_index (objfile
, section
,
2234 types_list_elements
))
2238 create_addrmap_from_index (objfile
, map
);
2240 dwarf2_per_objfile
->index_table
= map
;
2241 dwarf2_per_objfile
->using_index
= 1;
2242 dwarf2_per_objfile
->quick_file_names_table
=
2243 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2248 /* A helper for the "quick" functions which sets the global
2249 dwarf2_per_objfile according to OBJFILE. */
2252 dw2_setup (struct objfile
*objfile
)
2254 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2255 gdb_assert (dwarf2_per_objfile
);
2258 /* A helper for the "quick" functions which attempts to read the line
2259 table for THIS_CU. */
2261 static struct quick_file_names
*
2262 dw2_get_file_names (struct objfile
*objfile
,
2263 struct dwarf2_per_cu_data
*this_cu
)
2265 bfd
*abfd
= objfile
->obfd
;
2266 struct line_header
*lh
;
2267 struct attribute
*attr
;
2268 struct cleanup
*cleanups
;
2269 struct die_info
*comp_unit_die
;
2270 struct dwarf2_section_info
* sec
;
2271 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2272 int has_children
, i
;
2273 struct dwarf2_cu cu
;
2274 unsigned int bytes_read
, buffer_size
;
2275 struct die_reader_specs reader_specs
;
2276 char *name
, *comp_dir
;
2278 struct quick_file_names
*qfn
;
2279 unsigned int line_offset
;
2281 if (this_cu
->v
.quick
->file_names
!= NULL
)
2282 return this_cu
->v
.quick
->file_names
;
2283 /* If we know there is no line data, no point in looking again. */
2284 if (this_cu
->v
.quick
->no_file_data
)
2287 init_one_comp_unit (&cu
, objfile
);
2288 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2290 if (this_cu
->debug_type_section
)
2291 sec
= this_cu
->debug_type_section
;
2293 sec
= &dwarf2_per_objfile
->info
;
2294 dwarf2_read_section (objfile
, sec
);
2295 buffer_size
= sec
->size
;
2296 buffer
= sec
->buffer
;
2297 info_ptr
= buffer
+ this_cu
->offset
;
2298 beg_of_comp_unit
= info_ptr
;
2300 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2301 buffer
, buffer_size
,
2304 /* Complete the cu_header. */
2305 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2306 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2309 cu
.per_cu
= this_cu
;
2311 dwarf2_read_abbrevs (abfd
, &cu
);
2312 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2314 if (this_cu
->debug_type_section
)
2315 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2316 init_cu_die_reader (&reader_specs
, &cu
);
2317 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2323 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2326 struct quick_file_names find_entry
;
2328 line_offset
= DW_UNSND (attr
);
2330 /* We may have already read in this line header (TU line header sharing).
2331 If we have we're done. */
2332 find_entry
.offset
= line_offset
;
2333 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2334 &find_entry
, INSERT
);
2337 do_cleanups (cleanups
);
2338 this_cu
->v
.quick
->file_names
= *slot
;
2342 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2346 do_cleanups (cleanups
);
2347 this_cu
->v
.quick
->no_file_data
= 1;
2351 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2352 qfn
->offset
= line_offset
;
2353 gdb_assert (slot
!= NULL
);
2356 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2358 qfn
->num_file_names
= lh
->num_file_names
;
2359 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2360 lh
->num_file_names
* sizeof (char *));
2361 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2362 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2363 qfn
->real_names
= NULL
;
2365 free_line_header (lh
);
2366 do_cleanups (cleanups
);
2368 this_cu
->v
.quick
->file_names
= qfn
;
2372 /* A helper for the "quick" functions which computes and caches the
2373 real path for a given file name from the line table. */
2376 dw2_get_real_path (struct objfile
*objfile
,
2377 struct quick_file_names
*qfn
, int index
)
2379 if (qfn
->real_names
== NULL
)
2380 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2381 qfn
->num_file_names
, sizeof (char *));
2383 if (qfn
->real_names
[index
] == NULL
)
2384 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2386 return qfn
->real_names
[index
];
2389 static struct symtab
*
2390 dw2_find_last_source_symtab (struct objfile
*objfile
)
2394 dw2_setup (objfile
);
2395 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2396 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2399 /* Traversal function for dw2_forget_cached_source_info. */
2402 dw2_free_cached_file_names (void **slot
, void *info
)
2404 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2406 if (file_data
->real_names
)
2410 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2412 xfree ((void*) file_data
->real_names
[i
]);
2413 file_data
->real_names
[i
] = NULL
;
2421 dw2_forget_cached_source_info (struct objfile
*objfile
)
2423 dw2_setup (objfile
);
2425 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2426 dw2_free_cached_file_names
, NULL
);
2430 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2431 const char *full_path
, const char *real_path
,
2432 struct symtab
**result
)
2435 int check_basename
= lbasename (name
) == name
;
2436 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2438 dw2_setup (objfile
);
2440 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2441 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2444 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2445 struct quick_file_names
*file_data
;
2447 if (per_cu
->v
.quick
->symtab
)
2450 file_data
= dw2_get_file_names (objfile
, per_cu
);
2451 if (file_data
== NULL
)
2454 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2456 const char *this_name
= file_data
->file_names
[j
];
2458 if (FILENAME_CMP (name
, this_name
) == 0)
2460 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2464 if (check_basename
&& ! base_cu
2465 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2468 if (full_path
!= NULL
)
2470 const char *this_real_name
= dw2_get_real_path (objfile
,
2473 if (this_real_name
!= NULL
2474 && FILENAME_CMP (full_path
, this_real_name
) == 0)
2476 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2481 if (real_path
!= NULL
)
2483 const char *this_real_name
= dw2_get_real_path (objfile
,
2486 if (this_real_name
!= NULL
2487 && FILENAME_CMP (real_path
, this_real_name
) == 0)
2489 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2498 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2505 static struct symtab
*
2506 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2507 const char *name
, domain_enum domain
)
2509 /* We do all the work in the pre_expand_symtabs_matching hook
2514 /* A helper function that expands all symtabs that hold an object
2518 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2520 dw2_setup (objfile
);
2522 /* index_table is NULL if OBJF_READNOW. */
2523 if (dwarf2_per_objfile
->index_table
)
2527 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2530 offset_type i
, len
= MAYBE_SWAP (*vec
);
2531 for (i
= 0; i
< len
; ++i
)
2533 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2534 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2536 dw2_instantiate_symtab (objfile
, per_cu
);
2543 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2544 enum block_enum block_kind
, const char *name
,
2547 dw2_do_expand_symtabs_matching (objfile
, name
);
2551 dw2_print_stats (struct objfile
*objfile
)
2555 dw2_setup (objfile
);
2557 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2558 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2560 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2562 if (!per_cu
->v
.quick
->symtab
)
2565 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2569 dw2_dump (struct objfile
*objfile
)
2571 /* Nothing worth printing. */
2575 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2576 struct section_offsets
*delta
)
2578 /* There's nothing to relocate here. */
2582 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2583 const char *func_name
)
2585 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2589 dw2_expand_all_symtabs (struct objfile
*objfile
)
2593 dw2_setup (objfile
);
2595 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2596 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2598 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2600 dw2_instantiate_symtab (objfile
, per_cu
);
2605 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2606 const char *filename
)
2610 dw2_setup (objfile
);
2612 /* We don't need to consider type units here.
2613 This is only called for examining code, e.g. expand_line_sal.
2614 There can be an order of magnitude (or more) more type units
2615 than comp units, and we avoid them if we can. */
2617 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2620 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2621 struct quick_file_names
*file_data
;
2623 if (per_cu
->v
.quick
->symtab
)
2626 file_data
= dw2_get_file_names (objfile
, per_cu
);
2627 if (file_data
== NULL
)
2630 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2632 const char *this_name
= file_data
->file_names
[j
];
2633 if (FILENAME_CMP (this_name
, filename
) == 0)
2635 dw2_instantiate_symtab (objfile
, per_cu
);
2643 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2645 struct dwarf2_per_cu_data
*per_cu
;
2647 struct quick_file_names
*file_data
;
2649 dw2_setup (objfile
);
2651 /* index_table is NULL if OBJF_READNOW. */
2652 if (!dwarf2_per_objfile
->index_table
)
2655 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2659 /* Note that this just looks at the very first one named NAME -- but
2660 actually we are looking for a function. find_main_filename
2661 should be rewritten so that it doesn't require a custom hook. It
2662 could just use the ordinary symbol tables. */
2663 /* vec[0] is the length, which must always be >0. */
2664 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2666 file_data
= dw2_get_file_names (objfile
, per_cu
);
2667 if (file_data
== NULL
)
2670 return file_data
->file_names
[file_data
->num_file_names
- 1];
2674 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2675 struct objfile
*objfile
, int global
,
2676 int (*callback
) (struct block
*,
2677 struct symbol
*, void *),
2678 void *data
, symbol_compare_ftype
*match
,
2679 symbol_compare_ftype
*ordered_compare
)
2681 /* Currently unimplemented; used for Ada. The function can be called if the
2682 current language is Ada for a non-Ada objfile using GNU index. As Ada
2683 does not look for non-Ada symbols this function should just return. */
2687 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2688 int (*file_matcher
) (const char *, void *),
2689 int (*name_matcher
) (const char *, void *),
2690 enum search_domain kind
,
2695 struct mapped_index
*index
;
2697 dw2_setup (objfile
);
2699 /* index_table is NULL if OBJF_READNOW. */
2700 if (!dwarf2_per_objfile
->index_table
)
2702 index
= dwarf2_per_objfile
->index_table
;
2704 if (file_matcher
!= NULL
)
2705 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2706 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2709 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2710 struct quick_file_names
*file_data
;
2712 per_cu
->v
.quick
->mark
= 0;
2713 if (per_cu
->v
.quick
->symtab
)
2716 file_data
= dw2_get_file_names (objfile
, per_cu
);
2717 if (file_data
== NULL
)
2720 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2722 if (file_matcher (file_data
->file_names
[j
], data
))
2724 per_cu
->v
.quick
->mark
= 1;
2730 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2732 offset_type idx
= 2 * iter
;
2734 offset_type
*vec
, vec_len
, vec_idx
;
2736 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2739 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2741 if (! (*name_matcher
) (name
, data
))
2744 /* The name was matched, now expand corresponding CUs that were
2746 vec
= (offset_type
*) (index
->constant_pool
2747 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2748 vec_len
= MAYBE_SWAP (vec
[0]);
2749 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2751 struct dwarf2_per_cu_data
*per_cu
;
2753 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2754 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2755 dw2_instantiate_symtab (objfile
, per_cu
);
2760 static struct symtab
*
2761 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2762 struct minimal_symbol
*msymbol
,
2764 struct obj_section
*section
,
2767 struct dwarf2_per_cu_data
*data
;
2769 dw2_setup (objfile
);
2771 if (!objfile
->psymtabs_addrmap
)
2774 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2778 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2779 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2780 paddress (get_objfile_arch (objfile
), pc
));
2782 return dw2_instantiate_symtab (objfile
, data
);
2786 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2791 dw2_setup (objfile
);
2793 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2794 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2797 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2798 struct quick_file_names
*file_data
;
2800 if (per_cu
->v
.quick
->symtab
)
2803 file_data
= dw2_get_file_names (objfile
, per_cu
);
2804 if (file_data
== NULL
)
2807 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2809 const char *this_real_name
= dw2_get_real_path (objfile
, file_data
,
2811 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2817 dw2_has_symbols (struct objfile
*objfile
)
2822 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2825 dw2_find_last_source_symtab
,
2826 dw2_forget_cached_source_info
,
2829 dw2_pre_expand_symtabs_matching
,
2833 dw2_expand_symtabs_for_function
,
2834 dw2_expand_all_symtabs
,
2835 dw2_expand_symtabs_with_filename
,
2836 dw2_find_symbol_file
,
2837 dw2_map_matching_symbols
,
2838 dw2_expand_symtabs_matching
,
2839 dw2_find_pc_sect_symtab
,
2840 dw2_map_symbol_filenames
2843 /* Initialize for reading DWARF for this objfile. Return 0 if this
2844 file will use psymtabs, or 1 if using the GNU index. */
2847 dwarf2_initialize_objfile (struct objfile
*objfile
)
2849 /* If we're about to read full symbols, don't bother with the
2850 indices. In this case we also don't care if some other debug
2851 format is making psymtabs, because they are all about to be
2853 if ((objfile
->flags
& OBJF_READNOW
))
2857 dwarf2_per_objfile
->using_index
= 1;
2858 create_all_comp_units (objfile
);
2859 create_debug_types_hash_table (objfile
);
2860 dwarf2_per_objfile
->quick_file_names_table
=
2861 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2863 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2864 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2866 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2868 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2869 struct dwarf2_per_cu_quick_data
);
2872 /* Return 1 so that gdb sees the "quick" functions. However,
2873 these functions will be no-ops because we will have expanded
2878 if (dwarf2_read_index (objfile
))
2886 /* Build a partial symbol table. */
2889 dwarf2_build_psymtabs (struct objfile
*objfile
)
2891 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2893 init_psymbol_list (objfile
, 1024);
2896 dwarf2_build_psymtabs_hard (objfile
);
2899 /* Return TRUE if OFFSET is within CU_HEADER. */
2902 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2904 unsigned int bottom
= cu_header
->offset
;
2905 unsigned int top
= (cu_header
->offset
2907 + cu_header
->initial_length_size
);
2909 return (offset
>= bottom
&& offset
< top
);
2912 /* Read in the comp unit header information from the debug_info at info_ptr.
2913 NOTE: This leaves members offset, first_die_offset to be filled in
2917 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2918 gdb_byte
*info_ptr
, bfd
*abfd
)
2921 unsigned int bytes_read
;
2923 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2924 cu_header
->initial_length_size
= bytes_read
;
2925 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2926 info_ptr
+= bytes_read
;
2927 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2929 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2931 info_ptr
+= bytes_read
;
2932 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2934 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2935 if (signed_addr
< 0)
2936 internal_error (__FILE__
, __LINE__
,
2937 _("read_comp_unit_head: dwarf from non elf file"));
2938 cu_header
->signed_addr_p
= signed_addr
;
2944 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2945 gdb_byte
*buffer
, unsigned int buffer_size
,
2948 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2950 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2952 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2953 error (_("Dwarf Error: wrong version in compilation unit header "
2954 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2955 bfd_get_filename (abfd
));
2957 if (header
->abbrev_offset
2958 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
2959 &dwarf2_per_objfile
->abbrev
))
2960 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2961 "(offset 0x%lx + 6) [in module %s]"),
2962 (long) header
->abbrev_offset
,
2963 (long) (beg_of_comp_unit
- buffer
),
2964 bfd_get_filename (abfd
));
2966 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2967 > buffer
+ buffer_size
)
2968 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2969 "(offset 0x%lx + 0) [in module %s]"),
2970 (long) header
->length
,
2971 (long) (beg_of_comp_unit
- buffer
),
2972 bfd_get_filename (abfd
));
2977 /* Read in the types comp unit header information from .debug_types entry at
2978 types_ptr. The result is a pointer to one past the end of the header. */
2981 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2982 struct dwarf2_section_info
*section
,
2983 ULONGEST
*signature
,
2984 gdb_byte
*types_ptr
, bfd
*abfd
)
2986 gdb_byte
*initial_types_ptr
= types_ptr
;
2988 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
2989 cu_header
->offset
= types_ptr
- section
->buffer
;
2991 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2993 *signature
= read_8_bytes (abfd
, types_ptr
);
2995 types_ptr
+= cu_header
->offset_size
;
2996 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
3001 /* Allocate a new partial symtab for file named NAME and mark this new
3002 partial symtab as being an include of PST. */
3005 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3006 struct objfile
*objfile
)
3008 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3010 subpst
->section_offsets
= pst
->section_offsets
;
3011 subpst
->textlow
= 0;
3012 subpst
->texthigh
= 0;
3014 subpst
->dependencies
= (struct partial_symtab
**)
3015 obstack_alloc (&objfile
->objfile_obstack
,
3016 sizeof (struct partial_symtab
*));
3017 subpst
->dependencies
[0] = pst
;
3018 subpst
->number_of_dependencies
= 1;
3020 subpst
->globals_offset
= 0;
3021 subpst
->n_global_syms
= 0;
3022 subpst
->statics_offset
= 0;
3023 subpst
->n_static_syms
= 0;
3024 subpst
->symtab
= NULL
;
3025 subpst
->read_symtab
= pst
->read_symtab
;
3028 /* No private part is necessary for include psymtabs. This property
3029 can be used to differentiate between such include psymtabs and
3030 the regular ones. */
3031 subpst
->read_symtab_private
= NULL
;
3034 /* Read the Line Number Program data and extract the list of files
3035 included by the source file represented by PST. Build an include
3036 partial symtab for each of these included files. */
3039 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3040 struct die_info
*die
,
3041 struct partial_symtab
*pst
)
3043 struct objfile
*objfile
= cu
->objfile
;
3044 bfd
*abfd
= objfile
->obfd
;
3045 struct line_header
*lh
= NULL
;
3046 struct attribute
*attr
;
3048 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3051 unsigned int line_offset
= DW_UNSND (attr
);
3053 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3056 return; /* No linetable, so no includes. */
3058 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3059 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
3061 free_line_header (lh
);
3065 hash_type_signature (const void *item
)
3067 const struct signatured_type
*type_sig
= item
;
3069 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3070 return type_sig
->signature
;
3074 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
3076 const struct signatured_type
*lhs
= item_lhs
;
3077 const struct signatured_type
*rhs
= item_rhs
;
3079 return lhs
->signature
== rhs
->signature
;
3082 /* Allocate a hash table for signatured types. */
3085 allocate_signatured_type_table (struct objfile
*objfile
)
3087 return htab_create_alloc_ex (41,
3088 hash_type_signature
,
3091 &objfile
->objfile_obstack
,
3092 hashtab_obstack_allocate
,
3093 dummy_obstack_deallocate
);
3096 /* A helper function to add a signatured type CU to a list. */
3099 add_signatured_type_cu_to_list (void **slot
, void *datum
)
3101 struct signatured_type
*sigt
= *slot
;
3102 struct dwarf2_per_cu_data
***datap
= datum
;
3104 **datap
= &sigt
->per_cu
;
3110 /* Create the hash table of all entries in the .debug_types section.
3111 The result is zero if there is an error (e.g. missing .debug_types section),
3112 otherwise non-zero. */
3115 create_debug_types_hash_table (struct objfile
*objfile
)
3117 htab_t types_htab
= NULL
;
3118 struct dwarf2_per_cu_data
**iter
;
3120 struct dwarf2_section_info
*section
;
3122 if (VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
))
3124 dwarf2_per_objfile
->signatured_types
= NULL
;
3129 VEC_iterate (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
3133 gdb_byte
*info_ptr
, *end_ptr
;
3135 dwarf2_read_section (objfile
, section
);
3136 info_ptr
= section
->buffer
;
3138 if (info_ptr
== NULL
)
3141 if (types_htab
== NULL
)
3142 types_htab
= allocate_signatured_type_table (objfile
);
3144 if (dwarf2_die_debug
)
3145 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3147 end_ptr
= info_ptr
+ section
->size
;
3148 while (info_ptr
< end_ptr
)
3150 unsigned int offset
;
3151 unsigned int offset_size
;
3152 unsigned int type_offset
;
3153 unsigned int length
, initial_length_size
;
3154 unsigned short version
;
3156 struct signatured_type
*type_sig
;
3158 gdb_byte
*ptr
= info_ptr
;
3160 offset
= ptr
- section
->buffer
;
3162 /* We need to read the type's signature in order to build the hash
3163 table, but we don't need to read anything else just yet. */
3165 /* Sanity check to ensure entire cu is present. */
3166 length
= read_initial_length (objfile
->obfd
, ptr
,
3167 &initial_length_size
);
3168 if (ptr
+ length
+ initial_length_size
> end_ptr
)
3170 complaint (&symfile_complaints
,
3171 _("debug type entry runs off end "
3172 "of `.debug_types' section, ignored"));
3176 offset_size
= initial_length_size
== 4 ? 4 : 8;
3177 ptr
+= initial_length_size
;
3178 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3180 ptr
+= offset_size
; /* abbrev offset */
3181 ptr
+= 1; /* address size */
3182 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3184 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3186 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3187 memset (type_sig
, 0, sizeof (*type_sig
));
3188 type_sig
->signature
= signature
;
3189 type_sig
->type_offset
= type_offset
;
3190 type_sig
->per_cu
.objfile
= objfile
;
3191 type_sig
->per_cu
.debug_type_section
= section
;
3192 type_sig
->per_cu
.offset
= offset
;
3194 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3195 gdb_assert (slot
!= NULL
);
3198 const struct signatured_type
*dup_sig
= *slot
;
3200 complaint (&symfile_complaints
,
3201 _("debug type entry at offset 0x%x is duplicate to the "
3202 "entry at offset 0x%x, signature 0x%s"),
3203 offset
, dup_sig
->per_cu
.offset
,
3204 phex (signature
, sizeof (signature
)));
3205 gdb_assert (signature
== dup_sig
->signature
);
3209 if (dwarf2_die_debug
)
3210 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3211 offset
, phex (signature
, sizeof (signature
)));
3213 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3217 dwarf2_per_objfile
->signatured_types
= types_htab
;
3219 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3220 dwarf2_per_objfile
->type_comp_units
3221 = obstack_alloc (&objfile
->objfile_obstack
,
3222 dwarf2_per_objfile
->n_type_comp_units
3223 * sizeof (struct dwarf2_per_cu_data
*));
3224 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3225 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3226 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3227 == dwarf2_per_objfile
->n_type_comp_units
);
3232 /* Lookup a signature based type.
3233 Returns NULL if SIG is not present in the table. */
3235 static struct signatured_type
*
3236 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3238 struct signatured_type find_entry
, *entry
;
3240 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3242 complaint (&symfile_complaints
,
3243 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3247 find_entry
.signature
= sig
;
3248 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3252 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3255 init_cu_die_reader (struct die_reader_specs
*reader
,
3256 struct dwarf2_cu
*cu
)
3258 reader
->abfd
= cu
->objfile
->obfd
;
3260 if (cu
->per_cu
->debug_type_section
)
3262 gdb_assert (cu
->per_cu
->debug_type_section
->readin
);
3263 reader
->buffer
= cu
->per_cu
->debug_type_section
->buffer
;
3267 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3268 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3272 /* Find the base address of the compilation unit for range lists and
3273 location lists. It will normally be specified by DW_AT_low_pc.
3274 In DWARF-3 draft 4, the base address could be overridden by
3275 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3276 compilation units with discontinuous ranges. */
3279 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3281 struct attribute
*attr
;
3284 cu
->base_address
= 0;
3286 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3289 cu
->base_address
= DW_ADDR (attr
);
3294 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3297 cu
->base_address
= DW_ADDR (attr
);
3303 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3304 to combine the common parts.
3305 Process a compilation unit for a psymtab.
3306 BUFFER is a pointer to the beginning of the dwarf section buffer,
3307 either .debug_info or debug_types.
3308 INFO_PTR is a pointer to the start of the CU.
3309 Returns a pointer to the next CU. */
3312 process_psymtab_comp_unit (struct objfile
*objfile
,
3313 struct dwarf2_per_cu_data
*this_cu
,
3314 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3315 unsigned int buffer_size
)
3317 bfd
*abfd
= objfile
->obfd
;
3318 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3319 struct die_info
*comp_unit_die
;
3320 struct partial_symtab
*pst
;
3322 struct cleanup
*back_to_inner
;
3323 struct dwarf2_cu cu
;
3324 int has_children
, has_pc_info
;
3325 struct attribute
*attr
;
3326 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3327 struct die_reader_specs reader_specs
;
3328 const char *filename
;
3330 init_one_comp_unit (&cu
, objfile
);
3331 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3333 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3334 buffer
, buffer_size
,
3337 /* Complete the cu_header. */
3338 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3339 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3341 cu
.list_in_scope
= &file_symbols
;
3343 /* If this compilation unit was already read in, free the
3344 cached copy in order to read it in again. This is
3345 necessary because we skipped some symbols when we first
3346 read in the compilation unit (see load_partial_dies).
3347 This problem could be avoided, but the benefit is
3349 if (this_cu
->cu
!= NULL
)
3350 free_one_cached_comp_unit (this_cu
->cu
);
3352 /* Note that this is a pointer to our stack frame, being
3353 added to a global data structure. It will be cleaned up
3354 in free_stack_comp_unit when we finish with this
3355 compilation unit. */
3357 cu
.per_cu
= this_cu
;
3359 /* Read the abbrevs for this compilation unit into a table. */
3360 dwarf2_read_abbrevs (abfd
, &cu
);
3361 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3363 /* Read the compilation unit die. */
3364 if (this_cu
->debug_type_section
)
3365 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3366 init_cu_die_reader (&reader_specs
, &cu
);
3367 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3370 if (this_cu
->debug_type_section
)
3372 /* LENGTH has not been set yet for type units. */
3373 gdb_assert (this_cu
->offset
== cu
.header
.offset
);
3374 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3376 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3378 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3379 + cu
.header
.initial_length_size
);
3380 do_cleanups (back_to_inner
);
3384 prepare_one_comp_unit (&cu
, comp_unit_die
);
3386 /* Allocate a new partial symbol table structure. */
3387 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3388 if (attr
== NULL
|| !DW_STRING (attr
))
3391 filename
= DW_STRING (attr
);
3392 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3394 /* TEXTLOW and TEXTHIGH are set below. */
3396 objfile
->global_psymbols
.next
,
3397 objfile
->static_psymbols
.next
);
3399 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3401 pst
->dirname
= DW_STRING (attr
);
3403 pst
->read_symtab_private
= this_cu
;
3405 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3407 /* Store the function that reads in the rest of the symbol table. */
3408 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3410 this_cu
->v
.psymtab
= pst
;
3412 dwarf2_find_base_address (comp_unit_die
, &cu
);
3414 /* Possibly set the default values of LOWPC and HIGHPC from
3416 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3417 &best_highpc
, &cu
, pst
);
3418 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3419 /* Store the contiguous range if it is not empty; it can be empty for
3420 CUs with no code. */
3421 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3422 best_lowpc
+ baseaddr
,
3423 best_highpc
+ baseaddr
- 1, pst
);
3425 /* Check if comp unit has_children.
3426 If so, read the rest of the partial symbols from this comp unit.
3427 If not, there's no more debug_info for this comp unit. */
3430 struct partial_die_info
*first_die
;
3431 CORE_ADDR lowpc
, highpc
;
3433 lowpc
= ((CORE_ADDR
) -1);
3434 highpc
= ((CORE_ADDR
) 0);
3436 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3438 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3439 ! has_pc_info
, &cu
);
3441 /* If we didn't find a lowpc, set it to highpc to avoid
3442 complaints from `maint check'. */
3443 if (lowpc
== ((CORE_ADDR
) -1))
3446 /* If the compilation unit didn't have an explicit address range,
3447 then use the information extracted from its child dies. */
3451 best_highpc
= highpc
;
3454 pst
->textlow
= best_lowpc
+ baseaddr
;
3455 pst
->texthigh
= best_highpc
+ baseaddr
;
3457 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3458 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3459 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3460 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3461 sort_pst_symbols (pst
);
3463 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3464 + cu
.header
.initial_length_size
);
3466 if (this_cu
->debug_type_section
)
3468 /* It's not clear we want to do anything with stmt lists here.
3469 Waiting to see what gcc ultimately does. */
3473 /* Get the list of files included in the current compilation unit,
3474 and build a psymtab for each of them. */
3475 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3478 do_cleanups (back_to_inner
);
3483 /* Traversal function for htab_traverse_noresize.
3484 Process one .debug_types comp-unit. */
3487 process_type_comp_unit (void **slot
, void *info
)
3489 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3490 struct objfile
*objfile
= (struct objfile
*) info
;
3491 struct dwarf2_per_cu_data
*this_cu
;
3493 this_cu
= &entry
->per_cu
;
3495 gdb_assert (this_cu
->debug_type_section
->readin
);
3496 process_psymtab_comp_unit (objfile
, this_cu
,
3497 this_cu
->debug_type_section
->buffer
,
3498 (this_cu
->debug_type_section
->buffer
3500 this_cu
->debug_type_section
->size
);
3505 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3506 Build partial symbol tables for the .debug_types comp-units. */
3509 build_type_psymtabs (struct objfile
*objfile
)
3511 if (! create_debug_types_hash_table (objfile
))
3514 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3515 process_type_comp_unit
, objfile
);
3518 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3521 psymtabs_addrmap_cleanup (void *o
)
3523 struct objfile
*objfile
= o
;
3525 objfile
->psymtabs_addrmap
= NULL
;
3528 /* Build the partial symbol table by doing a quick pass through the
3529 .debug_info and .debug_abbrev sections. */
3532 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3535 struct cleanup
*back_to
, *addrmap_cleanup
;
3536 struct obstack temp_obstack
;
3538 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3540 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3541 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3543 /* Any cached compilation units will be linked by the per-objfile
3544 read_in_chain. Make sure to free them when we're done. */
3545 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3547 build_type_psymtabs (objfile
);
3549 create_all_comp_units (objfile
);
3551 /* Create a temporary address map on a temporary obstack. We later
3552 copy this to the final obstack. */
3553 obstack_init (&temp_obstack
);
3554 make_cleanup_obstack_free (&temp_obstack
);
3555 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3556 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3558 /* Since the objects we're extracting from .debug_info vary in
3559 length, only the individual functions to extract them (like
3560 read_comp_unit_head and load_partial_die) can really know whether
3561 the buffer is large enough to hold another complete object.
3563 At the moment, they don't actually check that. If .debug_info
3564 holds just one extra byte after the last compilation unit's dies,
3565 then read_comp_unit_head will happily read off the end of the
3566 buffer. read_partial_die is similarly casual. Those functions
3569 For this loop condition, simply checking whether there's any data
3570 left at all should be sufficient. */
3572 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3573 + dwarf2_per_objfile
->info
.size
))
3575 struct dwarf2_per_cu_data
*this_cu
;
3577 this_cu
= dwarf2_find_comp_unit (info_ptr
3578 - dwarf2_per_objfile
->info
.buffer
,
3581 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3582 dwarf2_per_objfile
->info
.buffer
,
3584 dwarf2_per_objfile
->info
.size
);
3587 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3588 &objfile
->objfile_obstack
);
3589 discard_cleanups (addrmap_cleanup
);
3591 do_cleanups (back_to
);
3594 /* Load the partial DIEs for a secondary CU into memory. */
3597 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3598 struct objfile
*objfile
)
3600 bfd
*abfd
= objfile
->obfd
;
3601 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3602 struct die_info
*comp_unit_die
;
3603 struct dwarf2_cu
*cu
;
3604 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3606 struct die_reader_specs reader_specs
;
3609 gdb_assert (! this_cu
->debug_type_section
);
3611 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3612 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3613 beg_of_comp_unit
= info_ptr
;
3615 if (this_cu
->cu
== NULL
)
3617 cu
= xmalloc (sizeof (*cu
));
3618 init_one_comp_unit (cu
, objfile
);
3622 /* If an error occurs while loading, release our storage. */
3623 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3625 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3626 dwarf2_per_objfile
->info
.buffer
,
3627 dwarf2_per_objfile
->info
.size
,
3630 /* Complete the cu_header. */
3631 cu
->header
.offset
= this_cu
->offset
;
3632 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3634 /* Link this compilation unit into the compilation unit tree. */
3636 cu
->per_cu
= this_cu
;
3638 /* Link this CU into read_in_chain. */
3639 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3640 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3645 info_ptr
+= cu
->header
.first_die_offset
;
3648 /* Read the abbrevs for this compilation unit into a table. */
3649 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3650 dwarf2_read_abbrevs (abfd
, cu
);
3651 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3653 /* Read the compilation unit die. */
3654 init_cu_die_reader (&reader_specs
, cu
);
3655 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3658 prepare_one_comp_unit (cu
, comp_unit_die
);
3660 /* Check if comp unit has_children.
3661 If so, read the rest of the partial symbols from this comp unit.
3662 If not, there's no more debug_info for this comp unit. */
3664 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3666 do_cleanups (free_abbrevs_cleanup
);
3670 /* We've successfully allocated this compilation unit. Let our
3671 caller clean it up when finished with it. */
3672 discard_cleanups (free_cu_cleanup
);
3676 /* Create a list of all compilation units in OBJFILE. We do this only
3677 if an inter-comp-unit reference is found; presumably if there is one,
3678 there will be many, and one will occur early in the .debug_info section.
3679 So there's no point in building this list incrementally. */
3682 create_all_comp_units (struct objfile
*objfile
)
3686 struct dwarf2_per_cu_data
**all_comp_units
;
3689 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3690 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3694 all_comp_units
= xmalloc (n_allocated
3695 * sizeof (struct dwarf2_per_cu_data
*));
3697 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3698 + dwarf2_per_objfile
->info
.size
)
3700 unsigned int length
, initial_length_size
;
3701 struct dwarf2_per_cu_data
*this_cu
;
3702 unsigned int offset
;
3704 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3706 /* Read just enough information to find out where the next
3707 compilation unit is. */
3708 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3709 &initial_length_size
);
3711 /* Save the compilation unit for later lookup. */
3712 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3713 sizeof (struct dwarf2_per_cu_data
));
3714 memset (this_cu
, 0, sizeof (*this_cu
));
3715 this_cu
->offset
= offset
;
3716 this_cu
->length
= length
+ initial_length_size
;
3717 this_cu
->objfile
= objfile
;
3719 if (n_comp_units
== n_allocated
)
3722 all_comp_units
= xrealloc (all_comp_units
,
3724 * sizeof (struct dwarf2_per_cu_data
*));
3726 all_comp_units
[n_comp_units
++] = this_cu
;
3728 info_ptr
= info_ptr
+ this_cu
->length
;
3731 dwarf2_per_objfile
->all_comp_units
3732 = obstack_alloc (&objfile
->objfile_obstack
,
3733 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3734 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3735 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3736 xfree (all_comp_units
);
3737 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3740 /* Process all loaded DIEs for compilation unit CU, starting at
3741 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3742 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3743 DW_AT_ranges). If NEED_PC is set, then this function will set
3744 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3745 and record the covered ranges in the addrmap. */
3748 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3749 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3751 struct partial_die_info
*pdi
;
3753 /* Now, march along the PDI's, descending into ones which have
3754 interesting children but skipping the children of the other ones,
3755 until we reach the end of the compilation unit. */
3761 fixup_partial_die (pdi
, cu
);
3763 /* Anonymous namespaces or modules have no name but have interesting
3764 children, so we need to look at them. Ditto for anonymous
3767 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3768 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3772 case DW_TAG_subprogram
:
3773 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3775 case DW_TAG_constant
:
3776 case DW_TAG_variable
:
3777 case DW_TAG_typedef
:
3778 case DW_TAG_union_type
:
3779 if (!pdi
->is_declaration
)
3781 add_partial_symbol (pdi
, cu
);
3784 case DW_TAG_class_type
:
3785 case DW_TAG_interface_type
:
3786 case DW_TAG_structure_type
:
3787 if (!pdi
->is_declaration
)
3789 add_partial_symbol (pdi
, cu
);
3792 case DW_TAG_enumeration_type
:
3793 if (!pdi
->is_declaration
)
3794 add_partial_enumeration (pdi
, cu
);
3796 case DW_TAG_base_type
:
3797 case DW_TAG_subrange_type
:
3798 /* File scope base type definitions are added to the partial
3800 add_partial_symbol (pdi
, cu
);
3802 case DW_TAG_namespace
:
3803 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3806 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3813 /* If the die has a sibling, skip to the sibling. */
3815 pdi
= pdi
->die_sibling
;
3819 /* Functions used to compute the fully scoped name of a partial DIE.
3821 Normally, this is simple. For C++, the parent DIE's fully scoped
3822 name is concatenated with "::" and the partial DIE's name. For
3823 Java, the same thing occurs except that "." is used instead of "::".
3824 Enumerators are an exception; they use the scope of their parent
3825 enumeration type, i.e. the name of the enumeration type is not
3826 prepended to the enumerator.
3828 There are two complexities. One is DW_AT_specification; in this
3829 case "parent" means the parent of the target of the specification,
3830 instead of the direct parent of the DIE. The other is compilers
3831 which do not emit DW_TAG_namespace; in this case we try to guess
3832 the fully qualified name of structure types from their members'
3833 linkage names. This must be done using the DIE's children rather
3834 than the children of any DW_AT_specification target. We only need
3835 to do this for structures at the top level, i.e. if the target of
3836 any DW_AT_specification (if any; otherwise the DIE itself) does not
3839 /* Compute the scope prefix associated with PDI's parent, in
3840 compilation unit CU. The result will be allocated on CU's
3841 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3842 field. NULL is returned if no prefix is necessary. */
3844 partial_die_parent_scope (struct partial_die_info
*pdi
,
3845 struct dwarf2_cu
*cu
)
3847 char *grandparent_scope
;
3848 struct partial_die_info
*parent
, *real_pdi
;
3850 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3851 then this means the parent of the specification DIE. */
3854 while (real_pdi
->has_specification
)
3855 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3857 parent
= real_pdi
->die_parent
;
3861 if (parent
->scope_set
)
3862 return parent
->scope
;
3864 fixup_partial_die (parent
, cu
);
3866 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3868 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3869 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3870 Work around this problem here. */
3871 if (cu
->language
== language_cplus
3872 && parent
->tag
== DW_TAG_namespace
3873 && strcmp (parent
->name
, "::") == 0
3874 && grandparent_scope
== NULL
)
3876 parent
->scope
= NULL
;
3877 parent
->scope_set
= 1;
3881 if (parent
->tag
== DW_TAG_namespace
3882 || parent
->tag
== DW_TAG_module
3883 || parent
->tag
== DW_TAG_structure_type
3884 || parent
->tag
== DW_TAG_class_type
3885 || parent
->tag
== DW_TAG_interface_type
3886 || parent
->tag
== DW_TAG_union_type
3887 || parent
->tag
== DW_TAG_enumeration_type
)
3889 if (grandparent_scope
== NULL
)
3890 parent
->scope
= parent
->name
;
3892 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3894 parent
->name
, 0, cu
);
3896 else if (parent
->tag
== DW_TAG_enumerator
)
3897 /* Enumerators should not get the name of the enumeration as a prefix. */
3898 parent
->scope
= grandparent_scope
;
3901 /* FIXME drow/2004-04-01: What should we be doing with
3902 function-local names? For partial symbols, we should probably be
3904 complaint (&symfile_complaints
,
3905 _("unhandled containing DIE tag %d for DIE at %d"),
3906 parent
->tag
, pdi
->offset
);
3907 parent
->scope
= grandparent_scope
;
3910 parent
->scope_set
= 1;
3911 return parent
->scope
;
3914 /* Return the fully scoped name associated with PDI, from compilation unit
3915 CU. The result will be allocated with malloc. */
3917 partial_die_full_name (struct partial_die_info
*pdi
,
3918 struct dwarf2_cu
*cu
)
3922 /* If this is a template instantiation, we can not work out the
3923 template arguments from partial DIEs. So, unfortunately, we have
3924 to go through the full DIEs. At least any work we do building
3925 types here will be reused if full symbols are loaded later. */
3926 if (pdi
->has_template_arguments
)
3928 fixup_partial_die (pdi
, cu
);
3930 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3932 struct die_info
*die
;
3933 struct attribute attr
;
3934 struct dwarf2_cu
*ref_cu
= cu
;
3937 attr
.form
= DW_FORM_ref_addr
;
3938 attr
.u
.addr
= pdi
->offset
;
3939 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3941 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3945 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3946 if (parent_scope
== NULL
)
3949 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3953 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3955 struct objfile
*objfile
= cu
->objfile
;
3957 char *actual_name
= NULL
;
3958 const struct partial_symbol
*psym
= NULL
;
3960 int built_actual_name
= 0;
3962 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3964 actual_name
= partial_die_full_name (pdi
, cu
);
3966 built_actual_name
= 1;
3968 if (actual_name
== NULL
)
3969 actual_name
= pdi
->name
;
3973 case DW_TAG_subprogram
:
3974 if (pdi
->is_external
|| cu
->language
== language_ada
)
3976 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3977 of the global scope. But in Ada, we want to be able to access
3978 nested procedures globally. So all Ada subprograms are stored
3979 in the global scope. */
3980 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3981 mst_text, objfile); */
3982 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3984 VAR_DOMAIN
, LOC_BLOCK
,
3985 &objfile
->global_psymbols
,
3986 0, pdi
->lowpc
+ baseaddr
,
3987 cu
->language
, objfile
);
3991 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3992 mst_file_text, objfile); */
3993 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3995 VAR_DOMAIN
, LOC_BLOCK
,
3996 &objfile
->static_psymbols
,
3997 0, pdi
->lowpc
+ baseaddr
,
3998 cu
->language
, objfile
);
4001 case DW_TAG_constant
:
4003 struct psymbol_allocation_list
*list
;
4005 if (pdi
->is_external
)
4006 list
= &objfile
->global_psymbols
;
4008 list
= &objfile
->static_psymbols
;
4009 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4010 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4011 list
, 0, 0, cu
->language
, objfile
);
4014 case DW_TAG_variable
:
4016 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4020 && !dwarf2_per_objfile
->has_section_at_zero
)
4022 /* A global or static variable may also have been stripped
4023 out by the linker if unused, in which case its address
4024 will be nullified; do not add such variables into partial
4025 symbol table then. */
4027 else if (pdi
->is_external
)
4030 Don't enter into the minimal symbol tables as there is
4031 a minimal symbol table entry from the ELF symbols already.
4032 Enter into partial symbol table if it has a location
4033 descriptor or a type.
4034 If the location descriptor is missing, new_symbol will create
4035 a LOC_UNRESOLVED symbol, the address of the variable will then
4036 be determined from the minimal symbol table whenever the variable
4038 The address for the partial symbol table entry is not
4039 used by GDB, but it comes in handy for debugging partial symbol
4042 if (pdi
->locdesc
|| pdi
->has_type
)
4043 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4045 VAR_DOMAIN
, LOC_STATIC
,
4046 &objfile
->global_psymbols
,
4048 cu
->language
, objfile
);
4052 /* Static Variable. Skip symbols without location descriptors. */
4053 if (pdi
->locdesc
== NULL
)
4055 if (built_actual_name
)
4056 xfree (actual_name
);
4059 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4060 mst_file_data, objfile); */
4061 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4063 VAR_DOMAIN
, LOC_STATIC
,
4064 &objfile
->static_psymbols
,
4066 cu
->language
, objfile
);
4069 case DW_TAG_typedef
:
4070 case DW_TAG_base_type
:
4071 case DW_TAG_subrange_type
:
4072 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4074 VAR_DOMAIN
, LOC_TYPEDEF
,
4075 &objfile
->static_psymbols
,
4076 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4078 case DW_TAG_namespace
:
4079 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4081 VAR_DOMAIN
, LOC_TYPEDEF
,
4082 &objfile
->global_psymbols
,
4083 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4085 case DW_TAG_class_type
:
4086 case DW_TAG_interface_type
:
4087 case DW_TAG_structure_type
:
4088 case DW_TAG_union_type
:
4089 case DW_TAG_enumeration_type
:
4090 /* Skip external references. The DWARF standard says in the section
4091 about "Structure, Union, and Class Type Entries": "An incomplete
4092 structure, union or class type is represented by a structure,
4093 union or class entry that does not have a byte size attribute
4094 and that has a DW_AT_declaration attribute." */
4095 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4097 if (built_actual_name
)
4098 xfree (actual_name
);
4102 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4103 static vs. global. */
4104 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4106 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4107 (cu
->language
== language_cplus
4108 || cu
->language
== language_java
)
4109 ? &objfile
->global_psymbols
4110 : &objfile
->static_psymbols
,
4111 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4114 case DW_TAG_enumerator
:
4115 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4117 VAR_DOMAIN
, LOC_CONST
,
4118 (cu
->language
== language_cplus
4119 || cu
->language
== language_java
)
4120 ? &objfile
->global_psymbols
4121 : &objfile
->static_psymbols
,
4122 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4128 if (built_actual_name
)
4129 xfree (actual_name
);
4132 /* Read a partial die corresponding to a namespace; also, add a symbol
4133 corresponding to that namespace to the symbol table. NAMESPACE is
4134 the name of the enclosing namespace. */
4137 add_partial_namespace (struct partial_die_info
*pdi
,
4138 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4139 int need_pc
, struct dwarf2_cu
*cu
)
4141 /* Add a symbol for the namespace. */
4143 add_partial_symbol (pdi
, cu
);
4145 /* Now scan partial symbols in that namespace. */
4147 if (pdi
->has_children
)
4148 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4151 /* Read a partial die corresponding to a Fortran module. */
4154 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4155 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4157 /* Now scan partial symbols in that module. */
4159 if (pdi
->has_children
)
4160 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4163 /* Read a partial die corresponding to a subprogram and create a partial
4164 symbol for that subprogram. When the CU language allows it, this
4165 routine also defines a partial symbol for each nested subprogram
4166 that this subprogram contains.
4168 DIE my also be a lexical block, in which case we simply search
4169 recursively for suprograms defined inside that lexical block.
4170 Again, this is only performed when the CU language allows this
4171 type of definitions. */
4174 add_partial_subprogram (struct partial_die_info
*pdi
,
4175 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4176 int need_pc
, struct dwarf2_cu
*cu
)
4178 if (pdi
->tag
== DW_TAG_subprogram
)
4180 if (pdi
->has_pc_info
)
4182 if (pdi
->lowpc
< *lowpc
)
4183 *lowpc
= pdi
->lowpc
;
4184 if (pdi
->highpc
> *highpc
)
4185 *highpc
= pdi
->highpc
;
4189 struct objfile
*objfile
= cu
->objfile
;
4191 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4192 SECT_OFF_TEXT (objfile
));
4193 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4194 pdi
->lowpc
+ baseaddr
,
4195 pdi
->highpc
- 1 + baseaddr
,
4196 cu
->per_cu
->v
.psymtab
);
4198 if (!pdi
->is_declaration
)
4199 /* Ignore subprogram DIEs that do not have a name, they are
4200 illegal. Do not emit a complaint at this point, we will
4201 do so when we convert this psymtab into a symtab. */
4203 add_partial_symbol (pdi
, cu
);
4207 if (! pdi
->has_children
)
4210 if (cu
->language
== language_ada
)
4212 pdi
= pdi
->die_child
;
4215 fixup_partial_die (pdi
, cu
);
4216 if (pdi
->tag
== DW_TAG_subprogram
4217 || pdi
->tag
== DW_TAG_lexical_block
)
4218 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4219 pdi
= pdi
->die_sibling
;
4224 /* Read a partial die corresponding to an enumeration type. */
4227 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4228 struct dwarf2_cu
*cu
)
4230 struct partial_die_info
*pdi
;
4232 if (enum_pdi
->name
!= NULL
)
4233 add_partial_symbol (enum_pdi
, cu
);
4235 pdi
= enum_pdi
->die_child
;
4238 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4239 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4241 add_partial_symbol (pdi
, cu
);
4242 pdi
= pdi
->die_sibling
;
4246 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4247 Return the corresponding abbrev, or NULL if the number is zero (indicating
4248 an empty DIE). In either case *BYTES_READ will be set to the length of
4249 the initial number. */
4251 static struct abbrev_info
*
4252 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4253 struct dwarf2_cu
*cu
)
4255 bfd
*abfd
= cu
->objfile
->obfd
;
4256 unsigned int abbrev_number
;
4257 struct abbrev_info
*abbrev
;
4259 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4261 if (abbrev_number
== 0)
4264 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4267 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4268 abbrev_number
, bfd_get_filename (abfd
));
4274 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4275 Returns a pointer to the end of a series of DIEs, terminated by an empty
4276 DIE. Any children of the skipped DIEs will also be skipped. */
4279 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4281 struct abbrev_info
*abbrev
;
4282 unsigned int bytes_read
;
4286 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4288 return info_ptr
+ bytes_read
;
4290 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4294 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4295 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4296 abbrev corresponding to that skipped uleb128 should be passed in
4297 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4301 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4302 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4304 unsigned int bytes_read
;
4305 struct attribute attr
;
4306 bfd
*abfd
= cu
->objfile
->obfd
;
4307 unsigned int form
, i
;
4309 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4311 /* The only abbrev we care about is DW_AT_sibling. */
4312 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4314 read_attribute (&attr
, &abbrev
->attrs
[i
],
4315 abfd
, info_ptr
, cu
);
4316 if (attr
.form
== DW_FORM_ref_addr
)
4317 complaint (&symfile_complaints
,
4318 _("ignoring absolute DW_AT_sibling"));
4320 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4323 /* If it isn't DW_AT_sibling, skip this attribute. */
4324 form
= abbrev
->attrs
[i
].form
;
4328 case DW_FORM_ref_addr
:
4329 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4330 and later it is offset sized. */
4331 if (cu
->header
.version
== 2)
4332 info_ptr
+= cu
->header
.addr_size
;
4334 info_ptr
+= cu
->header
.offset_size
;
4337 info_ptr
+= cu
->header
.addr_size
;
4344 case DW_FORM_flag_present
:
4356 case DW_FORM_ref_sig8
:
4359 case DW_FORM_string
:
4360 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4361 info_ptr
+= bytes_read
;
4363 case DW_FORM_sec_offset
:
4365 info_ptr
+= cu
->header
.offset_size
;
4367 case DW_FORM_exprloc
:
4369 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4370 info_ptr
+= bytes_read
;
4372 case DW_FORM_block1
:
4373 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4375 case DW_FORM_block2
:
4376 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4378 case DW_FORM_block4
:
4379 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4383 case DW_FORM_ref_udata
:
4384 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4386 case DW_FORM_indirect
:
4387 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4388 info_ptr
+= bytes_read
;
4389 /* We need to continue parsing from here, so just go back to
4391 goto skip_attribute
;
4394 error (_("Dwarf Error: Cannot handle %s "
4395 "in DWARF reader [in module %s]"),
4396 dwarf_form_name (form
),
4397 bfd_get_filename (abfd
));
4401 if (abbrev
->has_children
)
4402 return skip_children (buffer
, info_ptr
, cu
);
4407 /* Locate ORIG_PDI's sibling.
4408 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4412 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4413 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4414 bfd
*abfd
, struct dwarf2_cu
*cu
)
4416 /* Do we know the sibling already? */
4418 if (orig_pdi
->sibling
)
4419 return orig_pdi
->sibling
;
4421 /* Are there any children to deal with? */
4423 if (!orig_pdi
->has_children
)
4426 /* Skip the children the long way. */
4428 return skip_children (buffer
, info_ptr
, cu
);
4431 /* Expand this partial symbol table into a full symbol table. */
4434 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4440 warning (_("bug: psymtab for %s is already read in."),
4447 printf_filtered (_("Reading in symbols for %s..."),
4449 gdb_flush (gdb_stdout
);
4452 /* Restore our global data. */
4453 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4454 dwarf2_objfile_data_key
);
4456 /* If this psymtab is constructed from a debug-only objfile, the
4457 has_section_at_zero flag will not necessarily be correct. We
4458 can get the correct value for this flag by looking at the data
4459 associated with the (presumably stripped) associated objfile. */
4460 if (pst
->objfile
->separate_debug_objfile_backlink
)
4462 struct dwarf2_per_objfile
*dpo_backlink
4463 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4464 dwarf2_objfile_data_key
);
4466 dwarf2_per_objfile
->has_section_at_zero
4467 = dpo_backlink
->has_section_at_zero
;
4470 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4472 psymtab_to_symtab_1 (pst
);
4474 /* Finish up the debug error message. */
4476 printf_filtered (_("done.\n"));
4481 /* Add PER_CU to the queue. */
4484 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4486 struct dwarf2_queue_item
*item
;
4489 item
= xmalloc (sizeof (*item
));
4490 item
->per_cu
= per_cu
;
4493 if (dwarf2_queue
== NULL
)
4494 dwarf2_queue
= item
;
4496 dwarf2_queue_tail
->next
= item
;
4498 dwarf2_queue_tail
= item
;
4501 /* Process the queue. */
4504 process_queue (struct objfile
*objfile
)
4506 struct dwarf2_queue_item
*item
, *next_item
;
4508 /* The queue starts out with one item, but following a DIE reference
4509 may load a new CU, adding it to the end of the queue. */
4510 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4512 if (dwarf2_per_objfile
->using_index
4513 ? !item
->per_cu
->v
.quick
->symtab
4514 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4515 process_full_comp_unit (item
->per_cu
);
4517 item
->per_cu
->queued
= 0;
4518 next_item
= item
->next
;
4522 dwarf2_queue_tail
= NULL
;
4525 /* Free all allocated queue entries. This function only releases anything if
4526 an error was thrown; if the queue was processed then it would have been
4527 freed as we went along. */
4530 dwarf2_release_queue (void *dummy
)
4532 struct dwarf2_queue_item
*item
, *last
;
4534 item
= dwarf2_queue
;
4537 /* Anything still marked queued is likely to be in an
4538 inconsistent state, so discard it. */
4539 if (item
->per_cu
->queued
)
4541 if (item
->per_cu
->cu
!= NULL
)
4542 free_one_cached_comp_unit (item
->per_cu
->cu
);
4543 item
->per_cu
->queued
= 0;
4551 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4554 /* Read in full symbols for PST, and anything it depends on. */
4557 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4559 struct dwarf2_per_cu_data
*per_cu
;
4560 struct cleanup
*back_to
;
4563 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4564 if (!pst
->dependencies
[i
]->readin
)
4566 /* Inform about additional files that need to be read in. */
4569 /* FIXME: i18n: Need to make this a single string. */
4570 fputs_filtered (" ", gdb_stdout
);
4572 fputs_filtered ("and ", gdb_stdout
);
4574 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4575 wrap_here (""); /* Flush output. */
4576 gdb_flush (gdb_stdout
);
4578 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4581 per_cu
= pst
->read_symtab_private
;
4585 /* It's an include file, no symbols to read for it.
4586 Everything is in the parent symtab. */
4591 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4594 /* Load the DIEs associated with PER_CU into memory. */
4597 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
4598 struct objfile
*objfile
)
4600 bfd
*abfd
= objfile
->obfd
;
4601 struct dwarf2_cu
*cu
;
4602 unsigned int offset
;
4603 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4604 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4605 struct attribute
*attr
;
4608 gdb_assert (! per_cu
->debug_type_section
);
4610 /* Set local variables from the partial symbol table info. */
4611 offset
= per_cu
->offset
;
4613 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4614 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4615 beg_of_comp_unit
= info_ptr
;
4617 if (per_cu
->cu
== NULL
)
4619 cu
= xmalloc (sizeof (*cu
));
4620 init_one_comp_unit (cu
, objfile
);
4624 /* If an error occurs while loading, release our storage. */
4625 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4627 /* Read in the comp_unit header. */
4628 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4630 /* Complete the cu_header. */
4631 cu
->header
.offset
= offset
;
4632 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4634 /* Read the abbrevs for this compilation unit. */
4635 dwarf2_read_abbrevs (abfd
, cu
);
4636 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4638 /* Link this compilation unit into the compilation unit tree. */
4640 cu
->per_cu
= per_cu
;
4642 /* Link this CU into read_in_chain. */
4643 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4644 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4649 info_ptr
+= cu
->header
.first_die_offset
;
4652 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4654 /* We try not to read any attributes in this function, because not
4655 all objfiles needed for references have been loaded yet, and symbol
4656 table processing isn't initialized. But we have to set the CU language,
4657 or we won't be able to build types correctly. */
4658 prepare_one_comp_unit (cu
, cu
->dies
);
4660 /* Similarly, if we do not read the producer, we can not apply
4661 producer-specific interpretation. */
4662 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4664 cu
->producer
= DW_STRING (attr
);
4668 do_cleanups (free_abbrevs_cleanup
);
4670 /* We've successfully allocated this compilation unit. Let our
4671 caller clean it up when finished with it. */
4672 discard_cleanups (free_cu_cleanup
);
4676 /* Add a DIE to the delayed physname list. */
4679 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4680 const char *name
, struct die_info
*die
,
4681 struct dwarf2_cu
*cu
)
4683 struct delayed_method_info mi
;
4685 mi
.fnfield_index
= fnfield_index
;
4689 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4692 /* A cleanup for freeing the delayed method list. */
4695 free_delayed_list (void *ptr
)
4697 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4698 if (cu
->method_list
!= NULL
)
4700 VEC_free (delayed_method_info
, cu
->method_list
);
4701 cu
->method_list
= NULL
;
4705 /* Compute the physnames of any methods on the CU's method list.
4707 The computation of method physnames is delayed in order to avoid the
4708 (bad) condition that one of the method's formal parameters is of an as yet
4712 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4715 struct delayed_method_info
*mi
;
4716 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4718 const char *physname
;
4719 struct fn_fieldlist
*fn_flp
4720 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4721 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4722 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4726 /* Check for GCC >= 4.x. Return minor version (x) of 4.x in such case. If it
4727 is not GCC or it is GCC older than 4.x return -1. If it is GCC 5.x or
4728 higher return INT_MAX. */
4731 producer_is_gcc_ge_4 (struct dwarf2_cu
*cu
)
4736 if (cu
->producer
== NULL
)
4738 /* For unknown compilers expect their behavior is not compliant. For GCC
4739 this case can also happen for -gdwarf-4 type units supported since
4745 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
4747 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
4749 /* For non-GCC compilers expect their behavior is not compliant. */
4753 cs
= &cu
->producer
[strlen ("GNU ")];
4754 while (*cs
&& !isdigit (*cs
))
4756 if (sscanf (cs
, "%d.%d", &major
, &minor
) != 2)
4758 /* Not recognized as GCC. */
4770 /* Generate full symbol information for PST and CU, whose DIEs have
4771 already been loaded into memory. */
4774 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4776 struct dwarf2_cu
*cu
= per_cu
->cu
;
4777 struct objfile
*objfile
= per_cu
->objfile
;
4778 CORE_ADDR lowpc
, highpc
;
4779 struct symtab
*symtab
;
4780 struct cleanup
*back_to
, *delayed_list_cleanup
;
4783 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4786 back_to
= make_cleanup (really_free_pendings
, NULL
);
4787 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4789 cu
->list_in_scope
= &file_symbols
;
4791 /* Do line number decoding in read_file_scope () */
4792 process_die (cu
->dies
, cu
);
4794 /* Now that we have processed all the DIEs in the CU, all the types
4795 should be complete, and it should now be safe to compute all of the
4797 compute_delayed_physnames (cu
);
4798 do_cleanups (delayed_list_cleanup
);
4800 /* Some compilers don't define a DW_AT_high_pc attribute for the
4801 compilation unit. If the DW_AT_high_pc is missing, synthesize
4802 it, by scanning the DIE's below the compilation unit. */
4803 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4805 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4809 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
);
4811 /* Set symtab language to language from DW_AT_language. If the
4812 compilation is from a C file generated by language preprocessors, do
4813 not set the language if it was already deduced by start_subfile. */
4814 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4815 symtab
->language
= cu
->language
;
4817 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4818 produce DW_AT_location with location lists but it can be possibly
4819 invalid without -fvar-tracking.
4821 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4822 needed, it would be wrong due to missing DW_AT_producer there.
4824 Still one can confuse GDB by using non-standard GCC compilation
4825 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4827 if (cu
->has_loclist
&& gcc_4_minor
>= 0)
4828 symtab
->locations_valid
= 1;
4830 if (gcc_4_minor
>= 5)
4831 symtab
->epilogue_unwind_valid
= 1;
4834 if (dwarf2_per_objfile
->using_index
)
4835 per_cu
->v
.quick
->symtab
= symtab
;
4838 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4839 pst
->symtab
= symtab
;
4843 do_cleanups (back_to
);
4846 /* Process a die and its children. */
4849 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4853 case DW_TAG_padding
:
4855 case DW_TAG_compile_unit
:
4856 read_file_scope (die
, cu
);
4858 case DW_TAG_type_unit
:
4859 read_type_unit_scope (die
, cu
);
4861 case DW_TAG_subprogram
:
4862 case DW_TAG_inlined_subroutine
:
4863 read_func_scope (die
, cu
);
4865 case DW_TAG_lexical_block
:
4866 case DW_TAG_try_block
:
4867 case DW_TAG_catch_block
:
4868 read_lexical_block_scope (die
, cu
);
4870 case DW_TAG_class_type
:
4871 case DW_TAG_interface_type
:
4872 case DW_TAG_structure_type
:
4873 case DW_TAG_union_type
:
4874 process_structure_scope (die
, cu
);
4876 case DW_TAG_enumeration_type
:
4877 process_enumeration_scope (die
, cu
);
4880 /* These dies have a type, but processing them does not create
4881 a symbol or recurse to process the children. Therefore we can
4882 read them on-demand through read_type_die. */
4883 case DW_TAG_subroutine_type
:
4884 case DW_TAG_set_type
:
4885 case DW_TAG_array_type
:
4886 case DW_TAG_pointer_type
:
4887 case DW_TAG_ptr_to_member_type
:
4888 case DW_TAG_reference_type
:
4889 case DW_TAG_string_type
:
4892 case DW_TAG_base_type
:
4893 case DW_TAG_subrange_type
:
4894 case DW_TAG_typedef
:
4895 /* Add a typedef symbol for the type definition, if it has a
4897 new_symbol (die
, read_type_die (die
, cu
), cu
);
4899 case DW_TAG_common_block
:
4900 read_common_block (die
, cu
);
4902 case DW_TAG_common_inclusion
:
4904 case DW_TAG_namespace
:
4905 processing_has_namespace_info
= 1;
4906 read_namespace (die
, cu
);
4909 processing_has_namespace_info
= 1;
4910 read_module (die
, cu
);
4912 case DW_TAG_imported_declaration
:
4913 case DW_TAG_imported_module
:
4914 processing_has_namespace_info
= 1;
4915 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4916 || cu
->language
!= language_fortran
))
4917 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4918 dwarf_tag_name (die
->tag
));
4919 read_import_statement (die
, cu
);
4922 new_symbol (die
, NULL
, cu
);
4927 /* A helper function for dwarf2_compute_name which determines whether DIE
4928 needs to have the name of the scope prepended to the name listed in the
4932 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4934 struct attribute
*attr
;
4938 case DW_TAG_namespace
:
4939 case DW_TAG_typedef
:
4940 case DW_TAG_class_type
:
4941 case DW_TAG_interface_type
:
4942 case DW_TAG_structure_type
:
4943 case DW_TAG_union_type
:
4944 case DW_TAG_enumeration_type
:
4945 case DW_TAG_enumerator
:
4946 case DW_TAG_subprogram
:
4950 case DW_TAG_variable
:
4951 case DW_TAG_constant
:
4952 /* We only need to prefix "globally" visible variables. These include
4953 any variable marked with DW_AT_external or any variable that
4954 lives in a namespace. [Variables in anonymous namespaces
4955 require prefixing, but they are not DW_AT_external.] */
4957 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4959 struct dwarf2_cu
*spec_cu
= cu
;
4961 return die_needs_namespace (die_specification (die
, &spec_cu
),
4965 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4966 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4967 && die
->parent
->tag
!= DW_TAG_module
)
4969 /* A variable in a lexical block of some kind does not need a
4970 namespace, even though in C++ such variables may be external
4971 and have a mangled name. */
4972 if (die
->parent
->tag
== DW_TAG_lexical_block
4973 || die
->parent
->tag
== DW_TAG_try_block
4974 || die
->parent
->tag
== DW_TAG_catch_block
4975 || die
->parent
->tag
== DW_TAG_subprogram
)
4984 /* Retrieve the last character from a mem_file. */
4987 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4989 char *last_char_p
= (char *) object
;
4992 *last_char_p
= buffer
[length
- 1];
4995 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4996 compute the physname for the object, which include a method's
4997 formal parameters (C++/Java) and return type (Java).
4999 For Ada, return the DIE's linkage name rather than the fully qualified
5000 name. PHYSNAME is ignored..
5002 The result is allocated on the objfile_obstack and canonicalized. */
5005 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5009 name
= dwarf2_name (die
, cu
);
5011 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5012 compute it by typename_concat inside GDB. */
5013 if (cu
->language
== language_ada
5014 || (cu
->language
== language_fortran
&& physname
))
5016 /* For Ada unit, we prefer the linkage name over the name, as
5017 the former contains the exported name, which the user expects
5018 to be able to reference. Ideally, we want the user to be able
5019 to reference this entity using either natural or linkage name,
5020 but we haven't started looking at this enhancement yet. */
5021 struct attribute
*attr
;
5023 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5025 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5026 if (attr
&& DW_STRING (attr
))
5027 return DW_STRING (attr
);
5030 /* These are the only languages we know how to qualify names in. */
5032 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5033 || cu
->language
== language_fortran
))
5035 if (die_needs_namespace (die
, cu
))
5039 struct ui_file
*buf
;
5041 prefix
= determine_prefix (die
, cu
);
5042 buf
= mem_fileopen ();
5043 if (*prefix
!= '\0')
5045 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5048 fputs_unfiltered (prefixed_name
, buf
);
5049 xfree (prefixed_name
);
5052 fputs_unfiltered (name
, buf
);
5054 /* Template parameters may be specified in the DIE's DW_AT_name, or
5055 as children with DW_TAG_template_type_param or
5056 DW_TAG_value_type_param. If the latter, add them to the name
5057 here. If the name already has template parameters, then
5058 skip this step; some versions of GCC emit both, and
5059 it is more efficient to use the pre-computed name.
5061 Something to keep in mind about this process: it is very
5062 unlikely, or in some cases downright impossible, to produce
5063 something that will match the mangled name of a function.
5064 If the definition of the function has the same debug info,
5065 we should be able to match up with it anyway. But fallbacks
5066 using the minimal symbol, for instance to find a method
5067 implemented in a stripped copy of libstdc++, will not work.
5068 If we do not have debug info for the definition, we will have to
5069 match them up some other way.
5071 When we do name matching there is a related problem with function
5072 templates; two instantiated function templates are allowed to
5073 differ only by their return types, which we do not add here. */
5075 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5077 struct attribute
*attr
;
5078 struct die_info
*child
;
5081 die
->building_fullname
= 1;
5083 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5088 struct dwarf2_locexpr_baton
*baton
;
5091 if (child
->tag
!= DW_TAG_template_type_param
5092 && child
->tag
!= DW_TAG_template_value_param
)
5097 fputs_unfiltered ("<", buf
);
5101 fputs_unfiltered (", ", buf
);
5103 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5106 complaint (&symfile_complaints
,
5107 _("template parameter missing DW_AT_type"));
5108 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5111 type
= die_type (child
, cu
);
5113 if (child
->tag
== DW_TAG_template_type_param
)
5115 c_print_type (type
, "", buf
, -1, 0);
5119 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5122 complaint (&symfile_complaints
,
5123 _("template parameter missing "
5124 "DW_AT_const_value"));
5125 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5129 dwarf2_const_value_attr (attr
, type
, name
,
5130 &cu
->comp_unit_obstack
, cu
,
5131 &value
, &bytes
, &baton
);
5133 if (TYPE_NOSIGN (type
))
5134 /* GDB prints characters as NUMBER 'CHAR'. If that's
5135 changed, this can use value_print instead. */
5136 c_printchar (value
, type
, buf
);
5139 struct value_print_options opts
;
5142 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5146 else if (bytes
!= NULL
)
5148 v
= allocate_value (type
);
5149 memcpy (value_contents_writeable (v
), bytes
,
5150 TYPE_LENGTH (type
));
5153 v
= value_from_longest (type
, value
);
5155 /* Specify decimal so that we do not depend on
5157 get_formatted_print_options (&opts
, 'd');
5159 value_print (v
, buf
, &opts
);
5165 die
->building_fullname
= 0;
5169 /* Close the argument list, with a space if necessary
5170 (nested templates). */
5171 char last_char
= '\0';
5172 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5173 if (last_char
== '>')
5174 fputs_unfiltered (" >", buf
);
5176 fputs_unfiltered (">", buf
);
5180 /* For Java and C++ methods, append formal parameter type
5181 information, if PHYSNAME. */
5183 if (physname
&& die
->tag
== DW_TAG_subprogram
5184 && (cu
->language
== language_cplus
5185 || cu
->language
== language_java
))
5187 struct type
*type
= read_type_die (die
, cu
);
5189 c_type_print_args (type
, buf
, 1, cu
->language
);
5191 if (cu
->language
== language_java
)
5193 /* For java, we must append the return type to method
5195 if (die
->tag
== DW_TAG_subprogram
)
5196 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5199 else if (cu
->language
== language_cplus
)
5201 /* Assume that an artificial first parameter is
5202 "this", but do not crash if it is not. RealView
5203 marks unnamed (and thus unused) parameters as
5204 artificial; there is no way to differentiate
5206 if (TYPE_NFIELDS (type
) > 0
5207 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5208 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5209 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5211 fputs_unfiltered (" const", buf
);
5215 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
5217 ui_file_delete (buf
);
5219 if (cu
->language
== language_cplus
)
5222 = dwarf2_canonicalize_name (name
, cu
,
5223 &cu
->objfile
->objfile_obstack
);
5234 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5235 If scope qualifiers are appropriate they will be added. The result
5236 will be allocated on the objfile_obstack, or NULL if the DIE does
5237 not have a name. NAME may either be from a previous call to
5238 dwarf2_name or NULL.
5240 The output string will be canonicalized (if C++/Java). */
5243 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5245 return dwarf2_compute_name (name
, die
, cu
, 0);
5248 /* Construct a physname for the given DIE in CU. NAME may either be
5249 from a previous call to dwarf2_name or NULL. The result will be
5250 allocated on the objfile_objstack or NULL if the DIE does not have a
5253 The output string will be canonicalized (if C++/Java). */
5256 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5258 struct attribute
*attr
;
5259 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5260 struct cleanup
*back_to
;
5263 /* In this case dwarf2_compute_name is just a shortcut not building anything
5265 if (!die_needs_namespace (die
, cu
))
5266 return dwarf2_compute_name (name
, die
, cu
, 1);
5268 back_to
= make_cleanup (null_cleanup
, NULL
);
5270 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5272 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5274 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5276 if (attr
&& DW_STRING (attr
))
5280 mangled
= DW_STRING (attr
);
5282 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5283 type. It is easier for GDB users to search for such functions as
5284 `name(params)' than `long name(params)'. In such case the minimal
5285 symbol names do not match the full symbol names but for template
5286 functions there is never a need to look up their definition from their
5287 declaration so the only disadvantage remains the minimal symbol
5288 variant `long name(params)' does not have the proper inferior type.
5291 demangled
= cplus_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
5292 | (cu
->language
== language_java
5293 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5297 make_cleanup (xfree
, demangled
);
5307 if (canon
== NULL
|| check_physname
)
5309 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5311 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5313 /* It may not mean a bug in GDB. The compiler could also
5314 compute DW_AT_linkage_name incorrectly. But in such case
5315 GDB would need to be bug-to-bug compatible. */
5317 complaint (&symfile_complaints
,
5318 _("Computed physname <%s> does not match demangled <%s> "
5319 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5320 physname
, canon
, mangled
, die
->offset
, cu
->objfile
->name
);
5322 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5323 is available here - over computed PHYSNAME. It is safer
5324 against both buggy GDB and buggy compilers. */
5338 retval
= obsavestring (retval
, strlen (retval
),
5339 &cu
->objfile
->objfile_obstack
);
5341 do_cleanups (back_to
);
5345 /* Read the import statement specified by the given die and record it. */
5348 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5350 struct attribute
*import_attr
;
5351 struct die_info
*imported_die
, *child_die
;
5352 struct dwarf2_cu
*imported_cu
;
5353 const char *imported_name
;
5354 const char *imported_name_prefix
;
5355 const char *canonical_name
;
5356 const char *import_alias
;
5357 const char *imported_declaration
= NULL
;
5358 const char *import_prefix
;
5359 VEC (const_char_ptr
) *excludes
= NULL
;
5360 struct cleanup
*cleanups
;
5364 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5365 if (import_attr
== NULL
)
5367 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5368 dwarf_tag_name (die
->tag
));
5373 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5374 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5375 if (imported_name
== NULL
)
5377 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5379 The import in the following code:
5393 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5394 <52> DW_AT_decl_file : 1
5395 <53> DW_AT_decl_line : 6
5396 <54> DW_AT_import : <0x75>
5397 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5399 <5b> DW_AT_decl_file : 1
5400 <5c> DW_AT_decl_line : 2
5401 <5d> DW_AT_type : <0x6e>
5403 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5404 <76> DW_AT_byte_size : 4
5405 <77> DW_AT_encoding : 5 (signed)
5407 imports the wrong die ( 0x75 instead of 0x58 ).
5408 This case will be ignored until the gcc bug is fixed. */
5412 /* Figure out the local name after import. */
5413 import_alias
= dwarf2_name (die
, cu
);
5415 /* Figure out where the statement is being imported to. */
5416 import_prefix
= determine_prefix (die
, cu
);
5418 /* Figure out what the scope of the imported die is and prepend it
5419 to the name of the imported die. */
5420 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5422 if (imported_die
->tag
!= DW_TAG_namespace
5423 && imported_die
->tag
!= DW_TAG_module
)
5425 imported_declaration
= imported_name
;
5426 canonical_name
= imported_name_prefix
;
5428 else if (strlen (imported_name_prefix
) > 0)
5430 temp
= alloca (strlen (imported_name_prefix
)
5431 + 2 + strlen (imported_name
) + 1);
5432 strcpy (temp
, imported_name_prefix
);
5433 strcat (temp
, "::");
5434 strcat (temp
, imported_name
);
5435 canonical_name
= temp
;
5438 canonical_name
= imported_name
;
5440 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5442 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5443 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5444 child_die
= sibling_die (child_die
))
5446 /* DWARF-4: A Fortran use statement with a “rename list” may be
5447 represented by an imported module entry with an import attribute
5448 referring to the module and owned entries corresponding to those
5449 entities that are renamed as part of being imported. */
5451 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5453 complaint (&symfile_complaints
,
5454 _("child DW_TAG_imported_declaration expected "
5455 "- DIE at 0x%x [in module %s]"),
5456 child_die
->offset
, cu
->objfile
->name
);
5460 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5461 if (import_attr
== NULL
)
5463 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5464 dwarf_tag_name (child_die
->tag
));
5469 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5471 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5472 if (imported_name
== NULL
)
5474 complaint (&symfile_complaints
,
5475 _("child DW_TAG_imported_declaration has unknown "
5476 "imported name - DIE at 0x%x [in module %s]"),
5477 child_die
->offset
, cu
->objfile
->name
);
5481 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5483 process_die (child_die
, cu
);
5486 cp_add_using_directive (import_prefix
,
5489 imported_declaration
,
5491 &cu
->objfile
->objfile_obstack
);
5493 do_cleanups (cleanups
);
5497 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5499 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5502 /* Cleanup function for read_file_scope. */
5505 free_cu_line_header (void *arg
)
5507 struct dwarf2_cu
*cu
= arg
;
5509 free_line_header (cu
->line_header
);
5510 cu
->line_header
= NULL
;
5514 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5515 char **name
, char **comp_dir
)
5517 struct attribute
*attr
;
5522 /* Find the filename. Do not use dwarf2_name here, since the filename
5523 is not a source language identifier. */
5524 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5527 *name
= DW_STRING (attr
);
5530 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5532 *comp_dir
= DW_STRING (attr
);
5533 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5535 *comp_dir
= ldirname (*name
);
5536 if (*comp_dir
!= NULL
)
5537 make_cleanup (xfree
, *comp_dir
);
5539 if (*comp_dir
!= NULL
)
5541 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5542 directory, get rid of it. */
5543 char *cp
= strchr (*comp_dir
, ':');
5545 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5550 *name
= "<unknown>";
5553 /* Handle DW_AT_stmt_list for a compilation unit. */
5556 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
5557 const char *comp_dir
)
5559 struct attribute
*attr
;
5560 struct objfile
*objfile
= cu
->objfile
;
5561 bfd
*abfd
= objfile
->obfd
;
5563 /* Decode line number information if present. We do this before
5564 processing child DIEs, so that the line header table is available
5565 for DW_AT_decl_file. */
5566 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5569 unsigned int line_offset
= DW_UNSND (attr
);
5570 struct line_header
*line_header
5571 = dwarf_decode_line_header (line_offset
, abfd
, cu
);
5575 cu
->line_header
= line_header
;
5576 make_cleanup (free_cu_line_header
, cu
);
5577 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5582 /* Process DW_TAG_compile_unit. */
5585 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5587 struct objfile
*objfile
= cu
->objfile
;
5588 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5589 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5590 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5591 struct attribute
*attr
;
5593 char *comp_dir
= NULL
;
5594 struct die_info
*child_die
;
5595 bfd
*abfd
= objfile
->obfd
;
5598 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5600 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5602 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5603 from finish_block. */
5604 if (lowpc
== ((CORE_ADDR
) -1))
5609 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5611 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5614 set_cu_language (DW_UNSND (attr
), cu
);
5617 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5619 cu
->producer
= DW_STRING (attr
);
5621 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5622 standardised yet. As a workaround for the language detection we fall
5623 back to the DW_AT_producer string. */
5624 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5625 cu
->language
= language_opencl
;
5627 /* We assume that we're processing GCC output. */
5628 processing_gcc_compilation
= 2;
5630 processing_has_namespace_info
= 0;
5632 start_symtab (name
, comp_dir
, lowpc
);
5633 record_debugformat ("DWARF 2");
5634 record_producer (cu
->producer
);
5636 initialize_cu_func_list (cu
);
5638 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5640 /* Process all dies in compilation unit. */
5641 if (die
->child
!= NULL
)
5643 child_die
= die
->child
;
5644 while (child_die
&& child_die
->tag
)
5646 process_die (child_die
, cu
);
5647 child_die
= sibling_die (child_die
);
5651 /* Decode macro information, if present. Dwarf 2 macro information
5652 refers to information in the line number info statement program
5653 header, so we can only read it if we've read the header
5655 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
5656 if (attr
&& cu
->line_header
)
5658 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
5659 complaint (&symfile_complaints
,
5660 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5662 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
5664 &dwarf2_per_objfile
->macro
, 1);
5668 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5669 if (attr
&& cu
->line_header
)
5671 unsigned int macro_offset
= DW_UNSND (attr
);
5673 dwarf_decode_macros (cu
->line_header
, macro_offset
,
5675 &dwarf2_per_objfile
->macinfo
, 0);
5678 do_cleanups (back_to
);
5681 /* Process DW_TAG_type_unit.
5682 For TUs we want to skip the first top level sibling if it's not the
5683 actual type being defined by this TU. In this case the first top
5684 level sibling is there to provide context only. */
5687 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5689 struct objfile
*objfile
= cu
->objfile
;
5690 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5692 struct attribute
*attr
;
5694 char *comp_dir
= NULL
;
5695 struct die_info
*child_die
;
5696 bfd
*abfd
= objfile
->obfd
;
5698 /* start_symtab needs a low pc, but we don't really have one.
5699 Do what read_file_scope would do in the absence of such info. */
5700 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5702 /* Find the filename. Do not use dwarf2_name here, since the filename
5703 is not a source language identifier. */
5704 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5706 name
= DW_STRING (attr
);
5708 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5710 comp_dir
= DW_STRING (attr
);
5711 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5713 comp_dir
= ldirname (name
);
5714 if (comp_dir
!= NULL
)
5715 make_cleanup (xfree
, comp_dir
);
5721 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5723 set_cu_language (DW_UNSND (attr
), cu
);
5725 /* This isn't technically needed today. It is done for symmetry
5726 with read_file_scope. */
5727 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5729 cu
->producer
= DW_STRING (attr
);
5731 /* We assume that we're processing GCC output. */
5732 processing_gcc_compilation
= 2;
5734 processing_has_namespace_info
= 0;
5736 start_symtab (name
, comp_dir
, lowpc
);
5737 record_debugformat ("DWARF 2");
5738 record_producer (cu
->producer
);
5740 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5742 /* Process the dies in the type unit. */
5743 if (die
->child
== NULL
)
5745 dump_die_for_error (die
);
5746 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5747 bfd_get_filename (abfd
));
5750 child_die
= die
->child
;
5752 while (child_die
&& child_die
->tag
)
5754 process_die (child_die
, cu
);
5756 child_die
= sibling_die (child_die
);
5759 do_cleanups (back_to
);
5763 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5764 struct dwarf2_cu
*cu
)
5766 struct function_range
*thisfn
;
5768 thisfn
= (struct function_range
*)
5769 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5770 thisfn
->name
= name
;
5771 thisfn
->lowpc
= lowpc
;
5772 thisfn
->highpc
= highpc
;
5773 thisfn
->seen_line
= 0;
5774 thisfn
->next
= NULL
;
5776 if (cu
->last_fn
== NULL
)
5777 cu
->first_fn
= thisfn
;
5779 cu
->last_fn
->next
= thisfn
;
5781 cu
->last_fn
= thisfn
;
5784 /* qsort helper for inherit_abstract_dies. */
5787 unsigned_int_compar (const void *ap
, const void *bp
)
5789 unsigned int a
= *(unsigned int *) ap
;
5790 unsigned int b
= *(unsigned int *) bp
;
5792 return (a
> b
) - (b
> a
);
5795 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5796 Inherit only the children of the DW_AT_abstract_origin DIE not being
5797 already referenced by DW_AT_abstract_origin from the children of the
5801 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5803 struct die_info
*child_die
;
5804 unsigned die_children_count
;
5805 /* CU offsets which were referenced by children of the current DIE. */
5807 unsigned *offsets_end
, *offsetp
;
5808 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5809 struct die_info
*origin_die
;
5810 /* Iterator of the ORIGIN_DIE children. */
5811 struct die_info
*origin_child_die
;
5812 struct cleanup
*cleanups
;
5813 struct attribute
*attr
;
5814 struct dwarf2_cu
*origin_cu
;
5815 struct pending
**origin_previous_list_in_scope
;
5817 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5821 /* Note that following die references may follow to a die in a
5825 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5827 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5829 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5830 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5832 if (die
->tag
!= origin_die
->tag
5833 && !(die
->tag
== DW_TAG_inlined_subroutine
5834 && origin_die
->tag
== DW_TAG_subprogram
))
5835 complaint (&symfile_complaints
,
5836 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5837 die
->offset
, origin_die
->offset
);
5839 child_die
= die
->child
;
5840 die_children_count
= 0;
5841 while (child_die
&& child_die
->tag
)
5843 child_die
= sibling_die (child_die
);
5844 die_children_count
++;
5846 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5847 cleanups
= make_cleanup (xfree
, offsets
);
5849 offsets_end
= offsets
;
5850 child_die
= die
->child
;
5851 while (child_die
&& child_die
->tag
)
5853 /* For each CHILD_DIE, find the corresponding child of
5854 ORIGIN_DIE. If there is more than one layer of
5855 DW_AT_abstract_origin, follow them all; there shouldn't be,
5856 but GCC versions at least through 4.4 generate this (GCC PR
5858 struct die_info
*child_origin_die
= child_die
;
5859 struct dwarf2_cu
*child_origin_cu
= cu
;
5863 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5867 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5871 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5872 counterpart may exist. */
5873 if (child_origin_die
!= child_die
)
5875 if (child_die
->tag
!= child_origin_die
->tag
5876 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5877 && child_origin_die
->tag
== DW_TAG_subprogram
))
5878 complaint (&symfile_complaints
,
5879 _("Child DIE 0x%x and its abstract origin 0x%x have "
5880 "different tags"), child_die
->offset
,
5881 child_origin_die
->offset
);
5882 if (child_origin_die
->parent
!= origin_die
)
5883 complaint (&symfile_complaints
,
5884 _("Child DIE 0x%x and its abstract origin 0x%x have "
5885 "different parents"), child_die
->offset
,
5886 child_origin_die
->offset
);
5888 *offsets_end
++ = child_origin_die
->offset
;
5890 child_die
= sibling_die (child_die
);
5892 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5893 unsigned_int_compar
);
5894 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5895 if (offsetp
[-1] == *offsetp
)
5896 complaint (&symfile_complaints
,
5897 _("Multiple children of DIE 0x%x refer "
5898 "to DIE 0x%x as their abstract origin"),
5899 die
->offset
, *offsetp
);
5902 origin_child_die
= origin_die
->child
;
5903 while (origin_child_die
&& origin_child_die
->tag
)
5905 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5906 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5908 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5910 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5911 process_die (origin_child_die
, origin_cu
);
5913 origin_child_die
= sibling_die (origin_child_die
);
5915 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5917 do_cleanups (cleanups
);
5921 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5923 struct objfile
*objfile
= cu
->objfile
;
5924 struct context_stack
*new;
5927 struct die_info
*child_die
;
5928 struct attribute
*attr
, *call_line
, *call_file
;
5931 struct block
*block
;
5932 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5933 VEC (symbolp
) *template_args
= NULL
;
5934 struct template_symbol
*templ_func
= NULL
;
5938 /* If we do not have call site information, we can't show the
5939 caller of this inlined function. That's too confusing, so
5940 only use the scope for local variables. */
5941 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5942 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5943 if (call_line
== NULL
|| call_file
== NULL
)
5945 read_lexical_block_scope (die
, cu
);
5950 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5952 name
= dwarf2_name (die
, cu
);
5954 /* Ignore functions with missing or empty names. These are actually
5955 illegal according to the DWARF standard. */
5958 complaint (&symfile_complaints
,
5959 _("missing name for subprogram DIE at %d"), die
->offset
);
5963 /* Ignore functions with missing or invalid low and high pc attributes. */
5964 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5966 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5967 if (!attr
|| !DW_UNSND (attr
))
5968 complaint (&symfile_complaints
,
5969 _("cannot get low and high bounds "
5970 "for subprogram DIE at %d"),
5978 /* Record the function range for dwarf_decode_lines. */
5979 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5981 /* If we have any template arguments, then we must allocate a
5982 different sort of symbol. */
5983 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5985 if (child_die
->tag
== DW_TAG_template_type_param
5986 || child_die
->tag
== DW_TAG_template_value_param
)
5988 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5989 struct template_symbol
);
5990 templ_func
->base
.is_cplus_template_function
= 1;
5995 new = push_context (0, lowpc
);
5996 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5997 (struct symbol
*) templ_func
);
5999 /* If there is a location expression for DW_AT_frame_base, record
6001 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
6003 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
6004 expression is being recorded directly in the function's symbol
6005 and not in a separate frame-base object. I guess this hack is
6006 to avoid adding some sort of frame-base adjunct/annex to the
6007 function's symbol :-(. The problem with doing this is that it
6008 results in a function symbol with a location expression that
6009 has nothing to do with the location of the function, ouch! The
6010 relationship should be: a function's symbol has-a frame base; a
6011 frame-base has-a location expression. */
6012 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
6014 cu
->list_in_scope
= &local_symbols
;
6016 if (die
->child
!= NULL
)
6018 child_die
= die
->child
;
6019 while (child_die
&& child_die
->tag
)
6021 if (child_die
->tag
== DW_TAG_template_type_param
6022 || child_die
->tag
== DW_TAG_template_value_param
)
6024 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6027 VEC_safe_push (symbolp
, template_args
, arg
);
6030 process_die (child_die
, cu
);
6031 child_die
= sibling_die (child_die
);
6035 inherit_abstract_dies (die
, cu
);
6037 /* If we have a DW_AT_specification, we might need to import using
6038 directives from the context of the specification DIE. See the
6039 comment in determine_prefix. */
6040 if (cu
->language
== language_cplus
6041 && dwarf2_attr (die
, DW_AT_specification
, cu
))
6043 struct dwarf2_cu
*spec_cu
= cu
;
6044 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
6048 child_die
= spec_die
->child
;
6049 while (child_die
&& child_die
->tag
)
6051 if (child_die
->tag
== DW_TAG_imported_module
)
6052 process_die (child_die
, spec_cu
);
6053 child_die
= sibling_die (child_die
);
6056 /* In some cases, GCC generates specification DIEs that
6057 themselves contain DW_AT_specification attributes. */
6058 spec_die
= die_specification (spec_die
, &spec_cu
);
6062 new = pop_context ();
6063 /* Make a block for the local symbols within. */
6064 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
6065 lowpc
, highpc
, objfile
);
6067 /* For C++, set the block's scope. */
6068 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
6069 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
6070 determine_prefix (die
, cu
),
6071 processing_has_namespace_info
);
6073 /* If we have address ranges, record them. */
6074 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6076 /* Attach template arguments to function. */
6077 if (! VEC_empty (symbolp
, template_args
))
6079 gdb_assert (templ_func
!= NULL
);
6081 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
6082 templ_func
->template_arguments
6083 = obstack_alloc (&objfile
->objfile_obstack
,
6084 (templ_func
->n_template_arguments
6085 * sizeof (struct symbol
*)));
6086 memcpy (templ_func
->template_arguments
,
6087 VEC_address (symbolp
, template_args
),
6088 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
6089 VEC_free (symbolp
, template_args
);
6092 /* In C++, we can have functions nested inside functions (e.g., when
6093 a function declares a class that has methods). This means that
6094 when we finish processing a function scope, we may need to go
6095 back to building a containing block's symbol lists. */
6096 local_symbols
= new->locals
;
6097 param_symbols
= new->params
;
6098 using_directives
= new->using_directives
;
6100 /* If we've finished processing a top-level function, subsequent
6101 symbols go in the file symbol list. */
6102 if (outermost_context_p ())
6103 cu
->list_in_scope
= &file_symbols
;
6106 /* Process all the DIES contained within a lexical block scope. Start
6107 a new scope, process the dies, and then close the scope. */
6110 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6112 struct objfile
*objfile
= cu
->objfile
;
6113 struct context_stack
*new;
6114 CORE_ADDR lowpc
, highpc
;
6115 struct die_info
*child_die
;
6118 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6120 /* Ignore blocks with missing or invalid low and high pc attributes. */
6121 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6122 as multiple lexical blocks? Handling children in a sane way would
6123 be nasty. Might be easier to properly extend generic blocks to
6125 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6130 push_context (0, lowpc
);
6131 if (die
->child
!= NULL
)
6133 child_die
= die
->child
;
6134 while (child_die
&& child_die
->tag
)
6136 process_die (child_die
, cu
);
6137 child_die
= sibling_die (child_die
);
6140 new = pop_context ();
6142 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6145 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6148 /* Note that recording ranges after traversing children, as we
6149 do here, means that recording a parent's ranges entails
6150 walking across all its children's ranges as they appear in
6151 the address map, which is quadratic behavior.
6153 It would be nicer to record the parent's ranges before
6154 traversing its children, simply overriding whatever you find
6155 there. But since we don't even decide whether to create a
6156 block until after we've traversed its children, that's hard
6158 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6160 local_symbols
= new->locals
;
6161 using_directives
= new->using_directives
;
6164 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6165 Return 1 if the attributes are present and valid, otherwise, return 0.
6166 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6169 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6170 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6171 struct partial_symtab
*ranges_pst
)
6173 struct objfile
*objfile
= cu
->objfile
;
6174 struct comp_unit_head
*cu_header
= &cu
->header
;
6175 bfd
*obfd
= objfile
->obfd
;
6176 unsigned int addr_size
= cu_header
->addr_size
;
6177 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6178 /* Base address selection entry. */
6189 found_base
= cu
->base_known
;
6190 base
= cu
->base_address
;
6192 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6193 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6195 complaint (&symfile_complaints
,
6196 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6200 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6202 /* Read in the largest possible address. */
6203 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6204 if ((marker
& mask
) == mask
)
6206 /* If we found the largest possible address, then
6207 read the base address. */
6208 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6209 buffer
+= 2 * addr_size
;
6210 offset
+= 2 * addr_size
;
6216 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6220 CORE_ADDR range_beginning
, range_end
;
6222 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6223 buffer
+= addr_size
;
6224 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6225 buffer
+= addr_size
;
6226 offset
+= 2 * addr_size
;
6228 /* An end of list marker is a pair of zero addresses. */
6229 if (range_beginning
== 0 && range_end
== 0)
6230 /* Found the end of list entry. */
6233 /* Each base address selection entry is a pair of 2 values.
6234 The first is the largest possible address, the second is
6235 the base address. Check for a base address here. */
6236 if ((range_beginning
& mask
) == mask
)
6238 /* If we found the largest possible address, then
6239 read the base address. */
6240 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6247 /* We have no valid base address for the ranges
6249 complaint (&symfile_complaints
,
6250 _("Invalid .debug_ranges data (no base address)"));
6254 if (range_beginning
> range_end
)
6256 /* Inverted range entries are invalid. */
6257 complaint (&symfile_complaints
,
6258 _("Invalid .debug_ranges data (inverted range)"));
6262 /* Empty range entries have no effect. */
6263 if (range_beginning
== range_end
)
6266 range_beginning
+= base
;
6269 if (ranges_pst
!= NULL
)
6270 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6271 range_beginning
+ baseaddr
,
6272 range_end
- 1 + baseaddr
,
6275 /* FIXME: This is recording everything as a low-high
6276 segment of consecutive addresses. We should have a
6277 data structure for discontiguous block ranges
6281 low
= range_beginning
;
6287 if (range_beginning
< low
)
6288 low
= range_beginning
;
6289 if (range_end
> high
)
6295 /* If the first entry is an end-of-list marker, the range
6296 describes an empty scope, i.e. no instructions. */
6302 *high_return
= high
;
6306 /* Get low and high pc attributes from a die. Return 1 if the attributes
6307 are present and valid, otherwise, return 0. Return -1 if the range is
6308 discontinuous, i.e. derived from DW_AT_ranges information. */
6310 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6311 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6312 struct partial_symtab
*pst
)
6314 struct attribute
*attr
;
6319 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6322 high
= DW_ADDR (attr
);
6323 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6325 low
= DW_ADDR (attr
);
6327 /* Found high w/o low attribute. */
6330 /* Found consecutive range of addresses. */
6335 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6338 /* Value of the DW_AT_ranges attribute is the offset in the
6339 .debug_ranges section. */
6340 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6342 /* Found discontinuous range of addresses. */
6347 /* read_partial_die has also the strict LOW < HIGH requirement. */
6351 /* When using the GNU linker, .gnu.linkonce. sections are used to
6352 eliminate duplicate copies of functions and vtables and such.
6353 The linker will arbitrarily choose one and discard the others.
6354 The AT_*_pc values for such functions refer to local labels in
6355 these sections. If the section from that file was discarded, the
6356 labels are not in the output, so the relocs get a value of 0.
6357 If this is a discarded function, mark the pc bounds as invalid,
6358 so that GDB will ignore it. */
6359 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6367 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6368 its low and high PC addresses. Do nothing if these addresses could not
6369 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6370 and HIGHPC to the high address if greater than HIGHPC. */
6373 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6374 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6375 struct dwarf2_cu
*cu
)
6377 CORE_ADDR low
, high
;
6378 struct die_info
*child
= die
->child
;
6380 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6382 *lowpc
= min (*lowpc
, low
);
6383 *highpc
= max (*highpc
, high
);
6386 /* If the language does not allow nested subprograms (either inside
6387 subprograms or lexical blocks), we're done. */
6388 if (cu
->language
!= language_ada
)
6391 /* Check all the children of the given DIE. If it contains nested
6392 subprograms, then check their pc bounds. Likewise, we need to
6393 check lexical blocks as well, as they may also contain subprogram
6395 while (child
&& child
->tag
)
6397 if (child
->tag
== DW_TAG_subprogram
6398 || child
->tag
== DW_TAG_lexical_block
)
6399 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6400 child
= sibling_die (child
);
6404 /* Get the low and high pc's represented by the scope DIE, and store
6405 them in *LOWPC and *HIGHPC. If the correct values can't be
6406 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6409 get_scope_pc_bounds (struct die_info
*die
,
6410 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6411 struct dwarf2_cu
*cu
)
6413 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6414 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6415 CORE_ADDR current_low
, current_high
;
6417 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6419 best_low
= current_low
;
6420 best_high
= current_high
;
6424 struct die_info
*child
= die
->child
;
6426 while (child
&& child
->tag
)
6428 switch (child
->tag
) {
6429 case DW_TAG_subprogram
:
6430 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6432 case DW_TAG_namespace
:
6434 /* FIXME: carlton/2004-01-16: Should we do this for
6435 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6436 that current GCC's always emit the DIEs corresponding
6437 to definitions of methods of classes as children of a
6438 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6439 the DIEs giving the declarations, which could be
6440 anywhere). But I don't see any reason why the
6441 standards says that they have to be there. */
6442 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6444 if (current_low
!= ((CORE_ADDR
) -1))
6446 best_low
= min (best_low
, current_low
);
6447 best_high
= max (best_high
, current_high
);
6455 child
= sibling_die (child
);
6460 *highpc
= best_high
;
6463 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6466 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6467 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6469 struct attribute
*attr
;
6471 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6474 CORE_ADDR high
= DW_ADDR (attr
);
6476 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6479 CORE_ADDR low
= DW_ADDR (attr
);
6481 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6485 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6488 bfd
*obfd
= cu
->objfile
->obfd
;
6490 /* The value of the DW_AT_ranges attribute is the offset of the
6491 address range list in the .debug_ranges section. */
6492 unsigned long offset
= DW_UNSND (attr
);
6493 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6495 /* For some target architectures, but not others, the
6496 read_address function sign-extends the addresses it returns.
6497 To recognize base address selection entries, we need a
6499 unsigned int addr_size
= cu
->header
.addr_size
;
6500 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6502 /* The base address, to which the next pair is relative. Note
6503 that this 'base' is a DWARF concept: most entries in a range
6504 list are relative, to reduce the number of relocs against the
6505 debugging information. This is separate from this function's
6506 'baseaddr' argument, which GDB uses to relocate debugging
6507 information from a shared library based on the address at
6508 which the library was loaded. */
6509 CORE_ADDR base
= cu
->base_address
;
6510 int base_known
= cu
->base_known
;
6512 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6513 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6515 complaint (&symfile_complaints
,
6516 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6523 unsigned int bytes_read
;
6524 CORE_ADDR start
, end
;
6526 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6527 buffer
+= bytes_read
;
6528 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6529 buffer
+= bytes_read
;
6531 /* Did we find the end of the range list? */
6532 if (start
== 0 && end
== 0)
6535 /* Did we find a base address selection entry? */
6536 else if ((start
& base_select_mask
) == base_select_mask
)
6542 /* We found an ordinary address range. */
6547 complaint (&symfile_complaints
,
6548 _("Invalid .debug_ranges data "
6549 "(no base address)"));
6555 /* Inverted range entries are invalid. */
6556 complaint (&symfile_complaints
,
6557 _("Invalid .debug_ranges data "
6558 "(inverted range)"));
6562 /* Empty range entries have no effect. */
6566 record_block_range (block
,
6567 baseaddr
+ base
+ start
,
6568 baseaddr
+ base
+ end
- 1);
6574 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6575 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6576 during 4.6.0 experimental. */
6579 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6582 int major
, minor
, release
;
6584 if (cu
->producer
== NULL
)
6586 /* For unknown compilers expect their behavior is DWARF version
6589 GCC started to support .debug_types sections by -gdwarf-4 since
6590 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6591 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6592 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6593 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6598 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6600 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6602 /* For non-GCC compilers expect their behavior is DWARF version
6607 cs
= &cu
->producer
[strlen ("GNU ")];
6608 while (*cs
&& !isdigit (*cs
))
6610 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6612 /* Not recognized as GCC. */
6617 return major
< 4 || (major
== 4 && minor
< 6);
6620 /* Return the default accessibility type if it is not overriden by
6621 DW_AT_accessibility. */
6623 static enum dwarf_access_attribute
6624 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6626 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6628 /* The default DWARF 2 accessibility for members is public, the default
6629 accessibility for inheritance is private. */
6631 if (die
->tag
!= DW_TAG_inheritance
)
6632 return DW_ACCESS_public
;
6634 return DW_ACCESS_private
;
6638 /* DWARF 3+ defines the default accessibility a different way. The same
6639 rules apply now for DW_TAG_inheritance as for the members and it only
6640 depends on the container kind. */
6642 if (die
->parent
->tag
== DW_TAG_class_type
)
6643 return DW_ACCESS_private
;
6645 return DW_ACCESS_public
;
6649 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6650 offset. If the attribute was not found return 0, otherwise return
6651 1. If it was found but could not properly be handled, set *OFFSET
6655 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
6658 struct attribute
*attr
;
6660 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6665 /* Note that we do not check for a section offset first here.
6666 This is because DW_AT_data_member_location is new in DWARF 4,
6667 so if we see it, we can assume that a constant form is really
6668 a constant and not a section offset. */
6669 if (attr_form_is_constant (attr
))
6670 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
6671 else if (attr_form_is_section_offset (attr
))
6672 dwarf2_complex_location_expr_complaint ();
6673 else if (attr_form_is_block (attr
))
6674 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6676 dwarf2_complex_location_expr_complaint ();
6684 /* Add an aggregate field to the field list. */
6687 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6688 struct dwarf2_cu
*cu
)
6690 struct objfile
*objfile
= cu
->objfile
;
6691 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6692 struct nextfield
*new_field
;
6693 struct attribute
*attr
;
6695 char *fieldname
= "";
6697 /* Allocate a new field list entry and link it in. */
6698 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6699 make_cleanup (xfree
, new_field
);
6700 memset (new_field
, 0, sizeof (struct nextfield
));
6702 if (die
->tag
== DW_TAG_inheritance
)
6704 new_field
->next
= fip
->baseclasses
;
6705 fip
->baseclasses
= new_field
;
6709 new_field
->next
= fip
->fields
;
6710 fip
->fields
= new_field
;
6714 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6716 new_field
->accessibility
= DW_UNSND (attr
);
6718 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
6719 if (new_field
->accessibility
!= DW_ACCESS_public
)
6720 fip
->non_public_fields
= 1;
6722 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6724 new_field
->virtuality
= DW_UNSND (attr
);
6726 new_field
->virtuality
= DW_VIRTUALITY_none
;
6728 fp
= &new_field
->field
;
6730 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6734 /* Data member other than a C++ static data member. */
6736 /* Get type of field. */
6737 fp
->type
= die_type (die
, cu
);
6739 SET_FIELD_BITPOS (*fp
, 0);
6741 /* Get bit size of field (zero if none). */
6742 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6745 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6749 FIELD_BITSIZE (*fp
) = 0;
6752 /* Get bit offset of field. */
6753 if (handle_data_member_location (die
, cu
, &offset
))
6754 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
6755 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6758 if (gdbarch_bits_big_endian (gdbarch
))
6760 /* For big endian bits, the DW_AT_bit_offset gives the
6761 additional bit offset from the MSB of the containing
6762 anonymous object to the MSB of the field. We don't
6763 have to do anything special since we don't need to
6764 know the size of the anonymous object. */
6765 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6769 /* For little endian bits, compute the bit offset to the
6770 MSB of the anonymous object, subtract off the number of
6771 bits from the MSB of the field to the MSB of the
6772 object, and then subtract off the number of bits of
6773 the field itself. The result is the bit offset of
6774 the LSB of the field. */
6776 int bit_offset
= DW_UNSND (attr
);
6778 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6781 /* The size of the anonymous object containing
6782 the bit field is explicit, so use the
6783 indicated size (in bytes). */
6784 anonymous_size
= DW_UNSND (attr
);
6788 /* The size of the anonymous object containing
6789 the bit field must be inferred from the type
6790 attribute of the data member containing the
6792 anonymous_size
= TYPE_LENGTH (fp
->type
);
6794 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6795 - bit_offset
- FIELD_BITSIZE (*fp
);
6799 /* Get name of field. */
6800 fieldname
= dwarf2_name (die
, cu
);
6801 if (fieldname
== NULL
)
6804 /* The name is already allocated along with this objfile, so we don't
6805 need to duplicate it for the type. */
6806 fp
->name
= fieldname
;
6808 /* Change accessibility for artificial fields (e.g. virtual table
6809 pointer or virtual base class pointer) to private. */
6810 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6812 FIELD_ARTIFICIAL (*fp
) = 1;
6813 new_field
->accessibility
= DW_ACCESS_private
;
6814 fip
->non_public_fields
= 1;
6817 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6819 /* C++ static member. */
6821 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6822 is a declaration, but all versions of G++ as of this writing
6823 (so through at least 3.2.1) incorrectly generate
6824 DW_TAG_variable tags. */
6826 const char *physname
;
6828 /* Get name of field. */
6829 fieldname
= dwarf2_name (die
, cu
);
6830 if (fieldname
== NULL
)
6833 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6835 /* Only create a symbol if this is an external value.
6836 new_symbol checks this and puts the value in the global symbol
6837 table, which we want. If it is not external, new_symbol
6838 will try to put the value in cu->list_in_scope which is wrong. */
6839 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6841 /* A static const member, not much different than an enum as far as
6842 we're concerned, except that we can support more types. */
6843 new_symbol (die
, NULL
, cu
);
6846 /* Get physical name. */
6847 physname
= dwarf2_physname (fieldname
, die
, cu
);
6849 /* The name is already allocated along with this objfile, so we don't
6850 need to duplicate it for the type. */
6851 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6852 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6853 FIELD_NAME (*fp
) = fieldname
;
6855 else if (die
->tag
== DW_TAG_inheritance
)
6859 /* C++ base class field. */
6860 if (handle_data_member_location (die
, cu
, &offset
))
6861 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
6862 FIELD_BITSIZE (*fp
) = 0;
6863 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6864 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6865 fip
->nbaseclasses
++;
6869 /* Add a typedef defined in the scope of the FIP's class. */
6872 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6873 struct dwarf2_cu
*cu
)
6875 struct objfile
*objfile
= cu
->objfile
;
6876 struct typedef_field_list
*new_field
;
6877 struct attribute
*attr
;
6878 struct typedef_field
*fp
;
6879 char *fieldname
= "";
6881 /* Allocate a new field list entry and link it in. */
6882 new_field
= xzalloc (sizeof (*new_field
));
6883 make_cleanup (xfree
, new_field
);
6885 gdb_assert (die
->tag
== DW_TAG_typedef
);
6887 fp
= &new_field
->field
;
6889 /* Get name of field. */
6890 fp
->name
= dwarf2_name (die
, cu
);
6891 if (fp
->name
== NULL
)
6894 fp
->type
= read_type_die (die
, cu
);
6896 new_field
->next
= fip
->typedef_field_list
;
6897 fip
->typedef_field_list
= new_field
;
6898 fip
->typedef_field_list_count
++;
6901 /* Create the vector of fields, and attach it to the type. */
6904 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6905 struct dwarf2_cu
*cu
)
6907 int nfields
= fip
->nfields
;
6909 /* Record the field count, allocate space for the array of fields,
6910 and create blank accessibility bitfields if necessary. */
6911 TYPE_NFIELDS (type
) = nfields
;
6912 TYPE_FIELDS (type
) = (struct field
*)
6913 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6914 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6916 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6918 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6920 TYPE_FIELD_PRIVATE_BITS (type
) =
6921 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6922 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6924 TYPE_FIELD_PROTECTED_BITS (type
) =
6925 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6926 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6928 TYPE_FIELD_IGNORE_BITS (type
) =
6929 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6930 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6933 /* If the type has baseclasses, allocate and clear a bit vector for
6934 TYPE_FIELD_VIRTUAL_BITS. */
6935 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6937 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6938 unsigned char *pointer
;
6940 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6941 pointer
= TYPE_ALLOC (type
, num_bytes
);
6942 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6943 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6944 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6947 /* Copy the saved-up fields into the field vector. Start from the head of
6948 the list, adding to the tail of the field array, so that they end up in
6949 the same order in the array in which they were added to the list. */
6950 while (nfields
-- > 0)
6952 struct nextfield
*fieldp
;
6956 fieldp
= fip
->fields
;
6957 fip
->fields
= fieldp
->next
;
6961 fieldp
= fip
->baseclasses
;
6962 fip
->baseclasses
= fieldp
->next
;
6965 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6966 switch (fieldp
->accessibility
)
6968 case DW_ACCESS_private
:
6969 if (cu
->language
!= language_ada
)
6970 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6973 case DW_ACCESS_protected
:
6974 if (cu
->language
!= language_ada
)
6975 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6978 case DW_ACCESS_public
:
6982 /* Unknown accessibility. Complain and treat it as public. */
6984 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6985 fieldp
->accessibility
);
6989 if (nfields
< fip
->nbaseclasses
)
6991 switch (fieldp
->virtuality
)
6993 case DW_VIRTUALITY_virtual
:
6994 case DW_VIRTUALITY_pure_virtual
:
6995 if (cu
->language
== language_ada
)
6996 error (_("unexpected virtuality in component of Ada type"));
6997 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
7004 /* Add a member function to the proper fieldlist. */
7007 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
7008 struct type
*type
, struct dwarf2_cu
*cu
)
7010 struct objfile
*objfile
= cu
->objfile
;
7011 struct attribute
*attr
;
7012 struct fnfieldlist
*flp
;
7014 struct fn_field
*fnp
;
7016 struct nextfnfield
*new_fnfield
;
7017 struct type
*this_type
;
7018 enum dwarf_access_attribute accessibility
;
7020 if (cu
->language
== language_ada
)
7021 error (_("unexpected member function in Ada type"));
7023 /* Get name of member function. */
7024 fieldname
= dwarf2_name (die
, cu
);
7025 if (fieldname
== NULL
)
7028 /* Look up member function name in fieldlist. */
7029 for (i
= 0; i
< fip
->nfnfields
; i
++)
7031 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7035 /* Create new list element if necessary. */
7036 if (i
< fip
->nfnfields
)
7037 flp
= &fip
->fnfieldlists
[i
];
7040 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7042 fip
->fnfieldlists
= (struct fnfieldlist
*)
7043 xrealloc (fip
->fnfieldlists
,
7044 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7045 * sizeof (struct fnfieldlist
));
7046 if (fip
->nfnfields
== 0)
7047 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7049 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7050 flp
->name
= fieldname
;
7053 i
= fip
->nfnfields
++;
7056 /* Create a new member function field and chain it to the field list
7058 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7059 make_cleanup (xfree
, new_fnfield
);
7060 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7061 new_fnfield
->next
= flp
->head
;
7062 flp
->head
= new_fnfield
;
7065 /* Fill in the member function field info. */
7066 fnp
= &new_fnfield
->fnfield
;
7068 /* Delay processing of the physname until later. */
7069 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7071 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7076 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7077 fnp
->physname
= physname
? physname
: "";
7080 fnp
->type
= alloc_type (objfile
);
7081 this_type
= read_type_die (die
, cu
);
7082 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7084 int nparams
= TYPE_NFIELDS (this_type
);
7086 /* TYPE is the domain of this method, and THIS_TYPE is the type
7087 of the method itself (TYPE_CODE_METHOD). */
7088 smash_to_method_type (fnp
->type
, type
,
7089 TYPE_TARGET_TYPE (this_type
),
7090 TYPE_FIELDS (this_type
),
7091 TYPE_NFIELDS (this_type
),
7092 TYPE_VARARGS (this_type
));
7094 /* Handle static member functions.
7095 Dwarf2 has no clean way to discern C++ static and non-static
7096 member functions. G++ helps GDB by marking the first
7097 parameter for non-static member functions (which is the this
7098 pointer) as artificial. We obtain this information from
7099 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7100 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7101 fnp
->voffset
= VOFFSET_STATIC
;
7104 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7105 dwarf2_full_name (fieldname
, die
, cu
));
7107 /* Get fcontext from DW_AT_containing_type if present. */
7108 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7109 fnp
->fcontext
= die_containing_type (die
, cu
);
7111 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7112 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7114 /* Get accessibility. */
7115 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7117 accessibility
= DW_UNSND (attr
);
7119 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7120 switch (accessibility
)
7122 case DW_ACCESS_private
:
7123 fnp
->is_private
= 1;
7125 case DW_ACCESS_protected
:
7126 fnp
->is_protected
= 1;
7130 /* Check for artificial methods. */
7131 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7132 if (attr
&& DW_UNSND (attr
) != 0)
7133 fnp
->is_artificial
= 1;
7135 /* Get index in virtual function table if it is a virtual member
7136 function. For older versions of GCC, this is an offset in the
7137 appropriate virtual table, as specified by DW_AT_containing_type.
7138 For everyone else, it is an expression to be evaluated relative
7139 to the object address. */
7141 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7144 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7146 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7148 /* Old-style GCC. */
7149 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7151 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7152 || (DW_BLOCK (attr
)->size
> 1
7153 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7154 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7156 struct dwarf_block blk
;
7159 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7161 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7162 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7163 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7164 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7165 dwarf2_complex_location_expr_complaint ();
7167 fnp
->voffset
/= cu
->header
.addr_size
;
7171 dwarf2_complex_location_expr_complaint ();
7174 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7176 else if (attr_form_is_section_offset (attr
))
7178 dwarf2_complex_location_expr_complaint ();
7182 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7188 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7189 if (attr
&& DW_UNSND (attr
))
7191 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7192 complaint (&symfile_complaints
,
7193 _("Member function \"%s\" (offset %d) is virtual "
7194 "but the vtable offset is not specified"),
7195 fieldname
, die
->offset
);
7196 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7197 TYPE_CPLUS_DYNAMIC (type
) = 1;
7202 /* Create the vector of member function fields, and attach it to the type. */
7205 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7206 struct dwarf2_cu
*cu
)
7208 struct fnfieldlist
*flp
;
7209 int total_length
= 0;
7212 if (cu
->language
== language_ada
)
7213 error (_("unexpected member functions in Ada type"));
7215 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7216 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7217 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7219 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7221 struct nextfnfield
*nfp
= flp
->head
;
7222 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7225 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7226 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7227 fn_flp
->fn_fields
= (struct fn_field
*)
7228 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7229 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7230 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7232 total_length
+= flp
->length
;
7235 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7236 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
7239 /* Returns non-zero if NAME is the name of a vtable member in CU's
7240 language, zero otherwise. */
7242 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7244 static const char vptr
[] = "_vptr";
7245 static const char vtable
[] = "vtable";
7247 /* Look for the C++ and Java forms of the vtable. */
7248 if ((cu
->language
== language_java
7249 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7250 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7251 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7257 /* GCC outputs unnamed structures that are really pointers to member
7258 functions, with the ABI-specified layout. If TYPE describes
7259 such a structure, smash it into a member function type.
7261 GCC shouldn't do this; it should just output pointer to member DIEs.
7262 This is GCC PR debug/28767. */
7265 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7267 struct type
*pfn_type
, *domain_type
, *new_type
;
7269 /* Check for a structure with no name and two children. */
7270 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7273 /* Check for __pfn and __delta members. */
7274 if (TYPE_FIELD_NAME (type
, 0) == NULL
7275 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7276 || TYPE_FIELD_NAME (type
, 1) == NULL
7277 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7280 /* Find the type of the method. */
7281 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7282 if (pfn_type
== NULL
7283 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7284 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7287 /* Look for the "this" argument. */
7288 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7289 if (TYPE_NFIELDS (pfn_type
) == 0
7290 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7291 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7294 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7295 new_type
= alloc_type (objfile
);
7296 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7297 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7298 TYPE_VARARGS (pfn_type
));
7299 smash_to_methodptr_type (type
, new_type
);
7302 /* Called when we find the DIE that starts a structure or union scope
7303 (definition) to create a type for the structure or union. Fill in
7304 the type's name and general properties; the members will not be
7305 processed until process_structure_type.
7307 NOTE: we need to call these functions regardless of whether or not the
7308 DIE has a DW_AT_name attribute, since it might be an anonymous
7309 structure or union. This gets the type entered into our set of
7312 However, if the structure is incomplete (an opaque struct/union)
7313 then suppress creating a symbol table entry for it since gdb only
7314 wants to find the one with the complete definition. Note that if
7315 it is complete, we just call new_symbol, which does it's own
7316 checking about whether the struct/union is anonymous or not (and
7317 suppresses creating a symbol table entry itself). */
7319 static struct type
*
7320 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7322 struct objfile
*objfile
= cu
->objfile
;
7324 struct attribute
*attr
;
7327 /* If the definition of this type lives in .debug_types, read that type.
7328 Don't follow DW_AT_specification though, that will take us back up
7329 the chain and we want to go down. */
7330 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7333 struct dwarf2_cu
*type_cu
= cu
;
7334 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7336 /* We could just recurse on read_structure_type, but we need to call
7337 get_die_type to ensure only one type for this DIE is created.
7338 This is important, for example, because for c++ classes we need
7339 TYPE_NAME set which is only done by new_symbol. Blech. */
7340 type
= read_type_die (type_die
, type_cu
);
7342 /* TYPE_CU may not be the same as CU.
7343 Ensure TYPE is recorded in CU's type_hash table. */
7344 return set_die_type (die
, type
, cu
);
7347 type
= alloc_type (objfile
);
7348 INIT_CPLUS_SPECIFIC (type
);
7350 name
= dwarf2_name (die
, cu
);
7353 if (cu
->language
== language_cplus
7354 || cu
->language
== language_java
)
7356 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7358 /* dwarf2_full_name might have already finished building the DIE's
7359 type. If so, there is no need to continue. */
7360 if (get_die_type (die
, cu
) != NULL
)
7361 return get_die_type (die
, cu
);
7363 TYPE_TAG_NAME (type
) = full_name
;
7364 if (die
->tag
== DW_TAG_structure_type
7365 || die
->tag
== DW_TAG_class_type
)
7366 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7370 /* The name is already allocated along with this objfile, so
7371 we don't need to duplicate it for the type. */
7372 TYPE_TAG_NAME (type
) = (char *) name
;
7373 if (die
->tag
== DW_TAG_class_type
)
7374 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7378 if (die
->tag
== DW_TAG_structure_type
)
7380 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7382 else if (die
->tag
== DW_TAG_union_type
)
7384 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7388 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7391 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7392 TYPE_DECLARED_CLASS (type
) = 1;
7394 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7397 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7401 TYPE_LENGTH (type
) = 0;
7404 TYPE_STUB_SUPPORTED (type
) = 1;
7405 if (die_is_declaration (die
, cu
))
7406 TYPE_STUB (type
) = 1;
7407 else if (attr
== NULL
&& die
->child
== NULL
7408 && producer_is_realview (cu
->producer
))
7409 /* RealView does not output the required DW_AT_declaration
7410 on incomplete types. */
7411 TYPE_STUB (type
) = 1;
7413 /* We need to add the type field to the die immediately so we don't
7414 infinitely recurse when dealing with pointers to the structure
7415 type within the structure itself. */
7416 set_die_type (die
, type
, cu
);
7418 /* set_die_type should be already done. */
7419 set_descriptive_type (type
, die
, cu
);
7424 /* Finish creating a structure or union type, including filling in
7425 its members and creating a symbol for it. */
7428 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7430 struct objfile
*objfile
= cu
->objfile
;
7431 struct die_info
*child_die
= die
->child
;
7434 type
= get_die_type (die
, cu
);
7436 type
= read_structure_type (die
, cu
);
7438 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7440 struct field_info fi
;
7441 struct die_info
*child_die
;
7442 VEC (symbolp
) *template_args
= NULL
;
7443 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7445 memset (&fi
, 0, sizeof (struct field_info
));
7447 child_die
= die
->child
;
7449 while (child_die
&& child_die
->tag
)
7451 if (child_die
->tag
== DW_TAG_member
7452 || child_die
->tag
== DW_TAG_variable
)
7454 /* NOTE: carlton/2002-11-05: A C++ static data member
7455 should be a DW_TAG_member that is a declaration, but
7456 all versions of G++ as of this writing (so through at
7457 least 3.2.1) incorrectly generate DW_TAG_variable
7458 tags for them instead. */
7459 dwarf2_add_field (&fi
, child_die
, cu
);
7461 else if (child_die
->tag
== DW_TAG_subprogram
)
7463 /* C++ member function. */
7464 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7466 else if (child_die
->tag
== DW_TAG_inheritance
)
7468 /* C++ base class field. */
7469 dwarf2_add_field (&fi
, child_die
, cu
);
7471 else if (child_die
->tag
== DW_TAG_typedef
)
7472 dwarf2_add_typedef (&fi
, child_die
, cu
);
7473 else if (child_die
->tag
== DW_TAG_template_type_param
7474 || child_die
->tag
== DW_TAG_template_value_param
)
7476 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7479 VEC_safe_push (symbolp
, template_args
, arg
);
7482 child_die
= sibling_die (child_die
);
7485 /* Attach template arguments to type. */
7486 if (! VEC_empty (symbolp
, template_args
))
7488 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7489 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7490 = VEC_length (symbolp
, template_args
);
7491 TYPE_TEMPLATE_ARGUMENTS (type
)
7492 = obstack_alloc (&objfile
->objfile_obstack
,
7493 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7494 * sizeof (struct symbol
*)));
7495 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7496 VEC_address (symbolp
, template_args
),
7497 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7498 * sizeof (struct symbol
*)));
7499 VEC_free (symbolp
, template_args
);
7502 /* Attach fields and member functions to the type. */
7504 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7507 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7509 /* Get the type which refers to the base class (possibly this
7510 class itself) which contains the vtable pointer for the current
7511 class from the DW_AT_containing_type attribute. This use of
7512 DW_AT_containing_type is a GNU extension. */
7514 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7516 struct type
*t
= die_containing_type (die
, cu
);
7518 TYPE_VPTR_BASETYPE (type
) = t
;
7523 /* Our own class provides vtbl ptr. */
7524 for (i
= TYPE_NFIELDS (t
) - 1;
7525 i
>= TYPE_N_BASECLASSES (t
);
7528 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7530 if (is_vtable_name (fieldname
, cu
))
7532 TYPE_VPTR_FIELDNO (type
) = i
;
7537 /* Complain if virtual function table field not found. */
7538 if (i
< TYPE_N_BASECLASSES (t
))
7539 complaint (&symfile_complaints
,
7540 _("virtual function table pointer "
7541 "not found when defining class '%s'"),
7542 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7547 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7550 else if (cu
->producer
7551 && strncmp (cu
->producer
,
7552 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7554 /* The IBM XLC compiler does not provide direct indication
7555 of the containing type, but the vtable pointer is
7556 always named __vfp. */
7560 for (i
= TYPE_NFIELDS (type
) - 1;
7561 i
>= TYPE_N_BASECLASSES (type
);
7564 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7566 TYPE_VPTR_FIELDNO (type
) = i
;
7567 TYPE_VPTR_BASETYPE (type
) = type
;
7574 /* Copy fi.typedef_field_list linked list elements content into the
7575 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7576 if (fi
.typedef_field_list
)
7578 int i
= fi
.typedef_field_list_count
;
7580 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7581 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7582 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7583 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7585 /* Reverse the list order to keep the debug info elements order. */
7588 struct typedef_field
*dest
, *src
;
7590 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7591 src
= &fi
.typedef_field_list
->field
;
7592 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7597 do_cleanups (back_to
);
7599 if (HAVE_CPLUS_STRUCT (type
))
7600 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
7603 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
7605 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7606 snapshots) has been known to create a die giving a declaration
7607 for a class that has, as a child, a die giving a definition for a
7608 nested class. So we have to process our children even if the
7609 current die is a declaration. Normally, of course, a declaration
7610 won't have any children at all. */
7612 while (child_die
!= NULL
&& child_die
->tag
)
7614 if (child_die
->tag
== DW_TAG_member
7615 || child_die
->tag
== DW_TAG_variable
7616 || child_die
->tag
== DW_TAG_inheritance
7617 || child_die
->tag
== DW_TAG_template_value_param
7618 || child_die
->tag
== DW_TAG_template_type_param
)
7623 process_die (child_die
, cu
);
7625 child_die
= sibling_die (child_die
);
7628 /* Do not consider external references. According to the DWARF standard,
7629 these DIEs are identified by the fact that they have no byte_size
7630 attribute, and a declaration attribute. */
7631 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7632 || !die_is_declaration (die
, cu
))
7633 new_symbol (die
, type
, cu
);
7636 /* Given a DW_AT_enumeration_type die, set its type. We do not
7637 complete the type's fields yet, or create any symbols. */
7639 static struct type
*
7640 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7642 struct objfile
*objfile
= cu
->objfile
;
7644 struct attribute
*attr
;
7647 /* If the definition of this type lives in .debug_types, read that type.
7648 Don't follow DW_AT_specification though, that will take us back up
7649 the chain and we want to go down. */
7650 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7653 struct dwarf2_cu
*type_cu
= cu
;
7654 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7656 type
= read_type_die (type_die
, type_cu
);
7658 /* TYPE_CU may not be the same as CU.
7659 Ensure TYPE is recorded in CU's type_hash table. */
7660 return set_die_type (die
, type
, cu
);
7663 type
= alloc_type (objfile
);
7665 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7666 name
= dwarf2_full_name (NULL
, die
, cu
);
7668 TYPE_TAG_NAME (type
) = (char *) name
;
7670 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7673 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7677 TYPE_LENGTH (type
) = 0;
7680 /* The enumeration DIE can be incomplete. In Ada, any type can be
7681 declared as private in the package spec, and then defined only
7682 inside the package body. Such types are known as Taft Amendment
7683 Types. When another package uses such a type, an incomplete DIE
7684 may be generated by the compiler. */
7685 if (die_is_declaration (die
, cu
))
7686 TYPE_STUB (type
) = 1;
7688 return set_die_type (die
, type
, cu
);
7691 /* Given a pointer to a die which begins an enumeration, process all
7692 the dies that define the members of the enumeration, and create the
7693 symbol for the enumeration type.
7695 NOTE: We reverse the order of the element list. */
7698 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7700 struct type
*this_type
;
7702 this_type
= get_die_type (die
, cu
);
7703 if (this_type
== NULL
)
7704 this_type
= read_enumeration_type (die
, cu
);
7706 if (die
->child
!= NULL
)
7708 struct die_info
*child_die
;
7710 struct field
*fields
= NULL
;
7712 int unsigned_enum
= 1;
7715 child_die
= die
->child
;
7716 while (child_die
&& child_die
->tag
)
7718 if (child_die
->tag
!= DW_TAG_enumerator
)
7720 process_die (child_die
, cu
);
7724 name
= dwarf2_name (child_die
, cu
);
7727 sym
= new_symbol (child_die
, this_type
, cu
);
7728 if (SYMBOL_VALUE (sym
) < 0)
7731 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7733 fields
= (struct field
*)
7735 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7736 * sizeof (struct field
));
7739 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7740 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7741 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7742 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7748 child_die
= sibling_die (child_die
);
7753 TYPE_NFIELDS (this_type
) = num_fields
;
7754 TYPE_FIELDS (this_type
) = (struct field
*)
7755 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7756 memcpy (TYPE_FIELDS (this_type
), fields
,
7757 sizeof (struct field
) * num_fields
);
7761 TYPE_UNSIGNED (this_type
) = 1;
7764 /* If we are reading an enum from a .debug_types unit, and the enum
7765 is a declaration, and the enum is not the signatured type in the
7766 unit, then we do not want to add a symbol for it. Adding a
7767 symbol would in some cases obscure the true definition of the
7768 enum, giving users an incomplete type when the definition is
7769 actually available. Note that we do not want to do this for all
7770 enums which are just declarations, because C++0x allows forward
7771 enum declarations. */
7772 if (cu
->per_cu
->debug_type_section
7773 && die_is_declaration (die
, cu
))
7775 struct signatured_type
*type_sig
;
7778 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
7779 cu
->per_cu
->debug_type_section
,
7780 cu
->per_cu
->offset
);
7781 if (type_sig
->type_offset
!= die
->offset
)
7785 new_symbol (die
, this_type
, cu
);
7788 /* Extract all information from a DW_TAG_array_type DIE and put it in
7789 the DIE's type field. For now, this only handles one dimensional
7792 static struct type
*
7793 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7795 struct objfile
*objfile
= cu
->objfile
;
7796 struct die_info
*child_die
;
7798 struct type
*element_type
, *range_type
, *index_type
;
7799 struct type
**range_types
= NULL
;
7800 struct attribute
*attr
;
7802 struct cleanup
*back_to
;
7805 element_type
= die_type (die
, cu
);
7807 /* The die_type call above may have already set the type for this DIE. */
7808 type
= get_die_type (die
, cu
);
7812 /* Irix 6.2 native cc creates array types without children for
7813 arrays with unspecified length. */
7814 if (die
->child
== NULL
)
7816 index_type
= objfile_type (objfile
)->builtin_int
;
7817 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7818 type
= create_array_type (NULL
, element_type
, range_type
);
7819 return set_die_type (die
, type
, cu
);
7822 back_to
= make_cleanup (null_cleanup
, NULL
);
7823 child_die
= die
->child
;
7824 while (child_die
&& child_die
->tag
)
7826 if (child_die
->tag
== DW_TAG_subrange_type
)
7828 struct type
*child_type
= read_type_die (child_die
, cu
);
7830 if (child_type
!= NULL
)
7832 /* The range type was succesfully read. Save it for the
7833 array type creation. */
7834 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7836 range_types
= (struct type
**)
7837 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7838 * sizeof (struct type
*));
7840 make_cleanup (free_current_contents
, &range_types
);
7842 range_types
[ndim
++] = child_type
;
7845 child_die
= sibling_die (child_die
);
7848 /* Dwarf2 dimensions are output from left to right, create the
7849 necessary array types in backwards order. */
7851 type
= element_type
;
7853 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7858 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7863 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7866 /* Understand Dwarf2 support for vector types (like they occur on
7867 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7868 array type. This is not part of the Dwarf2/3 standard yet, but a
7869 custom vendor extension. The main difference between a regular
7870 array and the vector variant is that vectors are passed by value
7872 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7874 make_vector_type (type
);
7876 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7877 implementation may choose to implement triple vectors using this
7879 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7882 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
7883 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7885 complaint (&symfile_complaints
,
7886 _("DW_AT_byte_size for array type smaller "
7887 "than the total size of elements"));
7890 name
= dwarf2_name (die
, cu
);
7892 TYPE_NAME (type
) = name
;
7894 /* Install the type in the die. */
7895 set_die_type (die
, type
, cu
);
7897 /* set_die_type should be already done. */
7898 set_descriptive_type (type
, die
, cu
);
7900 do_cleanups (back_to
);
7905 static enum dwarf_array_dim_ordering
7906 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7908 struct attribute
*attr
;
7910 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7912 if (attr
) return DW_SND (attr
);
7914 /* GNU F77 is a special case, as at 08/2004 array type info is the
7915 opposite order to the dwarf2 specification, but data is still
7916 laid out as per normal fortran.
7918 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7919 version checking. */
7921 if (cu
->language
== language_fortran
7922 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7924 return DW_ORD_row_major
;
7927 switch (cu
->language_defn
->la_array_ordering
)
7929 case array_column_major
:
7930 return DW_ORD_col_major
;
7931 case array_row_major
:
7933 return DW_ORD_row_major
;
7937 /* Extract all information from a DW_TAG_set_type DIE and put it in
7938 the DIE's type field. */
7940 static struct type
*
7941 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7943 struct type
*domain_type
, *set_type
;
7944 struct attribute
*attr
;
7946 domain_type
= die_type (die
, cu
);
7948 /* The die_type call above may have already set the type for this DIE. */
7949 set_type
= get_die_type (die
, cu
);
7953 set_type
= create_set_type (NULL
, domain_type
);
7955 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7957 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7959 return set_die_type (die
, set_type
, cu
);
7962 /* First cut: install each common block member as a global variable. */
7965 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7967 struct die_info
*child_die
;
7968 struct attribute
*attr
;
7970 CORE_ADDR base
= (CORE_ADDR
) 0;
7972 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7975 /* Support the .debug_loc offsets. */
7976 if (attr_form_is_block (attr
))
7978 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7980 else if (attr_form_is_section_offset (attr
))
7982 dwarf2_complex_location_expr_complaint ();
7986 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7987 "common block member");
7990 if (die
->child
!= NULL
)
7992 child_die
= die
->child
;
7993 while (child_die
&& child_die
->tag
)
7997 sym
= new_symbol (child_die
, NULL
, cu
);
7999 && handle_data_member_location (child_die
, cu
, &offset
))
8001 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
8002 add_symbol_to_list (sym
, &global_symbols
);
8004 child_die
= sibling_die (child_die
);
8009 /* Create a type for a C++ namespace. */
8011 static struct type
*
8012 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8014 struct objfile
*objfile
= cu
->objfile
;
8015 const char *previous_prefix
, *name
;
8019 /* For extensions, reuse the type of the original namespace. */
8020 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
8022 struct die_info
*ext_die
;
8023 struct dwarf2_cu
*ext_cu
= cu
;
8025 ext_die
= dwarf2_extension (die
, &ext_cu
);
8026 type
= read_type_die (ext_die
, ext_cu
);
8028 /* EXT_CU may not be the same as CU.
8029 Ensure TYPE is recorded in CU's type_hash table. */
8030 return set_die_type (die
, type
, cu
);
8033 name
= namespace_name (die
, &is_anonymous
, cu
);
8035 /* Now build the name of the current namespace. */
8037 previous_prefix
= determine_prefix (die
, cu
);
8038 if (previous_prefix
[0] != '\0')
8039 name
= typename_concat (&objfile
->objfile_obstack
,
8040 previous_prefix
, name
, 0, cu
);
8042 /* Create the type. */
8043 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8045 TYPE_NAME (type
) = (char *) name
;
8046 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8048 return set_die_type (die
, type
, cu
);
8051 /* Read a C++ namespace. */
8054 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8056 struct objfile
*objfile
= cu
->objfile
;
8059 /* Add a symbol associated to this if we haven't seen the namespace
8060 before. Also, add a using directive if it's an anonymous
8063 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8067 type
= read_type_die (die
, cu
);
8068 new_symbol (die
, type
, cu
);
8070 namespace_name (die
, &is_anonymous
, cu
);
8073 const char *previous_prefix
= determine_prefix (die
, cu
);
8075 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8076 NULL
, NULL
, &objfile
->objfile_obstack
);
8080 if (die
->child
!= NULL
)
8082 struct die_info
*child_die
= die
->child
;
8084 while (child_die
&& child_die
->tag
)
8086 process_die (child_die
, cu
);
8087 child_die
= sibling_die (child_die
);
8092 /* Read a Fortran module as type. This DIE can be only a declaration used for
8093 imported module. Still we need that type as local Fortran "use ... only"
8094 declaration imports depend on the created type in determine_prefix. */
8096 static struct type
*
8097 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8099 struct objfile
*objfile
= cu
->objfile
;
8103 module_name
= dwarf2_name (die
, cu
);
8105 complaint (&symfile_complaints
,
8106 _("DW_TAG_module has no name, offset 0x%x"),
8108 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8110 /* determine_prefix uses TYPE_TAG_NAME. */
8111 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8113 return set_die_type (die
, type
, cu
);
8116 /* Read a Fortran module. */
8119 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8121 struct die_info
*child_die
= die
->child
;
8123 while (child_die
&& child_die
->tag
)
8125 process_die (child_die
, cu
);
8126 child_die
= sibling_die (child_die
);
8130 /* Return the name of the namespace represented by DIE. Set
8131 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8135 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8137 struct die_info
*current_die
;
8138 const char *name
= NULL
;
8140 /* Loop through the extensions until we find a name. */
8142 for (current_die
= die
;
8143 current_die
!= NULL
;
8144 current_die
= dwarf2_extension (die
, &cu
))
8146 name
= dwarf2_name (current_die
, cu
);
8151 /* Is it an anonymous namespace? */
8153 *is_anonymous
= (name
== NULL
);
8155 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8160 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8161 the user defined type vector. */
8163 static struct type
*
8164 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8166 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8167 struct comp_unit_head
*cu_header
= &cu
->header
;
8169 struct attribute
*attr_byte_size
;
8170 struct attribute
*attr_address_class
;
8171 int byte_size
, addr_class
;
8172 struct type
*target_type
;
8174 target_type
= die_type (die
, cu
);
8176 /* The die_type call above may have already set the type for this DIE. */
8177 type
= get_die_type (die
, cu
);
8181 type
= lookup_pointer_type (target_type
);
8183 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8185 byte_size
= DW_UNSND (attr_byte_size
);
8187 byte_size
= cu_header
->addr_size
;
8189 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8190 if (attr_address_class
)
8191 addr_class
= DW_UNSND (attr_address_class
);
8193 addr_class
= DW_ADDR_none
;
8195 /* If the pointer size or address class is different than the
8196 default, create a type variant marked as such and set the
8197 length accordingly. */
8198 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8200 if (gdbarch_address_class_type_flags_p (gdbarch
))
8204 type_flags
= gdbarch_address_class_type_flags
8205 (gdbarch
, byte_size
, addr_class
);
8206 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8208 type
= make_type_with_address_space (type
, type_flags
);
8210 else if (TYPE_LENGTH (type
) != byte_size
)
8212 complaint (&symfile_complaints
,
8213 _("invalid pointer size %d"), byte_size
);
8217 /* Should we also complain about unhandled address classes? */
8221 TYPE_LENGTH (type
) = byte_size
;
8222 return set_die_type (die
, type
, cu
);
8225 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8226 the user defined type vector. */
8228 static struct type
*
8229 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8232 struct type
*to_type
;
8233 struct type
*domain
;
8235 to_type
= die_type (die
, cu
);
8236 domain
= die_containing_type (die
, cu
);
8238 /* The calls above may have already set the type for this DIE. */
8239 type
= get_die_type (die
, cu
);
8243 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8244 type
= lookup_methodptr_type (to_type
);
8246 type
= lookup_memberptr_type (to_type
, domain
);
8248 return set_die_type (die
, type
, cu
);
8251 /* Extract all information from a DW_TAG_reference_type DIE and add to
8252 the user defined type vector. */
8254 static struct type
*
8255 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8257 struct comp_unit_head
*cu_header
= &cu
->header
;
8258 struct type
*type
, *target_type
;
8259 struct attribute
*attr
;
8261 target_type
= die_type (die
, cu
);
8263 /* The die_type call above may have already set the type for this DIE. */
8264 type
= get_die_type (die
, cu
);
8268 type
= lookup_reference_type (target_type
);
8269 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8272 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8276 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8278 return set_die_type (die
, type
, cu
);
8281 static struct type
*
8282 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8284 struct type
*base_type
, *cv_type
;
8286 base_type
= die_type (die
, cu
);
8288 /* The die_type call above may have already set the type for this DIE. */
8289 cv_type
= get_die_type (die
, cu
);
8293 /* In case the const qualifier is applied to an array type, the element type
8294 is so qualified, not the array type (section 6.7.3 of C99). */
8295 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8297 struct type
*el_type
, *inner_array
;
8299 base_type
= copy_type (base_type
);
8300 inner_array
= base_type
;
8302 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8304 TYPE_TARGET_TYPE (inner_array
) =
8305 copy_type (TYPE_TARGET_TYPE (inner_array
));
8306 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8309 el_type
= TYPE_TARGET_TYPE (inner_array
);
8310 TYPE_TARGET_TYPE (inner_array
) =
8311 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8313 return set_die_type (die
, base_type
, cu
);
8316 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8317 return set_die_type (die
, cv_type
, cu
);
8320 static struct type
*
8321 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8323 struct type
*base_type
, *cv_type
;
8325 base_type
= die_type (die
, cu
);
8327 /* The die_type call above may have already set the type for this DIE. */
8328 cv_type
= get_die_type (die
, cu
);
8332 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8333 return set_die_type (die
, cv_type
, cu
);
8336 /* Extract all information from a DW_TAG_string_type DIE and add to
8337 the user defined type vector. It isn't really a user defined type,
8338 but it behaves like one, with other DIE's using an AT_user_def_type
8339 attribute to reference it. */
8341 static struct type
*
8342 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8344 struct objfile
*objfile
= cu
->objfile
;
8345 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8346 struct type
*type
, *range_type
, *index_type
, *char_type
;
8347 struct attribute
*attr
;
8348 unsigned int length
;
8350 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8353 length
= DW_UNSND (attr
);
8357 /* Check for the DW_AT_byte_size attribute. */
8358 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8361 length
= DW_UNSND (attr
);
8369 index_type
= objfile_type (objfile
)->builtin_int
;
8370 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8371 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8372 type
= create_string_type (NULL
, char_type
, range_type
);
8374 return set_die_type (die
, type
, cu
);
8377 /* Handle DIES due to C code like:
8381 int (*funcp)(int a, long l);
8385 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8387 static struct type
*
8388 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8390 struct type
*type
; /* Type that this function returns. */
8391 struct type
*ftype
; /* Function that returns above type. */
8392 struct attribute
*attr
;
8394 type
= die_type (die
, cu
);
8396 /* The die_type call above may have already set the type for this DIE. */
8397 ftype
= get_die_type (die
, cu
);
8401 ftype
= lookup_function_type (type
);
8403 /* All functions in C++, Pascal and Java have prototypes. */
8404 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8405 if ((attr
&& (DW_UNSND (attr
) != 0))
8406 || cu
->language
== language_cplus
8407 || cu
->language
== language_java
8408 || cu
->language
== language_pascal
)
8409 TYPE_PROTOTYPED (ftype
) = 1;
8410 else if (producer_is_realview (cu
->producer
))
8411 /* RealView does not emit DW_AT_prototyped. We can not
8412 distinguish prototyped and unprototyped functions; default to
8413 prototyped, since that is more common in modern code (and
8414 RealView warns about unprototyped functions). */
8415 TYPE_PROTOTYPED (ftype
) = 1;
8417 /* Store the calling convention in the type if it's available in
8418 the subroutine die. Otherwise set the calling convention to
8419 the default value DW_CC_normal. */
8420 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8422 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8423 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8424 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8426 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8428 /* We need to add the subroutine type to the die immediately so
8429 we don't infinitely recurse when dealing with parameters
8430 declared as the same subroutine type. */
8431 set_die_type (die
, ftype
, cu
);
8433 if (die
->child
!= NULL
)
8435 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
8436 struct die_info
*child_die
;
8437 int nparams
, iparams
;
8439 /* Count the number of parameters.
8440 FIXME: GDB currently ignores vararg functions, but knows about
8441 vararg member functions. */
8443 child_die
= die
->child
;
8444 while (child_die
&& child_die
->tag
)
8446 if (child_die
->tag
== DW_TAG_formal_parameter
)
8448 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8449 TYPE_VARARGS (ftype
) = 1;
8450 child_die
= sibling_die (child_die
);
8453 /* Allocate storage for parameters and fill them in. */
8454 TYPE_NFIELDS (ftype
) = nparams
;
8455 TYPE_FIELDS (ftype
) = (struct field
*)
8456 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8458 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8459 even if we error out during the parameters reading below. */
8460 for (iparams
= 0; iparams
< nparams
; iparams
++)
8461 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8464 child_die
= die
->child
;
8465 while (child_die
&& child_die
->tag
)
8467 if (child_die
->tag
== DW_TAG_formal_parameter
)
8469 struct type
*arg_type
;
8471 /* DWARF version 2 has no clean way to discern C++
8472 static and non-static member functions. G++ helps
8473 GDB by marking the first parameter for non-static
8474 member functions (which is the this pointer) as
8475 artificial. We pass this information to
8476 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8478 DWARF version 3 added DW_AT_object_pointer, which GCC
8479 4.5 does not yet generate. */
8480 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8482 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8485 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8487 /* GCC/43521: In java, the formal parameter
8488 "this" is sometimes not marked with DW_AT_artificial. */
8489 if (cu
->language
== language_java
)
8491 const char *name
= dwarf2_name (child_die
, cu
);
8493 if (name
&& !strcmp (name
, "this"))
8494 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8497 arg_type
= die_type (child_die
, cu
);
8499 /* RealView does not mark THIS as const, which the testsuite
8500 expects. GCC marks THIS as const in method definitions,
8501 but not in the class specifications (GCC PR 43053). */
8502 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8503 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8506 struct dwarf2_cu
*arg_cu
= cu
;
8507 const char *name
= dwarf2_name (child_die
, cu
);
8509 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8512 /* If the compiler emits this, use it. */
8513 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8516 else if (name
&& strcmp (name
, "this") == 0)
8517 /* Function definitions will have the argument names. */
8519 else if (name
== NULL
&& iparams
== 0)
8520 /* Declarations may not have the names, so like
8521 elsewhere in GDB, assume an artificial first
8522 argument is "this". */
8526 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8530 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8533 child_die
= sibling_die (child_die
);
8540 static struct type
*
8541 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8543 struct objfile
*objfile
= cu
->objfile
;
8544 const char *name
= NULL
;
8545 struct type
*this_type
;
8547 name
= dwarf2_full_name (NULL
, die
, cu
);
8548 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8549 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8550 TYPE_NAME (this_type
) = (char *) name
;
8551 set_die_type (die
, this_type
, cu
);
8552 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
8556 /* Find a representation of a given base type and install
8557 it in the TYPE field of the die. */
8559 static struct type
*
8560 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8562 struct objfile
*objfile
= cu
->objfile
;
8564 struct attribute
*attr
;
8565 int encoding
= 0, size
= 0;
8567 enum type_code code
= TYPE_CODE_INT
;
8569 struct type
*target_type
= NULL
;
8571 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8574 encoding
= DW_UNSND (attr
);
8576 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8579 size
= DW_UNSND (attr
);
8581 name
= dwarf2_name (die
, cu
);
8584 complaint (&symfile_complaints
,
8585 _("DW_AT_name missing from DW_TAG_base_type"));
8590 case DW_ATE_address
:
8591 /* Turn DW_ATE_address into a void * pointer. */
8592 code
= TYPE_CODE_PTR
;
8593 type_flags
|= TYPE_FLAG_UNSIGNED
;
8594 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8596 case DW_ATE_boolean
:
8597 code
= TYPE_CODE_BOOL
;
8598 type_flags
|= TYPE_FLAG_UNSIGNED
;
8600 case DW_ATE_complex_float
:
8601 code
= TYPE_CODE_COMPLEX
;
8602 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8604 case DW_ATE_decimal_float
:
8605 code
= TYPE_CODE_DECFLOAT
;
8608 code
= TYPE_CODE_FLT
;
8612 case DW_ATE_unsigned
:
8613 type_flags
|= TYPE_FLAG_UNSIGNED
;
8614 if (cu
->language
== language_fortran
8616 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
8617 code
= TYPE_CODE_CHAR
;
8619 case DW_ATE_signed_char
:
8620 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8621 || cu
->language
== language_pascal
8622 || cu
->language
== language_fortran
)
8623 code
= TYPE_CODE_CHAR
;
8625 case DW_ATE_unsigned_char
:
8626 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8627 || cu
->language
== language_pascal
8628 || cu
->language
== language_fortran
)
8629 code
= TYPE_CODE_CHAR
;
8630 type_flags
|= TYPE_FLAG_UNSIGNED
;
8633 /* We just treat this as an integer and then recognize the
8634 type by name elsewhere. */
8638 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8639 dwarf_type_encoding_name (encoding
));
8643 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8644 TYPE_NAME (type
) = name
;
8645 TYPE_TARGET_TYPE (type
) = target_type
;
8647 if (name
&& strcmp (name
, "char") == 0)
8648 TYPE_NOSIGN (type
) = 1;
8650 return set_die_type (die
, type
, cu
);
8653 /* Read the given DW_AT_subrange DIE. */
8655 static struct type
*
8656 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8658 struct type
*base_type
;
8659 struct type
*range_type
;
8660 struct attribute
*attr
;
8664 LONGEST negative_mask
;
8666 base_type
= die_type (die
, cu
);
8667 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8668 check_typedef (base_type
);
8670 /* The die_type call above may have already set the type for this DIE. */
8671 range_type
= get_die_type (die
, cu
);
8675 if (cu
->language
== language_fortran
)
8677 /* FORTRAN implies a lower bound of 1, if not given. */
8681 /* FIXME: For variable sized arrays either of these could be
8682 a variable rather than a constant value. We'll allow it,
8683 but we don't know how to handle it. */
8684 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8686 low
= dwarf2_get_attr_constant_value (attr
, 0);
8688 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8691 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
8693 /* GCC encodes arrays with unspecified or dynamic length
8694 with a DW_FORM_block1 attribute or a reference attribute.
8695 FIXME: GDB does not yet know how to handle dynamic
8696 arrays properly, treat them as arrays with unspecified
8699 FIXME: jimb/2003-09-22: GDB does not really know
8700 how to handle arrays of unspecified length
8701 either; we just represent them as zero-length
8702 arrays. Choose an appropriate upper bound given
8703 the lower bound we've computed above. */
8707 high
= dwarf2_get_attr_constant_value (attr
, 1);
8711 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8714 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8715 high
= low
+ count
- 1;
8719 /* Unspecified array length. */
8724 /* Dwarf-2 specifications explicitly allows to create subrange types
8725 without specifying a base type.
8726 In that case, the base type must be set to the type of
8727 the lower bound, upper bound or count, in that order, if any of these
8728 three attributes references an object that has a type.
8729 If no base type is found, the Dwarf-2 specifications say that
8730 a signed integer type of size equal to the size of an address should
8732 For the following C code: `extern char gdb_int [];'
8733 GCC produces an empty range DIE.
8734 FIXME: muller/2010-05-28: Possible references to object for low bound,
8735 high bound or count are not yet handled by this code. */
8736 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8738 struct objfile
*objfile
= cu
->objfile
;
8739 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8740 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8741 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8743 /* Test "int", "long int", and "long long int" objfile types,
8744 and select the first one having a size above or equal to the
8745 architecture address size. */
8746 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8747 base_type
= int_type
;
8750 int_type
= objfile_type (objfile
)->builtin_long
;
8751 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8752 base_type
= int_type
;
8755 int_type
= objfile_type (objfile
)->builtin_long_long
;
8756 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8757 base_type
= int_type
;
8763 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8764 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8765 low
|= negative_mask
;
8766 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8767 high
|= negative_mask
;
8769 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8771 /* Mark arrays with dynamic length at least as an array of unspecified
8772 length. GDB could check the boundary but before it gets implemented at
8773 least allow accessing the array elements. */
8774 if (attr
&& attr_form_is_block (attr
))
8775 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8777 /* Ada expects an empty array on no boundary attributes. */
8778 if (attr
== NULL
&& cu
->language
!= language_ada
)
8779 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8781 name
= dwarf2_name (die
, cu
);
8783 TYPE_NAME (range_type
) = name
;
8785 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8787 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8789 set_die_type (die
, range_type
, cu
);
8791 /* set_die_type should be already done. */
8792 set_descriptive_type (range_type
, die
, cu
);
8797 static struct type
*
8798 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8802 /* For now, we only support the C meaning of an unspecified type: void. */
8804 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8805 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8807 return set_die_type (die
, type
, cu
);
8810 /* Trivial hash function for die_info: the hash value of a DIE
8811 is its offset in .debug_info for this objfile. */
8814 die_hash (const void *item
)
8816 const struct die_info
*die
= item
;
8821 /* Trivial comparison function for die_info structures: two DIEs
8822 are equal if they have the same offset. */
8825 die_eq (const void *item_lhs
, const void *item_rhs
)
8827 const struct die_info
*die_lhs
= item_lhs
;
8828 const struct die_info
*die_rhs
= item_rhs
;
8830 return die_lhs
->offset
== die_rhs
->offset
;
8833 /* Read a whole compilation unit into a linked list of dies. */
8835 static struct die_info
*
8836 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8838 struct die_reader_specs reader_specs
;
8839 int read_abbrevs
= 0;
8840 struct cleanup
*back_to
= NULL
;
8841 struct die_info
*die
;
8843 if (cu
->dwarf2_abbrevs
== NULL
)
8845 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8846 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8850 gdb_assert (cu
->die_hash
== NULL
);
8852 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8856 &cu
->comp_unit_obstack
,
8857 hashtab_obstack_allocate
,
8858 dummy_obstack_deallocate
);
8860 init_cu_die_reader (&reader_specs
, cu
);
8862 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8865 do_cleanups (back_to
);
8870 /* Main entry point for reading a DIE and all children.
8871 Read the DIE and dump it if requested. */
8873 static struct die_info
*
8874 read_die_and_children (const struct die_reader_specs
*reader
,
8876 gdb_byte
**new_info_ptr
,
8877 struct die_info
*parent
)
8879 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8880 new_info_ptr
, parent
);
8882 if (dwarf2_die_debug
)
8884 fprintf_unfiltered (gdb_stdlog
,
8885 "\nRead die from %s of %s:\n",
8886 (reader
->cu
->per_cu
->debug_type_section
8889 reader
->abfd
->filename
);
8890 dump_die (result
, dwarf2_die_debug
);
8896 /* Read a single die and all its descendents. Set the die's sibling
8897 field to NULL; set other fields in the die correctly, and set all
8898 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8899 location of the info_ptr after reading all of those dies. PARENT
8900 is the parent of the die in question. */
8902 static struct die_info
*
8903 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8905 gdb_byte
**new_info_ptr
,
8906 struct die_info
*parent
)
8908 struct die_info
*die
;
8912 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8915 *new_info_ptr
= cur_ptr
;
8918 store_in_ref_table (die
, reader
->cu
);
8921 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8925 *new_info_ptr
= cur_ptr
;
8928 die
->sibling
= NULL
;
8929 die
->parent
= parent
;
8933 /* Read a die, all of its descendents, and all of its siblings; set
8934 all of the fields of all of the dies correctly. Arguments are as
8935 in read_die_and_children. */
8937 static struct die_info
*
8938 read_die_and_siblings (const struct die_reader_specs
*reader
,
8940 gdb_byte
**new_info_ptr
,
8941 struct die_info
*parent
)
8943 struct die_info
*first_die
, *last_sibling
;
8947 first_die
= last_sibling
= NULL
;
8951 struct die_info
*die
8952 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8956 *new_info_ptr
= cur_ptr
;
8963 last_sibling
->sibling
= die
;
8969 /* Read the die from the .debug_info section buffer. Set DIEP to
8970 point to a newly allocated die with its information, except for its
8971 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8972 whether the die has children or not. */
8975 read_full_die (const struct die_reader_specs
*reader
,
8976 struct die_info
**diep
, gdb_byte
*info_ptr
,
8979 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8980 struct abbrev_info
*abbrev
;
8981 struct die_info
*die
;
8982 struct dwarf2_cu
*cu
= reader
->cu
;
8983 bfd
*abfd
= reader
->abfd
;
8985 offset
= info_ptr
- reader
->buffer
;
8986 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8987 info_ptr
+= bytes_read
;
8995 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8997 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8999 bfd_get_filename (abfd
));
9001 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
9002 die
->offset
= offset
;
9003 die
->tag
= abbrev
->tag
;
9004 die
->abbrev
= abbrev_number
;
9006 die
->num_attrs
= abbrev
->num_attrs
;
9008 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9009 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
9010 abfd
, info_ptr
, cu
);
9013 *has_children
= abbrev
->has_children
;
9017 /* In DWARF version 2, the description of the debugging information is
9018 stored in a separate .debug_abbrev section. Before we read any
9019 dies from a section we read in all abbreviations and install them
9020 in a hash table. This function also sets flags in CU describing
9021 the data found in the abbrev table. */
9024 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
9026 struct comp_unit_head
*cu_header
= &cu
->header
;
9027 gdb_byte
*abbrev_ptr
;
9028 struct abbrev_info
*cur_abbrev
;
9029 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9030 unsigned int abbrev_form
, hash_number
;
9031 struct attr_abbrev
*cur_attrs
;
9032 unsigned int allocated_attrs
;
9034 /* Initialize dwarf2 abbrevs. */
9035 obstack_init (&cu
->abbrev_obstack
);
9036 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9038 * sizeof (struct abbrev_info
*)));
9039 memset (cu
->dwarf2_abbrevs
, 0,
9040 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9042 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
9043 &dwarf2_per_objfile
->abbrev
);
9044 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
9045 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9046 abbrev_ptr
+= bytes_read
;
9048 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9049 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9051 /* Loop until we reach an abbrev number of 0. */
9052 while (abbrev_number
)
9054 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9056 /* read in abbrev header */
9057 cur_abbrev
->number
= abbrev_number
;
9058 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9059 abbrev_ptr
+= bytes_read
;
9060 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9063 if (cur_abbrev
->tag
== DW_TAG_namespace
)
9064 cu
->has_namespace_info
= 1;
9066 /* now read in declarations */
9067 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9068 abbrev_ptr
+= bytes_read
;
9069 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9070 abbrev_ptr
+= bytes_read
;
9073 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9075 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9077 = xrealloc (cur_attrs
, (allocated_attrs
9078 * sizeof (struct attr_abbrev
)));
9081 /* Record whether this compilation unit might have
9082 inter-compilation-unit references. If we don't know what form
9083 this attribute will have, then it might potentially be a
9084 DW_FORM_ref_addr, so we conservatively expect inter-CU
9087 if (abbrev_form
== DW_FORM_ref_addr
9088 || abbrev_form
== DW_FORM_indirect
)
9089 cu
->has_form_ref_addr
= 1;
9091 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9092 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9093 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9094 abbrev_ptr
+= bytes_read
;
9095 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9096 abbrev_ptr
+= bytes_read
;
9099 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9100 (cur_abbrev
->num_attrs
9101 * sizeof (struct attr_abbrev
)));
9102 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9103 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9105 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9106 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9107 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9109 /* Get next abbreviation.
9110 Under Irix6 the abbreviations for a compilation unit are not
9111 always properly terminated with an abbrev number of 0.
9112 Exit loop if we encounter an abbreviation which we have
9113 already read (which means we are about to read the abbreviations
9114 for the next compile unit) or if the end of the abbreviation
9115 table is reached. */
9116 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
9117 >= dwarf2_per_objfile
->abbrev
.size
)
9119 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9120 abbrev_ptr
+= bytes_read
;
9121 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9128 /* Release the memory used by the abbrev table for a compilation unit. */
9131 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9133 struct dwarf2_cu
*cu
= ptr_to_cu
;
9135 obstack_free (&cu
->abbrev_obstack
, NULL
);
9136 cu
->dwarf2_abbrevs
= NULL
;
9139 /* Lookup an abbrev_info structure in the abbrev hash table. */
9141 static struct abbrev_info
*
9142 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9144 unsigned int hash_number
;
9145 struct abbrev_info
*abbrev
;
9147 hash_number
= number
% ABBREV_HASH_SIZE
;
9148 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9152 if (abbrev
->number
== number
)
9155 abbrev
= abbrev
->next
;
9160 /* Returns nonzero if TAG represents a type that we might generate a partial
9164 is_type_tag_for_partial (int tag
)
9169 /* Some types that would be reasonable to generate partial symbols for,
9170 that we don't at present. */
9171 case DW_TAG_array_type
:
9172 case DW_TAG_file_type
:
9173 case DW_TAG_ptr_to_member_type
:
9174 case DW_TAG_set_type
:
9175 case DW_TAG_string_type
:
9176 case DW_TAG_subroutine_type
:
9178 case DW_TAG_base_type
:
9179 case DW_TAG_class_type
:
9180 case DW_TAG_interface_type
:
9181 case DW_TAG_enumeration_type
:
9182 case DW_TAG_structure_type
:
9183 case DW_TAG_subrange_type
:
9184 case DW_TAG_typedef
:
9185 case DW_TAG_union_type
:
9192 /* Load all DIEs that are interesting for partial symbols into memory. */
9194 static struct partial_die_info
*
9195 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9196 int building_psymtab
, struct dwarf2_cu
*cu
)
9198 struct partial_die_info
*part_die
;
9199 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9200 struct abbrev_info
*abbrev
;
9201 unsigned int bytes_read
;
9202 unsigned int load_all
= 0;
9204 int nesting_level
= 1;
9209 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
9213 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9217 &cu
->comp_unit_obstack
,
9218 hashtab_obstack_allocate
,
9219 dummy_obstack_deallocate
);
9221 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9222 sizeof (struct partial_die_info
));
9226 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9228 /* A NULL abbrev means the end of a series of children. */
9231 if (--nesting_level
== 0)
9233 /* PART_DIE was probably the last thing allocated on the
9234 comp_unit_obstack, so we could call obstack_free
9235 here. We don't do that because the waste is small,
9236 and will be cleaned up when we're done with this
9237 compilation unit. This way, we're also more robust
9238 against other users of the comp_unit_obstack. */
9241 info_ptr
+= bytes_read
;
9242 last_die
= parent_die
;
9243 parent_die
= parent_die
->die_parent
;
9247 /* Check for template arguments. We never save these; if
9248 they're seen, we just mark the parent, and go on our way. */
9249 if (parent_die
!= NULL
9250 && cu
->language
== language_cplus
9251 && (abbrev
->tag
== DW_TAG_template_type_param
9252 || abbrev
->tag
== DW_TAG_template_value_param
))
9254 parent_die
->has_template_arguments
= 1;
9258 /* We don't need a partial DIE for the template argument. */
9259 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9265 /* We only recurse into subprograms looking for template arguments.
9266 Skip their other children. */
9268 && cu
->language
== language_cplus
9269 && parent_die
!= NULL
9270 && parent_die
->tag
== DW_TAG_subprogram
)
9272 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9276 /* Check whether this DIE is interesting enough to save. Normally
9277 we would not be interested in members here, but there may be
9278 later variables referencing them via DW_AT_specification (for
9281 && !is_type_tag_for_partial (abbrev
->tag
)
9282 && abbrev
->tag
!= DW_TAG_constant
9283 && abbrev
->tag
!= DW_TAG_enumerator
9284 && abbrev
->tag
!= DW_TAG_subprogram
9285 && abbrev
->tag
!= DW_TAG_lexical_block
9286 && abbrev
->tag
!= DW_TAG_variable
9287 && abbrev
->tag
!= DW_TAG_namespace
9288 && abbrev
->tag
!= DW_TAG_module
9289 && abbrev
->tag
!= DW_TAG_member
)
9291 /* Otherwise we skip to the next sibling, if any. */
9292 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9296 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9297 buffer
, info_ptr
, cu
);
9299 /* This two-pass algorithm for processing partial symbols has a
9300 high cost in cache pressure. Thus, handle some simple cases
9301 here which cover the majority of C partial symbols. DIEs
9302 which neither have specification tags in them, nor could have
9303 specification tags elsewhere pointing at them, can simply be
9304 processed and discarded.
9306 This segment is also optional; scan_partial_symbols and
9307 add_partial_symbol will handle these DIEs if we chain
9308 them in normally. When compilers which do not emit large
9309 quantities of duplicate debug information are more common,
9310 this code can probably be removed. */
9312 /* Any complete simple types at the top level (pretty much all
9313 of them, for a language without namespaces), can be processed
9315 if (parent_die
== NULL
9316 && part_die
->has_specification
== 0
9317 && part_die
->is_declaration
== 0
9318 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9319 || part_die
->tag
== DW_TAG_base_type
9320 || part_die
->tag
== DW_TAG_subrange_type
))
9322 if (building_psymtab
&& part_die
->name
!= NULL
)
9323 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9324 VAR_DOMAIN
, LOC_TYPEDEF
,
9325 &cu
->objfile
->static_psymbols
,
9326 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9327 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9331 /* The exception for DW_TAG_typedef with has_children above is
9332 a workaround of GCC PR debug/47510. In the case of this complaint
9333 type_name_no_tag_or_error will error on such types later.
9335 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9336 it could not find the child DIEs referenced later, this is checked
9337 above. In correct DWARF DW_TAG_typedef should have no children. */
9339 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9340 complaint (&symfile_complaints
,
9341 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9342 "- DIE at 0x%x [in module %s]"),
9343 part_die
->offset
, cu
->objfile
->name
);
9345 /* If we're at the second level, and we're an enumerator, and
9346 our parent has no specification (meaning possibly lives in a
9347 namespace elsewhere), then we can add the partial symbol now
9348 instead of queueing it. */
9349 if (part_die
->tag
== DW_TAG_enumerator
9350 && parent_die
!= NULL
9351 && parent_die
->die_parent
== NULL
9352 && parent_die
->tag
== DW_TAG_enumeration_type
9353 && parent_die
->has_specification
== 0)
9355 if (part_die
->name
== NULL
)
9356 complaint (&symfile_complaints
,
9357 _("malformed enumerator DIE ignored"));
9358 else if (building_psymtab
)
9359 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9360 VAR_DOMAIN
, LOC_CONST
,
9361 (cu
->language
== language_cplus
9362 || cu
->language
== language_java
)
9363 ? &cu
->objfile
->global_psymbols
9364 : &cu
->objfile
->static_psymbols
,
9365 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9367 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9371 /* We'll save this DIE so link it in. */
9372 part_die
->die_parent
= parent_die
;
9373 part_die
->die_sibling
= NULL
;
9374 part_die
->die_child
= NULL
;
9376 if (last_die
&& last_die
== parent_die
)
9377 last_die
->die_child
= part_die
;
9379 last_die
->die_sibling
= part_die
;
9381 last_die
= part_die
;
9383 if (first_die
== NULL
)
9384 first_die
= part_die
;
9386 /* Maybe add the DIE to the hash table. Not all DIEs that we
9387 find interesting need to be in the hash table, because we
9388 also have the parent/sibling/child chains; only those that we
9389 might refer to by offset later during partial symbol reading.
9391 For now this means things that might have be the target of a
9392 DW_AT_specification, DW_AT_abstract_origin, or
9393 DW_AT_extension. DW_AT_extension will refer only to
9394 namespaces; DW_AT_abstract_origin refers to functions (and
9395 many things under the function DIE, but we do not recurse
9396 into function DIEs during partial symbol reading) and
9397 possibly variables as well; DW_AT_specification refers to
9398 declarations. Declarations ought to have the DW_AT_declaration
9399 flag. It happens that GCC forgets to put it in sometimes, but
9400 only for functions, not for types.
9402 Adding more things than necessary to the hash table is harmless
9403 except for the performance cost. Adding too few will result in
9404 wasted time in find_partial_die, when we reread the compilation
9405 unit with load_all_dies set. */
9408 || abbrev
->tag
== DW_TAG_constant
9409 || abbrev
->tag
== DW_TAG_subprogram
9410 || abbrev
->tag
== DW_TAG_variable
9411 || abbrev
->tag
== DW_TAG_namespace
9412 || part_die
->is_declaration
)
9416 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9417 part_die
->offset
, INSERT
);
9421 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9422 sizeof (struct partial_die_info
));
9424 /* For some DIEs we want to follow their children (if any). For C
9425 we have no reason to follow the children of structures; for other
9426 languages we have to, so that we can get at method physnames
9427 to infer fully qualified class names, for DW_AT_specification,
9428 and for C++ template arguments. For C++, we also look one level
9429 inside functions to find template arguments (if the name of the
9430 function does not already contain the template arguments).
9432 For Ada, we need to scan the children of subprograms and lexical
9433 blocks as well because Ada allows the definition of nested
9434 entities that could be interesting for the debugger, such as
9435 nested subprograms for instance. */
9436 if (last_die
->has_children
9438 || last_die
->tag
== DW_TAG_namespace
9439 || last_die
->tag
== DW_TAG_module
9440 || last_die
->tag
== DW_TAG_enumeration_type
9441 || (cu
->language
== language_cplus
9442 && last_die
->tag
== DW_TAG_subprogram
9443 && (last_die
->name
== NULL
9444 || strchr (last_die
->name
, '<') == NULL
))
9445 || (cu
->language
!= language_c
9446 && (last_die
->tag
== DW_TAG_class_type
9447 || last_die
->tag
== DW_TAG_interface_type
9448 || last_die
->tag
== DW_TAG_structure_type
9449 || last_die
->tag
== DW_TAG_union_type
))
9450 || (cu
->language
== language_ada
9451 && (last_die
->tag
== DW_TAG_subprogram
9452 || last_die
->tag
== DW_TAG_lexical_block
))))
9455 parent_die
= last_die
;
9459 /* Otherwise we skip to the next sibling, if any. */
9460 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9462 /* Back to the top, do it again. */
9466 /* Read a minimal amount of information into the minimal die structure. */
9469 read_partial_die (struct partial_die_info
*part_die
,
9470 struct abbrev_info
*abbrev
,
9471 unsigned int abbrev_len
, bfd
*abfd
,
9472 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9473 struct dwarf2_cu
*cu
)
9476 struct attribute attr
;
9477 int has_low_pc_attr
= 0;
9478 int has_high_pc_attr
= 0;
9480 memset (part_die
, 0, sizeof (struct partial_die_info
));
9482 part_die
->offset
= info_ptr
- buffer
;
9484 info_ptr
+= abbrev_len
;
9489 part_die
->tag
= abbrev
->tag
;
9490 part_die
->has_children
= abbrev
->has_children
;
9492 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9494 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9496 /* Store the data if it is of an attribute we want to keep in a
9497 partial symbol table. */
9501 switch (part_die
->tag
)
9503 case DW_TAG_compile_unit
:
9504 case DW_TAG_type_unit
:
9505 /* Compilation units have a DW_AT_name that is a filename, not
9506 a source language identifier. */
9507 case DW_TAG_enumeration_type
:
9508 case DW_TAG_enumerator
:
9509 /* These tags always have simple identifiers already; no need
9510 to canonicalize them. */
9511 part_die
->name
= DW_STRING (&attr
);
9515 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9516 &cu
->objfile
->objfile_obstack
);
9520 case DW_AT_linkage_name
:
9521 case DW_AT_MIPS_linkage_name
:
9522 /* Note that both forms of linkage name might appear. We
9523 assume they will be the same, and we only store the last
9525 if (cu
->language
== language_ada
)
9526 part_die
->name
= DW_STRING (&attr
);
9527 part_die
->linkage_name
= DW_STRING (&attr
);
9530 has_low_pc_attr
= 1;
9531 part_die
->lowpc
= DW_ADDR (&attr
);
9534 has_high_pc_attr
= 1;
9535 part_die
->highpc
= DW_ADDR (&attr
);
9537 case DW_AT_location
:
9538 /* Support the .debug_loc offsets. */
9539 if (attr_form_is_block (&attr
))
9541 part_die
->locdesc
= DW_BLOCK (&attr
);
9543 else if (attr_form_is_section_offset (&attr
))
9545 dwarf2_complex_location_expr_complaint ();
9549 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9550 "partial symbol information");
9553 case DW_AT_external
:
9554 part_die
->is_external
= DW_UNSND (&attr
);
9556 case DW_AT_declaration
:
9557 part_die
->is_declaration
= DW_UNSND (&attr
);
9560 part_die
->has_type
= 1;
9562 case DW_AT_abstract_origin
:
9563 case DW_AT_specification
:
9564 case DW_AT_extension
:
9565 part_die
->has_specification
= 1;
9566 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9569 /* Ignore absolute siblings, they might point outside of
9570 the current compile unit. */
9571 if (attr
.form
== DW_FORM_ref_addr
)
9572 complaint (&symfile_complaints
,
9573 _("ignoring absolute DW_AT_sibling"));
9575 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9577 case DW_AT_byte_size
:
9578 part_die
->has_byte_size
= 1;
9580 case DW_AT_calling_convention
:
9581 /* DWARF doesn't provide a way to identify a program's source-level
9582 entry point. DW_AT_calling_convention attributes are only meant
9583 to describe functions' calling conventions.
9585 However, because it's a necessary piece of information in
9586 Fortran, and because DW_CC_program is the only piece of debugging
9587 information whose definition refers to a 'main program' at all,
9588 several compilers have begun marking Fortran main programs with
9589 DW_CC_program --- even when those functions use the standard
9590 calling conventions.
9592 So until DWARF specifies a way to provide this information and
9593 compilers pick up the new representation, we'll support this
9595 if (DW_UNSND (&attr
) == DW_CC_program
9596 && cu
->language
== language_fortran
)
9598 set_main_name (part_die
->name
);
9600 /* As this DIE has a static linkage the name would be difficult
9601 to look up later. */
9602 language_of_main
= language_fortran
;
9610 if (has_low_pc_attr
&& has_high_pc_attr
)
9612 /* When using the GNU linker, .gnu.linkonce. sections are used to
9613 eliminate duplicate copies of functions and vtables and such.
9614 The linker will arbitrarily choose one and discard the others.
9615 The AT_*_pc values for such functions refer to local labels in
9616 these sections. If the section from that file was discarded, the
9617 labels are not in the output, so the relocs get a value of 0.
9618 If this is a discarded function, mark the pc bounds as invalid,
9619 so that GDB will ignore it. */
9620 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9622 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9624 complaint (&symfile_complaints
,
9625 _("DW_AT_low_pc %s is zero "
9626 "for DIE at 0x%x [in module %s]"),
9627 paddress (gdbarch
, part_die
->lowpc
),
9628 part_die
->offset
, cu
->objfile
->name
);
9630 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9631 else if (part_die
->lowpc
>= part_die
->highpc
)
9633 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9635 complaint (&symfile_complaints
,
9636 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9637 "for DIE at 0x%x [in module %s]"),
9638 paddress (gdbarch
, part_die
->lowpc
),
9639 paddress (gdbarch
, part_die
->highpc
),
9640 part_die
->offset
, cu
->objfile
->name
);
9643 part_die
->has_pc_info
= 1;
9649 /* Find a cached partial DIE at OFFSET in CU. */
9651 static struct partial_die_info
*
9652 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9654 struct partial_die_info
*lookup_die
= NULL
;
9655 struct partial_die_info part_die
;
9657 part_die
.offset
= offset
;
9658 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9663 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9664 except in the case of .debug_types DIEs which do not reference
9665 outside their CU (they do however referencing other types via
9666 DW_FORM_ref_sig8). */
9668 static struct partial_die_info
*
9669 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9671 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9672 struct partial_die_info
*pd
= NULL
;
9674 if (cu
->per_cu
->debug_type_section
)
9676 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9682 if (offset_in_cu_p (&cu
->header
, offset
))
9684 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9689 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9691 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9692 load_partial_comp_unit (per_cu
, cu
->objfile
);
9694 per_cu
->cu
->last_used
= 0;
9695 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9697 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9699 struct cleanup
*back_to
;
9700 struct partial_die_info comp_unit_die
;
9701 struct abbrev_info
*abbrev
;
9702 unsigned int bytes_read
;
9705 per_cu
->load_all_dies
= 1;
9707 /* Re-read the DIEs. */
9708 back_to
= make_cleanup (null_cleanup
, 0);
9709 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9711 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
9712 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9714 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9715 + per_cu
->cu
->header
.offset
9716 + per_cu
->cu
->header
.first_die_offset
);
9717 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9718 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9719 per_cu
->cu
->objfile
->obfd
,
9720 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9722 if (comp_unit_die
.has_children
)
9723 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
9724 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9726 do_cleanups (back_to
);
9728 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9734 internal_error (__FILE__
, __LINE__
,
9735 _("could not find partial DIE 0x%x "
9736 "in cache [from module %s]\n"),
9737 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9741 /* See if we can figure out if the class lives in a namespace. We do
9742 this by looking for a member function; its demangled name will
9743 contain namespace info, if there is any. */
9746 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9747 struct dwarf2_cu
*cu
)
9749 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9750 what template types look like, because the demangler
9751 frequently doesn't give the same name as the debug info. We
9752 could fix this by only using the demangled name to get the
9753 prefix (but see comment in read_structure_type). */
9755 struct partial_die_info
*real_pdi
;
9756 struct partial_die_info
*child_pdi
;
9758 /* If this DIE (this DIE's specification, if any) has a parent, then
9759 we should not do this. We'll prepend the parent's fully qualified
9760 name when we create the partial symbol. */
9762 real_pdi
= struct_pdi
;
9763 while (real_pdi
->has_specification
)
9764 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9766 if (real_pdi
->die_parent
!= NULL
)
9769 for (child_pdi
= struct_pdi
->die_child
;
9771 child_pdi
= child_pdi
->die_sibling
)
9773 if (child_pdi
->tag
== DW_TAG_subprogram
9774 && child_pdi
->linkage_name
!= NULL
)
9776 char *actual_class_name
9777 = language_class_name_from_physname (cu
->language_defn
,
9778 child_pdi
->linkage_name
);
9779 if (actual_class_name
!= NULL
)
9782 = obsavestring (actual_class_name
,
9783 strlen (actual_class_name
),
9784 &cu
->objfile
->objfile_obstack
);
9785 xfree (actual_class_name
);
9792 /* Adjust PART_DIE before generating a symbol for it. This function
9793 may set the is_external flag or change the DIE's name. */
9796 fixup_partial_die (struct partial_die_info
*part_die
,
9797 struct dwarf2_cu
*cu
)
9799 /* Once we've fixed up a die, there's no point in doing so again.
9800 This also avoids a memory leak if we were to call
9801 guess_partial_die_structure_name multiple times. */
9802 if (part_die
->fixup_called
)
9805 /* If we found a reference attribute and the DIE has no name, try
9806 to find a name in the referred to DIE. */
9808 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9810 struct partial_die_info
*spec_die
;
9812 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9814 fixup_partial_die (spec_die
, cu
);
9818 part_die
->name
= spec_die
->name
;
9820 /* Copy DW_AT_external attribute if it is set. */
9821 if (spec_die
->is_external
)
9822 part_die
->is_external
= spec_die
->is_external
;
9826 /* Set default names for some unnamed DIEs. */
9828 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9829 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
9831 /* If there is no parent die to provide a namespace, and there are
9832 children, see if we can determine the namespace from their linkage
9834 NOTE: We need to do this even if cu->has_namespace_info != 0.
9835 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9836 if (cu
->language
== language_cplus
9837 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
9838 && part_die
->die_parent
== NULL
9839 && part_die
->has_children
9840 && (part_die
->tag
== DW_TAG_class_type
9841 || part_die
->tag
== DW_TAG_structure_type
9842 || part_die
->tag
== DW_TAG_union_type
))
9843 guess_partial_die_structure_name (part_die
, cu
);
9845 /* GCC might emit a nameless struct or union that has a linkage
9846 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
9847 if (part_die
->name
== NULL
9848 && (part_die
->tag
== DW_TAG_structure_type
9849 || part_die
->tag
== DW_TAG_union_type
9850 || part_die
->tag
== DW_TAG_class_type
)
9851 && part_die
->linkage_name
!= NULL
)
9855 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
9858 part_die
->name
= obsavestring (demangled
, strlen (demangled
),
9859 &cu
->objfile
->objfile_obstack
);
9864 part_die
->fixup_called
= 1;
9867 /* Read an attribute value described by an attribute form. */
9870 read_attribute_value (struct attribute
*attr
, unsigned form
,
9871 bfd
*abfd
, gdb_byte
*info_ptr
,
9872 struct dwarf2_cu
*cu
)
9874 struct comp_unit_head
*cu_header
= &cu
->header
;
9875 unsigned int bytes_read
;
9876 struct dwarf_block
*blk
;
9881 case DW_FORM_ref_addr
:
9882 if (cu
->header
.version
== 2)
9883 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9885 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
9886 &cu
->header
, &bytes_read
);
9887 info_ptr
+= bytes_read
;
9890 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9891 info_ptr
+= bytes_read
;
9893 case DW_FORM_block2
:
9894 blk
= dwarf_alloc_block (cu
);
9895 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9897 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9898 info_ptr
+= blk
->size
;
9899 DW_BLOCK (attr
) = blk
;
9901 case DW_FORM_block4
:
9902 blk
= dwarf_alloc_block (cu
);
9903 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9905 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9906 info_ptr
+= blk
->size
;
9907 DW_BLOCK (attr
) = blk
;
9910 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9914 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9918 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9921 case DW_FORM_sec_offset
:
9922 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9923 info_ptr
+= bytes_read
;
9925 case DW_FORM_string
:
9926 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9927 DW_STRING_IS_CANONICAL (attr
) = 0;
9928 info_ptr
+= bytes_read
;
9931 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9933 DW_STRING_IS_CANONICAL (attr
) = 0;
9934 info_ptr
+= bytes_read
;
9936 case DW_FORM_exprloc
:
9938 blk
= dwarf_alloc_block (cu
);
9939 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9940 info_ptr
+= bytes_read
;
9941 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9942 info_ptr
+= blk
->size
;
9943 DW_BLOCK (attr
) = blk
;
9945 case DW_FORM_block1
:
9946 blk
= dwarf_alloc_block (cu
);
9947 blk
->size
= read_1_byte (abfd
, info_ptr
);
9949 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9950 info_ptr
+= blk
->size
;
9951 DW_BLOCK (attr
) = blk
;
9954 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9958 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9961 case DW_FORM_flag_present
:
9962 DW_UNSND (attr
) = 1;
9965 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9966 info_ptr
+= bytes_read
;
9969 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9970 info_ptr
+= bytes_read
;
9973 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9977 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9981 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9985 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9988 case DW_FORM_ref_sig8
:
9989 /* Convert the signature to something we can record in DW_UNSND
9991 NOTE: This is NULL if the type wasn't found. */
9992 DW_SIGNATURED_TYPE (attr
) =
9993 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9996 case DW_FORM_ref_udata
:
9997 DW_ADDR (attr
) = (cu
->header
.offset
9998 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9999 info_ptr
+= bytes_read
;
10001 case DW_FORM_indirect
:
10002 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10003 info_ptr
+= bytes_read
;
10004 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
10007 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10008 dwarf_form_name (form
),
10009 bfd_get_filename (abfd
));
10012 /* We have seen instances where the compiler tried to emit a byte
10013 size attribute of -1 which ended up being encoded as an unsigned
10014 0xffffffff. Although 0xffffffff is technically a valid size value,
10015 an object of this size seems pretty unlikely so we can relatively
10016 safely treat these cases as if the size attribute was invalid and
10017 treat them as zero by default. */
10018 if (attr
->name
== DW_AT_byte_size
10019 && form
== DW_FORM_data4
10020 && DW_UNSND (attr
) >= 0xffffffff)
10023 (&symfile_complaints
,
10024 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10025 hex_string (DW_UNSND (attr
)));
10026 DW_UNSND (attr
) = 0;
10032 /* Read an attribute described by an abbreviated attribute. */
10035 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10036 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
10038 attr
->name
= abbrev
->name
;
10039 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
10042 /* Read dwarf information from a buffer. */
10044 static unsigned int
10045 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10047 return bfd_get_8 (abfd
, buf
);
10051 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10053 return bfd_get_signed_8 (abfd
, buf
);
10056 static unsigned int
10057 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10059 return bfd_get_16 (abfd
, buf
);
10062 static unsigned int
10063 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10065 return bfd_get_32 (abfd
, buf
);
10069 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10071 return bfd_get_64 (abfd
, buf
);
10075 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10076 unsigned int *bytes_read
)
10078 struct comp_unit_head
*cu_header
= &cu
->header
;
10079 CORE_ADDR retval
= 0;
10081 if (cu_header
->signed_addr_p
)
10083 switch (cu_header
->addr_size
)
10086 retval
= bfd_get_signed_16 (abfd
, buf
);
10089 retval
= bfd_get_signed_32 (abfd
, buf
);
10092 retval
= bfd_get_signed_64 (abfd
, buf
);
10095 internal_error (__FILE__
, __LINE__
,
10096 _("read_address: bad switch, signed [in module %s]"),
10097 bfd_get_filename (abfd
));
10102 switch (cu_header
->addr_size
)
10105 retval
= bfd_get_16 (abfd
, buf
);
10108 retval
= bfd_get_32 (abfd
, buf
);
10111 retval
= bfd_get_64 (abfd
, buf
);
10114 internal_error (__FILE__
, __LINE__
,
10115 _("read_address: bad switch, "
10116 "unsigned [in module %s]"),
10117 bfd_get_filename (abfd
));
10121 *bytes_read
= cu_header
->addr_size
;
10125 /* Read the initial length from a section. The (draft) DWARF 3
10126 specification allows the initial length to take up either 4 bytes
10127 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10128 bytes describe the length and all offsets will be 8 bytes in length
10131 An older, non-standard 64-bit format is also handled by this
10132 function. The older format in question stores the initial length
10133 as an 8-byte quantity without an escape value. Lengths greater
10134 than 2^32 aren't very common which means that the initial 4 bytes
10135 is almost always zero. Since a length value of zero doesn't make
10136 sense for the 32-bit format, this initial zero can be considered to
10137 be an escape value which indicates the presence of the older 64-bit
10138 format. As written, the code can't detect (old format) lengths
10139 greater than 4GB. If it becomes necessary to handle lengths
10140 somewhat larger than 4GB, we could allow other small values (such
10141 as the non-sensical values of 1, 2, and 3) to also be used as
10142 escape values indicating the presence of the old format.
10144 The value returned via bytes_read should be used to increment the
10145 relevant pointer after calling read_initial_length().
10147 [ Note: read_initial_length() and read_offset() are based on the
10148 document entitled "DWARF Debugging Information Format", revision
10149 3, draft 8, dated November 19, 2001. This document was obtained
10152 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10154 This document is only a draft and is subject to change. (So beware.)
10156 Details regarding the older, non-standard 64-bit format were
10157 determined empirically by examining 64-bit ELF files produced by
10158 the SGI toolchain on an IRIX 6.5 machine.
10160 - Kevin, July 16, 2002
10164 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10166 LONGEST length
= bfd_get_32 (abfd
, buf
);
10168 if (length
== 0xffffffff)
10170 length
= bfd_get_64 (abfd
, buf
+ 4);
10173 else if (length
== 0)
10175 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10176 length
= bfd_get_64 (abfd
, buf
);
10187 /* Cover function for read_initial_length.
10188 Returns the length of the object at BUF, and stores the size of the
10189 initial length in *BYTES_READ and stores the size that offsets will be in
10191 If the initial length size is not equivalent to that specified in
10192 CU_HEADER then issue a complaint.
10193 This is useful when reading non-comp-unit headers. */
10196 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10197 const struct comp_unit_head
*cu_header
,
10198 unsigned int *bytes_read
,
10199 unsigned int *offset_size
)
10201 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10203 gdb_assert (cu_header
->initial_length_size
== 4
10204 || cu_header
->initial_length_size
== 8
10205 || cu_header
->initial_length_size
== 12);
10207 if (cu_header
->initial_length_size
!= *bytes_read
)
10208 complaint (&symfile_complaints
,
10209 _("intermixed 32-bit and 64-bit DWARF sections"));
10211 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10215 /* Read an offset from the data stream. The size of the offset is
10216 given by cu_header->offset_size. */
10219 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10220 unsigned int *bytes_read
)
10222 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10224 *bytes_read
= cu_header
->offset_size
;
10228 /* Read an offset from the data stream. */
10231 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10233 LONGEST retval
= 0;
10235 switch (offset_size
)
10238 retval
= bfd_get_32 (abfd
, buf
);
10241 retval
= bfd_get_64 (abfd
, buf
);
10244 internal_error (__FILE__
, __LINE__
,
10245 _("read_offset_1: bad switch [in module %s]"),
10246 bfd_get_filename (abfd
));
10253 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10255 /* If the size of a host char is 8 bits, we can return a pointer
10256 to the buffer, otherwise we have to copy the data to a buffer
10257 allocated on the temporary obstack. */
10258 gdb_assert (HOST_CHAR_BIT
== 8);
10263 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10265 /* If the size of a host char is 8 bits, we can return a pointer
10266 to the string, otherwise we have to copy the string to a buffer
10267 allocated on the temporary obstack. */
10268 gdb_assert (HOST_CHAR_BIT
== 8);
10271 *bytes_read_ptr
= 1;
10274 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10275 return (char *) buf
;
10279 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
10281 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10282 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10283 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10284 bfd_get_filename (abfd
));
10285 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10286 error (_("DW_FORM_strp pointing outside of "
10287 ".debug_str section [in module %s]"),
10288 bfd_get_filename (abfd
));
10289 gdb_assert (HOST_CHAR_BIT
== 8);
10290 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10292 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10296 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10297 const struct comp_unit_head
*cu_header
,
10298 unsigned int *bytes_read_ptr
)
10300 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10302 return read_indirect_string_at_offset (abfd
, str_offset
);
10305 static unsigned long
10306 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10308 unsigned long result
;
10309 unsigned int num_read
;
10311 unsigned char byte
;
10319 byte
= bfd_get_8 (abfd
, buf
);
10322 result
|= ((unsigned long)(byte
& 127) << shift
);
10323 if ((byte
& 128) == 0)
10329 *bytes_read_ptr
= num_read
;
10334 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10337 int i
, shift
, num_read
;
10338 unsigned char byte
;
10346 byte
= bfd_get_8 (abfd
, buf
);
10349 result
|= ((long)(byte
& 127) << shift
);
10351 if ((byte
& 128) == 0)
10356 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10357 result
|= -(((long)1) << shift
);
10358 *bytes_read_ptr
= num_read
;
10362 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10365 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10371 byte
= bfd_get_8 (abfd
, buf
);
10373 if ((byte
& 128) == 0)
10379 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10386 cu
->language
= language_c
;
10388 case DW_LANG_C_plus_plus
:
10389 cu
->language
= language_cplus
;
10392 cu
->language
= language_d
;
10394 case DW_LANG_Fortran77
:
10395 case DW_LANG_Fortran90
:
10396 case DW_LANG_Fortran95
:
10397 cu
->language
= language_fortran
;
10399 case DW_LANG_Mips_Assembler
:
10400 cu
->language
= language_asm
;
10403 cu
->language
= language_java
;
10405 case DW_LANG_Ada83
:
10406 case DW_LANG_Ada95
:
10407 cu
->language
= language_ada
;
10409 case DW_LANG_Modula2
:
10410 cu
->language
= language_m2
;
10412 case DW_LANG_Pascal83
:
10413 cu
->language
= language_pascal
;
10416 cu
->language
= language_objc
;
10418 case DW_LANG_Cobol74
:
10419 case DW_LANG_Cobol85
:
10421 cu
->language
= language_minimal
;
10424 cu
->language_defn
= language_def (cu
->language
);
10427 /* Return the named attribute or NULL if not there. */
10429 static struct attribute
*
10430 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10433 struct attribute
*spec
= NULL
;
10435 for (i
= 0; i
< die
->num_attrs
; ++i
)
10437 if (die
->attrs
[i
].name
== name
)
10438 return &die
->attrs
[i
];
10439 if (die
->attrs
[i
].name
== DW_AT_specification
10440 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10441 spec
= &die
->attrs
[i
];
10446 die
= follow_die_ref (die
, spec
, &cu
);
10447 return dwarf2_attr (die
, name
, cu
);
10453 /* Return the named attribute or NULL if not there,
10454 but do not follow DW_AT_specification, etc.
10455 This is for use in contexts where we're reading .debug_types dies.
10456 Following DW_AT_specification, DW_AT_abstract_origin will take us
10457 back up the chain, and we want to go down. */
10459 static struct attribute
*
10460 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10461 struct dwarf2_cu
*cu
)
10465 for (i
= 0; i
< die
->num_attrs
; ++i
)
10466 if (die
->attrs
[i
].name
== name
)
10467 return &die
->attrs
[i
];
10472 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10473 and holds a non-zero value. This function should only be used for
10474 DW_FORM_flag or DW_FORM_flag_present attributes. */
10477 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10479 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10481 return (attr
&& DW_UNSND (attr
));
10485 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10487 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10488 which value is non-zero. However, we have to be careful with
10489 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10490 (via dwarf2_flag_true_p) follows this attribute. So we may
10491 end up accidently finding a declaration attribute that belongs
10492 to a different DIE referenced by the specification attribute,
10493 even though the given DIE does not have a declaration attribute. */
10494 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10495 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10498 /* Return the die giving the specification for DIE, if there is
10499 one. *SPEC_CU is the CU containing DIE on input, and the CU
10500 containing the return value on output. If there is no
10501 specification, but there is an abstract origin, that is
10504 static struct die_info
*
10505 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10507 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10510 if (spec_attr
== NULL
)
10511 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10513 if (spec_attr
== NULL
)
10516 return follow_die_ref (die
, spec_attr
, spec_cu
);
10519 /* Free the line_header structure *LH, and any arrays and strings it
10521 NOTE: This is also used as a "cleanup" function. */
10524 free_line_header (struct line_header
*lh
)
10526 if (lh
->standard_opcode_lengths
)
10527 xfree (lh
->standard_opcode_lengths
);
10529 /* Remember that all the lh->file_names[i].name pointers are
10530 pointers into debug_line_buffer, and don't need to be freed. */
10531 if (lh
->file_names
)
10532 xfree (lh
->file_names
);
10534 /* Similarly for the include directory names. */
10535 if (lh
->include_dirs
)
10536 xfree (lh
->include_dirs
);
10541 /* Add an entry to LH's include directory table. */
10544 add_include_dir (struct line_header
*lh
, char *include_dir
)
10546 /* Grow the array if necessary. */
10547 if (lh
->include_dirs_size
== 0)
10549 lh
->include_dirs_size
= 1; /* for testing */
10550 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10551 * sizeof (*lh
->include_dirs
));
10553 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10555 lh
->include_dirs_size
*= 2;
10556 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10557 (lh
->include_dirs_size
10558 * sizeof (*lh
->include_dirs
)));
10561 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10564 /* Add an entry to LH's file name table. */
10567 add_file_name (struct line_header
*lh
,
10569 unsigned int dir_index
,
10570 unsigned int mod_time
,
10571 unsigned int length
)
10573 struct file_entry
*fe
;
10575 /* Grow the array if necessary. */
10576 if (lh
->file_names_size
== 0)
10578 lh
->file_names_size
= 1; /* for testing */
10579 lh
->file_names
= xmalloc (lh
->file_names_size
10580 * sizeof (*lh
->file_names
));
10582 else if (lh
->num_file_names
>= lh
->file_names_size
)
10584 lh
->file_names_size
*= 2;
10585 lh
->file_names
= xrealloc (lh
->file_names
,
10586 (lh
->file_names_size
10587 * sizeof (*lh
->file_names
)));
10590 fe
= &lh
->file_names
[lh
->num_file_names
++];
10592 fe
->dir_index
= dir_index
;
10593 fe
->mod_time
= mod_time
;
10594 fe
->length
= length
;
10595 fe
->included_p
= 0;
10599 /* Read the statement program header starting at OFFSET in
10600 .debug_line, according to the endianness of ABFD. Return a pointer
10601 to a struct line_header, allocated using xmalloc.
10603 NOTE: the strings in the include directory and file name tables of
10604 the returned object point into debug_line_buffer, and must not be
10607 static struct line_header
*
10608 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10609 struct dwarf2_cu
*cu
)
10611 struct cleanup
*back_to
;
10612 struct line_header
*lh
;
10613 gdb_byte
*line_ptr
;
10614 unsigned int bytes_read
, offset_size
;
10616 char *cur_dir
, *cur_file
;
10618 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10619 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10621 complaint (&symfile_complaints
, _("missing .debug_line section"));
10625 /* Make sure that at least there's room for the total_length field.
10626 That could be 12 bytes long, but we're just going to fudge that. */
10627 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10629 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10633 lh
= xmalloc (sizeof (*lh
));
10634 memset (lh
, 0, sizeof (*lh
));
10635 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10638 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10640 /* Read in the header. */
10642 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10643 &bytes_read
, &offset_size
);
10644 line_ptr
+= bytes_read
;
10645 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10646 + dwarf2_per_objfile
->line
.size
))
10648 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10651 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10652 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10654 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10655 line_ptr
+= offset_size
;
10656 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10658 if (lh
->version
>= 4)
10660 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10664 lh
->maximum_ops_per_instruction
= 1;
10666 if (lh
->maximum_ops_per_instruction
== 0)
10668 lh
->maximum_ops_per_instruction
= 1;
10669 complaint (&symfile_complaints
,
10670 _("invalid maximum_ops_per_instruction "
10671 "in `.debug_line' section"));
10674 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10676 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10678 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10680 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10682 lh
->standard_opcode_lengths
10683 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10685 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10686 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10688 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10692 /* Read directory table. */
10693 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10695 line_ptr
+= bytes_read
;
10696 add_include_dir (lh
, cur_dir
);
10698 line_ptr
+= bytes_read
;
10700 /* Read file name table. */
10701 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10703 unsigned int dir_index
, mod_time
, length
;
10705 line_ptr
+= bytes_read
;
10706 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10707 line_ptr
+= bytes_read
;
10708 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10709 line_ptr
+= bytes_read
;
10710 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10711 line_ptr
+= bytes_read
;
10713 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10715 line_ptr
+= bytes_read
;
10716 lh
->statement_program_start
= line_ptr
;
10718 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
10719 + dwarf2_per_objfile
->line
.size
))
10720 complaint (&symfile_complaints
,
10721 _("line number info header doesn't "
10722 "fit in `.debug_line' section"));
10724 discard_cleanups (back_to
);
10728 /* This function exists to work around a bug in certain compilers
10729 (particularly GCC 2.95), in which the first line number marker of a
10730 function does not show up until after the prologue, right before
10731 the second line number marker. This function shifts ADDRESS down
10732 to the beginning of the function if necessary, and is called on
10733 addresses passed to record_line. */
10736 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
10738 struct function_range
*fn
;
10740 /* Find the function_range containing address. */
10744 if (!cu
->cached_fn
)
10745 cu
->cached_fn
= cu
->first_fn
;
10747 fn
= cu
->cached_fn
;
10749 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10755 while (fn
&& fn
!= cu
->cached_fn
)
10756 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10766 if (address
!= fn
->lowpc
)
10767 complaint (&symfile_complaints
,
10768 _("misplaced first line number at 0x%lx for '%s'"),
10769 (unsigned long) address
, fn
->name
);
10774 /* Subroutine of dwarf_decode_lines to simplify it.
10775 Return the file name of the psymtab for included file FILE_INDEX
10776 in line header LH of PST.
10777 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10778 If space for the result is malloc'd, it will be freed by a cleanup.
10779 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10782 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10783 const struct partial_symtab
*pst
,
10784 const char *comp_dir
)
10786 const struct file_entry fe
= lh
->file_names
[file_index
];
10787 char *include_name
= fe
.name
;
10788 char *include_name_to_compare
= include_name
;
10789 char *dir_name
= NULL
;
10790 const char *pst_filename
;
10791 char *copied_name
= NULL
;
10795 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10797 if (!IS_ABSOLUTE_PATH (include_name
)
10798 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10800 /* Avoid creating a duplicate psymtab for PST.
10801 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10802 Before we do the comparison, however, we need to account
10803 for DIR_NAME and COMP_DIR.
10804 First prepend dir_name (if non-NULL). If we still don't
10805 have an absolute path prepend comp_dir (if non-NULL).
10806 However, the directory we record in the include-file's
10807 psymtab does not contain COMP_DIR (to match the
10808 corresponding symtab(s)).
10813 bash$ gcc -g ./hello.c
10814 include_name = "hello.c"
10816 DW_AT_comp_dir = comp_dir = "/tmp"
10817 DW_AT_name = "./hello.c" */
10819 if (dir_name
!= NULL
)
10821 include_name
= concat (dir_name
, SLASH_STRING
,
10822 include_name
, (char *)NULL
);
10823 include_name_to_compare
= include_name
;
10824 make_cleanup (xfree
, include_name
);
10826 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10828 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10829 include_name
, (char *)NULL
);
10833 pst_filename
= pst
->filename
;
10834 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10836 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
10837 pst_filename
, (char *)NULL
);
10838 pst_filename
= copied_name
;
10841 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
10843 if (include_name_to_compare
!= include_name
)
10844 xfree (include_name_to_compare
);
10845 if (copied_name
!= NULL
)
10846 xfree (copied_name
);
10850 return include_name
;
10853 /* Ignore this record_line request. */
10856 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10861 /* Decode the Line Number Program (LNP) for the given line_header
10862 structure and CU. The actual information extracted and the type
10863 of structures created from the LNP depends on the value of PST.
10865 1. If PST is NULL, then this procedure uses the data from the program
10866 to create all necessary symbol tables, and their linetables.
10868 2. If PST is not NULL, this procedure reads the program to determine
10869 the list of files included by the unit represented by PST, and
10870 builds all the associated partial symbol tables.
10872 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10873 It is used for relative paths in the line table.
10874 NOTE: When processing partial symtabs (pst != NULL),
10875 comp_dir == pst->dirname.
10877 NOTE: It is important that psymtabs have the same file name (via strcmp)
10878 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10879 symtab we don't use it in the name of the psymtabs we create.
10880 E.g. expand_line_sal requires this when finding psymtabs to expand.
10881 A good testcase for this is mb-inline.exp. */
10884 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
10885 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10887 gdb_byte
*line_ptr
, *extended_end
;
10888 gdb_byte
*line_end
;
10889 unsigned int bytes_read
, extended_len
;
10890 unsigned char op_code
, extended_op
, adj_opcode
;
10891 CORE_ADDR baseaddr
;
10892 struct objfile
*objfile
= cu
->objfile
;
10893 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10894 const int decode_for_pst_p
= (pst
!= NULL
);
10895 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10896 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10899 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10901 line_ptr
= lh
->statement_program_start
;
10902 line_end
= lh
->statement_program_end
;
10904 /* Read the statement sequences until there's nothing left. */
10905 while (line_ptr
< line_end
)
10907 /* state machine registers */
10908 CORE_ADDR address
= 0;
10909 unsigned int file
= 1;
10910 unsigned int line
= 1;
10911 unsigned int column
= 0;
10912 int is_stmt
= lh
->default_is_stmt
;
10913 int basic_block
= 0;
10914 int end_sequence
= 0;
10916 unsigned char op_index
= 0;
10918 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10920 /* Start a subfile for the current file of the state machine. */
10921 /* lh->include_dirs and lh->file_names are 0-based, but the
10922 directory and file name numbers in the statement program
10924 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10928 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10930 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10933 /* Decode the table. */
10934 while (!end_sequence
)
10936 op_code
= read_1_byte (abfd
, line_ptr
);
10938 if (line_ptr
> line_end
)
10940 dwarf2_debug_line_missing_end_sequence_complaint ();
10944 if (op_code
>= lh
->opcode_base
)
10946 /* Special operand. */
10947 adj_opcode
= op_code
- lh
->opcode_base
;
10948 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10949 / lh
->maximum_ops_per_instruction
)
10950 * lh
->minimum_instruction_length
);
10951 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10952 % lh
->maximum_ops_per_instruction
);
10953 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10954 if (lh
->num_file_names
< file
|| file
== 0)
10955 dwarf2_debug_line_missing_file_complaint ();
10956 /* For now we ignore lines not starting on an
10957 instruction boundary. */
10958 else if (op_index
== 0)
10960 lh
->file_names
[file
- 1].included_p
= 1;
10961 if (!decode_for_pst_p
&& is_stmt
)
10963 if (last_subfile
!= current_subfile
)
10965 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10967 (*p_record_line
) (last_subfile
, 0, addr
);
10968 last_subfile
= current_subfile
;
10970 /* Append row to matrix using current values. */
10971 addr
= check_cu_functions (address
, cu
);
10972 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10973 (*p_record_line
) (current_subfile
, line
, addr
);
10978 else switch (op_code
)
10980 case DW_LNS_extended_op
:
10981 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
10983 line_ptr
+= bytes_read
;
10984 extended_end
= line_ptr
+ extended_len
;
10985 extended_op
= read_1_byte (abfd
, line_ptr
);
10987 switch (extended_op
)
10989 case DW_LNE_end_sequence
:
10990 p_record_line
= record_line
;
10993 case DW_LNE_set_address
:
10994 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10996 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10998 /* This line table is for a function which has been
10999 GCd by the linker. Ignore it. PR gdb/12528 */
11002 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
11004 complaint (&symfile_complaints
,
11005 _(".debug_line address at offset 0x%lx is 0 "
11007 line_offset
, cu
->objfile
->name
);
11008 p_record_line
= noop_record_line
;
11012 line_ptr
+= bytes_read
;
11013 address
+= baseaddr
;
11015 case DW_LNE_define_file
:
11018 unsigned int dir_index
, mod_time
, length
;
11020 cur_file
= read_direct_string (abfd
, line_ptr
,
11022 line_ptr
+= bytes_read
;
11024 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11025 line_ptr
+= bytes_read
;
11027 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11028 line_ptr
+= bytes_read
;
11030 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11031 line_ptr
+= bytes_read
;
11032 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11035 case DW_LNE_set_discriminator
:
11036 /* The discriminator is not interesting to the debugger;
11038 line_ptr
= extended_end
;
11041 complaint (&symfile_complaints
,
11042 _("mangled .debug_line section"));
11045 /* Make sure that we parsed the extended op correctly. If e.g.
11046 we expected a different address size than the producer used,
11047 we may have read the wrong number of bytes. */
11048 if (line_ptr
!= extended_end
)
11050 complaint (&symfile_complaints
,
11051 _("mangled .debug_line section"));
11056 if (lh
->num_file_names
< file
|| file
== 0)
11057 dwarf2_debug_line_missing_file_complaint ();
11060 lh
->file_names
[file
- 1].included_p
= 1;
11061 if (!decode_for_pst_p
&& is_stmt
)
11063 if (last_subfile
!= current_subfile
)
11065 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11067 (*p_record_line
) (last_subfile
, 0, addr
);
11068 last_subfile
= current_subfile
;
11070 addr
= check_cu_functions (address
, cu
);
11071 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
11072 (*p_record_line
) (current_subfile
, line
, addr
);
11077 case DW_LNS_advance_pc
:
11080 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11082 address
+= (((op_index
+ adjust
)
11083 / lh
->maximum_ops_per_instruction
)
11084 * lh
->minimum_instruction_length
);
11085 op_index
= ((op_index
+ adjust
)
11086 % lh
->maximum_ops_per_instruction
);
11087 line_ptr
+= bytes_read
;
11090 case DW_LNS_advance_line
:
11091 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11092 line_ptr
+= bytes_read
;
11094 case DW_LNS_set_file
:
11096 /* The arrays lh->include_dirs and lh->file_names are
11097 0-based, but the directory and file name numbers in
11098 the statement program are 1-based. */
11099 struct file_entry
*fe
;
11102 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11103 line_ptr
+= bytes_read
;
11104 if (lh
->num_file_names
< file
|| file
== 0)
11105 dwarf2_debug_line_missing_file_complaint ();
11108 fe
= &lh
->file_names
[file
- 1];
11110 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11111 if (!decode_for_pst_p
)
11113 last_subfile
= current_subfile
;
11114 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11119 case DW_LNS_set_column
:
11120 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11121 line_ptr
+= bytes_read
;
11123 case DW_LNS_negate_stmt
:
11124 is_stmt
= (!is_stmt
);
11126 case DW_LNS_set_basic_block
:
11129 /* Add to the address register of the state machine the
11130 address increment value corresponding to special opcode
11131 255. I.e., this value is scaled by the minimum
11132 instruction length since special opcode 255 would have
11133 scaled the increment. */
11134 case DW_LNS_const_add_pc
:
11136 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11138 address
+= (((op_index
+ adjust
)
11139 / lh
->maximum_ops_per_instruction
)
11140 * lh
->minimum_instruction_length
);
11141 op_index
= ((op_index
+ adjust
)
11142 % lh
->maximum_ops_per_instruction
);
11145 case DW_LNS_fixed_advance_pc
:
11146 address
+= read_2_bytes (abfd
, line_ptr
);
11152 /* Unknown standard opcode, ignore it. */
11155 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11157 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11158 line_ptr
+= bytes_read
;
11163 if (lh
->num_file_names
< file
|| file
== 0)
11164 dwarf2_debug_line_missing_file_complaint ();
11167 lh
->file_names
[file
- 1].included_p
= 1;
11168 if (!decode_for_pst_p
)
11170 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11171 (*p_record_line
) (current_subfile
, 0, addr
);
11176 if (decode_for_pst_p
)
11180 /* Now that we're done scanning the Line Header Program, we can
11181 create the psymtab of each included file. */
11182 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11183 if (lh
->file_names
[file_index
].included_p
== 1)
11185 char *include_name
=
11186 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11187 if (include_name
!= NULL
)
11188 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11193 /* Make sure a symtab is created for every file, even files
11194 which contain only variables (i.e. no code with associated
11198 struct file_entry
*fe
;
11200 for (i
= 0; i
< lh
->num_file_names
; i
++)
11204 fe
= &lh
->file_names
[i
];
11206 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11207 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11209 /* Skip the main file; we don't need it, and it must be
11210 allocated last, so that it will show up before the
11211 non-primary symtabs in the objfile's symtab list. */
11212 if (current_subfile
== first_subfile
)
11215 if (current_subfile
->symtab
== NULL
)
11216 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11218 fe
->symtab
= current_subfile
->symtab
;
11223 /* Start a subfile for DWARF. FILENAME is the name of the file and
11224 DIRNAME the name of the source directory which contains FILENAME
11225 or NULL if not known. COMP_DIR is the compilation directory for the
11226 linetable's compilation unit or NULL if not known.
11227 This routine tries to keep line numbers from identical absolute and
11228 relative file names in a common subfile.
11230 Using the `list' example from the GDB testsuite, which resides in
11231 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11232 of /srcdir/list0.c yields the following debugging information for list0.c:
11234 DW_AT_name: /srcdir/list0.c
11235 DW_AT_comp_dir: /compdir
11236 files.files[0].name: list0.h
11237 files.files[0].dir: /srcdir
11238 files.files[1].name: list0.c
11239 files.files[1].dir: /srcdir
11241 The line number information for list0.c has to end up in a single
11242 subfile, so that `break /srcdir/list0.c:1' works as expected.
11243 start_subfile will ensure that this happens provided that we pass the
11244 concatenation of files.files[1].dir and files.files[1].name as the
11248 dwarf2_start_subfile (char *filename
, const char *dirname
,
11249 const char *comp_dir
)
11253 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11254 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11255 second argument to start_subfile. To be consistent, we do the
11256 same here. In order not to lose the line information directory,
11257 we concatenate it to the filename when it makes sense.
11258 Note that the Dwarf3 standard says (speaking of filenames in line
11259 information): ``The directory index is ignored for file names
11260 that represent full path names''. Thus ignoring dirname in the
11261 `else' branch below isn't an issue. */
11263 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11264 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11266 fullname
= filename
;
11268 start_subfile (fullname
, comp_dir
);
11270 if (fullname
!= filename
)
11275 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11276 struct dwarf2_cu
*cu
)
11278 struct objfile
*objfile
= cu
->objfile
;
11279 struct comp_unit_head
*cu_header
= &cu
->header
;
11281 /* NOTE drow/2003-01-30: There used to be a comment and some special
11282 code here to turn a symbol with DW_AT_external and a
11283 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11284 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11285 with some versions of binutils) where shared libraries could have
11286 relocations against symbols in their debug information - the
11287 minimal symbol would have the right address, but the debug info
11288 would not. It's no longer necessary, because we will explicitly
11289 apply relocations when we read in the debug information now. */
11291 /* A DW_AT_location attribute with no contents indicates that a
11292 variable has been optimized away. */
11293 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11295 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11299 /* Handle one degenerate form of location expression specially, to
11300 preserve GDB's previous behavior when section offsets are
11301 specified. If this is just a DW_OP_addr then mark this symbol
11304 if (attr_form_is_block (attr
)
11305 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11306 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11308 unsigned int dummy
;
11310 SYMBOL_VALUE_ADDRESS (sym
) =
11311 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11312 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11313 fixup_symbol_section (sym
, objfile
);
11314 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11315 SYMBOL_SECTION (sym
));
11319 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11320 expression evaluator, and use LOC_COMPUTED only when necessary
11321 (i.e. when the value of a register or memory location is
11322 referenced, or a thread-local block, etc.). Then again, it might
11323 not be worthwhile. I'm assuming that it isn't unless performance
11324 or memory numbers show me otherwise. */
11326 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11327 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11329 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11330 cu
->has_loclist
= 1;
11333 /* Given a pointer to a DWARF information entry, figure out if we need
11334 to make a symbol table entry for it, and if so, create a new entry
11335 and return a pointer to it.
11336 If TYPE is NULL, determine symbol type from the die, otherwise
11337 used the passed type.
11338 If SPACE is not NULL, use it to hold the new symbol. If it is
11339 NULL, allocate a new symbol on the objfile's obstack. */
11341 static struct symbol
*
11342 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11343 struct symbol
*space
)
11345 struct objfile
*objfile
= cu
->objfile
;
11346 struct symbol
*sym
= NULL
;
11348 struct attribute
*attr
= NULL
;
11349 struct attribute
*attr2
= NULL
;
11350 CORE_ADDR baseaddr
;
11351 struct pending
**list_to_add
= NULL
;
11353 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11355 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11357 name
= dwarf2_name (die
, cu
);
11360 const char *linkagename
;
11361 int suppress_add
= 0;
11366 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11367 OBJSTAT (objfile
, n_syms
++);
11369 /* Cache this symbol's name and the name's demangled form (if any). */
11370 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11371 linkagename
= dwarf2_physname (name
, die
, cu
);
11372 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11374 /* Fortran does not have mangling standard and the mangling does differ
11375 between gfortran, iFort etc. */
11376 if (cu
->language
== language_fortran
11377 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11378 symbol_set_demangled_name (&(sym
->ginfo
),
11379 (char *) dwarf2_full_name (name
, die
, cu
),
11382 /* Default assumptions.
11383 Use the passed type or decode it from the die. */
11384 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11385 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11387 SYMBOL_TYPE (sym
) = type
;
11389 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11390 attr
= dwarf2_attr (die
,
11391 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11395 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11398 attr
= dwarf2_attr (die
,
11399 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11403 int file_index
= DW_UNSND (attr
);
11405 if (cu
->line_header
== NULL
11406 || file_index
> cu
->line_header
->num_file_names
)
11407 complaint (&symfile_complaints
,
11408 _("file index out of range"));
11409 else if (file_index
> 0)
11411 struct file_entry
*fe
;
11413 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11414 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11421 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11424 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11426 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11427 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11428 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11429 add_symbol_to_list (sym
, cu
->list_in_scope
);
11431 case DW_TAG_subprogram
:
11432 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11434 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11435 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11436 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11437 || cu
->language
== language_ada
)
11439 /* Subprograms marked external are stored as a global symbol.
11440 Ada subprograms, whether marked external or not, are always
11441 stored as a global symbol, because we want to be able to
11442 access them globally. For instance, we want to be able
11443 to break on a nested subprogram without having to
11444 specify the context. */
11445 list_to_add
= &global_symbols
;
11449 list_to_add
= cu
->list_in_scope
;
11452 case DW_TAG_inlined_subroutine
:
11453 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11455 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11456 SYMBOL_INLINED (sym
) = 1;
11457 /* Do not add the symbol to any lists. It will be found via
11458 BLOCK_FUNCTION from the blockvector. */
11460 case DW_TAG_template_value_param
:
11462 /* Fall through. */
11463 case DW_TAG_constant
:
11464 case DW_TAG_variable
:
11465 case DW_TAG_member
:
11466 /* Compilation with minimal debug info may result in
11467 variables with missing type entries. Change the
11468 misleading `void' type to something sensible. */
11469 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11471 = objfile_type (objfile
)->nodebug_data_symbol
;
11473 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11474 /* In the case of DW_TAG_member, we should only be called for
11475 static const members. */
11476 if (die
->tag
== DW_TAG_member
)
11478 /* dwarf2_add_field uses die_is_declaration,
11479 so we do the same. */
11480 gdb_assert (die_is_declaration (die
, cu
));
11485 dwarf2_const_value (attr
, sym
, cu
);
11486 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11489 if (attr2
&& (DW_UNSND (attr2
) != 0))
11490 list_to_add
= &global_symbols
;
11492 list_to_add
= cu
->list_in_scope
;
11496 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11499 var_decode_location (attr
, sym
, cu
);
11500 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11501 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11502 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11503 && !dwarf2_per_objfile
->has_section_at_zero
)
11505 /* When a static variable is eliminated by the linker,
11506 the corresponding debug information is not stripped
11507 out, but the variable address is set to null;
11508 do not add such variables into symbol table. */
11510 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11512 /* Workaround gfortran PR debug/40040 - it uses
11513 DW_AT_location for variables in -fPIC libraries which may
11514 get overriden by other libraries/executable and get
11515 a different address. Resolve it by the minimal symbol
11516 which may come from inferior's executable using copy
11517 relocation. Make this workaround only for gfortran as for
11518 other compilers GDB cannot guess the minimal symbol
11519 Fortran mangling kind. */
11520 if (cu
->language
== language_fortran
&& die
->parent
11521 && die
->parent
->tag
== DW_TAG_module
11523 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11524 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11526 /* A variable with DW_AT_external is never static,
11527 but it may be block-scoped. */
11528 list_to_add
= (cu
->list_in_scope
== &file_symbols
11529 ? &global_symbols
: cu
->list_in_scope
);
11532 list_to_add
= cu
->list_in_scope
;
11536 /* We do not know the address of this symbol.
11537 If it is an external symbol and we have type information
11538 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11539 The address of the variable will then be determined from
11540 the minimal symbol table whenever the variable is
11542 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11543 if (attr2
&& (DW_UNSND (attr2
) != 0)
11544 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11546 /* A variable with DW_AT_external is never static, but it
11547 may be block-scoped. */
11548 list_to_add
= (cu
->list_in_scope
== &file_symbols
11549 ? &global_symbols
: cu
->list_in_scope
);
11551 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11553 else if (!die_is_declaration (die
, cu
))
11555 /* Use the default LOC_OPTIMIZED_OUT class. */
11556 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11558 list_to_add
= cu
->list_in_scope
;
11562 case DW_TAG_formal_parameter
:
11563 /* If we are inside a function, mark this as an argument. If
11564 not, we might be looking at an argument to an inlined function
11565 when we do not have enough information to show inlined frames;
11566 pretend it's a local variable in that case so that the user can
11568 if (context_stack_depth
> 0
11569 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11570 SYMBOL_IS_ARGUMENT (sym
) = 1;
11571 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11574 var_decode_location (attr
, sym
, cu
);
11576 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11579 dwarf2_const_value (attr
, sym
, cu
);
11581 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
11582 if (attr
&& DW_UNSND (attr
))
11584 struct type
*ref_type
;
11586 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
11587 SYMBOL_TYPE (sym
) = ref_type
;
11590 list_to_add
= cu
->list_in_scope
;
11592 case DW_TAG_unspecified_parameters
:
11593 /* From varargs functions; gdb doesn't seem to have any
11594 interest in this information, so just ignore it for now.
11597 case DW_TAG_template_type_param
:
11599 /* Fall through. */
11600 case DW_TAG_class_type
:
11601 case DW_TAG_interface_type
:
11602 case DW_TAG_structure_type
:
11603 case DW_TAG_union_type
:
11604 case DW_TAG_set_type
:
11605 case DW_TAG_enumeration_type
:
11606 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11607 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11610 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11611 really ever be static objects: otherwise, if you try
11612 to, say, break of a class's method and you're in a file
11613 which doesn't mention that class, it won't work unless
11614 the check for all static symbols in lookup_symbol_aux
11615 saves you. See the OtherFileClass tests in
11616 gdb.c++/namespace.exp. */
11620 list_to_add
= (cu
->list_in_scope
== &file_symbols
11621 && (cu
->language
== language_cplus
11622 || cu
->language
== language_java
)
11623 ? &global_symbols
: cu
->list_in_scope
);
11625 /* The semantics of C++ state that "struct foo {
11626 ... }" also defines a typedef for "foo". A Java
11627 class declaration also defines a typedef for the
11629 if (cu
->language
== language_cplus
11630 || cu
->language
== language_java
11631 || cu
->language
== language_ada
)
11633 /* The symbol's name is already allocated along
11634 with this objfile, so we don't need to
11635 duplicate it for the type. */
11636 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11637 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11642 case DW_TAG_typedef
:
11643 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11644 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11645 list_to_add
= cu
->list_in_scope
;
11647 case DW_TAG_base_type
:
11648 case DW_TAG_subrange_type
:
11649 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11650 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11651 list_to_add
= cu
->list_in_scope
;
11653 case DW_TAG_enumerator
:
11654 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11657 dwarf2_const_value (attr
, sym
, cu
);
11660 /* NOTE: carlton/2003-11-10: See comment above in the
11661 DW_TAG_class_type, etc. block. */
11663 list_to_add
= (cu
->list_in_scope
== &file_symbols
11664 && (cu
->language
== language_cplus
11665 || cu
->language
== language_java
)
11666 ? &global_symbols
: cu
->list_in_scope
);
11669 case DW_TAG_namespace
:
11670 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11671 list_to_add
= &global_symbols
;
11674 /* Not a tag we recognize. Hopefully we aren't processing
11675 trash data, but since we must specifically ignore things
11676 we don't recognize, there is nothing else we should do at
11678 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11679 dwarf_tag_name (die
->tag
));
11685 sym
->hash_next
= objfile
->template_symbols
;
11686 objfile
->template_symbols
= sym
;
11687 list_to_add
= NULL
;
11690 if (list_to_add
!= NULL
)
11691 add_symbol_to_list (sym
, list_to_add
);
11693 /* For the benefit of old versions of GCC, check for anonymous
11694 namespaces based on the demangled name. */
11695 if (!processing_has_namespace_info
11696 && cu
->language
== language_cplus
)
11697 cp_scan_for_anonymous_namespaces (sym
);
11702 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11704 static struct symbol
*
11705 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11707 return new_symbol_full (die
, type
, cu
, NULL
);
11710 /* Given an attr with a DW_FORM_dataN value in host byte order,
11711 zero-extend it as appropriate for the symbol's type. The DWARF
11712 standard (v4) is not entirely clear about the meaning of using
11713 DW_FORM_dataN for a constant with a signed type, where the type is
11714 wider than the data. The conclusion of a discussion on the DWARF
11715 list was that this is unspecified. We choose to always zero-extend
11716 because that is the interpretation long in use by GCC. */
11719 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11720 const char *name
, struct obstack
*obstack
,
11721 struct dwarf2_cu
*cu
, long *value
, int bits
)
11723 struct objfile
*objfile
= cu
->objfile
;
11724 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11725 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11726 LONGEST l
= DW_UNSND (attr
);
11728 if (bits
< sizeof (*value
) * 8)
11730 l
&= ((LONGEST
) 1 << bits
) - 1;
11733 else if (bits
== sizeof (*value
) * 8)
11737 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11738 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11745 /* Read a constant value from an attribute. Either set *VALUE, or if
11746 the value does not fit in *VALUE, set *BYTES - either already
11747 allocated on the objfile obstack, or newly allocated on OBSTACK,
11748 or, set *BATON, if we translated the constant to a location
11752 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11753 const char *name
, struct obstack
*obstack
,
11754 struct dwarf2_cu
*cu
,
11755 long *value
, gdb_byte
**bytes
,
11756 struct dwarf2_locexpr_baton
**baton
)
11758 struct objfile
*objfile
= cu
->objfile
;
11759 struct comp_unit_head
*cu_header
= &cu
->header
;
11760 struct dwarf_block
*blk
;
11761 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
11762 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
11768 switch (attr
->form
)
11774 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
11775 dwarf2_const_value_length_mismatch_complaint (name
,
11776 cu_header
->addr_size
,
11777 TYPE_LENGTH (type
));
11778 /* Symbols of this form are reasonably rare, so we just
11779 piggyback on the existing location code rather than writing
11780 a new implementation of symbol_computed_ops. */
11781 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11782 sizeof (struct dwarf2_locexpr_baton
));
11783 (*baton
)->per_cu
= cu
->per_cu
;
11784 gdb_assert ((*baton
)->per_cu
);
11786 (*baton
)->size
= 2 + cu_header
->addr_size
;
11787 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11788 (*baton
)->data
= data
;
11790 data
[0] = DW_OP_addr
;
11791 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11792 byte_order
, DW_ADDR (attr
));
11793 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11796 case DW_FORM_string
:
11798 /* DW_STRING is already allocated on the objfile obstack, point
11800 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11802 case DW_FORM_block1
:
11803 case DW_FORM_block2
:
11804 case DW_FORM_block4
:
11805 case DW_FORM_block
:
11806 case DW_FORM_exprloc
:
11807 blk
= DW_BLOCK (attr
);
11808 if (TYPE_LENGTH (type
) != blk
->size
)
11809 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11810 TYPE_LENGTH (type
));
11811 *bytes
= blk
->data
;
11814 /* The DW_AT_const_value attributes are supposed to carry the
11815 symbol's value "represented as it would be on the target
11816 architecture." By the time we get here, it's already been
11817 converted to host endianness, so we just need to sign- or
11818 zero-extend it as appropriate. */
11819 case DW_FORM_data1
:
11820 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11821 obstack
, cu
, value
, 8);
11823 case DW_FORM_data2
:
11824 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11825 obstack
, cu
, value
, 16);
11827 case DW_FORM_data4
:
11828 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11829 obstack
, cu
, value
, 32);
11831 case DW_FORM_data8
:
11832 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11833 obstack
, cu
, value
, 64);
11836 case DW_FORM_sdata
:
11837 *value
= DW_SND (attr
);
11840 case DW_FORM_udata
:
11841 *value
= DW_UNSND (attr
);
11845 complaint (&symfile_complaints
,
11846 _("unsupported const value attribute form: '%s'"),
11847 dwarf_form_name (attr
->form
));
11854 /* Copy constant value from an attribute to a symbol. */
11857 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11858 struct dwarf2_cu
*cu
)
11860 struct objfile
*objfile
= cu
->objfile
;
11861 struct comp_unit_head
*cu_header
= &cu
->header
;
11864 struct dwarf2_locexpr_baton
*baton
;
11866 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11867 SYMBOL_PRINT_NAME (sym
),
11868 &objfile
->objfile_obstack
, cu
,
11869 &value
, &bytes
, &baton
);
11873 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11874 SYMBOL_LOCATION_BATON (sym
) = baton
;
11875 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11877 else if (bytes
!= NULL
)
11879 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11880 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11884 SYMBOL_VALUE (sym
) = value
;
11885 SYMBOL_CLASS (sym
) = LOC_CONST
;
11889 /* Return the type of the die in question using its DW_AT_type attribute. */
11891 static struct type
*
11892 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11894 struct attribute
*type_attr
;
11896 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11899 /* A missing DW_AT_type represents a void type. */
11900 return objfile_type (cu
->objfile
)->builtin_void
;
11903 return lookup_die_type (die
, type_attr
, cu
);
11906 /* True iff CU's producer generates GNAT Ada auxiliary information
11907 that allows to find parallel types through that information instead
11908 of having to do expensive parallel lookups by type name. */
11911 need_gnat_info (struct dwarf2_cu
*cu
)
11913 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11914 of GNAT produces this auxiliary information, without any indication
11915 that it is produced. Part of enhancing the FSF version of GNAT
11916 to produce that information will be to put in place an indicator
11917 that we can use in order to determine whether the descriptive type
11918 info is available or not. One suggestion that has been made is
11919 to use a new attribute, attached to the CU die. For now, assume
11920 that the descriptive type info is not available. */
11924 /* Return the auxiliary type of the die in question using its
11925 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11926 attribute is not present. */
11928 static struct type
*
11929 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11931 struct attribute
*type_attr
;
11933 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11937 return lookup_die_type (die
, type_attr
, cu
);
11940 /* If DIE has a descriptive_type attribute, then set the TYPE's
11941 descriptive type accordingly. */
11944 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11945 struct dwarf2_cu
*cu
)
11947 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11949 if (descriptive_type
)
11951 ALLOCATE_GNAT_AUX_TYPE (type
);
11952 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11956 /* Return the containing type of the die in question using its
11957 DW_AT_containing_type attribute. */
11959 static struct type
*
11960 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11962 struct attribute
*type_attr
;
11964 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11966 error (_("Dwarf Error: Problem turning containing type into gdb type "
11967 "[in module %s]"), cu
->objfile
->name
);
11969 return lookup_die_type (die
, type_attr
, cu
);
11972 /* Look up the type of DIE in CU using its type attribute ATTR.
11973 If there is no type substitute an error marker. */
11975 static struct type
*
11976 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11977 struct dwarf2_cu
*cu
)
11979 struct type
*this_type
;
11981 /* First see if we have it cached. */
11983 if (is_ref_attr (attr
))
11985 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11987 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11989 else if (attr
->form
== DW_FORM_ref_sig8
)
11991 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11992 struct dwarf2_cu
*sig_cu
;
11993 unsigned int offset
;
11995 /* sig_type will be NULL if the signatured type is missing from
11997 if (sig_type
== NULL
)
11998 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11999 "at 0x%x [in module %s]"),
12000 die
->offset
, cu
->objfile
->name
);
12002 gdb_assert (sig_type
->per_cu
.debug_type_section
);
12003 offset
= sig_type
->per_cu
.offset
+ sig_type
->type_offset
;
12004 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
12008 dump_die_for_error (die
);
12009 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12010 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
12013 /* If not cached we need to read it in. */
12015 if (this_type
== NULL
)
12017 struct die_info
*type_die
;
12018 struct dwarf2_cu
*type_cu
= cu
;
12020 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
12021 /* If the type is cached, we should have found it above. */
12022 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
12023 this_type
= read_type_die_1 (type_die
, type_cu
);
12026 /* If we still don't have a type use an error marker. */
12028 if (this_type
== NULL
)
12030 char *message
, *saved
;
12032 /* read_type_die already issued a complaint. */
12033 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12037 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
12038 message
, strlen (message
));
12041 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
12047 /* Return the type in DIE, CU.
12048 Returns NULL for invalid types.
12050 This first does a lookup in the appropriate type_hash table,
12051 and only reads the die in if necessary.
12053 NOTE: This can be called when reading in partial or full symbols. */
12055 static struct type
*
12056 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12058 struct type
*this_type
;
12060 this_type
= get_die_type (die
, cu
);
12064 return read_type_die_1 (die
, cu
);
12067 /* Read the type in DIE, CU.
12068 Returns NULL for invalid types. */
12070 static struct type
*
12071 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12073 struct type
*this_type
= NULL
;
12077 case DW_TAG_class_type
:
12078 case DW_TAG_interface_type
:
12079 case DW_TAG_structure_type
:
12080 case DW_TAG_union_type
:
12081 this_type
= read_structure_type (die
, cu
);
12083 case DW_TAG_enumeration_type
:
12084 this_type
= read_enumeration_type (die
, cu
);
12086 case DW_TAG_subprogram
:
12087 case DW_TAG_subroutine_type
:
12088 case DW_TAG_inlined_subroutine
:
12089 this_type
= read_subroutine_type (die
, cu
);
12091 case DW_TAG_array_type
:
12092 this_type
= read_array_type (die
, cu
);
12094 case DW_TAG_set_type
:
12095 this_type
= read_set_type (die
, cu
);
12097 case DW_TAG_pointer_type
:
12098 this_type
= read_tag_pointer_type (die
, cu
);
12100 case DW_TAG_ptr_to_member_type
:
12101 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12103 case DW_TAG_reference_type
:
12104 this_type
= read_tag_reference_type (die
, cu
);
12106 case DW_TAG_const_type
:
12107 this_type
= read_tag_const_type (die
, cu
);
12109 case DW_TAG_volatile_type
:
12110 this_type
= read_tag_volatile_type (die
, cu
);
12112 case DW_TAG_string_type
:
12113 this_type
= read_tag_string_type (die
, cu
);
12115 case DW_TAG_typedef
:
12116 this_type
= read_typedef (die
, cu
);
12118 case DW_TAG_subrange_type
:
12119 this_type
= read_subrange_type (die
, cu
);
12121 case DW_TAG_base_type
:
12122 this_type
= read_base_type (die
, cu
);
12124 case DW_TAG_unspecified_type
:
12125 this_type
= read_unspecified_type (die
, cu
);
12127 case DW_TAG_namespace
:
12128 this_type
= read_namespace_type (die
, cu
);
12130 case DW_TAG_module
:
12131 this_type
= read_module_type (die
, cu
);
12134 complaint (&symfile_complaints
,
12135 _("unexpected tag in read_type_die: '%s'"),
12136 dwarf_tag_name (die
->tag
));
12143 /* See if we can figure out if the class lives in a namespace. We do
12144 this by looking for a member function; its demangled name will
12145 contain namespace info, if there is any.
12146 Return the computed name or NULL.
12147 Space for the result is allocated on the objfile's obstack.
12148 This is the full-die version of guess_partial_die_structure_name.
12149 In this case we know DIE has no useful parent. */
12152 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12154 struct die_info
*spec_die
;
12155 struct dwarf2_cu
*spec_cu
;
12156 struct die_info
*child
;
12159 spec_die
= die_specification (die
, &spec_cu
);
12160 if (spec_die
!= NULL
)
12166 for (child
= die
->child
;
12168 child
= child
->sibling
)
12170 if (child
->tag
== DW_TAG_subprogram
)
12172 struct attribute
*attr
;
12174 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12176 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12180 = language_class_name_from_physname (cu
->language_defn
,
12184 if (actual_name
!= NULL
)
12186 char *die_name
= dwarf2_name (die
, cu
);
12188 if (die_name
!= NULL
12189 && strcmp (die_name
, actual_name
) != 0)
12191 /* Strip off the class name from the full name.
12192 We want the prefix. */
12193 int die_name_len
= strlen (die_name
);
12194 int actual_name_len
= strlen (actual_name
);
12196 /* Test for '::' as a sanity check. */
12197 if (actual_name_len
> die_name_len
+ 2
12198 && actual_name
[actual_name_len
12199 - die_name_len
- 1] == ':')
12201 obsavestring (actual_name
,
12202 actual_name_len
- die_name_len
- 2,
12203 &cu
->objfile
->objfile_obstack
);
12206 xfree (actual_name
);
12215 /* Return the name of the namespace/class that DIE is defined within,
12216 or "" if we can't tell. The caller should not xfree the result.
12218 For example, if we're within the method foo() in the following
12228 then determine_prefix on foo's die will return "N::C". */
12231 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12233 struct die_info
*parent
, *spec_die
;
12234 struct dwarf2_cu
*spec_cu
;
12235 struct type
*parent_type
;
12237 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12238 && cu
->language
!= language_fortran
)
12241 /* We have to be careful in the presence of DW_AT_specification.
12242 For example, with GCC 3.4, given the code
12246 // Definition of N::foo.
12250 then we'll have a tree of DIEs like this:
12252 1: DW_TAG_compile_unit
12253 2: DW_TAG_namespace // N
12254 3: DW_TAG_subprogram // declaration of N::foo
12255 4: DW_TAG_subprogram // definition of N::foo
12256 DW_AT_specification // refers to die #3
12258 Thus, when processing die #4, we have to pretend that we're in
12259 the context of its DW_AT_specification, namely the contex of die
12262 spec_die
= die_specification (die
, &spec_cu
);
12263 if (spec_die
== NULL
)
12264 parent
= die
->parent
;
12267 parent
= spec_die
->parent
;
12271 if (parent
== NULL
)
12273 else if (parent
->building_fullname
)
12276 const char *parent_name
;
12278 /* It has been seen on RealView 2.2 built binaries,
12279 DW_TAG_template_type_param types actually _defined_ as
12280 children of the parent class:
12283 template class <class Enum> Class{};
12284 Class<enum E> class_e;
12286 1: DW_TAG_class_type (Class)
12287 2: DW_TAG_enumeration_type (E)
12288 3: DW_TAG_enumerator (enum1:0)
12289 3: DW_TAG_enumerator (enum2:1)
12291 2: DW_TAG_template_type_param
12292 DW_AT_type DW_FORM_ref_udata (E)
12294 Besides being broken debug info, it can put GDB into an
12295 infinite loop. Consider:
12297 When we're building the full name for Class<E>, we'll start
12298 at Class, and go look over its template type parameters,
12299 finding E. We'll then try to build the full name of E, and
12300 reach here. We're now trying to build the full name of E,
12301 and look over the parent DIE for containing scope. In the
12302 broken case, if we followed the parent DIE of E, we'd again
12303 find Class, and once again go look at its template type
12304 arguments, etc., etc. Simply don't consider such parent die
12305 as source-level parent of this die (it can't be, the language
12306 doesn't allow it), and break the loop here. */
12307 name
= dwarf2_name (die
, cu
);
12308 parent_name
= dwarf2_name (parent
, cu
);
12309 complaint (&symfile_complaints
,
12310 _("template param type '%s' defined within parent '%s'"),
12311 name
? name
: "<unknown>",
12312 parent_name
? parent_name
: "<unknown>");
12316 switch (parent
->tag
)
12318 case DW_TAG_namespace
:
12319 parent_type
= read_type_die (parent
, cu
);
12320 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12321 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12322 Work around this problem here. */
12323 if (cu
->language
== language_cplus
12324 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12326 /* We give a name to even anonymous namespaces. */
12327 return TYPE_TAG_NAME (parent_type
);
12328 case DW_TAG_class_type
:
12329 case DW_TAG_interface_type
:
12330 case DW_TAG_structure_type
:
12331 case DW_TAG_union_type
:
12332 case DW_TAG_module
:
12333 parent_type
= read_type_die (parent
, cu
);
12334 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12335 return TYPE_TAG_NAME (parent_type
);
12337 /* An anonymous structure is only allowed non-static data
12338 members; no typedefs, no member functions, et cetera.
12339 So it does not need a prefix. */
12341 case DW_TAG_compile_unit
:
12342 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12343 if (cu
->language
== language_cplus
12344 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12345 && die
->child
!= NULL
12346 && (die
->tag
== DW_TAG_class_type
12347 || die
->tag
== DW_TAG_structure_type
12348 || die
->tag
== DW_TAG_union_type
))
12350 char *name
= guess_full_die_structure_name (die
, cu
);
12356 return determine_prefix (parent
, cu
);
12360 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12361 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12362 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12363 an obconcat, otherwise allocate storage for the result. The CU argument is
12364 used to determine the language and hence, the appropriate separator. */
12366 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12369 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12370 int physname
, struct dwarf2_cu
*cu
)
12372 const char *lead
= "";
12375 if (suffix
== NULL
|| suffix
[0] == '\0'
12376 || prefix
== NULL
|| prefix
[0] == '\0')
12378 else if (cu
->language
== language_java
)
12380 else if (cu
->language
== language_fortran
&& physname
)
12382 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12383 DW_AT_MIPS_linkage_name is preferred and used instead. */
12391 if (prefix
== NULL
)
12393 if (suffix
== NULL
)
12399 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12401 strcpy (retval
, lead
);
12402 strcat (retval
, prefix
);
12403 strcat (retval
, sep
);
12404 strcat (retval
, suffix
);
12409 /* We have an obstack. */
12410 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12414 /* Return sibling of die, NULL if no sibling. */
12416 static struct die_info
*
12417 sibling_die (struct die_info
*die
)
12419 return die
->sibling
;
12422 /* Get name of a die, return NULL if not found. */
12425 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12426 struct obstack
*obstack
)
12428 if (name
&& cu
->language
== language_cplus
)
12430 char *canon_name
= cp_canonicalize_string (name
);
12432 if (canon_name
!= NULL
)
12434 if (strcmp (canon_name
, name
) != 0)
12435 name
= obsavestring (canon_name
, strlen (canon_name
),
12437 xfree (canon_name
);
12444 /* Get name of a die, return NULL if not found. */
12447 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12449 struct attribute
*attr
;
12451 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12452 if ((!attr
|| !DW_STRING (attr
))
12453 && die
->tag
!= DW_TAG_class_type
12454 && die
->tag
!= DW_TAG_interface_type
12455 && die
->tag
!= DW_TAG_structure_type
12456 && die
->tag
!= DW_TAG_union_type
)
12461 case DW_TAG_compile_unit
:
12462 /* Compilation units have a DW_AT_name that is a filename, not
12463 a source language identifier. */
12464 case DW_TAG_enumeration_type
:
12465 case DW_TAG_enumerator
:
12466 /* These tags always have simple identifiers already; no need
12467 to canonicalize them. */
12468 return DW_STRING (attr
);
12470 case DW_TAG_subprogram
:
12471 /* Java constructors will all be named "<init>", so return
12472 the class name when we see this special case. */
12473 if (cu
->language
== language_java
12474 && DW_STRING (attr
) != NULL
12475 && strcmp (DW_STRING (attr
), "<init>") == 0)
12477 struct dwarf2_cu
*spec_cu
= cu
;
12478 struct die_info
*spec_die
;
12480 /* GCJ will output '<init>' for Java constructor names.
12481 For this special case, return the name of the parent class. */
12483 /* GCJ may output suprogram DIEs with AT_specification set.
12484 If so, use the name of the specified DIE. */
12485 spec_die
= die_specification (die
, &spec_cu
);
12486 if (spec_die
!= NULL
)
12487 return dwarf2_name (spec_die
, spec_cu
);
12492 if (die
->tag
== DW_TAG_class_type
)
12493 return dwarf2_name (die
, cu
);
12495 while (die
->tag
!= DW_TAG_compile_unit
);
12499 case DW_TAG_class_type
:
12500 case DW_TAG_interface_type
:
12501 case DW_TAG_structure_type
:
12502 case DW_TAG_union_type
:
12503 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12504 structures or unions. These were of the form "._%d" in GCC 4.1,
12505 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12506 and GCC 4.4. We work around this problem by ignoring these. */
12507 if (attr
&& DW_STRING (attr
)
12508 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12509 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12512 /* GCC might emit a nameless typedef that has a linkage name. See
12513 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12514 if (!attr
|| DW_STRING (attr
) == NULL
)
12516 char *demangled
= NULL
;
12518 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12520 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12522 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12525 /* Avoid demangling DW_STRING (attr) the second time on a second
12526 call for the same DIE. */
12527 if (!DW_STRING_IS_CANONICAL (attr
))
12528 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12532 /* FIXME: we already did this for the partial symbol... */
12534 = obsavestring (demangled
, strlen (demangled
),
12535 &cu
->objfile
->objfile_obstack
);
12536 DW_STRING_IS_CANONICAL (attr
) = 1;
12546 if (!DW_STRING_IS_CANONICAL (attr
))
12549 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12550 &cu
->objfile
->objfile_obstack
);
12551 DW_STRING_IS_CANONICAL (attr
) = 1;
12553 return DW_STRING (attr
);
12556 /* Return the die that this die in an extension of, or NULL if there
12557 is none. *EXT_CU is the CU containing DIE on input, and the CU
12558 containing the return value on output. */
12560 static struct die_info
*
12561 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12563 struct attribute
*attr
;
12565 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12569 return follow_die_ref (die
, attr
, ext_cu
);
12572 /* Convert a DIE tag into its string name. */
12575 dwarf_tag_name (unsigned tag
)
12579 case DW_TAG_padding
:
12580 return "DW_TAG_padding";
12581 case DW_TAG_array_type
:
12582 return "DW_TAG_array_type";
12583 case DW_TAG_class_type
:
12584 return "DW_TAG_class_type";
12585 case DW_TAG_entry_point
:
12586 return "DW_TAG_entry_point";
12587 case DW_TAG_enumeration_type
:
12588 return "DW_TAG_enumeration_type";
12589 case DW_TAG_formal_parameter
:
12590 return "DW_TAG_formal_parameter";
12591 case DW_TAG_imported_declaration
:
12592 return "DW_TAG_imported_declaration";
12594 return "DW_TAG_label";
12595 case DW_TAG_lexical_block
:
12596 return "DW_TAG_lexical_block";
12597 case DW_TAG_member
:
12598 return "DW_TAG_member";
12599 case DW_TAG_pointer_type
:
12600 return "DW_TAG_pointer_type";
12601 case DW_TAG_reference_type
:
12602 return "DW_TAG_reference_type";
12603 case DW_TAG_compile_unit
:
12604 return "DW_TAG_compile_unit";
12605 case DW_TAG_string_type
:
12606 return "DW_TAG_string_type";
12607 case DW_TAG_structure_type
:
12608 return "DW_TAG_structure_type";
12609 case DW_TAG_subroutine_type
:
12610 return "DW_TAG_subroutine_type";
12611 case DW_TAG_typedef
:
12612 return "DW_TAG_typedef";
12613 case DW_TAG_union_type
:
12614 return "DW_TAG_union_type";
12615 case DW_TAG_unspecified_parameters
:
12616 return "DW_TAG_unspecified_parameters";
12617 case DW_TAG_variant
:
12618 return "DW_TAG_variant";
12619 case DW_TAG_common_block
:
12620 return "DW_TAG_common_block";
12621 case DW_TAG_common_inclusion
:
12622 return "DW_TAG_common_inclusion";
12623 case DW_TAG_inheritance
:
12624 return "DW_TAG_inheritance";
12625 case DW_TAG_inlined_subroutine
:
12626 return "DW_TAG_inlined_subroutine";
12627 case DW_TAG_module
:
12628 return "DW_TAG_module";
12629 case DW_TAG_ptr_to_member_type
:
12630 return "DW_TAG_ptr_to_member_type";
12631 case DW_TAG_set_type
:
12632 return "DW_TAG_set_type";
12633 case DW_TAG_subrange_type
:
12634 return "DW_TAG_subrange_type";
12635 case DW_TAG_with_stmt
:
12636 return "DW_TAG_with_stmt";
12637 case DW_TAG_access_declaration
:
12638 return "DW_TAG_access_declaration";
12639 case DW_TAG_base_type
:
12640 return "DW_TAG_base_type";
12641 case DW_TAG_catch_block
:
12642 return "DW_TAG_catch_block";
12643 case DW_TAG_const_type
:
12644 return "DW_TAG_const_type";
12645 case DW_TAG_constant
:
12646 return "DW_TAG_constant";
12647 case DW_TAG_enumerator
:
12648 return "DW_TAG_enumerator";
12649 case DW_TAG_file_type
:
12650 return "DW_TAG_file_type";
12651 case DW_TAG_friend
:
12652 return "DW_TAG_friend";
12653 case DW_TAG_namelist
:
12654 return "DW_TAG_namelist";
12655 case DW_TAG_namelist_item
:
12656 return "DW_TAG_namelist_item";
12657 case DW_TAG_packed_type
:
12658 return "DW_TAG_packed_type";
12659 case DW_TAG_subprogram
:
12660 return "DW_TAG_subprogram";
12661 case DW_TAG_template_type_param
:
12662 return "DW_TAG_template_type_param";
12663 case DW_TAG_template_value_param
:
12664 return "DW_TAG_template_value_param";
12665 case DW_TAG_thrown_type
:
12666 return "DW_TAG_thrown_type";
12667 case DW_TAG_try_block
:
12668 return "DW_TAG_try_block";
12669 case DW_TAG_variant_part
:
12670 return "DW_TAG_variant_part";
12671 case DW_TAG_variable
:
12672 return "DW_TAG_variable";
12673 case DW_TAG_volatile_type
:
12674 return "DW_TAG_volatile_type";
12675 case DW_TAG_dwarf_procedure
:
12676 return "DW_TAG_dwarf_procedure";
12677 case DW_TAG_restrict_type
:
12678 return "DW_TAG_restrict_type";
12679 case DW_TAG_interface_type
:
12680 return "DW_TAG_interface_type";
12681 case DW_TAG_namespace
:
12682 return "DW_TAG_namespace";
12683 case DW_TAG_imported_module
:
12684 return "DW_TAG_imported_module";
12685 case DW_TAG_unspecified_type
:
12686 return "DW_TAG_unspecified_type";
12687 case DW_TAG_partial_unit
:
12688 return "DW_TAG_partial_unit";
12689 case DW_TAG_imported_unit
:
12690 return "DW_TAG_imported_unit";
12691 case DW_TAG_condition
:
12692 return "DW_TAG_condition";
12693 case DW_TAG_shared_type
:
12694 return "DW_TAG_shared_type";
12695 case DW_TAG_type_unit
:
12696 return "DW_TAG_type_unit";
12697 case DW_TAG_MIPS_loop
:
12698 return "DW_TAG_MIPS_loop";
12699 case DW_TAG_HP_array_descriptor
:
12700 return "DW_TAG_HP_array_descriptor";
12701 case DW_TAG_format_label
:
12702 return "DW_TAG_format_label";
12703 case DW_TAG_function_template
:
12704 return "DW_TAG_function_template";
12705 case DW_TAG_class_template
:
12706 return "DW_TAG_class_template";
12707 case DW_TAG_GNU_BINCL
:
12708 return "DW_TAG_GNU_BINCL";
12709 case DW_TAG_GNU_EINCL
:
12710 return "DW_TAG_GNU_EINCL";
12711 case DW_TAG_upc_shared_type
:
12712 return "DW_TAG_upc_shared_type";
12713 case DW_TAG_upc_strict_type
:
12714 return "DW_TAG_upc_strict_type";
12715 case DW_TAG_upc_relaxed_type
:
12716 return "DW_TAG_upc_relaxed_type";
12717 case DW_TAG_PGI_kanji_type
:
12718 return "DW_TAG_PGI_kanji_type";
12719 case DW_TAG_PGI_interface_block
:
12720 return "DW_TAG_PGI_interface_block";
12722 return "DW_TAG_<unknown>";
12726 /* Convert a DWARF attribute code into its string name. */
12729 dwarf_attr_name (unsigned attr
)
12733 case DW_AT_sibling
:
12734 return "DW_AT_sibling";
12735 case DW_AT_location
:
12736 return "DW_AT_location";
12738 return "DW_AT_name";
12739 case DW_AT_ordering
:
12740 return "DW_AT_ordering";
12741 case DW_AT_subscr_data
:
12742 return "DW_AT_subscr_data";
12743 case DW_AT_byte_size
:
12744 return "DW_AT_byte_size";
12745 case DW_AT_bit_offset
:
12746 return "DW_AT_bit_offset";
12747 case DW_AT_bit_size
:
12748 return "DW_AT_bit_size";
12749 case DW_AT_element_list
:
12750 return "DW_AT_element_list";
12751 case DW_AT_stmt_list
:
12752 return "DW_AT_stmt_list";
12754 return "DW_AT_low_pc";
12755 case DW_AT_high_pc
:
12756 return "DW_AT_high_pc";
12757 case DW_AT_language
:
12758 return "DW_AT_language";
12760 return "DW_AT_member";
12762 return "DW_AT_discr";
12763 case DW_AT_discr_value
:
12764 return "DW_AT_discr_value";
12765 case DW_AT_visibility
:
12766 return "DW_AT_visibility";
12768 return "DW_AT_import";
12769 case DW_AT_string_length
:
12770 return "DW_AT_string_length";
12771 case DW_AT_common_reference
:
12772 return "DW_AT_common_reference";
12773 case DW_AT_comp_dir
:
12774 return "DW_AT_comp_dir";
12775 case DW_AT_const_value
:
12776 return "DW_AT_const_value";
12777 case DW_AT_containing_type
:
12778 return "DW_AT_containing_type";
12779 case DW_AT_default_value
:
12780 return "DW_AT_default_value";
12782 return "DW_AT_inline";
12783 case DW_AT_is_optional
:
12784 return "DW_AT_is_optional";
12785 case DW_AT_lower_bound
:
12786 return "DW_AT_lower_bound";
12787 case DW_AT_producer
:
12788 return "DW_AT_producer";
12789 case DW_AT_prototyped
:
12790 return "DW_AT_prototyped";
12791 case DW_AT_return_addr
:
12792 return "DW_AT_return_addr";
12793 case DW_AT_start_scope
:
12794 return "DW_AT_start_scope";
12795 case DW_AT_bit_stride
:
12796 return "DW_AT_bit_stride";
12797 case DW_AT_upper_bound
:
12798 return "DW_AT_upper_bound";
12799 case DW_AT_abstract_origin
:
12800 return "DW_AT_abstract_origin";
12801 case DW_AT_accessibility
:
12802 return "DW_AT_accessibility";
12803 case DW_AT_address_class
:
12804 return "DW_AT_address_class";
12805 case DW_AT_artificial
:
12806 return "DW_AT_artificial";
12807 case DW_AT_base_types
:
12808 return "DW_AT_base_types";
12809 case DW_AT_calling_convention
:
12810 return "DW_AT_calling_convention";
12812 return "DW_AT_count";
12813 case DW_AT_data_member_location
:
12814 return "DW_AT_data_member_location";
12815 case DW_AT_decl_column
:
12816 return "DW_AT_decl_column";
12817 case DW_AT_decl_file
:
12818 return "DW_AT_decl_file";
12819 case DW_AT_decl_line
:
12820 return "DW_AT_decl_line";
12821 case DW_AT_declaration
:
12822 return "DW_AT_declaration";
12823 case DW_AT_discr_list
:
12824 return "DW_AT_discr_list";
12825 case DW_AT_encoding
:
12826 return "DW_AT_encoding";
12827 case DW_AT_external
:
12828 return "DW_AT_external";
12829 case DW_AT_frame_base
:
12830 return "DW_AT_frame_base";
12832 return "DW_AT_friend";
12833 case DW_AT_identifier_case
:
12834 return "DW_AT_identifier_case";
12835 case DW_AT_macro_info
:
12836 return "DW_AT_macro_info";
12837 case DW_AT_namelist_items
:
12838 return "DW_AT_namelist_items";
12839 case DW_AT_priority
:
12840 return "DW_AT_priority";
12841 case DW_AT_segment
:
12842 return "DW_AT_segment";
12843 case DW_AT_specification
:
12844 return "DW_AT_specification";
12845 case DW_AT_static_link
:
12846 return "DW_AT_static_link";
12848 return "DW_AT_type";
12849 case DW_AT_use_location
:
12850 return "DW_AT_use_location";
12851 case DW_AT_variable_parameter
:
12852 return "DW_AT_variable_parameter";
12853 case DW_AT_virtuality
:
12854 return "DW_AT_virtuality";
12855 case DW_AT_vtable_elem_location
:
12856 return "DW_AT_vtable_elem_location";
12857 /* DWARF 3 values. */
12858 case DW_AT_allocated
:
12859 return "DW_AT_allocated";
12860 case DW_AT_associated
:
12861 return "DW_AT_associated";
12862 case DW_AT_data_location
:
12863 return "DW_AT_data_location";
12864 case DW_AT_byte_stride
:
12865 return "DW_AT_byte_stride";
12866 case DW_AT_entry_pc
:
12867 return "DW_AT_entry_pc";
12868 case DW_AT_use_UTF8
:
12869 return "DW_AT_use_UTF8";
12870 case DW_AT_extension
:
12871 return "DW_AT_extension";
12873 return "DW_AT_ranges";
12874 case DW_AT_trampoline
:
12875 return "DW_AT_trampoline";
12876 case DW_AT_call_column
:
12877 return "DW_AT_call_column";
12878 case DW_AT_call_file
:
12879 return "DW_AT_call_file";
12880 case DW_AT_call_line
:
12881 return "DW_AT_call_line";
12882 case DW_AT_description
:
12883 return "DW_AT_description";
12884 case DW_AT_binary_scale
:
12885 return "DW_AT_binary_scale";
12886 case DW_AT_decimal_scale
:
12887 return "DW_AT_decimal_scale";
12889 return "DW_AT_small";
12890 case DW_AT_decimal_sign
:
12891 return "DW_AT_decimal_sign";
12892 case DW_AT_digit_count
:
12893 return "DW_AT_digit_count";
12894 case DW_AT_picture_string
:
12895 return "DW_AT_picture_string";
12896 case DW_AT_mutable
:
12897 return "DW_AT_mutable";
12898 case DW_AT_threads_scaled
:
12899 return "DW_AT_threads_scaled";
12900 case DW_AT_explicit
:
12901 return "DW_AT_explicit";
12902 case DW_AT_object_pointer
:
12903 return "DW_AT_object_pointer";
12904 case DW_AT_endianity
:
12905 return "DW_AT_endianity";
12906 case DW_AT_elemental
:
12907 return "DW_AT_elemental";
12909 return "DW_AT_pure";
12910 case DW_AT_recursive
:
12911 return "DW_AT_recursive";
12912 /* DWARF 4 values. */
12913 case DW_AT_signature
:
12914 return "DW_AT_signature";
12915 case DW_AT_linkage_name
:
12916 return "DW_AT_linkage_name";
12917 /* SGI/MIPS extensions. */
12918 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12919 case DW_AT_MIPS_fde
:
12920 return "DW_AT_MIPS_fde";
12922 case DW_AT_MIPS_loop_begin
:
12923 return "DW_AT_MIPS_loop_begin";
12924 case DW_AT_MIPS_tail_loop_begin
:
12925 return "DW_AT_MIPS_tail_loop_begin";
12926 case DW_AT_MIPS_epilog_begin
:
12927 return "DW_AT_MIPS_epilog_begin";
12928 case DW_AT_MIPS_loop_unroll_factor
:
12929 return "DW_AT_MIPS_loop_unroll_factor";
12930 case DW_AT_MIPS_software_pipeline_depth
:
12931 return "DW_AT_MIPS_software_pipeline_depth";
12932 case DW_AT_MIPS_linkage_name
:
12933 return "DW_AT_MIPS_linkage_name";
12934 case DW_AT_MIPS_stride
:
12935 return "DW_AT_MIPS_stride";
12936 case DW_AT_MIPS_abstract_name
:
12937 return "DW_AT_MIPS_abstract_name";
12938 case DW_AT_MIPS_clone_origin
:
12939 return "DW_AT_MIPS_clone_origin";
12940 case DW_AT_MIPS_has_inlines
:
12941 return "DW_AT_MIPS_has_inlines";
12942 /* HP extensions. */
12943 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12944 case DW_AT_HP_block_index
:
12945 return "DW_AT_HP_block_index";
12947 case DW_AT_HP_unmodifiable
:
12948 return "DW_AT_HP_unmodifiable";
12949 case DW_AT_HP_actuals_stmt_list
:
12950 return "DW_AT_HP_actuals_stmt_list";
12951 case DW_AT_HP_proc_per_section
:
12952 return "DW_AT_HP_proc_per_section";
12953 case DW_AT_HP_raw_data_ptr
:
12954 return "DW_AT_HP_raw_data_ptr";
12955 case DW_AT_HP_pass_by_reference
:
12956 return "DW_AT_HP_pass_by_reference";
12957 case DW_AT_HP_opt_level
:
12958 return "DW_AT_HP_opt_level";
12959 case DW_AT_HP_prof_version_id
:
12960 return "DW_AT_HP_prof_version_id";
12961 case DW_AT_HP_opt_flags
:
12962 return "DW_AT_HP_opt_flags";
12963 case DW_AT_HP_cold_region_low_pc
:
12964 return "DW_AT_HP_cold_region_low_pc";
12965 case DW_AT_HP_cold_region_high_pc
:
12966 return "DW_AT_HP_cold_region_high_pc";
12967 case DW_AT_HP_all_variables_modifiable
:
12968 return "DW_AT_HP_all_variables_modifiable";
12969 case DW_AT_HP_linkage_name
:
12970 return "DW_AT_HP_linkage_name";
12971 case DW_AT_HP_prof_flags
:
12972 return "DW_AT_HP_prof_flags";
12973 /* GNU extensions. */
12974 case DW_AT_sf_names
:
12975 return "DW_AT_sf_names";
12976 case DW_AT_src_info
:
12977 return "DW_AT_src_info";
12978 case DW_AT_mac_info
:
12979 return "DW_AT_mac_info";
12980 case DW_AT_src_coords
:
12981 return "DW_AT_src_coords";
12982 case DW_AT_body_begin
:
12983 return "DW_AT_body_begin";
12984 case DW_AT_body_end
:
12985 return "DW_AT_body_end";
12986 case DW_AT_GNU_vector
:
12987 return "DW_AT_GNU_vector";
12988 case DW_AT_GNU_odr_signature
:
12989 return "DW_AT_GNU_odr_signature";
12990 /* VMS extensions. */
12991 case DW_AT_VMS_rtnbeg_pd_address
:
12992 return "DW_AT_VMS_rtnbeg_pd_address";
12993 /* UPC extension. */
12994 case DW_AT_upc_threads_scaled
:
12995 return "DW_AT_upc_threads_scaled";
12996 /* PGI (STMicroelectronics) extensions. */
12997 case DW_AT_PGI_lbase
:
12998 return "DW_AT_PGI_lbase";
12999 case DW_AT_PGI_soffset
:
13000 return "DW_AT_PGI_soffset";
13001 case DW_AT_PGI_lstride
:
13002 return "DW_AT_PGI_lstride";
13004 return "DW_AT_<unknown>";
13008 /* Convert a DWARF value form code into its string name. */
13011 dwarf_form_name (unsigned form
)
13016 return "DW_FORM_addr";
13017 case DW_FORM_block2
:
13018 return "DW_FORM_block2";
13019 case DW_FORM_block4
:
13020 return "DW_FORM_block4";
13021 case DW_FORM_data2
:
13022 return "DW_FORM_data2";
13023 case DW_FORM_data4
:
13024 return "DW_FORM_data4";
13025 case DW_FORM_data8
:
13026 return "DW_FORM_data8";
13027 case DW_FORM_string
:
13028 return "DW_FORM_string";
13029 case DW_FORM_block
:
13030 return "DW_FORM_block";
13031 case DW_FORM_block1
:
13032 return "DW_FORM_block1";
13033 case DW_FORM_data1
:
13034 return "DW_FORM_data1";
13036 return "DW_FORM_flag";
13037 case DW_FORM_sdata
:
13038 return "DW_FORM_sdata";
13040 return "DW_FORM_strp";
13041 case DW_FORM_udata
:
13042 return "DW_FORM_udata";
13043 case DW_FORM_ref_addr
:
13044 return "DW_FORM_ref_addr";
13046 return "DW_FORM_ref1";
13048 return "DW_FORM_ref2";
13050 return "DW_FORM_ref4";
13052 return "DW_FORM_ref8";
13053 case DW_FORM_ref_udata
:
13054 return "DW_FORM_ref_udata";
13055 case DW_FORM_indirect
:
13056 return "DW_FORM_indirect";
13057 case DW_FORM_sec_offset
:
13058 return "DW_FORM_sec_offset";
13059 case DW_FORM_exprloc
:
13060 return "DW_FORM_exprloc";
13061 case DW_FORM_flag_present
:
13062 return "DW_FORM_flag_present";
13063 case DW_FORM_ref_sig8
:
13064 return "DW_FORM_ref_sig8";
13066 return "DW_FORM_<unknown>";
13070 /* Convert a DWARF stack opcode into its string name. */
13073 dwarf_stack_op_name (unsigned op
)
13078 return "DW_OP_addr";
13080 return "DW_OP_deref";
13081 case DW_OP_const1u
:
13082 return "DW_OP_const1u";
13083 case DW_OP_const1s
:
13084 return "DW_OP_const1s";
13085 case DW_OP_const2u
:
13086 return "DW_OP_const2u";
13087 case DW_OP_const2s
:
13088 return "DW_OP_const2s";
13089 case DW_OP_const4u
:
13090 return "DW_OP_const4u";
13091 case DW_OP_const4s
:
13092 return "DW_OP_const4s";
13093 case DW_OP_const8u
:
13094 return "DW_OP_const8u";
13095 case DW_OP_const8s
:
13096 return "DW_OP_const8s";
13098 return "DW_OP_constu";
13100 return "DW_OP_consts";
13102 return "DW_OP_dup";
13104 return "DW_OP_drop";
13106 return "DW_OP_over";
13108 return "DW_OP_pick";
13110 return "DW_OP_swap";
13112 return "DW_OP_rot";
13114 return "DW_OP_xderef";
13116 return "DW_OP_abs";
13118 return "DW_OP_and";
13120 return "DW_OP_div";
13122 return "DW_OP_minus";
13124 return "DW_OP_mod";
13126 return "DW_OP_mul";
13128 return "DW_OP_neg";
13130 return "DW_OP_not";
13134 return "DW_OP_plus";
13135 case DW_OP_plus_uconst
:
13136 return "DW_OP_plus_uconst";
13138 return "DW_OP_shl";
13140 return "DW_OP_shr";
13142 return "DW_OP_shra";
13144 return "DW_OP_xor";
13146 return "DW_OP_bra";
13160 return "DW_OP_skip";
13162 return "DW_OP_lit0";
13164 return "DW_OP_lit1";
13166 return "DW_OP_lit2";
13168 return "DW_OP_lit3";
13170 return "DW_OP_lit4";
13172 return "DW_OP_lit5";
13174 return "DW_OP_lit6";
13176 return "DW_OP_lit7";
13178 return "DW_OP_lit8";
13180 return "DW_OP_lit9";
13182 return "DW_OP_lit10";
13184 return "DW_OP_lit11";
13186 return "DW_OP_lit12";
13188 return "DW_OP_lit13";
13190 return "DW_OP_lit14";
13192 return "DW_OP_lit15";
13194 return "DW_OP_lit16";
13196 return "DW_OP_lit17";
13198 return "DW_OP_lit18";
13200 return "DW_OP_lit19";
13202 return "DW_OP_lit20";
13204 return "DW_OP_lit21";
13206 return "DW_OP_lit22";
13208 return "DW_OP_lit23";
13210 return "DW_OP_lit24";
13212 return "DW_OP_lit25";
13214 return "DW_OP_lit26";
13216 return "DW_OP_lit27";
13218 return "DW_OP_lit28";
13220 return "DW_OP_lit29";
13222 return "DW_OP_lit30";
13224 return "DW_OP_lit31";
13226 return "DW_OP_reg0";
13228 return "DW_OP_reg1";
13230 return "DW_OP_reg2";
13232 return "DW_OP_reg3";
13234 return "DW_OP_reg4";
13236 return "DW_OP_reg5";
13238 return "DW_OP_reg6";
13240 return "DW_OP_reg7";
13242 return "DW_OP_reg8";
13244 return "DW_OP_reg9";
13246 return "DW_OP_reg10";
13248 return "DW_OP_reg11";
13250 return "DW_OP_reg12";
13252 return "DW_OP_reg13";
13254 return "DW_OP_reg14";
13256 return "DW_OP_reg15";
13258 return "DW_OP_reg16";
13260 return "DW_OP_reg17";
13262 return "DW_OP_reg18";
13264 return "DW_OP_reg19";
13266 return "DW_OP_reg20";
13268 return "DW_OP_reg21";
13270 return "DW_OP_reg22";
13272 return "DW_OP_reg23";
13274 return "DW_OP_reg24";
13276 return "DW_OP_reg25";
13278 return "DW_OP_reg26";
13280 return "DW_OP_reg27";
13282 return "DW_OP_reg28";
13284 return "DW_OP_reg29";
13286 return "DW_OP_reg30";
13288 return "DW_OP_reg31";
13290 return "DW_OP_breg0";
13292 return "DW_OP_breg1";
13294 return "DW_OP_breg2";
13296 return "DW_OP_breg3";
13298 return "DW_OP_breg4";
13300 return "DW_OP_breg5";
13302 return "DW_OP_breg6";
13304 return "DW_OP_breg7";
13306 return "DW_OP_breg8";
13308 return "DW_OP_breg9";
13310 return "DW_OP_breg10";
13312 return "DW_OP_breg11";
13314 return "DW_OP_breg12";
13316 return "DW_OP_breg13";
13318 return "DW_OP_breg14";
13320 return "DW_OP_breg15";
13322 return "DW_OP_breg16";
13324 return "DW_OP_breg17";
13326 return "DW_OP_breg18";
13328 return "DW_OP_breg19";
13330 return "DW_OP_breg20";
13332 return "DW_OP_breg21";
13334 return "DW_OP_breg22";
13336 return "DW_OP_breg23";
13338 return "DW_OP_breg24";
13340 return "DW_OP_breg25";
13342 return "DW_OP_breg26";
13344 return "DW_OP_breg27";
13346 return "DW_OP_breg28";
13348 return "DW_OP_breg29";
13350 return "DW_OP_breg30";
13352 return "DW_OP_breg31";
13354 return "DW_OP_regx";
13356 return "DW_OP_fbreg";
13358 return "DW_OP_bregx";
13360 return "DW_OP_piece";
13361 case DW_OP_deref_size
:
13362 return "DW_OP_deref_size";
13363 case DW_OP_xderef_size
:
13364 return "DW_OP_xderef_size";
13366 return "DW_OP_nop";
13367 /* DWARF 3 extensions. */
13368 case DW_OP_push_object_address
:
13369 return "DW_OP_push_object_address";
13371 return "DW_OP_call2";
13373 return "DW_OP_call4";
13374 case DW_OP_call_ref
:
13375 return "DW_OP_call_ref";
13376 case DW_OP_form_tls_address
:
13377 return "DW_OP_form_tls_address";
13378 case DW_OP_call_frame_cfa
:
13379 return "DW_OP_call_frame_cfa";
13380 case DW_OP_bit_piece
:
13381 return "DW_OP_bit_piece";
13382 /* DWARF 4 extensions. */
13383 case DW_OP_implicit_value
:
13384 return "DW_OP_implicit_value";
13385 case DW_OP_stack_value
:
13386 return "DW_OP_stack_value";
13387 /* GNU extensions. */
13388 case DW_OP_GNU_push_tls_address
:
13389 return "DW_OP_GNU_push_tls_address";
13390 case DW_OP_GNU_uninit
:
13391 return "DW_OP_GNU_uninit";
13392 case DW_OP_GNU_implicit_pointer
:
13393 return "DW_OP_GNU_implicit_pointer";
13394 case DW_OP_GNU_entry_value
:
13395 return "DW_OP_GNU_entry_value";
13396 case DW_OP_GNU_const_type
:
13397 return "DW_OP_GNU_const_type";
13398 case DW_OP_GNU_regval_type
:
13399 return "DW_OP_GNU_regval_type";
13400 case DW_OP_GNU_deref_type
:
13401 return "DW_OP_GNU_deref_type";
13402 case DW_OP_GNU_convert
:
13403 return "DW_OP_GNU_convert";
13404 case DW_OP_GNU_reinterpret
:
13405 return "DW_OP_GNU_reinterpret";
13412 dwarf_bool_name (unsigned mybool
)
13420 /* Convert a DWARF type code into its string name. */
13423 dwarf_type_encoding_name (unsigned enc
)
13428 return "DW_ATE_void";
13429 case DW_ATE_address
:
13430 return "DW_ATE_address";
13431 case DW_ATE_boolean
:
13432 return "DW_ATE_boolean";
13433 case DW_ATE_complex_float
:
13434 return "DW_ATE_complex_float";
13436 return "DW_ATE_float";
13437 case DW_ATE_signed
:
13438 return "DW_ATE_signed";
13439 case DW_ATE_signed_char
:
13440 return "DW_ATE_signed_char";
13441 case DW_ATE_unsigned
:
13442 return "DW_ATE_unsigned";
13443 case DW_ATE_unsigned_char
:
13444 return "DW_ATE_unsigned_char";
13446 case DW_ATE_imaginary_float
:
13447 return "DW_ATE_imaginary_float";
13448 case DW_ATE_packed_decimal
:
13449 return "DW_ATE_packed_decimal";
13450 case DW_ATE_numeric_string
:
13451 return "DW_ATE_numeric_string";
13452 case DW_ATE_edited
:
13453 return "DW_ATE_edited";
13454 case DW_ATE_signed_fixed
:
13455 return "DW_ATE_signed_fixed";
13456 case DW_ATE_unsigned_fixed
:
13457 return "DW_ATE_unsigned_fixed";
13458 case DW_ATE_decimal_float
:
13459 return "DW_ATE_decimal_float";
13462 return "DW_ATE_UTF";
13463 /* HP extensions. */
13464 case DW_ATE_HP_float80
:
13465 return "DW_ATE_HP_float80";
13466 case DW_ATE_HP_complex_float80
:
13467 return "DW_ATE_HP_complex_float80";
13468 case DW_ATE_HP_float128
:
13469 return "DW_ATE_HP_float128";
13470 case DW_ATE_HP_complex_float128
:
13471 return "DW_ATE_HP_complex_float128";
13472 case DW_ATE_HP_floathpintel
:
13473 return "DW_ATE_HP_floathpintel";
13474 case DW_ATE_HP_imaginary_float80
:
13475 return "DW_ATE_HP_imaginary_float80";
13476 case DW_ATE_HP_imaginary_float128
:
13477 return "DW_ATE_HP_imaginary_float128";
13479 return "DW_ATE_<unknown>";
13483 /* Convert a DWARF call frame info operation to its string name. */
13487 dwarf_cfi_name (unsigned cfi_opc
)
13491 case DW_CFA_advance_loc
:
13492 return "DW_CFA_advance_loc";
13493 case DW_CFA_offset
:
13494 return "DW_CFA_offset";
13495 case DW_CFA_restore
:
13496 return "DW_CFA_restore";
13498 return "DW_CFA_nop";
13499 case DW_CFA_set_loc
:
13500 return "DW_CFA_set_loc";
13501 case DW_CFA_advance_loc1
:
13502 return "DW_CFA_advance_loc1";
13503 case DW_CFA_advance_loc2
:
13504 return "DW_CFA_advance_loc2";
13505 case DW_CFA_advance_loc4
:
13506 return "DW_CFA_advance_loc4";
13507 case DW_CFA_offset_extended
:
13508 return "DW_CFA_offset_extended";
13509 case DW_CFA_restore_extended
:
13510 return "DW_CFA_restore_extended";
13511 case DW_CFA_undefined
:
13512 return "DW_CFA_undefined";
13513 case DW_CFA_same_value
:
13514 return "DW_CFA_same_value";
13515 case DW_CFA_register
:
13516 return "DW_CFA_register";
13517 case DW_CFA_remember_state
:
13518 return "DW_CFA_remember_state";
13519 case DW_CFA_restore_state
:
13520 return "DW_CFA_restore_state";
13521 case DW_CFA_def_cfa
:
13522 return "DW_CFA_def_cfa";
13523 case DW_CFA_def_cfa_register
:
13524 return "DW_CFA_def_cfa_register";
13525 case DW_CFA_def_cfa_offset
:
13526 return "DW_CFA_def_cfa_offset";
13528 case DW_CFA_def_cfa_expression
:
13529 return "DW_CFA_def_cfa_expression";
13530 case DW_CFA_expression
:
13531 return "DW_CFA_expression";
13532 case DW_CFA_offset_extended_sf
:
13533 return "DW_CFA_offset_extended_sf";
13534 case DW_CFA_def_cfa_sf
:
13535 return "DW_CFA_def_cfa_sf";
13536 case DW_CFA_def_cfa_offset_sf
:
13537 return "DW_CFA_def_cfa_offset_sf";
13538 case DW_CFA_val_offset
:
13539 return "DW_CFA_val_offset";
13540 case DW_CFA_val_offset_sf
:
13541 return "DW_CFA_val_offset_sf";
13542 case DW_CFA_val_expression
:
13543 return "DW_CFA_val_expression";
13544 /* SGI/MIPS specific. */
13545 case DW_CFA_MIPS_advance_loc8
:
13546 return "DW_CFA_MIPS_advance_loc8";
13547 /* GNU extensions. */
13548 case DW_CFA_GNU_window_save
:
13549 return "DW_CFA_GNU_window_save";
13550 case DW_CFA_GNU_args_size
:
13551 return "DW_CFA_GNU_args_size";
13552 case DW_CFA_GNU_negative_offset_extended
:
13553 return "DW_CFA_GNU_negative_offset_extended";
13555 return "DW_CFA_<unknown>";
13561 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13565 print_spaces (indent
, f
);
13566 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13567 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13569 if (die
->parent
!= NULL
)
13571 print_spaces (indent
, f
);
13572 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13573 die
->parent
->offset
);
13576 print_spaces (indent
, f
);
13577 fprintf_unfiltered (f
, " has children: %s\n",
13578 dwarf_bool_name (die
->child
!= NULL
));
13580 print_spaces (indent
, f
);
13581 fprintf_unfiltered (f
, " attributes:\n");
13583 for (i
= 0; i
< die
->num_attrs
; ++i
)
13585 print_spaces (indent
, f
);
13586 fprintf_unfiltered (f
, " %s (%s) ",
13587 dwarf_attr_name (die
->attrs
[i
].name
),
13588 dwarf_form_name (die
->attrs
[i
].form
));
13590 switch (die
->attrs
[i
].form
)
13592 case DW_FORM_ref_addr
:
13594 fprintf_unfiltered (f
, "address: ");
13595 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13597 case DW_FORM_block2
:
13598 case DW_FORM_block4
:
13599 case DW_FORM_block
:
13600 case DW_FORM_block1
:
13601 fprintf_unfiltered (f
, "block: size %d",
13602 DW_BLOCK (&die
->attrs
[i
])->size
);
13604 case DW_FORM_exprloc
:
13605 fprintf_unfiltered (f
, "expression: size %u",
13606 DW_BLOCK (&die
->attrs
[i
])->size
);
13611 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13612 (long) (DW_ADDR (&die
->attrs
[i
])));
13614 case DW_FORM_data1
:
13615 case DW_FORM_data2
:
13616 case DW_FORM_data4
:
13617 case DW_FORM_data8
:
13618 case DW_FORM_udata
:
13619 case DW_FORM_sdata
:
13620 fprintf_unfiltered (f
, "constant: %s",
13621 pulongest (DW_UNSND (&die
->attrs
[i
])));
13623 case DW_FORM_sec_offset
:
13624 fprintf_unfiltered (f
, "section offset: %s",
13625 pulongest (DW_UNSND (&die
->attrs
[i
])));
13627 case DW_FORM_ref_sig8
:
13628 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13629 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13630 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
);
13632 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13634 case DW_FORM_string
:
13636 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13637 DW_STRING (&die
->attrs
[i
])
13638 ? DW_STRING (&die
->attrs
[i
]) : "",
13639 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13642 if (DW_UNSND (&die
->attrs
[i
]))
13643 fprintf_unfiltered (f
, "flag: TRUE");
13645 fprintf_unfiltered (f
, "flag: FALSE");
13647 case DW_FORM_flag_present
:
13648 fprintf_unfiltered (f
, "flag: TRUE");
13650 case DW_FORM_indirect
:
13651 /* The reader will have reduced the indirect form to
13652 the "base form" so this form should not occur. */
13653 fprintf_unfiltered (f
,
13654 "unexpected attribute form: DW_FORM_indirect");
13657 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13658 die
->attrs
[i
].form
);
13661 fprintf_unfiltered (f
, "\n");
13666 dump_die_for_error (struct die_info
*die
)
13668 dump_die_shallow (gdb_stderr
, 0, die
);
13672 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13674 int indent
= level
* 4;
13676 gdb_assert (die
!= NULL
);
13678 if (level
>= max_level
)
13681 dump_die_shallow (f
, indent
, die
);
13683 if (die
->child
!= NULL
)
13685 print_spaces (indent
, f
);
13686 fprintf_unfiltered (f
, " Children:");
13687 if (level
+ 1 < max_level
)
13689 fprintf_unfiltered (f
, "\n");
13690 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13694 fprintf_unfiltered (f
,
13695 " [not printed, max nesting level reached]\n");
13699 if (die
->sibling
!= NULL
&& level
> 0)
13701 dump_die_1 (f
, level
, max_level
, die
->sibling
);
13705 /* This is called from the pdie macro in gdbinit.in.
13706 It's not static so gcc will keep a copy callable from gdb. */
13709 dump_die (struct die_info
*die
, int max_level
)
13711 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
13715 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
13719 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
13725 is_ref_attr (struct attribute
*attr
)
13727 switch (attr
->form
)
13729 case DW_FORM_ref_addr
:
13734 case DW_FORM_ref_udata
:
13741 static unsigned int
13742 dwarf2_get_ref_die_offset (struct attribute
*attr
)
13744 if (is_ref_attr (attr
))
13745 return DW_ADDR (attr
);
13747 complaint (&symfile_complaints
,
13748 _("unsupported die ref attribute form: '%s'"),
13749 dwarf_form_name (attr
->form
));
13753 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13754 * the value held by the attribute is not constant. */
13757 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
13759 if (attr
->form
== DW_FORM_sdata
)
13760 return DW_SND (attr
);
13761 else if (attr
->form
== DW_FORM_udata
13762 || attr
->form
== DW_FORM_data1
13763 || attr
->form
== DW_FORM_data2
13764 || attr
->form
== DW_FORM_data4
13765 || attr
->form
== DW_FORM_data8
)
13766 return DW_UNSND (attr
);
13769 complaint (&symfile_complaints
,
13770 _("Attribute value is not a constant (%s)"),
13771 dwarf_form_name (attr
->form
));
13772 return default_value
;
13776 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13777 unit and add it to our queue.
13778 The result is non-zero if PER_CU was queued, otherwise the result is zero
13779 meaning either PER_CU is already queued or it is already loaded. */
13782 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
13783 struct dwarf2_per_cu_data
*per_cu
)
13785 /* We may arrive here during partial symbol reading, if we need full
13786 DIEs to process an unusual case (e.g. template arguments). Do
13787 not queue PER_CU, just tell our caller to load its DIEs. */
13788 if (dwarf2_per_objfile
->reading_partial_symbols
)
13790 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
13795 /* Mark the dependence relation so that we don't flush PER_CU
13797 dwarf2_add_dependence (this_cu
, per_cu
);
13799 /* If it's already on the queue, we have nothing to do. */
13800 if (per_cu
->queued
)
13803 /* If the compilation unit is already loaded, just mark it as
13805 if (per_cu
->cu
!= NULL
)
13807 per_cu
->cu
->last_used
= 0;
13811 /* Add it to the queue. */
13812 queue_comp_unit (per_cu
, this_cu
->objfile
);
13817 /* Follow reference or signature attribute ATTR of SRC_DIE.
13818 On entry *REF_CU is the CU of SRC_DIE.
13819 On exit *REF_CU is the CU of the result. */
13821 static struct die_info
*
13822 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
13823 struct dwarf2_cu
**ref_cu
)
13825 struct die_info
*die
;
13827 if (is_ref_attr (attr
))
13828 die
= follow_die_ref (src_die
, attr
, ref_cu
);
13829 else if (attr
->form
== DW_FORM_ref_sig8
)
13830 die
= follow_die_sig (src_die
, attr
, ref_cu
);
13833 dump_die_for_error (src_die
);
13834 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13835 (*ref_cu
)->objfile
->name
);
13841 /* Follow reference OFFSET.
13842 On entry *REF_CU is the CU of the source die referencing OFFSET.
13843 On exit *REF_CU is the CU of the result.
13844 Returns NULL if OFFSET is invalid. */
13846 static struct die_info
*
13847 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
13849 struct die_info temp_die
;
13850 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
13852 gdb_assert (cu
->per_cu
!= NULL
);
13856 if (cu
->per_cu
->debug_type_section
)
13858 /* .debug_types CUs cannot reference anything outside their CU.
13859 If they need to, they have to reference a signatured type via
13860 DW_FORM_ref_sig8. */
13861 if (! offset_in_cu_p (&cu
->header
, offset
))
13864 else if (! offset_in_cu_p (&cu
->header
, offset
))
13866 struct dwarf2_per_cu_data
*per_cu
;
13868 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
13870 /* If necessary, add it to the queue and load its DIEs. */
13871 if (maybe_queue_comp_unit (cu
, per_cu
))
13872 load_full_comp_unit (per_cu
, cu
->objfile
);
13874 target_cu
= per_cu
->cu
;
13876 else if (cu
->dies
== NULL
)
13878 /* We're loading full DIEs during partial symbol reading. */
13879 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
13880 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
13883 *ref_cu
= target_cu
;
13884 temp_die
.offset
= offset
;
13885 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13888 /* Follow reference attribute ATTR of SRC_DIE.
13889 On entry *REF_CU is the CU of SRC_DIE.
13890 On exit *REF_CU is the CU of the result. */
13892 static struct die_info
*
13893 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13894 struct dwarf2_cu
**ref_cu
)
13896 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13897 struct dwarf2_cu
*cu
= *ref_cu
;
13898 struct die_info
*die
;
13900 die
= follow_die_offset (offset
, ref_cu
);
13902 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13903 "at 0x%x [in module %s]"),
13904 offset
, src_die
->offset
, cu
->objfile
->name
);
13909 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13910 value is intended for DW_OP_call*. You must call xfree on returned
13911 dwarf2_locexpr_baton->data. */
13913 struct dwarf2_locexpr_baton
13914 dwarf2_fetch_die_location_block (unsigned int offset
,
13915 struct dwarf2_per_cu_data
*per_cu
,
13916 CORE_ADDR (*get_frame_pc
) (void *baton
),
13919 struct dwarf2_cu
*cu
;
13920 struct die_info
*die
;
13921 struct attribute
*attr
;
13922 struct dwarf2_locexpr_baton retval
;
13924 dw2_setup (per_cu
->objfile
);
13926 if (per_cu
->cu
== NULL
)
13930 die
= follow_die_offset (offset
, &cu
);
13932 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13933 offset
, per_cu
->cu
->objfile
->name
);
13935 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13938 /* DWARF: "If there is no such attribute, then there is no effect.". */
13940 retval
.data
= NULL
;
13943 else if (attr_form_is_section_offset (attr
))
13945 struct dwarf2_loclist_baton loclist_baton
;
13946 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
13949 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
13951 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
13953 retval
.size
= size
;
13957 if (!attr_form_is_block (attr
))
13958 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13959 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13960 offset
, per_cu
->cu
->objfile
->name
);
13962 retval
.data
= DW_BLOCK (attr
)->data
;
13963 retval
.size
= DW_BLOCK (attr
)->size
;
13965 retval
.per_cu
= cu
->per_cu
;
13968 retval
.data
= xmemdup (retval
.data
, retval
.size
, retval
.size
);
13970 age_cached_comp_units ();
13975 /* Return the type of the DIE at DIE_OFFSET in the CU named by
13979 dwarf2_get_die_type (unsigned int die_offset
,
13980 struct dwarf2_per_cu_data
*per_cu
)
13982 dw2_setup (per_cu
->objfile
);
13983 return get_die_type_at_offset (die_offset
, per_cu
);
13986 /* Follow the signature attribute ATTR in SRC_DIE.
13987 On entry *REF_CU is the CU of SRC_DIE.
13988 On exit *REF_CU is the CU of the result. */
13990 static struct die_info
*
13991 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
13992 struct dwarf2_cu
**ref_cu
)
13994 struct objfile
*objfile
= (*ref_cu
)->objfile
;
13995 struct die_info temp_die
;
13996 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13997 struct dwarf2_cu
*sig_cu
;
13998 struct die_info
*die
;
14000 /* sig_type will be NULL if the signatured type is missing from
14002 if (sig_type
== NULL
)
14003 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14004 "at 0x%x [in module %s]"),
14005 src_die
->offset
, objfile
->name
);
14007 /* If necessary, add it to the queue and load its DIEs. */
14009 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14010 read_signatured_type (objfile
, sig_type
);
14012 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14014 sig_cu
= sig_type
->per_cu
.cu
;
14015 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
14016 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
14023 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14024 "from DIE at 0x%x [in module %s]"),
14025 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
14028 /* Given an offset of a signatured type, return its signatured_type. */
14030 static struct signatured_type
*
14031 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14032 struct dwarf2_section_info
*section
,
14033 unsigned int offset
)
14035 gdb_byte
*info_ptr
= section
->buffer
+ offset
;
14036 unsigned int length
, initial_length_size
;
14037 unsigned int sig_offset
;
14038 struct signatured_type find_entry
, *type_sig
;
14040 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14041 sig_offset
= (initial_length_size
14043 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14044 + 1 /*address_size*/);
14045 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14046 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14048 /* This is only used to lookup previously recorded types.
14049 If we didn't find it, it's our bug. */
14050 gdb_assert (type_sig
!= NULL
);
14051 gdb_assert (offset
== type_sig
->per_cu
.offset
);
14056 /* Read in signatured type at OFFSET and build its CU and die(s). */
14059 read_signatured_type_at_offset (struct objfile
*objfile
,
14060 struct dwarf2_section_info
*sect
,
14061 unsigned int offset
)
14063 struct signatured_type
*type_sig
;
14065 dwarf2_read_section (objfile
, sect
);
14067 /* We have the section offset, but we need the signature to do the
14068 hash table lookup. */
14069 type_sig
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14071 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14073 read_signatured_type (objfile
, type_sig
);
14075 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
14078 /* Read in a signatured type and build its CU and DIEs. */
14081 read_signatured_type (struct objfile
*objfile
,
14082 struct signatured_type
*type_sig
)
14084 gdb_byte
*types_ptr
;
14085 struct die_reader_specs reader_specs
;
14086 struct dwarf2_cu
*cu
;
14087 ULONGEST signature
;
14088 struct cleanup
*back_to
, *free_cu_cleanup
;
14089 struct dwarf2_section_info
*section
= type_sig
->per_cu
.debug_type_section
;
14091 dwarf2_read_section (objfile
, section
);
14092 types_ptr
= section
->buffer
+ type_sig
->per_cu
.offset
;
14094 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14096 cu
= xmalloc (sizeof (*cu
));
14097 init_one_comp_unit (cu
, objfile
);
14099 type_sig
->per_cu
.cu
= cu
;
14100 cu
->per_cu
= &type_sig
->per_cu
;
14102 /* If an error occurs while loading, release our storage. */
14103 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
14105 types_ptr
= read_type_comp_unit_head (&cu
->header
, section
, &signature
,
14106 types_ptr
, objfile
->obfd
);
14107 gdb_assert (signature
== type_sig
->signature
);
14110 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14114 &cu
->comp_unit_obstack
,
14115 hashtab_obstack_allocate
,
14116 dummy_obstack_deallocate
);
14118 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
14119 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
14121 init_cu_die_reader (&reader_specs
, cu
);
14123 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14126 /* We try not to read any attributes in this function, because not
14127 all objfiles needed for references have been loaded yet, and symbol
14128 table processing isn't initialized. But we have to set the CU language,
14129 or we won't be able to build types correctly. */
14130 prepare_one_comp_unit (cu
, cu
->dies
);
14132 do_cleanups (back_to
);
14134 /* We've successfully allocated this compilation unit. Let our caller
14135 clean it up when finished with it. */
14136 discard_cleanups (free_cu_cleanup
);
14138 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14139 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
14142 /* Workaround as dwarf_expr_context_funcs.read_mem implementation before
14143 a proper runtime DWARF expressions evaluator gets implemented.
14144 Otherwise gnuv3_baseclass_offset would error by:
14145 Expected a negative vbase offset (old compiler?) */
14148 decode_locdesc_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
,
14151 struct dwarf_expr_context
*ctx
= baton
;
14152 struct gdbarch
*gdbarch
= ctx
->gdbarch
;
14153 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
14155 memset (buf
, 0, length
);
14157 if (TYPE_LENGTH (ptr_type
) == length
)
14158 store_typed_address (buf
, ptr_type
, addr
);
14161 static const struct dwarf_expr_context_funcs decode_locdesc_ctx_funcs
=
14164 decode_locdesc_read_mem
,
14165 ctx_no_get_frame_base
,
14166 ctx_no_get_frame_cfa
,
14167 ctx_no_get_frame_pc
,
14168 ctx_no_get_tls_address
,
14170 ctx_no_get_base_type
14173 /* Decode simple location descriptions.
14174 Given a pointer to a dwarf block that defines a location, compute
14175 the location and return the value.
14177 NOTE drow/2003-11-18: This function is called in two situations
14178 now: for the address of static or global variables (partial symbols
14179 only) and for offsets into structures which are expected to be
14180 (more or less) constant. The partial symbol case should go away,
14181 and only the constant case should remain. That will let this
14182 function complain more accurately. A few special modes are allowed
14183 without complaint for global variables (for instance, global
14184 register values and thread-local values).
14186 A location description containing no operations indicates that the
14187 object is optimized out. The return value is 0 for that case.
14188 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14189 callers will only want a very basic result and this can become a
14193 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14195 struct objfile
*objfile
= cu
->objfile
;
14196 struct dwarf_expr_context
*ctx
;
14197 struct cleanup
*old_chain
;
14198 volatile struct gdb_exception ex
;
14200 ctx
= new_dwarf_expr_context ();
14201 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
14202 make_cleanup_value_free_to_mark (value_mark ());
14204 ctx
->gdbarch
= get_objfile_arch (objfile
);
14205 ctx
->addr_size
= cu
->header
.addr_size
;
14206 ctx
->offset
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14208 ctx
->funcs
= &decode_locdesc_ctx_funcs
;
14210 /* DW_AT_data_member_location expects the structure address to be pushed on
14211 the stack. Simulate the offset by address 0. */
14212 dwarf_expr_push_address (ctx
, 0, 0);
14214 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
14216 dwarf_expr_eval (ctx
, blk
->data
, blk
->size
);
14221 complaint (&symfile_complaints
, "%s", ex
.message
);
14223 else if (ctx
->num_pieces
== 0)
14224 switch (ctx
->location
)
14226 /* The returned number will be bogus, just do not complain for locations
14227 in global registers - it is here only a partial symbol address. */
14228 case DWARF_VALUE_REGISTER
:
14230 case DWARF_VALUE_MEMORY
:
14231 case DWARF_VALUE_STACK
:
14233 CORE_ADDR address
= dwarf_expr_fetch_address (ctx
, 0);
14235 do_cleanups (old_chain
);
14240 do_cleanups (old_chain
);
14241 dwarf2_complex_location_expr_complaint ();
14245 /* memory allocation interface */
14247 static struct dwarf_block
*
14248 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14250 struct dwarf_block
*blk
;
14252 blk
= (struct dwarf_block
*)
14253 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14257 static struct abbrev_info
*
14258 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14260 struct abbrev_info
*abbrev
;
14262 abbrev
= (struct abbrev_info
*)
14263 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14264 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14268 static struct die_info
*
14269 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14271 struct die_info
*die
;
14272 size_t size
= sizeof (struct die_info
);
14275 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14277 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14278 memset (die
, 0, sizeof (struct die_info
));
14283 /* Macro support. */
14285 /* Return the full name of file number I in *LH's file name table.
14286 Use COMP_DIR as the name of the current directory of the
14287 compilation. The result is allocated using xmalloc; the caller is
14288 responsible for freeing it. */
14290 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14292 /* Is the file number a valid index into the line header's file name
14293 table? Remember that file numbers start with one, not zero. */
14294 if (1 <= file
&& file
<= lh
->num_file_names
)
14296 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14298 if (IS_ABSOLUTE_PATH (fe
->name
))
14299 return xstrdup (fe
->name
);
14307 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14313 dir_len
= strlen (dir
);
14314 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14315 strcpy (full_name
, dir
);
14316 full_name
[dir_len
] = '/';
14317 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14321 return xstrdup (fe
->name
);
14326 /* The compiler produced a bogus file number. We can at least
14327 record the macro definitions made in the file, even if we
14328 won't be able to find the file by name. */
14329 char fake_name
[80];
14331 sprintf (fake_name
, "<bad macro file number %d>", file
);
14333 complaint (&symfile_complaints
,
14334 _("bad file number in macro information (%d)"),
14337 return xstrdup (fake_name
);
14342 static struct macro_source_file
*
14343 macro_start_file (int file
, int line
,
14344 struct macro_source_file
*current_file
,
14345 const char *comp_dir
,
14346 struct line_header
*lh
, struct objfile
*objfile
)
14348 /* The full name of this source file. */
14349 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14351 /* We don't create a macro table for this compilation unit
14352 at all until we actually get a filename. */
14353 if (! pending_macros
)
14354 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14355 objfile
->macro_cache
);
14357 if (! current_file
)
14358 /* If we have no current file, then this must be the start_file
14359 directive for the compilation unit's main source file. */
14360 current_file
= macro_set_main (pending_macros
, full_name
);
14362 current_file
= macro_include (current_file
, line
, full_name
);
14366 return current_file
;
14370 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14371 followed by a null byte. */
14373 copy_string (const char *buf
, int len
)
14375 char *s
= xmalloc (len
+ 1);
14377 memcpy (s
, buf
, len
);
14383 static const char *
14384 consume_improper_spaces (const char *p
, const char *body
)
14388 complaint (&symfile_complaints
,
14389 _("macro definition contains spaces "
14390 "in formal argument list:\n`%s'"),
14402 parse_macro_definition (struct macro_source_file
*file
, int line
,
14407 /* The body string takes one of two forms. For object-like macro
14408 definitions, it should be:
14410 <macro name> " " <definition>
14412 For function-like macro definitions, it should be:
14414 <macro name> "() " <definition>
14416 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14418 Spaces may appear only where explicitly indicated, and in the
14421 The Dwarf 2 spec says that an object-like macro's name is always
14422 followed by a space, but versions of GCC around March 2002 omit
14423 the space when the macro's definition is the empty string.
14425 The Dwarf 2 spec says that there should be no spaces between the
14426 formal arguments in a function-like macro's formal argument list,
14427 but versions of GCC around March 2002 include spaces after the
14431 /* Find the extent of the macro name. The macro name is terminated
14432 by either a space or null character (for an object-like macro) or
14433 an opening paren (for a function-like macro). */
14434 for (p
= body
; *p
; p
++)
14435 if (*p
== ' ' || *p
== '(')
14438 if (*p
== ' ' || *p
== '\0')
14440 /* It's an object-like macro. */
14441 int name_len
= p
- body
;
14442 char *name
= copy_string (body
, name_len
);
14443 const char *replacement
;
14446 replacement
= body
+ name_len
+ 1;
14449 dwarf2_macro_malformed_definition_complaint (body
);
14450 replacement
= body
+ name_len
;
14453 macro_define_object (file
, line
, name
, replacement
);
14457 else if (*p
== '(')
14459 /* It's a function-like macro. */
14460 char *name
= copy_string (body
, p
- body
);
14463 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14467 p
= consume_improper_spaces (p
, body
);
14469 /* Parse the formal argument list. */
14470 while (*p
&& *p
!= ')')
14472 /* Find the extent of the current argument name. */
14473 const char *arg_start
= p
;
14475 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14478 if (! *p
|| p
== arg_start
)
14479 dwarf2_macro_malformed_definition_complaint (body
);
14482 /* Make sure argv has room for the new argument. */
14483 if (argc
>= argv_size
)
14486 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14489 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14492 p
= consume_improper_spaces (p
, body
);
14494 /* Consume the comma, if present. */
14499 p
= consume_improper_spaces (p
, body
);
14508 /* Perfectly formed definition, no complaints. */
14509 macro_define_function (file
, line
, name
,
14510 argc
, (const char **) argv
,
14512 else if (*p
== '\0')
14514 /* Complain, but do define it. */
14515 dwarf2_macro_malformed_definition_complaint (body
);
14516 macro_define_function (file
, line
, name
,
14517 argc
, (const char **) argv
,
14521 /* Just complain. */
14522 dwarf2_macro_malformed_definition_complaint (body
);
14525 /* Just complain. */
14526 dwarf2_macro_malformed_definition_complaint (body
);
14532 for (i
= 0; i
< argc
; i
++)
14538 dwarf2_macro_malformed_definition_complaint (body
);
14541 /* Skip some bytes from BYTES according to the form given in FORM.
14542 Returns the new pointer. */
14545 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
14546 enum dwarf_form form
,
14547 unsigned int offset_size
,
14548 struct dwarf2_section_info
*section
)
14550 unsigned int bytes_read
;
14554 case DW_FORM_data1
:
14559 case DW_FORM_data2
:
14563 case DW_FORM_data4
:
14567 case DW_FORM_data8
:
14571 case DW_FORM_string
:
14572 read_direct_string (abfd
, bytes
, &bytes_read
);
14573 bytes
+= bytes_read
;
14576 case DW_FORM_sec_offset
:
14578 bytes
+= offset_size
;
14581 case DW_FORM_block
:
14582 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
14583 bytes
+= bytes_read
;
14586 case DW_FORM_block1
:
14587 bytes
+= 1 + read_1_byte (abfd
, bytes
);
14589 case DW_FORM_block2
:
14590 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
14592 case DW_FORM_block4
:
14593 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
14596 case DW_FORM_sdata
:
14597 case DW_FORM_udata
:
14598 bytes
= skip_leb128 (abfd
, bytes
);
14604 complaint (&symfile_complaints
,
14605 _("invalid form 0x%x in `%s'"),
14607 section
->asection
->name
);
14615 /* A helper for dwarf_decode_macros that handles skipping an unknown
14616 opcode. Returns an updated pointer to the macro data buffer; or,
14617 on error, issues a complaint and returns NULL. */
14620 skip_unknown_opcode (unsigned int opcode
,
14621 gdb_byte
**opcode_definitions
,
14624 unsigned int offset_size
,
14625 struct dwarf2_section_info
*section
)
14627 unsigned int bytes_read
, i
;
14631 if (opcode_definitions
[opcode
] == NULL
)
14633 complaint (&symfile_complaints
,
14634 _("unrecognized DW_MACFINO opcode 0x%x"),
14639 defn
= opcode_definitions
[opcode
];
14640 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
14641 defn
+= bytes_read
;
14643 for (i
= 0; i
< arg
; ++i
)
14645 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
14646 if (mac_ptr
== NULL
)
14648 /* skip_form_bytes already issued the complaint. */
14656 /* A helper function which parses the header of a macro section.
14657 If the macro section is the extended (for now called "GNU") type,
14658 then this updates *OFFSET_SIZE. Returns a pointer to just after
14659 the header, or issues a complaint and returns NULL on error. */
14662 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
14665 unsigned int *offset_size
,
14666 int section_is_gnu
)
14668 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
14670 if (section_is_gnu
)
14672 unsigned int version
, flags
;
14674 version
= read_2_bytes (abfd
, mac_ptr
);
14677 complaint (&symfile_complaints
,
14678 _("unrecognized version `%d' in .debug_macro section"),
14684 flags
= read_1_byte (abfd
, mac_ptr
);
14686 *offset_size
= (flags
& 1) ? 8 : 4;
14688 if ((flags
& 2) != 0)
14689 /* We don't need the line table offset. */
14690 mac_ptr
+= *offset_size
;
14692 /* Vendor opcode descriptions. */
14693 if ((flags
& 4) != 0)
14695 unsigned int i
, count
;
14697 count
= read_1_byte (abfd
, mac_ptr
);
14699 for (i
= 0; i
< count
; ++i
)
14701 unsigned int opcode
, bytes_read
;
14704 opcode
= read_1_byte (abfd
, mac_ptr
);
14706 opcode_definitions
[opcode
] = mac_ptr
;
14707 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14708 mac_ptr
+= bytes_read
;
14717 /* A helper for dwarf_decode_macros that handles the GNU extensions,
14718 including DW_GNU_MACINFO_transparent_include. */
14721 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
14722 struct macro_source_file
*current_file
,
14723 struct line_header
*lh
, char *comp_dir
,
14724 struct dwarf2_section_info
*section
,
14725 int section_is_gnu
,
14726 unsigned int offset_size
,
14727 struct objfile
*objfile
)
14729 enum dwarf_macro_record_type macinfo_type
;
14730 int at_commandline
;
14731 gdb_byte
*opcode_definitions
[256];
14733 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
14734 &offset_size
, section_is_gnu
);
14735 if (mac_ptr
== NULL
)
14737 /* We already issued a complaint. */
14741 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14742 GDB is still reading the definitions from command line. First
14743 DW_MACINFO_start_file will need to be ignored as it was already executed
14744 to create CURRENT_FILE for the main source holding also the command line
14745 definitions. On first met DW_MACINFO_start_file this flag is reset to
14746 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14748 at_commandline
= 1;
14752 /* Do we at least have room for a macinfo type byte? */
14753 if (mac_ptr
>= mac_end
)
14755 dwarf2_macros_too_long_complaint (section
);
14759 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14762 /* Note that we rely on the fact that the corresponding GNU and
14763 DWARF constants are the same. */
14764 switch (macinfo_type
)
14766 /* A zero macinfo type indicates the end of the macro
14771 case DW_MACRO_GNU_define
:
14772 case DW_MACRO_GNU_undef
:
14773 case DW_MACRO_GNU_define_indirect
:
14774 case DW_MACRO_GNU_undef_indirect
:
14776 unsigned int bytes_read
;
14781 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14782 mac_ptr
+= bytes_read
;
14784 if (macinfo_type
== DW_MACRO_GNU_define
14785 || macinfo_type
== DW_MACRO_GNU_undef
)
14787 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14788 mac_ptr
+= bytes_read
;
14792 LONGEST str_offset
;
14794 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
14795 mac_ptr
+= offset_size
;
14797 body
= read_indirect_string_at_offset (abfd
, str_offset
);
14800 is_define
= (macinfo_type
== DW_MACRO_GNU_define
14801 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
14802 if (! current_file
)
14804 /* DWARF violation as no main source is present. */
14805 complaint (&symfile_complaints
,
14806 _("debug info with no main source gives macro %s "
14808 is_define
? _("definition") : _("undefinition"),
14812 if ((line
== 0 && !at_commandline
)
14813 || (line
!= 0 && at_commandline
))
14814 complaint (&symfile_complaints
,
14815 _("debug info gives %s macro %s with %s line %d: %s"),
14816 at_commandline
? _("command-line") : _("in-file"),
14817 is_define
? _("definition") : _("undefinition"),
14818 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
14821 parse_macro_definition (current_file
, line
, body
);
14824 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
14825 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
14826 macro_undef (current_file
, line
, body
);
14831 case DW_MACRO_GNU_start_file
:
14833 unsigned int bytes_read
;
14836 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14837 mac_ptr
+= bytes_read
;
14838 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14839 mac_ptr
+= bytes_read
;
14841 if ((line
== 0 && !at_commandline
)
14842 || (line
!= 0 && at_commandline
))
14843 complaint (&symfile_complaints
,
14844 _("debug info gives source %d included "
14845 "from %s at %s line %d"),
14846 file
, at_commandline
? _("command-line") : _("file"),
14847 line
== 0 ? _("zero") : _("non-zero"), line
);
14849 if (at_commandline
)
14851 /* This DW_MACRO_GNU_start_file was executed in the
14853 at_commandline
= 0;
14856 current_file
= macro_start_file (file
, line
,
14857 current_file
, comp_dir
,
14862 case DW_MACRO_GNU_end_file
:
14863 if (! current_file
)
14864 complaint (&symfile_complaints
,
14865 _("macro debug info has an unmatched "
14866 "`close_file' directive"));
14869 current_file
= current_file
->included_by
;
14870 if (! current_file
)
14872 enum dwarf_macro_record_type next_type
;
14874 /* GCC circa March 2002 doesn't produce the zero
14875 type byte marking the end of the compilation
14876 unit. Complain if it's not there, but exit no
14879 /* Do we at least have room for a macinfo type byte? */
14880 if (mac_ptr
>= mac_end
)
14882 dwarf2_macros_too_long_complaint (section
);
14886 /* We don't increment mac_ptr here, so this is just
14888 next_type
= read_1_byte (abfd
, mac_ptr
);
14889 if (next_type
!= 0)
14890 complaint (&symfile_complaints
,
14891 _("no terminating 0-type entry for "
14892 "macros in `.debug_macinfo' section"));
14899 case DW_MACRO_GNU_transparent_include
:
14903 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
14904 mac_ptr
+= offset_size
;
14906 dwarf_decode_macro_bytes (abfd
,
14907 section
->buffer
+ offset
,
14908 mac_end
, current_file
,
14910 section
, section_is_gnu
,
14911 offset_size
, objfile
);
14915 case DW_MACINFO_vendor_ext
:
14916 if (!section_is_gnu
)
14918 unsigned int bytes_read
;
14921 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14922 mac_ptr
+= bytes_read
;
14923 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14924 mac_ptr
+= bytes_read
;
14926 /* We don't recognize any vendor extensions. */
14932 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
14933 mac_ptr
, abfd
, offset_size
,
14935 if (mac_ptr
== NULL
)
14939 } while (macinfo_type
!= 0);
14943 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
14944 char *comp_dir
, bfd
*abfd
,
14945 struct dwarf2_cu
*cu
,
14946 struct dwarf2_section_info
*section
,
14947 int section_is_gnu
)
14949 gdb_byte
*mac_ptr
, *mac_end
;
14950 struct macro_source_file
*current_file
= 0;
14951 enum dwarf_macro_record_type macinfo_type
;
14952 unsigned int offset_size
= cu
->header
.offset_size
;
14953 gdb_byte
*opcode_definitions
[256];
14955 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
14956 if (section
->buffer
== NULL
)
14958 complaint (&symfile_complaints
, _("missing %s section"),
14959 section
->asection
->name
);
14963 /* First pass: Find the name of the base filename.
14964 This filename is needed in order to process all macros whose definition
14965 (or undefinition) comes from the command line. These macros are defined
14966 before the first DW_MACINFO_start_file entry, and yet still need to be
14967 associated to the base file.
14969 To determine the base file name, we scan the macro definitions until we
14970 reach the first DW_MACINFO_start_file entry. We then initialize
14971 CURRENT_FILE accordingly so that any macro definition found before the
14972 first DW_MACINFO_start_file can still be associated to the base file. */
14974 mac_ptr
= section
->buffer
+ offset
;
14975 mac_end
= section
->buffer
+ section
->size
;
14977 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
14978 &offset_size
, section_is_gnu
);
14979 if (mac_ptr
== NULL
)
14981 /* We already issued a complaint. */
14987 /* Do we at least have room for a macinfo type byte? */
14988 if (mac_ptr
>= mac_end
)
14990 /* Complaint is printed during the second pass as GDB will probably
14991 stop the first pass earlier upon finding
14992 DW_MACINFO_start_file. */
14996 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14999 /* Note that we rely on the fact that the corresponding GNU and
15000 DWARF constants are the same. */
15001 switch (macinfo_type
)
15003 /* A zero macinfo type indicates the end of the macro
15008 case DW_MACRO_GNU_define
:
15009 case DW_MACRO_GNU_undef
:
15010 /* Only skip the data by MAC_PTR. */
15012 unsigned int bytes_read
;
15014 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15015 mac_ptr
+= bytes_read
;
15016 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15017 mac_ptr
+= bytes_read
;
15021 case DW_MACRO_GNU_start_file
:
15023 unsigned int bytes_read
;
15026 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15027 mac_ptr
+= bytes_read
;
15028 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15029 mac_ptr
+= bytes_read
;
15031 current_file
= macro_start_file (file
, line
, current_file
,
15032 comp_dir
, lh
, cu
->objfile
);
15036 case DW_MACRO_GNU_end_file
:
15037 /* No data to skip by MAC_PTR. */
15040 case DW_MACRO_GNU_define_indirect
:
15041 case DW_MACRO_GNU_undef_indirect
:
15043 unsigned int bytes_read
;
15045 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15046 mac_ptr
+= bytes_read
;
15047 mac_ptr
+= offset_size
;
15051 case DW_MACRO_GNU_transparent_include
:
15052 /* Note that, according to the spec, a transparent include
15053 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15054 skip this opcode. */
15055 mac_ptr
+= offset_size
;
15058 case DW_MACINFO_vendor_ext
:
15059 /* Only skip the data by MAC_PTR. */
15060 if (!section_is_gnu
)
15062 unsigned int bytes_read
;
15064 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15065 mac_ptr
+= bytes_read
;
15066 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15067 mac_ptr
+= bytes_read
;
15072 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15073 mac_ptr
, abfd
, offset_size
,
15075 if (mac_ptr
== NULL
)
15079 } while (macinfo_type
!= 0 && current_file
== NULL
);
15081 /* Second pass: Process all entries.
15083 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15084 command-line macro definitions/undefinitions. This flag is unset when we
15085 reach the first DW_MACINFO_start_file entry. */
15087 dwarf_decode_macro_bytes (abfd
, section
->buffer
+ offset
, mac_end
,
15088 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
15089 offset_size
, cu
->objfile
);
15092 /* Check if the attribute's form is a DW_FORM_block*
15093 if so return true else false. */
15095 attr_form_is_block (struct attribute
*attr
)
15097 return (attr
== NULL
? 0 :
15098 attr
->form
== DW_FORM_block1
15099 || attr
->form
== DW_FORM_block2
15100 || attr
->form
== DW_FORM_block4
15101 || attr
->form
== DW_FORM_block
15102 || attr
->form
== DW_FORM_exprloc
);
15105 /* Return non-zero if ATTR's value is a section offset --- classes
15106 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15107 You may use DW_UNSND (attr) to retrieve such offsets.
15109 Section 7.5.4, "Attribute Encodings", explains that no attribute
15110 may have a value that belongs to more than one of these classes; it
15111 would be ambiguous if we did, because we use the same forms for all
15114 attr_form_is_section_offset (struct attribute
*attr
)
15116 return (attr
->form
== DW_FORM_data4
15117 || attr
->form
== DW_FORM_data8
15118 || attr
->form
== DW_FORM_sec_offset
);
15122 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15123 zero otherwise. When this function returns true, you can apply
15124 dwarf2_get_attr_constant_value to it.
15126 However, note that for some attributes you must check
15127 attr_form_is_section_offset before using this test. DW_FORM_data4
15128 and DW_FORM_data8 are members of both the constant class, and of
15129 the classes that contain offsets into other debug sections
15130 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15131 that, if an attribute's can be either a constant or one of the
15132 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15133 taken as section offsets, not constants. */
15135 attr_form_is_constant (struct attribute
*attr
)
15137 switch (attr
->form
)
15139 case DW_FORM_sdata
:
15140 case DW_FORM_udata
:
15141 case DW_FORM_data1
:
15142 case DW_FORM_data2
:
15143 case DW_FORM_data4
:
15144 case DW_FORM_data8
:
15151 /* A helper function that fills in a dwarf2_loclist_baton. */
15154 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15155 struct dwarf2_loclist_baton
*baton
,
15156 struct attribute
*attr
)
15158 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15159 &dwarf2_per_objfile
->loc
);
15161 baton
->per_cu
= cu
->per_cu
;
15162 gdb_assert (baton
->per_cu
);
15163 /* We don't know how long the location list is, but make sure we
15164 don't run off the edge of the section. */
15165 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15166 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15167 baton
->base_address
= cu
->base_address
;
15171 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15172 struct dwarf2_cu
*cu
)
15174 if (attr_form_is_section_offset (attr
)
15175 /* ".debug_loc" may not exist at all, or the offset may be outside
15176 the section. If so, fall through to the complaint in the
15178 && DW_UNSND (attr
) < dwarf2_section_size (dwarf2_per_objfile
->objfile
,
15179 &dwarf2_per_objfile
->loc
))
15181 struct dwarf2_loclist_baton
*baton
;
15183 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
15184 sizeof (struct dwarf2_loclist_baton
));
15186 fill_in_loclist_baton (cu
, baton
, attr
);
15188 if (cu
->base_known
== 0)
15189 complaint (&symfile_complaints
,
15190 _("Location list used without "
15191 "specifying the CU base address."));
15193 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15194 SYMBOL_LOCATION_BATON (sym
) = baton
;
15198 struct dwarf2_locexpr_baton
*baton
;
15200 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
15201 sizeof (struct dwarf2_locexpr_baton
));
15202 baton
->per_cu
= cu
->per_cu
;
15203 gdb_assert (baton
->per_cu
);
15205 if (attr_form_is_block (attr
))
15207 /* Note that we're just copying the block's data pointer
15208 here, not the actual data. We're still pointing into the
15209 info_buffer for SYM's objfile; right now we never release
15210 that buffer, but when we do clean up properly this may
15212 baton
->size
= DW_BLOCK (attr
)->size
;
15213 baton
->data
= DW_BLOCK (attr
)->data
;
15217 dwarf2_invalid_attrib_class_complaint ("location description",
15218 SYMBOL_NATURAL_NAME (sym
));
15220 baton
->data
= NULL
;
15223 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15224 SYMBOL_LOCATION_BATON (sym
) = baton
;
15228 /* Return the OBJFILE associated with the compilation unit CU. If CU
15229 came from a separate debuginfo file, then the master objfile is
15233 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
15235 struct objfile
*objfile
= per_cu
->objfile
;
15237 /* Return the master objfile, so that we can report and look up the
15238 correct file containing this variable. */
15239 if (objfile
->separate_debug_objfile_backlink
)
15240 objfile
= objfile
->separate_debug_objfile_backlink
;
15245 /* Return the address size given in the compilation unit header for CU. */
15248 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15251 return per_cu
->cu
->header
.addr_size
;
15254 /* If the CU is not currently read in, we re-read its header. */
15255 struct objfile
*objfile
= per_cu
->objfile
;
15256 struct dwarf2_per_objfile
*per_objfile
15257 = objfile_data (objfile
, dwarf2_objfile_data_key
);
15258 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
15259 struct comp_unit_head cu_header
;
15261 memset (&cu_header
, 0, sizeof cu_header
);
15262 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
15263 return cu_header
.addr_size
;
15267 /* Return the offset size given in the compilation unit header for CU. */
15270 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
15273 return per_cu
->cu
->header
.offset_size
;
15276 /* If the CU is not currently read in, we re-read its header. */
15277 struct objfile
*objfile
= per_cu
->objfile
;
15278 struct dwarf2_per_objfile
*per_objfile
15279 = objfile_data (objfile
, dwarf2_objfile_data_key
);
15280 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
15281 struct comp_unit_head cu_header
;
15283 memset (&cu_header
, 0, sizeof cu_header
);
15284 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
15285 return cu_header
.offset_size
;
15289 /* Return the text offset of the CU. The returned offset comes from
15290 this CU's objfile. If this objfile came from a separate debuginfo
15291 file, then the offset may be different from the corresponding
15292 offset in the parent objfile. */
15295 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
15297 struct objfile
*objfile
= per_cu
->objfile
;
15299 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15302 /* Locate the .debug_info compilation unit from CU's objfile which contains
15303 the DIE at OFFSET. Raises an error on failure. */
15305 static struct dwarf2_per_cu_data
*
15306 dwarf2_find_containing_comp_unit (unsigned int offset
,
15307 struct objfile
*objfile
)
15309 struct dwarf2_per_cu_data
*this_cu
;
15313 high
= dwarf2_per_objfile
->n_comp_units
- 1;
15316 int mid
= low
+ (high
- low
) / 2;
15318 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
15323 gdb_assert (low
== high
);
15324 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
15327 error (_("Dwarf Error: could not find partial DIE containing "
15328 "offset 0x%lx [in module %s]"),
15329 (long) offset
, bfd_get_filename (objfile
->obfd
));
15331 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
15332 return dwarf2_per_objfile
->all_comp_units
[low
-1];
15336 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
15337 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
15338 && offset
>= this_cu
->offset
+ this_cu
->length
)
15339 error (_("invalid dwarf2 offset %u"), offset
);
15340 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
15345 /* Locate the compilation unit from OBJFILE which is located at exactly
15346 OFFSET. Raises an error on failure. */
15348 static struct dwarf2_per_cu_data
*
15349 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
15351 struct dwarf2_per_cu_data
*this_cu
;
15353 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
15354 if (this_cu
->offset
!= offset
)
15355 error (_("no compilation unit with offset %u."), offset
);
15359 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
15362 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
15364 memset (cu
, 0, sizeof (*cu
));
15365 cu
->objfile
= objfile
;
15366 obstack_init (&cu
->comp_unit_obstack
);
15369 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15372 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
15374 struct attribute
*attr
;
15376 /* Set the language we're debugging. */
15377 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
15379 set_cu_language (DW_UNSND (attr
), cu
);
15382 cu
->language
= language_minimal
;
15383 cu
->language_defn
= language_def (cu
->language
);
15387 /* Release one cached compilation unit, CU. We unlink it from the tree
15388 of compilation units, but we don't remove it from the read_in_chain;
15389 the caller is responsible for that.
15390 NOTE: DATA is a void * because this function is also used as a
15391 cleanup routine. */
15394 free_one_comp_unit (void *data
)
15396 struct dwarf2_cu
*cu
= data
;
15398 if (cu
->per_cu
!= NULL
)
15399 cu
->per_cu
->cu
= NULL
;
15402 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15407 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15408 when we're finished with it. We can't free the pointer itself, but be
15409 sure to unlink it from the cache. Also release any associated storage
15410 and perform cache maintenance.
15412 Only used during partial symbol parsing. */
15415 free_stack_comp_unit (void *data
)
15417 struct dwarf2_cu
*cu
= data
;
15419 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15420 cu
->partial_dies
= NULL
;
15422 if (cu
->per_cu
!= NULL
)
15424 /* This compilation unit is on the stack in our caller, so we
15425 should not xfree it. Just unlink it. */
15426 cu
->per_cu
->cu
= NULL
;
15429 /* If we had a per-cu pointer, then we may have other compilation
15430 units loaded, so age them now. */
15431 age_cached_comp_units ();
15435 /* Free all cached compilation units. */
15438 free_cached_comp_units (void *data
)
15440 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15442 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15443 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15444 while (per_cu
!= NULL
)
15446 struct dwarf2_per_cu_data
*next_cu
;
15448 next_cu
= per_cu
->cu
->read_in_chain
;
15450 free_one_comp_unit (per_cu
->cu
);
15451 *last_chain
= next_cu
;
15457 /* Increase the age counter on each cached compilation unit, and free
15458 any that are too old. */
15461 age_cached_comp_units (void)
15463 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15465 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
15466 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15467 while (per_cu
!= NULL
)
15469 per_cu
->cu
->last_used
++;
15470 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
15471 dwarf2_mark (per_cu
->cu
);
15472 per_cu
= per_cu
->cu
->read_in_chain
;
15475 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15476 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15477 while (per_cu
!= NULL
)
15479 struct dwarf2_per_cu_data
*next_cu
;
15481 next_cu
= per_cu
->cu
->read_in_chain
;
15483 if (!per_cu
->cu
->mark
)
15485 free_one_comp_unit (per_cu
->cu
);
15486 *last_chain
= next_cu
;
15489 last_chain
= &per_cu
->cu
->read_in_chain
;
15495 /* Remove a single compilation unit from the cache. */
15498 free_one_cached_comp_unit (void *target_cu
)
15500 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15502 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15503 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15504 while (per_cu
!= NULL
)
15506 struct dwarf2_per_cu_data
*next_cu
;
15508 next_cu
= per_cu
->cu
->read_in_chain
;
15510 if (per_cu
->cu
== target_cu
)
15512 free_one_comp_unit (per_cu
->cu
);
15513 *last_chain
= next_cu
;
15517 last_chain
= &per_cu
->cu
->read_in_chain
;
15523 /* Release all extra memory associated with OBJFILE. */
15526 dwarf2_free_objfile (struct objfile
*objfile
)
15528 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15530 if (dwarf2_per_objfile
== NULL
)
15533 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
15534 free_cached_comp_units (NULL
);
15536 if (dwarf2_per_objfile
->quick_file_names_table
)
15537 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
15539 /* Everything else should be on the objfile obstack. */
15542 /* A pair of DIE offset and GDB type pointer. We store these
15543 in a hash table separate from the DIEs, and preserve them
15544 when the DIEs are flushed out of cache. */
15546 struct dwarf2_offset_and_type
15548 unsigned int offset
;
15552 /* Hash function for a dwarf2_offset_and_type. */
15555 offset_and_type_hash (const void *item
)
15557 const struct dwarf2_offset_and_type
*ofs
= item
;
15559 return ofs
->offset
;
15562 /* Equality function for a dwarf2_offset_and_type. */
15565 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
15567 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
15568 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
15570 return ofs_lhs
->offset
== ofs_rhs
->offset
;
15573 /* Set the type associated with DIE to TYPE. Save it in CU's hash
15574 table if necessary. For convenience, return TYPE.
15576 The DIEs reading must have careful ordering to:
15577 * Not cause infite loops trying to read in DIEs as a prerequisite for
15578 reading current DIE.
15579 * Not trying to dereference contents of still incompletely read in types
15580 while reading in other DIEs.
15581 * Enable referencing still incompletely read in types just by a pointer to
15582 the type without accessing its fields.
15584 Therefore caller should follow these rules:
15585 * Try to fetch any prerequisite types we may need to build this DIE type
15586 before building the type and calling set_die_type.
15587 * After building type call set_die_type for current DIE as soon as
15588 possible before fetching more types to complete the current type.
15589 * Make the type as complete as possible before fetching more types. */
15591 static struct type
*
15592 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
15594 struct dwarf2_offset_and_type
**slot
, ofs
;
15595 struct objfile
*objfile
= cu
->objfile
;
15596 htab_t
*type_hash_ptr
;
15598 /* For Ada types, make sure that the gnat-specific data is always
15599 initialized (if not already set). There are a few types where
15600 we should not be doing so, because the type-specific area is
15601 already used to hold some other piece of info (eg: TYPE_CODE_FLT
15602 where the type-specific area is used to store the floatformat).
15603 But this is not a problem, because the gnat-specific information
15604 is actually not needed for these types. */
15605 if (need_gnat_info (cu
)
15606 && TYPE_CODE (type
) != TYPE_CODE_FUNC
15607 && TYPE_CODE (type
) != TYPE_CODE_FLT
15608 && !HAVE_GNAT_AUX_INFO (type
))
15609 INIT_GNAT_SPECIFIC (type
);
15611 if (cu
->per_cu
->debug_type_section
)
15612 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
15614 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
15616 if (*type_hash_ptr
== NULL
)
15619 = htab_create_alloc_ex (127,
15620 offset_and_type_hash
,
15621 offset_and_type_eq
,
15623 &objfile
->objfile_obstack
,
15624 hashtab_obstack_allocate
,
15625 dummy_obstack_deallocate
);
15628 ofs
.offset
= die
->offset
;
15630 slot
= (struct dwarf2_offset_and_type
**)
15631 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
15633 complaint (&symfile_complaints
,
15634 _("A problem internal to GDB: DIE 0x%x has type already set"),
15636 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
15641 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
15642 table, or return NULL if the die does not have a saved type. */
15644 static struct type
*
15645 get_die_type_at_offset (unsigned int offset
,
15646 struct dwarf2_per_cu_data
*per_cu
)
15648 struct dwarf2_offset_and_type
*slot
, ofs
;
15651 if (per_cu
->debug_type_section
)
15652 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
15654 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
15655 if (type_hash
== NULL
)
15658 ofs
.offset
= offset
;
15659 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
15666 /* Look up the type for DIE in the appropriate type_hash table,
15667 or return NULL if DIE does not have a saved type. */
15669 static struct type
*
15670 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15672 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
15675 /* Add a dependence relationship from CU to REF_PER_CU. */
15678 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
15679 struct dwarf2_per_cu_data
*ref_per_cu
)
15683 if (cu
->dependencies
== NULL
)
15685 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
15686 NULL
, &cu
->comp_unit_obstack
,
15687 hashtab_obstack_allocate
,
15688 dummy_obstack_deallocate
);
15690 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
15692 *slot
= ref_per_cu
;
15695 /* Subroutine of dwarf2_mark to pass to htab_traverse.
15696 Set the mark field in every compilation unit in the
15697 cache that we must keep because we are keeping CU. */
15700 dwarf2_mark_helper (void **slot
, void *data
)
15702 struct dwarf2_per_cu_data
*per_cu
;
15704 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
15706 /* cu->dependencies references may not yet have been ever read if QUIT aborts
15707 reading of the chain. As such dependencies remain valid it is not much
15708 useful to track and undo them during QUIT cleanups. */
15709 if (per_cu
->cu
== NULL
)
15712 if (per_cu
->cu
->mark
)
15714 per_cu
->cu
->mark
= 1;
15716 if (per_cu
->cu
->dependencies
!= NULL
)
15717 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15722 /* Set the mark field in CU and in every other compilation unit in the
15723 cache that we must keep because we are keeping CU. */
15726 dwarf2_mark (struct dwarf2_cu
*cu
)
15731 if (cu
->dependencies
!= NULL
)
15732 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15736 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
15740 per_cu
->cu
->mark
= 0;
15741 per_cu
= per_cu
->cu
->read_in_chain
;
15745 /* Trivial hash function for partial_die_info: the hash value of a DIE
15746 is its offset in .debug_info for this objfile. */
15749 partial_die_hash (const void *item
)
15751 const struct partial_die_info
*part_die
= item
;
15753 return part_die
->offset
;
15756 /* Trivial comparison function for partial_die_info structures: two DIEs
15757 are equal if they have the same offset. */
15760 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
15762 const struct partial_die_info
*part_die_lhs
= item_lhs
;
15763 const struct partial_die_info
*part_die_rhs
= item_rhs
;
15765 return part_die_lhs
->offset
== part_die_rhs
->offset
;
15768 static struct cmd_list_element
*set_dwarf2_cmdlist
;
15769 static struct cmd_list_element
*show_dwarf2_cmdlist
;
15772 set_dwarf2_cmd (char *args
, int from_tty
)
15774 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
15778 show_dwarf2_cmd (char *args
, int from_tty
)
15780 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
15783 /* If section described by INFO was mmapped, munmap it now. */
15786 munmap_section_buffer (struct dwarf2_section_info
*info
)
15788 if (info
->map_addr
!= NULL
)
15793 res
= munmap (info
->map_addr
, info
->map_len
);
15794 gdb_assert (res
== 0);
15796 /* Without HAVE_MMAP, we should never be here to begin with. */
15797 gdb_assert_not_reached ("no mmap support");
15802 /* munmap debug sections for OBJFILE, if necessary. */
15805 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
15807 struct dwarf2_per_objfile
*data
= d
;
15809 struct dwarf2_section_info
*section
;
15811 /* This is sorted according to the order they're defined in to make it easier
15812 to keep in sync. */
15813 munmap_section_buffer (&data
->info
);
15814 munmap_section_buffer (&data
->abbrev
);
15815 munmap_section_buffer (&data
->line
);
15816 munmap_section_buffer (&data
->loc
);
15817 munmap_section_buffer (&data
->macinfo
);
15818 munmap_section_buffer (&data
->macro
);
15819 munmap_section_buffer (&data
->str
);
15820 munmap_section_buffer (&data
->ranges
);
15821 munmap_section_buffer (&data
->frame
);
15822 munmap_section_buffer (&data
->eh_frame
);
15823 munmap_section_buffer (&data
->gdb_index
);
15826 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
15828 munmap_section_buffer (section
);
15830 VEC_free (dwarf2_section_info_def
, data
->types
);
15834 /* The "save gdb-index" command. */
15836 /* The contents of the hash table we create when building the string
15838 struct strtab_entry
15840 offset_type offset
;
15844 /* Hash function for a strtab_entry.
15846 Function is used only during write_hash_table so no index format backward
15847 compatibility is needed. */
15850 hash_strtab_entry (const void *e
)
15852 const struct strtab_entry
*entry
= e
;
15853 return mapped_index_string_hash (INT_MAX
, entry
->str
);
15856 /* Equality function for a strtab_entry. */
15859 eq_strtab_entry (const void *a
, const void *b
)
15861 const struct strtab_entry
*ea
= a
;
15862 const struct strtab_entry
*eb
= b
;
15863 return !strcmp (ea
->str
, eb
->str
);
15866 /* Create a strtab_entry hash table. */
15869 create_strtab (void)
15871 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
15872 xfree
, xcalloc
, xfree
);
15875 /* Add a string to the constant pool. Return the string's offset in
15879 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
15882 struct strtab_entry entry
;
15883 struct strtab_entry
*result
;
15886 slot
= htab_find_slot (table
, &entry
, INSERT
);
15891 result
= XNEW (struct strtab_entry
);
15892 result
->offset
= obstack_object_size (cpool
);
15894 obstack_grow_str0 (cpool
, str
);
15897 return result
->offset
;
15900 /* An entry in the symbol table. */
15901 struct symtab_index_entry
15903 /* The name of the symbol. */
15905 /* The offset of the name in the constant pool. */
15906 offset_type index_offset
;
15907 /* A sorted vector of the indices of all the CUs that hold an object
15909 VEC (offset_type
) *cu_indices
;
15912 /* The symbol table. This is a power-of-2-sized hash table. */
15913 struct mapped_symtab
15915 offset_type n_elements
;
15917 struct symtab_index_entry
**data
;
15920 /* Hash function for a symtab_index_entry. */
15923 hash_symtab_entry (const void *e
)
15925 const struct symtab_index_entry
*entry
= e
;
15926 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
15927 sizeof (offset_type
) * VEC_length (offset_type
,
15928 entry
->cu_indices
),
15932 /* Equality function for a symtab_index_entry. */
15935 eq_symtab_entry (const void *a
, const void *b
)
15937 const struct symtab_index_entry
*ea
= a
;
15938 const struct symtab_index_entry
*eb
= b
;
15939 int len
= VEC_length (offset_type
, ea
->cu_indices
);
15940 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
15942 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
15943 VEC_address (offset_type
, eb
->cu_indices
),
15944 sizeof (offset_type
) * len
);
15947 /* Destroy a symtab_index_entry. */
15950 delete_symtab_entry (void *p
)
15952 struct symtab_index_entry
*entry
= p
;
15953 VEC_free (offset_type
, entry
->cu_indices
);
15957 /* Create a hash table holding symtab_index_entry objects. */
15960 create_symbol_hash_table (void)
15962 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
15963 delete_symtab_entry
, xcalloc
, xfree
);
15966 /* Create a new mapped symtab object. */
15968 static struct mapped_symtab
*
15969 create_mapped_symtab (void)
15971 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
15972 symtab
->n_elements
= 0;
15973 symtab
->size
= 1024;
15974 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15978 /* Destroy a mapped_symtab. */
15981 cleanup_mapped_symtab (void *p
)
15983 struct mapped_symtab
*symtab
= p
;
15984 /* The contents of the array are freed when the other hash table is
15986 xfree (symtab
->data
);
15990 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
15993 Function is used only during write_hash_table so no index format backward
15994 compatibility is needed. */
15996 static struct symtab_index_entry
**
15997 find_slot (struct mapped_symtab
*symtab
, const char *name
)
15999 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
16001 index
= hash
& (symtab
->size
- 1);
16002 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
16006 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
16007 return &symtab
->data
[index
];
16008 index
= (index
+ step
) & (symtab
->size
- 1);
16012 /* Expand SYMTAB's hash table. */
16015 hash_expand (struct mapped_symtab
*symtab
)
16017 offset_type old_size
= symtab
->size
;
16019 struct symtab_index_entry
**old_entries
= symtab
->data
;
16022 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16024 for (i
= 0; i
< old_size
; ++i
)
16026 if (old_entries
[i
])
16028 struct symtab_index_entry
**slot
= find_slot (symtab
,
16029 old_entries
[i
]->name
);
16030 *slot
= old_entries
[i
];
16034 xfree (old_entries
);
16037 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16038 is the index of the CU in which the symbol appears. */
16041 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
16042 offset_type cu_index
)
16044 struct symtab_index_entry
**slot
;
16046 ++symtab
->n_elements
;
16047 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
16048 hash_expand (symtab
);
16050 slot
= find_slot (symtab
, name
);
16053 *slot
= XNEW (struct symtab_index_entry
);
16054 (*slot
)->name
= name
;
16055 (*slot
)->cu_indices
= NULL
;
16057 /* Don't push an index twice. Due to how we add entries we only
16058 have to check the last one. */
16059 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
16060 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
16061 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
16064 /* Add a vector of indices to the constant pool. */
16067 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
16068 struct symtab_index_entry
*entry
)
16072 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
16075 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
16076 offset_type val
= MAYBE_SWAP (len
);
16081 entry
->index_offset
= obstack_object_size (cpool
);
16083 obstack_grow (cpool
, &val
, sizeof (val
));
16085 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
16088 val
= MAYBE_SWAP (iter
);
16089 obstack_grow (cpool
, &val
, sizeof (val
));
16094 struct symtab_index_entry
*old_entry
= *slot
;
16095 entry
->index_offset
= old_entry
->index_offset
;
16098 return entry
->index_offset
;
16101 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16102 constant pool entries going into the obstack CPOOL. */
16105 write_hash_table (struct mapped_symtab
*symtab
,
16106 struct obstack
*output
, struct obstack
*cpool
)
16109 htab_t symbol_hash_table
;
16112 symbol_hash_table
= create_symbol_hash_table ();
16113 str_table
= create_strtab ();
16115 /* We add all the index vectors to the constant pool first, to
16116 ensure alignment is ok. */
16117 for (i
= 0; i
< symtab
->size
; ++i
)
16119 if (symtab
->data
[i
])
16120 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
16123 /* Now write out the hash table. */
16124 for (i
= 0; i
< symtab
->size
; ++i
)
16126 offset_type str_off
, vec_off
;
16128 if (symtab
->data
[i
])
16130 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
16131 vec_off
= symtab
->data
[i
]->index_offset
;
16135 /* While 0 is a valid constant pool index, it is not valid
16136 to have 0 for both offsets. */
16141 str_off
= MAYBE_SWAP (str_off
);
16142 vec_off
= MAYBE_SWAP (vec_off
);
16144 obstack_grow (output
, &str_off
, sizeof (str_off
));
16145 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
16148 htab_delete (str_table
);
16149 htab_delete (symbol_hash_table
);
16152 /* Struct to map psymtab to CU index in the index file. */
16153 struct psymtab_cu_index_map
16155 struct partial_symtab
*psymtab
;
16156 unsigned int cu_index
;
16160 hash_psymtab_cu_index (const void *item
)
16162 const struct psymtab_cu_index_map
*map
= item
;
16164 return htab_hash_pointer (map
->psymtab
);
16168 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16170 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16171 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16173 return lhs
->psymtab
== rhs
->psymtab
;
16176 /* Helper struct for building the address table. */
16177 struct addrmap_index_data
16179 struct objfile
*objfile
;
16180 struct obstack
*addr_obstack
;
16181 htab_t cu_index_htab
;
16183 /* Non-zero if the previous_* fields are valid.
16184 We can't write an entry until we see the next entry (since it is only then
16185 that we know the end of the entry). */
16186 int previous_valid
;
16187 /* Index of the CU in the table of all CUs in the index file. */
16188 unsigned int previous_cu_index
;
16189 /* Start address of the CU. */
16190 CORE_ADDR previous_cu_start
;
16193 /* Write an address entry to OBSTACK. */
16196 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16197 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16199 offset_type cu_index_to_write
;
16201 CORE_ADDR baseaddr
;
16203 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16205 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16206 obstack_grow (obstack
, addr
, 8);
16207 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16208 obstack_grow (obstack
, addr
, 8);
16209 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16210 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16213 /* Worker function for traversing an addrmap to build the address table. */
16216 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
16218 struct addrmap_index_data
*data
= datap
;
16219 struct partial_symtab
*pst
= obj
;
16220 offset_type cu_index
;
16223 if (data
->previous_valid
)
16224 add_address_entry (data
->objfile
, data
->addr_obstack
,
16225 data
->previous_cu_start
, start_addr
,
16226 data
->previous_cu_index
);
16228 data
->previous_cu_start
= start_addr
;
16231 struct psymtab_cu_index_map find_map
, *map
;
16232 find_map
.psymtab
= pst
;
16233 map
= htab_find (data
->cu_index_htab
, &find_map
);
16234 gdb_assert (map
!= NULL
);
16235 data
->previous_cu_index
= map
->cu_index
;
16236 data
->previous_valid
= 1;
16239 data
->previous_valid
= 0;
16244 /* Write OBJFILE's address map to OBSTACK.
16245 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16246 in the index file. */
16249 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
16250 htab_t cu_index_htab
)
16252 struct addrmap_index_data addrmap_index_data
;
16254 /* When writing the address table, we have to cope with the fact that
16255 the addrmap iterator only provides the start of a region; we have to
16256 wait until the next invocation to get the start of the next region. */
16258 addrmap_index_data
.objfile
= objfile
;
16259 addrmap_index_data
.addr_obstack
= obstack
;
16260 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
16261 addrmap_index_data
.previous_valid
= 0;
16263 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
16264 &addrmap_index_data
);
16266 /* It's highly unlikely the last entry (end address = 0xff...ff)
16267 is valid, but we should still handle it.
16268 The end address is recorded as the start of the next region, but that
16269 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16271 if (addrmap_index_data
.previous_valid
)
16272 add_address_entry (objfile
, obstack
,
16273 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
16274 addrmap_index_data
.previous_cu_index
);
16277 /* Add a list of partial symbols to SYMTAB. */
16280 write_psymbols (struct mapped_symtab
*symtab
,
16282 struct partial_symbol
**psymp
,
16284 offset_type cu_index
,
16287 for (; count
-- > 0; ++psymp
)
16289 void **slot
, *lookup
;
16291 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
16292 error (_("Ada is not currently supported by the index"));
16294 /* We only want to add a given psymbol once. However, we also
16295 want to account for whether it is global or static. So, we
16296 may add it twice, using slightly different values. */
16299 uintptr_t val
= 1 | (uintptr_t) *psymp
;
16301 lookup
= (void *) val
;
16306 /* Only add a given psymbol once. */
16307 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
16311 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
16316 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16317 exception if there is an error. */
16320 write_obstack (FILE *file
, struct obstack
*obstack
)
16322 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
16324 != obstack_object_size (obstack
))
16325 error (_("couldn't data write to file"));
16328 /* Unlink a file if the argument is not NULL. */
16331 unlink_if_set (void *p
)
16333 char **filename
= p
;
16335 unlink (*filename
);
16338 /* A helper struct used when iterating over debug_types. */
16339 struct signatured_type_index_data
16341 struct objfile
*objfile
;
16342 struct mapped_symtab
*symtab
;
16343 struct obstack
*types_list
;
16348 /* A helper function that writes a single signatured_type to an
16352 write_one_signatured_type (void **slot
, void *d
)
16354 struct signatured_type_index_data
*info
= d
;
16355 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
16356 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
16357 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16360 write_psymbols (info
->symtab
,
16362 info
->objfile
->global_psymbols
.list
16363 + psymtab
->globals_offset
,
16364 psymtab
->n_global_syms
, info
->cu_index
,
16366 write_psymbols (info
->symtab
,
16368 info
->objfile
->static_psymbols
.list
16369 + psymtab
->statics_offset
,
16370 psymtab
->n_static_syms
, info
->cu_index
,
16373 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->per_cu
.offset
);
16374 obstack_grow (info
->types_list
, val
, 8);
16375 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
16376 obstack_grow (info
->types_list
, val
, 8);
16377 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
16378 obstack_grow (info
->types_list
, val
, 8);
16385 /* A cleanup function for an htab_t. */
16388 cleanup_htab (void *arg
)
16393 /* Create an index file for OBJFILE in the directory DIR. */
16396 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
16398 struct cleanup
*cleanup
;
16399 char *filename
, *cleanup_filename
;
16400 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
16401 struct obstack cu_list
, types_cu_list
;
16404 struct mapped_symtab
*symtab
;
16405 offset_type val
, size_of_contents
, total_len
;
16409 htab_t cu_index_htab
;
16410 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
16412 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
16415 if (dwarf2_per_objfile
->using_index
)
16416 error (_("Cannot use an index to create the index"));
16418 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
16419 error (_("Cannot make an index when the file has multiple .debug_types sections"));
16421 if (stat (objfile
->name
, &st
) < 0)
16422 perror_with_name (objfile
->name
);
16424 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
16425 INDEX_SUFFIX
, (char *) NULL
);
16426 cleanup
= make_cleanup (xfree
, filename
);
16428 out_file
= fopen (filename
, "wb");
16430 error (_("Can't open `%s' for writing"), filename
);
16432 cleanup_filename
= filename
;
16433 make_cleanup (unlink_if_set
, &cleanup_filename
);
16435 symtab
= create_mapped_symtab ();
16436 make_cleanup (cleanup_mapped_symtab
, symtab
);
16438 obstack_init (&addr_obstack
);
16439 make_cleanup_obstack_free (&addr_obstack
);
16441 obstack_init (&cu_list
);
16442 make_cleanup_obstack_free (&cu_list
);
16444 obstack_init (&types_cu_list
);
16445 make_cleanup_obstack_free (&types_cu_list
);
16447 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
16448 NULL
, xcalloc
, xfree
);
16449 make_cleanup (cleanup_htab
, psyms_seen
);
16451 /* While we're scanning CU's create a table that maps a psymtab pointer
16452 (which is what addrmap records) to its index (which is what is recorded
16453 in the index file). This will later be needed to write the address
16455 cu_index_htab
= htab_create_alloc (100,
16456 hash_psymtab_cu_index
,
16457 eq_psymtab_cu_index
,
16458 NULL
, xcalloc
, xfree
);
16459 make_cleanup (cleanup_htab
, cu_index_htab
);
16460 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
16461 xmalloc (sizeof (struct psymtab_cu_index_map
)
16462 * dwarf2_per_objfile
->n_comp_units
);
16463 make_cleanup (xfree
, psymtab_cu_index_map
);
16465 /* The CU list is already sorted, so we don't need to do additional
16466 work here. Also, the debug_types entries do not appear in
16467 all_comp_units, but only in their own hash table. */
16468 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
16470 struct dwarf2_per_cu_data
*per_cu
16471 = dwarf2_per_objfile
->all_comp_units
[i
];
16472 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16474 struct psymtab_cu_index_map
*map
;
16477 write_psymbols (symtab
,
16479 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
16480 psymtab
->n_global_syms
, i
,
16482 write_psymbols (symtab
,
16484 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
16485 psymtab
->n_static_syms
, i
,
16488 map
= &psymtab_cu_index_map
[i
];
16489 map
->psymtab
= psymtab
;
16491 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
16492 gdb_assert (slot
!= NULL
);
16493 gdb_assert (*slot
== NULL
);
16496 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
16497 obstack_grow (&cu_list
, val
, 8);
16498 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
16499 obstack_grow (&cu_list
, val
, 8);
16502 /* Dump the address map. */
16503 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
16505 /* Write out the .debug_type entries, if any. */
16506 if (dwarf2_per_objfile
->signatured_types
)
16508 struct signatured_type_index_data sig_data
;
16510 sig_data
.objfile
= objfile
;
16511 sig_data
.symtab
= symtab
;
16512 sig_data
.types_list
= &types_cu_list
;
16513 sig_data
.psyms_seen
= psyms_seen
;
16514 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
16515 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
16516 write_one_signatured_type
, &sig_data
);
16519 obstack_init (&constant_pool
);
16520 make_cleanup_obstack_free (&constant_pool
);
16521 obstack_init (&symtab_obstack
);
16522 make_cleanup_obstack_free (&symtab_obstack
);
16523 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
16525 obstack_init (&contents
);
16526 make_cleanup_obstack_free (&contents
);
16527 size_of_contents
= 6 * sizeof (offset_type
);
16528 total_len
= size_of_contents
;
16530 /* The version number. */
16531 val
= MAYBE_SWAP (5);
16532 obstack_grow (&contents
, &val
, sizeof (val
));
16534 /* The offset of the CU list from the start of the file. */
16535 val
= MAYBE_SWAP (total_len
);
16536 obstack_grow (&contents
, &val
, sizeof (val
));
16537 total_len
+= obstack_object_size (&cu_list
);
16539 /* The offset of the types CU list from the start of the file. */
16540 val
= MAYBE_SWAP (total_len
);
16541 obstack_grow (&contents
, &val
, sizeof (val
));
16542 total_len
+= obstack_object_size (&types_cu_list
);
16544 /* The offset of the address table from the start of the file. */
16545 val
= MAYBE_SWAP (total_len
);
16546 obstack_grow (&contents
, &val
, sizeof (val
));
16547 total_len
+= obstack_object_size (&addr_obstack
);
16549 /* The offset of the symbol table from the start of the file. */
16550 val
= MAYBE_SWAP (total_len
);
16551 obstack_grow (&contents
, &val
, sizeof (val
));
16552 total_len
+= obstack_object_size (&symtab_obstack
);
16554 /* The offset of the constant pool from the start of the file. */
16555 val
= MAYBE_SWAP (total_len
);
16556 obstack_grow (&contents
, &val
, sizeof (val
));
16557 total_len
+= obstack_object_size (&constant_pool
);
16559 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
16561 write_obstack (out_file
, &contents
);
16562 write_obstack (out_file
, &cu_list
);
16563 write_obstack (out_file
, &types_cu_list
);
16564 write_obstack (out_file
, &addr_obstack
);
16565 write_obstack (out_file
, &symtab_obstack
);
16566 write_obstack (out_file
, &constant_pool
);
16570 /* We want to keep the file, so we set cleanup_filename to NULL
16571 here. See unlink_if_set. */
16572 cleanup_filename
= NULL
;
16574 do_cleanups (cleanup
);
16577 /* Implementation of the `save gdb-index' command.
16579 Note that the file format used by this command is documented in the
16580 GDB manual. Any changes here must be documented there. */
16583 save_gdb_index_command (char *arg
, int from_tty
)
16585 struct objfile
*objfile
;
16588 error (_("usage: save gdb-index DIRECTORY"));
16590 ALL_OBJFILES (objfile
)
16594 /* If the objfile does not correspond to an actual file, skip it. */
16595 if (stat (objfile
->name
, &st
) < 0)
16598 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16599 if (dwarf2_per_objfile
)
16601 volatile struct gdb_exception except
;
16603 TRY_CATCH (except
, RETURN_MASK_ERROR
)
16605 write_psymtabs_to_index (objfile
, arg
);
16607 if (except
.reason
< 0)
16608 exception_fprintf (gdb_stderr
, except
,
16609 _("Error while writing index for `%s': "),
16617 int dwarf2_always_disassemble
;
16620 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
16621 struct cmd_list_element
*c
, const char *value
)
16623 fprintf_filtered (file
,
16624 _("Whether to always disassemble "
16625 "DWARF expressions is %s.\n"),
16630 show_check_physname (struct ui_file
*file
, int from_tty
,
16631 struct cmd_list_element
*c
, const char *value
)
16633 fprintf_filtered (file
,
16634 _("Whether to check \"physname\" is %s.\n"),
16638 void _initialize_dwarf2_read (void);
16641 _initialize_dwarf2_read (void)
16643 struct cmd_list_element
*c
;
16645 dwarf2_objfile_data_key
16646 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
16648 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
16649 Set DWARF 2 specific variables.\n\
16650 Configure DWARF 2 variables such as the cache size"),
16651 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
16652 0/*allow-unknown*/, &maintenance_set_cmdlist
);
16654 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
16655 Show DWARF 2 specific variables\n\
16656 Show DWARF 2 variables such as the cache size"),
16657 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
16658 0/*allow-unknown*/, &maintenance_show_cmdlist
);
16660 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
16661 &dwarf2_max_cache_age
, _("\
16662 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
16663 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
16664 A higher limit means that cached compilation units will be stored\n\
16665 in memory longer, and more total memory will be used. Zero disables\n\
16666 caching, which can slow down startup."),
16668 show_dwarf2_max_cache_age
,
16669 &set_dwarf2_cmdlist
,
16670 &show_dwarf2_cmdlist
);
16672 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
16673 &dwarf2_always_disassemble
, _("\
16674 Set whether `info address' always disassembles DWARF expressions."), _("\
16675 Show whether `info address' always disassembles DWARF expressions."), _("\
16676 When enabled, DWARF expressions are always printed in an assembly-like\n\
16677 syntax. When disabled, expressions will be printed in a more\n\
16678 conversational style, when possible."),
16680 show_dwarf2_always_disassemble
,
16681 &set_dwarf2_cmdlist
,
16682 &show_dwarf2_cmdlist
);
16684 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
16685 Set debugging of the dwarf2 DIE reader."), _("\
16686 Show debugging of the dwarf2 DIE reader."), _("\
16687 When enabled (non-zero), DIEs are dumped after they are read in.\n\
16688 The value is the maximum depth to print."),
16691 &setdebuglist
, &showdebuglist
);
16693 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
16694 Set cross-checking of \"physname\" code against demangler."), _("\
16695 Show cross-checking of \"physname\" code against demangler."), _("\
16696 When enabled, GDB's internal \"physname\" code is checked against\n\
16698 NULL
, show_check_physname
,
16699 &setdebuglist
, &showdebuglist
);
16701 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
16703 Save a gdb-index file.\n\
16704 Usage: save gdb-index DIRECTORY"),
16706 set_cmd_completer (c
, filename_completer
);