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;
124 /* When set, the file that we're processing is known to have debugging
125 info for C++ namespaces. GCC 3.3.x did not produce this information,
126 but later versions do. */
128 static int processing_has_namespace_info
;
130 static const struct objfile_data
*dwarf2_objfile_data_key
;
132 struct dwarf2_section_info
138 /* True if we have tried to read this section. */
142 /* All offsets in the index are of this type. It must be
143 architecture-independent. */
144 typedef uint32_t offset_type
;
146 DEF_VEC_I (offset_type
);
148 /* A description of the mapped index. The file format is described in
149 a comment by the code that writes the index. */
152 /* The total length of the buffer. */
154 /* A pointer to the address table data. */
155 const gdb_byte
*address_table
;
156 /* Size of the address table data in bytes. */
157 offset_type address_table_size
;
158 /* The symbol table, implemented as a hash table. */
159 const offset_type
*symbol_table
;
160 /* Size in slots, each slot is 2 offset_types. */
161 offset_type symbol_table_slots
;
162 /* A pointer to the constant pool. */
163 const char *constant_pool
;
166 struct dwarf2_per_objfile
168 struct dwarf2_section_info info
;
169 struct dwarf2_section_info abbrev
;
170 struct dwarf2_section_info line
;
171 struct dwarf2_section_info loc
;
172 struct dwarf2_section_info macinfo
;
173 struct dwarf2_section_info str
;
174 struct dwarf2_section_info ranges
;
175 struct dwarf2_section_info types
;
176 struct dwarf2_section_info frame
;
177 struct dwarf2_section_info eh_frame
;
178 struct dwarf2_section_info gdb_index
;
181 struct objfile
*objfile
;
183 /* A list of all the compilation units. This is used to locate
184 the target compilation unit of a particular reference. */
185 struct dwarf2_per_cu_data
**all_comp_units
;
187 /* The number of compilation units in ALL_COMP_UNITS. */
190 /* The number of .debug_types-related CUs. */
191 int n_type_comp_units
;
193 /* The .debug_types-related CUs. */
194 struct dwarf2_per_cu_data
**type_comp_units
;
196 /* A chain of compilation units that are currently read in, so that
197 they can be freed later. */
198 struct dwarf2_per_cu_data
*read_in_chain
;
200 /* A table mapping .debug_types signatures to its signatured_type entry.
201 This is NULL if the .debug_types section hasn't been read in yet. */
202 htab_t signatured_types
;
204 /* A flag indicating wether this objfile has a section loaded at a
206 int has_section_at_zero
;
208 /* True if we are using the mapped index,
209 or we are faking it for OBJF_READNOW's sake. */
210 unsigned char using_index
;
212 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
213 struct mapped_index
*index_table
;
215 /* When using index_table, this keeps track of all quick_file_names entries.
216 TUs can share line table entries with CUs or other TUs, and there can be
217 a lot more TUs than unique line tables, so we maintain a separate table
218 of all line table entries to support the sharing. */
219 htab_t quick_file_names_table
;
221 /* Set during partial symbol reading, to prevent queueing of full
223 int reading_partial_symbols
;
225 /* Table mapping type .debug_info DIE offsets to types.
226 This is NULL if not allocated yet.
227 It (currently) makes sense to allocate debug_types_type_hash lazily.
228 To keep things simple we allocate both lazily. */
229 htab_t debug_info_type_hash
;
231 /* Table mapping type .debug_types DIE offsets to types.
232 This is NULL if not allocated yet. */
233 htab_t debug_types_type_hash
;
236 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
238 /* names of the debugging sections */
240 /* Note that if the debugging section has been compressed, it might
241 have a name like .zdebug_info. */
243 #define INFO_SECTION "debug_info"
244 #define ABBREV_SECTION "debug_abbrev"
245 #define LINE_SECTION "debug_line"
246 #define LOC_SECTION "debug_loc"
247 #define MACINFO_SECTION "debug_macinfo"
248 #define STR_SECTION "debug_str"
249 #define RANGES_SECTION "debug_ranges"
250 #define TYPES_SECTION "debug_types"
251 #define FRAME_SECTION "debug_frame"
252 #define EH_FRAME_SECTION "eh_frame"
253 #define GDB_INDEX_SECTION "gdb_index"
255 /* local data types */
257 /* We hold several abbreviation tables in memory at the same time. */
258 #ifndef ABBREV_HASH_SIZE
259 #define ABBREV_HASH_SIZE 121
262 /* The data in a compilation unit header, after target2host
263 translation, looks like this. */
264 struct comp_unit_head
268 unsigned char addr_size
;
269 unsigned char signed_addr_p
;
270 unsigned int abbrev_offset
;
272 /* Size of file offsets; either 4 or 8. */
273 unsigned int offset_size
;
275 /* Size of the length field; either 4 or 12. */
276 unsigned int initial_length_size
;
278 /* Offset to the first byte of this compilation unit header in the
279 .debug_info section, for resolving relative reference dies. */
282 /* Offset to first die in this cu from the start of the cu.
283 This will be the first byte following the compilation unit header. */
284 unsigned int first_die_offset
;
287 /* Type used for delaying computation of method physnames.
288 See comments for compute_delayed_physnames. */
289 struct delayed_method_info
291 /* The type to which the method is attached, i.e., its parent class. */
294 /* The index of the method in the type's function fieldlists. */
297 /* The index of the method in the fieldlist. */
300 /* The name of the DIE. */
303 /* The DIE associated with this method. */
304 struct die_info
*die
;
307 typedef struct delayed_method_info delayed_method_info
;
308 DEF_VEC_O (delayed_method_info
);
310 /* Internal state when decoding a particular compilation unit. */
313 /* The objfile containing this compilation unit. */
314 struct objfile
*objfile
;
316 /* The header of the compilation unit. */
317 struct comp_unit_head header
;
319 /* Base address of this compilation unit. */
320 CORE_ADDR base_address
;
322 /* Non-zero if base_address has been set. */
325 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
327 /* The language we are debugging. */
328 enum language language
;
329 const struct language_defn
*language_defn
;
331 const char *producer
;
333 /* The generic symbol table building routines have separate lists for
334 file scope symbols and all all other scopes (local scopes). So
335 we need to select the right one to pass to add_symbol_to_list().
336 We do it by keeping a pointer to the correct list in list_in_scope.
338 FIXME: The original dwarf code just treated the file scope as the
339 first local scope, and all other local scopes as nested local
340 scopes, and worked fine. Check to see if we really need to
341 distinguish these in buildsym.c. */
342 struct pending
**list_in_scope
;
344 /* DWARF abbreviation table associated with this compilation unit. */
345 struct abbrev_info
**dwarf2_abbrevs
;
347 /* Storage for the abbrev table. */
348 struct obstack abbrev_obstack
;
350 /* Hash table holding all the loaded partial DIEs. */
353 /* Storage for things with the same lifetime as this read-in compilation
354 unit, including partial DIEs. */
355 struct obstack comp_unit_obstack
;
357 /* When multiple dwarf2_cu structures are living in memory, this field
358 chains them all together, so that they can be released efficiently.
359 We will probably also want a generation counter so that most-recently-used
360 compilation units are cached... */
361 struct dwarf2_per_cu_data
*read_in_chain
;
363 /* Backchain to our per_cu entry if the tree has been built. */
364 struct dwarf2_per_cu_data
*per_cu
;
366 /* How many compilation units ago was this CU last referenced? */
369 /* A hash table of die offsets for following references. */
372 /* Full DIEs if read in. */
373 struct die_info
*dies
;
375 /* A set of pointers to dwarf2_per_cu_data objects for compilation
376 units referenced by this one. Only set during full symbol processing;
377 partial symbol tables do not have dependencies. */
380 /* Header data from the line table, during full symbol processing. */
381 struct line_header
*line_header
;
383 /* A list of methods which need to have physnames computed
384 after all type information has been read. */
385 VEC (delayed_method_info
) *method_list
;
387 /* Mark used when releasing cached dies. */
388 unsigned int mark
: 1;
390 /* This flag will be set if this compilation unit might include
391 inter-compilation-unit references. */
392 unsigned int has_form_ref_addr
: 1;
394 /* This flag will be set if this compilation unit includes any
395 DW_TAG_namespace DIEs. If we know that there are explicit
396 DIEs for namespaces, we don't need to try to infer them
397 from mangled names. */
398 unsigned int has_namespace_info
: 1;
401 /* Persistent data held for a compilation unit, even when not
402 processing it. We put a pointer to this structure in the
403 read_symtab_private field of the psymtab. If we encounter
404 inter-compilation-unit references, we also maintain a sorted
405 list of all compilation units. */
407 struct dwarf2_per_cu_data
409 /* The start offset and length of this compilation unit. 2**29-1
410 bytes should suffice to store the length of any compilation unit
411 - if it doesn't, GDB will fall over anyway.
412 NOTE: Unlike comp_unit_head.length, this length includes
413 initial_length_size. */
415 unsigned int length
: 29;
417 /* Flag indicating this compilation unit will be read in before
418 any of the current compilation units are processed. */
419 unsigned int queued
: 1;
421 /* This flag will be set if we need to load absolutely all DIEs
422 for this compilation unit, instead of just the ones we think
423 are interesting. It gets set if we look for a DIE in the
424 hash table and don't find it. */
425 unsigned int load_all_dies
: 1;
427 /* Non-zero if this CU is from .debug_types.
428 Otherwise it's from .debug_info. */
429 unsigned int from_debug_types
: 1;
431 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
432 of the CU cache it gets reset to NULL again. */
433 struct dwarf2_cu
*cu
;
435 /* The corresponding objfile. */
436 struct objfile
*objfile
;
438 /* When using partial symbol tables, the 'psymtab' field is active.
439 Otherwise the 'quick' field is active. */
442 /* The partial symbol table associated with this compilation unit,
443 or NULL for partial units (which do not have an associated
445 struct partial_symtab
*psymtab
;
447 /* Data needed by the "quick" functions. */
448 struct dwarf2_per_cu_quick_data
*quick
;
452 /* Entry in the signatured_types hash table. */
454 struct signatured_type
458 /* Offset in .debug_types of the TU (type_unit) for this type. */
461 /* Offset in .debug_types of the type defined by this TU. */
462 unsigned int type_offset
;
464 /* The CU(/TU) of this type. */
465 struct dwarf2_per_cu_data per_cu
;
468 /* Struct used to pass misc. parameters to read_die_and_children, et
469 al. which are used for both .debug_info and .debug_types dies.
470 All parameters here are unchanging for the life of the call. This
471 struct exists to abstract away the constant parameters of die
474 struct die_reader_specs
476 /* The bfd of this objfile. */
479 /* The CU of the DIE we are parsing. */
480 struct dwarf2_cu
*cu
;
482 /* Pointer to start of section buffer.
483 This is either the start of .debug_info or .debug_types. */
484 const gdb_byte
*buffer
;
487 /* The line number information for a compilation unit (found in the
488 .debug_line section) begins with a "statement program header",
489 which contains the following information. */
492 unsigned int total_length
;
493 unsigned short version
;
494 unsigned int header_length
;
495 unsigned char minimum_instruction_length
;
496 unsigned char maximum_ops_per_instruction
;
497 unsigned char default_is_stmt
;
499 unsigned char line_range
;
500 unsigned char opcode_base
;
502 /* standard_opcode_lengths[i] is the number of operands for the
503 standard opcode whose value is i. This means that
504 standard_opcode_lengths[0] is unused, and the last meaningful
505 element is standard_opcode_lengths[opcode_base - 1]. */
506 unsigned char *standard_opcode_lengths
;
508 /* The include_directories table. NOTE! These strings are not
509 allocated with xmalloc; instead, they are pointers into
510 debug_line_buffer. If you try to free them, `free' will get
512 unsigned int num_include_dirs
, include_dirs_size
;
515 /* The file_names table. NOTE! These strings are not allocated
516 with xmalloc; instead, they are pointers into debug_line_buffer.
517 Don't try to free them directly. */
518 unsigned int num_file_names
, file_names_size
;
522 unsigned int dir_index
;
523 unsigned int mod_time
;
525 int included_p
; /* Non-zero if referenced by the Line Number Program. */
526 struct symtab
*symtab
; /* The associated symbol table, if any. */
529 /* The start and end of the statement program following this
530 header. These point into dwarf2_per_objfile->line_buffer. */
531 gdb_byte
*statement_program_start
, *statement_program_end
;
534 /* When we construct a partial symbol table entry we only
535 need this much information. */
536 struct partial_die_info
538 /* Offset of this DIE. */
541 /* DWARF-2 tag for this DIE. */
542 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
544 /* Assorted flags describing the data found in this DIE. */
545 unsigned int has_children
: 1;
546 unsigned int is_external
: 1;
547 unsigned int is_declaration
: 1;
548 unsigned int has_type
: 1;
549 unsigned int has_specification
: 1;
550 unsigned int has_pc_info
: 1;
552 /* Flag set if the SCOPE field of this structure has been
554 unsigned int scope_set
: 1;
556 /* Flag set if the DIE has a byte_size attribute. */
557 unsigned int has_byte_size
: 1;
559 /* Flag set if any of the DIE's children are template arguments. */
560 unsigned int has_template_arguments
: 1;
562 /* Flag set if fixup_partial_die has been called on this die. */
563 unsigned int fixup_called
: 1;
565 /* The name of this DIE. Normally the value of DW_AT_name, but
566 sometimes a default name for unnamed DIEs. */
569 /* The linkage name, if present. */
570 const char *linkage_name
;
572 /* The scope to prepend to our children. This is generally
573 allocated on the comp_unit_obstack, so will disappear
574 when this compilation unit leaves the cache. */
577 /* The location description associated with this DIE, if any. */
578 struct dwarf_block
*locdesc
;
580 /* If HAS_PC_INFO, the PC range associated with this DIE. */
584 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
585 DW_AT_sibling, if any. */
586 /* NOTE: This member isn't strictly necessary, read_partial_die could
587 return DW_AT_sibling values to its caller load_partial_dies. */
590 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
591 DW_AT_specification (or DW_AT_abstract_origin or
593 unsigned int spec_offset
;
595 /* Pointers to this DIE's parent, first child, and next sibling,
597 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
600 /* This data structure holds the information of an abbrev. */
603 unsigned int number
; /* number identifying abbrev */
604 enum dwarf_tag tag
; /* dwarf tag */
605 unsigned short has_children
; /* boolean */
606 unsigned short num_attrs
; /* number of attributes */
607 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
608 struct abbrev_info
*next
; /* next in chain */
613 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
614 ENUM_BITFIELD(dwarf_form
) form
: 16;
617 /* Attributes have a name and a value. */
620 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
621 ENUM_BITFIELD(dwarf_form
) form
: 15;
623 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
624 field should be in u.str (existing only for DW_STRING) but it is kept
625 here for better struct attribute alignment. */
626 unsigned int string_is_canonical
: 1;
631 struct dwarf_block
*blk
;
635 struct signatured_type
*signatured_type
;
640 /* This data structure holds a complete die structure. */
643 /* DWARF-2 tag for this DIE. */
644 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
646 /* Number of attributes */
647 unsigned char num_attrs
;
649 /* True if we're presently building the full type name for the
650 type derived from this DIE. */
651 unsigned char building_fullname
: 1;
656 /* Offset in .debug_info or .debug_types section. */
659 /* The dies in a compilation unit form an n-ary tree. PARENT
660 points to this die's parent; CHILD points to the first child of
661 this node; and all the children of a given node are chained
662 together via their SIBLING fields. */
663 struct die_info
*child
; /* Its first child, if any. */
664 struct die_info
*sibling
; /* Its next sibling, if any. */
665 struct die_info
*parent
; /* Its parent, if any. */
667 /* An array of attributes, with NUM_ATTRS elements. There may be
668 zero, but it's not common and zero-sized arrays are not
669 sufficiently portable C. */
670 struct attribute attrs
[1];
673 struct function_range
676 CORE_ADDR lowpc
, highpc
;
678 struct function_range
*next
;
681 /* Get at parts of an attribute structure. */
683 #define DW_STRING(attr) ((attr)->u.str)
684 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
685 #define DW_UNSND(attr) ((attr)->u.unsnd)
686 #define DW_BLOCK(attr) ((attr)->u.blk)
687 #define DW_SND(attr) ((attr)->u.snd)
688 #define DW_ADDR(attr) ((attr)->u.addr)
689 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
691 /* Blocks are a bunch of untyped bytes. */
698 #ifndef ATTR_ALLOC_CHUNK
699 #define ATTR_ALLOC_CHUNK 4
702 /* Allocate fields for structs, unions and enums in this size. */
703 #ifndef DW_FIELD_ALLOC_CHUNK
704 #define DW_FIELD_ALLOC_CHUNK 4
707 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
708 but this would require a corresponding change in unpack_field_as_long
710 static int bits_per_byte
= 8;
712 /* The routines that read and process dies for a C struct or C++ class
713 pass lists of data member fields and lists of member function fields
714 in an instance of a field_info structure, as defined below. */
717 /* List of data member and baseclasses fields. */
720 struct nextfield
*next
;
725 *fields
, *baseclasses
;
727 /* Number of fields (including baseclasses). */
730 /* Number of baseclasses. */
733 /* Set if the accesibility of one of the fields is not public. */
734 int non_public_fields
;
736 /* Member function fields array, entries are allocated in the order they
737 are encountered in the object file. */
740 struct nextfnfield
*next
;
741 struct fn_field fnfield
;
745 /* Member function fieldlist array, contains name of possibly overloaded
746 member function, number of overloaded member functions and a pointer
747 to the head of the member function field chain. */
752 struct nextfnfield
*head
;
756 /* Number of entries in the fnfieldlists array. */
759 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
760 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
761 struct typedef_field_list
763 struct typedef_field field
;
764 struct typedef_field_list
*next
;
767 unsigned typedef_field_list_count
;
770 /* One item on the queue of compilation units to read in full symbols
772 struct dwarf2_queue_item
774 struct dwarf2_per_cu_data
*per_cu
;
775 struct dwarf2_queue_item
*next
;
778 /* The current queue. */
779 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
781 /* Loaded secondary compilation units are kept in memory until they
782 have not been referenced for the processing of this many
783 compilation units. Set this to zero to disable caching. Cache
784 sizes of up to at least twenty will improve startup time for
785 typical inter-CU-reference binaries, at an obvious memory cost. */
786 static int dwarf2_max_cache_age
= 5;
788 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
789 struct cmd_list_element
*c
, const char *value
)
791 fprintf_filtered (file
, _("The upper bound on the age of cached "
792 "dwarf2 compilation units is %s.\n"),
797 /* Various complaints about symbol reading that don't abort the process. */
800 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
802 complaint (&symfile_complaints
,
803 _("statement list doesn't fit in .debug_line section"));
807 dwarf2_debug_line_missing_file_complaint (void)
809 complaint (&symfile_complaints
,
810 _(".debug_line section has line data without a file"));
814 dwarf2_debug_line_missing_end_sequence_complaint (void)
816 complaint (&symfile_complaints
,
817 _(".debug_line section has line "
818 "program sequence without an end"));
822 dwarf2_complex_location_expr_complaint (void)
824 complaint (&symfile_complaints
, _("location expression too complex"));
828 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
831 complaint (&symfile_complaints
,
832 _("const value length mismatch for '%s', got %d, expected %d"),
837 dwarf2_macros_too_long_complaint (void)
839 complaint (&symfile_complaints
,
840 _("macro info runs off end of `.debug_macinfo' section"));
844 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
846 complaint (&symfile_complaints
,
847 _("macro debug info contains a "
848 "malformed macro definition:\n`%s'"),
853 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
855 complaint (&symfile_complaints
,
856 _("invalid attribute class or form for '%s' in '%s'"),
860 /* local function prototypes */
862 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
864 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
867 static void dwarf2_build_psymtabs_hard (struct objfile
*);
869 static void scan_partial_symbols (struct partial_die_info
*,
870 CORE_ADDR
*, CORE_ADDR
*,
871 int, struct dwarf2_cu
*);
873 static void add_partial_symbol (struct partial_die_info
*,
876 static void add_partial_namespace (struct partial_die_info
*pdi
,
877 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
878 int need_pc
, struct dwarf2_cu
*cu
);
880 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
881 CORE_ADDR
*highpc
, int need_pc
,
882 struct dwarf2_cu
*cu
);
884 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
885 struct dwarf2_cu
*cu
);
887 static void add_partial_subprogram (struct partial_die_info
*pdi
,
888 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
889 int need_pc
, struct dwarf2_cu
*cu
);
891 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
892 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
893 bfd
*abfd
, struct dwarf2_cu
*cu
);
895 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
897 static void psymtab_to_symtab_1 (struct partial_symtab
*);
899 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
901 static void dwarf2_free_abbrev_table (void *);
903 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
906 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
909 static struct partial_die_info
*load_partial_dies (bfd
*,
910 gdb_byte
*, gdb_byte
*,
911 int, struct dwarf2_cu
*);
913 static gdb_byte
*read_partial_die (struct partial_die_info
*,
914 struct abbrev_info
*abbrev
,
916 gdb_byte
*, gdb_byte
*,
919 static struct partial_die_info
*find_partial_die (unsigned int,
922 static void fixup_partial_die (struct partial_die_info
*,
925 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
926 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
928 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
929 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
931 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
933 static int read_1_signed_byte (bfd
*, gdb_byte
*);
935 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
937 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
939 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
941 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
944 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
946 static LONGEST read_checked_initial_length_and_offset
947 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
948 unsigned int *, unsigned int *);
950 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
953 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
955 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
957 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
959 static char *read_indirect_string (bfd
*, gdb_byte
*,
960 const struct comp_unit_head
*,
963 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
965 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
967 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
969 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
971 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
974 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
978 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
979 struct dwarf2_cu
*cu
);
981 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
983 static struct die_info
*die_specification (struct die_info
*die
,
984 struct dwarf2_cu
**);
986 static void free_line_header (struct line_header
*lh
);
988 static void add_file_name (struct line_header
*, char *, unsigned int,
989 unsigned int, unsigned int);
991 static struct line_header
*(dwarf_decode_line_header
992 (unsigned int offset
,
993 bfd
*abfd
, struct dwarf2_cu
*cu
));
995 static void dwarf_decode_lines (struct line_header
*, const char *, bfd
*,
996 struct dwarf2_cu
*, struct partial_symtab
*);
998 static void dwarf2_start_subfile (char *, const char *, const char *);
1000 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1001 struct dwarf2_cu
*);
1003 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1004 struct dwarf2_cu
*, struct symbol
*);
1006 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1007 struct dwarf2_cu
*);
1009 static void dwarf2_const_value_attr (struct attribute
*attr
,
1012 struct obstack
*obstack
,
1013 struct dwarf2_cu
*cu
, long *value
,
1015 struct dwarf2_locexpr_baton
**baton
);
1017 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1019 static int need_gnat_info (struct dwarf2_cu
*);
1021 static struct type
*die_descriptive_type (struct die_info
*,
1022 struct dwarf2_cu
*);
1024 static void set_descriptive_type (struct type
*, struct die_info
*,
1025 struct dwarf2_cu
*);
1027 static struct type
*die_containing_type (struct die_info
*,
1028 struct dwarf2_cu
*);
1030 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1031 struct dwarf2_cu
*);
1033 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1035 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1037 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1039 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1040 const char *suffix
, int physname
,
1041 struct dwarf2_cu
*cu
);
1043 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1045 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1047 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1049 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1051 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1052 struct dwarf2_cu
*, struct partial_symtab
*);
1054 static int dwarf2_get_pc_bounds (struct die_info
*,
1055 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1056 struct partial_symtab
*);
1058 static void get_scope_pc_bounds (struct die_info
*,
1059 CORE_ADDR
*, CORE_ADDR
*,
1060 struct dwarf2_cu
*);
1062 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1063 CORE_ADDR
, struct dwarf2_cu
*);
1065 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1066 struct dwarf2_cu
*);
1068 static void dwarf2_attach_fields_to_type (struct field_info
*,
1069 struct type
*, struct dwarf2_cu
*);
1071 static void dwarf2_add_member_fn (struct field_info
*,
1072 struct die_info
*, struct type
*,
1073 struct dwarf2_cu
*);
1075 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1077 struct dwarf2_cu
*);
1079 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1081 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1083 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1085 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1087 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1089 static struct type
*read_module_type (struct die_info
*die
,
1090 struct dwarf2_cu
*cu
);
1092 static const char *namespace_name (struct die_info
*die
,
1093 int *is_anonymous
, struct dwarf2_cu
*);
1095 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1097 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1099 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1100 struct dwarf2_cu
*);
1102 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1104 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1106 gdb_byte
**new_info_ptr
,
1107 struct die_info
*parent
);
1109 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1111 gdb_byte
**new_info_ptr
,
1112 struct die_info
*parent
);
1114 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1116 gdb_byte
**new_info_ptr
,
1117 struct die_info
*parent
);
1119 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1120 struct die_info
**, gdb_byte
*,
1123 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1125 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1128 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1130 static const char *dwarf2_full_name (char *name
,
1131 struct die_info
*die
,
1132 struct dwarf2_cu
*cu
);
1134 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1135 struct dwarf2_cu
**);
1137 static char *dwarf_tag_name (unsigned int);
1139 static char *dwarf_attr_name (unsigned int);
1141 static char *dwarf_form_name (unsigned int);
1143 static char *dwarf_bool_name (unsigned int);
1145 static char *dwarf_type_encoding_name (unsigned int);
1148 static char *dwarf_cfi_name (unsigned int);
1151 static struct die_info
*sibling_die (struct die_info
*);
1153 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1155 static void dump_die_for_error (struct die_info
*);
1157 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1160 /*static*/ void dump_die (struct die_info
*, int max_level
);
1162 static void store_in_ref_table (struct die_info
*,
1163 struct dwarf2_cu
*);
1165 static int is_ref_attr (struct attribute
*);
1167 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1169 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1171 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1173 struct dwarf2_cu
**);
1175 static struct die_info
*follow_die_ref (struct die_info
*,
1177 struct dwarf2_cu
**);
1179 static struct die_info
*follow_die_sig (struct die_info
*,
1181 struct dwarf2_cu
**);
1183 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1184 unsigned int offset
);
1186 static void read_signatured_type (struct objfile
*,
1187 struct signatured_type
*type_sig
);
1189 /* memory allocation interface */
1191 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1193 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1195 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1197 static void initialize_cu_func_list (struct dwarf2_cu
*);
1199 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1200 struct dwarf2_cu
*);
1202 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1203 char *, bfd
*, struct dwarf2_cu
*);
1205 static int attr_form_is_block (struct attribute
*);
1207 static int attr_form_is_section_offset (struct attribute
*);
1209 static int attr_form_is_constant (struct attribute
*);
1211 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1212 struct dwarf2_loclist_baton
*baton
,
1213 struct attribute
*attr
);
1215 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1217 struct dwarf2_cu
*cu
);
1219 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1220 struct abbrev_info
*abbrev
,
1221 struct dwarf2_cu
*cu
);
1223 static void free_stack_comp_unit (void *);
1225 static hashval_t
partial_die_hash (const void *item
);
1227 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1229 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1230 (unsigned int offset
, struct objfile
*objfile
);
1232 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1233 (unsigned int offset
, struct objfile
*objfile
);
1235 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1236 struct objfile
*objfile
);
1238 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1239 struct die_info
*comp_unit_die
);
1241 static void free_one_comp_unit (void *);
1243 static void free_cached_comp_units (void *);
1245 static void age_cached_comp_units (void);
1247 static void free_one_cached_comp_unit (void *);
1249 static struct type
*set_die_type (struct die_info
*, struct type
*,
1250 struct dwarf2_cu
*);
1252 static void create_all_comp_units (struct objfile
*);
1254 static int create_debug_types_hash_table (struct objfile
*objfile
);
1256 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1259 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1261 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1262 struct dwarf2_per_cu_data
*);
1264 static void dwarf2_mark (struct dwarf2_cu
*);
1266 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1268 static struct type
*get_die_type_at_offset (unsigned int,
1269 struct dwarf2_per_cu_data
*per_cu
);
1271 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1273 static void dwarf2_release_queue (void *dummy
);
1275 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1276 struct objfile
*objfile
);
1278 static void process_queue (struct objfile
*objfile
);
1280 static void find_file_and_directory (struct die_info
*die
,
1281 struct dwarf2_cu
*cu
,
1282 char **name
, char **comp_dir
);
1284 static char *file_full_name (int file
, struct line_header
*lh
,
1285 const char *comp_dir
);
1287 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1290 unsigned int buffer_size
,
1293 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1294 struct dwarf2_cu
*cu
);
1296 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1300 /* Convert VALUE between big- and little-endian. */
1302 byte_swap (offset_type value
)
1306 result
= (value
& 0xff) << 24;
1307 result
|= (value
& 0xff00) << 8;
1308 result
|= (value
& 0xff0000) >> 8;
1309 result
|= (value
& 0xff000000) >> 24;
1313 #define MAYBE_SWAP(V) byte_swap (V)
1316 #define MAYBE_SWAP(V) (V)
1317 #endif /* WORDS_BIGENDIAN */
1319 /* The suffix for an index file. */
1320 #define INDEX_SUFFIX ".gdb-index"
1322 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1323 struct dwarf2_cu
*cu
);
1325 /* Try to locate the sections we need for DWARF 2 debugging
1326 information and return true if we have enough to do something. */
1329 dwarf2_has_info (struct objfile
*objfile
)
1331 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1332 if (!dwarf2_per_objfile
)
1334 /* Initialize per-objfile state. */
1335 struct dwarf2_per_objfile
*data
1336 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1338 memset (data
, 0, sizeof (*data
));
1339 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1340 dwarf2_per_objfile
= data
;
1342 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1343 dwarf2_per_objfile
->objfile
= objfile
;
1345 return (dwarf2_per_objfile
->info
.asection
!= NULL
1346 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1349 /* When loading sections, we can either look for ".<name>", or for
1350 * ".z<name>", which indicates a compressed section. */
1353 section_is_p (const char *section_name
, const char *name
)
1355 return (section_name
[0] == '.'
1356 && (strcmp (section_name
+ 1, name
) == 0
1357 || (section_name
[1] == 'z'
1358 && strcmp (section_name
+ 2, name
) == 0)));
1361 /* This function is mapped across the sections and remembers the
1362 offset and size of each of the debugging sections we are interested
1366 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1368 if (section_is_p (sectp
->name
, INFO_SECTION
))
1370 dwarf2_per_objfile
->info
.asection
= sectp
;
1371 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1373 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1375 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1376 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1378 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1380 dwarf2_per_objfile
->line
.asection
= sectp
;
1381 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1383 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1385 dwarf2_per_objfile
->loc
.asection
= sectp
;
1386 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1388 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1390 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1391 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1393 else if (section_is_p (sectp
->name
, STR_SECTION
))
1395 dwarf2_per_objfile
->str
.asection
= sectp
;
1396 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1398 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1400 dwarf2_per_objfile
->frame
.asection
= sectp
;
1401 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1403 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1405 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1407 if (aflag
& SEC_HAS_CONTENTS
)
1409 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1410 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1413 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1415 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1416 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1418 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1420 dwarf2_per_objfile
->types
.asection
= sectp
;
1421 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1423 else if (section_is_p (sectp
->name
, GDB_INDEX_SECTION
))
1425 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1426 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1429 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1430 && bfd_section_vma (abfd
, sectp
) == 0)
1431 dwarf2_per_objfile
->has_section_at_zero
= 1;
1434 /* Decompress a section that was compressed using zlib. Store the
1435 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1438 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1439 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1441 bfd
*abfd
= objfile
->obfd
;
1443 error (_("Support for zlib-compressed DWARF data (from '%s') "
1444 "is disabled in this copy of GDB"),
1445 bfd_get_filename (abfd
));
1447 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1448 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1449 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1450 bfd_size_type uncompressed_size
;
1451 gdb_byte
*uncompressed_buffer
;
1454 int header_size
= 12;
1456 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1457 || bfd_bread (compressed_buffer
,
1458 compressed_size
, abfd
) != compressed_size
)
1459 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1460 bfd_get_filename (abfd
));
1462 /* Read the zlib header. In this case, it should be "ZLIB" followed
1463 by the uncompressed section size, 8 bytes in big-endian order. */
1464 if (compressed_size
< header_size
1465 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1466 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1467 bfd_get_filename (abfd
));
1468 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1469 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1470 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1471 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1472 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1473 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1474 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1475 uncompressed_size
+= compressed_buffer
[11];
1477 /* It is possible the section consists of several compressed
1478 buffers concatenated together, so we uncompress in a loop. */
1482 strm
.avail_in
= compressed_size
- header_size
;
1483 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1484 strm
.avail_out
= uncompressed_size
;
1485 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1487 rc
= inflateInit (&strm
);
1488 while (strm
.avail_in
> 0)
1491 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1492 bfd_get_filename (abfd
), rc
);
1493 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1494 + (uncompressed_size
- strm
.avail_out
));
1495 rc
= inflate (&strm
, Z_FINISH
);
1496 if (rc
!= Z_STREAM_END
)
1497 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1498 bfd_get_filename (abfd
), rc
);
1499 rc
= inflateReset (&strm
);
1501 rc
= inflateEnd (&strm
);
1503 || strm
.avail_out
!= 0)
1504 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1505 bfd_get_filename (abfd
), rc
);
1507 do_cleanups (cleanup
);
1508 *outbuf
= uncompressed_buffer
;
1509 *outsize
= uncompressed_size
;
1513 /* A helper function that decides whether a section is empty. */
1516 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1518 return info
->asection
== NULL
|| info
->size
== 0;
1521 /* Read the contents of the section SECTP from object file specified by
1522 OBJFILE, store info about the section into INFO.
1523 If the section is compressed, uncompress it before returning. */
1526 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1528 bfd
*abfd
= objfile
->obfd
;
1529 asection
*sectp
= info
->asection
;
1530 gdb_byte
*buf
, *retbuf
;
1531 unsigned char header
[4];
1535 info
->buffer
= NULL
;
1536 info
->was_mmapped
= 0;
1539 if (dwarf2_section_empty_p (info
))
1542 /* Check if the file has a 4-byte header indicating compression. */
1543 if (info
->size
> sizeof (header
)
1544 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1545 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1547 /* Upon decompression, update the buffer and its size. */
1548 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1550 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1558 pagesize
= getpagesize ();
1560 /* Only try to mmap sections which are large enough: we don't want to
1561 waste space due to fragmentation. Also, only try mmap for sections
1562 without relocations. */
1564 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1566 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1567 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1568 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1569 MAP_PRIVATE
, pg_offset
);
1571 if (retbuf
!= MAP_FAILED
)
1573 info
->was_mmapped
= 1;
1574 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1575 #if HAVE_POSIX_MADVISE
1576 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1583 /* If we get here, we are a normal, not-compressed section. */
1585 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1587 /* When debugging .o files, we may need to apply relocations; see
1588 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1589 We never compress sections in .o files, so we only need to
1590 try this when the section is not compressed. */
1591 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1594 info
->buffer
= retbuf
;
1598 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1599 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1600 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1601 bfd_get_filename (abfd
));
1604 /* A helper function that returns the size of a section in a safe way.
1605 If you are positive that the section has been read before using the
1606 size, then it is safe to refer to the dwarf2_section_info object's
1607 "size" field directly. In other cases, you must call this
1608 function, because for compressed sections the size field is not set
1609 correctly until the section has been read. */
1611 static bfd_size_type
1612 dwarf2_section_size (struct objfile
*objfile
,
1613 struct dwarf2_section_info
*info
)
1616 dwarf2_read_section (objfile
, info
);
1620 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1624 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1625 asection
**sectp
, gdb_byte
**bufp
,
1626 bfd_size_type
*sizep
)
1628 struct dwarf2_per_objfile
*data
1629 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1630 struct dwarf2_section_info
*info
;
1632 /* We may see an objfile without any DWARF, in which case we just
1641 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1642 info
= &data
->eh_frame
;
1643 else if (section_is_p (section_name
, FRAME_SECTION
))
1644 info
= &data
->frame
;
1646 gdb_assert_not_reached ("unexpected section");
1648 dwarf2_read_section (objfile
, info
);
1650 *sectp
= info
->asection
;
1651 *bufp
= info
->buffer
;
1652 *sizep
= info
->size
;
1656 /* DWARF quick_symbols_functions support. */
1658 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1659 unique line tables, so we maintain a separate table of all .debug_line
1660 derived entries to support the sharing.
1661 All the quick functions need is the list of file names. We discard the
1662 line_header when we're done and don't need to record it here. */
1663 struct quick_file_names
1665 /* The offset in .debug_line of the line table. We hash on this. */
1666 unsigned int offset
;
1668 /* The number of entries in file_names, real_names. */
1669 unsigned int num_file_names
;
1671 /* The file names from the line table, after being run through
1673 const char **file_names
;
1675 /* The file names from the line table after being run through
1676 gdb_realpath. These are computed lazily. */
1677 const char **real_names
;
1680 /* When using the index (and thus not using psymtabs), each CU has an
1681 object of this type. This is used to hold information needed by
1682 the various "quick" methods. */
1683 struct dwarf2_per_cu_quick_data
1685 /* The file table. This can be NULL if there was no file table
1686 or it's currently not read in.
1687 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1688 struct quick_file_names
*file_names
;
1690 /* The corresponding symbol table. This is NULL if symbols for this
1691 CU have not yet been read. */
1692 struct symtab
*symtab
;
1694 /* A temporary mark bit used when iterating over all CUs in
1695 expand_symtabs_matching. */
1696 unsigned int mark
: 1;
1698 /* True if we've tried to read the file table and found there isn't one.
1699 There will be no point in trying to read it again next time. */
1700 unsigned int no_file_data
: 1;
1703 /* Hash function for a quick_file_names. */
1706 hash_file_name_entry (const void *e
)
1708 const struct quick_file_names
*file_data
= e
;
1710 return file_data
->offset
;
1713 /* Equality function for a quick_file_names. */
1716 eq_file_name_entry (const void *a
, const void *b
)
1718 const struct quick_file_names
*ea
= a
;
1719 const struct quick_file_names
*eb
= b
;
1721 return ea
->offset
== eb
->offset
;
1724 /* Delete function for a quick_file_names. */
1727 delete_file_name_entry (void *e
)
1729 struct quick_file_names
*file_data
= e
;
1732 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1734 xfree ((void*) file_data
->file_names
[i
]);
1735 if (file_data
->real_names
)
1736 xfree ((void*) file_data
->real_names
[i
]);
1739 /* The space for the struct itself lives on objfile_obstack,
1740 so we don't free it here. */
1743 /* Create a quick_file_names hash table. */
1746 create_quick_file_names_table (unsigned int nr_initial_entries
)
1748 return htab_create_alloc (nr_initial_entries
,
1749 hash_file_name_entry
, eq_file_name_entry
,
1750 delete_file_name_entry
, xcalloc
, xfree
);
1753 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1757 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1758 struct dwarf2_per_cu_data
*per_cu
)
1760 struct cleanup
*back_to
;
1762 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1764 queue_comp_unit (per_cu
, objfile
);
1766 if (per_cu
->from_debug_types
)
1767 read_signatured_type_at_offset (objfile
, per_cu
->offset
);
1769 load_full_comp_unit (per_cu
, objfile
);
1771 process_queue (objfile
);
1773 /* Age the cache, releasing compilation units that have not
1774 been used recently. */
1775 age_cached_comp_units ();
1777 do_cleanups (back_to
);
1780 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1781 the objfile from which this CU came. Returns the resulting symbol
1784 static struct symtab
*
1785 dw2_instantiate_symtab (struct objfile
*objfile
,
1786 struct dwarf2_per_cu_data
*per_cu
)
1788 if (!per_cu
->v
.quick
->symtab
)
1790 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1791 increment_reading_symtab ();
1792 dw2_do_instantiate_symtab (objfile
, per_cu
);
1793 do_cleanups (back_to
);
1795 return per_cu
->v
.quick
->symtab
;
1798 /* Return the CU given its index. */
1800 static struct dwarf2_per_cu_data
*
1801 dw2_get_cu (int index
)
1803 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1805 index
-= dwarf2_per_objfile
->n_comp_units
;
1806 return dwarf2_per_objfile
->type_comp_units
[index
];
1808 return dwarf2_per_objfile
->all_comp_units
[index
];
1811 /* A helper function that knows how to read a 64-bit value in a way
1812 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1816 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1818 if (sizeof (ULONGEST
) < 8)
1822 /* Ignore the upper 4 bytes if they are all zero. */
1823 for (i
= 0; i
< 4; ++i
)
1824 if (bytes
[i
+ 4] != 0)
1827 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1830 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1834 /* Read the CU list from the mapped index, and use it to create all
1835 the CU objects for this objfile. Return 0 if something went wrong,
1836 1 if everything went ok. */
1839 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1840 offset_type cu_list_elements
)
1844 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1845 dwarf2_per_objfile
->all_comp_units
1846 = obstack_alloc (&objfile
->objfile_obstack
,
1847 dwarf2_per_objfile
->n_comp_units
1848 * sizeof (struct dwarf2_per_cu_data
*));
1850 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1852 struct dwarf2_per_cu_data
*the_cu
;
1853 ULONGEST offset
, length
;
1855 if (!extract_cu_value (cu_list
, &offset
)
1856 || !extract_cu_value (cu_list
+ 8, &length
))
1860 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1861 struct dwarf2_per_cu_data
);
1862 the_cu
->offset
= offset
;
1863 the_cu
->length
= length
;
1864 the_cu
->objfile
= objfile
;
1865 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1866 struct dwarf2_per_cu_quick_data
);
1867 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1873 /* Create the signatured type hash table from the index. */
1876 create_signatured_type_table_from_index (struct objfile
*objfile
,
1877 const gdb_byte
*bytes
,
1878 offset_type elements
)
1881 htab_t sig_types_hash
;
1883 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1884 dwarf2_per_objfile
->type_comp_units
1885 = obstack_alloc (&objfile
->objfile_obstack
,
1886 dwarf2_per_objfile
->n_type_comp_units
1887 * sizeof (struct dwarf2_per_cu_data
*));
1889 sig_types_hash
= allocate_signatured_type_table (objfile
);
1891 for (i
= 0; i
< elements
; i
+= 3)
1893 struct signatured_type
*type_sig
;
1894 ULONGEST offset
, type_offset
, signature
;
1897 if (!extract_cu_value (bytes
, &offset
)
1898 || !extract_cu_value (bytes
+ 8, &type_offset
))
1900 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1903 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1904 struct signatured_type
);
1905 type_sig
->signature
= signature
;
1906 type_sig
->offset
= offset
;
1907 type_sig
->type_offset
= type_offset
;
1908 type_sig
->per_cu
.from_debug_types
= 1;
1909 type_sig
->per_cu
.offset
= offset
;
1910 type_sig
->per_cu
.objfile
= objfile
;
1911 type_sig
->per_cu
.v
.quick
1912 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1913 struct dwarf2_per_cu_quick_data
);
1915 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1918 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1921 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1926 /* Read the address map data from the mapped index, and use it to
1927 populate the objfile's psymtabs_addrmap. */
1930 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1932 const gdb_byte
*iter
, *end
;
1933 struct obstack temp_obstack
;
1934 struct addrmap
*mutable_map
;
1935 struct cleanup
*cleanup
;
1938 obstack_init (&temp_obstack
);
1939 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1940 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1942 iter
= index
->address_table
;
1943 end
= iter
+ index
->address_table_size
;
1945 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1949 ULONGEST hi
, lo
, cu_index
;
1950 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1952 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1954 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1957 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1958 dw2_get_cu (cu_index
));
1961 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1962 &objfile
->objfile_obstack
);
1963 do_cleanups (cleanup
);
1966 /* The hash function for strings in the mapped index. This is the same as
1967 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
1968 implementation. This is necessary because the hash function is tied to the
1969 format of the mapped index file. The hash values do not have to match with
1970 SYMBOL_HASH_NEXT. */
1973 mapped_index_string_hash (const void *p
)
1975 const unsigned char *str
= (const unsigned char *) p
;
1979 while ((c
= *str
++) != 0)
1980 r
= r
* 67 + c
- 113;
1985 /* Find a slot in the mapped index INDEX for the object named NAME.
1986 If NAME is found, set *VEC_OUT to point to the CU vector in the
1987 constant pool and return 1. If NAME cannot be found, return 0. */
1990 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
1991 offset_type
**vec_out
)
1993 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1995 offset_type slot
, step
;
1997 if (current_language
->la_language
== language_cplus
1998 || current_language
->la_language
== language_java
1999 || current_language
->la_language
== language_fortran
)
2001 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2003 const char *paren
= strchr (name
, '(');
2009 dup
= xmalloc (paren
- name
+ 1);
2010 memcpy (dup
, name
, paren
- name
);
2011 dup
[paren
- name
] = 0;
2013 make_cleanup (xfree
, dup
);
2018 hash
= mapped_index_string_hash (name
);
2019 slot
= hash
& (index
->symbol_table_slots
- 1);
2020 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2024 /* Convert a slot number to an offset into the table. */
2025 offset_type i
= 2 * slot
;
2027 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2029 do_cleanups (back_to
);
2033 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2034 if (!strcmp (name
, str
))
2036 *vec_out
= (offset_type
*) (index
->constant_pool
2037 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2038 do_cleanups (back_to
);
2042 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2046 /* Read the index file. If everything went ok, initialize the "quick"
2047 elements of all the CUs and return 1. Otherwise, return 0. */
2050 dwarf2_read_index (struct objfile
*objfile
)
2053 struct mapped_index
*map
;
2054 offset_type
*metadata
;
2055 const gdb_byte
*cu_list
;
2056 const gdb_byte
*types_list
= NULL
;
2057 offset_type version
, cu_list_elements
;
2058 offset_type types_list_elements
= 0;
2061 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2064 /* Older elfutils strip versions could keep the section in the main
2065 executable while splitting it for the separate debug info file. */
2066 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2067 & SEC_HAS_CONTENTS
) == 0)
2070 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2072 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2073 /* Version check. */
2074 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2075 /* Versions earlier than 3 emitted every copy of a psymbol. This
2076 causes the index to behave very poorly for certain requests. Version 3
2077 contained incomplete addrmap. So, it seems better to just ignore such
2081 /* Indexes with higher version than the one supported by GDB may be no
2082 longer backward compatible. */
2086 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2087 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2089 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2092 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2093 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2097 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2098 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2099 - MAYBE_SWAP (metadata
[i
]))
2103 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2104 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2105 - MAYBE_SWAP (metadata
[i
]));
2108 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2109 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2110 - MAYBE_SWAP (metadata
[i
]))
2111 / (2 * sizeof (offset_type
)));
2114 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2116 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2119 if (types_list_elements
2120 && !create_signatured_type_table_from_index (objfile
, types_list
,
2121 types_list_elements
))
2124 create_addrmap_from_index (objfile
, map
);
2126 dwarf2_per_objfile
->index_table
= map
;
2127 dwarf2_per_objfile
->using_index
= 1;
2128 dwarf2_per_objfile
->quick_file_names_table
=
2129 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2134 /* A helper for the "quick" functions which sets the global
2135 dwarf2_per_objfile according to OBJFILE. */
2138 dw2_setup (struct objfile
*objfile
)
2140 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2141 gdb_assert (dwarf2_per_objfile
);
2144 /* A helper for the "quick" functions which attempts to read the line
2145 table for THIS_CU. */
2147 static struct quick_file_names
*
2148 dw2_get_file_names (struct objfile
*objfile
,
2149 struct dwarf2_per_cu_data
*this_cu
)
2151 bfd
*abfd
= objfile
->obfd
;
2152 struct line_header
*lh
;
2153 struct attribute
*attr
;
2154 struct cleanup
*cleanups
;
2155 struct die_info
*comp_unit_die
;
2156 struct dwarf2_section_info
* sec
;
2157 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2158 int has_children
, i
;
2159 struct dwarf2_cu cu
;
2160 unsigned int bytes_read
, buffer_size
;
2161 struct die_reader_specs reader_specs
;
2162 char *name
, *comp_dir
;
2164 struct quick_file_names
*qfn
;
2165 unsigned int line_offset
;
2167 if (this_cu
->v
.quick
->file_names
!= NULL
)
2168 return this_cu
->v
.quick
->file_names
;
2169 /* If we know there is no line data, no point in looking again. */
2170 if (this_cu
->v
.quick
->no_file_data
)
2173 init_one_comp_unit (&cu
, objfile
);
2174 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2176 if (this_cu
->from_debug_types
)
2177 sec
= &dwarf2_per_objfile
->types
;
2179 sec
= &dwarf2_per_objfile
->info
;
2180 dwarf2_read_section (objfile
, sec
);
2181 buffer_size
= sec
->size
;
2182 buffer
= sec
->buffer
;
2183 info_ptr
= buffer
+ this_cu
->offset
;
2184 beg_of_comp_unit
= info_ptr
;
2186 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2187 buffer
, buffer_size
,
2190 /* Complete the cu_header. */
2191 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2192 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2195 cu
.per_cu
= this_cu
;
2197 dwarf2_read_abbrevs (abfd
, &cu
);
2198 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2200 if (this_cu
->from_debug_types
)
2201 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2202 init_cu_die_reader (&reader_specs
, &cu
);
2203 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2209 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2212 struct quick_file_names find_entry
;
2214 line_offset
= DW_UNSND (attr
);
2216 /* We may have already read in this line header (TU line header sharing).
2217 If we have we're done. */
2218 find_entry
.offset
= line_offset
;
2219 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2220 &find_entry
, INSERT
);
2223 do_cleanups (cleanups
);
2224 this_cu
->v
.quick
->file_names
= *slot
;
2228 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2232 do_cleanups (cleanups
);
2233 this_cu
->v
.quick
->no_file_data
= 1;
2237 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2238 qfn
->offset
= line_offset
;
2239 gdb_assert (slot
!= NULL
);
2242 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2244 qfn
->num_file_names
= lh
->num_file_names
;
2245 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2246 lh
->num_file_names
* sizeof (char *));
2247 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2248 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2249 qfn
->real_names
= NULL
;
2251 free_line_header (lh
);
2252 do_cleanups (cleanups
);
2254 this_cu
->v
.quick
->file_names
= qfn
;
2258 /* A helper for the "quick" functions which computes and caches the
2259 real path for a given file name from the line table. */
2262 dw2_get_real_path (struct objfile
*objfile
,
2263 struct quick_file_names
*qfn
, int index
)
2265 if (qfn
->real_names
== NULL
)
2266 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2267 qfn
->num_file_names
, sizeof (char *));
2269 if (qfn
->real_names
[index
] == NULL
)
2270 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2272 return qfn
->real_names
[index
];
2275 static struct symtab
*
2276 dw2_find_last_source_symtab (struct objfile
*objfile
)
2280 dw2_setup (objfile
);
2281 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2282 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2285 /* Traversal function for dw2_forget_cached_source_info. */
2288 dw2_free_cached_file_names (void **slot
, void *info
)
2290 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2292 if (file_data
->real_names
)
2296 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2298 xfree ((void*) file_data
->real_names
[i
]);
2299 file_data
->real_names
[i
] = NULL
;
2307 dw2_forget_cached_source_info (struct objfile
*objfile
)
2309 dw2_setup (objfile
);
2311 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2312 dw2_free_cached_file_names
, NULL
);
2316 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2317 const char *full_path
, const char *real_path
,
2318 struct symtab
**result
)
2321 int check_basename
= lbasename (name
) == name
;
2322 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2324 dw2_setup (objfile
);
2326 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2327 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2330 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2331 struct quick_file_names
*file_data
;
2333 if (per_cu
->v
.quick
->symtab
)
2336 file_data
= dw2_get_file_names (objfile
, per_cu
);
2337 if (file_data
== NULL
)
2340 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2342 const char *this_name
= file_data
->file_names
[j
];
2344 if (FILENAME_CMP (name
, this_name
) == 0)
2346 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2350 if (check_basename
&& ! base_cu
2351 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2354 if (full_path
!= NULL
)
2356 const char *this_real_name
= dw2_get_real_path (objfile
,
2359 if (this_real_name
!= NULL
2360 && FILENAME_CMP (full_path
, this_real_name
) == 0)
2362 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2367 if (real_path
!= NULL
)
2369 const char *this_real_name
= dw2_get_real_path (objfile
,
2372 if (this_real_name
!= NULL
2373 && FILENAME_CMP (real_path
, this_real_name
) == 0)
2375 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2384 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2391 static struct symtab
*
2392 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2393 const char *name
, domain_enum domain
)
2395 /* We do all the work in the pre_expand_symtabs_matching hook
2400 /* A helper function that expands all symtabs that hold an object
2404 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2406 dw2_setup (objfile
);
2408 /* index_table is NULL if OBJF_READNOW. */
2409 if (dwarf2_per_objfile
->index_table
)
2413 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2416 offset_type i
, len
= MAYBE_SWAP (*vec
);
2417 for (i
= 0; i
< len
; ++i
)
2419 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2420 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2422 dw2_instantiate_symtab (objfile
, per_cu
);
2429 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2430 enum block_enum block_kind
, const char *name
,
2433 dw2_do_expand_symtabs_matching (objfile
, name
);
2437 dw2_print_stats (struct objfile
*objfile
)
2441 dw2_setup (objfile
);
2443 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2444 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2446 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2448 if (!per_cu
->v
.quick
->symtab
)
2451 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2455 dw2_dump (struct objfile
*objfile
)
2457 /* Nothing worth printing. */
2461 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2462 struct section_offsets
*delta
)
2464 /* There's nothing to relocate here. */
2468 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2469 const char *func_name
)
2471 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2475 dw2_expand_all_symtabs (struct objfile
*objfile
)
2479 dw2_setup (objfile
);
2481 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2482 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2484 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2486 dw2_instantiate_symtab (objfile
, per_cu
);
2491 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2492 const char *filename
)
2496 dw2_setup (objfile
);
2498 /* We don't need to consider type units here.
2499 This is only called for examining code, e.g. expand_line_sal.
2500 There can be an order of magnitude (or more) more type units
2501 than comp units, and we avoid them if we can. */
2503 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2506 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2507 struct quick_file_names
*file_data
;
2509 if (per_cu
->v
.quick
->symtab
)
2512 file_data
= dw2_get_file_names (objfile
, per_cu
);
2513 if (file_data
== NULL
)
2516 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2518 const char *this_name
= file_data
->file_names
[j
];
2519 if (FILENAME_CMP (this_name
, filename
) == 0)
2521 dw2_instantiate_symtab (objfile
, per_cu
);
2529 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2531 struct dwarf2_per_cu_data
*per_cu
;
2533 struct quick_file_names
*file_data
;
2535 dw2_setup (objfile
);
2537 /* index_table is NULL if OBJF_READNOW. */
2538 if (!dwarf2_per_objfile
->index_table
)
2541 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2545 /* Note that this just looks at the very first one named NAME -- but
2546 actually we are looking for a function. find_main_filename
2547 should be rewritten so that it doesn't require a custom hook. It
2548 could just use the ordinary symbol tables. */
2549 /* vec[0] is the length, which must always be >0. */
2550 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2552 file_data
= dw2_get_file_names (objfile
, per_cu
);
2553 if (file_data
== NULL
)
2556 return file_data
->file_names
[file_data
->num_file_names
- 1];
2560 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2561 struct objfile
*objfile
, int global
,
2562 int (*callback
) (struct block
*,
2563 struct symbol
*, void *),
2564 void *data
, symbol_compare_ftype
*match
,
2565 symbol_compare_ftype
*ordered_compare
)
2567 /* Currently unimplemented; used for Ada. The function can be called if the
2568 current language is Ada for a non-Ada objfile using GNU index. As Ada
2569 does not look for non-Ada symbols this function should just return. */
2573 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2574 int (*file_matcher
) (const char *, void *),
2575 int (*name_matcher
) (const char *, void *),
2576 enum search_domain kind
,
2581 struct mapped_index
*index
;
2583 dw2_setup (objfile
);
2585 /* index_table is NULL if OBJF_READNOW. */
2586 if (!dwarf2_per_objfile
->index_table
)
2588 index
= dwarf2_per_objfile
->index_table
;
2590 if (file_matcher
!= NULL
)
2591 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2592 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2595 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2596 struct quick_file_names
*file_data
;
2598 per_cu
->v
.quick
->mark
= 0;
2599 if (per_cu
->v
.quick
->symtab
)
2602 file_data
= dw2_get_file_names (objfile
, per_cu
);
2603 if (file_data
== NULL
)
2606 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2608 if (file_matcher (file_data
->file_names
[j
], data
))
2610 per_cu
->v
.quick
->mark
= 1;
2616 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2618 offset_type idx
= 2 * iter
;
2620 offset_type
*vec
, vec_len
, vec_idx
;
2622 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2625 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2627 if (! (*name_matcher
) (name
, data
))
2630 /* The name was matched, now expand corresponding CUs that were
2632 vec
= (offset_type
*) (index
->constant_pool
2633 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2634 vec_len
= MAYBE_SWAP (vec
[0]);
2635 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2637 struct dwarf2_per_cu_data
*per_cu
;
2639 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2640 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2641 dw2_instantiate_symtab (objfile
, per_cu
);
2646 static struct symtab
*
2647 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2648 struct minimal_symbol
*msymbol
,
2650 struct obj_section
*section
,
2653 struct dwarf2_per_cu_data
*data
;
2655 dw2_setup (objfile
);
2657 if (!objfile
->psymtabs_addrmap
)
2660 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2664 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2665 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2666 paddress (get_objfile_arch (objfile
), pc
));
2668 return dw2_instantiate_symtab (objfile
, data
);
2672 dw2_map_symbol_filenames (struct objfile
*objfile
,
2673 void (*fun
) (const char *, const char *, void *),
2678 dw2_setup (objfile
);
2680 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2681 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2684 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2685 struct quick_file_names
*file_data
;
2687 if (per_cu
->v
.quick
->symtab
)
2690 file_data
= dw2_get_file_names (objfile
, per_cu
);
2691 if (file_data
== NULL
)
2694 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2696 const char *this_real_name
= dw2_get_real_path (objfile
, file_data
,
2698 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2704 dw2_has_symbols (struct objfile
*objfile
)
2709 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2712 dw2_find_last_source_symtab
,
2713 dw2_forget_cached_source_info
,
2716 dw2_pre_expand_symtabs_matching
,
2720 dw2_expand_symtabs_for_function
,
2721 dw2_expand_all_symtabs
,
2722 dw2_expand_symtabs_with_filename
,
2723 dw2_find_symbol_file
,
2724 dw2_map_matching_symbols
,
2725 dw2_expand_symtabs_matching
,
2726 dw2_find_pc_sect_symtab
,
2727 dw2_map_symbol_filenames
2730 /* Initialize for reading DWARF for this objfile. Return 0 if this
2731 file will use psymtabs, or 1 if using the GNU index. */
2734 dwarf2_initialize_objfile (struct objfile
*objfile
)
2736 /* If we're about to read full symbols, don't bother with the
2737 indices. In this case we also don't care if some other debug
2738 format is making psymtabs, because they are all about to be
2740 if ((objfile
->flags
& OBJF_READNOW
))
2744 dwarf2_per_objfile
->using_index
= 1;
2745 create_all_comp_units (objfile
);
2746 create_debug_types_hash_table (objfile
);
2747 dwarf2_per_objfile
->quick_file_names_table
=
2748 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2750 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2751 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2753 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2755 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2756 struct dwarf2_per_cu_quick_data
);
2759 /* Return 1 so that gdb sees the "quick" functions. However,
2760 these functions will be no-ops because we will have expanded
2765 if (dwarf2_read_index (objfile
))
2773 /* Build a partial symbol table. */
2776 dwarf2_build_psymtabs (struct objfile
*objfile
)
2778 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2780 init_psymbol_list (objfile
, 1024);
2783 dwarf2_build_psymtabs_hard (objfile
);
2786 /* Return TRUE if OFFSET is within CU_HEADER. */
2789 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2791 unsigned int bottom
= cu_header
->offset
;
2792 unsigned int top
= (cu_header
->offset
2794 + cu_header
->initial_length_size
);
2796 return (offset
>= bottom
&& offset
< top
);
2799 /* Read in the comp unit header information from the debug_info at info_ptr.
2800 NOTE: This leaves members offset, first_die_offset to be filled in
2804 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2805 gdb_byte
*info_ptr
, bfd
*abfd
)
2808 unsigned int bytes_read
;
2810 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2811 cu_header
->initial_length_size
= bytes_read
;
2812 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2813 info_ptr
+= bytes_read
;
2814 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2816 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2818 info_ptr
+= bytes_read
;
2819 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2821 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2822 if (signed_addr
< 0)
2823 internal_error (__FILE__
, __LINE__
,
2824 _("read_comp_unit_head: dwarf from non elf file"));
2825 cu_header
->signed_addr_p
= signed_addr
;
2831 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2832 gdb_byte
*buffer
, unsigned int buffer_size
,
2835 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2837 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2839 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2840 error (_("Dwarf Error: wrong version in compilation unit header "
2841 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2842 bfd_get_filename (abfd
));
2844 if (header
->abbrev_offset
2845 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
2846 &dwarf2_per_objfile
->abbrev
))
2847 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2848 "(offset 0x%lx + 6) [in module %s]"),
2849 (long) header
->abbrev_offset
,
2850 (long) (beg_of_comp_unit
- buffer
),
2851 bfd_get_filename (abfd
));
2853 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2854 > buffer
+ buffer_size
)
2855 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2856 "(offset 0x%lx + 0) [in module %s]"),
2857 (long) header
->length
,
2858 (long) (beg_of_comp_unit
- buffer
),
2859 bfd_get_filename (abfd
));
2864 /* Read in the types comp unit header information from .debug_types entry at
2865 types_ptr. The result is a pointer to one past the end of the header. */
2868 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2869 ULONGEST
*signature
,
2870 gdb_byte
*types_ptr
, bfd
*abfd
)
2872 gdb_byte
*initial_types_ptr
= types_ptr
;
2874 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2875 &dwarf2_per_objfile
->types
);
2876 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2878 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2880 *signature
= read_8_bytes (abfd
, types_ptr
);
2882 types_ptr
+= cu_header
->offset_size
;
2883 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2888 /* Allocate a new partial symtab for file named NAME and mark this new
2889 partial symtab as being an include of PST. */
2892 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2893 struct objfile
*objfile
)
2895 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2897 subpst
->section_offsets
= pst
->section_offsets
;
2898 subpst
->textlow
= 0;
2899 subpst
->texthigh
= 0;
2901 subpst
->dependencies
= (struct partial_symtab
**)
2902 obstack_alloc (&objfile
->objfile_obstack
,
2903 sizeof (struct partial_symtab
*));
2904 subpst
->dependencies
[0] = pst
;
2905 subpst
->number_of_dependencies
= 1;
2907 subpst
->globals_offset
= 0;
2908 subpst
->n_global_syms
= 0;
2909 subpst
->statics_offset
= 0;
2910 subpst
->n_static_syms
= 0;
2911 subpst
->symtab
= NULL
;
2912 subpst
->read_symtab
= pst
->read_symtab
;
2915 /* No private part is necessary for include psymtabs. This property
2916 can be used to differentiate between such include psymtabs and
2917 the regular ones. */
2918 subpst
->read_symtab_private
= NULL
;
2921 /* Read the Line Number Program data and extract the list of files
2922 included by the source file represented by PST. Build an include
2923 partial symtab for each of these included files. */
2926 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2927 struct die_info
*die
,
2928 struct partial_symtab
*pst
)
2930 struct objfile
*objfile
= cu
->objfile
;
2931 bfd
*abfd
= objfile
->obfd
;
2932 struct line_header
*lh
= NULL
;
2933 struct attribute
*attr
;
2935 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2938 unsigned int line_offset
= DW_UNSND (attr
);
2940 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2943 return; /* No linetable, so no includes. */
2945 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2946 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
2948 free_line_header (lh
);
2952 hash_type_signature (const void *item
)
2954 const struct signatured_type
*type_sig
= item
;
2956 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2957 return type_sig
->signature
;
2961 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2963 const struct signatured_type
*lhs
= item_lhs
;
2964 const struct signatured_type
*rhs
= item_rhs
;
2966 return lhs
->signature
== rhs
->signature
;
2969 /* Allocate a hash table for signatured types. */
2972 allocate_signatured_type_table (struct objfile
*objfile
)
2974 return htab_create_alloc_ex (41,
2975 hash_type_signature
,
2978 &objfile
->objfile_obstack
,
2979 hashtab_obstack_allocate
,
2980 dummy_obstack_deallocate
);
2983 /* A helper function to add a signatured type CU to a list. */
2986 add_signatured_type_cu_to_list (void **slot
, void *datum
)
2988 struct signatured_type
*sigt
= *slot
;
2989 struct dwarf2_per_cu_data
***datap
= datum
;
2991 **datap
= &sigt
->per_cu
;
2997 /* Create the hash table of all entries in the .debug_types section.
2998 The result is zero if there is an error (e.g. missing .debug_types section),
2999 otherwise non-zero. */
3002 create_debug_types_hash_table (struct objfile
*objfile
)
3006 struct dwarf2_per_cu_data
**iter
;
3008 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
3009 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
3011 if (info_ptr
== NULL
)
3013 dwarf2_per_objfile
->signatured_types
= NULL
;
3017 types_htab
= allocate_signatured_type_table (objfile
);
3019 if (dwarf2_die_debug
)
3020 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3022 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
3023 + dwarf2_per_objfile
->types
.size
)
3025 unsigned int offset
;
3026 unsigned int offset_size
;
3027 unsigned int type_offset
;
3028 unsigned int length
, initial_length_size
;
3029 unsigned short version
;
3031 struct signatured_type
*type_sig
;
3033 gdb_byte
*ptr
= info_ptr
;
3035 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
3037 /* We need to read the type's signature in order to build the hash
3038 table, but we don't need to read anything else just yet. */
3040 /* Sanity check to ensure entire cu is present. */
3041 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
3042 if (ptr
+ length
+ initial_length_size
3043 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
3045 complaint (&symfile_complaints
,
3046 _("debug type entry runs off end "
3047 "of `.debug_types' section, ignored"));
3051 offset_size
= initial_length_size
== 4 ? 4 : 8;
3052 ptr
+= initial_length_size
;
3053 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3055 ptr
+= offset_size
; /* abbrev offset */
3056 ptr
+= 1; /* address size */
3057 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3059 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3061 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3062 memset (type_sig
, 0, sizeof (*type_sig
));
3063 type_sig
->signature
= signature
;
3064 type_sig
->offset
= offset
;
3065 type_sig
->type_offset
= type_offset
;
3066 type_sig
->per_cu
.objfile
= objfile
;
3067 type_sig
->per_cu
.from_debug_types
= 1;
3069 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3070 gdb_assert (slot
!= NULL
);
3073 if (dwarf2_die_debug
)
3074 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3075 offset
, phex (signature
, sizeof (signature
)));
3077 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3080 dwarf2_per_objfile
->signatured_types
= types_htab
;
3082 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3083 dwarf2_per_objfile
->type_comp_units
3084 = obstack_alloc (&objfile
->objfile_obstack
,
3085 dwarf2_per_objfile
->n_type_comp_units
3086 * sizeof (struct dwarf2_per_cu_data
*));
3087 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3088 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3089 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3090 == dwarf2_per_objfile
->n_type_comp_units
);
3095 /* Lookup a signature based type.
3096 Returns NULL if SIG is not present in the table. */
3098 static struct signatured_type
*
3099 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3101 struct signatured_type find_entry
, *entry
;
3103 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3105 complaint (&symfile_complaints
,
3106 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3110 find_entry
.signature
= sig
;
3111 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3115 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3118 init_cu_die_reader (struct die_reader_specs
*reader
,
3119 struct dwarf2_cu
*cu
)
3121 reader
->abfd
= cu
->objfile
->obfd
;
3123 if (cu
->per_cu
->from_debug_types
)
3125 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3126 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
3130 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3131 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3135 /* Find the base address of the compilation unit for range lists and
3136 location lists. It will normally be specified by DW_AT_low_pc.
3137 In DWARF-3 draft 4, the base address could be overridden by
3138 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3139 compilation units with discontinuous ranges. */
3142 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3144 struct attribute
*attr
;
3147 cu
->base_address
= 0;
3149 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3152 cu
->base_address
= DW_ADDR (attr
);
3157 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3160 cu
->base_address
= DW_ADDR (attr
);
3166 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3167 to combine the common parts.
3168 Process a compilation unit for a psymtab.
3169 BUFFER is a pointer to the beginning of the dwarf section buffer,
3170 either .debug_info or debug_types.
3171 INFO_PTR is a pointer to the start of the CU.
3172 Returns a pointer to the next CU. */
3175 process_psymtab_comp_unit (struct objfile
*objfile
,
3176 struct dwarf2_per_cu_data
*this_cu
,
3177 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3178 unsigned int buffer_size
)
3180 bfd
*abfd
= objfile
->obfd
;
3181 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3182 struct die_info
*comp_unit_die
;
3183 struct partial_symtab
*pst
;
3185 struct cleanup
*back_to_inner
;
3186 struct dwarf2_cu cu
;
3187 int has_children
, has_pc_info
;
3188 struct attribute
*attr
;
3189 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3190 struct die_reader_specs reader_specs
;
3191 const char *filename
;
3193 init_one_comp_unit (&cu
, objfile
);
3194 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3196 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3197 buffer
, buffer_size
,
3200 /* Complete the cu_header. */
3201 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3202 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3204 cu
.list_in_scope
= &file_symbols
;
3206 /* If this compilation unit was already read in, free the
3207 cached copy in order to read it in again. This is
3208 necessary because we skipped some symbols when we first
3209 read in the compilation unit (see load_partial_dies).
3210 This problem could be avoided, but the benefit is
3212 if (this_cu
->cu
!= NULL
)
3213 free_one_cached_comp_unit (this_cu
->cu
);
3215 /* Note that this is a pointer to our stack frame, being
3216 added to a global data structure. It will be cleaned up
3217 in free_stack_comp_unit when we finish with this
3218 compilation unit. */
3220 cu
.per_cu
= this_cu
;
3222 /* Read the abbrevs for this compilation unit into a table. */
3223 dwarf2_read_abbrevs (abfd
, &cu
);
3224 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3226 /* Read the compilation unit die. */
3227 if (this_cu
->from_debug_types
)
3228 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3229 init_cu_die_reader (&reader_specs
, &cu
);
3230 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3233 if (this_cu
->from_debug_types
)
3235 /* offset,length haven't been set yet for type units. */
3236 this_cu
->offset
= cu
.header
.offset
;
3237 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3239 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3241 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3242 + cu
.header
.initial_length_size
);
3243 do_cleanups (back_to_inner
);
3247 prepare_one_comp_unit (&cu
, comp_unit_die
);
3249 /* Allocate a new partial symbol table structure. */
3250 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3251 if (attr
== NULL
|| !DW_STRING (attr
))
3254 filename
= DW_STRING (attr
);
3255 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3257 /* TEXTLOW and TEXTHIGH are set below. */
3259 objfile
->global_psymbols
.next
,
3260 objfile
->static_psymbols
.next
);
3262 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3264 pst
->dirname
= DW_STRING (attr
);
3266 pst
->read_symtab_private
= this_cu
;
3268 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3270 /* Store the function that reads in the rest of the symbol table. */
3271 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3273 this_cu
->v
.psymtab
= pst
;
3275 dwarf2_find_base_address (comp_unit_die
, &cu
);
3277 /* Possibly set the default values of LOWPC and HIGHPC from
3279 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3280 &best_highpc
, &cu
, pst
);
3281 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3282 /* Store the contiguous range if it is not empty; it can be empty for
3283 CUs with no code. */
3284 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3285 best_lowpc
+ baseaddr
,
3286 best_highpc
+ baseaddr
- 1, pst
);
3288 /* Check if comp unit has_children.
3289 If so, read the rest of the partial symbols from this comp unit.
3290 If not, there's no more debug_info for this comp unit. */
3293 struct partial_die_info
*first_die
;
3294 CORE_ADDR lowpc
, highpc
;
3296 lowpc
= ((CORE_ADDR
) -1);
3297 highpc
= ((CORE_ADDR
) 0);
3299 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3301 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3302 ! has_pc_info
, &cu
);
3304 /* If we didn't find a lowpc, set it to highpc to avoid
3305 complaints from `maint check'. */
3306 if (lowpc
== ((CORE_ADDR
) -1))
3309 /* If the compilation unit didn't have an explicit address range,
3310 then use the information extracted from its child dies. */
3314 best_highpc
= highpc
;
3317 pst
->textlow
= best_lowpc
+ baseaddr
;
3318 pst
->texthigh
= best_highpc
+ baseaddr
;
3320 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3321 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3322 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3323 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3324 sort_pst_symbols (pst
);
3326 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3327 + cu
.header
.initial_length_size
);
3329 if (this_cu
->from_debug_types
)
3331 /* It's not clear we want to do anything with stmt lists here.
3332 Waiting to see what gcc ultimately does. */
3336 /* Get the list of files included in the current compilation unit,
3337 and build a psymtab for each of them. */
3338 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3341 do_cleanups (back_to_inner
);
3346 /* Traversal function for htab_traverse_noresize.
3347 Process one .debug_types comp-unit. */
3350 process_type_comp_unit (void **slot
, void *info
)
3352 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3353 struct objfile
*objfile
= (struct objfile
*) info
;
3354 struct dwarf2_per_cu_data
*this_cu
;
3356 this_cu
= &entry
->per_cu
;
3358 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3359 process_psymtab_comp_unit (objfile
, this_cu
,
3360 dwarf2_per_objfile
->types
.buffer
,
3361 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
3362 dwarf2_per_objfile
->types
.size
);
3367 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3368 Build partial symbol tables for the .debug_types comp-units. */
3371 build_type_psymtabs (struct objfile
*objfile
)
3373 if (! create_debug_types_hash_table (objfile
))
3376 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3377 process_type_comp_unit
, objfile
);
3380 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3383 psymtabs_addrmap_cleanup (void *o
)
3385 struct objfile
*objfile
= o
;
3387 objfile
->psymtabs_addrmap
= NULL
;
3390 /* Build the partial symbol table by doing a quick pass through the
3391 .debug_info and .debug_abbrev sections. */
3394 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3397 struct cleanup
*back_to
, *addrmap_cleanup
;
3398 struct obstack temp_obstack
;
3400 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3402 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3403 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3405 /* Any cached compilation units will be linked by the per-objfile
3406 read_in_chain. Make sure to free them when we're done. */
3407 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3409 build_type_psymtabs (objfile
);
3411 create_all_comp_units (objfile
);
3413 /* Create a temporary address map on a temporary obstack. We later
3414 copy this to the final obstack. */
3415 obstack_init (&temp_obstack
);
3416 make_cleanup_obstack_free (&temp_obstack
);
3417 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3418 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3420 /* Since the objects we're extracting from .debug_info vary in
3421 length, only the individual functions to extract them (like
3422 read_comp_unit_head and load_partial_die) can really know whether
3423 the buffer is large enough to hold another complete object.
3425 At the moment, they don't actually check that. If .debug_info
3426 holds just one extra byte after the last compilation unit's dies,
3427 then read_comp_unit_head will happily read off the end of the
3428 buffer. read_partial_die is similarly casual. Those functions
3431 For this loop condition, simply checking whether there's any data
3432 left at all should be sufficient. */
3434 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3435 + dwarf2_per_objfile
->info
.size
))
3437 struct dwarf2_per_cu_data
*this_cu
;
3439 this_cu
= dwarf2_find_comp_unit (info_ptr
3440 - dwarf2_per_objfile
->info
.buffer
,
3443 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3444 dwarf2_per_objfile
->info
.buffer
,
3446 dwarf2_per_objfile
->info
.size
);
3449 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3450 &objfile
->objfile_obstack
);
3451 discard_cleanups (addrmap_cleanup
);
3453 do_cleanups (back_to
);
3456 /* Load the partial DIEs for a secondary CU into memory. */
3459 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3460 struct objfile
*objfile
)
3462 bfd
*abfd
= objfile
->obfd
;
3463 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3464 struct die_info
*comp_unit_die
;
3465 struct dwarf2_cu
*cu
;
3466 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3468 struct die_reader_specs reader_specs
;
3471 gdb_assert (! this_cu
->from_debug_types
);
3473 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3474 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3475 beg_of_comp_unit
= info_ptr
;
3477 if (this_cu
->cu
== NULL
)
3479 cu
= xmalloc (sizeof (*cu
));
3480 init_one_comp_unit (cu
, objfile
);
3484 /* If an error occurs while loading, release our storage. */
3485 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3487 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3488 dwarf2_per_objfile
->info
.buffer
,
3489 dwarf2_per_objfile
->info
.size
,
3492 /* Complete the cu_header. */
3493 cu
->header
.offset
= this_cu
->offset
;
3494 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3496 /* Link this compilation unit into the compilation unit tree. */
3498 cu
->per_cu
= this_cu
;
3500 /* Link this CU into read_in_chain. */
3501 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3502 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3507 info_ptr
+= cu
->header
.first_die_offset
;
3510 /* Read the abbrevs for this compilation unit into a table. */
3511 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3512 dwarf2_read_abbrevs (abfd
, cu
);
3513 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3515 /* Read the compilation unit die. */
3516 init_cu_die_reader (&reader_specs
, cu
);
3517 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3520 prepare_one_comp_unit (cu
, comp_unit_die
);
3522 /* Check if comp unit has_children.
3523 If so, read the rest of the partial symbols from this comp unit.
3524 If not, there's no more debug_info for this comp unit. */
3526 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3528 do_cleanups (free_abbrevs_cleanup
);
3532 /* We've successfully allocated this compilation unit. Let our
3533 caller clean it up when finished with it. */
3534 discard_cleanups (free_cu_cleanup
);
3538 /* Create a list of all compilation units in OBJFILE. We do this only
3539 if an inter-comp-unit reference is found; presumably if there is one,
3540 there will be many, and one will occur early in the .debug_info section.
3541 So there's no point in building this list incrementally. */
3544 create_all_comp_units (struct objfile
*objfile
)
3548 struct dwarf2_per_cu_data
**all_comp_units
;
3551 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3552 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3556 all_comp_units
= xmalloc (n_allocated
3557 * sizeof (struct dwarf2_per_cu_data
*));
3559 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3560 + dwarf2_per_objfile
->info
.size
)
3562 unsigned int length
, initial_length_size
;
3563 struct dwarf2_per_cu_data
*this_cu
;
3564 unsigned int offset
;
3566 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3568 /* Read just enough information to find out where the next
3569 compilation unit is. */
3570 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3571 &initial_length_size
);
3573 /* Save the compilation unit for later lookup. */
3574 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3575 sizeof (struct dwarf2_per_cu_data
));
3576 memset (this_cu
, 0, sizeof (*this_cu
));
3577 this_cu
->offset
= offset
;
3578 this_cu
->length
= length
+ initial_length_size
;
3579 this_cu
->objfile
= objfile
;
3581 if (n_comp_units
== n_allocated
)
3584 all_comp_units
= xrealloc (all_comp_units
,
3586 * sizeof (struct dwarf2_per_cu_data
*));
3588 all_comp_units
[n_comp_units
++] = this_cu
;
3590 info_ptr
= info_ptr
+ this_cu
->length
;
3593 dwarf2_per_objfile
->all_comp_units
3594 = obstack_alloc (&objfile
->objfile_obstack
,
3595 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3596 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3597 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3598 xfree (all_comp_units
);
3599 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3602 /* Process all loaded DIEs for compilation unit CU, starting at
3603 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3604 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3605 DW_AT_ranges). If NEED_PC is set, then this function will set
3606 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3607 and record the covered ranges in the addrmap. */
3610 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3611 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3613 struct partial_die_info
*pdi
;
3615 /* Now, march along the PDI's, descending into ones which have
3616 interesting children but skipping the children of the other ones,
3617 until we reach the end of the compilation unit. */
3623 fixup_partial_die (pdi
, cu
);
3625 /* Anonymous namespaces or modules have no name but have interesting
3626 children, so we need to look at them. Ditto for anonymous
3629 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3630 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3634 case DW_TAG_subprogram
:
3635 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3637 case DW_TAG_constant
:
3638 case DW_TAG_variable
:
3639 case DW_TAG_typedef
:
3640 case DW_TAG_union_type
:
3641 if (!pdi
->is_declaration
)
3643 add_partial_symbol (pdi
, cu
);
3646 case DW_TAG_class_type
:
3647 case DW_TAG_interface_type
:
3648 case DW_TAG_structure_type
:
3649 if (!pdi
->is_declaration
)
3651 add_partial_symbol (pdi
, cu
);
3654 case DW_TAG_enumeration_type
:
3655 if (!pdi
->is_declaration
)
3656 add_partial_enumeration (pdi
, cu
);
3658 case DW_TAG_base_type
:
3659 case DW_TAG_subrange_type
:
3660 /* File scope base type definitions are added to the partial
3662 add_partial_symbol (pdi
, cu
);
3664 case DW_TAG_namespace
:
3665 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3668 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3675 /* If the die has a sibling, skip to the sibling. */
3677 pdi
= pdi
->die_sibling
;
3681 /* Functions used to compute the fully scoped name of a partial DIE.
3683 Normally, this is simple. For C++, the parent DIE's fully scoped
3684 name is concatenated with "::" and the partial DIE's name. For
3685 Java, the same thing occurs except that "." is used instead of "::".
3686 Enumerators are an exception; they use the scope of their parent
3687 enumeration type, i.e. the name of the enumeration type is not
3688 prepended to the enumerator.
3690 There are two complexities. One is DW_AT_specification; in this
3691 case "parent" means the parent of the target of the specification,
3692 instead of the direct parent of the DIE. The other is compilers
3693 which do not emit DW_TAG_namespace; in this case we try to guess
3694 the fully qualified name of structure types from their members'
3695 linkage names. This must be done using the DIE's children rather
3696 than the children of any DW_AT_specification target. We only need
3697 to do this for structures at the top level, i.e. if the target of
3698 any DW_AT_specification (if any; otherwise the DIE itself) does not
3701 /* Compute the scope prefix associated with PDI's parent, in
3702 compilation unit CU. The result will be allocated on CU's
3703 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3704 field. NULL is returned if no prefix is necessary. */
3706 partial_die_parent_scope (struct partial_die_info
*pdi
,
3707 struct dwarf2_cu
*cu
)
3709 char *grandparent_scope
;
3710 struct partial_die_info
*parent
, *real_pdi
;
3712 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3713 then this means the parent of the specification DIE. */
3716 while (real_pdi
->has_specification
)
3717 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3719 parent
= real_pdi
->die_parent
;
3723 if (parent
->scope_set
)
3724 return parent
->scope
;
3726 fixup_partial_die (parent
, cu
);
3728 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3730 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3731 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3732 Work around this problem here. */
3733 if (cu
->language
== language_cplus
3734 && parent
->tag
== DW_TAG_namespace
3735 && strcmp (parent
->name
, "::") == 0
3736 && grandparent_scope
== NULL
)
3738 parent
->scope
= NULL
;
3739 parent
->scope_set
= 1;
3743 if (parent
->tag
== DW_TAG_namespace
3744 || parent
->tag
== DW_TAG_module
3745 || parent
->tag
== DW_TAG_structure_type
3746 || parent
->tag
== DW_TAG_class_type
3747 || parent
->tag
== DW_TAG_interface_type
3748 || parent
->tag
== DW_TAG_union_type
3749 || parent
->tag
== DW_TAG_enumeration_type
)
3751 if (grandparent_scope
== NULL
)
3752 parent
->scope
= parent
->name
;
3754 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3756 parent
->name
, 0, cu
);
3758 else if (parent
->tag
== DW_TAG_enumerator
)
3759 /* Enumerators should not get the name of the enumeration as a prefix. */
3760 parent
->scope
= grandparent_scope
;
3763 /* FIXME drow/2004-04-01: What should we be doing with
3764 function-local names? For partial symbols, we should probably be
3766 complaint (&symfile_complaints
,
3767 _("unhandled containing DIE tag %d for DIE at %d"),
3768 parent
->tag
, pdi
->offset
);
3769 parent
->scope
= grandparent_scope
;
3772 parent
->scope_set
= 1;
3773 return parent
->scope
;
3776 /* Return the fully scoped name associated with PDI, from compilation unit
3777 CU. The result will be allocated with malloc. */
3779 partial_die_full_name (struct partial_die_info
*pdi
,
3780 struct dwarf2_cu
*cu
)
3784 /* If this is a template instantiation, we can not work out the
3785 template arguments from partial DIEs. So, unfortunately, we have
3786 to go through the full DIEs. At least any work we do building
3787 types here will be reused if full symbols are loaded later. */
3788 if (pdi
->has_template_arguments
)
3790 fixup_partial_die (pdi
, cu
);
3792 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3794 struct die_info
*die
;
3795 struct attribute attr
;
3796 struct dwarf2_cu
*ref_cu
= cu
;
3799 attr
.form
= DW_FORM_ref_addr
;
3800 attr
.u
.addr
= pdi
->offset
;
3801 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3803 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3807 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3808 if (parent_scope
== NULL
)
3811 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3815 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3817 struct objfile
*objfile
= cu
->objfile
;
3819 char *actual_name
= NULL
;
3820 const struct partial_symbol
*psym
= NULL
;
3822 int built_actual_name
= 0;
3824 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3826 actual_name
= partial_die_full_name (pdi
, cu
);
3828 built_actual_name
= 1;
3830 if (actual_name
== NULL
)
3831 actual_name
= pdi
->name
;
3835 case DW_TAG_subprogram
:
3836 if (pdi
->is_external
|| cu
->language
== language_ada
)
3838 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3839 of the global scope. But in Ada, we want to be able to access
3840 nested procedures globally. So all Ada subprograms are stored
3841 in the global scope. */
3842 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3843 mst_text, objfile); */
3844 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3846 VAR_DOMAIN
, LOC_BLOCK
,
3847 &objfile
->global_psymbols
,
3848 0, pdi
->lowpc
+ baseaddr
,
3849 cu
->language
, objfile
);
3853 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3854 mst_file_text, objfile); */
3855 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3857 VAR_DOMAIN
, LOC_BLOCK
,
3858 &objfile
->static_psymbols
,
3859 0, pdi
->lowpc
+ baseaddr
,
3860 cu
->language
, objfile
);
3863 case DW_TAG_constant
:
3865 struct psymbol_allocation_list
*list
;
3867 if (pdi
->is_external
)
3868 list
= &objfile
->global_psymbols
;
3870 list
= &objfile
->static_psymbols
;
3871 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3872 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
3873 list
, 0, 0, cu
->language
, objfile
);
3876 case DW_TAG_variable
:
3878 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3882 && !dwarf2_per_objfile
->has_section_at_zero
)
3884 /* A global or static variable may also have been stripped
3885 out by the linker if unused, in which case its address
3886 will be nullified; do not add such variables into partial
3887 symbol table then. */
3889 else if (pdi
->is_external
)
3892 Don't enter into the minimal symbol tables as there is
3893 a minimal symbol table entry from the ELF symbols already.
3894 Enter into partial symbol table if it has a location
3895 descriptor or a type.
3896 If the location descriptor is missing, new_symbol will create
3897 a LOC_UNRESOLVED symbol, the address of the variable will then
3898 be determined from the minimal symbol table whenever the variable
3900 The address for the partial symbol table entry is not
3901 used by GDB, but it comes in handy for debugging partial symbol
3904 if (pdi
->locdesc
|| pdi
->has_type
)
3905 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3907 VAR_DOMAIN
, LOC_STATIC
,
3908 &objfile
->global_psymbols
,
3910 cu
->language
, objfile
);
3914 /* Static Variable. Skip symbols without location descriptors. */
3915 if (pdi
->locdesc
== NULL
)
3917 if (built_actual_name
)
3918 xfree (actual_name
);
3921 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
3922 mst_file_data, objfile); */
3923 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3925 VAR_DOMAIN
, LOC_STATIC
,
3926 &objfile
->static_psymbols
,
3928 cu
->language
, objfile
);
3931 case DW_TAG_typedef
:
3932 case DW_TAG_base_type
:
3933 case DW_TAG_subrange_type
:
3934 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3936 VAR_DOMAIN
, LOC_TYPEDEF
,
3937 &objfile
->static_psymbols
,
3938 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3940 case DW_TAG_namespace
:
3941 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3943 VAR_DOMAIN
, LOC_TYPEDEF
,
3944 &objfile
->global_psymbols
,
3945 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3947 case DW_TAG_class_type
:
3948 case DW_TAG_interface_type
:
3949 case DW_TAG_structure_type
:
3950 case DW_TAG_union_type
:
3951 case DW_TAG_enumeration_type
:
3952 /* Skip external references. The DWARF standard says in the section
3953 about "Structure, Union, and Class Type Entries": "An incomplete
3954 structure, union or class type is represented by a structure,
3955 union or class entry that does not have a byte size attribute
3956 and that has a DW_AT_declaration attribute." */
3957 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3959 if (built_actual_name
)
3960 xfree (actual_name
);
3964 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3965 static vs. global. */
3966 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3968 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3969 (cu
->language
== language_cplus
3970 || cu
->language
== language_java
)
3971 ? &objfile
->global_psymbols
3972 : &objfile
->static_psymbols
,
3973 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3976 case DW_TAG_enumerator
:
3977 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3979 VAR_DOMAIN
, LOC_CONST
,
3980 (cu
->language
== language_cplus
3981 || cu
->language
== language_java
)
3982 ? &objfile
->global_psymbols
3983 : &objfile
->static_psymbols
,
3984 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3990 if (built_actual_name
)
3991 xfree (actual_name
);
3994 /* Read a partial die corresponding to a namespace; also, add a symbol
3995 corresponding to that namespace to the symbol table. NAMESPACE is
3996 the name of the enclosing namespace. */
3999 add_partial_namespace (struct partial_die_info
*pdi
,
4000 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4001 int need_pc
, struct dwarf2_cu
*cu
)
4003 /* Add a symbol for the namespace. */
4005 add_partial_symbol (pdi
, cu
);
4007 /* Now scan partial symbols in that namespace. */
4009 if (pdi
->has_children
)
4010 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4013 /* Read a partial die corresponding to a Fortran module. */
4016 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4017 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4019 /* Now scan partial symbols in that module. */
4021 if (pdi
->has_children
)
4022 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4025 /* Read a partial die corresponding to a subprogram and create a partial
4026 symbol for that subprogram. When the CU language allows it, this
4027 routine also defines a partial symbol for each nested subprogram
4028 that this subprogram contains.
4030 DIE my also be a lexical block, in which case we simply search
4031 recursively for suprograms defined inside that lexical block.
4032 Again, this is only performed when the CU language allows this
4033 type of definitions. */
4036 add_partial_subprogram (struct partial_die_info
*pdi
,
4037 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4038 int need_pc
, struct dwarf2_cu
*cu
)
4040 if (pdi
->tag
== DW_TAG_subprogram
)
4042 if (pdi
->has_pc_info
)
4044 if (pdi
->lowpc
< *lowpc
)
4045 *lowpc
= pdi
->lowpc
;
4046 if (pdi
->highpc
> *highpc
)
4047 *highpc
= pdi
->highpc
;
4051 struct objfile
*objfile
= cu
->objfile
;
4053 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4054 SECT_OFF_TEXT (objfile
));
4055 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4056 pdi
->lowpc
+ baseaddr
,
4057 pdi
->highpc
- 1 + baseaddr
,
4058 cu
->per_cu
->v
.psymtab
);
4060 if (!pdi
->is_declaration
)
4061 /* Ignore subprogram DIEs that do not have a name, they are
4062 illegal. Do not emit a complaint at this point, we will
4063 do so when we convert this psymtab into a symtab. */
4065 add_partial_symbol (pdi
, cu
);
4069 if (! pdi
->has_children
)
4072 if (cu
->language
== language_ada
)
4074 pdi
= pdi
->die_child
;
4077 fixup_partial_die (pdi
, cu
);
4078 if (pdi
->tag
== DW_TAG_subprogram
4079 || pdi
->tag
== DW_TAG_lexical_block
)
4080 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4081 pdi
= pdi
->die_sibling
;
4086 /* Read a partial die corresponding to an enumeration type. */
4089 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4090 struct dwarf2_cu
*cu
)
4092 struct partial_die_info
*pdi
;
4094 if (enum_pdi
->name
!= NULL
)
4095 add_partial_symbol (enum_pdi
, cu
);
4097 pdi
= enum_pdi
->die_child
;
4100 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4101 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4103 add_partial_symbol (pdi
, cu
);
4104 pdi
= pdi
->die_sibling
;
4108 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4109 Return the corresponding abbrev, or NULL if the number is zero (indicating
4110 an empty DIE). In either case *BYTES_READ will be set to the length of
4111 the initial number. */
4113 static struct abbrev_info
*
4114 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4115 struct dwarf2_cu
*cu
)
4117 bfd
*abfd
= cu
->objfile
->obfd
;
4118 unsigned int abbrev_number
;
4119 struct abbrev_info
*abbrev
;
4121 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4123 if (abbrev_number
== 0)
4126 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4129 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4130 abbrev_number
, bfd_get_filename (abfd
));
4136 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4137 Returns a pointer to the end of a series of DIEs, terminated by an empty
4138 DIE. Any children of the skipped DIEs will also be skipped. */
4141 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4143 struct abbrev_info
*abbrev
;
4144 unsigned int bytes_read
;
4148 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4150 return info_ptr
+ bytes_read
;
4152 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4156 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4157 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4158 abbrev corresponding to that skipped uleb128 should be passed in
4159 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4163 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4164 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4166 unsigned int bytes_read
;
4167 struct attribute attr
;
4168 bfd
*abfd
= cu
->objfile
->obfd
;
4169 unsigned int form
, i
;
4171 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4173 /* The only abbrev we care about is DW_AT_sibling. */
4174 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4176 read_attribute (&attr
, &abbrev
->attrs
[i
],
4177 abfd
, info_ptr
, cu
);
4178 if (attr
.form
== DW_FORM_ref_addr
)
4179 complaint (&symfile_complaints
,
4180 _("ignoring absolute DW_AT_sibling"));
4182 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4185 /* If it isn't DW_AT_sibling, skip this attribute. */
4186 form
= abbrev
->attrs
[i
].form
;
4190 case DW_FORM_ref_addr
:
4191 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4192 and later it is offset sized. */
4193 if (cu
->header
.version
== 2)
4194 info_ptr
+= cu
->header
.addr_size
;
4196 info_ptr
+= cu
->header
.offset_size
;
4199 info_ptr
+= cu
->header
.addr_size
;
4206 case DW_FORM_flag_present
:
4218 case DW_FORM_ref_sig8
:
4221 case DW_FORM_string
:
4222 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4223 info_ptr
+= bytes_read
;
4225 case DW_FORM_sec_offset
:
4227 info_ptr
+= cu
->header
.offset_size
;
4229 case DW_FORM_exprloc
:
4231 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4232 info_ptr
+= bytes_read
;
4234 case DW_FORM_block1
:
4235 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4237 case DW_FORM_block2
:
4238 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4240 case DW_FORM_block4
:
4241 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4245 case DW_FORM_ref_udata
:
4246 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4248 case DW_FORM_indirect
:
4249 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4250 info_ptr
+= bytes_read
;
4251 /* We need to continue parsing from here, so just go back to
4253 goto skip_attribute
;
4256 error (_("Dwarf Error: Cannot handle %s "
4257 "in DWARF reader [in module %s]"),
4258 dwarf_form_name (form
),
4259 bfd_get_filename (abfd
));
4263 if (abbrev
->has_children
)
4264 return skip_children (buffer
, info_ptr
, cu
);
4269 /* Locate ORIG_PDI's sibling.
4270 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4274 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4275 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4276 bfd
*abfd
, struct dwarf2_cu
*cu
)
4278 /* Do we know the sibling already? */
4280 if (orig_pdi
->sibling
)
4281 return orig_pdi
->sibling
;
4283 /* Are there any children to deal with? */
4285 if (!orig_pdi
->has_children
)
4288 /* Skip the children the long way. */
4290 return skip_children (buffer
, info_ptr
, cu
);
4293 /* Expand this partial symbol table into a full symbol table. */
4296 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4302 warning (_("bug: psymtab for %s is already read in."),
4309 printf_filtered (_("Reading in symbols for %s..."),
4311 gdb_flush (gdb_stdout
);
4314 /* Restore our global data. */
4315 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4316 dwarf2_objfile_data_key
);
4318 /* If this psymtab is constructed from a debug-only objfile, the
4319 has_section_at_zero flag will not necessarily be correct. We
4320 can get the correct value for this flag by looking at the data
4321 associated with the (presumably stripped) associated objfile. */
4322 if (pst
->objfile
->separate_debug_objfile_backlink
)
4324 struct dwarf2_per_objfile
*dpo_backlink
4325 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4326 dwarf2_objfile_data_key
);
4328 dwarf2_per_objfile
->has_section_at_zero
4329 = dpo_backlink
->has_section_at_zero
;
4332 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4334 psymtab_to_symtab_1 (pst
);
4336 /* Finish up the debug error message. */
4338 printf_filtered (_("done.\n"));
4343 /* Add PER_CU to the queue. */
4346 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4348 struct dwarf2_queue_item
*item
;
4351 item
= xmalloc (sizeof (*item
));
4352 item
->per_cu
= per_cu
;
4355 if (dwarf2_queue
== NULL
)
4356 dwarf2_queue
= item
;
4358 dwarf2_queue_tail
->next
= item
;
4360 dwarf2_queue_tail
= item
;
4363 /* Process the queue. */
4366 process_queue (struct objfile
*objfile
)
4368 struct dwarf2_queue_item
*item
, *next_item
;
4370 /* The queue starts out with one item, but following a DIE reference
4371 may load a new CU, adding it to the end of the queue. */
4372 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4374 if (dwarf2_per_objfile
->using_index
4375 ? !item
->per_cu
->v
.quick
->symtab
4376 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4377 process_full_comp_unit (item
->per_cu
);
4379 item
->per_cu
->queued
= 0;
4380 next_item
= item
->next
;
4384 dwarf2_queue_tail
= NULL
;
4387 /* Free all allocated queue entries. This function only releases anything if
4388 an error was thrown; if the queue was processed then it would have been
4389 freed as we went along. */
4392 dwarf2_release_queue (void *dummy
)
4394 struct dwarf2_queue_item
*item
, *last
;
4396 item
= dwarf2_queue
;
4399 /* Anything still marked queued is likely to be in an
4400 inconsistent state, so discard it. */
4401 if (item
->per_cu
->queued
)
4403 if (item
->per_cu
->cu
!= NULL
)
4404 free_one_cached_comp_unit (item
->per_cu
->cu
);
4405 item
->per_cu
->queued
= 0;
4413 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4416 /* Read in full symbols for PST, and anything it depends on. */
4419 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4421 struct dwarf2_per_cu_data
*per_cu
;
4422 struct cleanup
*back_to
;
4425 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4426 if (!pst
->dependencies
[i
]->readin
)
4428 /* Inform about additional files that need to be read in. */
4431 /* FIXME: i18n: Need to make this a single string. */
4432 fputs_filtered (" ", gdb_stdout
);
4434 fputs_filtered ("and ", gdb_stdout
);
4436 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4437 wrap_here (""); /* Flush output. */
4438 gdb_flush (gdb_stdout
);
4440 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4443 per_cu
= pst
->read_symtab_private
;
4447 /* It's an include file, no symbols to read for it.
4448 Everything is in the parent symtab. */
4453 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4456 /* Load the DIEs associated with PER_CU into memory. */
4459 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
4460 struct objfile
*objfile
)
4462 bfd
*abfd
= objfile
->obfd
;
4463 struct dwarf2_cu
*cu
;
4464 unsigned int offset
;
4465 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4466 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4467 struct attribute
*attr
;
4470 gdb_assert (! per_cu
->from_debug_types
);
4472 /* Set local variables from the partial symbol table info. */
4473 offset
= per_cu
->offset
;
4475 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4476 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4477 beg_of_comp_unit
= info_ptr
;
4479 if (per_cu
->cu
== NULL
)
4481 cu
= xmalloc (sizeof (*cu
));
4482 init_one_comp_unit (cu
, objfile
);
4486 /* If an error occurs while loading, release our storage. */
4487 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4489 /* Read in the comp_unit header. */
4490 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4492 /* Complete the cu_header. */
4493 cu
->header
.offset
= offset
;
4494 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4496 /* Read the abbrevs for this compilation unit. */
4497 dwarf2_read_abbrevs (abfd
, cu
);
4498 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4500 /* Link this compilation unit into the compilation unit tree. */
4502 cu
->per_cu
= per_cu
;
4504 /* Link this CU into read_in_chain. */
4505 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4506 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4511 info_ptr
+= cu
->header
.first_die_offset
;
4514 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4516 /* We try not to read any attributes in this function, because not
4517 all objfiles needed for references have been loaded yet, and symbol
4518 table processing isn't initialized. But we have to set the CU language,
4519 or we won't be able to build types correctly. */
4520 prepare_one_comp_unit (cu
, cu
->dies
);
4522 /* Similarly, if we do not read the producer, we can not apply
4523 producer-specific interpretation. */
4524 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4526 cu
->producer
= DW_STRING (attr
);
4530 do_cleanups (free_abbrevs_cleanup
);
4532 /* We've successfully allocated this compilation unit. Let our
4533 caller clean it up when finished with it. */
4534 discard_cleanups (free_cu_cleanup
);
4538 /* Add a DIE to the delayed physname list. */
4541 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4542 const char *name
, struct die_info
*die
,
4543 struct dwarf2_cu
*cu
)
4545 struct delayed_method_info mi
;
4547 mi
.fnfield_index
= fnfield_index
;
4551 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4554 /* A cleanup for freeing the delayed method list. */
4557 free_delayed_list (void *ptr
)
4559 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4560 if (cu
->method_list
!= NULL
)
4562 VEC_free (delayed_method_info
, cu
->method_list
);
4563 cu
->method_list
= NULL
;
4567 /* Compute the physnames of any methods on the CU's method list.
4569 The computation of method physnames is delayed in order to avoid the
4570 (bad) condition that one of the method's formal parameters is of an as yet
4574 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4577 struct delayed_method_info
*mi
;
4578 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4581 struct fn_fieldlist
*fn_flp
4582 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4583 physname
= (char *) dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4584 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4588 /* Generate full symbol information for PST and CU, whose DIEs have
4589 already been loaded into memory. */
4592 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4594 struct dwarf2_cu
*cu
= per_cu
->cu
;
4595 struct objfile
*objfile
= per_cu
->objfile
;
4596 CORE_ADDR lowpc
, highpc
;
4597 struct symtab
*symtab
;
4598 struct cleanup
*back_to
, *delayed_list_cleanup
;
4601 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4604 back_to
= make_cleanup (really_free_pendings
, NULL
);
4605 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4607 cu
->list_in_scope
= &file_symbols
;
4609 dwarf2_find_base_address (cu
->dies
, cu
);
4611 /* Do line number decoding in read_file_scope () */
4612 process_die (cu
->dies
, cu
);
4614 /* Now that we have processed all the DIEs in the CU, all the types
4615 should be complete, and it should now be safe to compute all of the
4617 compute_delayed_physnames (cu
);
4618 do_cleanups (delayed_list_cleanup
);
4620 /* Some compilers don't define a DW_AT_high_pc attribute for the
4621 compilation unit. If the DW_AT_high_pc is missing, synthesize
4622 it, by scanning the DIE's below the compilation unit. */
4623 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4625 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4627 /* Set symtab language to language from DW_AT_language.
4628 If the compilation is from a C file generated by language preprocessors,
4629 do not set the language if it was already deduced by start_subfile. */
4631 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4633 symtab
->language
= cu
->language
;
4636 if (dwarf2_per_objfile
->using_index
)
4637 per_cu
->v
.quick
->symtab
= symtab
;
4640 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4641 pst
->symtab
= symtab
;
4645 do_cleanups (back_to
);
4648 /* Process a die and its children. */
4651 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4655 case DW_TAG_padding
:
4657 case DW_TAG_compile_unit
:
4658 read_file_scope (die
, cu
);
4660 case DW_TAG_type_unit
:
4661 read_type_unit_scope (die
, cu
);
4663 case DW_TAG_subprogram
:
4664 case DW_TAG_inlined_subroutine
:
4665 read_func_scope (die
, cu
);
4667 case DW_TAG_lexical_block
:
4668 case DW_TAG_try_block
:
4669 case DW_TAG_catch_block
:
4670 read_lexical_block_scope (die
, cu
);
4672 case DW_TAG_class_type
:
4673 case DW_TAG_interface_type
:
4674 case DW_TAG_structure_type
:
4675 case DW_TAG_union_type
:
4676 process_structure_scope (die
, cu
);
4678 case DW_TAG_enumeration_type
:
4679 process_enumeration_scope (die
, cu
);
4682 /* These dies have a type, but processing them does not create
4683 a symbol or recurse to process the children. Therefore we can
4684 read them on-demand through read_type_die. */
4685 case DW_TAG_subroutine_type
:
4686 case DW_TAG_set_type
:
4687 case DW_TAG_array_type
:
4688 case DW_TAG_pointer_type
:
4689 case DW_TAG_ptr_to_member_type
:
4690 case DW_TAG_reference_type
:
4691 case DW_TAG_string_type
:
4694 case DW_TAG_base_type
:
4695 case DW_TAG_subrange_type
:
4696 case DW_TAG_typedef
:
4697 /* Add a typedef symbol for the type definition, if it has a
4699 new_symbol (die
, read_type_die (die
, cu
), cu
);
4701 case DW_TAG_common_block
:
4702 read_common_block (die
, cu
);
4704 case DW_TAG_common_inclusion
:
4706 case DW_TAG_namespace
:
4707 processing_has_namespace_info
= 1;
4708 read_namespace (die
, cu
);
4711 processing_has_namespace_info
= 1;
4712 read_module (die
, cu
);
4714 case DW_TAG_imported_declaration
:
4715 case DW_TAG_imported_module
:
4716 processing_has_namespace_info
= 1;
4717 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4718 || cu
->language
!= language_fortran
))
4719 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4720 dwarf_tag_name (die
->tag
));
4721 read_import_statement (die
, cu
);
4724 new_symbol (die
, NULL
, cu
);
4729 /* A helper function for dwarf2_compute_name which determines whether DIE
4730 needs to have the name of the scope prepended to the name listed in the
4734 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4736 struct attribute
*attr
;
4740 case DW_TAG_namespace
:
4741 case DW_TAG_typedef
:
4742 case DW_TAG_class_type
:
4743 case DW_TAG_interface_type
:
4744 case DW_TAG_structure_type
:
4745 case DW_TAG_union_type
:
4746 case DW_TAG_enumeration_type
:
4747 case DW_TAG_enumerator
:
4748 case DW_TAG_subprogram
:
4752 case DW_TAG_variable
:
4753 case DW_TAG_constant
:
4754 /* We only need to prefix "globally" visible variables. These include
4755 any variable marked with DW_AT_external or any variable that
4756 lives in a namespace. [Variables in anonymous namespaces
4757 require prefixing, but they are not DW_AT_external.] */
4759 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4761 struct dwarf2_cu
*spec_cu
= cu
;
4763 return die_needs_namespace (die_specification (die
, &spec_cu
),
4767 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4768 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4769 && die
->parent
->tag
!= DW_TAG_module
)
4771 /* A variable in a lexical block of some kind does not need a
4772 namespace, even though in C++ such variables may be external
4773 and have a mangled name. */
4774 if (die
->parent
->tag
== DW_TAG_lexical_block
4775 || die
->parent
->tag
== DW_TAG_try_block
4776 || die
->parent
->tag
== DW_TAG_catch_block
4777 || die
->parent
->tag
== DW_TAG_subprogram
)
4786 /* Retrieve the last character from a mem_file. */
4789 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4791 char *last_char_p
= (char *) object
;
4794 *last_char_p
= buffer
[length
- 1];
4797 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4798 compute the physname for the object, which include a method's
4799 formal parameters (C++/Java) and return type (Java).
4801 For Ada, return the DIE's linkage name rather than the fully qualified
4802 name. PHYSNAME is ignored..
4804 The result is allocated on the objfile_obstack and canonicalized. */
4807 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4811 name
= dwarf2_name (die
, cu
);
4813 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4814 compute it by typename_concat inside GDB. */
4815 if (cu
->language
== language_ada
4816 || (cu
->language
== language_fortran
&& physname
))
4818 /* For Ada unit, we prefer the linkage name over the name, as
4819 the former contains the exported name, which the user expects
4820 to be able to reference. Ideally, we want the user to be able
4821 to reference this entity using either natural or linkage name,
4822 but we haven't started looking at this enhancement yet. */
4823 struct attribute
*attr
;
4825 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4827 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4828 if (attr
&& DW_STRING (attr
))
4829 return DW_STRING (attr
);
4832 /* These are the only languages we know how to qualify names in. */
4834 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4835 || cu
->language
== language_fortran
))
4837 if (die_needs_namespace (die
, cu
))
4841 struct ui_file
*buf
;
4843 prefix
= determine_prefix (die
, cu
);
4844 buf
= mem_fileopen ();
4845 if (*prefix
!= '\0')
4847 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4850 fputs_unfiltered (prefixed_name
, buf
);
4851 xfree (prefixed_name
);
4854 fputs_unfiltered (name
, buf
);
4856 /* Template parameters may be specified in the DIE's DW_AT_name, or
4857 as children with DW_TAG_template_type_param or
4858 DW_TAG_value_type_param. If the latter, add them to the name
4859 here. If the name already has template parameters, then
4860 skip this step; some versions of GCC emit both, and
4861 it is more efficient to use the pre-computed name.
4863 Something to keep in mind about this process: it is very
4864 unlikely, or in some cases downright impossible, to produce
4865 something that will match the mangled name of a function.
4866 If the definition of the function has the same debug info,
4867 we should be able to match up with it anyway. But fallbacks
4868 using the minimal symbol, for instance to find a method
4869 implemented in a stripped copy of libstdc++, will not work.
4870 If we do not have debug info for the definition, we will have to
4871 match them up some other way.
4873 When we do name matching there is a related problem with function
4874 templates; two instantiated function templates are allowed to
4875 differ only by their return types, which we do not add here. */
4877 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
4879 struct attribute
*attr
;
4880 struct die_info
*child
;
4883 die
->building_fullname
= 1;
4885 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
4890 struct dwarf2_locexpr_baton
*baton
;
4893 if (child
->tag
!= DW_TAG_template_type_param
4894 && child
->tag
!= DW_TAG_template_value_param
)
4899 fputs_unfiltered ("<", buf
);
4903 fputs_unfiltered (", ", buf
);
4905 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
4908 complaint (&symfile_complaints
,
4909 _("template parameter missing DW_AT_type"));
4910 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
4913 type
= die_type (child
, cu
);
4915 if (child
->tag
== DW_TAG_template_type_param
)
4917 c_print_type (type
, "", buf
, -1, 0);
4921 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
4924 complaint (&symfile_complaints
,
4925 _("template parameter missing "
4926 "DW_AT_const_value"));
4927 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
4931 dwarf2_const_value_attr (attr
, type
, name
,
4932 &cu
->comp_unit_obstack
, cu
,
4933 &value
, &bytes
, &baton
);
4935 if (TYPE_NOSIGN (type
))
4936 /* GDB prints characters as NUMBER 'CHAR'. If that's
4937 changed, this can use value_print instead. */
4938 c_printchar (value
, type
, buf
);
4941 struct value_print_options opts
;
4944 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
4948 else if (bytes
!= NULL
)
4950 v
= allocate_value (type
);
4951 memcpy (value_contents_writeable (v
), bytes
,
4952 TYPE_LENGTH (type
));
4955 v
= value_from_longest (type
, value
);
4957 /* Specify decimal so that we do not depend on
4959 get_formatted_print_options (&opts
, 'd');
4961 value_print (v
, buf
, &opts
);
4967 die
->building_fullname
= 0;
4971 /* Close the argument list, with a space if necessary
4972 (nested templates). */
4973 char last_char
= '\0';
4974 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
4975 if (last_char
== '>')
4976 fputs_unfiltered (" >", buf
);
4978 fputs_unfiltered (">", buf
);
4982 /* For Java and C++ methods, append formal parameter type
4983 information, if PHYSNAME. */
4985 if (physname
&& die
->tag
== DW_TAG_subprogram
4986 && (cu
->language
== language_cplus
4987 || cu
->language
== language_java
))
4989 struct type
*type
= read_type_die (die
, cu
);
4991 c_type_print_args (type
, buf
, 1, cu
->language
);
4993 if (cu
->language
== language_java
)
4995 /* For java, we must append the return type to method
4997 if (die
->tag
== DW_TAG_subprogram
)
4998 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5001 else if (cu
->language
== language_cplus
)
5003 /* Assume that an artificial first parameter is
5004 "this", but do not crash if it is not. RealView
5005 marks unnamed (and thus unused) parameters as
5006 artificial; there is no way to differentiate
5008 if (TYPE_NFIELDS (type
) > 0
5009 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5010 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5011 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5013 fputs_unfiltered (" const", buf
);
5017 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
5019 ui_file_delete (buf
);
5021 if (cu
->language
== language_cplus
)
5024 = dwarf2_canonicalize_name (name
, cu
,
5025 &cu
->objfile
->objfile_obstack
);
5036 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5037 If scope qualifiers are appropriate they will be added. The result
5038 will be allocated on the objfile_obstack, or NULL if the DIE does
5039 not have a name. NAME may either be from a previous call to
5040 dwarf2_name or NULL.
5042 The output string will be canonicalized (if C++/Java). */
5045 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5047 return dwarf2_compute_name (name
, die
, cu
, 0);
5050 /* Construct a physname for the given DIE in CU. NAME may either be
5051 from a previous call to dwarf2_name or NULL. The result will be
5052 allocated on the objfile_objstack or NULL if the DIE does not have a
5055 The output string will be canonicalized (if C++/Java). */
5058 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5060 return dwarf2_compute_name (name
, die
, cu
, 1);
5063 /* Read the import statement specified by the given die and record it. */
5066 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5068 struct attribute
*import_attr
;
5069 struct die_info
*imported_die
;
5070 struct dwarf2_cu
*imported_cu
;
5071 const char *imported_name
;
5072 const char *imported_name_prefix
;
5073 const char *canonical_name
;
5074 const char *import_alias
;
5075 const char *imported_declaration
= NULL
;
5076 const char *import_prefix
;
5080 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5081 if (import_attr
== NULL
)
5083 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5084 dwarf_tag_name (die
->tag
));
5089 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5090 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5091 if (imported_name
== NULL
)
5093 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5095 The import in the following code:
5109 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5110 <52> DW_AT_decl_file : 1
5111 <53> DW_AT_decl_line : 6
5112 <54> DW_AT_import : <0x75>
5113 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5115 <5b> DW_AT_decl_file : 1
5116 <5c> DW_AT_decl_line : 2
5117 <5d> DW_AT_type : <0x6e>
5119 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5120 <76> DW_AT_byte_size : 4
5121 <77> DW_AT_encoding : 5 (signed)
5123 imports the wrong die ( 0x75 instead of 0x58 ).
5124 This case will be ignored until the gcc bug is fixed. */
5128 /* Figure out the local name after import. */
5129 import_alias
= dwarf2_name (die
, cu
);
5131 /* Figure out where the statement is being imported to. */
5132 import_prefix
= determine_prefix (die
, cu
);
5134 /* Figure out what the scope of the imported die is and prepend it
5135 to the name of the imported die. */
5136 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5138 if (imported_die
->tag
!= DW_TAG_namespace
5139 && imported_die
->tag
!= DW_TAG_module
)
5141 imported_declaration
= imported_name
;
5142 canonical_name
= imported_name_prefix
;
5144 else if (strlen (imported_name_prefix
) > 0)
5146 temp
= alloca (strlen (imported_name_prefix
)
5147 + 2 + strlen (imported_name
) + 1);
5148 strcpy (temp
, imported_name_prefix
);
5149 strcat (temp
, "::");
5150 strcat (temp
, imported_name
);
5151 canonical_name
= temp
;
5154 canonical_name
= imported_name
;
5156 cp_add_using_directive (import_prefix
,
5159 imported_declaration
,
5160 &cu
->objfile
->objfile_obstack
);
5164 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5166 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5169 /* Cleanup function for read_file_scope. */
5172 free_cu_line_header (void *arg
)
5174 struct dwarf2_cu
*cu
= arg
;
5176 free_line_header (cu
->line_header
);
5177 cu
->line_header
= NULL
;
5181 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5182 char **name
, char **comp_dir
)
5184 struct attribute
*attr
;
5189 /* Find the filename. Do not use dwarf2_name here, since the filename
5190 is not a source language identifier. */
5191 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5194 *name
= DW_STRING (attr
);
5197 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5199 *comp_dir
= DW_STRING (attr
);
5200 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5202 *comp_dir
= ldirname (*name
);
5203 if (*comp_dir
!= NULL
)
5204 make_cleanup (xfree
, *comp_dir
);
5206 if (*comp_dir
!= NULL
)
5208 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5209 directory, get rid of it. */
5210 char *cp
= strchr (*comp_dir
, ':');
5212 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5217 *name
= "<unknown>";
5220 /* Process DW_TAG_compile_unit. */
5223 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5225 struct objfile
*objfile
= cu
->objfile
;
5226 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5227 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5228 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5229 struct attribute
*attr
;
5231 char *comp_dir
= NULL
;
5232 struct die_info
*child_die
;
5233 bfd
*abfd
= objfile
->obfd
;
5234 struct line_header
*line_header
= 0;
5237 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5239 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5241 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5242 from finish_block. */
5243 if (lowpc
== ((CORE_ADDR
) -1))
5248 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5250 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5253 set_cu_language (DW_UNSND (attr
), cu
);
5256 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5258 cu
->producer
= DW_STRING (attr
);
5260 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5261 standardised yet. As a workaround for the language detection we fall
5262 back to the DW_AT_producer string. */
5263 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5264 cu
->language
= language_opencl
;
5266 /* We assume that we're processing GCC output. */
5267 processing_gcc_compilation
= 2;
5269 processing_has_namespace_info
= 0;
5271 start_symtab (name
, comp_dir
, lowpc
);
5272 record_debugformat ("DWARF 2");
5273 record_producer (cu
->producer
);
5275 initialize_cu_func_list (cu
);
5277 /* Decode line number information if present. We do this before
5278 processing child DIEs, so that the line header table is available
5279 for DW_AT_decl_file. */
5280 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5283 unsigned int line_offset
= DW_UNSND (attr
);
5284 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5287 cu
->line_header
= line_header
;
5288 make_cleanup (free_cu_line_header
, cu
);
5289 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5293 /* Process all dies in compilation unit. */
5294 if (die
->child
!= NULL
)
5296 child_die
= die
->child
;
5297 while (child_die
&& child_die
->tag
)
5299 process_die (child_die
, cu
);
5300 child_die
= sibling_die (child_die
);
5304 /* Decode macro information, if present. Dwarf 2 macro information
5305 refers to information in the line number info statement program
5306 header, so we can only read it if we've read the header
5308 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5309 if (attr
&& line_header
)
5311 unsigned int macro_offset
= DW_UNSND (attr
);
5313 dwarf_decode_macros (line_header
, macro_offset
,
5314 comp_dir
, abfd
, cu
);
5316 do_cleanups (back_to
);
5319 /* Process DW_TAG_type_unit.
5320 For TUs we want to skip the first top level sibling if it's not the
5321 actual type being defined by this TU. In this case the first top
5322 level sibling is there to provide context only. */
5325 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5327 struct objfile
*objfile
= cu
->objfile
;
5328 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5330 struct attribute
*attr
;
5332 char *comp_dir
= NULL
;
5333 struct die_info
*child_die
;
5334 bfd
*abfd
= objfile
->obfd
;
5336 /* start_symtab needs a low pc, but we don't really have one.
5337 Do what read_file_scope would do in the absence of such info. */
5338 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5340 /* Find the filename. Do not use dwarf2_name here, since the filename
5341 is not a source language identifier. */
5342 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5344 name
= DW_STRING (attr
);
5346 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5348 comp_dir
= DW_STRING (attr
);
5349 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5351 comp_dir
= ldirname (name
);
5352 if (comp_dir
!= NULL
)
5353 make_cleanup (xfree
, comp_dir
);
5359 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5361 set_cu_language (DW_UNSND (attr
), cu
);
5363 /* This isn't technically needed today. It is done for symmetry
5364 with read_file_scope. */
5365 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5367 cu
->producer
= DW_STRING (attr
);
5369 /* We assume that we're processing GCC output. */
5370 processing_gcc_compilation
= 2;
5372 processing_has_namespace_info
= 0;
5374 start_symtab (name
, comp_dir
, lowpc
);
5375 record_debugformat ("DWARF 2");
5376 record_producer (cu
->producer
);
5378 /* Process the dies in the type unit. */
5379 if (die
->child
== NULL
)
5381 dump_die_for_error (die
);
5382 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5383 bfd_get_filename (abfd
));
5386 child_die
= die
->child
;
5388 while (child_die
&& child_die
->tag
)
5390 process_die (child_die
, cu
);
5392 child_die
= sibling_die (child_die
);
5395 do_cleanups (back_to
);
5399 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5400 struct dwarf2_cu
*cu
)
5402 struct function_range
*thisfn
;
5404 thisfn
= (struct function_range
*)
5405 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5406 thisfn
->name
= name
;
5407 thisfn
->lowpc
= lowpc
;
5408 thisfn
->highpc
= highpc
;
5409 thisfn
->seen_line
= 0;
5410 thisfn
->next
= NULL
;
5412 if (cu
->last_fn
== NULL
)
5413 cu
->first_fn
= thisfn
;
5415 cu
->last_fn
->next
= thisfn
;
5417 cu
->last_fn
= thisfn
;
5420 /* qsort helper for inherit_abstract_dies. */
5423 unsigned_int_compar (const void *ap
, const void *bp
)
5425 unsigned int a
= *(unsigned int *) ap
;
5426 unsigned int b
= *(unsigned int *) bp
;
5428 return (a
> b
) - (b
> a
);
5431 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5432 Inherit only the children of the DW_AT_abstract_origin DIE not being
5433 already referenced by DW_AT_abstract_origin from the children of the
5437 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5439 struct die_info
*child_die
;
5440 unsigned die_children_count
;
5441 /* CU offsets which were referenced by children of the current DIE. */
5443 unsigned *offsets_end
, *offsetp
;
5444 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5445 struct die_info
*origin_die
;
5446 /* Iterator of the ORIGIN_DIE children. */
5447 struct die_info
*origin_child_die
;
5448 struct cleanup
*cleanups
;
5449 struct attribute
*attr
;
5450 struct dwarf2_cu
*origin_cu
;
5451 struct pending
**origin_previous_list_in_scope
;
5453 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5457 /* Note that following die references may follow to a die in a
5461 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5463 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5465 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5466 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5468 if (die
->tag
!= origin_die
->tag
5469 && !(die
->tag
== DW_TAG_inlined_subroutine
5470 && origin_die
->tag
== DW_TAG_subprogram
))
5471 complaint (&symfile_complaints
,
5472 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5473 die
->offset
, origin_die
->offset
);
5475 child_die
= die
->child
;
5476 die_children_count
= 0;
5477 while (child_die
&& child_die
->tag
)
5479 child_die
= sibling_die (child_die
);
5480 die_children_count
++;
5482 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5483 cleanups
= make_cleanup (xfree
, offsets
);
5485 offsets_end
= offsets
;
5486 child_die
= die
->child
;
5487 while (child_die
&& child_die
->tag
)
5489 /* For each CHILD_DIE, find the corresponding child of
5490 ORIGIN_DIE. If there is more than one layer of
5491 DW_AT_abstract_origin, follow them all; there shouldn't be,
5492 but GCC versions at least through 4.4 generate this (GCC PR
5494 struct die_info
*child_origin_die
= child_die
;
5495 struct dwarf2_cu
*child_origin_cu
= cu
;
5499 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5503 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5507 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5508 counterpart may exist. */
5509 if (child_origin_die
!= child_die
)
5511 if (child_die
->tag
!= child_origin_die
->tag
5512 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5513 && child_origin_die
->tag
== DW_TAG_subprogram
))
5514 complaint (&symfile_complaints
,
5515 _("Child DIE 0x%x and its abstract origin 0x%x have "
5516 "different tags"), child_die
->offset
,
5517 child_origin_die
->offset
);
5518 if (child_origin_die
->parent
!= origin_die
)
5519 complaint (&symfile_complaints
,
5520 _("Child DIE 0x%x and its abstract origin 0x%x have "
5521 "different parents"), child_die
->offset
,
5522 child_origin_die
->offset
);
5524 *offsets_end
++ = child_origin_die
->offset
;
5526 child_die
= sibling_die (child_die
);
5528 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5529 unsigned_int_compar
);
5530 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5531 if (offsetp
[-1] == *offsetp
)
5532 complaint (&symfile_complaints
,
5533 _("Multiple children of DIE 0x%x refer "
5534 "to DIE 0x%x as their abstract origin"),
5535 die
->offset
, *offsetp
);
5538 origin_child_die
= origin_die
->child
;
5539 while (origin_child_die
&& origin_child_die
->tag
)
5541 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5542 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5544 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5546 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5547 process_die (origin_child_die
, origin_cu
);
5549 origin_child_die
= sibling_die (origin_child_die
);
5551 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5553 do_cleanups (cleanups
);
5557 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5559 struct objfile
*objfile
= cu
->objfile
;
5560 struct context_stack
*new;
5563 struct die_info
*child_die
;
5564 struct attribute
*attr
, *call_line
, *call_file
;
5567 struct block
*block
;
5568 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5569 VEC (symbolp
) *template_args
= NULL
;
5570 struct template_symbol
*templ_func
= NULL
;
5574 /* If we do not have call site information, we can't show the
5575 caller of this inlined function. That's too confusing, so
5576 only use the scope for local variables. */
5577 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5578 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5579 if (call_line
== NULL
|| call_file
== NULL
)
5581 read_lexical_block_scope (die
, cu
);
5586 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5588 name
= dwarf2_name (die
, cu
);
5590 /* Ignore functions with missing or empty names. These are actually
5591 illegal according to the DWARF standard. */
5594 complaint (&symfile_complaints
,
5595 _("missing name for subprogram DIE at %d"), die
->offset
);
5599 /* Ignore functions with missing or invalid low and high pc attributes. */
5600 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5602 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5603 if (!attr
|| !DW_UNSND (attr
))
5604 complaint (&symfile_complaints
,
5605 _("cannot get low and high bounds "
5606 "for subprogram DIE at %d"),
5614 /* Record the function range for dwarf_decode_lines. */
5615 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5617 /* If we have any template arguments, then we must allocate a
5618 different sort of symbol. */
5619 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5621 if (child_die
->tag
== DW_TAG_template_type_param
5622 || child_die
->tag
== DW_TAG_template_value_param
)
5624 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5625 struct template_symbol
);
5626 templ_func
->base
.is_cplus_template_function
= 1;
5631 new = push_context (0, lowpc
);
5632 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5633 (struct symbol
*) templ_func
);
5635 /* If there is a location expression for DW_AT_frame_base, record
5637 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5639 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5640 expression is being recorded directly in the function's symbol
5641 and not in a separate frame-base object. I guess this hack is
5642 to avoid adding some sort of frame-base adjunct/annex to the
5643 function's symbol :-(. The problem with doing this is that it
5644 results in a function symbol with a location expression that
5645 has nothing to do with the location of the function, ouch! The
5646 relationship should be: a function's symbol has-a frame base; a
5647 frame-base has-a location expression. */
5648 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5650 cu
->list_in_scope
= &local_symbols
;
5652 if (die
->child
!= NULL
)
5654 child_die
= die
->child
;
5655 while (child_die
&& child_die
->tag
)
5657 if (child_die
->tag
== DW_TAG_template_type_param
5658 || child_die
->tag
== DW_TAG_template_value_param
)
5660 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5663 VEC_safe_push (symbolp
, template_args
, arg
);
5666 process_die (child_die
, cu
);
5667 child_die
= sibling_die (child_die
);
5671 inherit_abstract_dies (die
, cu
);
5673 /* If we have a DW_AT_specification, we might need to import using
5674 directives from the context of the specification DIE. See the
5675 comment in determine_prefix. */
5676 if (cu
->language
== language_cplus
5677 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5679 struct dwarf2_cu
*spec_cu
= cu
;
5680 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5684 child_die
= spec_die
->child
;
5685 while (child_die
&& child_die
->tag
)
5687 if (child_die
->tag
== DW_TAG_imported_module
)
5688 process_die (child_die
, spec_cu
);
5689 child_die
= sibling_die (child_die
);
5692 /* In some cases, GCC generates specification DIEs that
5693 themselves contain DW_AT_specification attributes. */
5694 spec_die
= die_specification (spec_die
, &spec_cu
);
5698 new = pop_context ();
5699 /* Make a block for the local symbols within. */
5700 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5701 lowpc
, highpc
, objfile
);
5703 /* For C++, set the block's scope. */
5704 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5705 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5706 determine_prefix (die
, cu
),
5707 processing_has_namespace_info
);
5709 /* If we have address ranges, record them. */
5710 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5712 /* Attach template arguments to function. */
5713 if (! VEC_empty (symbolp
, template_args
))
5715 gdb_assert (templ_func
!= NULL
);
5717 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5718 templ_func
->template_arguments
5719 = obstack_alloc (&objfile
->objfile_obstack
,
5720 (templ_func
->n_template_arguments
5721 * sizeof (struct symbol
*)));
5722 memcpy (templ_func
->template_arguments
,
5723 VEC_address (symbolp
, template_args
),
5724 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5725 VEC_free (symbolp
, template_args
);
5728 /* In C++, we can have functions nested inside functions (e.g., when
5729 a function declares a class that has methods). This means that
5730 when we finish processing a function scope, we may need to go
5731 back to building a containing block's symbol lists. */
5732 local_symbols
= new->locals
;
5733 param_symbols
= new->params
;
5734 using_directives
= new->using_directives
;
5736 /* If we've finished processing a top-level function, subsequent
5737 symbols go in the file symbol list. */
5738 if (outermost_context_p ())
5739 cu
->list_in_scope
= &file_symbols
;
5742 /* Process all the DIES contained within a lexical block scope. Start
5743 a new scope, process the dies, and then close the scope. */
5746 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5748 struct objfile
*objfile
= cu
->objfile
;
5749 struct context_stack
*new;
5750 CORE_ADDR lowpc
, highpc
;
5751 struct die_info
*child_die
;
5754 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5756 /* Ignore blocks with missing or invalid low and high pc attributes. */
5757 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5758 as multiple lexical blocks? Handling children in a sane way would
5759 be nasty. Might be easier to properly extend generic blocks to
5761 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5766 push_context (0, lowpc
);
5767 if (die
->child
!= NULL
)
5769 child_die
= die
->child
;
5770 while (child_die
&& child_die
->tag
)
5772 process_die (child_die
, cu
);
5773 child_die
= sibling_die (child_die
);
5776 new = pop_context ();
5778 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5781 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5784 /* Note that recording ranges after traversing children, as we
5785 do here, means that recording a parent's ranges entails
5786 walking across all its children's ranges as they appear in
5787 the address map, which is quadratic behavior.
5789 It would be nicer to record the parent's ranges before
5790 traversing its children, simply overriding whatever you find
5791 there. But since we don't even decide whether to create a
5792 block until after we've traversed its children, that's hard
5794 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5796 local_symbols
= new->locals
;
5797 using_directives
= new->using_directives
;
5800 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5801 Return 1 if the attributes are present and valid, otherwise, return 0.
5802 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5805 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5806 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5807 struct partial_symtab
*ranges_pst
)
5809 struct objfile
*objfile
= cu
->objfile
;
5810 struct comp_unit_head
*cu_header
= &cu
->header
;
5811 bfd
*obfd
= objfile
->obfd
;
5812 unsigned int addr_size
= cu_header
->addr_size
;
5813 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5814 /* Base address selection entry. */
5825 found_base
= cu
->base_known
;
5826 base
= cu
->base_address
;
5828 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5829 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5831 complaint (&symfile_complaints
,
5832 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5836 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5838 /* Read in the largest possible address. */
5839 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5840 if ((marker
& mask
) == mask
)
5842 /* If we found the largest possible address, then
5843 read the base address. */
5844 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5845 buffer
+= 2 * addr_size
;
5846 offset
+= 2 * addr_size
;
5852 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5856 CORE_ADDR range_beginning
, range_end
;
5858 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5859 buffer
+= addr_size
;
5860 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5861 buffer
+= addr_size
;
5862 offset
+= 2 * addr_size
;
5864 /* An end of list marker is a pair of zero addresses. */
5865 if (range_beginning
== 0 && range_end
== 0)
5866 /* Found the end of list entry. */
5869 /* Each base address selection entry is a pair of 2 values.
5870 The first is the largest possible address, the second is
5871 the base address. Check for a base address here. */
5872 if ((range_beginning
& mask
) == mask
)
5874 /* If we found the largest possible address, then
5875 read the base address. */
5876 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5883 /* We have no valid base address for the ranges
5885 complaint (&symfile_complaints
,
5886 _("Invalid .debug_ranges data (no base address)"));
5890 if (range_beginning
> range_end
)
5892 /* Inverted range entries are invalid. */
5893 complaint (&symfile_complaints
,
5894 _("Invalid .debug_ranges data (inverted range)"));
5898 /* Empty range entries have no effect. */
5899 if (range_beginning
== range_end
)
5902 range_beginning
+= base
;
5905 if (ranges_pst
!= NULL
)
5906 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5907 range_beginning
+ baseaddr
,
5908 range_end
- 1 + baseaddr
,
5911 /* FIXME: This is recording everything as a low-high
5912 segment of consecutive addresses. We should have a
5913 data structure for discontiguous block ranges
5917 low
= range_beginning
;
5923 if (range_beginning
< low
)
5924 low
= range_beginning
;
5925 if (range_end
> high
)
5931 /* If the first entry is an end-of-list marker, the range
5932 describes an empty scope, i.e. no instructions. */
5938 *high_return
= high
;
5942 /* Get low and high pc attributes from a die. Return 1 if the attributes
5943 are present and valid, otherwise, return 0. Return -1 if the range is
5944 discontinuous, i.e. derived from DW_AT_ranges information. */
5946 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5947 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5948 struct partial_symtab
*pst
)
5950 struct attribute
*attr
;
5955 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5958 high
= DW_ADDR (attr
);
5959 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5961 low
= DW_ADDR (attr
);
5963 /* Found high w/o low attribute. */
5966 /* Found consecutive range of addresses. */
5971 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5974 /* Value of the DW_AT_ranges attribute is the offset in the
5975 .debug_ranges section. */
5976 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
5978 /* Found discontinuous range of addresses. */
5983 /* read_partial_die has also the strict LOW < HIGH requirement. */
5987 /* When using the GNU linker, .gnu.linkonce. sections are used to
5988 eliminate duplicate copies of functions and vtables and such.
5989 The linker will arbitrarily choose one and discard the others.
5990 The AT_*_pc values for such functions refer to local labels in
5991 these sections. If the section from that file was discarded, the
5992 labels are not in the output, so the relocs get a value of 0.
5993 If this is a discarded function, mark the pc bounds as invalid,
5994 so that GDB will ignore it. */
5995 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6003 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6004 its low and high PC addresses. Do nothing if these addresses could not
6005 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6006 and HIGHPC to the high address if greater than HIGHPC. */
6009 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6010 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6011 struct dwarf2_cu
*cu
)
6013 CORE_ADDR low
, high
;
6014 struct die_info
*child
= die
->child
;
6016 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6018 *lowpc
= min (*lowpc
, low
);
6019 *highpc
= max (*highpc
, high
);
6022 /* If the language does not allow nested subprograms (either inside
6023 subprograms or lexical blocks), we're done. */
6024 if (cu
->language
!= language_ada
)
6027 /* Check all the children of the given DIE. If it contains nested
6028 subprograms, then check their pc bounds. Likewise, we need to
6029 check lexical blocks as well, as they may also contain subprogram
6031 while (child
&& child
->tag
)
6033 if (child
->tag
== DW_TAG_subprogram
6034 || child
->tag
== DW_TAG_lexical_block
)
6035 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6036 child
= sibling_die (child
);
6040 /* Get the low and high pc's represented by the scope DIE, and store
6041 them in *LOWPC and *HIGHPC. If the correct values can't be
6042 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6045 get_scope_pc_bounds (struct die_info
*die
,
6046 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6047 struct dwarf2_cu
*cu
)
6049 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6050 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6051 CORE_ADDR current_low
, current_high
;
6053 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6055 best_low
= current_low
;
6056 best_high
= current_high
;
6060 struct die_info
*child
= die
->child
;
6062 while (child
&& child
->tag
)
6064 switch (child
->tag
) {
6065 case DW_TAG_subprogram
:
6066 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6068 case DW_TAG_namespace
:
6070 /* FIXME: carlton/2004-01-16: Should we do this for
6071 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6072 that current GCC's always emit the DIEs corresponding
6073 to definitions of methods of classes as children of a
6074 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6075 the DIEs giving the declarations, which could be
6076 anywhere). But I don't see any reason why the
6077 standards says that they have to be there. */
6078 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6080 if (current_low
!= ((CORE_ADDR
) -1))
6082 best_low
= min (best_low
, current_low
);
6083 best_high
= max (best_high
, current_high
);
6091 child
= sibling_die (child
);
6096 *highpc
= best_high
;
6099 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6102 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6103 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6105 struct attribute
*attr
;
6107 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6110 CORE_ADDR high
= DW_ADDR (attr
);
6112 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6115 CORE_ADDR low
= DW_ADDR (attr
);
6117 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6121 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6124 bfd
*obfd
= cu
->objfile
->obfd
;
6126 /* The value of the DW_AT_ranges attribute is the offset of the
6127 address range list in the .debug_ranges section. */
6128 unsigned long offset
= DW_UNSND (attr
);
6129 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6131 /* For some target architectures, but not others, the
6132 read_address function sign-extends the addresses it returns.
6133 To recognize base address selection entries, we need a
6135 unsigned int addr_size
= cu
->header
.addr_size
;
6136 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6138 /* The base address, to which the next pair is relative. Note
6139 that this 'base' is a DWARF concept: most entries in a range
6140 list are relative, to reduce the number of relocs against the
6141 debugging information. This is separate from this function's
6142 'baseaddr' argument, which GDB uses to relocate debugging
6143 information from a shared library based on the address at
6144 which the library was loaded. */
6145 CORE_ADDR base
= cu
->base_address
;
6146 int base_known
= cu
->base_known
;
6148 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6149 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6151 complaint (&symfile_complaints
,
6152 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6159 unsigned int bytes_read
;
6160 CORE_ADDR start
, end
;
6162 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6163 buffer
+= bytes_read
;
6164 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6165 buffer
+= bytes_read
;
6167 /* Did we find the end of the range list? */
6168 if (start
== 0 && end
== 0)
6171 /* Did we find a base address selection entry? */
6172 else if ((start
& base_select_mask
) == base_select_mask
)
6178 /* We found an ordinary address range. */
6183 complaint (&symfile_complaints
,
6184 _("Invalid .debug_ranges data "
6185 "(no base address)"));
6191 /* Inverted range entries are invalid. */
6192 complaint (&symfile_complaints
,
6193 _("Invalid .debug_ranges data "
6194 "(inverted range)"));
6198 /* Empty range entries have no effect. */
6202 record_block_range (block
,
6203 baseaddr
+ base
+ start
,
6204 baseaddr
+ base
+ end
- 1);
6210 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6211 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6212 during 4.6.0 experimental. */
6215 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6218 int major
, minor
, release
;
6220 if (cu
->producer
== NULL
)
6222 /* For unknown compilers expect their behavior is DWARF version
6225 GCC started to support .debug_types sections by -gdwarf-4 since
6226 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6227 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6228 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6229 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6234 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6236 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6238 /* For non-GCC compilers expect their behavior is DWARF version
6243 cs
= &cu
->producer
[strlen ("GNU ")];
6244 while (*cs
&& !isdigit (*cs
))
6246 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6248 /* Not recognized as GCC. */
6253 return major
< 4 || (major
== 4 && minor
< 6);
6256 /* Return the default accessibility type if it is not overriden by
6257 DW_AT_accessibility. */
6259 static enum dwarf_access_attribute
6260 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6262 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6264 /* The default DWARF 2 accessibility for members is public, the default
6265 accessibility for inheritance is private. */
6267 if (die
->tag
!= DW_TAG_inheritance
)
6268 return DW_ACCESS_public
;
6270 return DW_ACCESS_private
;
6274 /* DWARF 3+ defines the default accessibility a different way. The same
6275 rules apply now for DW_TAG_inheritance as for the members and it only
6276 depends on the container kind. */
6278 if (die
->parent
->tag
== DW_TAG_class_type
)
6279 return DW_ACCESS_private
;
6281 return DW_ACCESS_public
;
6285 /* Add an aggregate field to the field list. */
6288 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6289 struct dwarf2_cu
*cu
)
6291 struct objfile
*objfile
= cu
->objfile
;
6292 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6293 struct nextfield
*new_field
;
6294 struct attribute
*attr
;
6296 char *fieldname
= "";
6298 /* Allocate a new field list entry and link it in. */
6299 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6300 make_cleanup (xfree
, new_field
);
6301 memset (new_field
, 0, sizeof (struct nextfield
));
6303 if (die
->tag
== DW_TAG_inheritance
)
6305 new_field
->next
= fip
->baseclasses
;
6306 fip
->baseclasses
= new_field
;
6310 new_field
->next
= fip
->fields
;
6311 fip
->fields
= new_field
;
6315 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6317 new_field
->accessibility
= DW_UNSND (attr
);
6319 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
6320 if (new_field
->accessibility
!= DW_ACCESS_public
)
6321 fip
->non_public_fields
= 1;
6323 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6325 new_field
->virtuality
= DW_UNSND (attr
);
6327 new_field
->virtuality
= DW_VIRTUALITY_none
;
6329 fp
= &new_field
->field
;
6331 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6333 /* Data member other than a C++ static data member. */
6335 /* Get type of field. */
6336 fp
->type
= die_type (die
, cu
);
6338 SET_FIELD_BITPOS (*fp
, 0);
6340 /* Get bit size of field (zero if none). */
6341 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6344 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6348 FIELD_BITSIZE (*fp
) = 0;
6351 /* Get bit offset of field. */
6352 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6355 int byte_offset
= 0;
6357 if (attr_form_is_section_offset (attr
))
6358 dwarf2_complex_location_expr_complaint ();
6359 else if (attr_form_is_constant (attr
))
6360 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6361 else if (attr_form_is_block (attr
))
6362 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6364 dwarf2_complex_location_expr_complaint ();
6366 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6368 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6371 if (gdbarch_bits_big_endian (gdbarch
))
6373 /* For big endian bits, the DW_AT_bit_offset gives the
6374 additional bit offset from the MSB of the containing
6375 anonymous object to the MSB of the field. We don't
6376 have to do anything special since we don't need to
6377 know the size of the anonymous object. */
6378 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6382 /* For little endian bits, compute the bit offset to the
6383 MSB of the anonymous object, subtract off the number of
6384 bits from the MSB of the field to the MSB of the
6385 object, and then subtract off the number of bits of
6386 the field itself. The result is the bit offset of
6387 the LSB of the field. */
6389 int bit_offset
= DW_UNSND (attr
);
6391 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6394 /* The size of the anonymous object containing
6395 the bit field is explicit, so use the
6396 indicated size (in bytes). */
6397 anonymous_size
= DW_UNSND (attr
);
6401 /* The size of the anonymous object containing
6402 the bit field must be inferred from the type
6403 attribute of the data member containing the
6405 anonymous_size
= TYPE_LENGTH (fp
->type
);
6407 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6408 - bit_offset
- FIELD_BITSIZE (*fp
);
6412 /* Get name of field. */
6413 fieldname
= dwarf2_name (die
, cu
);
6414 if (fieldname
== NULL
)
6417 /* The name is already allocated along with this objfile, so we don't
6418 need to duplicate it for the type. */
6419 fp
->name
= fieldname
;
6421 /* Change accessibility for artificial fields (e.g. virtual table
6422 pointer or virtual base class pointer) to private. */
6423 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6425 FIELD_ARTIFICIAL (*fp
) = 1;
6426 new_field
->accessibility
= DW_ACCESS_private
;
6427 fip
->non_public_fields
= 1;
6430 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6432 /* C++ static member. */
6434 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6435 is a declaration, but all versions of G++ as of this writing
6436 (so through at least 3.2.1) incorrectly generate
6437 DW_TAG_variable tags. */
6441 /* Get name of field. */
6442 fieldname
= dwarf2_name (die
, cu
);
6443 if (fieldname
== NULL
)
6446 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6448 /* Only create a symbol if this is an external value.
6449 new_symbol checks this and puts the value in the global symbol
6450 table, which we want. If it is not external, new_symbol
6451 will try to put the value in cu->list_in_scope which is wrong. */
6452 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6454 /* A static const member, not much different than an enum as far as
6455 we're concerned, except that we can support more types. */
6456 new_symbol (die
, NULL
, cu
);
6459 /* Get physical name. */
6460 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6462 /* The name is already allocated along with this objfile, so we don't
6463 need to duplicate it for the type. */
6464 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6465 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6466 FIELD_NAME (*fp
) = fieldname
;
6468 else if (die
->tag
== DW_TAG_inheritance
)
6470 /* C++ base class field. */
6471 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6474 int byte_offset
= 0;
6476 if (attr_form_is_section_offset (attr
))
6477 dwarf2_complex_location_expr_complaint ();
6478 else if (attr_form_is_constant (attr
))
6479 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6480 else if (attr_form_is_block (attr
))
6481 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6483 dwarf2_complex_location_expr_complaint ();
6485 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6487 FIELD_BITSIZE (*fp
) = 0;
6488 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6489 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6490 fip
->nbaseclasses
++;
6494 /* Add a typedef defined in the scope of the FIP's class. */
6497 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6498 struct dwarf2_cu
*cu
)
6500 struct objfile
*objfile
= cu
->objfile
;
6501 struct typedef_field_list
*new_field
;
6502 struct attribute
*attr
;
6503 struct typedef_field
*fp
;
6504 char *fieldname
= "";
6506 /* Allocate a new field list entry and link it in. */
6507 new_field
= xzalloc (sizeof (*new_field
));
6508 make_cleanup (xfree
, new_field
);
6510 gdb_assert (die
->tag
== DW_TAG_typedef
);
6512 fp
= &new_field
->field
;
6514 /* Get name of field. */
6515 fp
->name
= dwarf2_name (die
, cu
);
6516 if (fp
->name
== NULL
)
6519 fp
->type
= read_type_die (die
, cu
);
6521 new_field
->next
= fip
->typedef_field_list
;
6522 fip
->typedef_field_list
= new_field
;
6523 fip
->typedef_field_list_count
++;
6526 /* Create the vector of fields, and attach it to the type. */
6529 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6530 struct dwarf2_cu
*cu
)
6532 int nfields
= fip
->nfields
;
6534 /* Record the field count, allocate space for the array of fields,
6535 and create blank accessibility bitfields if necessary. */
6536 TYPE_NFIELDS (type
) = nfields
;
6537 TYPE_FIELDS (type
) = (struct field
*)
6538 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6539 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6541 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6543 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6545 TYPE_FIELD_PRIVATE_BITS (type
) =
6546 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6547 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6549 TYPE_FIELD_PROTECTED_BITS (type
) =
6550 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6551 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6553 TYPE_FIELD_IGNORE_BITS (type
) =
6554 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6555 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6558 /* If the type has baseclasses, allocate and clear a bit vector for
6559 TYPE_FIELD_VIRTUAL_BITS. */
6560 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6562 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6563 unsigned char *pointer
;
6565 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6566 pointer
= TYPE_ALLOC (type
, num_bytes
);
6567 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6568 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6569 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6572 /* Copy the saved-up fields into the field vector. Start from the head of
6573 the list, adding to the tail of the field array, so that they end up in
6574 the same order in the array in which they were added to the list. */
6575 while (nfields
-- > 0)
6577 struct nextfield
*fieldp
;
6581 fieldp
= fip
->fields
;
6582 fip
->fields
= fieldp
->next
;
6586 fieldp
= fip
->baseclasses
;
6587 fip
->baseclasses
= fieldp
->next
;
6590 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6591 switch (fieldp
->accessibility
)
6593 case DW_ACCESS_private
:
6594 if (cu
->language
!= language_ada
)
6595 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6598 case DW_ACCESS_protected
:
6599 if (cu
->language
!= language_ada
)
6600 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6603 case DW_ACCESS_public
:
6607 /* Unknown accessibility. Complain and treat it as public. */
6609 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6610 fieldp
->accessibility
);
6614 if (nfields
< fip
->nbaseclasses
)
6616 switch (fieldp
->virtuality
)
6618 case DW_VIRTUALITY_virtual
:
6619 case DW_VIRTUALITY_pure_virtual
:
6620 if (cu
->language
== language_ada
)
6621 error (_("unexpected virtuality in component of Ada type"));
6622 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6629 /* Add a member function to the proper fieldlist. */
6632 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6633 struct type
*type
, struct dwarf2_cu
*cu
)
6635 struct objfile
*objfile
= cu
->objfile
;
6636 struct attribute
*attr
;
6637 struct fnfieldlist
*flp
;
6639 struct fn_field
*fnp
;
6641 struct nextfnfield
*new_fnfield
;
6642 struct type
*this_type
;
6643 enum dwarf_access_attribute accessibility
;
6645 if (cu
->language
== language_ada
)
6646 error (_("unexpected member function in Ada type"));
6648 /* Get name of member function. */
6649 fieldname
= dwarf2_name (die
, cu
);
6650 if (fieldname
== NULL
)
6653 /* Look up member function name in fieldlist. */
6654 for (i
= 0; i
< fip
->nfnfields
; i
++)
6656 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6660 /* Create new list element if necessary. */
6661 if (i
< fip
->nfnfields
)
6662 flp
= &fip
->fnfieldlists
[i
];
6665 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6667 fip
->fnfieldlists
= (struct fnfieldlist
*)
6668 xrealloc (fip
->fnfieldlists
,
6669 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6670 * sizeof (struct fnfieldlist
));
6671 if (fip
->nfnfields
== 0)
6672 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6674 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6675 flp
->name
= fieldname
;
6678 i
= fip
->nfnfields
++;
6681 /* Create a new member function field and chain it to the field list
6683 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6684 make_cleanup (xfree
, new_fnfield
);
6685 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6686 new_fnfield
->next
= flp
->head
;
6687 flp
->head
= new_fnfield
;
6690 /* Fill in the member function field info. */
6691 fnp
= &new_fnfield
->fnfield
;
6693 /* Delay processing of the physname until later. */
6694 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
6696 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
6701 char *physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6702 fnp
->physname
= physname
? physname
: "";
6705 fnp
->type
= alloc_type (objfile
);
6706 this_type
= read_type_die (die
, cu
);
6707 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6709 int nparams
= TYPE_NFIELDS (this_type
);
6711 /* TYPE is the domain of this method, and THIS_TYPE is the type
6712 of the method itself (TYPE_CODE_METHOD). */
6713 smash_to_method_type (fnp
->type
, type
,
6714 TYPE_TARGET_TYPE (this_type
),
6715 TYPE_FIELDS (this_type
),
6716 TYPE_NFIELDS (this_type
),
6717 TYPE_VARARGS (this_type
));
6719 /* Handle static member functions.
6720 Dwarf2 has no clean way to discern C++ static and non-static
6721 member functions. G++ helps GDB by marking the first
6722 parameter for non-static member functions (which is the this
6723 pointer) as artificial. We obtain this information from
6724 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6725 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6726 fnp
->voffset
= VOFFSET_STATIC
;
6729 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
6730 dwarf2_full_name (fieldname
, die
, cu
));
6732 /* Get fcontext from DW_AT_containing_type if present. */
6733 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6734 fnp
->fcontext
= die_containing_type (die
, cu
);
6736 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
6737 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6739 /* Get accessibility. */
6740 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6742 accessibility
= DW_UNSND (attr
);
6744 accessibility
= dwarf2_default_access_attribute (die
, cu
);
6745 switch (accessibility
)
6747 case DW_ACCESS_private
:
6748 fnp
->is_private
= 1;
6750 case DW_ACCESS_protected
:
6751 fnp
->is_protected
= 1;
6755 /* Check for artificial methods. */
6756 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
6757 if (attr
&& DW_UNSND (attr
) != 0)
6758 fnp
->is_artificial
= 1;
6760 /* Get index in virtual function table if it is a virtual member
6761 function. For older versions of GCC, this is an offset in the
6762 appropriate virtual table, as specified by DW_AT_containing_type.
6763 For everyone else, it is an expression to be evaluated relative
6764 to the object address. */
6766 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
6769 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
6771 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
6773 /* Old-style GCC. */
6774 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
6776 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6777 || (DW_BLOCK (attr
)->size
> 1
6778 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
6779 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
6781 struct dwarf_block blk
;
6784 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6786 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
6787 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
6788 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6789 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
6790 dwarf2_complex_location_expr_complaint ();
6792 fnp
->voffset
/= cu
->header
.addr_size
;
6796 dwarf2_complex_location_expr_complaint ();
6799 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
6801 else if (attr_form_is_section_offset (attr
))
6803 dwarf2_complex_location_expr_complaint ();
6807 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6813 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6814 if (attr
&& DW_UNSND (attr
))
6816 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6817 complaint (&symfile_complaints
,
6818 _("Member function \"%s\" (offset %d) is virtual "
6819 "but the vtable offset is not specified"),
6820 fieldname
, die
->offset
);
6821 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6822 TYPE_CPLUS_DYNAMIC (type
) = 1;
6827 /* Create the vector of member function fields, and attach it to the type. */
6830 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6831 struct dwarf2_cu
*cu
)
6833 struct fnfieldlist
*flp
;
6834 int total_length
= 0;
6837 if (cu
->language
== language_ada
)
6838 error (_("unexpected member functions in Ada type"));
6840 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6841 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6842 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6844 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6846 struct nextfnfield
*nfp
= flp
->head
;
6847 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6850 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6851 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6852 fn_flp
->fn_fields
= (struct fn_field
*)
6853 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6854 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6855 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6857 total_length
+= flp
->length
;
6860 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6861 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6864 /* Returns non-zero if NAME is the name of a vtable member in CU's
6865 language, zero otherwise. */
6867 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6869 static const char vptr
[] = "_vptr";
6870 static const char vtable
[] = "vtable";
6872 /* Look for the C++ and Java forms of the vtable. */
6873 if ((cu
->language
== language_java
6874 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6875 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6876 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6882 /* GCC outputs unnamed structures that are really pointers to member
6883 functions, with the ABI-specified layout. If TYPE describes
6884 such a structure, smash it into a member function type.
6886 GCC shouldn't do this; it should just output pointer to member DIEs.
6887 This is GCC PR debug/28767. */
6890 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6892 struct type
*pfn_type
, *domain_type
, *new_type
;
6894 /* Check for a structure with no name and two children. */
6895 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6898 /* Check for __pfn and __delta members. */
6899 if (TYPE_FIELD_NAME (type
, 0) == NULL
6900 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6901 || TYPE_FIELD_NAME (type
, 1) == NULL
6902 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6905 /* Find the type of the method. */
6906 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6907 if (pfn_type
== NULL
6908 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6909 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6912 /* Look for the "this" argument. */
6913 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6914 if (TYPE_NFIELDS (pfn_type
) == 0
6915 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6916 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6919 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6920 new_type
= alloc_type (objfile
);
6921 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6922 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6923 TYPE_VARARGS (pfn_type
));
6924 smash_to_methodptr_type (type
, new_type
);
6927 /* Called when we find the DIE that starts a structure or union scope
6928 (definition) to create a type for the structure or union. Fill in
6929 the type's name and general properties; the members will not be
6930 processed until process_structure_type.
6932 NOTE: we need to call these functions regardless of whether or not the
6933 DIE has a DW_AT_name attribute, since it might be an anonymous
6934 structure or union. This gets the type entered into our set of
6937 However, if the structure is incomplete (an opaque struct/union)
6938 then suppress creating a symbol table entry for it since gdb only
6939 wants to find the one with the complete definition. Note that if
6940 it is complete, we just call new_symbol, which does it's own
6941 checking about whether the struct/union is anonymous or not (and
6942 suppresses creating a symbol table entry itself). */
6944 static struct type
*
6945 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6947 struct objfile
*objfile
= cu
->objfile
;
6949 struct attribute
*attr
;
6952 /* If the definition of this type lives in .debug_types, read that type.
6953 Don't follow DW_AT_specification though, that will take us back up
6954 the chain and we want to go down. */
6955 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6958 struct dwarf2_cu
*type_cu
= cu
;
6959 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6961 /* We could just recurse on read_structure_type, but we need to call
6962 get_die_type to ensure only one type for this DIE is created.
6963 This is important, for example, because for c++ classes we need
6964 TYPE_NAME set which is only done by new_symbol. Blech. */
6965 type
= read_type_die (type_die
, type_cu
);
6967 /* TYPE_CU may not be the same as CU.
6968 Ensure TYPE is recorded in CU's type_hash table. */
6969 return set_die_type (die
, type
, cu
);
6972 type
= alloc_type (objfile
);
6973 INIT_CPLUS_SPECIFIC (type
);
6975 name
= dwarf2_name (die
, cu
);
6978 if (cu
->language
== language_cplus
6979 || cu
->language
== language_java
)
6981 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
6983 /* dwarf2_full_name might have already finished building the DIE's
6984 type. If so, there is no need to continue. */
6985 if (get_die_type (die
, cu
) != NULL
)
6986 return get_die_type (die
, cu
);
6988 TYPE_TAG_NAME (type
) = full_name
;
6989 if (die
->tag
== DW_TAG_structure_type
6990 || die
->tag
== DW_TAG_class_type
)
6991 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6995 /* The name is already allocated along with this objfile, so
6996 we don't need to duplicate it for the type. */
6997 TYPE_TAG_NAME (type
) = (char *) name
;
6998 if (die
->tag
== DW_TAG_class_type
)
6999 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7003 if (die
->tag
== DW_TAG_structure_type
)
7005 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7007 else if (die
->tag
== DW_TAG_union_type
)
7009 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7013 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7016 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7017 TYPE_DECLARED_CLASS (type
) = 1;
7019 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7022 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7026 TYPE_LENGTH (type
) = 0;
7029 TYPE_STUB_SUPPORTED (type
) = 1;
7030 if (die_is_declaration (die
, cu
))
7031 TYPE_STUB (type
) = 1;
7032 else if (attr
== NULL
&& die
->child
== NULL
7033 && producer_is_realview (cu
->producer
))
7034 /* RealView does not output the required DW_AT_declaration
7035 on incomplete types. */
7036 TYPE_STUB (type
) = 1;
7038 /* We need to add the type field to the die immediately so we don't
7039 infinitely recurse when dealing with pointers to the structure
7040 type within the structure itself. */
7041 set_die_type (die
, type
, cu
);
7043 /* set_die_type should be already done. */
7044 set_descriptive_type (type
, die
, cu
);
7049 /* Finish creating a structure or union type, including filling in
7050 its members and creating a symbol for it. */
7053 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7055 struct objfile
*objfile
= cu
->objfile
;
7056 struct die_info
*child_die
= die
->child
;
7059 type
= get_die_type (die
, cu
);
7061 type
= read_structure_type (die
, cu
);
7063 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7065 struct field_info fi
;
7066 struct die_info
*child_die
;
7067 VEC (symbolp
) *template_args
= NULL
;
7068 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7070 memset (&fi
, 0, sizeof (struct field_info
));
7072 child_die
= die
->child
;
7074 while (child_die
&& child_die
->tag
)
7076 if (child_die
->tag
== DW_TAG_member
7077 || child_die
->tag
== DW_TAG_variable
)
7079 /* NOTE: carlton/2002-11-05: A C++ static data member
7080 should be a DW_TAG_member that is a declaration, but
7081 all versions of G++ as of this writing (so through at
7082 least 3.2.1) incorrectly generate DW_TAG_variable
7083 tags for them instead. */
7084 dwarf2_add_field (&fi
, child_die
, cu
);
7086 else if (child_die
->tag
== DW_TAG_subprogram
)
7088 /* C++ member function. */
7089 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7091 else if (child_die
->tag
== DW_TAG_inheritance
)
7093 /* C++ base class field. */
7094 dwarf2_add_field (&fi
, child_die
, cu
);
7096 else if (child_die
->tag
== DW_TAG_typedef
)
7097 dwarf2_add_typedef (&fi
, child_die
, cu
);
7098 else if (child_die
->tag
== DW_TAG_template_type_param
7099 || child_die
->tag
== DW_TAG_template_value_param
)
7101 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7104 VEC_safe_push (symbolp
, template_args
, arg
);
7107 child_die
= sibling_die (child_die
);
7110 /* Attach template arguments to type. */
7111 if (! VEC_empty (symbolp
, template_args
))
7113 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7114 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7115 = VEC_length (symbolp
, template_args
);
7116 TYPE_TEMPLATE_ARGUMENTS (type
)
7117 = obstack_alloc (&objfile
->objfile_obstack
,
7118 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7119 * sizeof (struct symbol
*)));
7120 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7121 VEC_address (symbolp
, template_args
),
7122 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7123 * sizeof (struct symbol
*)));
7124 VEC_free (symbolp
, template_args
);
7127 /* Attach fields and member functions to the type. */
7129 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7132 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7134 /* Get the type which refers to the base class (possibly this
7135 class itself) which contains the vtable pointer for the current
7136 class from the DW_AT_containing_type attribute. This use of
7137 DW_AT_containing_type is a GNU extension. */
7139 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7141 struct type
*t
= die_containing_type (die
, cu
);
7143 TYPE_VPTR_BASETYPE (type
) = t
;
7148 /* Our own class provides vtbl ptr. */
7149 for (i
= TYPE_NFIELDS (t
) - 1;
7150 i
>= TYPE_N_BASECLASSES (t
);
7153 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7155 if (is_vtable_name (fieldname
, cu
))
7157 TYPE_VPTR_FIELDNO (type
) = i
;
7162 /* Complain if virtual function table field not found. */
7163 if (i
< TYPE_N_BASECLASSES (t
))
7164 complaint (&symfile_complaints
,
7165 _("virtual function table pointer "
7166 "not found when defining class '%s'"),
7167 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7172 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7175 else if (cu
->producer
7176 && strncmp (cu
->producer
,
7177 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7179 /* The IBM XLC compiler does not provide direct indication
7180 of the containing type, but the vtable pointer is
7181 always named __vfp. */
7185 for (i
= TYPE_NFIELDS (type
) - 1;
7186 i
>= TYPE_N_BASECLASSES (type
);
7189 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7191 TYPE_VPTR_FIELDNO (type
) = i
;
7192 TYPE_VPTR_BASETYPE (type
) = type
;
7199 /* Copy fi.typedef_field_list linked list elements content into the
7200 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7201 if (fi
.typedef_field_list
)
7203 int i
= fi
.typedef_field_list_count
;
7205 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7206 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7207 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7208 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7210 /* Reverse the list order to keep the debug info elements order. */
7213 struct typedef_field
*dest
, *src
;
7215 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7216 src
= &fi
.typedef_field_list
->field
;
7217 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7222 do_cleanups (back_to
);
7225 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
7227 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7228 snapshots) has been known to create a die giving a declaration
7229 for a class that has, as a child, a die giving a definition for a
7230 nested class. So we have to process our children even if the
7231 current die is a declaration. Normally, of course, a declaration
7232 won't have any children at all. */
7234 while (child_die
!= NULL
&& child_die
->tag
)
7236 if (child_die
->tag
== DW_TAG_member
7237 || child_die
->tag
== DW_TAG_variable
7238 || child_die
->tag
== DW_TAG_inheritance
7239 || child_die
->tag
== DW_TAG_template_value_param
7240 || child_die
->tag
== DW_TAG_template_type_param
)
7245 process_die (child_die
, cu
);
7247 child_die
= sibling_die (child_die
);
7250 /* Do not consider external references. According to the DWARF standard,
7251 these DIEs are identified by the fact that they have no byte_size
7252 attribute, and a declaration attribute. */
7253 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7254 || !die_is_declaration (die
, cu
))
7255 new_symbol (die
, type
, cu
);
7258 /* Given a DW_AT_enumeration_type die, set its type. We do not
7259 complete the type's fields yet, or create any symbols. */
7261 static struct type
*
7262 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7264 struct objfile
*objfile
= cu
->objfile
;
7266 struct attribute
*attr
;
7269 /* If the definition of this type lives in .debug_types, read that type.
7270 Don't follow DW_AT_specification though, that will take us back up
7271 the chain and we want to go down. */
7272 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7275 struct dwarf2_cu
*type_cu
= cu
;
7276 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7278 type
= read_type_die (type_die
, type_cu
);
7280 /* TYPE_CU may not be the same as CU.
7281 Ensure TYPE is recorded in CU's type_hash table. */
7282 return set_die_type (die
, type
, cu
);
7285 type
= alloc_type (objfile
);
7287 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7288 name
= dwarf2_full_name (NULL
, die
, cu
);
7290 TYPE_TAG_NAME (type
) = (char *) name
;
7292 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7295 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7299 TYPE_LENGTH (type
) = 0;
7302 /* The enumeration DIE can be incomplete. In Ada, any type can be
7303 declared as private in the package spec, and then defined only
7304 inside the package body. Such types are known as Taft Amendment
7305 Types. When another package uses such a type, an incomplete DIE
7306 may be generated by the compiler. */
7307 if (die_is_declaration (die
, cu
))
7308 TYPE_STUB (type
) = 1;
7310 return set_die_type (die
, type
, cu
);
7313 /* Given a pointer to a die which begins an enumeration, process all
7314 the dies that define the members of the enumeration, and create the
7315 symbol for the enumeration type.
7317 NOTE: We reverse the order of the element list. */
7320 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7322 struct type
*this_type
;
7324 this_type
= get_die_type (die
, cu
);
7325 if (this_type
== NULL
)
7326 this_type
= read_enumeration_type (die
, cu
);
7328 if (die
->child
!= NULL
)
7330 struct die_info
*child_die
;
7332 struct field
*fields
= NULL
;
7334 int unsigned_enum
= 1;
7337 child_die
= die
->child
;
7338 while (child_die
&& child_die
->tag
)
7340 if (child_die
->tag
!= DW_TAG_enumerator
)
7342 process_die (child_die
, cu
);
7346 name
= dwarf2_name (child_die
, cu
);
7349 sym
= new_symbol (child_die
, this_type
, cu
);
7350 if (SYMBOL_VALUE (sym
) < 0)
7353 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7355 fields
= (struct field
*)
7357 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7358 * sizeof (struct field
));
7361 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7362 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7363 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7364 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7370 child_die
= sibling_die (child_die
);
7375 TYPE_NFIELDS (this_type
) = num_fields
;
7376 TYPE_FIELDS (this_type
) = (struct field
*)
7377 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7378 memcpy (TYPE_FIELDS (this_type
), fields
,
7379 sizeof (struct field
) * num_fields
);
7383 TYPE_UNSIGNED (this_type
) = 1;
7386 new_symbol (die
, this_type
, cu
);
7389 /* Extract all information from a DW_TAG_array_type DIE and put it in
7390 the DIE's type field. For now, this only handles one dimensional
7393 static struct type
*
7394 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7396 struct objfile
*objfile
= cu
->objfile
;
7397 struct die_info
*child_die
;
7399 struct type
*element_type
, *range_type
, *index_type
;
7400 struct type
**range_types
= NULL
;
7401 struct attribute
*attr
;
7403 struct cleanup
*back_to
;
7406 element_type
= die_type (die
, cu
);
7408 /* The die_type call above may have already set the type for this DIE. */
7409 type
= get_die_type (die
, cu
);
7413 /* Irix 6.2 native cc creates array types without children for
7414 arrays with unspecified length. */
7415 if (die
->child
== NULL
)
7417 index_type
= objfile_type (objfile
)->builtin_int
;
7418 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7419 type
= create_array_type (NULL
, element_type
, range_type
);
7420 return set_die_type (die
, type
, cu
);
7423 back_to
= make_cleanup (null_cleanup
, NULL
);
7424 child_die
= die
->child
;
7425 while (child_die
&& child_die
->tag
)
7427 if (child_die
->tag
== DW_TAG_subrange_type
)
7429 struct type
*child_type
= read_type_die (child_die
, cu
);
7431 if (child_type
!= NULL
)
7433 /* The range type was succesfully read. Save it for the
7434 array type creation. */
7435 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7437 range_types
= (struct type
**)
7438 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7439 * sizeof (struct type
*));
7441 make_cleanup (free_current_contents
, &range_types
);
7443 range_types
[ndim
++] = child_type
;
7446 child_die
= sibling_die (child_die
);
7449 /* Dwarf2 dimensions are output from left to right, create the
7450 necessary array types in backwards order. */
7452 type
= element_type
;
7454 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7459 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7464 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7467 /* Understand Dwarf2 support for vector types (like they occur on
7468 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7469 array type. This is not part of the Dwarf2/3 standard yet, but a
7470 custom vendor extension. The main difference between a regular
7471 array and the vector variant is that vectors are passed by value
7473 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7475 make_vector_type (type
);
7477 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7478 implementation may choose to implement triple vectors using this
7480 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7483 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
7484 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7486 complaint (&symfile_complaints
,
7487 _("DW_AT_byte_size for array type smaller "
7488 "than the total size of elements"));
7491 name
= dwarf2_name (die
, cu
);
7493 TYPE_NAME (type
) = name
;
7495 /* Install the type in the die. */
7496 set_die_type (die
, type
, cu
);
7498 /* set_die_type should be already done. */
7499 set_descriptive_type (type
, die
, cu
);
7501 do_cleanups (back_to
);
7506 static enum dwarf_array_dim_ordering
7507 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7509 struct attribute
*attr
;
7511 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7513 if (attr
) return DW_SND (attr
);
7515 /* GNU F77 is a special case, as at 08/2004 array type info is the
7516 opposite order to the dwarf2 specification, but data is still
7517 laid out as per normal fortran.
7519 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7520 version checking. */
7522 if (cu
->language
== language_fortran
7523 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7525 return DW_ORD_row_major
;
7528 switch (cu
->language_defn
->la_array_ordering
)
7530 case array_column_major
:
7531 return DW_ORD_col_major
;
7532 case array_row_major
:
7534 return DW_ORD_row_major
;
7538 /* Extract all information from a DW_TAG_set_type DIE and put it in
7539 the DIE's type field. */
7541 static struct type
*
7542 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7544 struct type
*domain_type
, *set_type
;
7545 struct attribute
*attr
;
7547 domain_type
= die_type (die
, cu
);
7549 /* The die_type call above may have already set the type for this DIE. */
7550 set_type
= get_die_type (die
, cu
);
7554 set_type
= create_set_type (NULL
, domain_type
);
7556 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7558 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7560 return set_die_type (die
, set_type
, cu
);
7563 /* First cut: install each common block member as a global variable. */
7566 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7568 struct die_info
*child_die
;
7569 struct attribute
*attr
;
7571 CORE_ADDR base
= (CORE_ADDR
) 0;
7573 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7576 /* Support the .debug_loc offsets. */
7577 if (attr_form_is_block (attr
))
7579 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7581 else if (attr_form_is_section_offset (attr
))
7583 dwarf2_complex_location_expr_complaint ();
7587 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7588 "common block member");
7591 if (die
->child
!= NULL
)
7593 child_die
= die
->child
;
7594 while (child_die
&& child_die
->tag
)
7596 sym
= new_symbol (child_die
, NULL
, cu
);
7597 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
7598 if (sym
!= NULL
&& attr
!= NULL
)
7600 CORE_ADDR byte_offset
= 0;
7602 if (attr_form_is_section_offset (attr
))
7603 dwarf2_complex_location_expr_complaint ();
7604 else if (attr_form_is_constant (attr
))
7605 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
7606 else if (attr_form_is_block (attr
))
7607 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7609 dwarf2_complex_location_expr_complaint ();
7611 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
7612 add_symbol_to_list (sym
, &global_symbols
);
7614 child_die
= sibling_die (child_die
);
7619 /* Create a type for a C++ namespace. */
7621 static struct type
*
7622 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7624 struct objfile
*objfile
= cu
->objfile
;
7625 const char *previous_prefix
, *name
;
7629 /* For extensions, reuse the type of the original namespace. */
7630 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7632 struct die_info
*ext_die
;
7633 struct dwarf2_cu
*ext_cu
= cu
;
7635 ext_die
= dwarf2_extension (die
, &ext_cu
);
7636 type
= read_type_die (ext_die
, ext_cu
);
7638 /* EXT_CU may not be the same as CU.
7639 Ensure TYPE is recorded in CU's type_hash table. */
7640 return set_die_type (die
, type
, cu
);
7643 name
= namespace_name (die
, &is_anonymous
, cu
);
7645 /* Now build the name of the current namespace. */
7647 previous_prefix
= determine_prefix (die
, cu
);
7648 if (previous_prefix
[0] != '\0')
7649 name
= typename_concat (&objfile
->objfile_obstack
,
7650 previous_prefix
, name
, 0, cu
);
7652 /* Create the type. */
7653 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7655 TYPE_NAME (type
) = (char *) name
;
7656 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7658 return set_die_type (die
, type
, cu
);
7661 /* Read a C++ namespace. */
7664 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7666 struct objfile
*objfile
= cu
->objfile
;
7669 /* Add a symbol associated to this if we haven't seen the namespace
7670 before. Also, add a using directive if it's an anonymous
7673 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7677 type
= read_type_die (die
, cu
);
7678 new_symbol (die
, type
, cu
);
7680 namespace_name (die
, &is_anonymous
, cu
);
7683 const char *previous_prefix
= determine_prefix (die
, cu
);
7685 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7686 NULL
, &objfile
->objfile_obstack
);
7690 if (die
->child
!= NULL
)
7692 struct die_info
*child_die
= die
->child
;
7694 while (child_die
&& child_die
->tag
)
7696 process_die (child_die
, cu
);
7697 child_die
= sibling_die (child_die
);
7702 /* Read a Fortran module as type. This DIE can be only a declaration used for
7703 imported module. Still we need that type as local Fortran "use ... only"
7704 declaration imports depend on the created type in determine_prefix. */
7706 static struct type
*
7707 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7709 struct objfile
*objfile
= cu
->objfile
;
7713 module_name
= dwarf2_name (die
, cu
);
7715 complaint (&symfile_complaints
,
7716 _("DW_TAG_module has no name, offset 0x%x"),
7718 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7720 /* determine_prefix uses TYPE_TAG_NAME. */
7721 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7723 return set_die_type (die
, type
, cu
);
7726 /* Read a Fortran module. */
7729 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7731 struct die_info
*child_die
= die
->child
;
7733 while (child_die
&& child_die
->tag
)
7735 process_die (child_die
, cu
);
7736 child_die
= sibling_die (child_die
);
7740 /* Return the name of the namespace represented by DIE. Set
7741 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7745 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
7747 struct die_info
*current_die
;
7748 const char *name
= NULL
;
7750 /* Loop through the extensions until we find a name. */
7752 for (current_die
= die
;
7753 current_die
!= NULL
;
7754 current_die
= dwarf2_extension (die
, &cu
))
7756 name
= dwarf2_name (current_die
, cu
);
7761 /* Is it an anonymous namespace? */
7763 *is_anonymous
= (name
== NULL
);
7765 name
= "(anonymous namespace)";
7770 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7771 the user defined type vector. */
7773 static struct type
*
7774 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7776 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7777 struct comp_unit_head
*cu_header
= &cu
->header
;
7779 struct attribute
*attr_byte_size
;
7780 struct attribute
*attr_address_class
;
7781 int byte_size
, addr_class
;
7782 struct type
*target_type
;
7784 target_type
= die_type (die
, cu
);
7786 /* The die_type call above may have already set the type for this DIE. */
7787 type
= get_die_type (die
, cu
);
7791 type
= lookup_pointer_type (target_type
);
7793 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7795 byte_size
= DW_UNSND (attr_byte_size
);
7797 byte_size
= cu_header
->addr_size
;
7799 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
7800 if (attr_address_class
)
7801 addr_class
= DW_UNSND (attr_address_class
);
7803 addr_class
= DW_ADDR_none
;
7805 /* If the pointer size or address class is different than the
7806 default, create a type variant marked as such and set the
7807 length accordingly. */
7808 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
7810 if (gdbarch_address_class_type_flags_p (gdbarch
))
7814 type_flags
= gdbarch_address_class_type_flags
7815 (gdbarch
, byte_size
, addr_class
);
7816 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
7818 type
= make_type_with_address_space (type
, type_flags
);
7820 else if (TYPE_LENGTH (type
) != byte_size
)
7822 complaint (&symfile_complaints
,
7823 _("invalid pointer size %d"), byte_size
);
7827 /* Should we also complain about unhandled address classes? */
7831 TYPE_LENGTH (type
) = byte_size
;
7832 return set_die_type (die
, type
, cu
);
7835 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7836 the user defined type vector. */
7838 static struct type
*
7839 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7842 struct type
*to_type
;
7843 struct type
*domain
;
7845 to_type
= die_type (die
, cu
);
7846 domain
= die_containing_type (die
, cu
);
7848 /* The calls above may have already set the type for this DIE. */
7849 type
= get_die_type (die
, cu
);
7853 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
7854 type
= lookup_methodptr_type (to_type
);
7856 type
= lookup_memberptr_type (to_type
, domain
);
7858 return set_die_type (die
, type
, cu
);
7861 /* Extract all information from a DW_TAG_reference_type DIE and add to
7862 the user defined type vector. */
7864 static struct type
*
7865 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7867 struct comp_unit_head
*cu_header
= &cu
->header
;
7868 struct type
*type
, *target_type
;
7869 struct attribute
*attr
;
7871 target_type
= die_type (die
, cu
);
7873 /* The die_type call above may have already set the type for this DIE. */
7874 type
= get_die_type (die
, cu
);
7878 type
= lookup_reference_type (target_type
);
7879 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7882 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7886 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7888 return set_die_type (die
, type
, cu
);
7891 static struct type
*
7892 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7894 struct type
*base_type
, *cv_type
;
7896 base_type
= die_type (die
, cu
);
7898 /* The die_type call above may have already set the type for this DIE. */
7899 cv_type
= get_die_type (die
, cu
);
7903 /* In case the const qualifier is applied to an array type, the element type
7904 is so qualified, not the array type (section 6.7.3 of C99). */
7905 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
7907 struct type
*el_type
, *inner_array
;
7909 base_type
= copy_type (base_type
);
7910 inner_array
= base_type
;
7912 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
7914 TYPE_TARGET_TYPE (inner_array
) =
7915 copy_type (TYPE_TARGET_TYPE (inner_array
));
7916 inner_array
= TYPE_TARGET_TYPE (inner_array
);
7919 el_type
= TYPE_TARGET_TYPE (inner_array
);
7920 TYPE_TARGET_TYPE (inner_array
) =
7921 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
7923 return set_die_type (die
, base_type
, cu
);
7926 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7927 return set_die_type (die
, cv_type
, cu
);
7930 static struct type
*
7931 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7933 struct type
*base_type
, *cv_type
;
7935 base_type
= die_type (die
, cu
);
7937 /* The die_type call above may have already set the type for this DIE. */
7938 cv_type
= get_die_type (die
, cu
);
7942 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7943 return set_die_type (die
, cv_type
, cu
);
7946 /* Extract all information from a DW_TAG_string_type DIE and add to
7947 the user defined type vector. It isn't really a user defined type,
7948 but it behaves like one, with other DIE's using an AT_user_def_type
7949 attribute to reference it. */
7951 static struct type
*
7952 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7954 struct objfile
*objfile
= cu
->objfile
;
7955 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7956 struct type
*type
, *range_type
, *index_type
, *char_type
;
7957 struct attribute
*attr
;
7958 unsigned int length
;
7960 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7963 length
= DW_UNSND (attr
);
7967 /* Check for the DW_AT_byte_size attribute. */
7968 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7971 length
= DW_UNSND (attr
);
7979 index_type
= objfile_type (objfile
)->builtin_int
;
7980 range_type
= create_range_type (NULL
, index_type
, 1, length
);
7981 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
7982 type
= create_string_type (NULL
, char_type
, range_type
);
7984 return set_die_type (die
, type
, cu
);
7987 /* Handle DIES due to C code like:
7991 int (*funcp)(int a, long l);
7995 ('funcp' generates a DW_TAG_subroutine_type DIE). */
7997 static struct type
*
7998 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8000 struct type
*type
; /* Type that this function returns. */
8001 struct type
*ftype
; /* Function that returns above type. */
8002 struct attribute
*attr
;
8004 type
= die_type (die
, cu
);
8006 /* The die_type call above may have already set the type for this DIE. */
8007 ftype
= get_die_type (die
, cu
);
8011 ftype
= lookup_function_type (type
);
8013 /* All functions in C++, Pascal and Java have prototypes. */
8014 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8015 if ((attr
&& (DW_UNSND (attr
) != 0))
8016 || cu
->language
== language_cplus
8017 || cu
->language
== language_java
8018 || cu
->language
== language_pascal
)
8019 TYPE_PROTOTYPED (ftype
) = 1;
8020 else if (producer_is_realview (cu
->producer
))
8021 /* RealView does not emit DW_AT_prototyped. We can not
8022 distinguish prototyped and unprototyped functions; default to
8023 prototyped, since that is more common in modern code (and
8024 RealView warns about unprototyped functions). */
8025 TYPE_PROTOTYPED (ftype
) = 1;
8027 /* Store the calling convention in the type if it's available in
8028 the subroutine die. Otherwise set the calling convention to
8029 the default value DW_CC_normal. */
8030 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8032 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8033 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8034 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8036 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8038 /* We need to add the subroutine type to the die immediately so
8039 we don't infinitely recurse when dealing with parameters
8040 declared as the same subroutine type. */
8041 set_die_type (die
, ftype
, cu
);
8043 if (die
->child
!= NULL
)
8045 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
8046 struct die_info
*child_die
;
8047 int nparams
, iparams
;
8049 /* Count the number of parameters.
8050 FIXME: GDB currently ignores vararg functions, but knows about
8051 vararg member functions. */
8053 child_die
= die
->child
;
8054 while (child_die
&& child_die
->tag
)
8056 if (child_die
->tag
== DW_TAG_formal_parameter
)
8058 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8059 TYPE_VARARGS (ftype
) = 1;
8060 child_die
= sibling_die (child_die
);
8063 /* Allocate storage for parameters and fill them in. */
8064 TYPE_NFIELDS (ftype
) = nparams
;
8065 TYPE_FIELDS (ftype
) = (struct field
*)
8066 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8068 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8069 even if we error out during the parameters reading below. */
8070 for (iparams
= 0; iparams
< nparams
; iparams
++)
8071 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8074 child_die
= die
->child
;
8075 while (child_die
&& child_die
->tag
)
8077 if (child_die
->tag
== DW_TAG_formal_parameter
)
8079 struct type
*arg_type
;
8081 /* DWARF version 2 has no clean way to discern C++
8082 static and non-static member functions. G++ helps
8083 GDB by marking the first parameter for non-static
8084 member functions (which is the this pointer) as
8085 artificial. We pass this information to
8086 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8088 DWARF version 3 added DW_AT_object_pointer, which GCC
8089 4.5 does not yet generate. */
8090 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8092 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8095 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8097 /* GCC/43521: In java, the formal parameter
8098 "this" is sometimes not marked with DW_AT_artificial. */
8099 if (cu
->language
== language_java
)
8101 const char *name
= dwarf2_name (child_die
, cu
);
8103 if (name
&& !strcmp (name
, "this"))
8104 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8107 arg_type
= die_type (child_die
, cu
);
8109 /* RealView does not mark THIS as const, which the testsuite
8110 expects. GCC marks THIS as const in method definitions,
8111 but not in the class specifications (GCC PR 43053). */
8112 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8113 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8116 struct dwarf2_cu
*arg_cu
= cu
;
8117 const char *name
= dwarf2_name (child_die
, cu
);
8119 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8122 /* If the compiler emits this, use it. */
8123 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8126 else if (name
&& strcmp (name
, "this") == 0)
8127 /* Function definitions will have the argument names. */
8129 else if (name
== NULL
&& iparams
== 0)
8130 /* Declarations may not have the names, so like
8131 elsewhere in GDB, assume an artificial first
8132 argument is "this". */
8136 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8140 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8143 child_die
= sibling_die (child_die
);
8150 static struct type
*
8151 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8153 struct objfile
*objfile
= cu
->objfile
;
8154 const char *name
= NULL
;
8155 struct type
*this_type
;
8157 name
= dwarf2_full_name (NULL
, die
, cu
);
8158 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8159 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8160 TYPE_NAME (this_type
) = (char *) name
;
8161 set_die_type (die
, this_type
, cu
);
8162 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
8166 /* Find a representation of a given base type and install
8167 it in the TYPE field of the die. */
8169 static struct type
*
8170 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8172 struct objfile
*objfile
= cu
->objfile
;
8174 struct attribute
*attr
;
8175 int encoding
= 0, size
= 0;
8177 enum type_code code
= TYPE_CODE_INT
;
8179 struct type
*target_type
= NULL
;
8181 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8184 encoding
= DW_UNSND (attr
);
8186 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8189 size
= DW_UNSND (attr
);
8191 name
= dwarf2_name (die
, cu
);
8194 complaint (&symfile_complaints
,
8195 _("DW_AT_name missing from DW_TAG_base_type"));
8200 case DW_ATE_address
:
8201 /* Turn DW_ATE_address into a void * pointer. */
8202 code
= TYPE_CODE_PTR
;
8203 type_flags
|= TYPE_FLAG_UNSIGNED
;
8204 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8206 case DW_ATE_boolean
:
8207 code
= TYPE_CODE_BOOL
;
8208 type_flags
|= TYPE_FLAG_UNSIGNED
;
8210 case DW_ATE_complex_float
:
8211 code
= TYPE_CODE_COMPLEX
;
8212 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8214 case DW_ATE_decimal_float
:
8215 code
= TYPE_CODE_DECFLOAT
;
8218 code
= TYPE_CODE_FLT
;
8222 case DW_ATE_unsigned
:
8223 type_flags
|= TYPE_FLAG_UNSIGNED
;
8225 case DW_ATE_signed_char
:
8226 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8227 || cu
->language
== language_pascal
)
8228 code
= TYPE_CODE_CHAR
;
8230 case DW_ATE_unsigned_char
:
8231 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8232 || cu
->language
== language_pascal
)
8233 code
= TYPE_CODE_CHAR
;
8234 type_flags
|= TYPE_FLAG_UNSIGNED
;
8237 /* We just treat this as an integer and then recognize the
8238 type by name elsewhere. */
8242 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8243 dwarf_type_encoding_name (encoding
));
8247 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8248 TYPE_NAME (type
) = name
;
8249 TYPE_TARGET_TYPE (type
) = target_type
;
8251 if (name
&& strcmp (name
, "char") == 0)
8252 TYPE_NOSIGN (type
) = 1;
8254 return set_die_type (die
, type
, cu
);
8257 /* Read the given DW_AT_subrange DIE. */
8259 static struct type
*
8260 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8262 struct type
*base_type
;
8263 struct type
*range_type
;
8264 struct attribute
*attr
;
8268 LONGEST negative_mask
;
8270 base_type
= die_type (die
, cu
);
8271 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8272 check_typedef (base_type
);
8274 /* The die_type call above may have already set the type for this DIE. */
8275 range_type
= get_die_type (die
, cu
);
8279 if (cu
->language
== language_fortran
)
8281 /* FORTRAN implies a lower bound of 1, if not given. */
8285 /* FIXME: For variable sized arrays either of these could be
8286 a variable rather than a constant value. We'll allow it,
8287 but we don't know how to handle it. */
8288 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8290 low
= dwarf2_get_attr_constant_value (attr
, 0);
8292 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8295 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
8297 /* GCC encodes arrays with unspecified or dynamic length
8298 with a DW_FORM_block1 attribute or a reference attribute.
8299 FIXME: GDB does not yet know how to handle dynamic
8300 arrays properly, treat them as arrays with unspecified
8303 FIXME: jimb/2003-09-22: GDB does not really know
8304 how to handle arrays of unspecified length
8305 either; we just represent them as zero-length
8306 arrays. Choose an appropriate upper bound given
8307 the lower bound we've computed above. */
8311 high
= dwarf2_get_attr_constant_value (attr
, 1);
8315 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8318 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8319 high
= low
+ count
- 1;
8323 /* Unspecified array length. */
8328 /* Dwarf-2 specifications explicitly allows to create subrange types
8329 without specifying a base type.
8330 In that case, the base type must be set to the type of
8331 the lower bound, upper bound or count, in that order, if any of these
8332 three attributes references an object that has a type.
8333 If no base type is found, the Dwarf-2 specifications say that
8334 a signed integer type of size equal to the size of an address should
8336 For the following C code: `extern char gdb_int [];'
8337 GCC produces an empty range DIE.
8338 FIXME: muller/2010-05-28: Possible references to object for low bound,
8339 high bound or count are not yet handled by this code. */
8340 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8342 struct objfile
*objfile
= cu
->objfile
;
8343 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8344 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8345 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8347 /* Test "int", "long int", and "long long int" objfile types,
8348 and select the first one having a size above or equal to the
8349 architecture address size. */
8350 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8351 base_type
= int_type
;
8354 int_type
= objfile_type (objfile
)->builtin_long
;
8355 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8356 base_type
= int_type
;
8359 int_type
= objfile_type (objfile
)->builtin_long_long
;
8360 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8361 base_type
= int_type
;
8367 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8368 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8369 low
|= negative_mask
;
8370 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8371 high
|= negative_mask
;
8373 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8375 /* Mark arrays with dynamic length at least as an array of unspecified
8376 length. GDB could check the boundary but before it gets implemented at
8377 least allow accessing the array elements. */
8378 if (attr
&& attr
->form
== DW_FORM_block1
)
8379 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8381 /* Ada expects an empty array on no boundary attributes. */
8382 if (attr
== NULL
&& cu
->language
!= language_ada
)
8383 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8385 name
= dwarf2_name (die
, cu
);
8387 TYPE_NAME (range_type
) = name
;
8389 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8391 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8393 set_die_type (die
, range_type
, cu
);
8395 /* set_die_type should be already done. */
8396 set_descriptive_type (range_type
, die
, cu
);
8401 static struct type
*
8402 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8406 /* For now, we only support the C meaning of an unspecified type: void. */
8408 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8409 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8411 return set_die_type (die
, type
, cu
);
8414 /* Trivial hash function for die_info: the hash value of a DIE
8415 is its offset in .debug_info for this objfile. */
8418 die_hash (const void *item
)
8420 const struct die_info
*die
= item
;
8425 /* Trivial comparison function for die_info structures: two DIEs
8426 are equal if they have the same offset. */
8429 die_eq (const void *item_lhs
, const void *item_rhs
)
8431 const struct die_info
*die_lhs
= item_lhs
;
8432 const struct die_info
*die_rhs
= item_rhs
;
8434 return die_lhs
->offset
== die_rhs
->offset
;
8437 /* Read a whole compilation unit into a linked list of dies. */
8439 static struct die_info
*
8440 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8442 struct die_reader_specs reader_specs
;
8443 int read_abbrevs
= 0;
8444 struct cleanup
*back_to
= NULL
;
8445 struct die_info
*die
;
8447 if (cu
->dwarf2_abbrevs
== NULL
)
8449 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8450 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8454 gdb_assert (cu
->die_hash
== NULL
);
8456 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8460 &cu
->comp_unit_obstack
,
8461 hashtab_obstack_allocate
,
8462 dummy_obstack_deallocate
);
8464 init_cu_die_reader (&reader_specs
, cu
);
8466 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8469 do_cleanups (back_to
);
8474 /* Main entry point for reading a DIE and all children.
8475 Read the DIE and dump it if requested. */
8477 static struct die_info
*
8478 read_die_and_children (const struct die_reader_specs
*reader
,
8480 gdb_byte
**new_info_ptr
,
8481 struct die_info
*parent
)
8483 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8484 new_info_ptr
, parent
);
8486 if (dwarf2_die_debug
)
8488 fprintf_unfiltered (gdb_stdlog
,
8489 "\nRead die from %s of %s:\n",
8490 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8492 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8494 : "unknown section",
8495 reader
->abfd
->filename
);
8496 dump_die (result
, dwarf2_die_debug
);
8502 /* Read a single die and all its descendents. Set the die's sibling
8503 field to NULL; set other fields in the die correctly, and set all
8504 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8505 location of the info_ptr after reading all of those dies. PARENT
8506 is the parent of the die in question. */
8508 static struct die_info
*
8509 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8511 gdb_byte
**new_info_ptr
,
8512 struct die_info
*parent
)
8514 struct die_info
*die
;
8518 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8521 *new_info_ptr
= cur_ptr
;
8524 store_in_ref_table (die
, reader
->cu
);
8527 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8531 *new_info_ptr
= cur_ptr
;
8534 die
->sibling
= NULL
;
8535 die
->parent
= parent
;
8539 /* Read a die, all of its descendents, and all of its siblings; set
8540 all of the fields of all of the dies correctly. Arguments are as
8541 in read_die_and_children. */
8543 static struct die_info
*
8544 read_die_and_siblings (const struct die_reader_specs
*reader
,
8546 gdb_byte
**new_info_ptr
,
8547 struct die_info
*parent
)
8549 struct die_info
*first_die
, *last_sibling
;
8553 first_die
= last_sibling
= NULL
;
8557 struct die_info
*die
8558 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8562 *new_info_ptr
= cur_ptr
;
8569 last_sibling
->sibling
= die
;
8575 /* Read the die from the .debug_info section buffer. Set DIEP to
8576 point to a newly allocated die with its information, except for its
8577 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8578 whether the die has children or not. */
8581 read_full_die (const struct die_reader_specs
*reader
,
8582 struct die_info
**diep
, gdb_byte
*info_ptr
,
8585 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8586 struct abbrev_info
*abbrev
;
8587 struct die_info
*die
;
8588 struct dwarf2_cu
*cu
= reader
->cu
;
8589 bfd
*abfd
= reader
->abfd
;
8591 offset
= info_ptr
- reader
->buffer
;
8592 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8593 info_ptr
+= bytes_read
;
8601 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8603 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8605 bfd_get_filename (abfd
));
8607 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8608 die
->offset
= offset
;
8609 die
->tag
= abbrev
->tag
;
8610 die
->abbrev
= abbrev_number
;
8612 die
->num_attrs
= abbrev
->num_attrs
;
8614 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8615 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8616 abfd
, info_ptr
, cu
);
8619 *has_children
= abbrev
->has_children
;
8623 /* In DWARF version 2, the description of the debugging information is
8624 stored in a separate .debug_abbrev section. Before we read any
8625 dies from a section we read in all abbreviations and install them
8626 in a hash table. This function also sets flags in CU describing
8627 the data found in the abbrev table. */
8630 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8632 struct comp_unit_head
*cu_header
= &cu
->header
;
8633 gdb_byte
*abbrev_ptr
;
8634 struct abbrev_info
*cur_abbrev
;
8635 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8636 unsigned int abbrev_form
, hash_number
;
8637 struct attr_abbrev
*cur_attrs
;
8638 unsigned int allocated_attrs
;
8640 /* Initialize dwarf2 abbrevs. */
8641 obstack_init (&cu
->abbrev_obstack
);
8642 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8644 * sizeof (struct abbrev_info
*)));
8645 memset (cu
->dwarf2_abbrevs
, 0,
8646 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8648 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8649 &dwarf2_per_objfile
->abbrev
);
8650 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8651 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8652 abbrev_ptr
+= bytes_read
;
8654 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8655 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8657 /* Loop until we reach an abbrev number of 0. */
8658 while (abbrev_number
)
8660 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8662 /* read in abbrev header */
8663 cur_abbrev
->number
= abbrev_number
;
8664 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8665 abbrev_ptr
+= bytes_read
;
8666 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8669 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8670 cu
->has_namespace_info
= 1;
8672 /* now read in declarations */
8673 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8674 abbrev_ptr
+= bytes_read
;
8675 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8676 abbrev_ptr
+= bytes_read
;
8679 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8681 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8683 = xrealloc (cur_attrs
, (allocated_attrs
8684 * sizeof (struct attr_abbrev
)));
8687 /* Record whether this compilation unit might have
8688 inter-compilation-unit references. If we don't know what form
8689 this attribute will have, then it might potentially be a
8690 DW_FORM_ref_addr, so we conservatively expect inter-CU
8693 if (abbrev_form
== DW_FORM_ref_addr
8694 || abbrev_form
== DW_FORM_indirect
)
8695 cu
->has_form_ref_addr
= 1;
8697 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8698 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8699 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8700 abbrev_ptr
+= bytes_read
;
8701 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8702 abbrev_ptr
+= bytes_read
;
8705 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8706 (cur_abbrev
->num_attrs
8707 * sizeof (struct attr_abbrev
)));
8708 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8709 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8711 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8712 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8713 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8715 /* Get next abbreviation.
8716 Under Irix6 the abbreviations for a compilation unit are not
8717 always properly terminated with an abbrev number of 0.
8718 Exit loop if we encounter an abbreviation which we have
8719 already read (which means we are about to read the abbreviations
8720 for the next compile unit) or if the end of the abbreviation
8721 table is reached. */
8722 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8723 >= dwarf2_per_objfile
->abbrev
.size
)
8725 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8726 abbrev_ptr
+= bytes_read
;
8727 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
8734 /* Release the memory used by the abbrev table for a compilation unit. */
8737 dwarf2_free_abbrev_table (void *ptr_to_cu
)
8739 struct dwarf2_cu
*cu
= ptr_to_cu
;
8741 obstack_free (&cu
->abbrev_obstack
, NULL
);
8742 cu
->dwarf2_abbrevs
= NULL
;
8745 /* Lookup an abbrev_info structure in the abbrev hash table. */
8747 static struct abbrev_info
*
8748 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
8750 unsigned int hash_number
;
8751 struct abbrev_info
*abbrev
;
8753 hash_number
= number
% ABBREV_HASH_SIZE
;
8754 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
8758 if (abbrev
->number
== number
)
8761 abbrev
= abbrev
->next
;
8766 /* Returns nonzero if TAG represents a type that we might generate a partial
8770 is_type_tag_for_partial (int tag
)
8775 /* Some types that would be reasonable to generate partial symbols for,
8776 that we don't at present. */
8777 case DW_TAG_array_type
:
8778 case DW_TAG_file_type
:
8779 case DW_TAG_ptr_to_member_type
:
8780 case DW_TAG_set_type
:
8781 case DW_TAG_string_type
:
8782 case DW_TAG_subroutine_type
:
8784 case DW_TAG_base_type
:
8785 case DW_TAG_class_type
:
8786 case DW_TAG_interface_type
:
8787 case DW_TAG_enumeration_type
:
8788 case DW_TAG_structure_type
:
8789 case DW_TAG_subrange_type
:
8790 case DW_TAG_typedef
:
8791 case DW_TAG_union_type
:
8798 /* Load all DIEs that are interesting for partial symbols into memory. */
8800 static struct partial_die_info
*
8801 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8802 int building_psymtab
, struct dwarf2_cu
*cu
)
8804 struct partial_die_info
*part_die
;
8805 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
8806 struct abbrev_info
*abbrev
;
8807 unsigned int bytes_read
;
8808 unsigned int load_all
= 0;
8810 int nesting_level
= 1;
8815 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
8819 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8823 &cu
->comp_unit_obstack
,
8824 hashtab_obstack_allocate
,
8825 dummy_obstack_deallocate
);
8827 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8828 sizeof (struct partial_die_info
));
8832 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
8834 /* A NULL abbrev means the end of a series of children. */
8837 if (--nesting_level
== 0)
8839 /* PART_DIE was probably the last thing allocated on the
8840 comp_unit_obstack, so we could call obstack_free
8841 here. We don't do that because the waste is small,
8842 and will be cleaned up when we're done with this
8843 compilation unit. This way, we're also more robust
8844 against other users of the comp_unit_obstack. */
8847 info_ptr
+= bytes_read
;
8848 last_die
= parent_die
;
8849 parent_die
= parent_die
->die_parent
;
8853 /* Check for template arguments. We never save these; if
8854 they're seen, we just mark the parent, and go on our way. */
8855 if (parent_die
!= NULL
8856 && cu
->language
== language_cplus
8857 && (abbrev
->tag
== DW_TAG_template_type_param
8858 || abbrev
->tag
== DW_TAG_template_value_param
))
8860 parent_die
->has_template_arguments
= 1;
8864 /* We don't need a partial DIE for the template argument. */
8865 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
8871 /* We only recurse into subprograms looking for template arguments.
8872 Skip their other children. */
8874 && cu
->language
== language_cplus
8875 && parent_die
!= NULL
8876 && parent_die
->tag
== DW_TAG_subprogram
)
8878 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8882 /* Check whether this DIE is interesting enough to save. Normally
8883 we would not be interested in members here, but there may be
8884 later variables referencing them via DW_AT_specification (for
8887 && !is_type_tag_for_partial (abbrev
->tag
)
8888 && abbrev
->tag
!= DW_TAG_constant
8889 && abbrev
->tag
!= DW_TAG_enumerator
8890 && abbrev
->tag
!= DW_TAG_subprogram
8891 && abbrev
->tag
!= DW_TAG_lexical_block
8892 && abbrev
->tag
!= DW_TAG_variable
8893 && abbrev
->tag
!= DW_TAG_namespace
8894 && abbrev
->tag
!= DW_TAG_module
8895 && abbrev
->tag
!= DW_TAG_member
)
8897 /* Otherwise we skip to the next sibling, if any. */
8898 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8902 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
8903 buffer
, info_ptr
, cu
);
8905 /* This two-pass algorithm for processing partial symbols has a
8906 high cost in cache pressure. Thus, handle some simple cases
8907 here which cover the majority of C partial symbols. DIEs
8908 which neither have specification tags in them, nor could have
8909 specification tags elsewhere pointing at them, can simply be
8910 processed and discarded.
8912 This segment is also optional; scan_partial_symbols and
8913 add_partial_symbol will handle these DIEs if we chain
8914 them in normally. When compilers which do not emit large
8915 quantities of duplicate debug information are more common,
8916 this code can probably be removed. */
8918 /* Any complete simple types at the top level (pretty much all
8919 of them, for a language without namespaces), can be processed
8921 if (parent_die
== NULL
8922 && part_die
->has_specification
== 0
8923 && part_die
->is_declaration
== 0
8924 && (part_die
->tag
== DW_TAG_typedef
8925 || part_die
->tag
== DW_TAG_base_type
8926 || part_die
->tag
== DW_TAG_subrange_type
))
8928 if (building_psymtab
&& part_die
->name
!= NULL
)
8929 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8930 VAR_DOMAIN
, LOC_TYPEDEF
,
8931 &cu
->objfile
->static_psymbols
,
8932 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8933 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8937 /* If we're at the second level, and we're an enumerator, and
8938 our parent has no specification (meaning possibly lives in a
8939 namespace elsewhere), then we can add the partial symbol now
8940 instead of queueing it. */
8941 if (part_die
->tag
== DW_TAG_enumerator
8942 && parent_die
!= NULL
8943 && parent_die
->die_parent
== NULL
8944 && parent_die
->tag
== DW_TAG_enumeration_type
8945 && parent_die
->has_specification
== 0)
8947 if (part_die
->name
== NULL
)
8948 complaint (&symfile_complaints
,
8949 _("malformed enumerator DIE ignored"));
8950 else if (building_psymtab
)
8951 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8952 VAR_DOMAIN
, LOC_CONST
,
8953 (cu
->language
== language_cplus
8954 || cu
->language
== language_java
)
8955 ? &cu
->objfile
->global_psymbols
8956 : &cu
->objfile
->static_psymbols
,
8957 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8959 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8963 /* We'll save this DIE so link it in. */
8964 part_die
->die_parent
= parent_die
;
8965 part_die
->die_sibling
= NULL
;
8966 part_die
->die_child
= NULL
;
8968 if (last_die
&& last_die
== parent_die
)
8969 last_die
->die_child
= part_die
;
8971 last_die
->die_sibling
= part_die
;
8973 last_die
= part_die
;
8975 if (first_die
== NULL
)
8976 first_die
= part_die
;
8978 /* Maybe add the DIE to the hash table. Not all DIEs that we
8979 find interesting need to be in the hash table, because we
8980 also have the parent/sibling/child chains; only those that we
8981 might refer to by offset later during partial symbol reading.
8983 For now this means things that might have be the target of a
8984 DW_AT_specification, DW_AT_abstract_origin, or
8985 DW_AT_extension. DW_AT_extension will refer only to
8986 namespaces; DW_AT_abstract_origin refers to functions (and
8987 many things under the function DIE, but we do not recurse
8988 into function DIEs during partial symbol reading) and
8989 possibly variables as well; DW_AT_specification refers to
8990 declarations. Declarations ought to have the DW_AT_declaration
8991 flag. It happens that GCC forgets to put it in sometimes, but
8992 only for functions, not for types.
8994 Adding more things than necessary to the hash table is harmless
8995 except for the performance cost. Adding too few will result in
8996 wasted time in find_partial_die, when we reread the compilation
8997 unit with load_all_dies set. */
9000 || abbrev
->tag
== DW_TAG_constant
9001 || abbrev
->tag
== DW_TAG_subprogram
9002 || abbrev
->tag
== DW_TAG_variable
9003 || abbrev
->tag
== DW_TAG_namespace
9004 || part_die
->is_declaration
)
9008 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9009 part_die
->offset
, INSERT
);
9013 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9014 sizeof (struct partial_die_info
));
9016 /* For some DIEs we want to follow their children (if any). For C
9017 we have no reason to follow the children of structures; for other
9018 languages we have to, so that we can get at method physnames
9019 to infer fully qualified class names, for DW_AT_specification,
9020 and for C++ template arguments. For C++, we also look one level
9021 inside functions to find template arguments (if the name of the
9022 function does not already contain the template arguments).
9024 For Ada, we need to scan the children of subprograms and lexical
9025 blocks as well because Ada allows the definition of nested
9026 entities that could be interesting for the debugger, such as
9027 nested subprograms for instance. */
9028 if (last_die
->has_children
9030 || last_die
->tag
== DW_TAG_namespace
9031 || last_die
->tag
== DW_TAG_module
9032 || last_die
->tag
== DW_TAG_enumeration_type
9033 || (cu
->language
== language_cplus
9034 && last_die
->tag
== DW_TAG_subprogram
9035 && (last_die
->name
== NULL
9036 || strchr (last_die
->name
, '<') == NULL
))
9037 || (cu
->language
!= language_c
9038 && (last_die
->tag
== DW_TAG_class_type
9039 || last_die
->tag
== DW_TAG_interface_type
9040 || last_die
->tag
== DW_TAG_structure_type
9041 || last_die
->tag
== DW_TAG_union_type
))
9042 || (cu
->language
== language_ada
9043 && (last_die
->tag
== DW_TAG_subprogram
9044 || last_die
->tag
== DW_TAG_lexical_block
))))
9047 parent_die
= last_die
;
9051 /* Otherwise we skip to the next sibling, if any. */
9052 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9054 /* Back to the top, do it again. */
9058 /* Read a minimal amount of information into the minimal die structure. */
9061 read_partial_die (struct partial_die_info
*part_die
,
9062 struct abbrev_info
*abbrev
,
9063 unsigned int abbrev_len
, bfd
*abfd
,
9064 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9065 struct dwarf2_cu
*cu
)
9068 struct attribute attr
;
9069 int has_low_pc_attr
= 0;
9070 int has_high_pc_attr
= 0;
9072 memset (part_die
, 0, sizeof (struct partial_die_info
));
9074 part_die
->offset
= info_ptr
- buffer
;
9076 info_ptr
+= abbrev_len
;
9081 part_die
->tag
= abbrev
->tag
;
9082 part_die
->has_children
= abbrev
->has_children
;
9084 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9086 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9088 /* Store the data if it is of an attribute we want to keep in a
9089 partial symbol table. */
9093 switch (part_die
->tag
)
9095 case DW_TAG_compile_unit
:
9096 case DW_TAG_type_unit
:
9097 /* Compilation units have a DW_AT_name that is a filename, not
9098 a source language identifier. */
9099 case DW_TAG_enumeration_type
:
9100 case DW_TAG_enumerator
:
9101 /* These tags always have simple identifiers already; no need
9102 to canonicalize them. */
9103 part_die
->name
= DW_STRING (&attr
);
9107 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9108 &cu
->objfile
->objfile_obstack
);
9112 case DW_AT_linkage_name
:
9113 case DW_AT_MIPS_linkage_name
:
9114 /* Note that both forms of linkage name might appear. We
9115 assume they will be the same, and we only store the last
9117 if (cu
->language
== language_ada
)
9118 part_die
->name
= DW_STRING (&attr
);
9119 part_die
->linkage_name
= DW_STRING (&attr
);
9122 has_low_pc_attr
= 1;
9123 part_die
->lowpc
= DW_ADDR (&attr
);
9126 has_high_pc_attr
= 1;
9127 part_die
->highpc
= DW_ADDR (&attr
);
9129 case DW_AT_location
:
9130 /* Support the .debug_loc offsets. */
9131 if (attr_form_is_block (&attr
))
9133 part_die
->locdesc
= DW_BLOCK (&attr
);
9135 else if (attr_form_is_section_offset (&attr
))
9137 dwarf2_complex_location_expr_complaint ();
9141 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9142 "partial symbol information");
9145 case DW_AT_external
:
9146 part_die
->is_external
= DW_UNSND (&attr
);
9148 case DW_AT_declaration
:
9149 part_die
->is_declaration
= DW_UNSND (&attr
);
9152 part_die
->has_type
= 1;
9154 case DW_AT_abstract_origin
:
9155 case DW_AT_specification
:
9156 case DW_AT_extension
:
9157 part_die
->has_specification
= 1;
9158 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9161 /* Ignore absolute siblings, they might point outside of
9162 the current compile unit. */
9163 if (attr
.form
== DW_FORM_ref_addr
)
9164 complaint (&symfile_complaints
,
9165 _("ignoring absolute DW_AT_sibling"));
9167 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9169 case DW_AT_byte_size
:
9170 part_die
->has_byte_size
= 1;
9172 case DW_AT_calling_convention
:
9173 /* DWARF doesn't provide a way to identify a program's source-level
9174 entry point. DW_AT_calling_convention attributes are only meant
9175 to describe functions' calling conventions.
9177 However, because it's a necessary piece of information in
9178 Fortran, and because DW_CC_program is the only piece of debugging
9179 information whose definition refers to a 'main program' at all,
9180 several compilers have begun marking Fortran main programs with
9181 DW_CC_program --- even when those functions use the standard
9182 calling conventions.
9184 So until DWARF specifies a way to provide this information and
9185 compilers pick up the new representation, we'll support this
9187 if (DW_UNSND (&attr
) == DW_CC_program
9188 && cu
->language
== language_fortran
)
9190 set_main_name (part_die
->name
);
9192 /* As this DIE has a static linkage the name would be difficult
9193 to look up later. */
9194 language_of_main
= language_fortran
;
9202 if (has_low_pc_attr
&& has_high_pc_attr
)
9204 /* When using the GNU linker, .gnu.linkonce. sections are used to
9205 eliminate duplicate copies of functions and vtables and such.
9206 The linker will arbitrarily choose one and discard the others.
9207 The AT_*_pc values for such functions refer to local labels in
9208 these sections. If the section from that file was discarded, the
9209 labels are not in the output, so the relocs get a value of 0.
9210 If this is a discarded function, mark the pc bounds as invalid,
9211 so that GDB will ignore it. */
9212 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9214 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9216 complaint (&symfile_complaints
,
9217 _("DW_AT_low_pc %s is zero "
9218 "for DIE at 0x%x [in module %s]"),
9219 paddress (gdbarch
, part_die
->lowpc
),
9220 part_die
->offset
, cu
->objfile
->name
);
9222 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9223 else if (part_die
->lowpc
>= part_die
->highpc
)
9225 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9227 complaint (&symfile_complaints
,
9228 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9229 "for DIE at 0x%x [in module %s]"),
9230 paddress (gdbarch
, part_die
->lowpc
),
9231 paddress (gdbarch
, part_die
->highpc
),
9232 part_die
->offset
, cu
->objfile
->name
);
9235 part_die
->has_pc_info
= 1;
9241 /* Find a cached partial DIE at OFFSET in CU. */
9243 static struct partial_die_info
*
9244 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9246 struct partial_die_info
*lookup_die
= NULL
;
9247 struct partial_die_info part_die
;
9249 part_die
.offset
= offset
;
9250 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9255 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9256 except in the case of .debug_types DIEs which do not reference
9257 outside their CU (they do however referencing other types via
9258 DW_FORM_ref_sig8). */
9260 static struct partial_die_info
*
9261 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9263 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9264 struct partial_die_info
*pd
= NULL
;
9266 if (cu
->per_cu
->from_debug_types
)
9268 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9274 if (offset_in_cu_p (&cu
->header
, offset
))
9276 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9281 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9283 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9284 load_partial_comp_unit (per_cu
, cu
->objfile
);
9286 per_cu
->cu
->last_used
= 0;
9287 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9289 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9291 struct cleanup
*back_to
;
9292 struct partial_die_info comp_unit_die
;
9293 struct abbrev_info
*abbrev
;
9294 unsigned int bytes_read
;
9297 per_cu
->load_all_dies
= 1;
9299 /* Re-read the DIEs. */
9300 back_to
= make_cleanup (null_cleanup
, 0);
9301 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9303 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
9304 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9306 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9307 + per_cu
->cu
->header
.offset
9308 + per_cu
->cu
->header
.first_die_offset
);
9309 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9310 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9311 per_cu
->cu
->objfile
->obfd
,
9312 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9314 if (comp_unit_die
.has_children
)
9315 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
9316 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9318 do_cleanups (back_to
);
9320 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9326 internal_error (__FILE__
, __LINE__
,
9327 _("could not find partial DIE 0x%x "
9328 "in cache [from module %s]\n"),
9329 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9333 /* See if we can figure out if the class lives in a namespace. We do
9334 this by looking for a member function; its demangled name will
9335 contain namespace info, if there is any. */
9338 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9339 struct dwarf2_cu
*cu
)
9341 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9342 what template types look like, because the demangler
9343 frequently doesn't give the same name as the debug info. We
9344 could fix this by only using the demangled name to get the
9345 prefix (but see comment in read_structure_type). */
9347 struct partial_die_info
*real_pdi
;
9348 struct partial_die_info
*child_pdi
;
9350 /* If this DIE (this DIE's specification, if any) has a parent, then
9351 we should not do this. We'll prepend the parent's fully qualified
9352 name when we create the partial symbol. */
9354 real_pdi
= struct_pdi
;
9355 while (real_pdi
->has_specification
)
9356 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9358 if (real_pdi
->die_parent
!= NULL
)
9361 for (child_pdi
= struct_pdi
->die_child
;
9363 child_pdi
= child_pdi
->die_sibling
)
9365 if (child_pdi
->tag
== DW_TAG_subprogram
9366 && child_pdi
->linkage_name
!= NULL
)
9368 char *actual_class_name
9369 = language_class_name_from_physname (cu
->language_defn
,
9370 child_pdi
->linkage_name
);
9371 if (actual_class_name
!= NULL
)
9374 = obsavestring (actual_class_name
,
9375 strlen (actual_class_name
),
9376 &cu
->objfile
->objfile_obstack
);
9377 xfree (actual_class_name
);
9384 /* Adjust PART_DIE before generating a symbol for it. This function
9385 may set the is_external flag or change the DIE's name. */
9388 fixup_partial_die (struct partial_die_info
*part_die
,
9389 struct dwarf2_cu
*cu
)
9391 /* Once we've fixed up a die, there's no point in doing so again.
9392 This also avoids a memory leak if we were to call
9393 guess_partial_die_structure_name multiple times. */
9394 if (part_die
->fixup_called
)
9397 /* If we found a reference attribute and the DIE has no name, try
9398 to find a name in the referred to DIE. */
9400 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9402 struct partial_die_info
*spec_die
;
9404 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9406 fixup_partial_die (spec_die
, cu
);
9410 part_die
->name
= spec_die
->name
;
9412 /* Copy DW_AT_external attribute if it is set. */
9413 if (spec_die
->is_external
)
9414 part_die
->is_external
= spec_die
->is_external
;
9418 /* Set default names for some unnamed DIEs. */
9420 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9421 part_die
->name
= "(anonymous namespace)";
9423 /* If there is no parent die to provide a namespace, and there are
9424 children, see if we can determine the namespace from their linkage
9426 NOTE: We need to do this even if cu->has_namespace_info != 0.
9427 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9428 if (cu
->language
== language_cplus
9429 && dwarf2_per_objfile
->types
.asection
!= NULL
9430 && part_die
->die_parent
== NULL
9431 && part_die
->has_children
9432 && (part_die
->tag
== DW_TAG_class_type
9433 || part_die
->tag
== DW_TAG_structure_type
9434 || part_die
->tag
== DW_TAG_union_type
))
9435 guess_partial_die_structure_name (part_die
, cu
);
9437 /* GCC might emit a nameless struct or union that has a linkage
9438 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
9439 if (part_die
->name
== NULL
9440 && (part_die
->tag
== DW_TAG_structure_type
9441 || part_die
->tag
== DW_TAG_union_type
9442 || part_die
->tag
== DW_TAG_class_type
)
9443 && part_die
->linkage_name
!= NULL
)
9447 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
9450 part_die
->name
= obsavestring (demangled
, strlen (demangled
),
9451 &cu
->objfile
->objfile_obstack
);
9456 part_die
->fixup_called
= 1;
9459 /* Read an attribute value described by an attribute form. */
9462 read_attribute_value (struct attribute
*attr
, unsigned form
,
9463 bfd
*abfd
, gdb_byte
*info_ptr
,
9464 struct dwarf2_cu
*cu
)
9466 struct comp_unit_head
*cu_header
= &cu
->header
;
9467 unsigned int bytes_read
;
9468 struct dwarf_block
*blk
;
9473 case DW_FORM_ref_addr
:
9474 if (cu
->header
.version
== 2)
9475 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9477 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
9478 &cu
->header
, &bytes_read
);
9479 info_ptr
+= bytes_read
;
9482 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9483 info_ptr
+= bytes_read
;
9485 case DW_FORM_block2
:
9486 blk
= dwarf_alloc_block (cu
);
9487 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9489 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9490 info_ptr
+= blk
->size
;
9491 DW_BLOCK (attr
) = blk
;
9493 case DW_FORM_block4
:
9494 blk
= dwarf_alloc_block (cu
);
9495 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9497 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9498 info_ptr
+= blk
->size
;
9499 DW_BLOCK (attr
) = blk
;
9502 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9506 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9510 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9513 case DW_FORM_sec_offset
:
9514 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9515 info_ptr
+= bytes_read
;
9517 case DW_FORM_string
:
9518 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9519 DW_STRING_IS_CANONICAL (attr
) = 0;
9520 info_ptr
+= bytes_read
;
9523 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9525 DW_STRING_IS_CANONICAL (attr
) = 0;
9526 info_ptr
+= bytes_read
;
9528 case DW_FORM_exprloc
:
9530 blk
= dwarf_alloc_block (cu
);
9531 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9532 info_ptr
+= bytes_read
;
9533 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9534 info_ptr
+= blk
->size
;
9535 DW_BLOCK (attr
) = blk
;
9537 case DW_FORM_block1
:
9538 blk
= dwarf_alloc_block (cu
);
9539 blk
->size
= read_1_byte (abfd
, info_ptr
);
9541 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9542 info_ptr
+= blk
->size
;
9543 DW_BLOCK (attr
) = blk
;
9546 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9550 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9553 case DW_FORM_flag_present
:
9554 DW_UNSND (attr
) = 1;
9557 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9558 info_ptr
+= bytes_read
;
9561 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9562 info_ptr
+= bytes_read
;
9565 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9569 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9573 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9577 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9580 case DW_FORM_ref_sig8
:
9581 /* Convert the signature to something we can record in DW_UNSND
9583 NOTE: This is NULL if the type wasn't found. */
9584 DW_SIGNATURED_TYPE (attr
) =
9585 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9588 case DW_FORM_ref_udata
:
9589 DW_ADDR (attr
) = (cu
->header
.offset
9590 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9591 info_ptr
+= bytes_read
;
9593 case DW_FORM_indirect
:
9594 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9595 info_ptr
+= bytes_read
;
9596 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9599 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9600 dwarf_form_name (form
),
9601 bfd_get_filename (abfd
));
9604 /* We have seen instances where the compiler tried to emit a byte
9605 size attribute of -1 which ended up being encoded as an unsigned
9606 0xffffffff. Although 0xffffffff is technically a valid size value,
9607 an object of this size seems pretty unlikely so we can relatively
9608 safely treat these cases as if the size attribute was invalid and
9609 treat them as zero by default. */
9610 if (attr
->name
== DW_AT_byte_size
9611 && form
== DW_FORM_data4
9612 && DW_UNSND (attr
) >= 0xffffffff)
9615 (&symfile_complaints
,
9616 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9617 hex_string (DW_UNSND (attr
)));
9618 DW_UNSND (attr
) = 0;
9624 /* Read an attribute described by an abbreviated attribute. */
9627 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9628 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9630 attr
->name
= abbrev
->name
;
9631 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9634 /* Read dwarf information from a buffer. */
9637 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9639 return bfd_get_8 (abfd
, buf
);
9643 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9645 return bfd_get_signed_8 (abfd
, buf
);
9649 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9651 return bfd_get_16 (abfd
, buf
);
9655 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9657 return bfd_get_signed_16 (abfd
, buf
);
9661 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9663 return bfd_get_32 (abfd
, buf
);
9667 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9669 return bfd_get_signed_32 (abfd
, buf
);
9673 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9675 return bfd_get_64 (abfd
, buf
);
9679 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9680 unsigned int *bytes_read
)
9682 struct comp_unit_head
*cu_header
= &cu
->header
;
9683 CORE_ADDR retval
= 0;
9685 if (cu_header
->signed_addr_p
)
9687 switch (cu_header
->addr_size
)
9690 retval
= bfd_get_signed_16 (abfd
, buf
);
9693 retval
= bfd_get_signed_32 (abfd
, buf
);
9696 retval
= bfd_get_signed_64 (abfd
, buf
);
9699 internal_error (__FILE__
, __LINE__
,
9700 _("read_address: bad switch, signed [in module %s]"),
9701 bfd_get_filename (abfd
));
9706 switch (cu_header
->addr_size
)
9709 retval
= bfd_get_16 (abfd
, buf
);
9712 retval
= bfd_get_32 (abfd
, buf
);
9715 retval
= bfd_get_64 (abfd
, buf
);
9718 internal_error (__FILE__
, __LINE__
,
9719 _("read_address: bad switch, "
9720 "unsigned [in module %s]"),
9721 bfd_get_filename (abfd
));
9725 *bytes_read
= cu_header
->addr_size
;
9729 /* Read the initial length from a section. The (draft) DWARF 3
9730 specification allows the initial length to take up either 4 bytes
9731 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9732 bytes describe the length and all offsets will be 8 bytes in length
9735 An older, non-standard 64-bit format is also handled by this
9736 function. The older format in question stores the initial length
9737 as an 8-byte quantity without an escape value. Lengths greater
9738 than 2^32 aren't very common which means that the initial 4 bytes
9739 is almost always zero. Since a length value of zero doesn't make
9740 sense for the 32-bit format, this initial zero can be considered to
9741 be an escape value which indicates the presence of the older 64-bit
9742 format. As written, the code can't detect (old format) lengths
9743 greater than 4GB. If it becomes necessary to handle lengths
9744 somewhat larger than 4GB, we could allow other small values (such
9745 as the non-sensical values of 1, 2, and 3) to also be used as
9746 escape values indicating the presence of the old format.
9748 The value returned via bytes_read should be used to increment the
9749 relevant pointer after calling read_initial_length().
9751 [ Note: read_initial_length() and read_offset() are based on the
9752 document entitled "DWARF Debugging Information Format", revision
9753 3, draft 8, dated November 19, 2001. This document was obtained
9756 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9758 This document is only a draft and is subject to change. (So beware.)
9760 Details regarding the older, non-standard 64-bit format were
9761 determined empirically by examining 64-bit ELF files produced by
9762 the SGI toolchain on an IRIX 6.5 machine.
9764 - Kevin, July 16, 2002
9768 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
9770 LONGEST length
= bfd_get_32 (abfd
, buf
);
9772 if (length
== 0xffffffff)
9774 length
= bfd_get_64 (abfd
, buf
+ 4);
9777 else if (length
== 0)
9779 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9780 length
= bfd_get_64 (abfd
, buf
);
9791 /* Cover function for read_initial_length.
9792 Returns the length of the object at BUF, and stores the size of the
9793 initial length in *BYTES_READ and stores the size that offsets will be in
9795 If the initial length size is not equivalent to that specified in
9796 CU_HEADER then issue a complaint.
9797 This is useful when reading non-comp-unit headers. */
9800 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
9801 const struct comp_unit_head
*cu_header
,
9802 unsigned int *bytes_read
,
9803 unsigned int *offset_size
)
9805 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
9807 gdb_assert (cu_header
->initial_length_size
== 4
9808 || cu_header
->initial_length_size
== 8
9809 || cu_header
->initial_length_size
== 12);
9811 if (cu_header
->initial_length_size
!= *bytes_read
)
9812 complaint (&symfile_complaints
,
9813 _("intermixed 32-bit and 64-bit DWARF sections"));
9815 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
9819 /* Read an offset from the data stream. The size of the offset is
9820 given by cu_header->offset_size. */
9823 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
9824 unsigned int *bytes_read
)
9826 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
9828 *bytes_read
= cu_header
->offset_size
;
9832 /* Read an offset from the data stream. */
9835 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
9839 switch (offset_size
)
9842 retval
= bfd_get_32 (abfd
, buf
);
9845 retval
= bfd_get_64 (abfd
, buf
);
9848 internal_error (__FILE__
, __LINE__
,
9849 _("read_offset_1: bad switch [in module %s]"),
9850 bfd_get_filename (abfd
));
9857 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
9859 /* If the size of a host char is 8 bits, we can return a pointer
9860 to the buffer, otherwise we have to copy the data to a buffer
9861 allocated on the temporary obstack. */
9862 gdb_assert (HOST_CHAR_BIT
== 8);
9867 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9869 /* If the size of a host char is 8 bits, we can return a pointer
9870 to the string, otherwise we have to copy the string to a buffer
9871 allocated on the temporary obstack. */
9872 gdb_assert (HOST_CHAR_BIT
== 8);
9875 *bytes_read_ptr
= 1;
9878 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
9879 return (char *) buf
;
9883 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
9884 const struct comp_unit_head
*cu_header
,
9885 unsigned int *bytes_read_ptr
)
9887 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
9889 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
9890 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
9892 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9893 bfd_get_filename (abfd
));
9896 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
9898 error (_("DW_FORM_strp pointing outside of "
9899 ".debug_str section [in module %s]"),
9900 bfd_get_filename (abfd
));
9903 gdb_assert (HOST_CHAR_BIT
== 8);
9904 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
9906 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
9909 static unsigned long
9910 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9912 unsigned long result
;
9913 unsigned int num_read
;
9923 byte
= bfd_get_8 (abfd
, buf
);
9926 result
|= ((unsigned long)(byte
& 127) << shift
);
9927 if ((byte
& 128) == 0)
9933 *bytes_read_ptr
= num_read
;
9938 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9941 int i
, shift
, num_read
;
9950 byte
= bfd_get_8 (abfd
, buf
);
9953 result
|= ((long)(byte
& 127) << shift
);
9955 if ((byte
& 128) == 0)
9960 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
9961 result
|= -(((long)1) << shift
);
9962 *bytes_read_ptr
= num_read
;
9966 /* Return a pointer to just past the end of an LEB128 number in BUF. */
9969 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
9975 byte
= bfd_get_8 (abfd
, buf
);
9977 if ((byte
& 128) == 0)
9983 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
9990 cu
->language
= language_c
;
9992 case DW_LANG_C_plus_plus
:
9993 cu
->language
= language_cplus
;
9996 cu
->language
= language_d
;
9998 case DW_LANG_Fortran77
:
9999 case DW_LANG_Fortran90
:
10000 case DW_LANG_Fortran95
:
10001 cu
->language
= language_fortran
;
10003 case DW_LANG_Mips_Assembler
:
10004 cu
->language
= language_asm
;
10007 cu
->language
= language_java
;
10009 case DW_LANG_Ada83
:
10010 case DW_LANG_Ada95
:
10011 cu
->language
= language_ada
;
10013 case DW_LANG_Modula2
:
10014 cu
->language
= language_m2
;
10016 case DW_LANG_Pascal83
:
10017 cu
->language
= language_pascal
;
10020 cu
->language
= language_objc
;
10022 case DW_LANG_Cobol74
:
10023 case DW_LANG_Cobol85
:
10025 cu
->language
= language_minimal
;
10028 cu
->language_defn
= language_def (cu
->language
);
10031 /* Return the named attribute or NULL if not there. */
10033 static struct attribute
*
10034 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10037 struct attribute
*spec
= NULL
;
10039 for (i
= 0; i
< die
->num_attrs
; ++i
)
10041 if (die
->attrs
[i
].name
== name
)
10042 return &die
->attrs
[i
];
10043 if (die
->attrs
[i
].name
== DW_AT_specification
10044 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10045 spec
= &die
->attrs
[i
];
10050 die
= follow_die_ref (die
, spec
, &cu
);
10051 return dwarf2_attr (die
, name
, cu
);
10057 /* Return the named attribute or NULL if not there,
10058 but do not follow DW_AT_specification, etc.
10059 This is for use in contexts where we're reading .debug_types dies.
10060 Following DW_AT_specification, DW_AT_abstract_origin will take us
10061 back up the chain, and we want to go down. */
10063 static struct attribute
*
10064 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10065 struct dwarf2_cu
*cu
)
10069 for (i
= 0; i
< die
->num_attrs
; ++i
)
10070 if (die
->attrs
[i
].name
== name
)
10071 return &die
->attrs
[i
];
10076 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10077 and holds a non-zero value. This function should only be used for
10078 DW_FORM_flag or DW_FORM_flag_present attributes. */
10081 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10083 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10085 return (attr
&& DW_UNSND (attr
));
10089 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10091 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10092 which value is non-zero. However, we have to be careful with
10093 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10094 (via dwarf2_flag_true_p) follows this attribute. So we may
10095 end up accidently finding a declaration attribute that belongs
10096 to a different DIE referenced by the specification attribute,
10097 even though the given DIE does not have a declaration attribute. */
10098 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10099 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10102 /* Return the die giving the specification for DIE, if there is
10103 one. *SPEC_CU is the CU containing DIE on input, and the CU
10104 containing the return value on output. If there is no
10105 specification, but there is an abstract origin, that is
10108 static struct die_info
*
10109 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10111 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10114 if (spec_attr
== NULL
)
10115 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10117 if (spec_attr
== NULL
)
10120 return follow_die_ref (die
, spec_attr
, spec_cu
);
10123 /* Free the line_header structure *LH, and any arrays and strings it
10125 NOTE: This is also used as a "cleanup" function. */
10128 free_line_header (struct line_header
*lh
)
10130 if (lh
->standard_opcode_lengths
)
10131 xfree (lh
->standard_opcode_lengths
);
10133 /* Remember that all the lh->file_names[i].name pointers are
10134 pointers into debug_line_buffer, and don't need to be freed. */
10135 if (lh
->file_names
)
10136 xfree (lh
->file_names
);
10138 /* Similarly for the include directory names. */
10139 if (lh
->include_dirs
)
10140 xfree (lh
->include_dirs
);
10145 /* Add an entry to LH's include directory table. */
10148 add_include_dir (struct line_header
*lh
, char *include_dir
)
10150 /* Grow the array if necessary. */
10151 if (lh
->include_dirs_size
== 0)
10153 lh
->include_dirs_size
= 1; /* for testing */
10154 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10155 * sizeof (*lh
->include_dirs
));
10157 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10159 lh
->include_dirs_size
*= 2;
10160 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10161 (lh
->include_dirs_size
10162 * sizeof (*lh
->include_dirs
)));
10165 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10168 /* Add an entry to LH's file name table. */
10171 add_file_name (struct line_header
*lh
,
10173 unsigned int dir_index
,
10174 unsigned int mod_time
,
10175 unsigned int length
)
10177 struct file_entry
*fe
;
10179 /* Grow the array if necessary. */
10180 if (lh
->file_names_size
== 0)
10182 lh
->file_names_size
= 1; /* for testing */
10183 lh
->file_names
= xmalloc (lh
->file_names_size
10184 * sizeof (*lh
->file_names
));
10186 else if (lh
->num_file_names
>= lh
->file_names_size
)
10188 lh
->file_names_size
*= 2;
10189 lh
->file_names
= xrealloc (lh
->file_names
,
10190 (lh
->file_names_size
10191 * sizeof (*lh
->file_names
)));
10194 fe
= &lh
->file_names
[lh
->num_file_names
++];
10196 fe
->dir_index
= dir_index
;
10197 fe
->mod_time
= mod_time
;
10198 fe
->length
= length
;
10199 fe
->included_p
= 0;
10203 /* Read the statement program header starting at OFFSET in
10204 .debug_line, according to the endianness of ABFD. Return a pointer
10205 to a struct line_header, allocated using xmalloc.
10207 NOTE: the strings in the include directory and file name tables of
10208 the returned object point into debug_line_buffer, and must not be
10211 static struct line_header
*
10212 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10213 struct dwarf2_cu
*cu
)
10215 struct cleanup
*back_to
;
10216 struct line_header
*lh
;
10217 gdb_byte
*line_ptr
;
10218 unsigned int bytes_read
, offset_size
;
10220 char *cur_dir
, *cur_file
;
10222 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10223 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10225 complaint (&symfile_complaints
, _("missing .debug_line section"));
10229 /* Make sure that at least there's room for the total_length field.
10230 That could be 12 bytes long, but we're just going to fudge that. */
10231 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10233 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10237 lh
= xmalloc (sizeof (*lh
));
10238 memset (lh
, 0, sizeof (*lh
));
10239 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10242 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10244 /* Read in the header. */
10246 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10247 &bytes_read
, &offset_size
);
10248 line_ptr
+= bytes_read
;
10249 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10250 + dwarf2_per_objfile
->line
.size
))
10252 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10255 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10256 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10258 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10259 line_ptr
+= offset_size
;
10260 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10262 if (lh
->version
>= 4)
10264 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10268 lh
->maximum_ops_per_instruction
= 1;
10270 if (lh
->maximum_ops_per_instruction
== 0)
10272 lh
->maximum_ops_per_instruction
= 1;
10273 complaint (&symfile_complaints
,
10274 _("invalid maximum_ops_per_instruction "
10275 "in `.debug_line' section"));
10278 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10280 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10282 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10284 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10286 lh
->standard_opcode_lengths
10287 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10289 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10290 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10292 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10296 /* Read directory table. */
10297 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10299 line_ptr
+= bytes_read
;
10300 add_include_dir (lh
, cur_dir
);
10302 line_ptr
+= bytes_read
;
10304 /* Read file name table. */
10305 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10307 unsigned int dir_index
, mod_time
, length
;
10309 line_ptr
+= bytes_read
;
10310 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10311 line_ptr
+= bytes_read
;
10312 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10313 line_ptr
+= bytes_read
;
10314 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10315 line_ptr
+= bytes_read
;
10317 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10319 line_ptr
+= bytes_read
;
10320 lh
->statement_program_start
= line_ptr
;
10322 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
10323 + dwarf2_per_objfile
->line
.size
))
10324 complaint (&symfile_complaints
,
10325 _("line number info header doesn't "
10326 "fit in `.debug_line' section"));
10328 discard_cleanups (back_to
);
10332 /* This function exists to work around a bug in certain compilers
10333 (particularly GCC 2.95), in which the first line number marker of a
10334 function does not show up until after the prologue, right before
10335 the second line number marker. This function shifts ADDRESS down
10336 to the beginning of the function if necessary, and is called on
10337 addresses passed to record_line. */
10340 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
10342 struct function_range
*fn
;
10344 /* Find the function_range containing address. */
10348 if (!cu
->cached_fn
)
10349 cu
->cached_fn
= cu
->first_fn
;
10351 fn
= cu
->cached_fn
;
10353 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10359 while (fn
&& fn
!= cu
->cached_fn
)
10360 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10370 if (address
!= fn
->lowpc
)
10371 complaint (&symfile_complaints
,
10372 _("misplaced first line number at 0x%lx for '%s'"),
10373 (unsigned long) address
, fn
->name
);
10378 /* Subroutine of dwarf_decode_lines to simplify it.
10379 Return the file name of the psymtab for included file FILE_INDEX
10380 in line header LH of PST.
10381 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10382 If space for the result is malloc'd, it will be freed by a cleanup.
10383 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10386 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10387 const struct partial_symtab
*pst
,
10388 const char *comp_dir
)
10390 const struct file_entry fe
= lh
->file_names
[file_index
];
10391 char *include_name
= fe
.name
;
10392 char *include_name_to_compare
= include_name
;
10393 char *dir_name
= NULL
;
10394 const char *pst_filename
;
10395 char *copied_name
= NULL
;
10399 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10401 if (!IS_ABSOLUTE_PATH (include_name
)
10402 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10404 /* Avoid creating a duplicate psymtab for PST.
10405 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10406 Before we do the comparison, however, we need to account
10407 for DIR_NAME and COMP_DIR.
10408 First prepend dir_name (if non-NULL). If we still don't
10409 have an absolute path prepend comp_dir (if non-NULL).
10410 However, the directory we record in the include-file's
10411 psymtab does not contain COMP_DIR (to match the
10412 corresponding symtab(s)).
10417 bash$ gcc -g ./hello.c
10418 include_name = "hello.c"
10420 DW_AT_comp_dir = comp_dir = "/tmp"
10421 DW_AT_name = "./hello.c" */
10423 if (dir_name
!= NULL
)
10425 include_name
= concat (dir_name
, SLASH_STRING
,
10426 include_name
, (char *)NULL
);
10427 include_name_to_compare
= include_name
;
10428 make_cleanup (xfree
, include_name
);
10430 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10432 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10433 include_name
, (char *)NULL
);
10437 pst_filename
= pst
->filename
;
10438 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10440 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
10441 pst_filename
, (char *)NULL
);
10442 pst_filename
= copied_name
;
10445 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
10447 if (include_name_to_compare
!= include_name
)
10448 xfree (include_name_to_compare
);
10449 if (copied_name
!= NULL
)
10450 xfree (copied_name
);
10454 return include_name
;
10457 /* Ignore this record_line request. */
10460 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10465 /* Decode the Line Number Program (LNP) for the given line_header
10466 structure and CU. The actual information extracted and the type
10467 of structures created from the LNP depends on the value of PST.
10469 1. If PST is NULL, then this procedure uses the data from the program
10470 to create all necessary symbol tables, and their linetables.
10472 2. If PST is not NULL, this procedure reads the program to determine
10473 the list of files included by the unit represented by PST, and
10474 builds all the associated partial symbol tables.
10476 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10477 It is used for relative paths in the line table.
10478 NOTE: When processing partial symtabs (pst != NULL),
10479 comp_dir == pst->dirname.
10481 NOTE: It is important that psymtabs have the same file name (via strcmp)
10482 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10483 symtab we don't use it in the name of the psymtabs we create.
10484 E.g. expand_line_sal requires this when finding psymtabs to expand.
10485 A good testcase for this is mb-inline.exp. */
10488 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
10489 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10491 gdb_byte
*line_ptr
, *extended_end
;
10492 gdb_byte
*line_end
;
10493 unsigned int bytes_read
, extended_len
;
10494 unsigned char op_code
, extended_op
, adj_opcode
;
10495 CORE_ADDR baseaddr
;
10496 struct objfile
*objfile
= cu
->objfile
;
10497 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10498 const int decode_for_pst_p
= (pst
!= NULL
);
10499 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10500 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10503 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10505 line_ptr
= lh
->statement_program_start
;
10506 line_end
= lh
->statement_program_end
;
10508 /* Read the statement sequences until there's nothing left. */
10509 while (line_ptr
< line_end
)
10511 /* state machine registers */
10512 CORE_ADDR address
= 0;
10513 unsigned int file
= 1;
10514 unsigned int line
= 1;
10515 unsigned int column
= 0;
10516 int is_stmt
= lh
->default_is_stmt
;
10517 int basic_block
= 0;
10518 int end_sequence
= 0;
10520 unsigned char op_index
= 0;
10522 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10524 /* Start a subfile for the current file of the state machine. */
10525 /* lh->include_dirs and lh->file_names are 0-based, but the
10526 directory and file name numbers in the statement program
10528 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10532 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10534 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10537 /* Decode the table. */
10538 while (!end_sequence
)
10540 op_code
= read_1_byte (abfd
, line_ptr
);
10542 if (line_ptr
> line_end
)
10544 dwarf2_debug_line_missing_end_sequence_complaint ();
10548 if (op_code
>= lh
->opcode_base
)
10550 /* Special operand. */
10551 adj_opcode
= op_code
- lh
->opcode_base
;
10552 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10553 / lh
->maximum_ops_per_instruction
)
10554 * lh
->minimum_instruction_length
);
10555 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10556 % lh
->maximum_ops_per_instruction
);
10557 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10558 if (lh
->num_file_names
< file
|| file
== 0)
10559 dwarf2_debug_line_missing_file_complaint ();
10560 /* For now we ignore lines not starting on an
10561 instruction boundary. */
10562 else if (op_index
== 0)
10564 lh
->file_names
[file
- 1].included_p
= 1;
10565 if (!decode_for_pst_p
&& is_stmt
)
10567 if (last_subfile
!= current_subfile
)
10569 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10571 (*p_record_line
) (last_subfile
, 0, addr
);
10572 last_subfile
= current_subfile
;
10574 /* Append row to matrix using current values. */
10575 addr
= check_cu_functions (address
, cu
);
10576 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10577 (*p_record_line
) (current_subfile
, line
, addr
);
10582 else switch (op_code
)
10584 case DW_LNS_extended_op
:
10585 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
10587 line_ptr
+= bytes_read
;
10588 extended_end
= line_ptr
+ extended_len
;
10589 extended_op
= read_1_byte (abfd
, line_ptr
);
10591 switch (extended_op
)
10593 case DW_LNE_end_sequence
:
10594 p_record_line
= record_line
;
10597 case DW_LNE_set_address
:
10598 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10600 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10602 /* This line table is for a function which has been
10603 GCd by the linker. Ignore it. PR gdb/12528 */
10606 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
10608 complaint (&symfile_complaints
,
10609 _(".debug_line address at offset 0x%lx is 0 "
10611 line_offset
, cu
->objfile
->name
);
10612 p_record_line
= noop_record_line
;
10616 line_ptr
+= bytes_read
;
10617 address
+= baseaddr
;
10619 case DW_LNE_define_file
:
10622 unsigned int dir_index
, mod_time
, length
;
10624 cur_file
= read_direct_string (abfd
, line_ptr
,
10626 line_ptr
+= bytes_read
;
10628 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10629 line_ptr
+= bytes_read
;
10631 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10632 line_ptr
+= bytes_read
;
10634 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10635 line_ptr
+= bytes_read
;
10636 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10639 case DW_LNE_set_discriminator
:
10640 /* The discriminator is not interesting to the debugger;
10642 line_ptr
= extended_end
;
10645 complaint (&symfile_complaints
,
10646 _("mangled .debug_line section"));
10649 /* Make sure that we parsed the extended op correctly. If e.g.
10650 we expected a different address size than the producer used,
10651 we may have read the wrong number of bytes. */
10652 if (line_ptr
!= extended_end
)
10654 complaint (&symfile_complaints
,
10655 _("mangled .debug_line section"));
10660 if (lh
->num_file_names
< file
|| file
== 0)
10661 dwarf2_debug_line_missing_file_complaint ();
10664 lh
->file_names
[file
- 1].included_p
= 1;
10665 if (!decode_for_pst_p
&& is_stmt
)
10667 if (last_subfile
!= current_subfile
)
10669 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10671 (*p_record_line
) (last_subfile
, 0, addr
);
10672 last_subfile
= current_subfile
;
10674 addr
= check_cu_functions (address
, cu
);
10675 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10676 (*p_record_line
) (current_subfile
, line
, addr
);
10681 case DW_LNS_advance_pc
:
10684 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10686 address
+= (((op_index
+ adjust
)
10687 / lh
->maximum_ops_per_instruction
)
10688 * lh
->minimum_instruction_length
);
10689 op_index
= ((op_index
+ adjust
)
10690 % lh
->maximum_ops_per_instruction
);
10691 line_ptr
+= bytes_read
;
10694 case DW_LNS_advance_line
:
10695 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
10696 line_ptr
+= bytes_read
;
10698 case DW_LNS_set_file
:
10700 /* The arrays lh->include_dirs and lh->file_names are
10701 0-based, but the directory and file name numbers in
10702 the statement program are 1-based. */
10703 struct file_entry
*fe
;
10706 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10707 line_ptr
+= bytes_read
;
10708 if (lh
->num_file_names
< file
|| file
== 0)
10709 dwarf2_debug_line_missing_file_complaint ();
10712 fe
= &lh
->file_names
[file
- 1];
10714 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10715 if (!decode_for_pst_p
)
10717 last_subfile
= current_subfile
;
10718 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10723 case DW_LNS_set_column
:
10724 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10725 line_ptr
+= bytes_read
;
10727 case DW_LNS_negate_stmt
:
10728 is_stmt
= (!is_stmt
);
10730 case DW_LNS_set_basic_block
:
10733 /* Add to the address register of the state machine the
10734 address increment value corresponding to special opcode
10735 255. I.e., this value is scaled by the minimum
10736 instruction length since special opcode 255 would have
10737 scaled the increment. */
10738 case DW_LNS_const_add_pc
:
10740 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
10742 address
+= (((op_index
+ adjust
)
10743 / lh
->maximum_ops_per_instruction
)
10744 * lh
->minimum_instruction_length
);
10745 op_index
= ((op_index
+ adjust
)
10746 % lh
->maximum_ops_per_instruction
);
10749 case DW_LNS_fixed_advance_pc
:
10750 address
+= read_2_bytes (abfd
, line_ptr
);
10756 /* Unknown standard opcode, ignore it. */
10759 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
10761 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10762 line_ptr
+= bytes_read
;
10767 if (lh
->num_file_names
< file
|| file
== 0)
10768 dwarf2_debug_line_missing_file_complaint ();
10771 lh
->file_names
[file
- 1].included_p
= 1;
10772 if (!decode_for_pst_p
)
10774 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10775 (*p_record_line
) (current_subfile
, 0, addr
);
10780 if (decode_for_pst_p
)
10784 /* Now that we're done scanning the Line Header Program, we can
10785 create the psymtab of each included file. */
10786 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
10787 if (lh
->file_names
[file_index
].included_p
== 1)
10789 char *include_name
=
10790 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
10791 if (include_name
!= NULL
)
10792 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
10797 /* Make sure a symtab is created for every file, even files
10798 which contain only variables (i.e. no code with associated
10802 struct file_entry
*fe
;
10804 for (i
= 0; i
< lh
->num_file_names
; i
++)
10808 fe
= &lh
->file_names
[i
];
10810 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10811 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10813 /* Skip the main file; we don't need it, and it must be
10814 allocated last, so that it will show up before the
10815 non-primary symtabs in the objfile's symtab list. */
10816 if (current_subfile
== first_subfile
)
10819 if (current_subfile
->symtab
== NULL
)
10820 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
10822 fe
->symtab
= current_subfile
->symtab
;
10827 /* Start a subfile for DWARF. FILENAME is the name of the file and
10828 DIRNAME the name of the source directory which contains FILENAME
10829 or NULL if not known. COMP_DIR is the compilation directory for the
10830 linetable's compilation unit or NULL if not known.
10831 This routine tries to keep line numbers from identical absolute and
10832 relative file names in a common subfile.
10834 Using the `list' example from the GDB testsuite, which resides in
10835 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10836 of /srcdir/list0.c yields the following debugging information for list0.c:
10838 DW_AT_name: /srcdir/list0.c
10839 DW_AT_comp_dir: /compdir
10840 files.files[0].name: list0.h
10841 files.files[0].dir: /srcdir
10842 files.files[1].name: list0.c
10843 files.files[1].dir: /srcdir
10845 The line number information for list0.c has to end up in a single
10846 subfile, so that `break /srcdir/list0.c:1' works as expected.
10847 start_subfile will ensure that this happens provided that we pass the
10848 concatenation of files.files[1].dir and files.files[1].name as the
10852 dwarf2_start_subfile (char *filename
, const char *dirname
,
10853 const char *comp_dir
)
10857 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10858 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10859 second argument to start_subfile. To be consistent, we do the
10860 same here. In order not to lose the line information directory,
10861 we concatenate it to the filename when it makes sense.
10862 Note that the Dwarf3 standard says (speaking of filenames in line
10863 information): ``The directory index is ignored for file names
10864 that represent full path names''. Thus ignoring dirname in the
10865 `else' branch below isn't an issue. */
10867 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
10868 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
10870 fullname
= filename
;
10872 start_subfile (fullname
, comp_dir
);
10874 if (fullname
!= filename
)
10879 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
10880 struct dwarf2_cu
*cu
)
10882 struct objfile
*objfile
= cu
->objfile
;
10883 struct comp_unit_head
*cu_header
= &cu
->header
;
10885 /* NOTE drow/2003-01-30: There used to be a comment and some special
10886 code here to turn a symbol with DW_AT_external and a
10887 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10888 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10889 with some versions of binutils) where shared libraries could have
10890 relocations against symbols in their debug information - the
10891 minimal symbol would have the right address, but the debug info
10892 would not. It's no longer necessary, because we will explicitly
10893 apply relocations when we read in the debug information now. */
10895 /* A DW_AT_location attribute with no contents indicates that a
10896 variable has been optimized away. */
10897 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
10899 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10903 /* Handle one degenerate form of location expression specially, to
10904 preserve GDB's previous behavior when section offsets are
10905 specified. If this is just a DW_OP_addr then mark this symbol
10908 if (attr_form_is_block (attr
)
10909 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
10910 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
10912 unsigned int dummy
;
10914 SYMBOL_VALUE_ADDRESS (sym
) =
10915 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
10916 SYMBOL_CLASS (sym
) = LOC_STATIC
;
10917 fixup_symbol_section (sym
, objfile
);
10918 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
10919 SYMBOL_SECTION (sym
));
10923 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
10924 expression evaluator, and use LOC_COMPUTED only when necessary
10925 (i.e. when the value of a register or memory location is
10926 referenced, or a thread-local block, etc.). Then again, it might
10927 not be worthwhile. I'm assuming that it isn't unless performance
10928 or memory numbers show me otherwise. */
10930 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
10931 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10934 /* Given a pointer to a DWARF information entry, figure out if we need
10935 to make a symbol table entry for it, and if so, create a new entry
10936 and return a pointer to it.
10937 If TYPE is NULL, determine symbol type from the die, otherwise
10938 used the passed type.
10939 If SPACE is not NULL, use it to hold the new symbol. If it is
10940 NULL, allocate a new symbol on the objfile's obstack. */
10942 static struct symbol
*
10943 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
10944 struct symbol
*space
)
10946 struct objfile
*objfile
= cu
->objfile
;
10947 struct symbol
*sym
= NULL
;
10949 struct attribute
*attr
= NULL
;
10950 struct attribute
*attr2
= NULL
;
10951 CORE_ADDR baseaddr
;
10952 struct pending
**list_to_add
= NULL
;
10954 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10956 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10958 name
= dwarf2_name (die
, cu
);
10961 const char *linkagename
;
10962 int suppress_add
= 0;
10967 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
10968 OBJSTAT (objfile
, n_syms
++);
10970 /* Cache this symbol's name and the name's demangled form (if any). */
10971 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
10972 linkagename
= dwarf2_physname (name
, die
, cu
);
10973 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
10975 /* Fortran does not have mangling standard and the mangling does differ
10976 between gfortran, iFort etc. */
10977 if (cu
->language
== language_fortran
10978 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
10979 symbol_set_demangled_name (&(sym
->ginfo
),
10980 (char *) dwarf2_full_name (name
, die
, cu
),
10983 /* Default assumptions.
10984 Use the passed type or decode it from the die. */
10985 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10986 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10988 SYMBOL_TYPE (sym
) = type
;
10990 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
10991 attr
= dwarf2_attr (die
,
10992 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
10996 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
10999 attr
= dwarf2_attr (die
,
11000 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11004 int file_index
= DW_UNSND (attr
);
11006 if (cu
->line_header
== NULL
11007 || file_index
> cu
->line_header
->num_file_names
)
11008 complaint (&symfile_complaints
,
11009 _("file index out of range"));
11010 else if (file_index
> 0)
11012 struct file_entry
*fe
;
11014 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11015 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11022 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11025 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11027 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11028 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11029 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11030 add_symbol_to_list (sym
, cu
->list_in_scope
);
11032 case DW_TAG_subprogram
:
11033 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11035 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11036 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11037 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11038 || cu
->language
== language_ada
)
11040 /* Subprograms marked external are stored as a global symbol.
11041 Ada subprograms, whether marked external or not, are always
11042 stored as a global symbol, because we want to be able to
11043 access them globally. For instance, we want to be able
11044 to break on a nested subprogram without having to
11045 specify the context. */
11046 list_to_add
= &global_symbols
;
11050 list_to_add
= cu
->list_in_scope
;
11053 case DW_TAG_inlined_subroutine
:
11054 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11056 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11057 SYMBOL_INLINED (sym
) = 1;
11058 /* Do not add the symbol to any lists. It will be found via
11059 BLOCK_FUNCTION from the blockvector. */
11061 case DW_TAG_template_value_param
:
11063 /* Fall through. */
11064 case DW_TAG_constant
:
11065 case DW_TAG_variable
:
11066 case DW_TAG_member
:
11067 /* Compilation with minimal debug info may result in
11068 variables with missing type entries. Change the
11069 misleading `void' type to something sensible. */
11070 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11072 = objfile_type (objfile
)->nodebug_data_symbol
;
11074 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11075 /* In the case of DW_TAG_member, we should only be called for
11076 static const members. */
11077 if (die
->tag
== DW_TAG_member
)
11079 /* dwarf2_add_field uses die_is_declaration,
11080 so we do the same. */
11081 gdb_assert (die_is_declaration (die
, cu
));
11086 dwarf2_const_value (attr
, sym
, cu
);
11087 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11090 if (attr2
&& (DW_UNSND (attr2
) != 0))
11091 list_to_add
= &global_symbols
;
11093 list_to_add
= cu
->list_in_scope
;
11097 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11100 var_decode_location (attr
, sym
, cu
);
11101 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11102 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11103 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11104 && !dwarf2_per_objfile
->has_section_at_zero
)
11106 /* When a static variable is eliminated by the linker,
11107 the corresponding debug information is not stripped
11108 out, but the variable address is set to null;
11109 do not add such variables into symbol table. */
11111 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11113 /* Workaround gfortran PR debug/40040 - it uses
11114 DW_AT_location for variables in -fPIC libraries which may
11115 get overriden by other libraries/executable and get
11116 a different address. Resolve it by the minimal symbol
11117 which may come from inferior's executable using copy
11118 relocation. Make this workaround only for gfortran as for
11119 other compilers GDB cannot guess the minimal symbol
11120 Fortran mangling kind. */
11121 if (cu
->language
== language_fortran
&& die
->parent
11122 && die
->parent
->tag
== DW_TAG_module
11124 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11125 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11127 /* A variable with DW_AT_external is never static,
11128 but it may be block-scoped. */
11129 list_to_add
= (cu
->list_in_scope
== &file_symbols
11130 ? &global_symbols
: cu
->list_in_scope
);
11133 list_to_add
= cu
->list_in_scope
;
11137 /* We do not know the address of this symbol.
11138 If it is an external symbol and we have type information
11139 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11140 The address of the variable will then be determined from
11141 the minimal symbol table whenever the variable is
11143 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11144 if (attr2
&& (DW_UNSND (attr2
) != 0)
11145 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11147 /* A variable with DW_AT_external is never static, but it
11148 may be block-scoped. */
11149 list_to_add
= (cu
->list_in_scope
== &file_symbols
11150 ? &global_symbols
: cu
->list_in_scope
);
11152 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11154 else if (!die_is_declaration (die
, cu
))
11156 /* Use the default LOC_OPTIMIZED_OUT class. */
11157 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11159 list_to_add
= cu
->list_in_scope
;
11163 case DW_TAG_formal_parameter
:
11164 /* If we are inside a function, mark this as an argument. If
11165 not, we might be looking at an argument to an inlined function
11166 when we do not have enough information to show inlined frames;
11167 pretend it's a local variable in that case so that the user can
11169 if (context_stack_depth
> 0
11170 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11171 SYMBOL_IS_ARGUMENT (sym
) = 1;
11172 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11175 var_decode_location (attr
, sym
, cu
);
11177 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11180 dwarf2_const_value (attr
, sym
, cu
);
11182 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
11183 if (attr
&& DW_UNSND (attr
))
11185 struct type
*ref_type
;
11187 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
11188 SYMBOL_TYPE (sym
) = ref_type
;
11191 list_to_add
= cu
->list_in_scope
;
11193 case DW_TAG_unspecified_parameters
:
11194 /* From varargs functions; gdb doesn't seem to have any
11195 interest in this information, so just ignore it for now.
11198 case DW_TAG_template_type_param
:
11200 /* Fall through. */
11201 case DW_TAG_class_type
:
11202 case DW_TAG_interface_type
:
11203 case DW_TAG_structure_type
:
11204 case DW_TAG_union_type
:
11205 case DW_TAG_set_type
:
11206 case DW_TAG_enumeration_type
:
11207 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11208 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11211 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11212 really ever be static objects: otherwise, if you try
11213 to, say, break of a class's method and you're in a file
11214 which doesn't mention that class, it won't work unless
11215 the check for all static symbols in lookup_symbol_aux
11216 saves you. See the OtherFileClass tests in
11217 gdb.c++/namespace.exp. */
11221 list_to_add
= (cu
->list_in_scope
== &file_symbols
11222 && (cu
->language
== language_cplus
11223 || cu
->language
== language_java
)
11224 ? &global_symbols
: cu
->list_in_scope
);
11226 /* The semantics of C++ state that "struct foo {
11227 ... }" also defines a typedef for "foo". A Java
11228 class declaration also defines a typedef for the
11230 if (cu
->language
== language_cplus
11231 || cu
->language
== language_java
11232 || cu
->language
== language_ada
)
11234 /* The symbol's name is already allocated along
11235 with this objfile, so we don't need to
11236 duplicate it for the type. */
11237 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11238 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11243 case DW_TAG_typedef
:
11244 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11245 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11246 list_to_add
= cu
->list_in_scope
;
11248 case DW_TAG_base_type
:
11249 case DW_TAG_subrange_type
:
11250 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11251 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11252 list_to_add
= cu
->list_in_scope
;
11254 case DW_TAG_enumerator
:
11255 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11258 dwarf2_const_value (attr
, sym
, cu
);
11261 /* NOTE: carlton/2003-11-10: See comment above in the
11262 DW_TAG_class_type, etc. block. */
11264 list_to_add
= (cu
->list_in_scope
== &file_symbols
11265 && (cu
->language
== language_cplus
11266 || cu
->language
== language_java
)
11267 ? &global_symbols
: cu
->list_in_scope
);
11270 case DW_TAG_namespace
:
11271 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11272 list_to_add
= &global_symbols
;
11275 /* Not a tag we recognize. Hopefully we aren't processing
11276 trash data, but since we must specifically ignore things
11277 we don't recognize, there is nothing else we should do at
11279 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11280 dwarf_tag_name (die
->tag
));
11286 sym
->hash_next
= objfile
->template_symbols
;
11287 objfile
->template_symbols
= sym
;
11288 list_to_add
= NULL
;
11291 if (list_to_add
!= NULL
)
11292 add_symbol_to_list (sym
, list_to_add
);
11294 /* For the benefit of old versions of GCC, check for anonymous
11295 namespaces based on the demangled name. */
11296 if (!processing_has_namespace_info
11297 && cu
->language
== language_cplus
)
11298 cp_scan_for_anonymous_namespaces (sym
);
11303 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11305 static struct symbol
*
11306 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11308 return new_symbol_full (die
, type
, cu
, NULL
);
11311 /* Given an attr with a DW_FORM_dataN value in host byte order,
11312 zero-extend it as appropriate for the symbol's type. The DWARF
11313 standard (v4) is not entirely clear about the meaning of using
11314 DW_FORM_dataN for a constant with a signed type, where the type is
11315 wider than the data. The conclusion of a discussion on the DWARF
11316 list was that this is unspecified. We choose to always zero-extend
11317 because that is the interpretation long in use by GCC. */
11320 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11321 const char *name
, struct obstack
*obstack
,
11322 struct dwarf2_cu
*cu
, long *value
, int bits
)
11324 struct objfile
*objfile
= cu
->objfile
;
11325 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11326 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11327 LONGEST l
= DW_UNSND (attr
);
11329 if (bits
< sizeof (*value
) * 8)
11331 l
&= ((LONGEST
) 1 << bits
) - 1;
11334 else if (bits
== sizeof (*value
) * 8)
11338 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11339 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11346 /* Read a constant value from an attribute. Either set *VALUE, or if
11347 the value does not fit in *VALUE, set *BYTES - either already
11348 allocated on the objfile obstack, or newly allocated on OBSTACK,
11349 or, set *BATON, if we translated the constant to a location
11353 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11354 const char *name
, struct obstack
*obstack
,
11355 struct dwarf2_cu
*cu
,
11356 long *value
, gdb_byte
**bytes
,
11357 struct dwarf2_locexpr_baton
**baton
)
11359 struct objfile
*objfile
= cu
->objfile
;
11360 struct comp_unit_head
*cu_header
= &cu
->header
;
11361 struct dwarf_block
*blk
;
11362 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
11363 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
11369 switch (attr
->form
)
11375 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
11376 dwarf2_const_value_length_mismatch_complaint (name
,
11377 cu_header
->addr_size
,
11378 TYPE_LENGTH (type
));
11379 /* Symbols of this form are reasonably rare, so we just
11380 piggyback on the existing location code rather than writing
11381 a new implementation of symbol_computed_ops. */
11382 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11383 sizeof (struct dwarf2_locexpr_baton
));
11384 (*baton
)->per_cu
= cu
->per_cu
;
11385 gdb_assert ((*baton
)->per_cu
);
11387 (*baton
)->size
= 2 + cu_header
->addr_size
;
11388 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11389 (*baton
)->data
= data
;
11391 data
[0] = DW_OP_addr
;
11392 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11393 byte_order
, DW_ADDR (attr
));
11394 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11397 case DW_FORM_string
:
11399 /* DW_STRING is already allocated on the objfile obstack, point
11401 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11403 case DW_FORM_block1
:
11404 case DW_FORM_block2
:
11405 case DW_FORM_block4
:
11406 case DW_FORM_block
:
11407 case DW_FORM_exprloc
:
11408 blk
= DW_BLOCK (attr
);
11409 if (TYPE_LENGTH (type
) != blk
->size
)
11410 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11411 TYPE_LENGTH (type
));
11412 *bytes
= blk
->data
;
11415 /* The DW_AT_const_value attributes are supposed to carry the
11416 symbol's value "represented as it would be on the target
11417 architecture." By the time we get here, it's already been
11418 converted to host endianness, so we just need to sign- or
11419 zero-extend it as appropriate. */
11420 case DW_FORM_data1
:
11421 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11422 obstack
, cu
, value
, 8);
11424 case DW_FORM_data2
:
11425 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11426 obstack
, cu
, value
, 16);
11428 case DW_FORM_data4
:
11429 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11430 obstack
, cu
, value
, 32);
11432 case DW_FORM_data8
:
11433 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11434 obstack
, cu
, value
, 64);
11437 case DW_FORM_sdata
:
11438 *value
= DW_SND (attr
);
11441 case DW_FORM_udata
:
11442 *value
= DW_UNSND (attr
);
11446 complaint (&symfile_complaints
,
11447 _("unsupported const value attribute form: '%s'"),
11448 dwarf_form_name (attr
->form
));
11455 /* Copy constant value from an attribute to a symbol. */
11458 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11459 struct dwarf2_cu
*cu
)
11461 struct objfile
*objfile
= cu
->objfile
;
11462 struct comp_unit_head
*cu_header
= &cu
->header
;
11465 struct dwarf2_locexpr_baton
*baton
;
11467 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11468 SYMBOL_PRINT_NAME (sym
),
11469 &objfile
->objfile_obstack
, cu
,
11470 &value
, &bytes
, &baton
);
11474 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11475 SYMBOL_LOCATION_BATON (sym
) = baton
;
11476 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11478 else if (bytes
!= NULL
)
11480 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11481 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11485 SYMBOL_VALUE (sym
) = value
;
11486 SYMBOL_CLASS (sym
) = LOC_CONST
;
11490 /* Return the type of the die in question using its DW_AT_type attribute. */
11492 static struct type
*
11493 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11495 struct attribute
*type_attr
;
11497 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11500 /* A missing DW_AT_type represents a void type. */
11501 return objfile_type (cu
->objfile
)->builtin_void
;
11504 return lookup_die_type (die
, type_attr
, cu
);
11507 /* True iff CU's producer generates GNAT Ada auxiliary information
11508 that allows to find parallel types through that information instead
11509 of having to do expensive parallel lookups by type name. */
11512 need_gnat_info (struct dwarf2_cu
*cu
)
11514 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11515 of GNAT produces this auxiliary information, without any indication
11516 that it is produced. Part of enhancing the FSF version of GNAT
11517 to produce that information will be to put in place an indicator
11518 that we can use in order to determine whether the descriptive type
11519 info is available or not. One suggestion that has been made is
11520 to use a new attribute, attached to the CU die. For now, assume
11521 that the descriptive type info is not available. */
11525 /* Return the auxiliary type of the die in question using its
11526 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11527 attribute is not present. */
11529 static struct type
*
11530 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11532 struct attribute
*type_attr
;
11534 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11538 return lookup_die_type (die
, type_attr
, cu
);
11541 /* If DIE has a descriptive_type attribute, then set the TYPE's
11542 descriptive type accordingly. */
11545 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11546 struct dwarf2_cu
*cu
)
11548 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11550 if (descriptive_type
)
11552 ALLOCATE_GNAT_AUX_TYPE (type
);
11553 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11557 /* Return the containing type of the die in question using its
11558 DW_AT_containing_type attribute. */
11560 static struct type
*
11561 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11563 struct attribute
*type_attr
;
11565 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11567 error (_("Dwarf Error: Problem turning containing type into gdb type "
11568 "[in module %s]"), cu
->objfile
->name
);
11570 return lookup_die_type (die
, type_attr
, cu
);
11573 /* Look up the type of DIE in CU using its type attribute ATTR.
11574 If there is no type substitute an error marker. */
11576 static struct type
*
11577 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11578 struct dwarf2_cu
*cu
)
11580 struct type
*this_type
;
11582 /* First see if we have it cached. */
11584 if (is_ref_attr (attr
))
11586 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11588 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11590 else if (attr
->form
== DW_FORM_ref_sig8
)
11592 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11593 struct dwarf2_cu
*sig_cu
;
11594 unsigned int offset
;
11596 /* sig_type will be NULL if the signatured type is missing from
11598 if (sig_type
== NULL
)
11599 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11600 "at 0x%x [in module %s]"),
11601 die
->offset
, cu
->objfile
->name
);
11603 gdb_assert (sig_type
->per_cu
.from_debug_types
);
11604 offset
= sig_type
->offset
+ sig_type
->type_offset
;
11605 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11609 dump_die_for_error (die
);
11610 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11611 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11614 /* If not cached we need to read it in. */
11616 if (this_type
== NULL
)
11618 struct die_info
*type_die
;
11619 struct dwarf2_cu
*type_cu
= cu
;
11621 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11622 /* If the type is cached, we should have found it above. */
11623 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
11624 this_type
= read_type_die_1 (type_die
, type_cu
);
11627 /* If we still don't have a type use an error marker. */
11629 if (this_type
== NULL
)
11631 char *message
, *saved
;
11633 /* read_type_die already issued a complaint. */
11634 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11638 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
11639 message
, strlen (message
));
11642 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
11648 /* Return the type in DIE, CU.
11649 Returns NULL for invalid types.
11651 This first does a lookup in the appropriate type_hash table,
11652 and only reads the die in if necessary.
11654 NOTE: This can be called when reading in partial or full symbols. */
11656 static struct type
*
11657 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11659 struct type
*this_type
;
11661 this_type
= get_die_type (die
, cu
);
11665 return read_type_die_1 (die
, cu
);
11668 /* Read the type in DIE, CU.
11669 Returns NULL for invalid types. */
11671 static struct type
*
11672 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
11674 struct type
*this_type
= NULL
;
11678 case DW_TAG_class_type
:
11679 case DW_TAG_interface_type
:
11680 case DW_TAG_structure_type
:
11681 case DW_TAG_union_type
:
11682 this_type
= read_structure_type (die
, cu
);
11684 case DW_TAG_enumeration_type
:
11685 this_type
= read_enumeration_type (die
, cu
);
11687 case DW_TAG_subprogram
:
11688 case DW_TAG_subroutine_type
:
11689 case DW_TAG_inlined_subroutine
:
11690 this_type
= read_subroutine_type (die
, cu
);
11692 case DW_TAG_array_type
:
11693 this_type
= read_array_type (die
, cu
);
11695 case DW_TAG_set_type
:
11696 this_type
= read_set_type (die
, cu
);
11698 case DW_TAG_pointer_type
:
11699 this_type
= read_tag_pointer_type (die
, cu
);
11701 case DW_TAG_ptr_to_member_type
:
11702 this_type
= read_tag_ptr_to_member_type (die
, cu
);
11704 case DW_TAG_reference_type
:
11705 this_type
= read_tag_reference_type (die
, cu
);
11707 case DW_TAG_const_type
:
11708 this_type
= read_tag_const_type (die
, cu
);
11710 case DW_TAG_volatile_type
:
11711 this_type
= read_tag_volatile_type (die
, cu
);
11713 case DW_TAG_string_type
:
11714 this_type
= read_tag_string_type (die
, cu
);
11716 case DW_TAG_typedef
:
11717 this_type
= read_typedef (die
, cu
);
11719 case DW_TAG_subrange_type
:
11720 this_type
= read_subrange_type (die
, cu
);
11722 case DW_TAG_base_type
:
11723 this_type
= read_base_type (die
, cu
);
11725 case DW_TAG_unspecified_type
:
11726 this_type
= read_unspecified_type (die
, cu
);
11728 case DW_TAG_namespace
:
11729 this_type
= read_namespace_type (die
, cu
);
11731 case DW_TAG_module
:
11732 this_type
= read_module_type (die
, cu
);
11735 complaint (&symfile_complaints
,
11736 _("unexpected tag in read_type_die: '%s'"),
11737 dwarf_tag_name (die
->tag
));
11744 /* See if we can figure out if the class lives in a namespace. We do
11745 this by looking for a member function; its demangled name will
11746 contain namespace info, if there is any.
11747 Return the computed name or NULL.
11748 Space for the result is allocated on the objfile's obstack.
11749 This is the full-die version of guess_partial_die_structure_name.
11750 In this case we know DIE has no useful parent. */
11753 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11755 struct die_info
*spec_die
;
11756 struct dwarf2_cu
*spec_cu
;
11757 struct die_info
*child
;
11760 spec_die
= die_specification (die
, &spec_cu
);
11761 if (spec_die
!= NULL
)
11767 for (child
= die
->child
;
11769 child
= child
->sibling
)
11771 if (child
->tag
== DW_TAG_subprogram
)
11773 struct attribute
*attr
;
11775 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
11777 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
11781 = language_class_name_from_physname (cu
->language_defn
,
11785 if (actual_name
!= NULL
)
11787 char *die_name
= dwarf2_name (die
, cu
);
11789 if (die_name
!= NULL
11790 && strcmp (die_name
, actual_name
) != 0)
11792 /* Strip off the class name from the full name.
11793 We want the prefix. */
11794 int die_name_len
= strlen (die_name
);
11795 int actual_name_len
= strlen (actual_name
);
11797 /* Test for '::' as a sanity check. */
11798 if (actual_name_len
> die_name_len
+ 2
11799 && actual_name
[actual_name_len
11800 - die_name_len
- 1] == ':')
11802 obsavestring (actual_name
,
11803 actual_name_len
- die_name_len
- 2,
11804 &cu
->objfile
->objfile_obstack
);
11807 xfree (actual_name
);
11816 /* Return the name of the namespace/class that DIE is defined within,
11817 or "" if we can't tell. The caller should not xfree the result.
11819 For example, if we're within the method foo() in the following
11829 then determine_prefix on foo's die will return "N::C". */
11832 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
11834 struct die_info
*parent
, *spec_die
;
11835 struct dwarf2_cu
*spec_cu
;
11836 struct type
*parent_type
;
11838 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
11839 && cu
->language
!= language_fortran
)
11842 /* We have to be careful in the presence of DW_AT_specification.
11843 For example, with GCC 3.4, given the code
11847 // Definition of N::foo.
11851 then we'll have a tree of DIEs like this:
11853 1: DW_TAG_compile_unit
11854 2: DW_TAG_namespace // N
11855 3: DW_TAG_subprogram // declaration of N::foo
11856 4: DW_TAG_subprogram // definition of N::foo
11857 DW_AT_specification // refers to die #3
11859 Thus, when processing die #4, we have to pretend that we're in
11860 the context of its DW_AT_specification, namely the contex of die
11863 spec_die
= die_specification (die
, &spec_cu
);
11864 if (spec_die
== NULL
)
11865 parent
= die
->parent
;
11868 parent
= spec_die
->parent
;
11872 if (parent
== NULL
)
11874 else if (parent
->building_fullname
)
11877 const char *parent_name
;
11879 /* It has been seen on RealView 2.2 built binaries,
11880 DW_TAG_template_type_param types actually _defined_ as
11881 children of the parent class:
11884 template class <class Enum> Class{};
11885 Class<enum E> class_e;
11887 1: DW_TAG_class_type (Class)
11888 2: DW_TAG_enumeration_type (E)
11889 3: DW_TAG_enumerator (enum1:0)
11890 3: DW_TAG_enumerator (enum2:1)
11892 2: DW_TAG_template_type_param
11893 DW_AT_type DW_FORM_ref_udata (E)
11895 Besides being broken debug info, it can put GDB into an
11896 infinite loop. Consider:
11898 When we're building the full name for Class<E>, we'll start
11899 at Class, and go look over its template type parameters,
11900 finding E. We'll then try to build the full name of E, and
11901 reach here. We're now trying to build the full name of E,
11902 and look over the parent DIE for containing scope. In the
11903 broken case, if we followed the parent DIE of E, we'd again
11904 find Class, and once again go look at its template type
11905 arguments, etc., etc. Simply don't consider such parent die
11906 as source-level parent of this die (it can't be, the language
11907 doesn't allow it), and break the loop here. */
11908 name
= dwarf2_name (die
, cu
);
11909 parent_name
= dwarf2_name (parent
, cu
);
11910 complaint (&symfile_complaints
,
11911 _("template param type '%s' defined within parent '%s'"),
11912 name
? name
: "<unknown>",
11913 parent_name
? parent_name
: "<unknown>");
11917 switch (parent
->tag
)
11919 case DW_TAG_namespace
:
11920 parent_type
= read_type_die (parent
, cu
);
11921 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
11922 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
11923 Work around this problem here. */
11924 if (cu
->language
== language_cplus
11925 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
11927 /* We give a name to even anonymous namespaces. */
11928 return TYPE_TAG_NAME (parent_type
);
11929 case DW_TAG_class_type
:
11930 case DW_TAG_interface_type
:
11931 case DW_TAG_structure_type
:
11932 case DW_TAG_union_type
:
11933 case DW_TAG_module
:
11934 parent_type
= read_type_die (parent
, cu
);
11935 if (TYPE_TAG_NAME (parent_type
) != NULL
)
11936 return TYPE_TAG_NAME (parent_type
);
11938 /* An anonymous structure is only allowed non-static data
11939 members; no typedefs, no member functions, et cetera.
11940 So it does not need a prefix. */
11942 case DW_TAG_compile_unit
:
11943 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
11944 if (cu
->language
== language_cplus
11945 && dwarf2_per_objfile
->types
.asection
!= NULL
11946 && die
->child
!= NULL
11947 && (die
->tag
== DW_TAG_class_type
11948 || die
->tag
== DW_TAG_structure_type
11949 || die
->tag
== DW_TAG_union_type
))
11951 char *name
= guess_full_die_structure_name (die
, cu
);
11957 return determine_prefix (parent
, cu
);
11961 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
11962 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
11963 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
11964 an obconcat, otherwise allocate storage for the result. The CU argument is
11965 used to determine the language and hence, the appropriate separator. */
11967 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
11970 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
11971 int physname
, struct dwarf2_cu
*cu
)
11973 const char *lead
= "";
11976 if (suffix
== NULL
|| suffix
[0] == '\0'
11977 || prefix
== NULL
|| prefix
[0] == '\0')
11979 else if (cu
->language
== language_java
)
11981 else if (cu
->language
== language_fortran
&& physname
)
11983 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
11984 DW_AT_MIPS_linkage_name is preferred and used instead. */
11992 if (prefix
== NULL
)
11994 if (suffix
== NULL
)
12000 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12002 strcpy (retval
, lead
);
12003 strcat (retval
, prefix
);
12004 strcat (retval
, sep
);
12005 strcat (retval
, suffix
);
12010 /* We have an obstack. */
12011 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12015 /* Return sibling of die, NULL if no sibling. */
12017 static struct die_info
*
12018 sibling_die (struct die_info
*die
)
12020 return die
->sibling
;
12023 /* Get name of a die, return NULL if not found. */
12026 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12027 struct obstack
*obstack
)
12029 if (name
&& cu
->language
== language_cplus
)
12031 char *canon_name
= cp_canonicalize_string (name
);
12033 if (canon_name
!= NULL
)
12035 if (strcmp (canon_name
, name
) != 0)
12036 name
= obsavestring (canon_name
, strlen (canon_name
),
12038 xfree (canon_name
);
12045 /* Get name of a die, return NULL if not found. */
12048 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12050 struct attribute
*attr
;
12052 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12053 if ((!attr
|| !DW_STRING (attr
))
12054 && die
->tag
!= DW_TAG_class_type
12055 && die
->tag
!= DW_TAG_interface_type
12056 && die
->tag
!= DW_TAG_structure_type
12057 && die
->tag
!= DW_TAG_union_type
)
12062 case DW_TAG_compile_unit
:
12063 /* Compilation units have a DW_AT_name that is a filename, not
12064 a source language identifier. */
12065 case DW_TAG_enumeration_type
:
12066 case DW_TAG_enumerator
:
12067 /* These tags always have simple identifiers already; no need
12068 to canonicalize them. */
12069 return DW_STRING (attr
);
12071 case DW_TAG_subprogram
:
12072 /* Java constructors will all be named "<init>", so return
12073 the class name when we see this special case. */
12074 if (cu
->language
== language_java
12075 && DW_STRING (attr
) != NULL
12076 && strcmp (DW_STRING (attr
), "<init>") == 0)
12078 struct dwarf2_cu
*spec_cu
= cu
;
12079 struct die_info
*spec_die
;
12081 /* GCJ will output '<init>' for Java constructor names.
12082 For this special case, return the name of the parent class. */
12084 /* GCJ may output suprogram DIEs with AT_specification set.
12085 If so, use the name of the specified DIE. */
12086 spec_die
= die_specification (die
, &spec_cu
);
12087 if (spec_die
!= NULL
)
12088 return dwarf2_name (spec_die
, spec_cu
);
12093 if (die
->tag
== DW_TAG_class_type
)
12094 return dwarf2_name (die
, cu
);
12096 while (die
->tag
!= DW_TAG_compile_unit
);
12100 case DW_TAG_class_type
:
12101 case DW_TAG_interface_type
:
12102 case DW_TAG_structure_type
:
12103 case DW_TAG_union_type
:
12104 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12105 structures or unions. These were of the form "._%d" in GCC 4.1,
12106 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12107 and GCC 4.4. We work around this problem by ignoring these. */
12108 if (attr
&& DW_STRING (attr
)
12109 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12110 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12113 /* GCC might emit a nameless typedef that has a linkage name. See
12114 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12115 if (!attr
|| DW_STRING (attr
) == NULL
)
12117 char *demangled
= NULL
;
12119 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12121 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12123 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12126 /* Avoid demangling DW_STRING (attr) the second time on a second
12127 call for the same DIE. */
12128 if (!DW_STRING_IS_CANONICAL (attr
))
12129 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12133 /* FIXME: we already did this for the partial symbol... */
12135 = obsavestring (demangled
, strlen (demangled
),
12136 &cu
->objfile
->objfile_obstack
);
12137 DW_STRING_IS_CANONICAL (attr
) = 1;
12147 if (!DW_STRING_IS_CANONICAL (attr
))
12150 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12151 &cu
->objfile
->objfile_obstack
);
12152 DW_STRING_IS_CANONICAL (attr
) = 1;
12154 return DW_STRING (attr
);
12157 /* Return the die that this die in an extension of, or NULL if there
12158 is none. *EXT_CU is the CU containing DIE on input, and the CU
12159 containing the return value on output. */
12161 static struct die_info
*
12162 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12164 struct attribute
*attr
;
12166 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12170 return follow_die_ref (die
, attr
, ext_cu
);
12173 /* Convert a DIE tag into its string name. */
12176 dwarf_tag_name (unsigned tag
)
12180 case DW_TAG_padding
:
12181 return "DW_TAG_padding";
12182 case DW_TAG_array_type
:
12183 return "DW_TAG_array_type";
12184 case DW_TAG_class_type
:
12185 return "DW_TAG_class_type";
12186 case DW_TAG_entry_point
:
12187 return "DW_TAG_entry_point";
12188 case DW_TAG_enumeration_type
:
12189 return "DW_TAG_enumeration_type";
12190 case DW_TAG_formal_parameter
:
12191 return "DW_TAG_formal_parameter";
12192 case DW_TAG_imported_declaration
:
12193 return "DW_TAG_imported_declaration";
12195 return "DW_TAG_label";
12196 case DW_TAG_lexical_block
:
12197 return "DW_TAG_lexical_block";
12198 case DW_TAG_member
:
12199 return "DW_TAG_member";
12200 case DW_TAG_pointer_type
:
12201 return "DW_TAG_pointer_type";
12202 case DW_TAG_reference_type
:
12203 return "DW_TAG_reference_type";
12204 case DW_TAG_compile_unit
:
12205 return "DW_TAG_compile_unit";
12206 case DW_TAG_string_type
:
12207 return "DW_TAG_string_type";
12208 case DW_TAG_structure_type
:
12209 return "DW_TAG_structure_type";
12210 case DW_TAG_subroutine_type
:
12211 return "DW_TAG_subroutine_type";
12212 case DW_TAG_typedef
:
12213 return "DW_TAG_typedef";
12214 case DW_TAG_union_type
:
12215 return "DW_TAG_union_type";
12216 case DW_TAG_unspecified_parameters
:
12217 return "DW_TAG_unspecified_parameters";
12218 case DW_TAG_variant
:
12219 return "DW_TAG_variant";
12220 case DW_TAG_common_block
:
12221 return "DW_TAG_common_block";
12222 case DW_TAG_common_inclusion
:
12223 return "DW_TAG_common_inclusion";
12224 case DW_TAG_inheritance
:
12225 return "DW_TAG_inheritance";
12226 case DW_TAG_inlined_subroutine
:
12227 return "DW_TAG_inlined_subroutine";
12228 case DW_TAG_module
:
12229 return "DW_TAG_module";
12230 case DW_TAG_ptr_to_member_type
:
12231 return "DW_TAG_ptr_to_member_type";
12232 case DW_TAG_set_type
:
12233 return "DW_TAG_set_type";
12234 case DW_TAG_subrange_type
:
12235 return "DW_TAG_subrange_type";
12236 case DW_TAG_with_stmt
:
12237 return "DW_TAG_with_stmt";
12238 case DW_TAG_access_declaration
:
12239 return "DW_TAG_access_declaration";
12240 case DW_TAG_base_type
:
12241 return "DW_TAG_base_type";
12242 case DW_TAG_catch_block
:
12243 return "DW_TAG_catch_block";
12244 case DW_TAG_const_type
:
12245 return "DW_TAG_const_type";
12246 case DW_TAG_constant
:
12247 return "DW_TAG_constant";
12248 case DW_TAG_enumerator
:
12249 return "DW_TAG_enumerator";
12250 case DW_TAG_file_type
:
12251 return "DW_TAG_file_type";
12252 case DW_TAG_friend
:
12253 return "DW_TAG_friend";
12254 case DW_TAG_namelist
:
12255 return "DW_TAG_namelist";
12256 case DW_TAG_namelist_item
:
12257 return "DW_TAG_namelist_item";
12258 case DW_TAG_packed_type
:
12259 return "DW_TAG_packed_type";
12260 case DW_TAG_subprogram
:
12261 return "DW_TAG_subprogram";
12262 case DW_TAG_template_type_param
:
12263 return "DW_TAG_template_type_param";
12264 case DW_TAG_template_value_param
:
12265 return "DW_TAG_template_value_param";
12266 case DW_TAG_thrown_type
:
12267 return "DW_TAG_thrown_type";
12268 case DW_TAG_try_block
:
12269 return "DW_TAG_try_block";
12270 case DW_TAG_variant_part
:
12271 return "DW_TAG_variant_part";
12272 case DW_TAG_variable
:
12273 return "DW_TAG_variable";
12274 case DW_TAG_volatile_type
:
12275 return "DW_TAG_volatile_type";
12276 case DW_TAG_dwarf_procedure
:
12277 return "DW_TAG_dwarf_procedure";
12278 case DW_TAG_restrict_type
:
12279 return "DW_TAG_restrict_type";
12280 case DW_TAG_interface_type
:
12281 return "DW_TAG_interface_type";
12282 case DW_TAG_namespace
:
12283 return "DW_TAG_namespace";
12284 case DW_TAG_imported_module
:
12285 return "DW_TAG_imported_module";
12286 case DW_TAG_unspecified_type
:
12287 return "DW_TAG_unspecified_type";
12288 case DW_TAG_partial_unit
:
12289 return "DW_TAG_partial_unit";
12290 case DW_TAG_imported_unit
:
12291 return "DW_TAG_imported_unit";
12292 case DW_TAG_condition
:
12293 return "DW_TAG_condition";
12294 case DW_TAG_shared_type
:
12295 return "DW_TAG_shared_type";
12296 case DW_TAG_type_unit
:
12297 return "DW_TAG_type_unit";
12298 case DW_TAG_MIPS_loop
:
12299 return "DW_TAG_MIPS_loop";
12300 case DW_TAG_HP_array_descriptor
:
12301 return "DW_TAG_HP_array_descriptor";
12302 case DW_TAG_format_label
:
12303 return "DW_TAG_format_label";
12304 case DW_TAG_function_template
:
12305 return "DW_TAG_function_template";
12306 case DW_TAG_class_template
:
12307 return "DW_TAG_class_template";
12308 case DW_TAG_GNU_BINCL
:
12309 return "DW_TAG_GNU_BINCL";
12310 case DW_TAG_GNU_EINCL
:
12311 return "DW_TAG_GNU_EINCL";
12312 case DW_TAG_upc_shared_type
:
12313 return "DW_TAG_upc_shared_type";
12314 case DW_TAG_upc_strict_type
:
12315 return "DW_TAG_upc_strict_type";
12316 case DW_TAG_upc_relaxed_type
:
12317 return "DW_TAG_upc_relaxed_type";
12318 case DW_TAG_PGI_kanji_type
:
12319 return "DW_TAG_PGI_kanji_type";
12320 case DW_TAG_PGI_interface_block
:
12321 return "DW_TAG_PGI_interface_block";
12323 return "DW_TAG_<unknown>";
12327 /* Convert a DWARF attribute code into its string name. */
12330 dwarf_attr_name (unsigned attr
)
12334 case DW_AT_sibling
:
12335 return "DW_AT_sibling";
12336 case DW_AT_location
:
12337 return "DW_AT_location";
12339 return "DW_AT_name";
12340 case DW_AT_ordering
:
12341 return "DW_AT_ordering";
12342 case DW_AT_subscr_data
:
12343 return "DW_AT_subscr_data";
12344 case DW_AT_byte_size
:
12345 return "DW_AT_byte_size";
12346 case DW_AT_bit_offset
:
12347 return "DW_AT_bit_offset";
12348 case DW_AT_bit_size
:
12349 return "DW_AT_bit_size";
12350 case DW_AT_element_list
:
12351 return "DW_AT_element_list";
12352 case DW_AT_stmt_list
:
12353 return "DW_AT_stmt_list";
12355 return "DW_AT_low_pc";
12356 case DW_AT_high_pc
:
12357 return "DW_AT_high_pc";
12358 case DW_AT_language
:
12359 return "DW_AT_language";
12361 return "DW_AT_member";
12363 return "DW_AT_discr";
12364 case DW_AT_discr_value
:
12365 return "DW_AT_discr_value";
12366 case DW_AT_visibility
:
12367 return "DW_AT_visibility";
12369 return "DW_AT_import";
12370 case DW_AT_string_length
:
12371 return "DW_AT_string_length";
12372 case DW_AT_common_reference
:
12373 return "DW_AT_common_reference";
12374 case DW_AT_comp_dir
:
12375 return "DW_AT_comp_dir";
12376 case DW_AT_const_value
:
12377 return "DW_AT_const_value";
12378 case DW_AT_containing_type
:
12379 return "DW_AT_containing_type";
12380 case DW_AT_default_value
:
12381 return "DW_AT_default_value";
12383 return "DW_AT_inline";
12384 case DW_AT_is_optional
:
12385 return "DW_AT_is_optional";
12386 case DW_AT_lower_bound
:
12387 return "DW_AT_lower_bound";
12388 case DW_AT_producer
:
12389 return "DW_AT_producer";
12390 case DW_AT_prototyped
:
12391 return "DW_AT_prototyped";
12392 case DW_AT_return_addr
:
12393 return "DW_AT_return_addr";
12394 case DW_AT_start_scope
:
12395 return "DW_AT_start_scope";
12396 case DW_AT_bit_stride
:
12397 return "DW_AT_bit_stride";
12398 case DW_AT_upper_bound
:
12399 return "DW_AT_upper_bound";
12400 case DW_AT_abstract_origin
:
12401 return "DW_AT_abstract_origin";
12402 case DW_AT_accessibility
:
12403 return "DW_AT_accessibility";
12404 case DW_AT_address_class
:
12405 return "DW_AT_address_class";
12406 case DW_AT_artificial
:
12407 return "DW_AT_artificial";
12408 case DW_AT_base_types
:
12409 return "DW_AT_base_types";
12410 case DW_AT_calling_convention
:
12411 return "DW_AT_calling_convention";
12413 return "DW_AT_count";
12414 case DW_AT_data_member_location
:
12415 return "DW_AT_data_member_location";
12416 case DW_AT_decl_column
:
12417 return "DW_AT_decl_column";
12418 case DW_AT_decl_file
:
12419 return "DW_AT_decl_file";
12420 case DW_AT_decl_line
:
12421 return "DW_AT_decl_line";
12422 case DW_AT_declaration
:
12423 return "DW_AT_declaration";
12424 case DW_AT_discr_list
:
12425 return "DW_AT_discr_list";
12426 case DW_AT_encoding
:
12427 return "DW_AT_encoding";
12428 case DW_AT_external
:
12429 return "DW_AT_external";
12430 case DW_AT_frame_base
:
12431 return "DW_AT_frame_base";
12433 return "DW_AT_friend";
12434 case DW_AT_identifier_case
:
12435 return "DW_AT_identifier_case";
12436 case DW_AT_macro_info
:
12437 return "DW_AT_macro_info";
12438 case DW_AT_namelist_items
:
12439 return "DW_AT_namelist_items";
12440 case DW_AT_priority
:
12441 return "DW_AT_priority";
12442 case DW_AT_segment
:
12443 return "DW_AT_segment";
12444 case DW_AT_specification
:
12445 return "DW_AT_specification";
12446 case DW_AT_static_link
:
12447 return "DW_AT_static_link";
12449 return "DW_AT_type";
12450 case DW_AT_use_location
:
12451 return "DW_AT_use_location";
12452 case DW_AT_variable_parameter
:
12453 return "DW_AT_variable_parameter";
12454 case DW_AT_virtuality
:
12455 return "DW_AT_virtuality";
12456 case DW_AT_vtable_elem_location
:
12457 return "DW_AT_vtable_elem_location";
12458 /* DWARF 3 values. */
12459 case DW_AT_allocated
:
12460 return "DW_AT_allocated";
12461 case DW_AT_associated
:
12462 return "DW_AT_associated";
12463 case DW_AT_data_location
:
12464 return "DW_AT_data_location";
12465 case DW_AT_byte_stride
:
12466 return "DW_AT_byte_stride";
12467 case DW_AT_entry_pc
:
12468 return "DW_AT_entry_pc";
12469 case DW_AT_use_UTF8
:
12470 return "DW_AT_use_UTF8";
12471 case DW_AT_extension
:
12472 return "DW_AT_extension";
12474 return "DW_AT_ranges";
12475 case DW_AT_trampoline
:
12476 return "DW_AT_trampoline";
12477 case DW_AT_call_column
:
12478 return "DW_AT_call_column";
12479 case DW_AT_call_file
:
12480 return "DW_AT_call_file";
12481 case DW_AT_call_line
:
12482 return "DW_AT_call_line";
12483 case DW_AT_description
:
12484 return "DW_AT_description";
12485 case DW_AT_binary_scale
:
12486 return "DW_AT_binary_scale";
12487 case DW_AT_decimal_scale
:
12488 return "DW_AT_decimal_scale";
12490 return "DW_AT_small";
12491 case DW_AT_decimal_sign
:
12492 return "DW_AT_decimal_sign";
12493 case DW_AT_digit_count
:
12494 return "DW_AT_digit_count";
12495 case DW_AT_picture_string
:
12496 return "DW_AT_picture_string";
12497 case DW_AT_mutable
:
12498 return "DW_AT_mutable";
12499 case DW_AT_threads_scaled
:
12500 return "DW_AT_threads_scaled";
12501 case DW_AT_explicit
:
12502 return "DW_AT_explicit";
12503 case DW_AT_object_pointer
:
12504 return "DW_AT_object_pointer";
12505 case DW_AT_endianity
:
12506 return "DW_AT_endianity";
12507 case DW_AT_elemental
:
12508 return "DW_AT_elemental";
12510 return "DW_AT_pure";
12511 case DW_AT_recursive
:
12512 return "DW_AT_recursive";
12513 /* DWARF 4 values. */
12514 case DW_AT_signature
:
12515 return "DW_AT_signature";
12516 case DW_AT_linkage_name
:
12517 return "DW_AT_linkage_name";
12518 /* SGI/MIPS extensions. */
12519 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12520 case DW_AT_MIPS_fde
:
12521 return "DW_AT_MIPS_fde";
12523 case DW_AT_MIPS_loop_begin
:
12524 return "DW_AT_MIPS_loop_begin";
12525 case DW_AT_MIPS_tail_loop_begin
:
12526 return "DW_AT_MIPS_tail_loop_begin";
12527 case DW_AT_MIPS_epilog_begin
:
12528 return "DW_AT_MIPS_epilog_begin";
12529 case DW_AT_MIPS_loop_unroll_factor
:
12530 return "DW_AT_MIPS_loop_unroll_factor";
12531 case DW_AT_MIPS_software_pipeline_depth
:
12532 return "DW_AT_MIPS_software_pipeline_depth";
12533 case DW_AT_MIPS_linkage_name
:
12534 return "DW_AT_MIPS_linkage_name";
12535 case DW_AT_MIPS_stride
:
12536 return "DW_AT_MIPS_stride";
12537 case DW_AT_MIPS_abstract_name
:
12538 return "DW_AT_MIPS_abstract_name";
12539 case DW_AT_MIPS_clone_origin
:
12540 return "DW_AT_MIPS_clone_origin";
12541 case DW_AT_MIPS_has_inlines
:
12542 return "DW_AT_MIPS_has_inlines";
12543 /* HP extensions. */
12544 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12545 case DW_AT_HP_block_index
:
12546 return "DW_AT_HP_block_index";
12548 case DW_AT_HP_unmodifiable
:
12549 return "DW_AT_HP_unmodifiable";
12550 case DW_AT_HP_actuals_stmt_list
:
12551 return "DW_AT_HP_actuals_stmt_list";
12552 case DW_AT_HP_proc_per_section
:
12553 return "DW_AT_HP_proc_per_section";
12554 case DW_AT_HP_raw_data_ptr
:
12555 return "DW_AT_HP_raw_data_ptr";
12556 case DW_AT_HP_pass_by_reference
:
12557 return "DW_AT_HP_pass_by_reference";
12558 case DW_AT_HP_opt_level
:
12559 return "DW_AT_HP_opt_level";
12560 case DW_AT_HP_prof_version_id
:
12561 return "DW_AT_HP_prof_version_id";
12562 case DW_AT_HP_opt_flags
:
12563 return "DW_AT_HP_opt_flags";
12564 case DW_AT_HP_cold_region_low_pc
:
12565 return "DW_AT_HP_cold_region_low_pc";
12566 case DW_AT_HP_cold_region_high_pc
:
12567 return "DW_AT_HP_cold_region_high_pc";
12568 case DW_AT_HP_all_variables_modifiable
:
12569 return "DW_AT_HP_all_variables_modifiable";
12570 case DW_AT_HP_linkage_name
:
12571 return "DW_AT_HP_linkage_name";
12572 case DW_AT_HP_prof_flags
:
12573 return "DW_AT_HP_prof_flags";
12574 /* GNU extensions. */
12575 case DW_AT_sf_names
:
12576 return "DW_AT_sf_names";
12577 case DW_AT_src_info
:
12578 return "DW_AT_src_info";
12579 case DW_AT_mac_info
:
12580 return "DW_AT_mac_info";
12581 case DW_AT_src_coords
:
12582 return "DW_AT_src_coords";
12583 case DW_AT_body_begin
:
12584 return "DW_AT_body_begin";
12585 case DW_AT_body_end
:
12586 return "DW_AT_body_end";
12587 case DW_AT_GNU_vector
:
12588 return "DW_AT_GNU_vector";
12589 case DW_AT_GNU_odr_signature
:
12590 return "DW_AT_GNU_odr_signature";
12591 /* VMS extensions. */
12592 case DW_AT_VMS_rtnbeg_pd_address
:
12593 return "DW_AT_VMS_rtnbeg_pd_address";
12594 /* UPC extension. */
12595 case DW_AT_upc_threads_scaled
:
12596 return "DW_AT_upc_threads_scaled";
12597 /* PGI (STMicroelectronics) extensions. */
12598 case DW_AT_PGI_lbase
:
12599 return "DW_AT_PGI_lbase";
12600 case DW_AT_PGI_soffset
:
12601 return "DW_AT_PGI_soffset";
12602 case DW_AT_PGI_lstride
:
12603 return "DW_AT_PGI_lstride";
12605 return "DW_AT_<unknown>";
12609 /* Convert a DWARF value form code into its string name. */
12612 dwarf_form_name (unsigned form
)
12617 return "DW_FORM_addr";
12618 case DW_FORM_block2
:
12619 return "DW_FORM_block2";
12620 case DW_FORM_block4
:
12621 return "DW_FORM_block4";
12622 case DW_FORM_data2
:
12623 return "DW_FORM_data2";
12624 case DW_FORM_data4
:
12625 return "DW_FORM_data4";
12626 case DW_FORM_data8
:
12627 return "DW_FORM_data8";
12628 case DW_FORM_string
:
12629 return "DW_FORM_string";
12630 case DW_FORM_block
:
12631 return "DW_FORM_block";
12632 case DW_FORM_block1
:
12633 return "DW_FORM_block1";
12634 case DW_FORM_data1
:
12635 return "DW_FORM_data1";
12637 return "DW_FORM_flag";
12638 case DW_FORM_sdata
:
12639 return "DW_FORM_sdata";
12641 return "DW_FORM_strp";
12642 case DW_FORM_udata
:
12643 return "DW_FORM_udata";
12644 case DW_FORM_ref_addr
:
12645 return "DW_FORM_ref_addr";
12647 return "DW_FORM_ref1";
12649 return "DW_FORM_ref2";
12651 return "DW_FORM_ref4";
12653 return "DW_FORM_ref8";
12654 case DW_FORM_ref_udata
:
12655 return "DW_FORM_ref_udata";
12656 case DW_FORM_indirect
:
12657 return "DW_FORM_indirect";
12658 case DW_FORM_sec_offset
:
12659 return "DW_FORM_sec_offset";
12660 case DW_FORM_exprloc
:
12661 return "DW_FORM_exprloc";
12662 case DW_FORM_flag_present
:
12663 return "DW_FORM_flag_present";
12664 case DW_FORM_ref_sig8
:
12665 return "DW_FORM_ref_sig8";
12667 return "DW_FORM_<unknown>";
12671 /* Convert a DWARF stack opcode into its string name. */
12674 dwarf_stack_op_name (unsigned op
)
12679 return "DW_OP_addr";
12681 return "DW_OP_deref";
12682 case DW_OP_const1u
:
12683 return "DW_OP_const1u";
12684 case DW_OP_const1s
:
12685 return "DW_OP_const1s";
12686 case DW_OP_const2u
:
12687 return "DW_OP_const2u";
12688 case DW_OP_const2s
:
12689 return "DW_OP_const2s";
12690 case DW_OP_const4u
:
12691 return "DW_OP_const4u";
12692 case DW_OP_const4s
:
12693 return "DW_OP_const4s";
12694 case DW_OP_const8u
:
12695 return "DW_OP_const8u";
12696 case DW_OP_const8s
:
12697 return "DW_OP_const8s";
12699 return "DW_OP_constu";
12701 return "DW_OP_consts";
12703 return "DW_OP_dup";
12705 return "DW_OP_drop";
12707 return "DW_OP_over";
12709 return "DW_OP_pick";
12711 return "DW_OP_swap";
12713 return "DW_OP_rot";
12715 return "DW_OP_xderef";
12717 return "DW_OP_abs";
12719 return "DW_OP_and";
12721 return "DW_OP_div";
12723 return "DW_OP_minus";
12725 return "DW_OP_mod";
12727 return "DW_OP_mul";
12729 return "DW_OP_neg";
12731 return "DW_OP_not";
12735 return "DW_OP_plus";
12736 case DW_OP_plus_uconst
:
12737 return "DW_OP_plus_uconst";
12739 return "DW_OP_shl";
12741 return "DW_OP_shr";
12743 return "DW_OP_shra";
12745 return "DW_OP_xor";
12747 return "DW_OP_bra";
12761 return "DW_OP_skip";
12763 return "DW_OP_lit0";
12765 return "DW_OP_lit1";
12767 return "DW_OP_lit2";
12769 return "DW_OP_lit3";
12771 return "DW_OP_lit4";
12773 return "DW_OP_lit5";
12775 return "DW_OP_lit6";
12777 return "DW_OP_lit7";
12779 return "DW_OP_lit8";
12781 return "DW_OP_lit9";
12783 return "DW_OP_lit10";
12785 return "DW_OP_lit11";
12787 return "DW_OP_lit12";
12789 return "DW_OP_lit13";
12791 return "DW_OP_lit14";
12793 return "DW_OP_lit15";
12795 return "DW_OP_lit16";
12797 return "DW_OP_lit17";
12799 return "DW_OP_lit18";
12801 return "DW_OP_lit19";
12803 return "DW_OP_lit20";
12805 return "DW_OP_lit21";
12807 return "DW_OP_lit22";
12809 return "DW_OP_lit23";
12811 return "DW_OP_lit24";
12813 return "DW_OP_lit25";
12815 return "DW_OP_lit26";
12817 return "DW_OP_lit27";
12819 return "DW_OP_lit28";
12821 return "DW_OP_lit29";
12823 return "DW_OP_lit30";
12825 return "DW_OP_lit31";
12827 return "DW_OP_reg0";
12829 return "DW_OP_reg1";
12831 return "DW_OP_reg2";
12833 return "DW_OP_reg3";
12835 return "DW_OP_reg4";
12837 return "DW_OP_reg5";
12839 return "DW_OP_reg6";
12841 return "DW_OP_reg7";
12843 return "DW_OP_reg8";
12845 return "DW_OP_reg9";
12847 return "DW_OP_reg10";
12849 return "DW_OP_reg11";
12851 return "DW_OP_reg12";
12853 return "DW_OP_reg13";
12855 return "DW_OP_reg14";
12857 return "DW_OP_reg15";
12859 return "DW_OP_reg16";
12861 return "DW_OP_reg17";
12863 return "DW_OP_reg18";
12865 return "DW_OP_reg19";
12867 return "DW_OP_reg20";
12869 return "DW_OP_reg21";
12871 return "DW_OP_reg22";
12873 return "DW_OP_reg23";
12875 return "DW_OP_reg24";
12877 return "DW_OP_reg25";
12879 return "DW_OP_reg26";
12881 return "DW_OP_reg27";
12883 return "DW_OP_reg28";
12885 return "DW_OP_reg29";
12887 return "DW_OP_reg30";
12889 return "DW_OP_reg31";
12891 return "DW_OP_breg0";
12893 return "DW_OP_breg1";
12895 return "DW_OP_breg2";
12897 return "DW_OP_breg3";
12899 return "DW_OP_breg4";
12901 return "DW_OP_breg5";
12903 return "DW_OP_breg6";
12905 return "DW_OP_breg7";
12907 return "DW_OP_breg8";
12909 return "DW_OP_breg9";
12911 return "DW_OP_breg10";
12913 return "DW_OP_breg11";
12915 return "DW_OP_breg12";
12917 return "DW_OP_breg13";
12919 return "DW_OP_breg14";
12921 return "DW_OP_breg15";
12923 return "DW_OP_breg16";
12925 return "DW_OP_breg17";
12927 return "DW_OP_breg18";
12929 return "DW_OP_breg19";
12931 return "DW_OP_breg20";
12933 return "DW_OP_breg21";
12935 return "DW_OP_breg22";
12937 return "DW_OP_breg23";
12939 return "DW_OP_breg24";
12941 return "DW_OP_breg25";
12943 return "DW_OP_breg26";
12945 return "DW_OP_breg27";
12947 return "DW_OP_breg28";
12949 return "DW_OP_breg29";
12951 return "DW_OP_breg30";
12953 return "DW_OP_breg31";
12955 return "DW_OP_regx";
12957 return "DW_OP_fbreg";
12959 return "DW_OP_bregx";
12961 return "DW_OP_piece";
12962 case DW_OP_deref_size
:
12963 return "DW_OP_deref_size";
12964 case DW_OP_xderef_size
:
12965 return "DW_OP_xderef_size";
12967 return "DW_OP_nop";
12968 /* DWARF 3 extensions. */
12969 case DW_OP_push_object_address
:
12970 return "DW_OP_push_object_address";
12972 return "DW_OP_call2";
12974 return "DW_OP_call4";
12975 case DW_OP_call_ref
:
12976 return "DW_OP_call_ref";
12977 case DW_OP_form_tls_address
:
12978 return "DW_OP_form_tls_address";
12979 case DW_OP_call_frame_cfa
:
12980 return "DW_OP_call_frame_cfa";
12981 case DW_OP_bit_piece
:
12982 return "DW_OP_bit_piece";
12983 /* DWARF 4 extensions. */
12984 case DW_OP_implicit_value
:
12985 return "DW_OP_implicit_value";
12986 case DW_OP_stack_value
:
12987 return "DW_OP_stack_value";
12988 /* GNU extensions. */
12989 case DW_OP_GNU_push_tls_address
:
12990 return "DW_OP_GNU_push_tls_address";
12991 case DW_OP_GNU_uninit
:
12992 return "DW_OP_GNU_uninit";
12993 case DW_OP_GNU_implicit_pointer
:
12994 return "DW_OP_GNU_implicit_pointer";
13001 dwarf_bool_name (unsigned mybool
)
13009 /* Convert a DWARF type code into its string name. */
13012 dwarf_type_encoding_name (unsigned enc
)
13017 return "DW_ATE_void";
13018 case DW_ATE_address
:
13019 return "DW_ATE_address";
13020 case DW_ATE_boolean
:
13021 return "DW_ATE_boolean";
13022 case DW_ATE_complex_float
:
13023 return "DW_ATE_complex_float";
13025 return "DW_ATE_float";
13026 case DW_ATE_signed
:
13027 return "DW_ATE_signed";
13028 case DW_ATE_signed_char
:
13029 return "DW_ATE_signed_char";
13030 case DW_ATE_unsigned
:
13031 return "DW_ATE_unsigned";
13032 case DW_ATE_unsigned_char
:
13033 return "DW_ATE_unsigned_char";
13035 case DW_ATE_imaginary_float
:
13036 return "DW_ATE_imaginary_float";
13037 case DW_ATE_packed_decimal
:
13038 return "DW_ATE_packed_decimal";
13039 case DW_ATE_numeric_string
:
13040 return "DW_ATE_numeric_string";
13041 case DW_ATE_edited
:
13042 return "DW_ATE_edited";
13043 case DW_ATE_signed_fixed
:
13044 return "DW_ATE_signed_fixed";
13045 case DW_ATE_unsigned_fixed
:
13046 return "DW_ATE_unsigned_fixed";
13047 case DW_ATE_decimal_float
:
13048 return "DW_ATE_decimal_float";
13051 return "DW_ATE_UTF";
13052 /* HP extensions. */
13053 case DW_ATE_HP_float80
:
13054 return "DW_ATE_HP_float80";
13055 case DW_ATE_HP_complex_float80
:
13056 return "DW_ATE_HP_complex_float80";
13057 case DW_ATE_HP_float128
:
13058 return "DW_ATE_HP_float128";
13059 case DW_ATE_HP_complex_float128
:
13060 return "DW_ATE_HP_complex_float128";
13061 case DW_ATE_HP_floathpintel
:
13062 return "DW_ATE_HP_floathpintel";
13063 case DW_ATE_HP_imaginary_float80
:
13064 return "DW_ATE_HP_imaginary_float80";
13065 case DW_ATE_HP_imaginary_float128
:
13066 return "DW_ATE_HP_imaginary_float128";
13068 return "DW_ATE_<unknown>";
13072 /* Convert a DWARF call frame info operation to its string name. */
13076 dwarf_cfi_name (unsigned cfi_opc
)
13080 case DW_CFA_advance_loc
:
13081 return "DW_CFA_advance_loc";
13082 case DW_CFA_offset
:
13083 return "DW_CFA_offset";
13084 case DW_CFA_restore
:
13085 return "DW_CFA_restore";
13087 return "DW_CFA_nop";
13088 case DW_CFA_set_loc
:
13089 return "DW_CFA_set_loc";
13090 case DW_CFA_advance_loc1
:
13091 return "DW_CFA_advance_loc1";
13092 case DW_CFA_advance_loc2
:
13093 return "DW_CFA_advance_loc2";
13094 case DW_CFA_advance_loc4
:
13095 return "DW_CFA_advance_loc4";
13096 case DW_CFA_offset_extended
:
13097 return "DW_CFA_offset_extended";
13098 case DW_CFA_restore_extended
:
13099 return "DW_CFA_restore_extended";
13100 case DW_CFA_undefined
:
13101 return "DW_CFA_undefined";
13102 case DW_CFA_same_value
:
13103 return "DW_CFA_same_value";
13104 case DW_CFA_register
:
13105 return "DW_CFA_register";
13106 case DW_CFA_remember_state
:
13107 return "DW_CFA_remember_state";
13108 case DW_CFA_restore_state
:
13109 return "DW_CFA_restore_state";
13110 case DW_CFA_def_cfa
:
13111 return "DW_CFA_def_cfa";
13112 case DW_CFA_def_cfa_register
:
13113 return "DW_CFA_def_cfa_register";
13114 case DW_CFA_def_cfa_offset
:
13115 return "DW_CFA_def_cfa_offset";
13117 case DW_CFA_def_cfa_expression
:
13118 return "DW_CFA_def_cfa_expression";
13119 case DW_CFA_expression
:
13120 return "DW_CFA_expression";
13121 case DW_CFA_offset_extended_sf
:
13122 return "DW_CFA_offset_extended_sf";
13123 case DW_CFA_def_cfa_sf
:
13124 return "DW_CFA_def_cfa_sf";
13125 case DW_CFA_def_cfa_offset_sf
:
13126 return "DW_CFA_def_cfa_offset_sf";
13127 case DW_CFA_val_offset
:
13128 return "DW_CFA_val_offset";
13129 case DW_CFA_val_offset_sf
:
13130 return "DW_CFA_val_offset_sf";
13131 case DW_CFA_val_expression
:
13132 return "DW_CFA_val_expression";
13133 /* SGI/MIPS specific. */
13134 case DW_CFA_MIPS_advance_loc8
:
13135 return "DW_CFA_MIPS_advance_loc8";
13136 /* GNU extensions. */
13137 case DW_CFA_GNU_window_save
:
13138 return "DW_CFA_GNU_window_save";
13139 case DW_CFA_GNU_args_size
:
13140 return "DW_CFA_GNU_args_size";
13141 case DW_CFA_GNU_negative_offset_extended
:
13142 return "DW_CFA_GNU_negative_offset_extended";
13144 return "DW_CFA_<unknown>";
13150 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13154 print_spaces (indent
, f
);
13155 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13156 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13158 if (die
->parent
!= NULL
)
13160 print_spaces (indent
, f
);
13161 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13162 die
->parent
->offset
);
13165 print_spaces (indent
, f
);
13166 fprintf_unfiltered (f
, " has children: %s\n",
13167 dwarf_bool_name (die
->child
!= NULL
));
13169 print_spaces (indent
, f
);
13170 fprintf_unfiltered (f
, " attributes:\n");
13172 for (i
= 0; i
< die
->num_attrs
; ++i
)
13174 print_spaces (indent
, f
);
13175 fprintf_unfiltered (f
, " %s (%s) ",
13176 dwarf_attr_name (die
->attrs
[i
].name
),
13177 dwarf_form_name (die
->attrs
[i
].form
));
13179 switch (die
->attrs
[i
].form
)
13181 case DW_FORM_ref_addr
:
13183 fprintf_unfiltered (f
, "address: ");
13184 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13186 case DW_FORM_block2
:
13187 case DW_FORM_block4
:
13188 case DW_FORM_block
:
13189 case DW_FORM_block1
:
13190 fprintf_unfiltered (f
, "block: size %d",
13191 DW_BLOCK (&die
->attrs
[i
])->size
);
13193 case DW_FORM_exprloc
:
13194 fprintf_unfiltered (f
, "expression: size %u",
13195 DW_BLOCK (&die
->attrs
[i
])->size
);
13200 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13201 (long) (DW_ADDR (&die
->attrs
[i
])));
13203 case DW_FORM_data1
:
13204 case DW_FORM_data2
:
13205 case DW_FORM_data4
:
13206 case DW_FORM_data8
:
13207 case DW_FORM_udata
:
13208 case DW_FORM_sdata
:
13209 fprintf_unfiltered (f
, "constant: %s",
13210 pulongest (DW_UNSND (&die
->attrs
[i
])));
13212 case DW_FORM_sec_offset
:
13213 fprintf_unfiltered (f
, "section offset: %s",
13214 pulongest (DW_UNSND (&die
->attrs
[i
])));
13216 case DW_FORM_ref_sig8
:
13217 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13218 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13219 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
13221 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13223 case DW_FORM_string
:
13225 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13226 DW_STRING (&die
->attrs
[i
])
13227 ? DW_STRING (&die
->attrs
[i
]) : "",
13228 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13231 if (DW_UNSND (&die
->attrs
[i
]))
13232 fprintf_unfiltered (f
, "flag: TRUE");
13234 fprintf_unfiltered (f
, "flag: FALSE");
13236 case DW_FORM_flag_present
:
13237 fprintf_unfiltered (f
, "flag: TRUE");
13239 case DW_FORM_indirect
:
13240 /* The reader will have reduced the indirect form to
13241 the "base form" so this form should not occur. */
13242 fprintf_unfiltered (f
,
13243 "unexpected attribute form: DW_FORM_indirect");
13246 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13247 die
->attrs
[i
].form
);
13250 fprintf_unfiltered (f
, "\n");
13255 dump_die_for_error (struct die_info
*die
)
13257 dump_die_shallow (gdb_stderr
, 0, die
);
13261 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13263 int indent
= level
* 4;
13265 gdb_assert (die
!= NULL
);
13267 if (level
>= max_level
)
13270 dump_die_shallow (f
, indent
, die
);
13272 if (die
->child
!= NULL
)
13274 print_spaces (indent
, f
);
13275 fprintf_unfiltered (f
, " Children:");
13276 if (level
+ 1 < max_level
)
13278 fprintf_unfiltered (f
, "\n");
13279 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13283 fprintf_unfiltered (f
,
13284 " [not printed, max nesting level reached]\n");
13288 if (die
->sibling
!= NULL
&& level
> 0)
13290 dump_die_1 (f
, level
, max_level
, die
->sibling
);
13294 /* This is called from the pdie macro in gdbinit.in.
13295 It's not static so gcc will keep a copy callable from gdb. */
13298 dump_die (struct die_info
*die
, int max_level
)
13300 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
13304 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
13308 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
13314 is_ref_attr (struct attribute
*attr
)
13316 switch (attr
->form
)
13318 case DW_FORM_ref_addr
:
13323 case DW_FORM_ref_udata
:
13330 static unsigned int
13331 dwarf2_get_ref_die_offset (struct attribute
*attr
)
13333 if (is_ref_attr (attr
))
13334 return DW_ADDR (attr
);
13336 complaint (&symfile_complaints
,
13337 _("unsupported die ref attribute form: '%s'"),
13338 dwarf_form_name (attr
->form
));
13342 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13343 * the value held by the attribute is not constant. */
13346 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
13348 if (attr
->form
== DW_FORM_sdata
)
13349 return DW_SND (attr
);
13350 else if (attr
->form
== DW_FORM_udata
13351 || attr
->form
== DW_FORM_data1
13352 || attr
->form
== DW_FORM_data2
13353 || attr
->form
== DW_FORM_data4
13354 || attr
->form
== DW_FORM_data8
)
13355 return DW_UNSND (attr
);
13358 complaint (&symfile_complaints
,
13359 _("Attribute value is not a constant (%s)"),
13360 dwarf_form_name (attr
->form
));
13361 return default_value
;
13365 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13366 unit and add it to our queue.
13367 The result is non-zero if PER_CU was queued, otherwise the result is zero
13368 meaning either PER_CU is already queued or it is already loaded. */
13371 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
13372 struct dwarf2_per_cu_data
*per_cu
)
13374 /* We may arrive here during partial symbol reading, if we need full
13375 DIEs to process an unusual case (e.g. template arguments). Do
13376 not queue PER_CU, just tell our caller to load its DIEs. */
13377 if (dwarf2_per_objfile
->reading_partial_symbols
)
13379 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
13384 /* Mark the dependence relation so that we don't flush PER_CU
13386 dwarf2_add_dependence (this_cu
, per_cu
);
13388 /* If it's already on the queue, we have nothing to do. */
13389 if (per_cu
->queued
)
13392 /* If the compilation unit is already loaded, just mark it as
13394 if (per_cu
->cu
!= NULL
)
13396 per_cu
->cu
->last_used
= 0;
13400 /* Add it to the queue. */
13401 queue_comp_unit (per_cu
, this_cu
->objfile
);
13406 /* Follow reference or signature attribute ATTR of SRC_DIE.
13407 On entry *REF_CU is the CU of SRC_DIE.
13408 On exit *REF_CU is the CU of the result. */
13410 static struct die_info
*
13411 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
13412 struct dwarf2_cu
**ref_cu
)
13414 struct die_info
*die
;
13416 if (is_ref_attr (attr
))
13417 die
= follow_die_ref (src_die
, attr
, ref_cu
);
13418 else if (attr
->form
== DW_FORM_ref_sig8
)
13419 die
= follow_die_sig (src_die
, attr
, ref_cu
);
13422 dump_die_for_error (src_die
);
13423 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13424 (*ref_cu
)->objfile
->name
);
13430 /* Follow reference OFFSET.
13431 On entry *REF_CU is the CU of the source die referencing OFFSET.
13432 On exit *REF_CU is the CU of the result.
13433 Returns NULL if OFFSET is invalid. */
13435 static struct die_info
*
13436 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
13438 struct die_info temp_die
;
13439 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
13441 gdb_assert (cu
->per_cu
!= NULL
);
13445 if (cu
->per_cu
->from_debug_types
)
13447 /* .debug_types CUs cannot reference anything outside their CU.
13448 If they need to, they have to reference a signatured type via
13449 DW_FORM_ref_sig8. */
13450 if (! offset_in_cu_p (&cu
->header
, offset
))
13453 else if (! offset_in_cu_p (&cu
->header
, offset
))
13455 struct dwarf2_per_cu_data
*per_cu
;
13457 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
13459 /* If necessary, add it to the queue and load its DIEs. */
13460 if (maybe_queue_comp_unit (cu
, per_cu
))
13461 load_full_comp_unit (per_cu
, cu
->objfile
);
13463 target_cu
= per_cu
->cu
;
13465 else if (cu
->dies
== NULL
)
13467 /* We're loading full DIEs during partial symbol reading. */
13468 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
13469 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
13472 *ref_cu
= target_cu
;
13473 temp_die
.offset
= offset
;
13474 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13477 /* Follow reference attribute ATTR of SRC_DIE.
13478 On entry *REF_CU is the CU of SRC_DIE.
13479 On exit *REF_CU is the CU of the result. */
13481 static struct die_info
*
13482 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13483 struct dwarf2_cu
**ref_cu
)
13485 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13486 struct dwarf2_cu
*cu
= *ref_cu
;
13487 struct die_info
*die
;
13489 die
= follow_die_offset (offset
, ref_cu
);
13491 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13492 "at 0x%x [in module %s]"),
13493 offset
, src_die
->offset
, cu
->objfile
->name
);
13498 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13499 value is intended for DW_OP_call*. */
13501 struct dwarf2_locexpr_baton
13502 dwarf2_fetch_die_location_block (unsigned int offset
,
13503 struct dwarf2_per_cu_data
*per_cu
,
13504 CORE_ADDR (*get_frame_pc
) (void *baton
),
13507 struct dwarf2_cu
*cu
= per_cu
->cu
;
13508 struct die_info
*die
;
13509 struct attribute
*attr
;
13510 struct dwarf2_locexpr_baton retval
;
13512 dw2_setup (per_cu
->objfile
);
13514 die
= follow_die_offset (offset
, &cu
);
13516 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13517 offset
, per_cu
->cu
->objfile
->name
);
13519 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13522 /* DWARF: "If there is no such attribute, then there is no effect.". */
13524 retval
.data
= NULL
;
13527 else if (attr_form_is_section_offset (attr
))
13529 struct dwarf2_loclist_baton loclist_baton
;
13530 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
13533 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
13535 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
13537 retval
.size
= size
;
13541 if (!attr_form_is_block (attr
))
13542 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13543 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13544 offset
, per_cu
->cu
->objfile
->name
);
13546 retval
.data
= DW_BLOCK (attr
)->data
;
13547 retval
.size
= DW_BLOCK (attr
)->size
;
13549 retval
.per_cu
= cu
->per_cu
;
13553 /* Follow the signature attribute ATTR in SRC_DIE.
13554 On entry *REF_CU is the CU of SRC_DIE.
13555 On exit *REF_CU is the CU of the result. */
13557 static struct die_info
*
13558 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
13559 struct dwarf2_cu
**ref_cu
)
13561 struct objfile
*objfile
= (*ref_cu
)->objfile
;
13562 struct die_info temp_die
;
13563 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13564 struct dwarf2_cu
*sig_cu
;
13565 struct die_info
*die
;
13567 /* sig_type will be NULL if the signatured type is missing from
13569 if (sig_type
== NULL
)
13570 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13571 "at 0x%x [in module %s]"),
13572 src_die
->offset
, objfile
->name
);
13574 /* If necessary, add it to the queue and load its DIEs. */
13576 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
13577 read_signatured_type (objfile
, sig_type
);
13579 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
13581 sig_cu
= sig_type
->per_cu
.cu
;
13582 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
13583 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
13590 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
13591 "from DIE at 0x%x [in module %s]"),
13592 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
13595 /* Given an offset of a signatured type, return its signatured_type. */
13597 static struct signatured_type
*
13598 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
13600 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
13601 unsigned int length
, initial_length_size
;
13602 unsigned int sig_offset
;
13603 struct signatured_type find_entry
, *type_sig
;
13605 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
13606 sig_offset
= (initial_length_size
13608 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
13609 + 1 /*address_size*/);
13610 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
13611 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
13613 /* This is only used to lookup previously recorded types.
13614 If we didn't find it, it's our bug. */
13615 gdb_assert (type_sig
!= NULL
);
13616 gdb_assert (offset
== type_sig
->offset
);
13621 /* Read in signatured type at OFFSET and build its CU and die(s). */
13624 read_signatured_type_at_offset (struct objfile
*objfile
,
13625 unsigned int offset
)
13627 struct signatured_type
*type_sig
;
13629 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13631 /* We have the section offset, but we need the signature to do the
13632 hash table lookup. */
13633 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
13635 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13637 read_signatured_type (objfile
, type_sig
);
13639 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
13642 /* Read in a signatured type and build its CU and DIEs. */
13645 read_signatured_type (struct objfile
*objfile
,
13646 struct signatured_type
*type_sig
)
13648 gdb_byte
*types_ptr
;
13649 struct die_reader_specs reader_specs
;
13650 struct dwarf2_cu
*cu
;
13651 ULONGEST signature
;
13652 struct cleanup
*back_to
, *free_cu_cleanup
;
13654 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13655 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
13657 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13659 cu
= xmalloc (sizeof (*cu
));
13660 init_one_comp_unit (cu
, objfile
);
13662 type_sig
->per_cu
.cu
= cu
;
13663 cu
->per_cu
= &type_sig
->per_cu
;
13665 /* If an error occurs while loading, release our storage. */
13666 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
13668 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
13669 types_ptr
, objfile
->obfd
);
13670 gdb_assert (signature
== type_sig
->signature
);
13673 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13677 &cu
->comp_unit_obstack
,
13678 hashtab_obstack_allocate
,
13679 dummy_obstack_deallocate
);
13681 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
13682 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
13684 init_cu_die_reader (&reader_specs
, cu
);
13686 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
13689 /* We try not to read any attributes in this function, because not
13690 all objfiles needed for references have been loaded yet, and symbol
13691 table processing isn't initialized. But we have to set the CU language,
13692 or we won't be able to build types correctly. */
13693 prepare_one_comp_unit (cu
, cu
->dies
);
13695 do_cleanups (back_to
);
13697 /* We've successfully allocated this compilation unit. Let our caller
13698 clean it up when finished with it. */
13699 discard_cleanups (free_cu_cleanup
);
13701 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
13702 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
13705 /* Decode simple location descriptions.
13706 Given a pointer to a dwarf block that defines a location, compute
13707 the location and return the value.
13709 NOTE drow/2003-11-18: This function is called in two situations
13710 now: for the address of static or global variables (partial symbols
13711 only) and for offsets into structures which are expected to be
13712 (more or less) constant. The partial symbol case should go away,
13713 and only the constant case should remain. That will let this
13714 function complain more accurately. A few special modes are allowed
13715 without complaint for global variables (for instance, global
13716 register values and thread-local values).
13718 A location description containing no operations indicates that the
13719 object is optimized out. The return value is 0 for that case.
13720 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13721 callers will only want a very basic result and this can become a
13724 Note that stack[0] is unused except as a default error return. */
13727 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
13729 struct objfile
*objfile
= cu
->objfile
;
13731 int size
= blk
->size
;
13732 gdb_byte
*data
= blk
->data
;
13733 CORE_ADDR stack
[64];
13735 unsigned int bytes_read
, unsnd
;
13741 stack
[++stacki
] = 0;
13780 stack
[++stacki
] = op
- DW_OP_lit0
;
13815 stack
[++stacki
] = op
- DW_OP_reg0
;
13817 dwarf2_complex_location_expr_complaint ();
13821 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13823 stack
[++stacki
] = unsnd
;
13825 dwarf2_complex_location_expr_complaint ();
13829 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
13834 case DW_OP_const1u
:
13835 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
13839 case DW_OP_const1s
:
13840 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
13844 case DW_OP_const2u
:
13845 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
13849 case DW_OP_const2s
:
13850 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
13854 case DW_OP_const4u
:
13855 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
13859 case DW_OP_const4s
:
13860 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
13865 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
13871 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
13876 stack
[stacki
+ 1] = stack
[stacki
];
13881 stack
[stacki
- 1] += stack
[stacki
];
13885 case DW_OP_plus_uconst
:
13886 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
13892 stack
[stacki
- 1] -= stack
[stacki
];
13897 /* If we're not the last op, then we definitely can't encode
13898 this using GDB's address_class enum. This is valid for partial
13899 global symbols, although the variable's address will be bogus
13902 dwarf2_complex_location_expr_complaint ();
13905 case DW_OP_GNU_push_tls_address
:
13906 /* The top of the stack has the offset from the beginning
13907 of the thread control block at which the variable is located. */
13908 /* Nothing should follow this operator, so the top of stack would
13910 /* This is valid for partial global symbols, but the variable's
13911 address will be bogus in the psymtab. */
13913 dwarf2_complex_location_expr_complaint ();
13916 case DW_OP_GNU_uninit
:
13921 const char *name
= dwarf_stack_op_name (op
);
13924 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
13927 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
13931 return (stack
[stacki
]);
13934 /* Enforce maximum stack depth of SIZE-1 to avoid writing
13935 outside of the allocated space. Also enforce minimum>0. */
13936 if (stacki
>= ARRAY_SIZE (stack
) - 1)
13938 complaint (&symfile_complaints
,
13939 _("location description stack overflow"));
13945 complaint (&symfile_complaints
,
13946 _("location description stack underflow"));
13950 return (stack
[stacki
]);
13953 /* memory allocation interface */
13955 static struct dwarf_block
*
13956 dwarf_alloc_block (struct dwarf2_cu
*cu
)
13958 struct dwarf_block
*blk
;
13960 blk
= (struct dwarf_block
*)
13961 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
13965 static struct abbrev_info
*
13966 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
13968 struct abbrev_info
*abbrev
;
13970 abbrev
= (struct abbrev_info
*)
13971 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
13972 memset (abbrev
, 0, sizeof (struct abbrev_info
));
13976 static struct die_info
*
13977 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
13979 struct die_info
*die
;
13980 size_t size
= sizeof (struct die_info
);
13983 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
13985 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
13986 memset (die
, 0, sizeof (struct die_info
));
13991 /* Macro support. */
13993 /* Return the full name of file number I in *LH's file name table.
13994 Use COMP_DIR as the name of the current directory of the
13995 compilation. The result is allocated using xmalloc; the caller is
13996 responsible for freeing it. */
13998 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14000 /* Is the file number a valid index into the line header's file name
14001 table? Remember that file numbers start with one, not zero. */
14002 if (1 <= file
&& file
<= lh
->num_file_names
)
14004 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14006 if (IS_ABSOLUTE_PATH (fe
->name
))
14007 return xstrdup (fe
->name
);
14015 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14021 dir_len
= strlen (dir
);
14022 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14023 strcpy (full_name
, dir
);
14024 full_name
[dir_len
] = '/';
14025 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14029 return xstrdup (fe
->name
);
14034 /* The compiler produced a bogus file number. We can at least
14035 record the macro definitions made in the file, even if we
14036 won't be able to find the file by name. */
14037 char fake_name
[80];
14039 sprintf (fake_name
, "<bad macro file number %d>", file
);
14041 complaint (&symfile_complaints
,
14042 _("bad file number in macro information (%d)"),
14045 return xstrdup (fake_name
);
14050 static struct macro_source_file
*
14051 macro_start_file (int file
, int line
,
14052 struct macro_source_file
*current_file
,
14053 const char *comp_dir
,
14054 struct line_header
*lh
, struct objfile
*objfile
)
14056 /* The full name of this source file. */
14057 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14059 /* We don't create a macro table for this compilation unit
14060 at all until we actually get a filename. */
14061 if (! pending_macros
)
14062 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14063 objfile
->macro_cache
);
14065 if (! current_file
)
14066 /* If we have no current file, then this must be the start_file
14067 directive for the compilation unit's main source file. */
14068 current_file
= macro_set_main (pending_macros
, full_name
);
14070 current_file
= macro_include (current_file
, line
, full_name
);
14074 return current_file
;
14078 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14079 followed by a null byte. */
14081 copy_string (const char *buf
, int len
)
14083 char *s
= xmalloc (len
+ 1);
14085 memcpy (s
, buf
, len
);
14091 static const char *
14092 consume_improper_spaces (const char *p
, const char *body
)
14096 complaint (&symfile_complaints
,
14097 _("macro definition contains spaces "
14098 "in formal argument list:\n`%s'"),
14110 parse_macro_definition (struct macro_source_file
*file
, int line
,
14115 /* The body string takes one of two forms. For object-like macro
14116 definitions, it should be:
14118 <macro name> " " <definition>
14120 For function-like macro definitions, it should be:
14122 <macro name> "() " <definition>
14124 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14126 Spaces may appear only where explicitly indicated, and in the
14129 The Dwarf 2 spec says that an object-like macro's name is always
14130 followed by a space, but versions of GCC around March 2002 omit
14131 the space when the macro's definition is the empty string.
14133 The Dwarf 2 spec says that there should be no spaces between the
14134 formal arguments in a function-like macro's formal argument list,
14135 but versions of GCC around March 2002 include spaces after the
14139 /* Find the extent of the macro name. The macro name is terminated
14140 by either a space or null character (for an object-like macro) or
14141 an opening paren (for a function-like macro). */
14142 for (p
= body
; *p
; p
++)
14143 if (*p
== ' ' || *p
== '(')
14146 if (*p
== ' ' || *p
== '\0')
14148 /* It's an object-like macro. */
14149 int name_len
= p
- body
;
14150 char *name
= copy_string (body
, name_len
);
14151 const char *replacement
;
14154 replacement
= body
+ name_len
+ 1;
14157 dwarf2_macro_malformed_definition_complaint (body
);
14158 replacement
= body
+ name_len
;
14161 macro_define_object (file
, line
, name
, replacement
);
14165 else if (*p
== '(')
14167 /* It's a function-like macro. */
14168 char *name
= copy_string (body
, p
- body
);
14171 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14175 p
= consume_improper_spaces (p
, body
);
14177 /* Parse the formal argument list. */
14178 while (*p
&& *p
!= ')')
14180 /* Find the extent of the current argument name. */
14181 const char *arg_start
= p
;
14183 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14186 if (! *p
|| p
== arg_start
)
14187 dwarf2_macro_malformed_definition_complaint (body
);
14190 /* Make sure argv has room for the new argument. */
14191 if (argc
>= argv_size
)
14194 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14197 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14200 p
= consume_improper_spaces (p
, body
);
14202 /* Consume the comma, if present. */
14207 p
= consume_improper_spaces (p
, body
);
14216 /* Perfectly formed definition, no complaints. */
14217 macro_define_function (file
, line
, name
,
14218 argc
, (const char **) argv
,
14220 else if (*p
== '\0')
14222 /* Complain, but do define it. */
14223 dwarf2_macro_malformed_definition_complaint (body
);
14224 macro_define_function (file
, line
, name
,
14225 argc
, (const char **) argv
,
14229 /* Just complain. */
14230 dwarf2_macro_malformed_definition_complaint (body
);
14233 /* Just complain. */
14234 dwarf2_macro_malformed_definition_complaint (body
);
14240 for (i
= 0; i
< argc
; i
++)
14246 dwarf2_macro_malformed_definition_complaint (body
);
14251 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
14252 char *comp_dir
, bfd
*abfd
,
14253 struct dwarf2_cu
*cu
)
14255 gdb_byte
*mac_ptr
, *mac_end
;
14256 struct macro_source_file
*current_file
= 0;
14257 enum dwarf_macinfo_record_type macinfo_type
;
14258 int at_commandline
;
14260 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14261 &dwarf2_per_objfile
->macinfo
);
14262 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
14264 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
14268 /* First pass: Find the name of the base filename.
14269 This filename is needed in order to process all macros whose definition
14270 (or undefinition) comes from the command line. These macros are defined
14271 before the first DW_MACINFO_start_file entry, and yet still need to be
14272 associated to the base file.
14274 To determine the base file name, we scan the macro definitions until we
14275 reach the first DW_MACINFO_start_file entry. We then initialize
14276 CURRENT_FILE accordingly so that any macro definition found before the
14277 first DW_MACINFO_start_file can still be associated to the base file. */
14279 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14280 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
14281 + dwarf2_per_objfile
->macinfo
.size
;
14285 /* Do we at least have room for a macinfo type byte? */
14286 if (mac_ptr
>= mac_end
)
14288 /* Complaint is printed during the second pass as GDB will probably
14289 stop the first pass earlier upon finding
14290 DW_MACINFO_start_file. */
14294 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14297 switch (macinfo_type
)
14299 /* A zero macinfo type indicates the end of the macro
14304 case DW_MACINFO_define
:
14305 case DW_MACINFO_undef
:
14306 /* Only skip the data by MAC_PTR. */
14308 unsigned int bytes_read
;
14310 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14311 mac_ptr
+= bytes_read
;
14312 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14313 mac_ptr
+= bytes_read
;
14317 case DW_MACINFO_start_file
:
14319 unsigned int bytes_read
;
14322 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14323 mac_ptr
+= bytes_read
;
14324 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14325 mac_ptr
+= bytes_read
;
14327 current_file
= macro_start_file (file
, line
, current_file
,
14328 comp_dir
, lh
, cu
->objfile
);
14332 case DW_MACINFO_end_file
:
14333 /* No data to skip by MAC_PTR. */
14336 case DW_MACINFO_vendor_ext
:
14337 /* Only skip the data by MAC_PTR. */
14339 unsigned int bytes_read
;
14341 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14342 mac_ptr
+= bytes_read
;
14343 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14344 mac_ptr
+= bytes_read
;
14351 } while (macinfo_type
!= 0 && current_file
== NULL
);
14353 /* Second pass: Process all entries.
14355 Use the AT_COMMAND_LINE flag to determine whether we are still processing
14356 command-line macro definitions/undefinitions. This flag is unset when we
14357 reach the first DW_MACINFO_start_file entry. */
14359 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14361 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14362 GDB is still reading the definitions from command line. First
14363 DW_MACINFO_start_file will need to be ignored as it was already executed
14364 to create CURRENT_FILE for the main source holding also the command line
14365 definitions. On first met DW_MACINFO_start_file this flag is reset to
14366 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14368 at_commandline
= 1;
14372 /* Do we at least have room for a macinfo type byte? */
14373 if (mac_ptr
>= mac_end
)
14375 dwarf2_macros_too_long_complaint ();
14379 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14382 switch (macinfo_type
)
14384 /* A zero macinfo type indicates the end of the macro
14389 case DW_MACINFO_define
:
14390 case DW_MACINFO_undef
:
14392 unsigned int bytes_read
;
14396 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14397 mac_ptr
+= bytes_read
;
14398 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14399 mac_ptr
+= bytes_read
;
14401 if (! current_file
)
14403 /* DWARF violation as no main source is present. */
14404 complaint (&symfile_complaints
,
14405 _("debug info with no main source gives macro %s "
14407 macinfo_type
== DW_MACINFO_define
?
14409 macinfo_type
== DW_MACINFO_undef
?
14410 _("undefinition") :
14411 _("something-or-other"), line
, body
);
14414 if ((line
== 0 && !at_commandline
)
14415 || (line
!= 0 && at_commandline
))
14416 complaint (&symfile_complaints
,
14417 _("debug info gives %s macro %s with %s line %d: %s"),
14418 at_commandline
? _("command-line") : _("in-file"),
14419 macinfo_type
== DW_MACINFO_define
?
14421 macinfo_type
== DW_MACINFO_undef
?
14422 _("undefinition") :
14423 _("something-or-other"),
14424 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
14426 if (macinfo_type
== DW_MACINFO_define
)
14427 parse_macro_definition (current_file
, line
, body
);
14428 else if (macinfo_type
== DW_MACINFO_undef
)
14429 macro_undef (current_file
, line
, body
);
14433 case DW_MACINFO_start_file
:
14435 unsigned int bytes_read
;
14438 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14439 mac_ptr
+= bytes_read
;
14440 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14441 mac_ptr
+= bytes_read
;
14443 if ((line
== 0 && !at_commandline
)
14444 || (line
!= 0 && at_commandline
))
14445 complaint (&symfile_complaints
,
14446 _("debug info gives source %d included "
14447 "from %s at %s line %d"),
14448 file
, at_commandline
? _("command-line") : _("file"),
14449 line
== 0 ? _("zero") : _("non-zero"), line
);
14451 if (at_commandline
)
14453 /* This DW_MACINFO_start_file was executed in the pass one. */
14454 at_commandline
= 0;
14457 current_file
= macro_start_file (file
, line
,
14458 current_file
, comp_dir
,
14463 case DW_MACINFO_end_file
:
14464 if (! current_file
)
14465 complaint (&symfile_complaints
,
14466 _("macro debug info has an unmatched "
14467 "`close_file' directive"));
14470 current_file
= current_file
->included_by
;
14471 if (! current_file
)
14473 enum dwarf_macinfo_record_type next_type
;
14475 /* GCC circa March 2002 doesn't produce the zero
14476 type byte marking the end of the compilation
14477 unit. Complain if it's not there, but exit no
14480 /* Do we at least have room for a macinfo type byte? */
14481 if (mac_ptr
>= mac_end
)
14483 dwarf2_macros_too_long_complaint ();
14487 /* We don't increment mac_ptr here, so this is just
14489 next_type
= read_1_byte (abfd
, mac_ptr
);
14490 if (next_type
!= 0)
14491 complaint (&symfile_complaints
,
14492 _("no terminating 0-type entry for "
14493 "macros in `.debug_macinfo' section"));
14500 case DW_MACINFO_vendor_ext
:
14502 unsigned int bytes_read
;
14505 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14506 mac_ptr
+= bytes_read
;
14507 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14508 mac_ptr
+= bytes_read
;
14510 /* We don't recognize any vendor extensions. */
14514 } while (macinfo_type
!= 0);
14517 /* Check if the attribute's form is a DW_FORM_block*
14518 if so return true else false. */
14520 attr_form_is_block (struct attribute
*attr
)
14522 return (attr
== NULL
? 0 :
14523 attr
->form
== DW_FORM_block1
14524 || attr
->form
== DW_FORM_block2
14525 || attr
->form
== DW_FORM_block4
14526 || attr
->form
== DW_FORM_block
14527 || attr
->form
== DW_FORM_exprloc
);
14530 /* Return non-zero if ATTR's value is a section offset --- classes
14531 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14532 You may use DW_UNSND (attr) to retrieve such offsets.
14534 Section 7.5.4, "Attribute Encodings", explains that no attribute
14535 may have a value that belongs to more than one of these classes; it
14536 would be ambiguous if we did, because we use the same forms for all
14539 attr_form_is_section_offset (struct attribute
*attr
)
14541 return (attr
->form
== DW_FORM_data4
14542 || attr
->form
== DW_FORM_data8
14543 || attr
->form
== DW_FORM_sec_offset
);
14547 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14548 zero otherwise. When this function returns true, you can apply
14549 dwarf2_get_attr_constant_value to it.
14551 However, note that for some attributes you must check
14552 attr_form_is_section_offset before using this test. DW_FORM_data4
14553 and DW_FORM_data8 are members of both the constant class, and of
14554 the classes that contain offsets into other debug sections
14555 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14556 that, if an attribute's can be either a constant or one of the
14557 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14558 taken as section offsets, not constants. */
14560 attr_form_is_constant (struct attribute
*attr
)
14562 switch (attr
->form
)
14564 case DW_FORM_sdata
:
14565 case DW_FORM_udata
:
14566 case DW_FORM_data1
:
14567 case DW_FORM_data2
:
14568 case DW_FORM_data4
:
14569 case DW_FORM_data8
:
14576 /* A helper function that fills in a dwarf2_loclist_baton. */
14579 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
14580 struct dwarf2_loclist_baton
*baton
,
14581 struct attribute
*attr
)
14583 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14584 &dwarf2_per_objfile
->loc
);
14586 baton
->per_cu
= cu
->per_cu
;
14587 gdb_assert (baton
->per_cu
);
14588 /* We don't know how long the location list is, but make sure we
14589 don't run off the edge of the section. */
14590 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
14591 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
14592 baton
->base_address
= cu
->base_address
;
14596 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
14597 struct dwarf2_cu
*cu
)
14599 if (attr_form_is_section_offset (attr
)
14600 /* ".debug_loc" may not exist at all, or the offset may be outside
14601 the section. If so, fall through to the complaint in the
14603 && DW_UNSND (attr
) < dwarf2_section_size (dwarf2_per_objfile
->objfile
,
14604 &dwarf2_per_objfile
->loc
))
14606 struct dwarf2_loclist_baton
*baton
;
14608 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14609 sizeof (struct dwarf2_loclist_baton
));
14611 fill_in_loclist_baton (cu
, baton
, attr
);
14613 if (cu
->base_known
== 0)
14614 complaint (&symfile_complaints
,
14615 _("Location list used without "
14616 "specifying the CU base address."));
14618 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
14619 SYMBOL_LOCATION_BATON (sym
) = baton
;
14623 struct dwarf2_locexpr_baton
*baton
;
14625 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14626 sizeof (struct dwarf2_locexpr_baton
));
14627 baton
->per_cu
= cu
->per_cu
;
14628 gdb_assert (baton
->per_cu
);
14630 if (attr_form_is_block (attr
))
14632 /* Note that we're just copying the block's data pointer
14633 here, not the actual data. We're still pointing into the
14634 info_buffer for SYM's objfile; right now we never release
14635 that buffer, but when we do clean up properly this may
14637 baton
->size
= DW_BLOCK (attr
)->size
;
14638 baton
->data
= DW_BLOCK (attr
)->data
;
14642 dwarf2_invalid_attrib_class_complaint ("location description",
14643 SYMBOL_NATURAL_NAME (sym
));
14645 baton
->data
= NULL
;
14648 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14649 SYMBOL_LOCATION_BATON (sym
) = baton
;
14653 /* Return the OBJFILE associated with the compilation unit CU. If CU
14654 came from a separate debuginfo file, then the master objfile is
14658 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
14660 struct objfile
*objfile
= per_cu
->objfile
;
14662 /* Return the master objfile, so that we can report and look up the
14663 correct file containing this variable. */
14664 if (objfile
->separate_debug_objfile_backlink
)
14665 objfile
= objfile
->separate_debug_objfile_backlink
;
14670 /* Return the address size given in the compilation unit header for CU. */
14673 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
14676 return per_cu
->cu
->header
.addr_size
;
14679 /* If the CU is not currently read in, we re-read its header. */
14680 struct objfile
*objfile
= per_cu
->objfile
;
14681 struct dwarf2_per_objfile
*per_objfile
14682 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14683 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14684 struct comp_unit_head cu_header
;
14686 memset (&cu_header
, 0, sizeof cu_header
);
14687 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14688 return cu_header
.addr_size
;
14692 /* Return the offset size given in the compilation unit header for CU. */
14695 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
14698 return per_cu
->cu
->header
.offset_size
;
14701 /* If the CU is not currently read in, we re-read its header. */
14702 struct objfile
*objfile
= per_cu
->objfile
;
14703 struct dwarf2_per_objfile
*per_objfile
14704 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14705 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14706 struct comp_unit_head cu_header
;
14708 memset (&cu_header
, 0, sizeof cu_header
);
14709 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14710 return cu_header
.offset_size
;
14714 /* Return the text offset of the CU. The returned offset comes from
14715 this CU's objfile. If this objfile came from a separate debuginfo
14716 file, then the offset may be different from the corresponding
14717 offset in the parent objfile. */
14720 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
14722 struct objfile
*objfile
= per_cu
->objfile
;
14724 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14727 /* Locate the .debug_info compilation unit from CU's objfile which contains
14728 the DIE at OFFSET. Raises an error on failure. */
14730 static struct dwarf2_per_cu_data
*
14731 dwarf2_find_containing_comp_unit (unsigned int offset
,
14732 struct objfile
*objfile
)
14734 struct dwarf2_per_cu_data
*this_cu
;
14738 high
= dwarf2_per_objfile
->n_comp_units
- 1;
14741 int mid
= low
+ (high
- low
) / 2;
14743 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
14748 gdb_assert (low
== high
);
14749 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
14752 error (_("Dwarf Error: could not find partial DIE containing "
14753 "offset 0x%lx [in module %s]"),
14754 (long) offset
, bfd_get_filename (objfile
->obfd
));
14756 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
14757 return dwarf2_per_objfile
->all_comp_units
[low
-1];
14761 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
14762 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
14763 && offset
>= this_cu
->offset
+ this_cu
->length
)
14764 error (_("invalid dwarf2 offset %u"), offset
);
14765 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
14770 /* Locate the compilation unit from OBJFILE which is located at exactly
14771 OFFSET. Raises an error on failure. */
14773 static struct dwarf2_per_cu_data
*
14774 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
14776 struct dwarf2_per_cu_data
*this_cu
;
14778 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
14779 if (this_cu
->offset
!= offset
)
14780 error (_("no compilation unit with offset %u."), offset
);
14784 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
14787 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
14789 memset (cu
, 0, sizeof (*cu
));
14790 cu
->objfile
= objfile
;
14791 obstack_init (&cu
->comp_unit_obstack
);
14794 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
14797 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
14799 struct attribute
*attr
;
14801 /* Set the language we're debugging. */
14802 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
14804 set_cu_language (DW_UNSND (attr
), cu
);
14807 cu
->language
= language_minimal
;
14808 cu
->language_defn
= language_def (cu
->language
);
14812 /* Release one cached compilation unit, CU. We unlink it from the tree
14813 of compilation units, but we don't remove it from the read_in_chain;
14814 the caller is responsible for that.
14815 NOTE: DATA is a void * because this function is also used as a
14816 cleanup routine. */
14819 free_one_comp_unit (void *data
)
14821 struct dwarf2_cu
*cu
= data
;
14823 if (cu
->per_cu
!= NULL
)
14824 cu
->per_cu
->cu
= NULL
;
14827 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14832 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14833 when we're finished with it. We can't free the pointer itself, but be
14834 sure to unlink it from the cache. Also release any associated storage
14835 and perform cache maintenance.
14837 Only used during partial symbol parsing. */
14840 free_stack_comp_unit (void *data
)
14842 struct dwarf2_cu
*cu
= data
;
14844 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14845 cu
->partial_dies
= NULL
;
14847 if (cu
->per_cu
!= NULL
)
14849 /* This compilation unit is on the stack in our caller, so we
14850 should not xfree it. Just unlink it. */
14851 cu
->per_cu
->cu
= NULL
;
14854 /* If we had a per-cu pointer, then we may have other compilation
14855 units loaded, so age them now. */
14856 age_cached_comp_units ();
14860 /* Free all cached compilation units. */
14863 free_cached_comp_units (void *data
)
14865 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14867 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14868 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14869 while (per_cu
!= NULL
)
14871 struct dwarf2_per_cu_data
*next_cu
;
14873 next_cu
= per_cu
->cu
->read_in_chain
;
14875 free_one_comp_unit (per_cu
->cu
);
14876 *last_chain
= next_cu
;
14882 /* Increase the age counter on each cached compilation unit, and free
14883 any that are too old. */
14886 age_cached_comp_units (void)
14888 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14890 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
14891 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14892 while (per_cu
!= NULL
)
14894 per_cu
->cu
->last_used
++;
14895 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
14896 dwarf2_mark (per_cu
->cu
);
14897 per_cu
= per_cu
->cu
->read_in_chain
;
14900 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14901 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14902 while (per_cu
!= NULL
)
14904 struct dwarf2_per_cu_data
*next_cu
;
14906 next_cu
= per_cu
->cu
->read_in_chain
;
14908 if (!per_cu
->cu
->mark
)
14910 free_one_comp_unit (per_cu
->cu
);
14911 *last_chain
= next_cu
;
14914 last_chain
= &per_cu
->cu
->read_in_chain
;
14920 /* Remove a single compilation unit from the cache. */
14923 free_one_cached_comp_unit (void *target_cu
)
14925 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14927 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14928 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14929 while (per_cu
!= NULL
)
14931 struct dwarf2_per_cu_data
*next_cu
;
14933 next_cu
= per_cu
->cu
->read_in_chain
;
14935 if (per_cu
->cu
== target_cu
)
14937 free_one_comp_unit (per_cu
->cu
);
14938 *last_chain
= next_cu
;
14942 last_chain
= &per_cu
->cu
->read_in_chain
;
14948 /* Release all extra memory associated with OBJFILE. */
14951 dwarf2_free_objfile (struct objfile
*objfile
)
14953 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14955 if (dwarf2_per_objfile
== NULL
)
14958 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
14959 free_cached_comp_units (NULL
);
14961 if (dwarf2_per_objfile
->quick_file_names_table
)
14962 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
14964 /* Everything else should be on the objfile obstack. */
14967 /* A pair of DIE offset and GDB type pointer. We store these
14968 in a hash table separate from the DIEs, and preserve them
14969 when the DIEs are flushed out of cache. */
14971 struct dwarf2_offset_and_type
14973 unsigned int offset
;
14977 /* Hash function for a dwarf2_offset_and_type. */
14980 offset_and_type_hash (const void *item
)
14982 const struct dwarf2_offset_and_type
*ofs
= item
;
14984 return ofs
->offset
;
14987 /* Equality function for a dwarf2_offset_and_type. */
14990 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
14992 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
14993 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
14995 return ofs_lhs
->offset
== ofs_rhs
->offset
;
14998 /* Set the type associated with DIE to TYPE. Save it in CU's hash
14999 table if necessary. For convenience, return TYPE.
15001 The DIEs reading must have careful ordering to:
15002 * Not cause infite loops trying to read in DIEs as a prerequisite for
15003 reading current DIE.
15004 * Not trying to dereference contents of still incompletely read in types
15005 while reading in other DIEs.
15006 * Enable referencing still incompletely read in types just by a pointer to
15007 the type without accessing its fields.
15009 Therefore caller should follow these rules:
15010 * Try to fetch any prerequisite types we may need to build this DIE type
15011 before building the type and calling set_die_type.
15012 * After building type call set_die_type for current DIE as soon as
15013 possible before fetching more types to complete the current type.
15014 * Make the type as complete as possible before fetching more types. */
15016 static struct type
*
15017 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
15019 struct dwarf2_offset_and_type
**slot
, ofs
;
15020 struct objfile
*objfile
= cu
->objfile
;
15021 htab_t
*type_hash_ptr
;
15023 /* For Ada types, make sure that the gnat-specific data is always
15024 initialized (if not already set). There are a few types where
15025 we should not be doing so, because the type-specific area is
15026 already used to hold some other piece of info (eg: TYPE_CODE_FLT
15027 where the type-specific area is used to store the floatformat).
15028 But this is not a problem, because the gnat-specific information
15029 is actually not needed for these types. */
15030 if (need_gnat_info (cu
)
15031 && TYPE_CODE (type
) != TYPE_CODE_FUNC
15032 && TYPE_CODE (type
) != TYPE_CODE_FLT
15033 && !HAVE_GNAT_AUX_INFO (type
))
15034 INIT_GNAT_SPECIFIC (type
);
15036 if (cu
->per_cu
->from_debug_types
)
15037 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
15039 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
15041 if (*type_hash_ptr
== NULL
)
15044 = htab_create_alloc_ex (127,
15045 offset_and_type_hash
,
15046 offset_and_type_eq
,
15048 &objfile
->objfile_obstack
,
15049 hashtab_obstack_allocate
,
15050 dummy_obstack_deallocate
);
15053 ofs
.offset
= die
->offset
;
15055 slot
= (struct dwarf2_offset_and_type
**)
15056 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
15058 complaint (&symfile_complaints
,
15059 _("A problem internal to GDB: DIE 0x%x has type already set"),
15061 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
15066 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
15067 table, or return NULL if the die does not have a saved type. */
15069 static struct type
*
15070 get_die_type_at_offset (unsigned int offset
,
15071 struct dwarf2_per_cu_data
*per_cu
)
15073 struct dwarf2_offset_and_type
*slot
, ofs
;
15076 if (per_cu
->from_debug_types
)
15077 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
15079 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
15080 if (type_hash
== NULL
)
15083 ofs
.offset
= offset
;
15084 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
15091 /* Look up the type for DIE in the appropriate type_hash table,
15092 or return NULL if DIE does not have a saved type. */
15094 static struct type
*
15095 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15097 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
15100 /* Add a dependence relationship from CU to REF_PER_CU. */
15103 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
15104 struct dwarf2_per_cu_data
*ref_per_cu
)
15108 if (cu
->dependencies
== NULL
)
15110 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
15111 NULL
, &cu
->comp_unit_obstack
,
15112 hashtab_obstack_allocate
,
15113 dummy_obstack_deallocate
);
15115 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
15117 *slot
= ref_per_cu
;
15120 /* Subroutine of dwarf2_mark to pass to htab_traverse.
15121 Set the mark field in every compilation unit in the
15122 cache that we must keep because we are keeping CU. */
15125 dwarf2_mark_helper (void **slot
, void *data
)
15127 struct dwarf2_per_cu_data
*per_cu
;
15129 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
15130 if (per_cu
->cu
->mark
)
15132 per_cu
->cu
->mark
= 1;
15134 if (per_cu
->cu
->dependencies
!= NULL
)
15135 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15140 /* Set the mark field in CU and in every other compilation unit in the
15141 cache that we must keep because we are keeping CU. */
15144 dwarf2_mark (struct dwarf2_cu
*cu
)
15149 if (cu
->dependencies
!= NULL
)
15150 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15154 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
15158 per_cu
->cu
->mark
= 0;
15159 per_cu
= per_cu
->cu
->read_in_chain
;
15163 /* Trivial hash function for partial_die_info: the hash value of a DIE
15164 is its offset in .debug_info for this objfile. */
15167 partial_die_hash (const void *item
)
15169 const struct partial_die_info
*part_die
= item
;
15171 return part_die
->offset
;
15174 /* Trivial comparison function for partial_die_info structures: two DIEs
15175 are equal if they have the same offset. */
15178 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
15180 const struct partial_die_info
*part_die_lhs
= item_lhs
;
15181 const struct partial_die_info
*part_die_rhs
= item_rhs
;
15183 return part_die_lhs
->offset
== part_die_rhs
->offset
;
15186 static struct cmd_list_element
*set_dwarf2_cmdlist
;
15187 static struct cmd_list_element
*show_dwarf2_cmdlist
;
15190 set_dwarf2_cmd (char *args
, int from_tty
)
15192 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
15196 show_dwarf2_cmd (char *args
, int from_tty
)
15198 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
15201 /* If section described by INFO was mmapped, munmap it now. */
15204 munmap_section_buffer (struct dwarf2_section_info
*info
)
15206 if (info
->was_mmapped
)
15209 intptr_t begin
= (intptr_t) info
->buffer
;
15210 intptr_t map_begin
= begin
& ~(pagesize
- 1);
15211 size_t map_length
= info
->size
+ begin
- map_begin
;
15213 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
15215 /* Without HAVE_MMAP, we should never be here to begin with. */
15216 gdb_assert_not_reached ("no mmap support");
15221 /* munmap debug sections for OBJFILE, if necessary. */
15224 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
15226 struct dwarf2_per_objfile
*data
= d
;
15228 /* This is sorted according to the order they're defined in to make it easier
15229 to keep in sync. */
15230 munmap_section_buffer (&data
->info
);
15231 munmap_section_buffer (&data
->abbrev
);
15232 munmap_section_buffer (&data
->line
);
15233 munmap_section_buffer (&data
->loc
);
15234 munmap_section_buffer (&data
->macinfo
);
15235 munmap_section_buffer (&data
->str
);
15236 munmap_section_buffer (&data
->ranges
);
15237 munmap_section_buffer (&data
->types
);
15238 munmap_section_buffer (&data
->frame
);
15239 munmap_section_buffer (&data
->eh_frame
);
15240 munmap_section_buffer (&data
->gdb_index
);
15244 /* The "save gdb-index" command. */
15246 /* The contents of the hash table we create when building the string
15248 struct strtab_entry
15250 offset_type offset
;
15254 /* Hash function for a strtab_entry. */
15257 hash_strtab_entry (const void *e
)
15259 const struct strtab_entry
*entry
= e
;
15260 return mapped_index_string_hash (entry
->str
);
15263 /* Equality function for a strtab_entry. */
15266 eq_strtab_entry (const void *a
, const void *b
)
15268 const struct strtab_entry
*ea
= a
;
15269 const struct strtab_entry
*eb
= b
;
15270 return !strcmp (ea
->str
, eb
->str
);
15273 /* Create a strtab_entry hash table. */
15276 create_strtab (void)
15278 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
15279 xfree
, xcalloc
, xfree
);
15282 /* Add a string to the constant pool. Return the string's offset in
15286 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
15289 struct strtab_entry entry
;
15290 struct strtab_entry
*result
;
15293 slot
= htab_find_slot (table
, &entry
, INSERT
);
15298 result
= XNEW (struct strtab_entry
);
15299 result
->offset
= obstack_object_size (cpool
);
15301 obstack_grow_str0 (cpool
, str
);
15304 return result
->offset
;
15307 /* An entry in the symbol table. */
15308 struct symtab_index_entry
15310 /* The name of the symbol. */
15312 /* The offset of the name in the constant pool. */
15313 offset_type index_offset
;
15314 /* A sorted vector of the indices of all the CUs that hold an object
15316 VEC (offset_type
) *cu_indices
;
15319 /* The symbol table. This is a power-of-2-sized hash table. */
15320 struct mapped_symtab
15322 offset_type n_elements
;
15324 struct symtab_index_entry
**data
;
15327 /* Hash function for a symtab_index_entry. */
15330 hash_symtab_entry (const void *e
)
15332 const struct symtab_index_entry
*entry
= e
;
15333 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
15334 sizeof (offset_type
) * VEC_length (offset_type
,
15335 entry
->cu_indices
),
15339 /* Equality function for a symtab_index_entry. */
15342 eq_symtab_entry (const void *a
, const void *b
)
15344 const struct symtab_index_entry
*ea
= a
;
15345 const struct symtab_index_entry
*eb
= b
;
15346 int len
= VEC_length (offset_type
, ea
->cu_indices
);
15347 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
15349 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
15350 VEC_address (offset_type
, eb
->cu_indices
),
15351 sizeof (offset_type
) * len
);
15354 /* Destroy a symtab_index_entry. */
15357 delete_symtab_entry (void *p
)
15359 struct symtab_index_entry
*entry
= p
;
15360 VEC_free (offset_type
, entry
->cu_indices
);
15364 /* Create a hash table holding symtab_index_entry objects. */
15367 create_symbol_hash_table (void)
15369 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
15370 delete_symtab_entry
, xcalloc
, xfree
);
15373 /* Create a new mapped symtab object. */
15375 static struct mapped_symtab
*
15376 create_mapped_symtab (void)
15378 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
15379 symtab
->n_elements
= 0;
15380 symtab
->size
= 1024;
15381 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15385 /* Destroy a mapped_symtab. */
15388 cleanup_mapped_symtab (void *p
)
15390 struct mapped_symtab
*symtab
= p
;
15391 /* The contents of the array are freed when the other hash table is
15393 xfree (symtab
->data
);
15397 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
15400 static struct symtab_index_entry
**
15401 find_slot (struct mapped_symtab
*symtab
, const char *name
)
15403 offset_type index
, step
, hash
= mapped_index_string_hash (name
);
15405 index
= hash
& (symtab
->size
- 1);
15406 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
15410 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
15411 return &symtab
->data
[index
];
15412 index
= (index
+ step
) & (symtab
->size
- 1);
15416 /* Expand SYMTAB's hash table. */
15419 hash_expand (struct mapped_symtab
*symtab
)
15421 offset_type old_size
= symtab
->size
;
15423 struct symtab_index_entry
**old_entries
= symtab
->data
;
15426 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15428 for (i
= 0; i
< old_size
; ++i
)
15430 if (old_entries
[i
])
15432 struct symtab_index_entry
**slot
= find_slot (symtab
,
15433 old_entries
[i
]->name
);
15434 *slot
= old_entries
[i
];
15438 xfree (old_entries
);
15441 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
15442 is the index of the CU in which the symbol appears. */
15445 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
15446 offset_type cu_index
)
15448 struct symtab_index_entry
**slot
;
15450 ++symtab
->n_elements
;
15451 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
15452 hash_expand (symtab
);
15454 slot
= find_slot (symtab
, name
);
15457 *slot
= XNEW (struct symtab_index_entry
);
15458 (*slot
)->name
= name
;
15459 (*slot
)->cu_indices
= NULL
;
15461 /* Don't push an index twice. Due to how we add entries we only
15462 have to check the last one. */
15463 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
15464 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
15465 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
15468 /* Add a vector of indices to the constant pool. */
15471 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
15472 struct symtab_index_entry
*entry
)
15476 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
15479 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
15480 offset_type val
= MAYBE_SWAP (len
);
15485 entry
->index_offset
= obstack_object_size (cpool
);
15487 obstack_grow (cpool
, &val
, sizeof (val
));
15489 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
15492 val
= MAYBE_SWAP (iter
);
15493 obstack_grow (cpool
, &val
, sizeof (val
));
15498 struct symtab_index_entry
*old_entry
= *slot
;
15499 entry
->index_offset
= old_entry
->index_offset
;
15502 return entry
->index_offset
;
15505 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15506 constant pool entries going into the obstack CPOOL. */
15509 write_hash_table (struct mapped_symtab
*symtab
,
15510 struct obstack
*output
, struct obstack
*cpool
)
15513 htab_t symbol_hash_table
;
15516 symbol_hash_table
= create_symbol_hash_table ();
15517 str_table
= create_strtab ();
15519 /* We add all the index vectors to the constant pool first, to
15520 ensure alignment is ok. */
15521 for (i
= 0; i
< symtab
->size
; ++i
)
15523 if (symtab
->data
[i
])
15524 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
15527 /* Now write out the hash table. */
15528 for (i
= 0; i
< symtab
->size
; ++i
)
15530 offset_type str_off
, vec_off
;
15532 if (symtab
->data
[i
])
15534 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
15535 vec_off
= symtab
->data
[i
]->index_offset
;
15539 /* While 0 is a valid constant pool index, it is not valid
15540 to have 0 for both offsets. */
15545 str_off
= MAYBE_SWAP (str_off
);
15546 vec_off
= MAYBE_SWAP (vec_off
);
15548 obstack_grow (output
, &str_off
, sizeof (str_off
));
15549 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
15552 htab_delete (str_table
);
15553 htab_delete (symbol_hash_table
);
15556 /* Struct to map psymtab to CU index in the index file. */
15557 struct psymtab_cu_index_map
15559 struct partial_symtab
*psymtab
;
15560 unsigned int cu_index
;
15564 hash_psymtab_cu_index (const void *item
)
15566 const struct psymtab_cu_index_map
*map
= item
;
15568 return htab_hash_pointer (map
->psymtab
);
15572 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
15574 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
15575 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
15577 return lhs
->psymtab
== rhs
->psymtab
;
15580 /* Helper struct for building the address table. */
15581 struct addrmap_index_data
15583 struct objfile
*objfile
;
15584 struct obstack
*addr_obstack
;
15585 htab_t cu_index_htab
;
15587 /* Non-zero if the previous_* fields are valid.
15588 We can't write an entry until we see the next entry (since it is only then
15589 that we know the end of the entry). */
15590 int previous_valid
;
15591 /* Index of the CU in the table of all CUs in the index file. */
15592 unsigned int previous_cu_index
;
15593 /* Start address of the CU. */
15594 CORE_ADDR previous_cu_start
;
15597 /* Write an address entry to OBSTACK. */
15600 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
15601 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
15603 offset_type cu_index_to_write
;
15605 CORE_ADDR baseaddr
;
15607 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15609 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
15610 obstack_grow (obstack
, addr
, 8);
15611 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
15612 obstack_grow (obstack
, addr
, 8);
15613 cu_index_to_write
= MAYBE_SWAP (cu_index
);
15614 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
15617 /* Worker function for traversing an addrmap to build the address table. */
15620 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
15622 struct addrmap_index_data
*data
= datap
;
15623 struct partial_symtab
*pst
= obj
;
15624 offset_type cu_index
;
15627 if (data
->previous_valid
)
15628 add_address_entry (data
->objfile
, data
->addr_obstack
,
15629 data
->previous_cu_start
, start_addr
,
15630 data
->previous_cu_index
);
15632 data
->previous_cu_start
= start_addr
;
15635 struct psymtab_cu_index_map find_map
, *map
;
15636 find_map
.psymtab
= pst
;
15637 map
= htab_find (data
->cu_index_htab
, &find_map
);
15638 gdb_assert (map
!= NULL
);
15639 data
->previous_cu_index
= map
->cu_index
;
15640 data
->previous_valid
= 1;
15643 data
->previous_valid
= 0;
15648 /* Write OBJFILE's address map to OBSTACK.
15649 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
15650 in the index file. */
15653 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
15654 htab_t cu_index_htab
)
15656 struct addrmap_index_data addrmap_index_data
;
15658 /* When writing the address table, we have to cope with the fact that
15659 the addrmap iterator only provides the start of a region; we have to
15660 wait until the next invocation to get the start of the next region. */
15662 addrmap_index_data
.objfile
= objfile
;
15663 addrmap_index_data
.addr_obstack
= obstack
;
15664 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
15665 addrmap_index_data
.previous_valid
= 0;
15667 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
15668 &addrmap_index_data
);
15670 /* It's highly unlikely the last entry (end address = 0xff...ff)
15671 is valid, but we should still handle it.
15672 The end address is recorded as the start of the next region, but that
15673 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
15675 if (addrmap_index_data
.previous_valid
)
15676 add_address_entry (objfile
, obstack
,
15677 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
15678 addrmap_index_data
.previous_cu_index
);
15681 /* Add a list of partial symbols to SYMTAB. */
15684 write_psymbols (struct mapped_symtab
*symtab
,
15686 struct partial_symbol
**psymp
,
15688 offset_type cu_index
,
15691 for (; count
-- > 0; ++psymp
)
15693 void **slot
, *lookup
;
15695 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
15696 error (_("Ada is not currently supported by the index"));
15698 /* We only want to add a given psymbol once. However, we also
15699 want to account for whether it is global or static. So, we
15700 may add it twice, using slightly different values. */
15703 uintptr_t val
= 1 | (uintptr_t) *psymp
;
15705 lookup
= (void *) val
;
15710 /* Only add a given psymbol once. */
15711 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
15715 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
15720 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
15721 exception if there is an error. */
15724 write_obstack (FILE *file
, struct obstack
*obstack
)
15726 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
15728 != obstack_object_size (obstack
))
15729 error (_("couldn't data write to file"));
15732 /* Unlink a file if the argument is not NULL. */
15735 unlink_if_set (void *p
)
15737 char **filename
= p
;
15739 unlink (*filename
);
15742 /* A helper struct used when iterating over debug_types. */
15743 struct signatured_type_index_data
15745 struct objfile
*objfile
;
15746 struct mapped_symtab
*symtab
;
15747 struct obstack
*types_list
;
15752 /* A helper function that writes a single signatured_type to an
15756 write_one_signatured_type (void **slot
, void *d
)
15758 struct signatured_type_index_data
*info
= d
;
15759 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
15760 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
15761 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15764 write_psymbols (info
->symtab
,
15766 info
->objfile
->global_psymbols
.list
15767 + psymtab
->globals_offset
,
15768 psymtab
->n_global_syms
, info
->cu_index
,
15770 write_psymbols (info
->symtab
,
15772 info
->objfile
->static_psymbols
.list
15773 + psymtab
->statics_offset
,
15774 psymtab
->n_static_syms
, info
->cu_index
,
15777 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->offset
);
15778 obstack_grow (info
->types_list
, val
, 8);
15779 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
15780 obstack_grow (info
->types_list
, val
, 8);
15781 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
15782 obstack_grow (info
->types_list
, val
, 8);
15789 /* A cleanup function for an htab_t. */
15792 cleanup_htab (void *arg
)
15797 /* Create an index file for OBJFILE in the directory DIR. */
15800 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
15802 struct cleanup
*cleanup
;
15803 char *filename
, *cleanup_filename
;
15804 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
15805 struct obstack cu_list
, types_cu_list
;
15808 struct mapped_symtab
*symtab
;
15809 offset_type val
, size_of_contents
, total_len
;
15813 htab_t cu_index_htab
;
15814 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
15816 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
15819 if (dwarf2_per_objfile
->using_index
)
15820 error (_("Cannot use an index to create the index"));
15822 if (stat (objfile
->name
, &st
) < 0)
15823 perror_with_name (objfile
->name
);
15825 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
15826 INDEX_SUFFIX
, (char *) NULL
);
15827 cleanup
= make_cleanup (xfree
, filename
);
15829 out_file
= fopen (filename
, "wb");
15831 error (_("Can't open `%s' for writing"), filename
);
15833 cleanup_filename
= filename
;
15834 make_cleanup (unlink_if_set
, &cleanup_filename
);
15836 symtab
= create_mapped_symtab ();
15837 make_cleanup (cleanup_mapped_symtab
, symtab
);
15839 obstack_init (&addr_obstack
);
15840 make_cleanup_obstack_free (&addr_obstack
);
15842 obstack_init (&cu_list
);
15843 make_cleanup_obstack_free (&cu_list
);
15845 obstack_init (&types_cu_list
);
15846 make_cleanup_obstack_free (&types_cu_list
);
15848 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
15849 NULL
, xcalloc
, xfree
);
15850 make_cleanup (cleanup_htab
, psyms_seen
);
15852 /* While we're scanning CU's create a table that maps a psymtab pointer
15853 (which is what addrmap records) to its index (which is what is recorded
15854 in the index file). This will later be needed to write the address
15856 cu_index_htab
= htab_create_alloc (100,
15857 hash_psymtab_cu_index
,
15858 eq_psymtab_cu_index
,
15859 NULL
, xcalloc
, xfree
);
15860 make_cleanup (cleanup_htab
, cu_index_htab
);
15861 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
15862 xmalloc (sizeof (struct psymtab_cu_index_map
)
15863 * dwarf2_per_objfile
->n_comp_units
);
15864 make_cleanup (xfree
, psymtab_cu_index_map
);
15866 /* The CU list is already sorted, so we don't need to do additional
15867 work here. Also, the debug_types entries do not appear in
15868 all_comp_units, but only in their own hash table. */
15869 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
15871 struct dwarf2_per_cu_data
*per_cu
15872 = dwarf2_per_objfile
->all_comp_units
[i
];
15873 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15875 struct psymtab_cu_index_map
*map
;
15878 write_psymbols (symtab
,
15880 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15881 psymtab
->n_global_syms
, i
,
15883 write_psymbols (symtab
,
15885 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15886 psymtab
->n_static_syms
, i
,
15889 map
= &psymtab_cu_index_map
[i
];
15890 map
->psymtab
= psymtab
;
15892 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
15893 gdb_assert (slot
!= NULL
);
15894 gdb_assert (*slot
== NULL
);
15897 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
15898 obstack_grow (&cu_list
, val
, 8);
15899 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
15900 obstack_grow (&cu_list
, val
, 8);
15903 /* Dump the address map. */
15904 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
15906 /* Write out the .debug_type entries, if any. */
15907 if (dwarf2_per_objfile
->signatured_types
)
15909 struct signatured_type_index_data sig_data
;
15911 sig_data
.objfile
= objfile
;
15912 sig_data
.symtab
= symtab
;
15913 sig_data
.types_list
= &types_cu_list
;
15914 sig_data
.psyms_seen
= psyms_seen
;
15915 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
15916 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
15917 write_one_signatured_type
, &sig_data
);
15920 obstack_init (&constant_pool
);
15921 make_cleanup_obstack_free (&constant_pool
);
15922 obstack_init (&symtab_obstack
);
15923 make_cleanup_obstack_free (&symtab_obstack
);
15924 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
15926 obstack_init (&contents
);
15927 make_cleanup_obstack_free (&contents
);
15928 size_of_contents
= 6 * sizeof (offset_type
);
15929 total_len
= size_of_contents
;
15931 /* The version number. */
15932 val
= MAYBE_SWAP (4);
15933 obstack_grow (&contents
, &val
, sizeof (val
));
15935 /* The offset of the CU list from the start of the file. */
15936 val
= MAYBE_SWAP (total_len
);
15937 obstack_grow (&contents
, &val
, sizeof (val
));
15938 total_len
+= obstack_object_size (&cu_list
);
15940 /* The offset of the types CU list from the start of the file. */
15941 val
= MAYBE_SWAP (total_len
);
15942 obstack_grow (&contents
, &val
, sizeof (val
));
15943 total_len
+= obstack_object_size (&types_cu_list
);
15945 /* The offset of the address table from the start of the file. */
15946 val
= MAYBE_SWAP (total_len
);
15947 obstack_grow (&contents
, &val
, sizeof (val
));
15948 total_len
+= obstack_object_size (&addr_obstack
);
15950 /* The offset of the symbol table from the start of the file. */
15951 val
= MAYBE_SWAP (total_len
);
15952 obstack_grow (&contents
, &val
, sizeof (val
));
15953 total_len
+= obstack_object_size (&symtab_obstack
);
15955 /* The offset of the constant pool from the start of the file. */
15956 val
= MAYBE_SWAP (total_len
);
15957 obstack_grow (&contents
, &val
, sizeof (val
));
15958 total_len
+= obstack_object_size (&constant_pool
);
15960 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
15962 write_obstack (out_file
, &contents
);
15963 write_obstack (out_file
, &cu_list
);
15964 write_obstack (out_file
, &types_cu_list
);
15965 write_obstack (out_file
, &addr_obstack
);
15966 write_obstack (out_file
, &symtab_obstack
);
15967 write_obstack (out_file
, &constant_pool
);
15971 /* We want to keep the file, so we set cleanup_filename to NULL
15972 here. See unlink_if_set. */
15973 cleanup_filename
= NULL
;
15975 do_cleanups (cleanup
);
15978 /* Implementation of the `save gdb-index' command.
15980 Note that the file format used by this command is documented in the
15981 GDB manual. Any changes here must be documented there. */
15984 save_gdb_index_command (char *arg
, int from_tty
)
15986 struct objfile
*objfile
;
15989 error (_("usage: save gdb-index DIRECTORY"));
15991 ALL_OBJFILES (objfile
)
15995 /* If the objfile does not correspond to an actual file, skip it. */
15996 if (stat (objfile
->name
, &st
) < 0)
15999 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16000 if (dwarf2_per_objfile
)
16002 volatile struct gdb_exception except
;
16004 TRY_CATCH (except
, RETURN_MASK_ERROR
)
16006 write_psymtabs_to_index (objfile
, arg
);
16008 if (except
.reason
< 0)
16009 exception_fprintf (gdb_stderr
, except
,
16010 _("Error while writing index for `%s': "),
16018 int dwarf2_always_disassemble
;
16021 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
16022 struct cmd_list_element
*c
, const char *value
)
16024 fprintf_filtered (file
,
16025 _("Whether to always disassemble "
16026 "DWARF expressions is %s.\n"),
16030 void _initialize_dwarf2_read (void);
16033 _initialize_dwarf2_read (void)
16035 struct cmd_list_element
*c
;
16037 dwarf2_objfile_data_key
16038 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
16040 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
16041 Set DWARF 2 specific variables.\n\
16042 Configure DWARF 2 variables such as the cache size"),
16043 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
16044 0/*allow-unknown*/, &maintenance_set_cmdlist
);
16046 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
16047 Show DWARF 2 specific variables\n\
16048 Show DWARF 2 variables such as the cache size"),
16049 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
16050 0/*allow-unknown*/, &maintenance_show_cmdlist
);
16052 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
16053 &dwarf2_max_cache_age
, _("\
16054 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
16055 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
16056 A higher limit means that cached compilation units will be stored\n\
16057 in memory longer, and more total memory will be used. Zero disables\n\
16058 caching, which can slow down startup."),
16060 show_dwarf2_max_cache_age
,
16061 &set_dwarf2_cmdlist
,
16062 &show_dwarf2_cmdlist
);
16064 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
16065 &dwarf2_always_disassemble
, _("\
16066 Set whether `info address' always disassembles DWARF expressions."), _("\
16067 Show whether `info address' always disassembles DWARF expressions."), _("\
16068 When enabled, DWARF expressions are always printed in an assembly-like\n\
16069 syntax. When disabled, expressions will be printed in a more\n\
16070 conversational style, when possible."),
16072 show_dwarf2_always_disassemble
,
16073 &set_dwarf2_cmdlist
,
16074 &show_dwarf2_cmdlist
);
16076 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
16077 Set debugging of the dwarf2 DIE reader."), _("\
16078 Show debugging of the dwarf2 DIE reader."), _("\
16079 When enabled (non-zero), DIEs are dumped after they are read in.\n\
16080 The value is the maximum depth to print."),
16083 &setdebuglist
, &showdebuglist
);
16085 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
16087 Save a gdb-index file.\n\
16088 Usage: save gdb-index DIRECTORY"),
16090 set_cmd_completer (c
, filename_completer
);