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 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2591 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2594 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2595 struct quick_file_names
*file_data
;
2597 per_cu
->v
.quick
->mark
= 0;
2598 if (per_cu
->v
.quick
->symtab
)
2601 file_data
= dw2_get_file_names (objfile
, per_cu
);
2602 if (file_data
== NULL
)
2605 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2607 if (file_matcher (file_data
->file_names
[j
], data
))
2609 per_cu
->v
.quick
->mark
= 1;
2615 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2617 offset_type idx
= 2 * iter
;
2619 offset_type
*vec
, vec_len
, vec_idx
;
2621 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2624 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2626 if (! (*name_matcher
) (name
, data
))
2629 /* The name was matched, now expand corresponding CUs that were
2631 vec
= (offset_type
*) (index
->constant_pool
2632 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2633 vec_len
= MAYBE_SWAP (vec
[0]);
2634 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2636 struct dwarf2_per_cu_data
*per_cu
;
2638 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2639 if (per_cu
->v
.quick
->mark
)
2640 dw2_instantiate_symtab (objfile
, per_cu
);
2645 static struct symtab
*
2646 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2647 struct minimal_symbol
*msymbol
,
2649 struct obj_section
*section
,
2652 struct dwarf2_per_cu_data
*data
;
2654 dw2_setup (objfile
);
2656 if (!objfile
->psymtabs_addrmap
)
2659 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2663 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2664 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2665 paddress (get_objfile_arch (objfile
), pc
));
2667 return dw2_instantiate_symtab (objfile
, data
);
2671 dw2_map_symbol_names (struct objfile
*objfile
,
2672 void (*fun
) (const char *, void *),
2676 struct mapped_index
*index
;
2678 dw2_setup (objfile
);
2680 /* index_table is NULL if OBJF_READNOW. */
2681 if (!dwarf2_per_objfile
->index_table
)
2683 index
= dwarf2_per_objfile
->index_table
;
2685 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2687 offset_type idx
= 2 * iter
;
2689 offset_type
*vec
, vec_len
, vec_idx
;
2691 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2694 name
= (index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]));
2696 (*fun
) (name
, data
);
2701 dw2_map_symbol_filenames (struct objfile
*objfile
,
2702 void (*fun
) (const char *, const char *, void *),
2707 dw2_setup (objfile
);
2709 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2710 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2713 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2714 struct quick_file_names
*file_data
;
2716 if (per_cu
->v
.quick
->symtab
)
2719 file_data
= dw2_get_file_names (objfile
, per_cu
);
2720 if (file_data
== NULL
)
2723 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2725 const char *this_real_name
= dw2_get_real_path (objfile
, file_data
,
2727 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2733 dw2_has_symbols (struct objfile
*objfile
)
2738 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2741 dw2_find_last_source_symtab
,
2742 dw2_forget_cached_source_info
,
2745 dw2_pre_expand_symtabs_matching
,
2749 dw2_expand_symtabs_for_function
,
2750 dw2_expand_all_symtabs
,
2751 dw2_expand_symtabs_with_filename
,
2752 dw2_find_symbol_file
,
2753 dw2_map_matching_symbols
,
2754 dw2_expand_symtabs_matching
,
2755 dw2_find_pc_sect_symtab
,
2756 dw2_map_symbol_names
,
2757 dw2_map_symbol_filenames
2760 /* Initialize for reading DWARF for this objfile. Return 0 if this
2761 file will use psymtabs, or 1 if using the GNU index. */
2764 dwarf2_initialize_objfile (struct objfile
*objfile
)
2766 /* If we're about to read full symbols, don't bother with the
2767 indices. In this case we also don't care if some other debug
2768 format is making psymtabs, because they are all about to be
2770 if ((objfile
->flags
& OBJF_READNOW
))
2774 dwarf2_per_objfile
->using_index
= 1;
2775 create_all_comp_units (objfile
);
2776 create_debug_types_hash_table (objfile
);
2777 dwarf2_per_objfile
->quick_file_names_table
=
2778 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2780 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2781 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2783 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2785 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2786 struct dwarf2_per_cu_quick_data
);
2789 /* Return 1 so that gdb sees the "quick" functions. However,
2790 these functions will be no-ops because we will have expanded
2795 if (dwarf2_read_index (objfile
))
2803 /* Build a partial symbol table. */
2806 dwarf2_build_psymtabs (struct objfile
*objfile
)
2808 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2810 init_psymbol_list (objfile
, 1024);
2813 dwarf2_build_psymtabs_hard (objfile
);
2816 /* Return TRUE if OFFSET is within CU_HEADER. */
2819 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2821 unsigned int bottom
= cu_header
->offset
;
2822 unsigned int top
= (cu_header
->offset
2824 + cu_header
->initial_length_size
);
2826 return (offset
>= bottom
&& offset
< top
);
2829 /* Read in the comp unit header information from the debug_info at info_ptr.
2830 NOTE: This leaves members offset, first_die_offset to be filled in
2834 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2835 gdb_byte
*info_ptr
, bfd
*abfd
)
2838 unsigned int bytes_read
;
2840 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2841 cu_header
->initial_length_size
= bytes_read
;
2842 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2843 info_ptr
+= bytes_read
;
2844 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2846 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2848 info_ptr
+= bytes_read
;
2849 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2851 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2852 if (signed_addr
< 0)
2853 internal_error (__FILE__
, __LINE__
,
2854 _("read_comp_unit_head: dwarf from non elf file"));
2855 cu_header
->signed_addr_p
= signed_addr
;
2861 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2862 gdb_byte
*buffer
, unsigned int buffer_size
,
2865 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2867 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2869 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2870 error (_("Dwarf Error: wrong version in compilation unit header "
2871 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2872 bfd_get_filename (abfd
));
2874 if (header
->abbrev_offset
2875 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
2876 &dwarf2_per_objfile
->abbrev
))
2877 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2878 "(offset 0x%lx + 6) [in module %s]"),
2879 (long) header
->abbrev_offset
,
2880 (long) (beg_of_comp_unit
- buffer
),
2881 bfd_get_filename (abfd
));
2883 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2884 > buffer
+ buffer_size
)
2885 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2886 "(offset 0x%lx + 0) [in module %s]"),
2887 (long) header
->length
,
2888 (long) (beg_of_comp_unit
- buffer
),
2889 bfd_get_filename (abfd
));
2894 /* Read in the types comp unit header information from .debug_types entry at
2895 types_ptr. The result is a pointer to one past the end of the header. */
2898 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2899 ULONGEST
*signature
,
2900 gdb_byte
*types_ptr
, bfd
*abfd
)
2902 gdb_byte
*initial_types_ptr
= types_ptr
;
2904 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2905 &dwarf2_per_objfile
->types
);
2906 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2908 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2910 *signature
= read_8_bytes (abfd
, types_ptr
);
2912 types_ptr
+= cu_header
->offset_size
;
2913 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2918 /* Allocate a new partial symtab for file named NAME and mark this new
2919 partial symtab as being an include of PST. */
2922 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2923 struct objfile
*objfile
)
2925 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2927 subpst
->section_offsets
= pst
->section_offsets
;
2928 subpst
->textlow
= 0;
2929 subpst
->texthigh
= 0;
2931 subpst
->dependencies
= (struct partial_symtab
**)
2932 obstack_alloc (&objfile
->objfile_obstack
,
2933 sizeof (struct partial_symtab
*));
2934 subpst
->dependencies
[0] = pst
;
2935 subpst
->number_of_dependencies
= 1;
2937 subpst
->globals_offset
= 0;
2938 subpst
->n_global_syms
= 0;
2939 subpst
->statics_offset
= 0;
2940 subpst
->n_static_syms
= 0;
2941 subpst
->symtab
= NULL
;
2942 subpst
->read_symtab
= pst
->read_symtab
;
2945 /* No private part is necessary for include psymtabs. This property
2946 can be used to differentiate between such include psymtabs and
2947 the regular ones. */
2948 subpst
->read_symtab_private
= NULL
;
2951 /* Read the Line Number Program data and extract the list of files
2952 included by the source file represented by PST. Build an include
2953 partial symtab for each of these included files. */
2956 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2957 struct die_info
*die
,
2958 struct partial_symtab
*pst
)
2960 struct objfile
*objfile
= cu
->objfile
;
2961 bfd
*abfd
= objfile
->obfd
;
2962 struct line_header
*lh
= NULL
;
2963 struct attribute
*attr
;
2965 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2968 unsigned int line_offset
= DW_UNSND (attr
);
2970 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2973 return; /* No linetable, so no includes. */
2975 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2976 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
2978 free_line_header (lh
);
2982 hash_type_signature (const void *item
)
2984 const struct signatured_type
*type_sig
= item
;
2986 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2987 return type_sig
->signature
;
2991 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2993 const struct signatured_type
*lhs
= item_lhs
;
2994 const struct signatured_type
*rhs
= item_rhs
;
2996 return lhs
->signature
== rhs
->signature
;
2999 /* Allocate a hash table for signatured types. */
3002 allocate_signatured_type_table (struct objfile
*objfile
)
3004 return htab_create_alloc_ex (41,
3005 hash_type_signature
,
3008 &objfile
->objfile_obstack
,
3009 hashtab_obstack_allocate
,
3010 dummy_obstack_deallocate
);
3013 /* A helper function to add a signatured type CU to a list. */
3016 add_signatured_type_cu_to_list (void **slot
, void *datum
)
3018 struct signatured_type
*sigt
= *slot
;
3019 struct dwarf2_per_cu_data
***datap
= datum
;
3021 **datap
= &sigt
->per_cu
;
3027 /* Create the hash table of all entries in the .debug_types section.
3028 The result is zero if there is an error (e.g. missing .debug_types section),
3029 otherwise non-zero. */
3032 create_debug_types_hash_table (struct objfile
*objfile
)
3036 struct dwarf2_per_cu_data
**iter
;
3038 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
3039 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
3041 if (info_ptr
== NULL
)
3043 dwarf2_per_objfile
->signatured_types
= NULL
;
3047 types_htab
= allocate_signatured_type_table (objfile
);
3049 if (dwarf2_die_debug
)
3050 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3052 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
3053 + dwarf2_per_objfile
->types
.size
)
3055 unsigned int offset
;
3056 unsigned int offset_size
;
3057 unsigned int type_offset
;
3058 unsigned int length
, initial_length_size
;
3059 unsigned short version
;
3061 struct signatured_type
*type_sig
;
3063 gdb_byte
*ptr
= info_ptr
;
3065 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
3067 /* We need to read the type's signature in order to build the hash
3068 table, but we don't need to read anything else just yet. */
3070 /* Sanity check to ensure entire cu is present. */
3071 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
3072 if (ptr
+ length
+ initial_length_size
3073 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
3075 complaint (&symfile_complaints
,
3076 _("debug type entry runs off end "
3077 "of `.debug_types' section, ignored"));
3081 offset_size
= initial_length_size
== 4 ? 4 : 8;
3082 ptr
+= initial_length_size
;
3083 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3085 ptr
+= offset_size
; /* abbrev offset */
3086 ptr
+= 1; /* address size */
3087 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3089 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3091 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3092 memset (type_sig
, 0, sizeof (*type_sig
));
3093 type_sig
->signature
= signature
;
3094 type_sig
->offset
= offset
;
3095 type_sig
->type_offset
= type_offset
;
3096 type_sig
->per_cu
.objfile
= objfile
;
3097 type_sig
->per_cu
.from_debug_types
= 1;
3099 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3100 gdb_assert (slot
!= NULL
);
3103 if (dwarf2_die_debug
)
3104 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3105 offset
, phex (signature
, sizeof (signature
)));
3107 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3110 dwarf2_per_objfile
->signatured_types
= types_htab
;
3112 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3113 dwarf2_per_objfile
->type_comp_units
3114 = obstack_alloc (&objfile
->objfile_obstack
,
3115 dwarf2_per_objfile
->n_type_comp_units
3116 * sizeof (struct dwarf2_per_cu_data
*));
3117 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3118 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3119 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3120 == dwarf2_per_objfile
->n_type_comp_units
);
3125 /* Lookup a signature based type.
3126 Returns NULL if SIG is not present in the table. */
3128 static struct signatured_type
*
3129 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3131 struct signatured_type find_entry
, *entry
;
3133 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3135 complaint (&symfile_complaints
,
3136 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3140 find_entry
.signature
= sig
;
3141 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3145 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3148 init_cu_die_reader (struct die_reader_specs
*reader
,
3149 struct dwarf2_cu
*cu
)
3151 reader
->abfd
= cu
->objfile
->obfd
;
3153 if (cu
->per_cu
->from_debug_types
)
3155 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3156 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
3160 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3161 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3165 /* Find the base address of the compilation unit for range lists and
3166 location lists. It will normally be specified by DW_AT_low_pc.
3167 In DWARF-3 draft 4, the base address could be overridden by
3168 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3169 compilation units with discontinuous ranges. */
3172 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3174 struct attribute
*attr
;
3177 cu
->base_address
= 0;
3179 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3182 cu
->base_address
= DW_ADDR (attr
);
3187 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3190 cu
->base_address
= DW_ADDR (attr
);
3196 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3197 to combine the common parts.
3198 Process a compilation unit for a psymtab.
3199 BUFFER is a pointer to the beginning of the dwarf section buffer,
3200 either .debug_info or debug_types.
3201 INFO_PTR is a pointer to the start of the CU.
3202 Returns a pointer to the next CU. */
3205 process_psymtab_comp_unit (struct objfile
*objfile
,
3206 struct dwarf2_per_cu_data
*this_cu
,
3207 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3208 unsigned int buffer_size
)
3210 bfd
*abfd
= objfile
->obfd
;
3211 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3212 struct die_info
*comp_unit_die
;
3213 struct partial_symtab
*pst
;
3215 struct cleanup
*back_to_inner
;
3216 struct dwarf2_cu cu
;
3217 int has_children
, has_pc_info
;
3218 struct attribute
*attr
;
3219 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3220 struct die_reader_specs reader_specs
;
3221 const char *filename
;
3223 init_one_comp_unit (&cu
, objfile
);
3224 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3226 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3227 buffer
, buffer_size
,
3230 /* Complete the cu_header. */
3231 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3232 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3234 cu
.list_in_scope
= &file_symbols
;
3236 /* If this compilation unit was already read in, free the
3237 cached copy in order to read it in again. This is
3238 necessary because we skipped some symbols when we first
3239 read in the compilation unit (see load_partial_dies).
3240 This problem could be avoided, but the benefit is
3242 if (this_cu
->cu
!= NULL
)
3243 free_one_cached_comp_unit (this_cu
->cu
);
3245 /* Note that this is a pointer to our stack frame, being
3246 added to a global data structure. It will be cleaned up
3247 in free_stack_comp_unit when we finish with this
3248 compilation unit. */
3250 cu
.per_cu
= this_cu
;
3252 /* Read the abbrevs for this compilation unit into a table. */
3253 dwarf2_read_abbrevs (abfd
, &cu
);
3254 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3256 /* Read the compilation unit die. */
3257 if (this_cu
->from_debug_types
)
3258 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3259 init_cu_die_reader (&reader_specs
, &cu
);
3260 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3263 if (this_cu
->from_debug_types
)
3265 /* offset,length haven't been set yet for type units. */
3266 this_cu
->offset
= cu
.header
.offset
;
3267 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3269 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3271 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3272 + cu
.header
.initial_length_size
);
3273 do_cleanups (back_to_inner
);
3277 prepare_one_comp_unit (&cu
, comp_unit_die
);
3279 /* Allocate a new partial symbol table structure. */
3280 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3281 if (attr
== NULL
|| !DW_STRING (attr
))
3284 filename
= DW_STRING (attr
);
3285 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3287 /* TEXTLOW and TEXTHIGH are set below. */
3289 objfile
->global_psymbols
.next
,
3290 objfile
->static_psymbols
.next
);
3292 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3294 pst
->dirname
= DW_STRING (attr
);
3296 pst
->read_symtab_private
= this_cu
;
3298 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3300 /* Store the function that reads in the rest of the symbol table. */
3301 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3303 this_cu
->v
.psymtab
= pst
;
3305 dwarf2_find_base_address (comp_unit_die
, &cu
);
3307 /* Possibly set the default values of LOWPC and HIGHPC from
3309 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3310 &best_highpc
, &cu
, pst
);
3311 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3312 /* Store the contiguous range if it is not empty; it can be empty for
3313 CUs with no code. */
3314 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3315 best_lowpc
+ baseaddr
,
3316 best_highpc
+ baseaddr
- 1, pst
);
3318 /* Check if comp unit has_children.
3319 If so, read the rest of the partial symbols from this comp unit.
3320 If not, there's no more debug_info for this comp unit. */
3323 struct partial_die_info
*first_die
;
3324 CORE_ADDR lowpc
, highpc
;
3326 lowpc
= ((CORE_ADDR
) -1);
3327 highpc
= ((CORE_ADDR
) 0);
3329 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3331 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3332 ! has_pc_info
, &cu
);
3334 /* If we didn't find a lowpc, set it to highpc to avoid
3335 complaints from `maint check'. */
3336 if (lowpc
== ((CORE_ADDR
) -1))
3339 /* If the compilation unit didn't have an explicit address range,
3340 then use the information extracted from its child dies. */
3344 best_highpc
= highpc
;
3347 pst
->textlow
= best_lowpc
+ baseaddr
;
3348 pst
->texthigh
= best_highpc
+ baseaddr
;
3350 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3351 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3352 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3353 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3354 sort_pst_symbols (pst
);
3356 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3357 + cu
.header
.initial_length_size
);
3359 if (this_cu
->from_debug_types
)
3361 /* It's not clear we want to do anything with stmt lists here.
3362 Waiting to see what gcc ultimately does. */
3366 /* Get the list of files included in the current compilation unit,
3367 and build a psymtab for each of them. */
3368 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3371 do_cleanups (back_to_inner
);
3376 /* Traversal function for htab_traverse_noresize.
3377 Process one .debug_types comp-unit. */
3380 process_type_comp_unit (void **slot
, void *info
)
3382 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3383 struct objfile
*objfile
= (struct objfile
*) info
;
3384 struct dwarf2_per_cu_data
*this_cu
;
3386 this_cu
= &entry
->per_cu
;
3388 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3389 process_psymtab_comp_unit (objfile
, this_cu
,
3390 dwarf2_per_objfile
->types
.buffer
,
3391 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
3392 dwarf2_per_objfile
->types
.size
);
3397 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3398 Build partial symbol tables for the .debug_types comp-units. */
3401 build_type_psymtabs (struct objfile
*objfile
)
3403 if (! create_debug_types_hash_table (objfile
))
3406 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3407 process_type_comp_unit
, objfile
);
3410 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3413 psymtabs_addrmap_cleanup (void *o
)
3415 struct objfile
*objfile
= o
;
3417 objfile
->psymtabs_addrmap
= NULL
;
3420 /* Build the partial symbol table by doing a quick pass through the
3421 .debug_info and .debug_abbrev sections. */
3424 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3427 struct cleanup
*back_to
, *addrmap_cleanup
;
3428 struct obstack temp_obstack
;
3430 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3432 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3433 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3435 /* Any cached compilation units will be linked by the per-objfile
3436 read_in_chain. Make sure to free them when we're done. */
3437 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3439 build_type_psymtabs (objfile
);
3441 create_all_comp_units (objfile
);
3443 /* Create a temporary address map on a temporary obstack. We later
3444 copy this to the final obstack. */
3445 obstack_init (&temp_obstack
);
3446 make_cleanup_obstack_free (&temp_obstack
);
3447 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3448 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3450 /* Since the objects we're extracting from .debug_info vary in
3451 length, only the individual functions to extract them (like
3452 read_comp_unit_head and load_partial_die) can really know whether
3453 the buffer is large enough to hold another complete object.
3455 At the moment, they don't actually check that. If .debug_info
3456 holds just one extra byte after the last compilation unit's dies,
3457 then read_comp_unit_head will happily read off the end of the
3458 buffer. read_partial_die is similarly casual. Those functions
3461 For this loop condition, simply checking whether there's any data
3462 left at all should be sufficient. */
3464 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3465 + dwarf2_per_objfile
->info
.size
))
3467 struct dwarf2_per_cu_data
*this_cu
;
3469 this_cu
= dwarf2_find_comp_unit (info_ptr
3470 - dwarf2_per_objfile
->info
.buffer
,
3473 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3474 dwarf2_per_objfile
->info
.buffer
,
3476 dwarf2_per_objfile
->info
.size
);
3479 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3480 &objfile
->objfile_obstack
);
3481 discard_cleanups (addrmap_cleanup
);
3483 do_cleanups (back_to
);
3486 /* Load the partial DIEs for a secondary CU into memory. */
3489 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3490 struct objfile
*objfile
)
3492 bfd
*abfd
= objfile
->obfd
;
3493 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3494 struct die_info
*comp_unit_die
;
3495 struct dwarf2_cu
*cu
;
3496 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3498 struct die_reader_specs reader_specs
;
3501 gdb_assert (! this_cu
->from_debug_types
);
3503 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3504 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3505 beg_of_comp_unit
= info_ptr
;
3507 if (this_cu
->cu
== NULL
)
3509 cu
= xmalloc (sizeof (*cu
));
3510 init_one_comp_unit (cu
, objfile
);
3514 /* If an error occurs while loading, release our storage. */
3515 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3517 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3518 dwarf2_per_objfile
->info
.buffer
,
3519 dwarf2_per_objfile
->info
.size
,
3522 /* Complete the cu_header. */
3523 cu
->header
.offset
= this_cu
->offset
;
3524 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3526 /* Link this compilation unit into the compilation unit tree. */
3528 cu
->per_cu
= this_cu
;
3530 /* Link this CU into read_in_chain. */
3531 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3532 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3537 info_ptr
+= cu
->header
.first_die_offset
;
3540 /* Read the abbrevs for this compilation unit into a table. */
3541 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3542 dwarf2_read_abbrevs (abfd
, cu
);
3543 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3545 /* Read the compilation unit die. */
3546 init_cu_die_reader (&reader_specs
, cu
);
3547 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3550 prepare_one_comp_unit (cu
, comp_unit_die
);
3552 /* Check if comp unit has_children.
3553 If so, read the rest of the partial symbols from this comp unit.
3554 If not, there's no more debug_info for this comp unit. */
3556 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3558 do_cleanups (free_abbrevs_cleanup
);
3562 /* We've successfully allocated this compilation unit. Let our
3563 caller clean it up when finished with it. */
3564 discard_cleanups (free_cu_cleanup
);
3568 /* Create a list of all compilation units in OBJFILE. We do this only
3569 if an inter-comp-unit reference is found; presumably if there is one,
3570 there will be many, and one will occur early in the .debug_info section.
3571 So there's no point in building this list incrementally. */
3574 create_all_comp_units (struct objfile
*objfile
)
3578 struct dwarf2_per_cu_data
**all_comp_units
;
3581 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3582 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3586 all_comp_units
= xmalloc (n_allocated
3587 * sizeof (struct dwarf2_per_cu_data
*));
3589 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3590 + dwarf2_per_objfile
->info
.size
)
3592 unsigned int length
, initial_length_size
;
3593 struct dwarf2_per_cu_data
*this_cu
;
3594 unsigned int offset
;
3596 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3598 /* Read just enough information to find out where the next
3599 compilation unit is. */
3600 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3601 &initial_length_size
);
3603 /* Save the compilation unit for later lookup. */
3604 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3605 sizeof (struct dwarf2_per_cu_data
));
3606 memset (this_cu
, 0, sizeof (*this_cu
));
3607 this_cu
->offset
= offset
;
3608 this_cu
->length
= length
+ initial_length_size
;
3609 this_cu
->objfile
= objfile
;
3611 if (n_comp_units
== n_allocated
)
3614 all_comp_units
= xrealloc (all_comp_units
,
3616 * sizeof (struct dwarf2_per_cu_data
*));
3618 all_comp_units
[n_comp_units
++] = this_cu
;
3620 info_ptr
= info_ptr
+ this_cu
->length
;
3623 dwarf2_per_objfile
->all_comp_units
3624 = obstack_alloc (&objfile
->objfile_obstack
,
3625 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3626 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3627 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3628 xfree (all_comp_units
);
3629 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3632 /* Process all loaded DIEs for compilation unit CU, starting at
3633 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3634 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3635 DW_AT_ranges). If NEED_PC is set, then this function will set
3636 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3637 and record the covered ranges in the addrmap. */
3640 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3641 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3643 struct partial_die_info
*pdi
;
3645 /* Now, march along the PDI's, descending into ones which have
3646 interesting children but skipping the children of the other ones,
3647 until we reach the end of the compilation unit. */
3653 fixup_partial_die (pdi
, cu
);
3655 /* Anonymous namespaces or modules have no name but have interesting
3656 children, so we need to look at them. Ditto for anonymous
3659 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3660 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3664 case DW_TAG_subprogram
:
3665 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3667 case DW_TAG_constant
:
3668 case DW_TAG_variable
:
3669 case DW_TAG_typedef
:
3670 case DW_TAG_union_type
:
3671 if (!pdi
->is_declaration
)
3673 add_partial_symbol (pdi
, cu
);
3676 case DW_TAG_class_type
:
3677 case DW_TAG_interface_type
:
3678 case DW_TAG_structure_type
:
3679 if (!pdi
->is_declaration
)
3681 add_partial_symbol (pdi
, cu
);
3684 case DW_TAG_enumeration_type
:
3685 if (!pdi
->is_declaration
)
3686 add_partial_enumeration (pdi
, cu
);
3688 case DW_TAG_base_type
:
3689 case DW_TAG_subrange_type
:
3690 /* File scope base type definitions are added to the partial
3692 add_partial_symbol (pdi
, cu
);
3694 case DW_TAG_namespace
:
3695 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3698 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3705 /* If the die has a sibling, skip to the sibling. */
3707 pdi
= pdi
->die_sibling
;
3711 /* Functions used to compute the fully scoped name of a partial DIE.
3713 Normally, this is simple. For C++, the parent DIE's fully scoped
3714 name is concatenated with "::" and the partial DIE's name. For
3715 Java, the same thing occurs except that "." is used instead of "::".
3716 Enumerators are an exception; they use the scope of their parent
3717 enumeration type, i.e. the name of the enumeration type is not
3718 prepended to the enumerator.
3720 There are two complexities. One is DW_AT_specification; in this
3721 case "parent" means the parent of the target of the specification,
3722 instead of the direct parent of the DIE. The other is compilers
3723 which do not emit DW_TAG_namespace; in this case we try to guess
3724 the fully qualified name of structure types from their members'
3725 linkage names. This must be done using the DIE's children rather
3726 than the children of any DW_AT_specification target. We only need
3727 to do this for structures at the top level, i.e. if the target of
3728 any DW_AT_specification (if any; otherwise the DIE itself) does not
3731 /* Compute the scope prefix associated with PDI's parent, in
3732 compilation unit CU. The result will be allocated on CU's
3733 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3734 field. NULL is returned if no prefix is necessary. */
3736 partial_die_parent_scope (struct partial_die_info
*pdi
,
3737 struct dwarf2_cu
*cu
)
3739 char *grandparent_scope
;
3740 struct partial_die_info
*parent
, *real_pdi
;
3742 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3743 then this means the parent of the specification DIE. */
3746 while (real_pdi
->has_specification
)
3747 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3749 parent
= real_pdi
->die_parent
;
3753 if (parent
->scope_set
)
3754 return parent
->scope
;
3756 fixup_partial_die (parent
, cu
);
3758 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3760 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3761 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3762 Work around this problem here. */
3763 if (cu
->language
== language_cplus
3764 && parent
->tag
== DW_TAG_namespace
3765 && strcmp (parent
->name
, "::") == 0
3766 && grandparent_scope
== NULL
)
3768 parent
->scope
= NULL
;
3769 parent
->scope_set
= 1;
3773 if (parent
->tag
== DW_TAG_namespace
3774 || parent
->tag
== DW_TAG_module
3775 || parent
->tag
== DW_TAG_structure_type
3776 || parent
->tag
== DW_TAG_class_type
3777 || parent
->tag
== DW_TAG_interface_type
3778 || parent
->tag
== DW_TAG_union_type
3779 || parent
->tag
== DW_TAG_enumeration_type
)
3781 if (grandparent_scope
== NULL
)
3782 parent
->scope
= parent
->name
;
3784 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3786 parent
->name
, 0, cu
);
3788 else if (parent
->tag
== DW_TAG_enumerator
)
3789 /* Enumerators should not get the name of the enumeration as a prefix. */
3790 parent
->scope
= grandparent_scope
;
3793 /* FIXME drow/2004-04-01: What should we be doing with
3794 function-local names? For partial symbols, we should probably be
3796 complaint (&symfile_complaints
,
3797 _("unhandled containing DIE tag %d for DIE at %d"),
3798 parent
->tag
, pdi
->offset
);
3799 parent
->scope
= grandparent_scope
;
3802 parent
->scope_set
= 1;
3803 return parent
->scope
;
3806 /* Return the fully scoped name associated with PDI, from compilation unit
3807 CU. The result will be allocated with malloc. */
3809 partial_die_full_name (struct partial_die_info
*pdi
,
3810 struct dwarf2_cu
*cu
)
3814 /* If this is a template instantiation, we can not work out the
3815 template arguments from partial DIEs. So, unfortunately, we have
3816 to go through the full DIEs. At least any work we do building
3817 types here will be reused if full symbols are loaded later. */
3818 if (pdi
->has_template_arguments
)
3820 fixup_partial_die (pdi
, cu
);
3822 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3824 struct die_info
*die
;
3825 struct attribute attr
;
3826 struct dwarf2_cu
*ref_cu
= cu
;
3829 attr
.form
= DW_FORM_ref_addr
;
3830 attr
.u
.addr
= pdi
->offset
;
3831 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3833 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3837 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3838 if (parent_scope
== NULL
)
3841 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3845 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3847 struct objfile
*objfile
= cu
->objfile
;
3849 char *actual_name
= NULL
;
3850 const struct partial_symbol
*psym
= NULL
;
3852 int built_actual_name
= 0;
3854 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3856 actual_name
= partial_die_full_name (pdi
, cu
);
3858 built_actual_name
= 1;
3860 if (actual_name
== NULL
)
3861 actual_name
= pdi
->name
;
3865 case DW_TAG_subprogram
:
3866 if (pdi
->is_external
|| cu
->language
== language_ada
)
3868 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3869 of the global scope. But in Ada, we want to be able to access
3870 nested procedures globally. So all Ada subprograms are stored
3871 in the global scope. */
3872 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3873 mst_text, objfile); */
3874 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3876 VAR_DOMAIN
, LOC_BLOCK
,
3877 &objfile
->global_psymbols
,
3878 0, pdi
->lowpc
+ baseaddr
,
3879 cu
->language
, objfile
);
3883 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3884 mst_file_text, objfile); */
3885 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3887 VAR_DOMAIN
, LOC_BLOCK
,
3888 &objfile
->static_psymbols
,
3889 0, pdi
->lowpc
+ baseaddr
,
3890 cu
->language
, objfile
);
3893 case DW_TAG_constant
:
3895 struct psymbol_allocation_list
*list
;
3897 if (pdi
->is_external
)
3898 list
= &objfile
->global_psymbols
;
3900 list
= &objfile
->static_psymbols
;
3901 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3902 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
3903 list
, 0, 0, cu
->language
, objfile
);
3906 case DW_TAG_variable
:
3908 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3912 && !dwarf2_per_objfile
->has_section_at_zero
)
3914 /* A global or static variable may also have been stripped
3915 out by the linker if unused, in which case its address
3916 will be nullified; do not add such variables into partial
3917 symbol table then. */
3919 else if (pdi
->is_external
)
3922 Don't enter into the minimal symbol tables as there is
3923 a minimal symbol table entry from the ELF symbols already.
3924 Enter into partial symbol table if it has a location
3925 descriptor or a type.
3926 If the location descriptor is missing, new_symbol will create
3927 a LOC_UNRESOLVED symbol, the address of the variable will then
3928 be determined from the minimal symbol table whenever the variable
3930 The address for the partial symbol table entry is not
3931 used by GDB, but it comes in handy for debugging partial symbol
3934 if (pdi
->locdesc
|| pdi
->has_type
)
3935 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3937 VAR_DOMAIN
, LOC_STATIC
,
3938 &objfile
->global_psymbols
,
3940 cu
->language
, objfile
);
3944 /* Static Variable. Skip symbols without location descriptors. */
3945 if (pdi
->locdesc
== NULL
)
3947 if (built_actual_name
)
3948 xfree (actual_name
);
3951 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
3952 mst_file_data, objfile); */
3953 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3955 VAR_DOMAIN
, LOC_STATIC
,
3956 &objfile
->static_psymbols
,
3958 cu
->language
, objfile
);
3961 case DW_TAG_typedef
:
3962 case DW_TAG_base_type
:
3963 case DW_TAG_subrange_type
:
3964 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3966 VAR_DOMAIN
, LOC_TYPEDEF
,
3967 &objfile
->static_psymbols
,
3968 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3970 case DW_TAG_namespace
:
3971 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3973 VAR_DOMAIN
, LOC_TYPEDEF
,
3974 &objfile
->global_psymbols
,
3975 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3977 case DW_TAG_class_type
:
3978 case DW_TAG_interface_type
:
3979 case DW_TAG_structure_type
:
3980 case DW_TAG_union_type
:
3981 case DW_TAG_enumeration_type
:
3982 /* Skip external references. The DWARF standard says in the section
3983 about "Structure, Union, and Class Type Entries": "An incomplete
3984 structure, union or class type is represented by a structure,
3985 union or class entry that does not have a byte size attribute
3986 and that has a DW_AT_declaration attribute." */
3987 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3989 if (built_actual_name
)
3990 xfree (actual_name
);
3994 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3995 static vs. global. */
3996 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3998 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3999 (cu
->language
== language_cplus
4000 || cu
->language
== language_java
)
4001 ? &objfile
->global_psymbols
4002 : &objfile
->static_psymbols
,
4003 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4006 case DW_TAG_enumerator
:
4007 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4009 VAR_DOMAIN
, LOC_CONST
,
4010 (cu
->language
== language_cplus
4011 || cu
->language
== language_java
)
4012 ? &objfile
->global_psymbols
4013 : &objfile
->static_psymbols
,
4014 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4020 if (built_actual_name
)
4021 xfree (actual_name
);
4024 /* Read a partial die corresponding to a namespace; also, add a symbol
4025 corresponding to that namespace to the symbol table. NAMESPACE is
4026 the name of the enclosing namespace. */
4029 add_partial_namespace (struct partial_die_info
*pdi
,
4030 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4031 int need_pc
, struct dwarf2_cu
*cu
)
4033 /* Add a symbol for the namespace. */
4035 add_partial_symbol (pdi
, cu
);
4037 /* Now scan partial symbols in that namespace. */
4039 if (pdi
->has_children
)
4040 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4043 /* Read a partial die corresponding to a Fortran module. */
4046 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4047 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4049 /* Now scan partial symbols in that module. */
4051 if (pdi
->has_children
)
4052 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4055 /* Read a partial die corresponding to a subprogram and create a partial
4056 symbol for that subprogram. When the CU language allows it, this
4057 routine also defines a partial symbol for each nested subprogram
4058 that this subprogram contains.
4060 DIE my also be a lexical block, in which case we simply search
4061 recursively for suprograms defined inside that lexical block.
4062 Again, this is only performed when the CU language allows this
4063 type of definitions. */
4066 add_partial_subprogram (struct partial_die_info
*pdi
,
4067 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4068 int need_pc
, struct dwarf2_cu
*cu
)
4070 if (pdi
->tag
== DW_TAG_subprogram
)
4072 if (pdi
->has_pc_info
)
4074 if (pdi
->lowpc
< *lowpc
)
4075 *lowpc
= pdi
->lowpc
;
4076 if (pdi
->highpc
> *highpc
)
4077 *highpc
= pdi
->highpc
;
4081 struct objfile
*objfile
= cu
->objfile
;
4083 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4084 SECT_OFF_TEXT (objfile
));
4085 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4086 pdi
->lowpc
+ baseaddr
,
4087 pdi
->highpc
- 1 + baseaddr
,
4088 cu
->per_cu
->v
.psymtab
);
4090 if (!pdi
->is_declaration
)
4091 /* Ignore subprogram DIEs that do not have a name, they are
4092 illegal. Do not emit a complaint at this point, we will
4093 do so when we convert this psymtab into a symtab. */
4095 add_partial_symbol (pdi
, cu
);
4099 if (! pdi
->has_children
)
4102 if (cu
->language
== language_ada
)
4104 pdi
= pdi
->die_child
;
4107 fixup_partial_die (pdi
, cu
);
4108 if (pdi
->tag
== DW_TAG_subprogram
4109 || pdi
->tag
== DW_TAG_lexical_block
)
4110 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4111 pdi
= pdi
->die_sibling
;
4116 /* Read a partial die corresponding to an enumeration type. */
4119 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4120 struct dwarf2_cu
*cu
)
4122 struct partial_die_info
*pdi
;
4124 if (enum_pdi
->name
!= NULL
)
4125 add_partial_symbol (enum_pdi
, cu
);
4127 pdi
= enum_pdi
->die_child
;
4130 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4131 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4133 add_partial_symbol (pdi
, cu
);
4134 pdi
= pdi
->die_sibling
;
4138 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4139 Return the corresponding abbrev, or NULL if the number is zero (indicating
4140 an empty DIE). In either case *BYTES_READ will be set to the length of
4141 the initial number. */
4143 static struct abbrev_info
*
4144 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4145 struct dwarf2_cu
*cu
)
4147 bfd
*abfd
= cu
->objfile
->obfd
;
4148 unsigned int abbrev_number
;
4149 struct abbrev_info
*abbrev
;
4151 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4153 if (abbrev_number
== 0)
4156 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4159 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4160 abbrev_number
, bfd_get_filename (abfd
));
4166 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4167 Returns a pointer to the end of a series of DIEs, terminated by an empty
4168 DIE. Any children of the skipped DIEs will also be skipped. */
4171 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4173 struct abbrev_info
*abbrev
;
4174 unsigned int bytes_read
;
4178 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4180 return info_ptr
+ bytes_read
;
4182 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4186 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4187 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4188 abbrev corresponding to that skipped uleb128 should be passed in
4189 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4193 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4194 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4196 unsigned int bytes_read
;
4197 struct attribute attr
;
4198 bfd
*abfd
= cu
->objfile
->obfd
;
4199 unsigned int form
, i
;
4201 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4203 /* The only abbrev we care about is DW_AT_sibling. */
4204 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4206 read_attribute (&attr
, &abbrev
->attrs
[i
],
4207 abfd
, info_ptr
, cu
);
4208 if (attr
.form
== DW_FORM_ref_addr
)
4209 complaint (&symfile_complaints
,
4210 _("ignoring absolute DW_AT_sibling"));
4212 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4215 /* If it isn't DW_AT_sibling, skip this attribute. */
4216 form
= abbrev
->attrs
[i
].form
;
4220 case DW_FORM_ref_addr
:
4221 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4222 and later it is offset sized. */
4223 if (cu
->header
.version
== 2)
4224 info_ptr
+= cu
->header
.addr_size
;
4226 info_ptr
+= cu
->header
.offset_size
;
4229 info_ptr
+= cu
->header
.addr_size
;
4236 case DW_FORM_flag_present
:
4248 case DW_FORM_ref_sig8
:
4251 case DW_FORM_string
:
4252 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4253 info_ptr
+= bytes_read
;
4255 case DW_FORM_sec_offset
:
4257 info_ptr
+= cu
->header
.offset_size
;
4259 case DW_FORM_exprloc
:
4261 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4262 info_ptr
+= bytes_read
;
4264 case DW_FORM_block1
:
4265 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4267 case DW_FORM_block2
:
4268 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4270 case DW_FORM_block4
:
4271 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4275 case DW_FORM_ref_udata
:
4276 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4278 case DW_FORM_indirect
:
4279 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4280 info_ptr
+= bytes_read
;
4281 /* We need to continue parsing from here, so just go back to
4283 goto skip_attribute
;
4286 error (_("Dwarf Error: Cannot handle %s "
4287 "in DWARF reader [in module %s]"),
4288 dwarf_form_name (form
),
4289 bfd_get_filename (abfd
));
4293 if (abbrev
->has_children
)
4294 return skip_children (buffer
, info_ptr
, cu
);
4299 /* Locate ORIG_PDI's sibling.
4300 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4304 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4305 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4306 bfd
*abfd
, struct dwarf2_cu
*cu
)
4308 /* Do we know the sibling already? */
4310 if (orig_pdi
->sibling
)
4311 return orig_pdi
->sibling
;
4313 /* Are there any children to deal with? */
4315 if (!orig_pdi
->has_children
)
4318 /* Skip the children the long way. */
4320 return skip_children (buffer
, info_ptr
, cu
);
4323 /* Expand this partial symbol table into a full symbol table. */
4326 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4332 warning (_("bug: psymtab for %s is already read in."),
4339 printf_filtered (_("Reading in symbols for %s..."),
4341 gdb_flush (gdb_stdout
);
4344 /* Restore our global data. */
4345 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4346 dwarf2_objfile_data_key
);
4348 /* If this psymtab is constructed from a debug-only objfile, the
4349 has_section_at_zero flag will not necessarily be correct. We
4350 can get the correct value for this flag by looking at the data
4351 associated with the (presumably stripped) associated objfile. */
4352 if (pst
->objfile
->separate_debug_objfile_backlink
)
4354 struct dwarf2_per_objfile
*dpo_backlink
4355 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4356 dwarf2_objfile_data_key
);
4358 dwarf2_per_objfile
->has_section_at_zero
4359 = dpo_backlink
->has_section_at_zero
;
4362 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4364 psymtab_to_symtab_1 (pst
);
4366 /* Finish up the debug error message. */
4368 printf_filtered (_("done.\n"));
4373 /* Add PER_CU to the queue. */
4376 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4378 struct dwarf2_queue_item
*item
;
4381 item
= xmalloc (sizeof (*item
));
4382 item
->per_cu
= per_cu
;
4385 if (dwarf2_queue
== NULL
)
4386 dwarf2_queue
= item
;
4388 dwarf2_queue_tail
->next
= item
;
4390 dwarf2_queue_tail
= item
;
4393 /* Process the queue. */
4396 process_queue (struct objfile
*objfile
)
4398 struct dwarf2_queue_item
*item
, *next_item
;
4400 /* The queue starts out with one item, but following a DIE reference
4401 may load a new CU, adding it to the end of the queue. */
4402 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4404 if (dwarf2_per_objfile
->using_index
4405 ? !item
->per_cu
->v
.quick
->symtab
4406 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4407 process_full_comp_unit (item
->per_cu
);
4409 item
->per_cu
->queued
= 0;
4410 next_item
= item
->next
;
4414 dwarf2_queue_tail
= NULL
;
4417 /* Free all allocated queue entries. This function only releases anything if
4418 an error was thrown; if the queue was processed then it would have been
4419 freed as we went along. */
4422 dwarf2_release_queue (void *dummy
)
4424 struct dwarf2_queue_item
*item
, *last
;
4426 item
= dwarf2_queue
;
4429 /* Anything still marked queued is likely to be in an
4430 inconsistent state, so discard it. */
4431 if (item
->per_cu
->queued
)
4433 if (item
->per_cu
->cu
!= NULL
)
4434 free_one_cached_comp_unit (item
->per_cu
->cu
);
4435 item
->per_cu
->queued
= 0;
4443 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4446 /* Read in full symbols for PST, and anything it depends on. */
4449 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4451 struct dwarf2_per_cu_data
*per_cu
;
4452 struct cleanup
*back_to
;
4455 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4456 if (!pst
->dependencies
[i
]->readin
)
4458 /* Inform about additional files that need to be read in. */
4461 /* FIXME: i18n: Need to make this a single string. */
4462 fputs_filtered (" ", gdb_stdout
);
4464 fputs_filtered ("and ", gdb_stdout
);
4466 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4467 wrap_here (""); /* Flush output. */
4468 gdb_flush (gdb_stdout
);
4470 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4473 per_cu
= pst
->read_symtab_private
;
4477 /* It's an include file, no symbols to read for it.
4478 Everything is in the parent symtab. */
4483 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4486 /* Load the DIEs associated with PER_CU into memory. */
4489 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
4490 struct objfile
*objfile
)
4492 bfd
*abfd
= objfile
->obfd
;
4493 struct dwarf2_cu
*cu
;
4494 unsigned int offset
;
4495 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4496 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4497 struct attribute
*attr
;
4500 gdb_assert (! per_cu
->from_debug_types
);
4502 /* Set local variables from the partial symbol table info. */
4503 offset
= per_cu
->offset
;
4505 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4506 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4507 beg_of_comp_unit
= info_ptr
;
4509 if (per_cu
->cu
== NULL
)
4511 cu
= xmalloc (sizeof (*cu
));
4512 init_one_comp_unit (cu
, objfile
);
4516 /* If an error occurs while loading, release our storage. */
4517 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4519 /* Read in the comp_unit header. */
4520 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4522 /* Complete the cu_header. */
4523 cu
->header
.offset
= offset
;
4524 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4526 /* Read the abbrevs for this compilation unit. */
4527 dwarf2_read_abbrevs (abfd
, cu
);
4528 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4530 /* Link this compilation unit into the compilation unit tree. */
4532 cu
->per_cu
= per_cu
;
4534 /* Link this CU into read_in_chain. */
4535 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4536 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4541 info_ptr
+= cu
->header
.first_die_offset
;
4544 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4546 /* We try not to read any attributes in this function, because not
4547 all objfiles needed for references have been loaded yet, and symbol
4548 table processing isn't initialized. But we have to set the CU language,
4549 or we won't be able to build types correctly. */
4550 prepare_one_comp_unit (cu
, cu
->dies
);
4552 /* Similarly, if we do not read the producer, we can not apply
4553 producer-specific interpretation. */
4554 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4556 cu
->producer
= DW_STRING (attr
);
4560 do_cleanups (free_abbrevs_cleanup
);
4562 /* We've successfully allocated this compilation unit. Let our
4563 caller clean it up when finished with it. */
4564 discard_cleanups (free_cu_cleanup
);
4568 /* Add a DIE to the delayed physname list. */
4571 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4572 const char *name
, struct die_info
*die
,
4573 struct dwarf2_cu
*cu
)
4575 struct delayed_method_info mi
;
4577 mi
.fnfield_index
= fnfield_index
;
4581 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4584 /* A cleanup for freeing the delayed method list. */
4587 free_delayed_list (void *ptr
)
4589 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4590 if (cu
->method_list
!= NULL
)
4592 VEC_free (delayed_method_info
, cu
->method_list
);
4593 cu
->method_list
= NULL
;
4597 /* Compute the physnames of any methods on the CU's method list.
4599 The computation of method physnames is delayed in order to avoid the
4600 (bad) condition that one of the method's formal parameters is of an as yet
4604 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4607 struct delayed_method_info
*mi
;
4608 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4611 struct fn_fieldlist
*fn_flp
4612 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4613 physname
= (char *) dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4614 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4618 /* Generate full symbol information for PST and CU, whose DIEs have
4619 already been loaded into memory. */
4622 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4624 struct dwarf2_cu
*cu
= per_cu
->cu
;
4625 struct objfile
*objfile
= per_cu
->objfile
;
4626 CORE_ADDR lowpc
, highpc
;
4627 struct symtab
*symtab
;
4628 struct cleanup
*back_to
, *delayed_list_cleanup
;
4631 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4634 back_to
= make_cleanup (really_free_pendings
, NULL
);
4635 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4637 cu
->list_in_scope
= &file_symbols
;
4639 dwarf2_find_base_address (cu
->dies
, cu
);
4641 /* Do line number decoding in read_file_scope () */
4642 process_die (cu
->dies
, cu
);
4644 /* Now that we have processed all the DIEs in the CU, all the types
4645 should be complete, and it should now be safe to compute all of the
4647 compute_delayed_physnames (cu
);
4648 do_cleanups (delayed_list_cleanup
);
4650 /* Some compilers don't define a DW_AT_high_pc attribute for the
4651 compilation unit. If the DW_AT_high_pc is missing, synthesize
4652 it, by scanning the DIE's below the compilation unit. */
4653 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4655 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4657 /* Set symtab language to language from DW_AT_language.
4658 If the compilation is from a C file generated by language preprocessors,
4659 do not set the language if it was already deduced by start_subfile. */
4661 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4663 symtab
->language
= cu
->language
;
4666 if (dwarf2_per_objfile
->using_index
)
4667 per_cu
->v
.quick
->symtab
= symtab
;
4670 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4671 pst
->symtab
= symtab
;
4675 do_cleanups (back_to
);
4678 /* Process a die and its children. */
4681 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4685 case DW_TAG_padding
:
4687 case DW_TAG_compile_unit
:
4688 read_file_scope (die
, cu
);
4690 case DW_TAG_type_unit
:
4691 read_type_unit_scope (die
, cu
);
4693 case DW_TAG_subprogram
:
4694 case DW_TAG_inlined_subroutine
:
4695 read_func_scope (die
, cu
);
4697 case DW_TAG_lexical_block
:
4698 case DW_TAG_try_block
:
4699 case DW_TAG_catch_block
:
4700 read_lexical_block_scope (die
, cu
);
4702 case DW_TAG_class_type
:
4703 case DW_TAG_interface_type
:
4704 case DW_TAG_structure_type
:
4705 case DW_TAG_union_type
:
4706 process_structure_scope (die
, cu
);
4708 case DW_TAG_enumeration_type
:
4709 process_enumeration_scope (die
, cu
);
4712 /* These dies have a type, but processing them does not create
4713 a symbol or recurse to process the children. Therefore we can
4714 read them on-demand through read_type_die. */
4715 case DW_TAG_subroutine_type
:
4716 case DW_TAG_set_type
:
4717 case DW_TAG_array_type
:
4718 case DW_TAG_pointer_type
:
4719 case DW_TAG_ptr_to_member_type
:
4720 case DW_TAG_reference_type
:
4721 case DW_TAG_string_type
:
4724 case DW_TAG_base_type
:
4725 case DW_TAG_subrange_type
:
4726 case DW_TAG_typedef
:
4727 /* Add a typedef symbol for the type definition, if it has a
4729 new_symbol (die
, read_type_die (die
, cu
), cu
);
4731 case DW_TAG_common_block
:
4732 read_common_block (die
, cu
);
4734 case DW_TAG_common_inclusion
:
4736 case DW_TAG_namespace
:
4737 processing_has_namespace_info
= 1;
4738 read_namespace (die
, cu
);
4741 processing_has_namespace_info
= 1;
4742 read_module (die
, cu
);
4744 case DW_TAG_imported_declaration
:
4745 case DW_TAG_imported_module
:
4746 processing_has_namespace_info
= 1;
4747 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4748 || cu
->language
!= language_fortran
))
4749 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4750 dwarf_tag_name (die
->tag
));
4751 read_import_statement (die
, cu
);
4754 new_symbol (die
, NULL
, cu
);
4759 /* A helper function for dwarf2_compute_name which determines whether DIE
4760 needs to have the name of the scope prepended to the name listed in the
4764 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4766 struct attribute
*attr
;
4770 case DW_TAG_namespace
:
4771 case DW_TAG_typedef
:
4772 case DW_TAG_class_type
:
4773 case DW_TAG_interface_type
:
4774 case DW_TAG_structure_type
:
4775 case DW_TAG_union_type
:
4776 case DW_TAG_enumeration_type
:
4777 case DW_TAG_enumerator
:
4778 case DW_TAG_subprogram
:
4782 case DW_TAG_variable
:
4783 case DW_TAG_constant
:
4784 /* We only need to prefix "globally" visible variables. These include
4785 any variable marked with DW_AT_external or any variable that
4786 lives in a namespace. [Variables in anonymous namespaces
4787 require prefixing, but they are not DW_AT_external.] */
4789 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4791 struct dwarf2_cu
*spec_cu
= cu
;
4793 return die_needs_namespace (die_specification (die
, &spec_cu
),
4797 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4798 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4799 && die
->parent
->tag
!= DW_TAG_module
)
4801 /* A variable in a lexical block of some kind does not need a
4802 namespace, even though in C++ such variables may be external
4803 and have a mangled name. */
4804 if (die
->parent
->tag
== DW_TAG_lexical_block
4805 || die
->parent
->tag
== DW_TAG_try_block
4806 || die
->parent
->tag
== DW_TAG_catch_block
4807 || die
->parent
->tag
== DW_TAG_subprogram
)
4816 /* Retrieve the last character from a mem_file. */
4819 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4821 char *last_char_p
= (char *) object
;
4824 *last_char_p
= buffer
[length
- 1];
4827 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4828 compute the physname for the object, which include a method's
4829 formal parameters (C++/Java) and return type (Java).
4831 For Ada, return the DIE's linkage name rather than the fully qualified
4832 name. PHYSNAME is ignored..
4834 The result is allocated on the objfile_obstack and canonicalized. */
4837 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4841 name
= dwarf2_name (die
, cu
);
4843 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4844 compute it by typename_concat inside GDB. */
4845 if (cu
->language
== language_ada
4846 || (cu
->language
== language_fortran
&& physname
))
4848 /* For Ada unit, we prefer the linkage name over the name, as
4849 the former contains the exported name, which the user expects
4850 to be able to reference. Ideally, we want the user to be able
4851 to reference this entity using either natural or linkage name,
4852 but we haven't started looking at this enhancement yet. */
4853 struct attribute
*attr
;
4855 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4857 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4858 if (attr
&& DW_STRING (attr
))
4859 return DW_STRING (attr
);
4862 /* These are the only languages we know how to qualify names in. */
4864 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4865 || cu
->language
== language_fortran
))
4867 if (die_needs_namespace (die
, cu
))
4871 struct ui_file
*buf
;
4873 prefix
= determine_prefix (die
, cu
);
4874 buf
= mem_fileopen ();
4875 if (*prefix
!= '\0')
4877 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4880 fputs_unfiltered (prefixed_name
, buf
);
4881 xfree (prefixed_name
);
4884 fputs_unfiltered (name
, buf
);
4886 /* Template parameters may be specified in the DIE's DW_AT_name, or
4887 as children with DW_TAG_template_type_param or
4888 DW_TAG_value_type_param. If the latter, add them to the name
4889 here. If the name already has template parameters, then
4890 skip this step; some versions of GCC emit both, and
4891 it is more efficient to use the pre-computed name.
4893 Something to keep in mind about this process: it is very
4894 unlikely, or in some cases downright impossible, to produce
4895 something that will match the mangled name of a function.
4896 If the definition of the function has the same debug info,
4897 we should be able to match up with it anyway. But fallbacks
4898 using the minimal symbol, for instance to find a method
4899 implemented in a stripped copy of libstdc++, will not work.
4900 If we do not have debug info for the definition, we will have to
4901 match them up some other way.
4903 When we do name matching there is a related problem with function
4904 templates; two instantiated function templates are allowed to
4905 differ only by their return types, which we do not add here. */
4907 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
4909 struct attribute
*attr
;
4910 struct die_info
*child
;
4913 die
->building_fullname
= 1;
4915 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
4920 struct dwarf2_locexpr_baton
*baton
;
4923 if (child
->tag
!= DW_TAG_template_type_param
4924 && child
->tag
!= DW_TAG_template_value_param
)
4929 fputs_unfiltered ("<", buf
);
4933 fputs_unfiltered (", ", buf
);
4935 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
4938 complaint (&symfile_complaints
,
4939 _("template parameter missing DW_AT_type"));
4940 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
4943 type
= die_type (child
, cu
);
4945 if (child
->tag
== DW_TAG_template_type_param
)
4947 c_print_type (type
, "", buf
, -1, 0);
4951 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
4954 complaint (&symfile_complaints
,
4955 _("template parameter missing "
4956 "DW_AT_const_value"));
4957 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
4961 dwarf2_const_value_attr (attr
, type
, name
,
4962 &cu
->comp_unit_obstack
, cu
,
4963 &value
, &bytes
, &baton
);
4965 if (TYPE_NOSIGN (type
))
4966 /* GDB prints characters as NUMBER 'CHAR'. If that's
4967 changed, this can use value_print instead. */
4968 c_printchar (value
, type
, buf
);
4971 struct value_print_options opts
;
4974 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
4978 else if (bytes
!= NULL
)
4980 v
= allocate_value (type
);
4981 memcpy (value_contents_writeable (v
), bytes
,
4982 TYPE_LENGTH (type
));
4985 v
= value_from_longest (type
, value
);
4987 /* Specify decimal so that we do not depend on
4989 get_formatted_print_options (&opts
, 'd');
4991 value_print (v
, buf
, &opts
);
4997 die
->building_fullname
= 0;
5001 /* Close the argument list, with a space if necessary
5002 (nested templates). */
5003 char last_char
= '\0';
5004 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5005 if (last_char
== '>')
5006 fputs_unfiltered (" >", buf
);
5008 fputs_unfiltered (">", buf
);
5012 /* For Java and C++ methods, append formal parameter type
5013 information, if PHYSNAME. */
5015 if (physname
&& die
->tag
== DW_TAG_subprogram
5016 && (cu
->language
== language_cplus
5017 || cu
->language
== language_java
))
5019 struct type
*type
= read_type_die (die
, cu
);
5021 c_type_print_args (type
, buf
, 1, cu
->language
);
5023 if (cu
->language
== language_java
)
5025 /* For java, we must append the return type to method
5027 if (die
->tag
== DW_TAG_subprogram
)
5028 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5031 else if (cu
->language
== language_cplus
)
5033 /* Assume that an artificial first parameter is
5034 "this", but do not crash if it is not. RealView
5035 marks unnamed (and thus unused) parameters as
5036 artificial; there is no way to differentiate
5038 if (TYPE_NFIELDS (type
) > 0
5039 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5040 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5041 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5043 fputs_unfiltered (" const", buf
);
5047 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
5049 ui_file_delete (buf
);
5051 if (cu
->language
== language_cplus
)
5054 = dwarf2_canonicalize_name (name
, cu
,
5055 &cu
->objfile
->objfile_obstack
);
5066 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5067 If scope qualifiers are appropriate they will be added. The result
5068 will be allocated on the objfile_obstack, or NULL if the DIE does
5069 not have a name. NAME may either be from a previous call to
5070 dwarf2_name or NULL.
5072 The output string will be canonicalized (if C++/Java). */
5075 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5077 return dwarf2_compute_name (name
, die
, cu
, 0);
5080 /* Construct a physname for the given DIE in CU. NAME may either be
5081 from a previous call to dwarf2_name or NULL. The result will be
5082 allocated on the objfile_objstack or NULL if the DIE does not have a
5085 The output string will be canonicalized (if C++/Java). */
5088 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5090 return dwarf2_compute_name (name
, die
, cu
, 1);
5093 /* Read the import statement specified by the given die and record it. */
5096 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5098 struct attribute
*import_attr
;
5099 struct die_info
*imported_die
;
5100 struct dwarf2_cu
*imported_cu
;
5101 const char *imported_name
;
5102 const char *imported_name_prefix
;
5103 const char *canonical_name
;
5104 const char *import_alias
;
5105 const char *imported_declaration
= NULL
;
5106 const char *import_prefix
;
5110 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5111 if (import_attr
== NULL
)
5113 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5114 dwarf_tag_name (die
->tag
));
5119 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5120 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5121 if (imported_name
== NULL
)
5123 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5125 The import in the following code:
5139 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5140 <52> DW_AT_decl_file : 1
5141 <53> DW_AT_decl_line : 6
5142 <54> DW_AT_import : <0x75>
5143 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5145 <5b> DW_AT_decl_file : 1
5146 <5c> DW_AT_decl_line : 2
5147 <5d> DW_AT_type : <0x6e>
5149 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5150 <76> DW_AT_byte_size : 4
5151 <77> DW_AT_encoding : 5 (signed)
5153 imports the wrong die ( 0x75 instead of 0x58 ).
5154 This case will be ignored until the gcc bug is fixed. */
5158 /* Figure out the local name after import. */
5159 import_alias
= dwarf2_name (die
, cu
);
5161 /* Figure out where the statement is being imported to. */
5162 import_prefix
= determine_prefix (die
, cu
);
5164 /* Figure out what the scope of the imported die is and prepend it
5165 to the name of the imported die. */
5166 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5168 if (imported_die
->tag
!= DW_TAG_namespace
5169 && imported_die
->tag
!= DW_TAG_module
)
5171 imported_declaration
= imported_name
;
5172 canonical_name
= imported_name_prefix
;
5174 else if (strlen (imported_name_prefix
) > 0)
5176 temp
= alloca (strlen (imported_name_prefix
)
5177 + 2 + strlen (imported_name
) + 1);
5178 strcpy (temp
, imported_name_prefix
);
5179 strcat (temp
, "::");
5180 strcat (temp
, imported_name
);
5181 canonical_name
= temp
;
5184 canonical_name
= imported_name
;
5186 cp_add_using_directive (import_prefix
,
5189 imported_declaration
,
5190 &cu
->objfile
->objfile_obstack
);
5194 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5196 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5199 /* Cleanup function for read_file_scope. */
5202 free_cu_line_header (void *arg
)
5204 struct dwarf2_cu
*cu
= arg
;
5206 free_line_header (cu
->line_header
);
5207 cu
->line_header
= NULL
;
5211 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5212 char **name
, char **comp_dir
)
5214 struct attribute
*attr
;
5219 /* Find the filename. Do not use dwarf2_name here, since the filename
5220 is not a source language identifier. */
5221 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5224 *name
= DW_STRING (attr
);
5227 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5229 *comp_dir
= DW_STRING (attr
);
5230 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5232 *comp_dir
= ldirname (*name
);
5233 if (*comp_dir
!= NULL
)
5234 make_cleanup (xfree
, *comp_dir
);
5236 if (*comp_dir
!= NULL
)
5238 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5239 directory, get rid of it. */
5240 char *cp
= strchr (*comp_dir
, ':');
5242 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5247 *name
= "<unknown>";
5250 /* Process DW_TAG_compile_unit. */
5253 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5255 struct objfile
*objfile
= cu
->objfile
;
5256 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5257 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5258 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5259 struct attribute
*attr
;
5261 char *comp_dir
= NULL
;
5262 struct die_info
*child_die
;
5263 bfd
*abfd
= objfile
->obfd
;
5264 struct line_header
*line_header
= 0;
5267 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5269 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5271 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5272 from finish_block. */
5273 if (lowpc
== ((CORE_ADDR
) -1))
5278 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5280 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5283 set_cu_language (DW_UNSND (attr
), cu
);
5286 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5288 cu
->producer
= DW_STRING (attr
);
5290 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5291 standardised yet. As a workaround for the language detection we fall
5292 back to the DW_AT_producer string. */
5293 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5294 cu
->language
= language_opencl
;
5296 /* We assume that we're processing GCC output. */
5297 processing_gcc_compilation
= 2;
5299 processing_has_namespace_info
= 0;
5301 start_symtab (name
, comp_dir
, lowpc
);
5302 record_debugformat ("DWARF 2");
5303 record_producer (cu
->producer
);
5305 initialize_cu_func_list (cu
);
5307 /* Decode line number information if present. We do this before
5308 processing child DIEs, so that the line header table is available
5309 for DW_AT_decl_file. */
5310 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5313 unsigned int line_offset
= DW_UNSND (attr
);
5314 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5317 cu
->line_header
= line_header
;
5318 make_cleanup (free_cu_line_header
, cu
);
5319 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5323 /* Process all dies in compilation unit. */
5324 if (die
->child
!= NULL
)
5326 child_die
= die
->child
;
5327 while (child_die
&& child_die
->tag
)
5329 process_die (child_die
, cu
);
5330 child_die
= sibling_die (child_die
);
5334 /* Decode macro information, if present. Dwarf 2 macro information
5335 refers to information in the line number info statement program
5336 header, so we can only read it if we've read the header
5338 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5339 if (attr
&& line_header
)
5341 unsigned int macro_offset
= DW_UNSND (attr
);
5343 dwarf_decode_macros (line_header
, macro_offset
,
5344 comp_dir
, abfd
, cu
);
5346 do_cleanups (back_to
);
5349 /* Process DW_TAG_type_unit.
5350 For TUs we want to skip the first top level sibling if it's not the
5351 actual type being defined by this TU. In this case the first top
5352 level sibling is there to provide context only. */
5355 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5357 struct objfile
*objfile
= cu
->objfile
;
5358 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5360 struct attribute
*attr
;
5362 char *comp_dir
= NULL
;
5363 struct die_info
*child_die
;
5364 bfd
*abfd
= objfile
->obfd
;
5366 /* start_symtab needs a low pc, but we don't really have one.
5367 Do what read_file_scope would do in the absence of such info. */
5368 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5370 /* Find the filename. Do not use dwarf2_name here, since the filename
5371 is not a source language identifier. */
5372 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5374 name
= DW_STRING (attr
);
5376 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5378 comp_dir
= DW_STRING (attr
);
5379 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5381 comp_dir
= ldirname (name
);
5382 if (comp_dir
!= NULL
)
5383 make_cleanup (xfree
, comp_dir
);
5389 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5391 set_cu_language (DW_UNSND (attr
), cu
);
5393 /* This isn't technically needed today. It is done for symmetry
5394 with read_file_scope. */
5395 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5397 cu
->producer
= DW_STRING (attr
);
5399 /* We assume that we're processing GCC output. */
5400 processing_gcc_compilation
= 2;
5402 processing_has_namespace_info
= 0;
5404 start_symtab (name
, comp_dir
, lowpc
);
5405 record_debugformat ("DWARF 2");
5406 record_producer (cu
->producer
);
5408 /* Process the dies in the type unit. */
5409 if (die
->child
== NULL
)
5411 dump_die_for_error (die
);
5412 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5413 bfd_get_filename (abfd
));
5416 child_die
= die
->child
;
5418 while (child_die
&& child_die
->tag
)
5420 process_die (child_die
, cu
);
5422 child_die
= sibling_die (child_die
);
5425 do_cleanups (back_to
);
5429 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5430 struct dwarf2_cu
*cu
)
5432 struct function_range
*thisfn
;
5434 thisfn
= (struct function_range
*)
5435 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5436 thisfn
->name
= name
;
5437 thisfn
->lowpc
= lowpc
;
5438 thisfn
->highpc
= highpc
;
5439 thisfn
->seen_line
= 0;
5440 thisfn
->next
= NULL
;
5442 if (cu
->last_fn
== NULL
)
5443 cu
->first_fn
= thisfn
;
5445 cu
->last_fn
->next
= thisfn
;
5447 cu
->last_fn
= thisfn
;
5450 /* qsort helper for inherit_abstract_dies. */
5453 unsigned_int_compar (const void *ap
, const void *bp
)
5455 unsigned int a
= *(unsigned int *) ap
;
5456 unsigned int b
= *(unsigned int *) bp
;
5458 return (a
> b
) - (b
> a
);
5461 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5462 Inherit only the children of the DW_AT_abstract_origin DIE not being
5463 already referenced by DW_AT_abstract_origin from the children of the
5467 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5469 struct die_info
*child_die
;
5470 unsigned die_children_count
;
5471 /* CU offsets which were referenced by children of the current DIE. */
5473 unsigned *offsets_end
, *offsetp
;
5474 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5475 struct die_info
*origin_die
;
5476 /* Iterator of the ORIGIN_DIE children. */
5477 struct die_info
*origin_child_die
;
5478 struct cleanup
*cleanups
;
5479 struct attribute
*attr
;
5480 struct dwarf2_cu
*origin_cu
;
5481 struct pending
**origin_previous_list_in_scope
;
5483 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5487 /* Note that following die references may follow to a die in a
5491 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5493 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5495 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5496 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5498 if (die
->tag
!= origin_die
->tag
5499 && !(die
->tag
== DW_TAG_inlined_subroutine
5500 && origin_die
->tag
== DW_TAG_subprogram
))
5501 complaint (&symfile_complaints
,
5502 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5503 die
->offset
, origin_die
->offset
);
5505 child_die
= die
->child
;
5506 die_children_count
= 0;
5507 while (child_die
&& child_die
->tag
)
5509 child_die
= sibling_die (child_die
);
5510 die_children_count
++;
5512 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5513 cleanups
= make_cleanup (xfree
, offsets
);
5515 offsets_end
= offsets
;
5516 child_die
= die
->child
;
5517 while (child_die
&& child_die
->tag
)
5519 /* For each CHILD_DIE, find the corresponding child of
5520 ORIGIN_DIE. If there is more than one layer of
5521 DW_AT_abstract_origin, follow them all; there shouldn't be,
5522 but GCC versions at least through 4.4 generate this (GCC PR
5524 struct die_info
*child_origin_die
= child_die
;
5525 struct dwarf2_cu
*child_origin_cu
= cu
;
5529 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5533 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5537 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5538 counterpart may exist. */
5539 if (child_origin_die
!= child_die
)
5541 if (child_die
->tag
!= child_origin_die
->tag
5542 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5543 && child_origin_die
->tag
== DW_TAG_subprogram
))
5544 complaint (&symfile_complaints
,
5545 _("Child DIE 0x%x and its abstract origin 0x%x have "
5546 "different tags"), child_die
->offset
,
5547 child_origin_die
->offset
);
5548 if (child_origin_die
->parent
!= origin_die
)
5549 complaint (&symfile_complaints
,
5550 _("Child DIE 0x%x and its abstract origin 0x%x have "
5551 "different parents"), child_die
->offset
,
5552 child_origin_die
->offset
);
5554 *offsets_end
++ = child_origin_die
->offset
;
5556 child_die
= sibling_die (child_die
);
5558 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5559 unsigned_int_compar
);
5560 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5561 if (offsetp
[-1] == *offsetp
)
5562 complaint (&symfile_complaints
,
5563 _("Multiple children of DIE 0x%x refer "
5564 "to DIE 0x%x as their abstract origin"),
5565 die
->offset
, *offsetp
);
5568 origin_child_die
= origin_die
->child
;
5569 while (origin_child_die
&& origin_child_die
->tag
)
5571 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5572 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5574 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5576 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5577 process_die (origin_child_die
, origin_cu
);
5579 origin_child_die
= sibling_die (origin_child_die
);
5581 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5583 do_cleanups (cleanups
);
5587 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5589 struct objfile
*objfile
= cu
->objfile
;
5590 struct context_stack
*new;
5593 struct die_info
*child_die
;
5594 struct attribute
*attr
, *call_line
, *call_file
;
5597 struct block
*block
;
5598 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5599 VEC (symbolp
) *template_args
= NULL
;
5600 struct template_symbol
*templ_func
= NULL
;
5604 /* If we do not have call site information, we can't show the
5605 caller of this inlined function. That's too confusing, so
5606 only use the scope for local variables. */
5607 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5608 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5609 if (call_line
== NULL
|| call_file
== NULL
)
5611 read_lexical_block_scope (die
, cu
);
5616 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5618 name
= dwarf2_name (die
, cu
);
5620 /* Ignore functions with missing or empty names. These are actually
5621 illegal according to the DWARF standard. */
5624 complaint (&symfile_complaints
,
5625 _("missing name for subprogram DIE at %d"), die
->offset
);
5629 /* Ignore functions with missing or invalid low and high pc attributes. */
5630 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5632 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5633 if (!attr
|| !DW_UNSND (attr
))
5634 complaint (&symfile_complaints
,
5635 _("cannot get low and high bounds "
5636 "for subprogram DIE at %d"),
5644 /* Record the function range for dwarf_decode_lines. */
5645 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5647 /* If we have any template arguments, then we must allocate a
5648 different sort of symbol. */
5649 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5651 if (child_die
->tag
== DW_TAG_template_type_param
5652 || child_die
->tag
== DW_TAG_template_value_param
)
5654 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5655 struct template_symbol
);
5656 templ_func
->base
.is_cplus_template_function
= 1;
5661 new = push_context (0, lowpc
);
5662 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5663 (struct symbol
*) templ_func
);
5665 /* If there is a location expression for DW_AT_frame_base, record
5667 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5669 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5670 expression is being recorded directly in the function's symbol
5671 and not in a separate frame-base object. I guess this hack is
5672 to avoid adding some sort of frame-base adjunct/annex to the
5673 function's symbol :-(. The problem with doing this is that it
5674 results in a function symbol with a location expression that
5675 has nothing to do with the location of the function, ouch! The
5676 relationship should be: a function's symbol has-a frame base; a
5677 frame-base has-a location expression. */
5678 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5680 cu
->list_in_scope
= &local_symbols
;
5682 if (die
->child
!= NULL
)
5684 child_die
= die
->child
;
5685 while (child_die
&& child_die
->tag
)
5687 if (child_die
->tag
== DW_TAG_template_type_param
5688 || child_die
->tag
== DW_TAG_template_value_param
)
5690 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5693 VEC_safe_push (symbolp
, template_args
, arg
);
5696 process_die (child_die
, cu
);
5697 child_die
= sibling_die (child_die
);
5701 inherit_abstract_dies (die
, cu
);
5703 /* If we have a DW_AT_specification, we might need to import using
5704 directives from the context of the specification DIE. See the
5705 comment in determine_prefix. */
5706 if (cu
->language
== language_cplus
5707 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5709 struct dwarf2_cu
*spec_cu
= cu
;
5710 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5714 child_die
= spec_die
->child
;
5715 while (child_die
&& child_die
->tag
)
5717 if (child_die
->tag
== DW_TAG_imported_module
)
5718 process_die (child_die
, spec_cu
);
5719 child_die
= sibling_die (child_die
);
5722 /* In some cases, GCC generates specification DIEs that
5723 themselves contain DW_AT_specification attributes. */
5724 spec_die
= die_specification (spec_die
, &spec_cu
);
5728 new = pop_context ();
5729 /* Make a block for the local symbols within. */
5730 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5731 lowpc
, highpc
, objfile
);
5733 /* For C++, set the block's scope. */
5734 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5735 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5736 determine_prefix (die
, cu
),
5737 processing_has_namespace_info
);
5739 /* If we have address ranges, record them. */
5740 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5742 /* Attach template arguments to function. */
5743 if (! VEC_empty (symbolp
, template_args
))
5745 gdb_assert (templ_func
!= NULL
);
5747 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5748 templ_func
->template_arguments
5749 = obstack_alloc (&objfile
->objfile_obstack
,
5750 (templ_func
->n_template_arguments
5751 * sizeof (struct symbol
*)));
5752 memcpy (templ_func
->template_arguments
,
5753 VEC_address (symbolp
, template_args
),
5754 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5755 VEC_free (symbolp
, template_args
);
5758 /* In C++, we can have functions nested inside functions (e.g., when
5759 a function declares a class that has methods). This means that
5760 when we finish processing a function scope, we may need to go
5761 back to building a containing block's symbol lists. */
5762 local_symbols
= new->locals
;
5763 param_symbols
= new->params
;
5764 using_directives
= new->using_directives
;
5766 /* If we've finished processing a top-level function, subsequent
5767 symbols go in the file symbol list. */
5768 if (outermost_context_p ())
5769 cu
->list_in_scope
= &file_symbols
;
5772 /* Process all the DIES contained within a lexical block scope. Start
5773 a new scope, process the dies, and then close the scope. */
5776 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5778 struct objfile
*objfile
= cu
->objfile
;
5779 struct context_stack
*new;
5780 CORE_ADDR lowpc
, highpc
;
5781 struct die_info
*child_die
;
5784 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5786 /* Ignore blocks with missing or invalid low and high pc attributes. */
5787 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5788 as multiple lexical blocks? Handling children in a sane way would
5789 be nasty. Might be easier to properly extend generic blocks to
5791 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5796 push_context (0, lowpc
);
5797 if (die
->child
!= NULL
)
5799 child_die
= die
->child
;
5800 while (child_die
&& child_die
->tag
)
5802 process_die (child_die
, cu
);
5803 child_die
= sibling_die (child_die
);
5806 new = pop_context ();
5808 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5811 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5814 /* Note that recording ranges after traversing children, as we
5815 do here, means that recording a parent's ranges entails
5816 walking across all its children's ranges as they appear in
5817 the address map, which is quadratic behavior.
5819 It would be nicer to record the parent's ranges before
5820 traversing its children, simply overriding whatever you find
5821 there. But since we don't even decide whether to create a
5822 block until after we've traversed its children, that's hard
5824 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5826 local_symbols
= new->locals
;
5827 using_directives
= new->using_directives
;
5830 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5831 Return 1 if the attributes are present and valid, otherwise, return 0.
5832 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5835 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5836 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5837 struct partial_symtab
*ranges_pst
)
5839 struct objfile
*objfile
= cu
->objfile
;
5840 struct comp_unit_head
*cu_header
= &cu
->header
;
5841 bfd
*obfd
= objfile
->obfd
;
5842 unsigned int addr_size
= cu_header
->addr_size
;
5843 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5844 /* Base address selection entry. */
5855 found_base
= cu
->base_known
;
5856 base
= cu
->base_address
;
5858 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5859 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5861 complaint (&symfile_complaints
,
5862 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5866 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5868 /* Read in the largest possible address. */
5869 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5870 if ((marker
& mask
) == mask
)
5872 /* If we found the largest possible address, then
5873 read the base address. */
5874 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5875 buffer
+= 2 * addr_size
;
5876 offset
+= 2 * addr_size
;
5882 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5886 CORE_ADDR range_beginning
, range_end
;
5888 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5889 buffer
+= addr_size
;
5890 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5891 buffer
+= addr_size
;
5892 offset
+= 2 * addr_size
;
5894 /* An end of list marker is a pair of zero addresses. */
5895 if (range_beginning
== 0 && range_end
== 0)
5896 /* Found the end of list entry. */
5899 /* Each base address selection entry is a pair of 2 values.
5900 The first is the largest possible address, the second is
5901 the base address. Check for a base address here. */
5902 if ((range_beginning
& mask
) == mask
)
5904 /* If we found the largest possible address, then
5905 read the base address. */
5906 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5913 /* We have no valid base address for the ranges
5915 complaint (&symfile_complaints
,
5916 _("Invalid .debug_ranges data (no base address)"));
5920 if (range_beginning
> range_end
)
5922 /* Inverted range entries are invalid. */
5923 complaint (&symfile_complaints
,
5924 _("Invalid .debug_ranges data (inverted range)"));
5928 /* Empty range entries have no effect. */
5929 if (range_beginning
== range_end
)
5932 range_beginning
+= base
;
5935 if (ranges_pst
!= NULL
)
5936 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5937 range_beginning
+ baseaddr
,
5938 range_end
- 1 + baseaddr
,
5941 /* FIXME: This is recording everything as a low-high
5942 segment of consecutive addresses. We should have a
5943 data structure for discontiguous block ranges
5947 low
= range_beginning
;
5953 if (range_beginning
< low
)
5954 low
= range_beginning
;
5955 if (range_end
> high
)
5961 /* If the first entry is an end-of-list marker, the range
5962 describes an empty scope, i.e. no instructions. */
5968 *high_return
= high
;
5972 /* Get low and high pc attributes from a die. Return 1 if the attributes
5973 are present and valid, otherwise, return 0. Return -1 if the range is
5974 discontinuous, i.e. derived from DW_AT_ranges information. */
5976 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5977 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5978 struct partial_symtab
*pst
)
5980 struct attribute
*attr
;
5985 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5988 high
= DW_ADDR (attr
);
5989 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5991 low
= DW_ADDR (attr
);
5993 /* Found high w/o low attribute. */
5996 /* Found consecutive range of addresses. */
6001 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6004 /* Value of the DW_AT_ranges attribute is the offset in the
6005 .debug_ranges section. */
6006 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6008 /* Found discontinuous range of addresses. */
6013 /* read_partial_die has also the strict LOW < HIGH requirement. */
6017 /* When using the GNU linker, .gnu.linkonce. sections are used to
6018 eliminate duplicate copies of functions and vtables and such.
6019 The linker will arbitrarily choose one and discard the others.
6020 The AT_*_pc values for such functions refer to local labels in
6021 these sections. If the section from that file was discarded, the
6022 labels are not in the output, so the relocs get a value of 0.
6023 If this is a discarded function, mark the pc bounds as invalid,
6024 so that GDB will ignore it. */
6025 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6033 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6034 its low and high PC addresses. Do nothing if these addresses could not
6035 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6036 and HIGHPC to the high address if greater than HIGHPC. */
6039 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6040 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6041 struct dwarf2_cu
*cu
)
6043 CORE_ADDR low
, high
;
6044 struct die_info
*child
= die
->child
;
6046 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6048 *lowpc
= min (*lowpc
, low
);
6049 *highpc
= max (*highpc
, high
);
6052 /* If the language does not allow nested subprograms (either inside
6053 subprograms or lexical blocks), we're done. */
6054 if (cu
->language
!= language_ada
)
6057 /* Check all the children of the given DIE. If it contains nested
6058 subprograms, then check their pc bounds. Likewise, we need to
6059 check lexical blocks as well, as they may also contain subprogram
6061 while (child
&& child
->tag
)
6063 if (child
->tag
== DW_TAG_subprogram
6064 || child
->tag
== DW_TAG_lexical_block
)
6065 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6066 child
= sibling_die (child
);
6070 /* Get the low and high pc's represented by the scope DIE, and store
6071 them in *LOWPC and *HIGHPC. If the correct values can't be
6072 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6075 get_scope_pc_bounds (struct die_info
*die
,
6076 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6077 struct dwarf2_cu
*cu
)
6079 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6080 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6081 CORE_ADDR current_low
, current_high
;
6083 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6085 best_low
= current_low
;
6086 best_high
= current_high
;
6090 struct die_info
*child
= die
->child
;
6092 while (child
&& child
->tag
)
6094 switch (child
->tag
) {
6095 case DW_TAG_subprogram
:
6096 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6098 case DW_TAG_namespace
:
6100 /* FIXME: carlton/2004-01-16: Should we do this for
6101 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6102 that current GCC's always emit the DIEs corresponding
6103 to definitions of methods of classes as children of a
6104 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6105 the DIEs giving the declarations, which could be
6106 anywhere). But I don't see any reason why the
6107 standards says that they have to be there. */
6108 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6110 if (current_low
!= ((CORE_ADDR
) -1))
6112 best_low
= min (best_low
, current_low
);
6113 best_high
= max (best_high
, current_high
);
6121 child
= sibling_die (child
);
6126 *highpc
= best_high
;
6129 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6132 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6133 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6135 struct attribute
*attr
;
6137 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6140 CORE_ADDR high
= DW_ADDR (attr
);
6142 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6145 CORE_ADDR low
= DW_ADDR (attr
);
6147 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6151 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6154 bfd
*obfd
= cu
->objfile
->obfd
;
6156 /* The value of the DW_AT_ranges attribute is the offset of the
6157 address range list in the .debug_ranges section. */
6158 unsigned long offset
= DW_UNSND (attr
);
6159 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6161 /* For some target architectures, but not others, the
6162 read_address function sign-extends the addresses it returns.
6163 To recognize base address selection entries, we need a
6165 unsigned int addr_size
= cu
->header
.addr_size
;
6166 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6168 /* The base address, to which the next pair is relative. Note
6169 that this 'base' is a DWARF concept: most entries in a range
6170 list are relative, to reduce the number of relocs against the
6171 debugging information. This is separate from this function's
6172 'baseaddr' argument, which GDB uses to relocate debugging
6173 information from a shared library based on the address at
6174 which the library was loaded. */
6175 CORE_ADDR base
= cu
->base_address
;
6176 int base_known
= cu
->base_known
;
6178 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6179 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6181 complaint (&symfile_complaints
,
6182 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6189 unsigned int bytes_read
;
6190 CORE_ADDR start
, end
;
6192 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6193 buffer
+= bytes_read
;
6194 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6195 buffer
+= bytes_read
;
6197 /* Did we find the end of the range list? */
6198 if (start
== 0 && end
== 0)
6201 /* Did we find a base address selection entry? */
6202 else if ((start
& base_select_mask
) == base_select_mask
)
6208 /* We found an ordinary address range. */
6213 complaint (&symfile_complaints
,
6214 _("Invalid .debug_ranges data "
6215 "(no base address)"));
6221 /* Inverted range entries are invalid. */
6222 complaint (&symfile_complaints
,
6223 _("Invalid .debug_ranges data "
6224 "(inverted range)"));
6228 /* Empty range entries have no effect. */
6232 record_block_range (block
,
6233 baseaddr
+ base
+ start
,
6234 baseaddr
+ base
+ end
- 1);
6240 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6241 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6242 during 4.6.0 experimental. */
6245 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6248 int major
, minor
, release
;
6250 if (cu
->producer
== NULL
)
6252 /* For unknown compilers expect their behavior is DWARF version
6255 GCC started to support .debug_types sections by -gdwarf-4 since
6256 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6257 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6258 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6259 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6264 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6266 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6268 /* For non-GCC compilers expect their behavior is DWARF version
6273 cs
= &cu
->producer
[strlen ("GNU ")];
6274 while (*cs
&& !isdigit (*cs
))
6276 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6278 /* Not recognized as GCC. */
6283 return major
< 4 || (major
== 4 && minor
< 6);
6286 /* Return the default accessibility type if it is not overriden by
6287 DW_AT_accessibility. */
6289 static enum dwarf_access_attribute
6290 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6292 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6294 /* The default DWARF 2 accessibility for members is public, the default
6295 accessibility for inheritance is private. */
6297 if (die
->tag
!= DW_TAG_inheritance
)
6298 return DW_ACCESS_public
;
6300 return DW_ACCESS_private
;
6304 /* DWARF 3+ defines the default accessibility a different way. The same
6305 rules apply now for DW_TAG_inheritance as for the members and it only
6306 depends on the container kind. */
6308 if (die
->parent
->tag
== DW_TAG_class_type
)
6309 return DW_ACCESS_private
;
6311 return DW_ACCESS_public
;
6315 /* Add an aggregate field to the field list. */
6318 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6319 struct dwarf2_cu
*cu
)
6321 struct objfile
*objfile
= cu
->objfile
;
6322 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6323 struct nextfield
*new_field
;
6324 struct attribute
*attr
;
6326 char *fieldname
= "";
6328 /* Allocate a new field list entry and link it in. */
6329 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6330 make_cleanup (xfree
, new_field
);
6331 memset (new_field
, 0, sizeof (struct nextfield
));
6333 if (die
->tag
== DW_TAG_inheritance
)
6335 new_field
->next
= fip
->baseclasses
;
6336 fip
->baseclasses
= new_field
;
6340 new_field
->next
= fip
->fields
;
6341 fip
->fields
= new_field
;
6345 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6347 new_field
->accessibility
= DW_UNSND (attr
);
6349 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
6350 if (new_field
->accessibility
!= DW_ACCESS_public
)
6351 fip
->non_public_fields
= 1;
6353 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6355 new_field
->virtuality
= DW_UNSND (attr
);
6357 new_field
->virtuality
= DW_VIRTUALITY_none
;
6359 fp
= &new_field
->field
;
6361 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6363 /* Data member other than a C++ static data member. */
6365 /* Get type of field. */
6366 fp
->type
= die_type (die
, cu
);
6368 SET_FIELD_BITPOS (*fp
, 0);
6370 /* Get bit size of field (zero if none). */
6371 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6374 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6378 FIELD_BITSIZE (*fp
) = 0;
6381 /* Get bit offset of field. */
6382 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6385 int byte_offset
= 0;
6387 if (attr_form_is_section_offset (attr
))
6388 dwarf2_complex_location_expr_complaint ();
6389 else if (attr_form_is_constant (attr
))
6390 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6391 else if (attr_form_is_block (attr
))
6392 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6394 dwarf2_complex_location_expr_complaint ();
6396 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6398 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6401 if (gdbarch_bits_big_endian (gdbarch
))
6403 /* For big endian bits, the DW_AT_bit_offset gives the
6404 additional bit offset from the MSB of the containing
6405 anonymous object to the MSB of the field. We don't
6406 have to do anything special since we don't need to
6407 know the size of the anonymous object. */
6408 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6412 /* For little endian bits, compute the bit offset to the
6413 MSB of the anonymous object, subtract off the number of
6414 bits from the MSB of the field to the MSB of the
6415 object, and then subtract off the number of bits of
6416 the field itself. The result is the bit offset of
6417 the LSB of the field. */
6419 int bit_offset
= DW_UNSND (attr
);
6421 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6424 /* The size of the anonymous object containing
6425 the bit field is explicit, so use the
6426 indicated size (in bytes). */
6427 anonymous_size
= DW_UNSND (attr
);
6431 /* The size of the anonymous object containing
6432 the bit field must be inferred from the type
6433 attribute of the data member containing the
6435 anonymous_size
= TYPE_LENGTH (fp
->type
);
6437 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6438 - bit_offset
- FIELD_BITSIZE (*fp
);
6442 /* Get name of field. */
6443 fieldname
= dwarf2_name (die
, cu
);
6444 if (fieldname
== NULL
)
6447 /* The name is already allocated along with this objfile, so we don't
6448 need to duplicate it for the type. */
6449 fp
->name
= fieldname
;
6451 /* Change accessibility for artificial fields (e.g. virtual table
6452 pointer or virtual base class pointer) to private. */
6453 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6455 FIELD_ARTIFICIAL (*fp
) = 1;
6456 new_field
->accessibility
= DW_ACCESS_private
;
6457 fip
->non_public_fields
= 1;
6460 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6462 /* C++ static member. */
6464 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6465 is a declaration, but all versions of G++ as of this writing
6466 (so through at least 3.2.1) incorrectly generate
6467 DW_TAG_variable tags. */
6471 /* Get name of field. */
6472 fieldname
= dwarf2_name (die
, cu
);
6473 if (fieldname
== NULL
)
6476 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6478 /* Only create a symbol if this is an external value.
6479 new_symbol checks this and puts the value in the global symbol
6480 table, which we want. If it is not external, new_symbol
6481 will try to put the value in cu->list_in_scope which is wrong. */
6482 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6484 /* A static const member, not much different than an enum as far as
6485 we're concerned, except that we can support more types. */
6486 new_symbol (die
, NULL
, cu
);
6489 /* Get physical name. */
6490 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6492 /* The name is already allocated along with this objfile, so we don't
6493 need to duplicate it for the type. */
6494 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6495 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6496 FIELD_NAME (*fp
) = fieldname
;
6498 else if (die
->tag
== DW_TAG_inheritance
)
6500 /* C++ base class field. */
6501 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6504 int byte_offset
= 0;
6506 if (attr_form_is_section_offset (attr
))
6507 dwarf2_complex_location_expr_complaint ();
6508 else if (attr_form_is_constant (attr
))
6509 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6510 else if (attr_form_is_block (attr
))
6511 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6513 dwarf2_complex_location_expr_complaint ();
6515 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6517 FIELD_BITSIZE (*fp
) = 0;
6518 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6519 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6520 fip
->nbaseclasses
++;
6524 /* Add a typedef defined in the scope of the FIP's class. */
6527 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6528 struct dwarf2_cu
*cu
)
6530 struct objfile
*objfile
= cu
->objfile
;
6531 struct typedef_field_list
*new_field
;
6532 struct attribute
*attr
;
6533 struct typedef_field
*fp
;
6534 char *fieldname
= "";
6536 /* Allocate a new field list entry and link it in. */
6537 new_field
= xzalloc (sizeof (*new_field
));
6538 make_cleanup (xfree
, new_field
);
6540 gdb_assert (die
->tag
== DW_TAG_typedef
);
6542 fp
= &new_field
->field
;
6544 /* Get name of field. */
6545 fp
->name
= dwarf2_name (die
, cu
);
6546 if (fp
->name
== NULL
)
6549 fp
->type
= read_type_die (die
, cu
);
6551 new_field
->next
= fip
->typedef_field_list
;
6552 fip
->typedef_field_list
= new_field
;
6553 fip
->typedef_field_list_count
++;
6556 /* Create the vector of fields, and attach it to the type. */
6559 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6560 struct dwarf2_cu
*cu
)
6562 int nfields
= fip
->nfields
;
6564 /* Record the field count, allocate space for the array of fields,
6565 and create blank accessibility bitfields if necessary. */
6566 TYPE_NFIELDS (type
) = nfields
;
6567 TYPE_FIELDS (type
) = (struct field
*)
6568 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6569 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6571 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6573 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6575 TYPE_FIELD_PRIVATE_BITS (type
) =
6576 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6577 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6579 TYPE_FIELD_PROTECTED_BITS (type
) =
6580 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6581 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6583 TYPE_FIELD_IGNORE_BITS (type
) =
6584 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6585 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6588 /* If the type has baseclasses, allocate and clear a bit vector for
6589 TYPE_FIELD_VIRTUAL_BITS. */
6590 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6592 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6593 unsigned char *pointer
;
6595 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6596 pointer
= TYPE_ALLOC (type
, num_bytes
);
6597 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6598 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6599 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6602 /* Copy the saved-up fields into the field vector. Start from the head of
6603 the list, adding to the tail of the field array, so that they end up in
6604 the same order in the array in which they were added to the list. */
6605 while (nfields
-- > 0)
6607 struct nextfield
*fieldp
;
6611 fieldp
= fip
->fields
;
6612 fip
->fields
= fieldp
->next
;
6616 fieldp
= fip
->baseclasses
;
6617 fip
->baseclasses
= fieldp
->next
;
6620 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6621 switch (fieldp
->accessibility
)
6623 case DW_ACCESS_private
:
6624 if (cu
->language
!= language_ada
)
6625 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6628 case DW_ACCESS_protected
:
6629 if (cu
->language
!= language_ada
)
6630 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6633 case DW_ACCESS_public
:
6637 /* Unknown accessibility. Complain and treat it as public. */
6639 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6640 fieldp
->accessibility
);
6644 if (nfields
< fip
->nbaseclasses
)
6646 switch (fieldp
->virtuality
)
6648 case DW_VIRTUALITY_virtual
:
6649 case DW_VIRTUALITY_pure_virtual
:
6650 if (cu
->language
== language_ada
)
6651 error (_("unexpected virtuality in component of Ada type"));
6652 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6659 /* Add a member function to the proper fieldlist. */
6662 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6663 struct type
*type
, struct dwarf2_cu
*cu
)
6665 struct objfile
*objfile
= cu
->objfile
;
6666 struct attribute
*attr
;
6667 struct fnfieldlist
*flp
;
6669 struct fn_field
*fnp
;
6671 struct nextfnfield
*new_fnfield
;
6672 struct type
*this_type
;
6673 enum dwarf_access_attribute accessibility
;
6675 if (cu
->language
== language_ada
)
6676 error (_("unexpected member function in Ada type"));
6678 /* Get name of member function. */
6679 fieldname
= dwarf2_name (die
, cu
);
6680 if (fieldname
== NULL
)
6683 /* Look up member function name in fieldlist. */
6684 for (i
= 0; i
< fip
->nfnfields
; i
++)
6686 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6690 /* Create new list element if necessary. */
6691 if (i
< fip
->nfnfields
)
6692 flp
= &fip
->fnfieldlists
[i
];
6695 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6697 fip
->fnfieldlists
= (struct fnfieldlist
*)
6698 xrealloc (fip
->fnfieldlists
,
6699 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6700 * sizeof (struct fnfieldlist
));
6701 if (fip
->nfnfields
== 0)
6702 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6704 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6705 flp
->name
= fieldname
;
6708 i
= fip
->nfnfields
++;
6711 /* Create a new member function field and chain it to the field list
6713 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6714 make_cleanup (xfree
, new_fnfield
);
6715 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6716 new_fnfield
->next
= flp
->head
;
6717 flp
->head
= new_fnfield
;
6720 /* Fill in the member function field info. */
6721 fnp
= &new_fnfield
->fnfield
;
6723 /* Delay processing of the physname until later. */
6724 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
6726 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
6731 char *physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6732 fnp
->physname
= physname
? physname
: "";
6735 fnp
->type
= alloc_type (objfile
);
6736 this_type
= read_type_die (die
, cu
);
6737 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6739 int nparams
= TYPE_NFIELDS (this_type
);
6741 /* TYPE is the domain of this method, and THIS_TYPE is the type
6742 of the method itself (TYPE_CODE_METHOD). */
6743 smash_to_method_type (fnp
->type
, type
,
6744 TYPE_TARGET_TYPE (this_type
),
6745 TYPE_FIELDS (this_type
),
6746 TYPE_NFIELDS (this_type
),
6747 TYPE_VARARGS (this_type
));
6749 /* Handle static member functions.
6750 Dwarf2 has no clean way to discern C++ static and non-static
6751 member functions. G++ helps GDB by marking the first
6752 parameter for non-static member functions (which is the this
6753 pointer) as artificial. We obtain this information from
6754 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6755 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6756 fnp
->voffset
= VOFFSET_STATIC
;
6759 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
6760 dwarf2_full_name (fieldname
, die
, cu
));
6762 /* Get fcontext from DW_AT_containing_type if present. */
6763 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6764 fnp
->fcontext
= die_containing_type (die
, cu
);
6766 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
6767 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6769 /* Get accessibility. */
6770 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6772 accessibility
= DW_UNSND (attr
);
6774 accessibility
= dwarf2_default_access_attribute (die
, cu
);
6775 switch (accessibility
)
6777 case DW_ACCESS_private
:
6778 fnp
->is_private
= 1;
6780 case DW_ACCESS_protected
:
6781 fnp
->is_protected
= 1;
6785 /* Check for artificial methods. */
6786 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
6787 if (attr
&& DW_UNSND (attr
) != 0)
6788 fnp
->is_artificial
= 1;
6790 /* Get index in virtual function table if it is a virtual member
6791 function. For older versions of GCC, this is an offset in the
6792 appropriate virtual table, as specified by DW_AT_containing_type.
6793 For everyone else, it is an expression to be evaluated relative
6794 to the object address. */
6796 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
6799 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
6801 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
6803 /* Old-style GCC. */
6804 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
6806 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6807 || (DW_BLOCK (attr
)->size
> 1
6808 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
6809 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
6811 struct dwarf_block blk
;
6814 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6816 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
6817 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
6818 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6819 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
6820 dwarf2_complex_location_expr_complaint ();
6822 fnp
->voffset
/= cu
->header
.addr_size
;
6826 dwarf2_complex_location_expr_complaint ();
6829 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
6831 else if (attr_form_is_section_offset (attr
))
6833 dwarf2_complex_location_expr_complaint ();
6837 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6843 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6844 if (attr
&& DW_UNSND (attr
))
6846 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6847 complaint (&symfile_complaints
,
6848 _("Member function \"%s\" (offset %d) is virtual "
6849 "but the vtable offset is not specified"),
6850 fieldname
, die
->offset
);
6851 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6852 TYPE_CPLUS_DYNAMIC (type
) = 1;
6857 /* Create the vector of member function fields, and attach it to the type. */
6860 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6861 struct dwarf2_cu
*cu
)
6863 struct fnfieldlist
*flp
;
6864 int total_length
= 0;
6867 if (cu
->language
== language_ada
)
6868 error (_("unexpected member functions in Ada type"));
6870 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6871 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6872 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6874 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6876 struct nextfnfield
*nfp
= flp
->head
;
6877 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6880 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6881 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6882 fn_flp
->fn_fields
= (struct fn_field
*)
6883 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6884 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6885 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6887 total_length
+= flp
->length
;
6890 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6891 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6894 /* Returns non-zero if NAME is the name of a vtable member in CU's
6895 language, zero otherwise. */
6897 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6899 static const char vptr
[] = "_vptr";
6900 static const char vtable
[] = "vtable";
6902 /* Look for the C++ and Java forms of the vtable. */
6903 if ((cu
->language
== language_java
6904 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6905 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6906 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6912 /* GCC outputs unnamed structures that are really pointers to member
6913 functions, with the ABI-specified layout. If TYPE describes
6914 such a structure, smash it into a member function type.
6916 GCC shouldn't do this; it should just output pointer to member DIEs.
6917 This is GCC PR debug/28767. */
6920 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6922 struct type
*pfn_type
, *domain_type
, *new_type
;
6924 /* Check for a structure with no name and two children. */
6925 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6928 /* Check for __pfn and __delta members. */
6929 if (TYPE_FIELD_NAME (type
, 0) == NULL
6930 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6931 || TYPE_FIELD_NAME (type
, 1) == NULL
6932 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6935 /* Find the type of the method. */
6936 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6937 if (pfn_type
== NULL
6938 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6939 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6942 /* Look for the "this" argument. */
6943 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6944 if (TYPE_NFIELDS (pfn_type
) == 0
6945 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6946 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6949 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6950 new_type
= alloc_type (objfile
);
6951 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6952 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6953 TYPE_VARARGS (pfn_type
));
6954 smash_to_methodptr_type (type
, new_type
);
6957 /* Called when we find the DIE that starts a structure or union scope
6958 (definition) to create a type for the structure or union. Fill in
6959 the type's name and general properties; the members will not be
6960 processed until process_structure_type.
6962 NOTE: we need to call these functions regardless of whether or not the
6963 DIE has a DW_AT_name attribute, since it might be an anonymous
6964 structure or union. This gets the type entered into our set of
6967 However, if the structure is incomplete (an opaque struct/union)
6968 then suppress creating a symbol table entry for it since gdb only
6969 wants to find the one with the complete definition. Note that if
6970 it is complete, we just call new_symbol, which does it's own
6971 checking about whether the struct/union is anonymous or not (and
6972 suppresses creating a symbol table entry itself). */
6974 static struct type
*
6975 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6977 struct objfile
*objfile
= cu
->objfile
;
6979 struct attribute
*attr
;
6982 /* If the definition of this type lives in .debug_types, read that type.
6983 Don't follow DW_AT_specification though, that will take us back up
6984 the chain and we want to go down. */
6985 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6988 struct dwarf2_cu
*type_cu
= cu
;
6989 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6991 /* We could just recurse on read_structure_type, but we need to call
6992 get_die_type to ensure only one type for this DIE is created.
6993 This is important, for example, because for c++ classes we need
6994 TYPE_NAME set which is only done by new_symbol. Blech. */
6995 type
= read_type_die (type_die
, type_cu
);
6997 /* TYPE_CU may not be the same as CU.
6998 Ensure TYPE is recorded in CU's type_hash table. */
6999 return set_die_type (die
, type
, cu
);
7002 type
= alloc_type (objfile
);
7003 INIT_CPLUS_SPECIFIC (type
);
7005 name
= dwarf2_name (die
, cu
);
7008 if (cu
->language
== language_cplus
7009 || cu
->language
== language_java
)
7011 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7013 /* dwarf2_full_name might have already finished building the DIE's
7014 type. If so, there is no need to continue. */
7015 if (get_die_type (die
, cu
) != NULL
)
7016 return get_die_type (die
, cu
);
7018 TYPE_TAG_NAME (type
) = full_name
;
7019 if (die
->tag
== DW_TAG_structure_type
7020 || die
->tag
== DW_TAG_class_type
)
7021 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7025 /* The name is already allocated along with this objfile, so
7026 we don't need to duplicate it for the type. */
7027 TYPE_TAG_NAME (type
) = (char *) name
;
7028 if (die
->tag
== DW_TAG_class_type
)
7029 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7033 if (die
->tag
== DW_TAG_structure_type
)
7035 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7037 else if (die
->tag
== DW_TAG_union_type
)
7039 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7043 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7046 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7047 TYPE_DECLARED_CLASS (type
) = 1;
7049 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7052 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7056 TYPE_LENGTH (type
) = 0;
7059 TYPE_STUB_SUPPORTED (type
) = 1;
7060 if (die_is_declaration (die
, cu
))
7061 TYPE_STUB (type
) = 1;
7062 else if (attr
== NULL
&& die
->child
== NULL
7063 && producer_is_realview (cu
->producer
))
7064 /* RealView does not output the required DW_AT_declaration
7065 on incomplete types. */
7066 TYPE_STUB (type
) = 1;
7068 /* We need to add the type field to the die immediately so we don't
7069 infinitely recurse when dealing with pointers to the structure
7070 type within the structure itself. */
7071 set_die_type (die
, type
, cu
);
7073 /* set_die_type should be already done. */
7074 set_descriptive_type (type
, die
, cu
);
7079 /* Finish creating a structure or union type, including filling in
7080 its members and creating a symbol for it. */
7083 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7085 struct objfile
*objfile
= cu
->objfile
;
7086 struct die_info
*child_die
= die
->child
;
7089 type
= get_die_type (die
, cu
);
7091 type
= read_structure_type (die
, cu
);
7093 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7095 struct field_info fi
;
7096 struct die_info
*child_die
;
7097 VEC (symbolp
) *template_args
= NULL
;
7098 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7100 memset (&fi
, 0, sizeof (struct field_info
));
7102 child_die
= die
->child
;
7104 while (child_die
&& child_die
->tag
)
7106 if (child_die
->tag
== DW_TAG_member
7107 || child_die
->tag
== DW_TAG_variable
)
7109 /* NOTE: carlton/2002-11-05: A C++ static data member
7110 should be a DW_TAG_member that is a declaration, but
7111 all versions of G++ as of this writing (so through at
7112 least 3.2.1) incorrectly generate DW_TAG_variable
7113 tags for them instead. */
7114 dwarf2_add_field (&fi
, child_die
, cu
);
7116 else if (child_die
->tag
== DW_TAG_subprogram
)
7118 /* C++ member function. */
7119 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7121 else if (child_die
->tag
== DW_TAG_inheritance
)
7123 /* C++ base class field. */
7124 dwarf2_add_field (&fi
, child_die
, cu
);
7126 else if (child_die
->tag
== DW_TAG_typedef
)
7127 dwarf2_add_typedef (&fi
, child_die
, cu
);
7128 else if (child_die
->tag
== DW_TAG_template_type_param
7129 || child_die
->tag
== DW_TAG_template_value_param
)
7131 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7134 VEC_safe_push (symbolp
, template_args
, arg
);
7137 child_die
= sibling_die (child_die
);
7140 /* Attach template arguments to type. */
7141 if (! VEC_empty (symbolp
, template_args
))
7143 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7144 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7145 = VEC_length (symbolp
, template_args
);
7146 TYPE_TEMPLATE_ARGUMENTS (type
)
7147 = obstack_alloc (&objfile
->objfile_obstack
,
7148 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7149 * sizeof (struct symbol
*)));
7150 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7151 VEC_address (symbolp
, template_args
),
7152 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7153 * sizeof (struct symbol
*)));
7154 VEC_free (symbolp
, template_args
);
7157 /* Attach fields and member functions to the type. */
7159 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7162 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7164 /* Get the type which refers to the base class (possibly this
7165 class itself) which contains the vtable pointer for the current
7166 class from the DW_AT_containing_type attribute. This use of
7167 DW_AT_containing_type is a GNU extension. */
7169 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7171 struct type
*t
= die_containing_type (die
, cu
);
7173 TYPE_VPTR_BASETYPE (type
) = t
;
7178 /* Our own class provides vtbl ptr. */
7179 for (i
= TYPE_NFIELDS (t
) - 1;
7180 i
>= TYPE_N_BASECLASSES (t
);
7183 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7185 if (is_vtable_name (fieldname
, cu
))
7187 TYPE_VPTR_FIELDNO (type
) = i
;
7192 /* Complain if virtual function table field not found. */
7193 if (i
< TYPE_N_BASECLASSES (t
))
7194 complaint (&symfile_complaints
,
7195 _("virtual function table pointer "
7196 "not found when defining class '%s'"),
7197 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7202 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7205 else if (cu
->producer
7206 && strncmp (cu
->producer
,
7207 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7209 /* The IBM XLC compiler does not provide direct indication
7210 of the containing type, but the vtable pointer is
7211 always named __vfp. */
7215 for (i
= TYPE_NFIELDS (type
) - 1;
7216 i
>= TYPE_N_BASECLASSES (type
);
7219 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7221 TYPE_VPTR_FIELDNO (type
) = i
;
7222 TYPE_VPTR_BASETYPE (type
) = type
;
7229 /* Copy fi.typedef_field_list linked list elements content into the
7230 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7231 if (fi
.typedef_field_list
)
7233 int i
= fi
.typedef_field_list_count
;
7235 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7236 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7237 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7238 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7240 /* Reverse the list order to keep the debug info elements order. */
7243 struct typedef_field
*dest
, *src
;
7245 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7246 src
= &fi
.typedef_field_list
->field
;
7247 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7252 do_cleanups (back_to
);
7255 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
7257 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7258 snapshots) has been known to create a die giving a declaration
7259 for a class that has, as a child, a die giving a definition for a
7260 nested class. So we have to process our children even if the
7261 current die is a declaration. Normally, of course, a declaration
7262 won't have any children at all. */
7264 while (child_die
!= NULL
&& child_die
->tag
)
7266 if (child_die
->tag
== DW_TAG_member
7267 || child_die
->tag
== DW_TAG_variable
7268 || child_die
->tag
== DW_TAG_inheritance
7269 || child_die
->tag
== DW_TAG_template_value_param
7270 || child_die
->tag
== DW_TAG_template_type_param
)
7275 process_die (child_die
, cu
);
7277 child_die
= sibling_die (child_die
);
7280 /* Do not consider external references. According to the DWARF standard,
7281 these DIEs are identified by the fact that they have no byte_size
7282 attribute, and a declaration attribute. */
7283 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7284 || !die_is_declaration (die
, cu
))
7285 new_symbol (die
, type
, cu
);
7288 /* Given a DW_AT_enumeration_type die, set its type. We do not
7289 complete the type's fields yet, or create any symbols. */
7291 static struct type
*
7292 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7294 struct objfile
*objfile
= cu
->objfile
;
7296 struct attribute
*attr
;
7299 /* If the definition of this type lives in .debug_types, read that type.
7300 Don't follow DW_AT_specification though, that will take us back up
7301 the chain and we want to go down. */
7302 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7305 struct dwarf2_cu
*type_cu
= cu
;
7306 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7308 type
= read_type_die (type_die
, type_cu
);
7310 /* TYPE_CU may not be the same as CU.
7311 Ensure TYPE is recorded in CU's type_hash table. */
7312 return set_die_type (die
, type
, cu
);
7315 type
= alloc_type (objfile
);
7317 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7318 name
= dwarf2_full_name (NULL
, die
, cu
);
7320 TYPE_TAG_NAME (type
) = (char *) name
;
7322 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7325 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7329 TYPE_LENGTH (type
) = 0;
7332 /* The enumeration DIE can be incomplete. In Ada, any type can be
7333 declared as private in the package spec, and then defined only
7334 inside the package body. Such types are known as Taft Amendment
7335 Types. When another package uses such a type, an incomplete DIE
7336 may be generated by the compiler. */
7337 if (die_is_declaration (die
, cu
))
7338 TYPE_STUB (type
) = 1;
7340 return set_die_type (die
, type
, cu
);
7343 /* Given a pointer to a die which begins an enumeration, process all
7344 the dies that define the members of the enumeration, and create the
7345 symbol for the enumeration type.
7347 NOTE: We reverse the order of the element list. */
7350 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7352 struct type
*this_type
;
7354 this_type
= get_die_type (die
, cu
);
7355 if (this_type
== NULL
)
7356 this_type
= read_enumeration_type (die
, cu
);
7358 if (die
->child
!= NULL
)
7360 struct die_info
*child_die
;
7362 struct field
*fields
= NULL
;
7364 int unsigned_enum
= 1;
7367 child_die
= die
->child
;
7368 while (child_die
&& child_die
->tag
)
7370 if (child_die
->tag
!= DW_TAG_enumerator
)
7372 process_die (child_die
, cu
);
7376 name
= dwarf2_name (child_die
, cu
);
7379 sym
= new_symbol (child_die
, this_type
, cu
);
7380 if (SYMBOL_VALUE (sym
) < 0)
7383 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7385 fields
= (struct field
*)
7387 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7388 * sizeof (struct field
));
7391 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7392 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7393 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7394 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7400 child_die
= sibling_die (child_die
);
7405 TYPE_NFIELDS (this_type
) = num_fields
;
7406 TYPE_FIELDS (this_type
) = (struct field
*)
7407 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7408 memcpy (TYPE_FIELDS (this_type
), fields
,
7409 sizeof (struct field
) * num_fields
);
7413 TYPE_UNSIGNED (this_type
) = 1;
7416 new_symbol (die
, this_type
, cu
);
7419 /* Extract all information from a DW_TAG_array_type DIE and put it in
7420 the DIE's type field. For now, this only handles one dimensional
7423 static struct type
*
7424 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7426 struct objfile
*objfile
= cu
->objfile
;
7427 struct die_info
*child_die
;
7429 struct type
*element_type
, *range_type
, *index_type
;
7430 struct type
**range_types
= NULL
;
7431 struct attribute
*attr
;
7433 struct cleanup
*back_to
;
7436 element_type
= die_type (die
, cu
);
7438 /* The die_type call above may have already set the type for this DIE. */
7439 type
= get_die_type (die
, cu
);
7443 /* Irix 6.2 native cc creates array types without children for
7444 arrays with unspecified length. */
7445 if (die
->child
== NULL
)
7447 index_type
= objfile_type (objfile
)->builtin_int
;
7448 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7449 type
= create_array_type (NULL
, element_type
, range_type
);
7450 return set_die_type (die
, type
, cu
);
7453 back_to
= make_cleanup (null_cleanup
, NULL
);
7454 child_die
= die
->child
;
7455 while (child_die
&& child_die
->tag
)
7457 if (child_die
->tag
== DW_TAG_subrange_type
)
7459 struct type
*child_type
= read_type_die (child_die
, cu
);
7461 if (child_type
!= NULL
)
7463 /* The range type was succesfully read. Save it for the
7464 array type creation. */
7465 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7467 range_types
= (struct type
**)
7468 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7469 * sizeof (struct type
*));
7471 make_cleanup (free_current_contents
, &range_types
);
7473 range_types
[ndim
++] = child_type
;
7476 child_die
= sibling_die (child_die
);
7479 /* Dwarf2 dimensions are output from left to right, create the
7480 necessary array types in backwards order. */
7482 type
= element_type
;
7484 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7489 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7494 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7497 /* Understand Dwarf2 support for vector types (like they occur on
7498 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7499 array type. This is not part of the Dwarf2/3 standard yet, but a
7500 custom vendor extension. The main difference between a regular
7501 array and the vector variant is that vectors are passed by value
7503 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7505 make_vector_type (type
);
7507 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7508 implementation may choose to implement triple vectors using this
7510 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7513 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
7514 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7516 complaint (&symfile_complaints
,
7517 _("DW_AT_byte_size for array type smaller "
7518 "than the total size of elements"));
7521 name
= dwarf2_name (die
, cu
);
7523 TYPE_NAME (type
) = name
;
7525 /* Install the type in the die. */
7526 set_die_type (die
, type
, cu
);
7528 /* set_die_type should be already done. */
7529 set_descriptive_type (type
, die
, cu
);
7531 do_cleanups (back_to
);
7536 static enum dwarf_array_dim_ordering
7537 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7539 struct attribute
*attr
;
7541 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7543 if (attr
) return DW_SND (attr
);
7545 /* GNU F77 is a special case, as at 08/2004 array type info is the
7546 opposite order to the dwarf2 specification, but data is still
7547 laid out as per normal fortran.
7549 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7550 version checking. */
7552 if (cu
->language
== language_fortran
7553 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7555 return DW_ORD_row_major
;
7558 switch (cu
->language_defn
->la_array_ordering
)
7560 case array_column_major
:
7561 return DW_ORD_col_major
;
7562 case array_row_major
:
7564 return DW_ORD_row_major
;
7568 /* Extract all information from a DW_TAG_set_type DIE and put it in
7569 the DIE's type field. */
7571 static struct type
*
7572 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7574 struct type
*domain_type
, *set_type
;
7575 struct attribute
*attr
;
7577 domain_type
= die_type (die
, cu
);
7579 /* The die_type call above may have already set the type for this DIE. */
7580 set_type
= get_die_type (die
, cu
);
7584 set_type
= create_set_type (NULL
, domain_type
);
7586 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7588 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7590 return set_die_type (die
, set_type
, cu
);
7593 /* First cut: install each common block member as a global variable. */
7596 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7598 struct die_info
*child_die
;
7599 struct attribute
*attr
;
7601 CORE_ADDR base
= (CORE_ADDR
) 0;
7603 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7606 /* Support the .debug_loc offsets. */
7607 if (attr_form_is_block (attr
))
7609 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7611 else if (attr_form_is_section_offset (attr
))
7613 dwarf2_complex_location_expr_complaint ();
7617 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7618 "common block member");
7621 if (die
->child
!= NULL
)
7623 child_die
= die
->child
;
7624 while (child_die
&& child_die
->tag
)
7626 sym
= new_symbol (child_die
, NULL
, cu
);
7627 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
7628 if (sym
!= NULL
&& attr
!= NULL
)
7630 CORE_ADDR byte_offset
= 0;
7632 if (attr_form_is_section_offset (attr
))
7633 dwarf2_complex_location_expr_complaint ();
7634 else if (attr_form_is_constant (attr
))
7635 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
7636 else if (attr_form_is_block (attr
))
7637 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7639 dwarf2_complex_location_expr_complaint ();
7641 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
7642 add_symbol_to_list (sym
, &global_symbols
);
7644 child_die
= sibling_die (child_die
);
7649 /* Create a type for a C++ namespace. */
7651 static struct type
*
7652 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7654 struct objfile
*objfile
= cu
->objfile
;
7655 const char *previous_prefix
, *name
;
7659 /* For extensions, reuse the type of the original namespace. */
7660 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7662 struct die_info
*ext_die
;
7663 struct dwarf2_cu
*ext_cu
= cu
;
7665 ext_die
= dwarf2_extension (die
, &ext_cu
);
7666 type
= read_type_die (ext_die
, ext_cu
);
7668 /* EXT_CU may not be the same as CU.
7669 Ensure TYPE is recorded in CU's type_hash table. */
7670 return set_die_type (die
, type
, cu
);
7673 name
= namespace_name (die
, &is_anonymous
, cu
);
7675 /* Now build the name of the current namespace. */
7677 previous_prefix
= determine_prefix (die
, cu
);
7678 if (previous_prefix
[0] != '\0')
7679 name
= typename_concat (&objfile
->objfile_obstack
,
7680 previous_prefix
, name
, 0, cu
);
7682 /* Create the type. */
7683 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7685 TYPE_NAME (type
) = (char *) name
;
7686 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7688 return set_die_type (die
, type
, cu
);
7691 /* Read a C++ namespace. */
7694 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7696 struct objfile
*objfile
= cu
->objfile
;
7699 /* Add a symbol associated to this if we haven't seen the namespace
7700 before. Also, add a using directive if it's an anonymous
7703 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7707 type
= read_type_die (die
, cu
);
7708 new_symbol (die
, type
, cu
);
7710 namespace_name (die
, &is_anonymous
, cu
);
7713 const char *previous_prefix
= determine_prefix (die
, cu
);
7715 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7716 NULL
, &objfile
->objfile_obstack
);
7720 if (die
->child
!= NULL
)
7722 struct die_info
*child_die
= die
->child
;
7724 while (child_die
&& child_die
->tag
)
7726 process_die (child_die
, cu
);
7727 child_die
= sibling_die (child_die
);
7732 /* Read a Fortran module as type. This DIE can be only a declaration used for
7733 imported module. Still we need that type as local Fortran "use ... only"
7734 declaration imports depend on the created type in determine_prefix. */
7736 static struct type
*
7737 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7739 struct objfile
*objfile
= cu
->objfile
;
7743 module_name
= dwarf2_name (die
, cu
);
7745 complaint (&symfile_complaints
,
7746 _("DW_TAG_module has no name, offset 0x%x"),
7748 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7750 /* determine_prefix uses TYPE_TAG_NAME. */
7751 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7753 return set_die_type (die
, type
, cu
);
7756 /* Read a Fortran module. */
7759 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7761 struct die_info
*child_die
= die
->child
;
7763 while (child_die
&& child_die
->tag
)
7765 process_die (child_die
, cu
);
7766 child_die
= sibling_die (child_die
);
7770 /* Return the name of the namespace represented by DIE. Set
7771 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7775 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
7777 struct die_info
*current_die
;
7778 const char *name
= NULL
;
7780 /* Loop through the extensions until we find a name. */
7782 for (current_die
= die
;
7783 current_die
!= NULL
;
7784 current_die
= dwarf2_extension (die
, &cu
))
7786 name
= dwarf2_name (current_die
, cu
);
7791 /* Is it an anonymous namespace? */
7793 *is_anonymous
= (name
== NULL
);
7795 name
= "(anonymous namespace)";
7800 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7801 the user defined type vector. */
7803 static struct type
*
7804 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7806 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7807 struct comp_unit_head
*cu_header
= &cu
->header
;
7809 struct attribute
*attr_byte_size
;
7810 struct attribute
*attr_address_class
;
7811 int byte_size
, addr_class
;
7812 struct type
*target_type
;
7814 target_type
= die_type (die
, cu
);
7816 /* The die_type call above may have already set the type for this DIE. */
7817 type
= get_die_type (die
, cu
);
7821 type
= lookup_pointer_type (target_type
);
7823 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7825 byte_size
= DW_UNSND (attr_byte_size
);
7827 byte_size
= cu_header
->addr_size
;
7829 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
7830 if (attr_address_class
)
7831 addr_class
= DW_UNSND (attr_address_class
);
7833 addr_class
= DW_ADDR_none
;
7835 /* If the pointer size or address class is different than the
7836 default, create a type variant marked as such and set the
7837 length accordingly. */
7838 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
7840 if (gdbarch_address_class_type_flags_p (gdbarch
))
7844 type_flags
= gdbarch_address_class_type_flags
7845 (gdbarch
, byte_size
, addr_class
);
7846 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
7848 type
= make_type_with_address_space (type
, type_flags
);
7850 else if (TYPE_LENGTH (type
) != byte_size
)
7852 complaint (&symfile_complaints
,
7853 _("invalid pointer size %d"), byte_size
);
7857 /* Should we also complain about unhandled address classes? */
7861 TYPE_LENGTH (type
) = byte_size
;
7862 return set_die_type (die
, type
, cu
);
7865 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7866 the user defined type vector. */
7868 static struct type
*
7869 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7872 struct type
*to_type
;
7873 struct type
*domain
;
7875 to_type
= die_type (die
, cu
);
7876 domain
= die_containing_type (die
, cu
);
7878 /* The calls above may have already set the type for this DIE. */
7879 type
= get_die_type (die
, cu
);
7883 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
7884 type
= lookup_methodptr_type (to_type
);
7886 type
= lookup_memberptr_type (to_type
, domain
);
7888 return set_die_type (die
, type
, cu
);
7891 /* Extract all information from a DW_TAG_reference_type DIE and add to
7892 the user defined type vector. */
7894 static struct type
*
7895 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7897 struct comp_unit_head
*cu_header
= &cu
->header
;
7898 struct type
*type
, *target_type
;
7899 struct attribute
*attr
;
7901 target_type
= die_type (die
, cu
);
7903 /* The die_type call above may have already set the type for this DIE. */
7904 type
= get_die_type (die
, cu
);
7908 type
= lookup_reference_type (target_type
);
7909 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7912 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7916 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7918 return set_die_type (die
, type
, cu
);
7921 static struct type
*
7922 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7924 struct type
*base_type
, *cv_type
;
7926 base_type
= die_type (die
, cu
);
7928 /* The die_type call above may have already set the type for this DIE. */
7929 cv_type
= get_die_type (die
, cu
);
7933 /* In case the const qualifier is applied to an array type, the element type
7934 is so qualified, not the array type (section 6.7.3 of C99). */
7935 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
7937 struct type
*el_type
, *inner_array
;
7939 base_type
= copy_type (base_type
);
7940 inner_array
= base_type
;
7942 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
7944 TYPE_TARGET_TYPE (inner_array
) =
7945 copy_type (TYPE_TARGET_TYPE (inner_array
));
7946 inner_array
= TYPE_TARGET_TYPE (inner_array
);
7949 el_type
= TYPE_TARGET_TYPE (inner_array
);
7950 TYPE_TARGET_TYPE (inner_array
) =
7951 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
7953 return set_die_type (die
, base_type
, cu
);
7956 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7957 return set_die_type (die
, cv_type
, cu
);
7960 static struct type
*
7961 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7963 struct type
*base_type
, *cv_type
;
7965 base_type
= die_type (die
, cu
);
7967 /* The die_type call above may have already set the type for this DIE. */
7968 cv_type
= get_die_type (die
, cu
);
7972 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7973 return set_die_type (die
, cv_type
, cu
);
7976 /* Extract all information from a DW_TAG_string_type DIE and add to
7977 the user defined type vector. It isn't really a user defined type,
7978 but it behaves like one, with other DIE's using an AT_user_def_type
7979 attribute to reference it. */
7981 static struct type
*
7982 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7984 struct objfile
*objfile
= cu
->objfile
;
7985 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7986 struct type
*type
, *range_type
, *index_type
, *char_type
;
7987 struct attribute
*attr
;
7988 unsigned int length
;
7990 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7993 length
= DW_UNSND (attr
);
7997 /* Check for the DW_AT_byte_size attribute. */
7998 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8001 length
= DW_UNSND (attr
);
8009 index_type
= objfile_type (objfile
)->builtin_int
;
8010 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8011 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8012 type
= create_string_type (NULL
, char_type
, range_type
);
8014 return set_die_type (die
, type
, cu
);
8017 /* Handle DIES due to C code like:
8021 int (*funcp)(int a, long l);
8025 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8027 static struct type
*
8028 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8030 struct type
*type
; /* Type that this function returns. */
8031 struct type
*ftype
; /* Function that returns above type. */
8032 struct attribute
*attr
;
8034 type
= die_type (die
, cu
);
8036 /* The die_type call above may have already set the type for this DIE. */
8037 ftype
= get_die_type (die
, cu
);
8041 ftype
= lookup_function_type (type
);
8043 /* All functions in C++, Pascal and Java have prototypes. */
8044 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8045 if ((attr
&& (DW_UNSND (attr
) != 0))
8046 || cu
->language
== language_cplus
8047 || cu
->language
== language_java
8048 || cu
->language
== language_pascal
)
8049 TYPE_PROTOTYPED (ftype
) = 1;
8050 else if (producer_is_realview (cu
->producer
))
8051 /* RealView does not emit DW_AT_prototyped. We can not
8052 distinguish prototyped and unprototyped functions; default to
8053 prototyped, since that is more common in modern code (and
8054 RealView warns about unprototyped functions). */
8055 TYPE_PROTOTYPED (ftype
) = 1;
8057 /* Store the calling convention in the type if it's available in
8058 the subroutine die. Otherwise set the calling convention to
8059 the default value DW_CC_normal. */
8060 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8062 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8063 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8064 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8066 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8068 /* We need to add the subroutine type to the die immediately so
8069 we don't infinitely recurse when dealing with parameters
8070 declared as the same subroutine type. */
8071 set_die_type (die
, ftype
, cu
);
8073 if (die
->child
!= NULL
)
8075 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
8076 struct die_info
*child_die
;
8077 int nparams
, iparams
;
8079 /* Count the number of parameters.
8080 FIXME: GDB currently ignores vararg functions, but knows about
8081 vararg member functions. */
8083 child_die
= die
->child
;
8084 while (child_die
&& child_die
->tag
)
8086 if (child_die
->tag
== DW_TAG_formal_parameter
)
8088 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8089 TYPE_VARARGS (ftype
) = 1;
8090 child_die
= sibling_die (child_die
);
8093 /* Allocate storage for parameters and fill them in. */
8094 TYPE_NFIELDS (ftype
) = nparams
;
8095 TYPE_FIELDS (ftype
) = (struct field
*)
8096 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8098 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8099 even if we error out during the parameters reading below. */
8100 for (iparams
= 0; iparams
< nparams
; iparams
++)
8101 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8104 child_die
= die
->child
;
8105 while (child_die
&& child_die
->tag
)
8107 if (child_die
->tag
== DW_TAG_formal_parameter
)
8109 struct type
*arg_type
;
8111 /* DWARF version 2 has no clean way to discern C++
8112 static and non-static member functions. G++ helps
8113 GDB by marking the first parameter for non-static
8114 member functions (which is the this pointer) as
8115 artificial. We pass this information to
8116 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8118 DWARF version 3 added DW_AT_object_pointer, which GCC
8119 4.5 does not yet generate. */
8120 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8122 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8125 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8127 /* GCC/43521: In java, the formal parameter
8128 "this" is sometimes not marked with DW_AT_artificial. */
8129 if (cu
->language
== language_java
)
8131 const char *name
= dwarf2_name (child_die
, cu
);
8133 if (name
&& !strcmp (name
, "this"))
8134 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8137 arg_type
= die_type (child_die
, cu
);
8139 /* RealView does not mark THIS as const, which the testsuite
8140 expects. GCC marks THIS as const in method definitions,
8141 but not in the class specifications (GCC PR 43053). */
8142 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8143 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8146 struct dwarf2_cu
*arg_cu
= cu
;
8147 const char *name
= dwarf2_name (child_die
, cu
);
8149 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8152 /* If the compiler emits this, use it. */
8153 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8156 else if (name
&& strcmp (name
, "this") == 0)
8157 /* Function definitions will have the argument names. */
8159 else if (name
== NULL
&& iparams
== 0)
8160 /* Declarations may not have the names, so like
8161 elsewhere in GDB, assume an artificial first
8162 argument is "this". */
8166 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8170 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8173 child_die
= sibling_die (child_die
);
8180 static struct type
*
8181 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8183 struct objfile
*objfile
= cu
->objfile
;
8184 const char *name
= NULL
;
8185 struct type
*this_type
;
8187 name
= dwarf2_full_name (NULL
, die
, cu
);
8188 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8189 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8190 TYPE_NAME (this_type
) = (char *) name
;
8191 set_die_type (die
, this_type
, cu
);
8192 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
8196 /* Find a representation of a given base type and install
8197 it in the TYPE field of the die. */
8199 static struct type
*
8200 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8202 struct objfile
*objfile
= cu
->objfile
;
8204 struct attribute
*attr
;
8205 int encoding
= 0, size
= 0;
8207 enum type_code code
= TYPE_CODE_INT
;
8209 struct type
*target_type
= NULL
;
8211 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8214 encoding
= DW_UNSND (attr
);
8216 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8219 size
= DW_UNSND (attr
);
8221 name
= dwarf2_name (die
, cu
);
8224 complaint (&symfile_complaints
,
8225 _("DW_AT_name missing from DW_TAG_base_type"));
8230 case DW_ATE_address
:
8231 /* Turn DW_ATE_address into a void * pointer. */
8232 code
= TYPE_CODE_PTR
;
8233 type_flags
|= TYPE_FLAG_UNSIGNED
;
8234 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8236 case DW_ATE_boolean
:
8237 code
= TYPE_CODE_BOOL
;
8238 type_flags
|= TYPE_FLAG_UNSIGNED
;
8240 case DW_ATE_complex_float
:
8241 code
= TYPE_CODE_COMPLEX
;
8242 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8244 case DW_ATE_decimal_float
:
8245 code
= TYPE_CODE_DECFLOAT
;
8248 code
= TYPE_CODE_FLT
;
8252 case DW_ATE_unsigned
:
8253 type_flags
|= TYPE_FLAG_UNSIGNED
;
8255 case DW_ATE_signed_char
:
8256 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8257 || cu
->language
== language_pascal
)
8258 code
= TYPE_CODE_CHAR
;
8260 case DW_ATE_unsigned_char
:
8261 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8262 || cu
->language
== language_pascal
)
8263 code
= TYPE_CODE_CHAR
;
8264 type_flags
|= TYPE_FLAG_UNSIGNED
;
8267 /* We just treat this as an integer and then recognize the
8268 type by name elsewhere. */
8272 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8273 dwarf_type_encoding_name (encoding
));
8277 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8278 TYPE_NAME (type
) = name
;
8279 TYPE_TARGET_TYPE (type
) = target_type
;
8281 if (name
&& strcmp (name
, "char") == 0)
8282 TYPE_NOSIGN (type
) = 1;
8284 return set_die_type (die
, type
, cu
);
8287 /* Read the given DW_AT_subrange DIE. */
8289 static struct type
*
8290 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8292 struct type
*base_type
;
8293 struct type
*range_type
;
8294 struct attribute
*attr
;
8298 LONGEST negative_mask
;
8300 base_type
= die_type (die
, cu
);
8301 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8302 check_typedef (base_type
);
8304 /* The die_type call above may have already set the type for this DIE. */
8305 range_type
= get_die_type (die
, cu
);
8309 if (cu
->language
== language_fortran
)
8311 /* FORTRAN implies a lower bound of 1, if not given. */
8315 /* FIXME: For variable sized arrays either of these could be
8316 a variable rather than a constant value. We'll allow it,
8317 but we don't know how to handle it. */
8318 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8320 low
= dwarf2_get_attr_constant_value (attr
, 0);
8322 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8325 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
8327 /* GCC encodes arrays with unspecified or dynamic length
8328 with a DW_FORM_block1 attribute or a reference attribute.
8329 FIXME: GDB does not yet know how to handle dynamic
8330 arrays properly, treat them as arrays with unspecified
8333 FIXME: jimb/2003-09-22: GDB does not really know
8334 how to handle arrays of unspecified length
8335 either; we just represent them as zero-length
8336 arrays. Choose an appropriate upper bound given
8337 the lower bound we've computed above. */
8341 high
= dwarf2_get_attr_constant_value (attr
, 1);
8345 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8348 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8349 high
= low
+ count
- 1;
8353 /* Unspecified array length. */
8358 /* Dwarf-2 specifications explicitly allows to create subrange types
8359 without specifying a base type.
8360 In that case, the base type must be set to the type of
8361 the lower bound, upper bound or count, in that order, if any of these
8362 three attributes references an object that has a type.
8363 If no base type is found, the Dwarf-2 specifications say that
8364 a signed integer type of size equal to the size of an address should
8366 For the following C code: `extern char gdb_int [];'
8367 GCC produces an empty range DIE.
8368 FIXME: muller/2010-05-28: Possible references to object for low bound,
8369 high bound or count are not yet handled by this code. */
8370 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8372 struct objfile
*objfile
= cu
->objfile
;
8373 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8374 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8375 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8377 /* Test "int", "long int", and "long long int" objfile types,
8378 and select the first one having a size above or equal to the
8379 architecture address size. */
8380 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8381 base_type
= int_type
;
8384 int_type
= objfile_type (objfile
)->builtin_long
;
8385 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8386 base_type
= int_type
;
8389 int_type
= objfile_type (objfile
)->builtin_long_long
;
8390 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8391 base_type
= int_type
;
8397 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8398 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8399 low
|= negative_mask
;
8400 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8401 high
|= negative_mask
;
8403 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8405 /* Mark arrays with dynamic length at least as an array of unspecified
8406 length. GDB could check the boundary but before it gets implemented at
8407 least allow accessing the array elements. */
8408 if (attr
&& attr
->form
== DW_FORM_block1
)
8409 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8411 /* Ada expects an empty array on no boundary attributes. */
8412 if (attr
== NULL
&& cu
->language
!= language_ada
)
8413 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8415 name
= dwarf2_name (die
, cu
);
8417 TYPE_NAME (range_type
) = name
;
8419 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8421 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8423 set_die_type (die
, range_type
, cu
);
8425 /* set_die_type should be already done. */
8426 set_descriptive_type (range_type
, die
, cu
);
8431 static struct type
*
8432 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8436 /* For now, we only support the C meaning of an unspecified type: void. */
8438 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8439 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8441 return set_die_type (die
, type
, cu
);
8444 /* Trivial hash function for die_info: the hash value of a DIE
8445 is its offset in .debug_info for this objfile. */
8448 die_hash (const void *item
)
8450 const struct die_info
*die
= item
;
8455 /* Trivial comparison function for die_info structures: two DIEs
8456 are equal if they have the same offset. */
8459 die_eq (const void *item_lhs
, const void *item_rhs
)
8461 const struct die_info
*die_lhs
= item_lhs
;
8462 const struct die_info
*die_rhs
= item_rhs
;
8464 return die_lhs
->offset
== die_rhs
->offset
;
8467 /* Read a whole compilation unit into a linked list of dies. */
8469 static struct die_info
*
8470 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8472 struct die_reader_specs reader_specs
;
8473 int read_abbrevs
= 0;
8474 struct cleanup
*back_to
= NULL
;
8475 struct die_info
*die
;
8477 if (cu
->dwarf2_abbrevs
== NULL
)
8479 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8480 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8484 gdb_assert (cu
->die_hash
== NULL
);
8486 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8490 &cu
->comp_unit_obstack
,
8491 hashtab_obstack_allocate
,
8492 dummy_obstack_deallocate
);
8494 init_cu_die_reader (&reader_specs
, cu
);
8496 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8499 do_cleanups (back_to
);
8504 /* Main entry point for reading a DIE and all children.
8505 Read the DIE and dump it if requested. */
8507 static struct die_info
*
8508 read_die_and_children (const struct die_reader_specs
*reader
,
8510 gdb_byte
**new_info_ptr
,
8511 struct die_info
*parent
)
8513 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8514 new_info_ptr
, parent
);
8516 if (dwarf2_die_debug
)
8518 fprintf_unfiltered (gdb_stdlog
,
8519 "\nRead die from %s of %s:\n",
8520 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8522 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8524 : "unknown section",
8525 reader
->abfd
->filename
);
8526 dump_die (result
, dwarf2_die_debug
);
8532 /* Read a single die and all its descendents. Set the die's sibling
8533 field to NULL; set other fields in the die correctly, and set all
8534 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8535 location of the info_ptr after reading all of those dies. PARENT
8536 is the parent of the die in question. */
8538 static struct die_info
*
8539 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8541 gdb_byte
**new_info_ptr
,
8542 struct die_info
*parent
)
8544 struct die_info
*die
;
8548 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8551 *new_info_ptr
= cur_ptr
;
8554 store_in_ref_table (die
, reader
->cu
);
8557 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8561 *new_info_ptr
= cur_ptr
;
8564 die
->sibling
= NULL
;
8565 die
->parent
= parent
;
8569 /* Read a die, all of its descendents, and all of its siblings; set
8570 all of the fields of all of the dies correctly. Arguments are as
8571 in read_die_and_children. */
8573 static struct die_info
*
8574 read_die_and_siblings (const struct die_reader_specs
*reader
,
8576 gdb_byte
**new_info_ptr
,
8577 struct die_info
*parent
)
8579 struct die_info
*first_die
, *last_sibling
;
8583 first_die
= last_sibling
= NULL
;
8587 struct die_info
*die
8588 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8592 *new_info_ptr
= cur_ptr
;
8599 last_sibling
->sibling
= die
;
8605 /* Read the die from the .debug_info section buffer. Set DIEP to
8606 point to a newly allocated die with its information, except for its
8607 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8608 whether the die has children or not. */
8611 read_full_die (const struct die_reader_specs
*reader
,
8612 struct die_info
**diep
, gdb_byte
*info_ptr
,
8615 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8616 struct abbrev_info
*abbrev
;
8617 struct die_info
*die
;
8618 struct dwarf2_cu
*cu
= reader
->cu
;
8619 bfd
*abfd
= reader
->abfd
;
8621 offset
= info_ptr
- reader
->buffer
;
8622 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8623 info_ptr
+= bytes_read
;
8631 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8633 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8635 bfd_get_filename (abfd
));
8637 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8638 die
->offset
= offset
;
8639 die
->tag
= abbrev
->tag
;
8640 die
->abbrev
= abbrev_number
;
8642 die
->num_attrs
= abbrev
->num_attrs
;
8644 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8645 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8646 abfd
, info_ptr
, cu
);
8649 *has_children
= abbrev
->has_children
;
8653 /* In DWARF version 2, the description of the debugging information is
8654 stored in a separate .debug_abbrev section. Before we read any
8655 dies from a section we read in all abbreviations and install them
8656 in a hash table. This function also sets flags in CU describing
8657 the data found in the abbrev table. */
8660 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8662 struct comp_unit_head
*cu_header
= &cu
->header
;
8663 gdb_byte
*abbrev_ptr
;
8664 struct abbrev_info
*cur_abbrev
;
8665 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8666 unsigned int abbrev_form
, hash_number
;
8667 struct attr_abbrev
*cur_attrs
;
8668 unsigned int allocated_attrs
;
8670 /* Initialize dwarf2 abbrevs. */
8671 obstack_init (&cu
->abbrev_obstack
);
8672 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8674 * sizeof (struct abbrev_info
*)));
8675 memset (cu
->dwarf2_abbrevs
, 0,
8676 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8678 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8679 &dwarf2_per_objfile
->abbrev
);
8680 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8681 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8682 abbrev_ptr
+= bytes_read
;
8684 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8685 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8687 /* Loop until we reach an abbrev number of 0. */
8688 while (abbrev_number
)
8690 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8692 /* read in abbrev header */
8693 cur_abbrev
->number
= abbrev_number
;
8694 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8695 abbrev_ptr
+= bytes_read
;
8696 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8699 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8700 cu
->has_namespace_info
= 1;
8702 /* now read in declarations */
8703 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8704 abbrev_ptr
+= bytes_read
;
8705 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8706 abbrev_ptr
+= bytes_read
;
8709 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8711 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8713 = xrealloc (cur_attrs
, (allocated_attrs
8714 * sizeof (struct attr_abbrev
)));
8717 /* Record whether this compilation unit might have
8718 inter-compilation-unit references. If we don't know what form
8719 this attribute will have, then it might potentially be a
8720 DW_FORM_ref_addr, so we conservatively expect inter-CU
8723 if (abbrev_form
== DW_FORM_ref_addr
8724 || abbrev_form
== DW_FORM_indirect
)
8725 cu
->has_form_ref_addr
= 1;
8727 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8728 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8729 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8730 abbrev_ptr
+= bytes_read
;
8731 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8732 abbrev_ptr
+= bytes_read
;
8735 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8736 (cur_abbrev
->num_attrs
8737 * sizeof (struct attr_abbrev
)));
8738 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8739 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8741 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8742 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8743 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8745 /* Get next abbreviation.
8746 Under Irix6 the abbreviations for a compilation unit are not
8747 always properly terminated with an abbrev number of 0.
8748 Exit loop if we encounter an abbreviation which we have
8749 already read (which means we are about to read the abbreviations
8750 for the next compile unit) or if the end of the abbreviation
8751 table is reached. */
8752 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8753 >= dwarf2_per_objfile
->abbrev
.size
)
8755 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8756 abbrev_ptr
+= bytes_read
;
8757 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
8764 /* Release the memory used by the abbrev table for a compilation unit. */
8767 dwarf2_free_abbrev_table (void *ptr_to_cu
)
8769 struct dwarf2_cu
*cu
= ptr_to_cu
;
8771 obstack_free (&cu
->abbrev_obstack
, NULL
);
8772 cu
->dwarf2_abbrevs
= NULL
;
8775 /* Lookup an abbrev_info structure in the abbrev hash table. */
8777 static struct abbrev_info
*
8778 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
8780 unsigned int hash_number
;
8781 struct abbrev_info
*abbrev
;
8783 hash_number
= number
% ABBREV_HASH_SIZE
;
8784 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
8788 if (abbrev
->number
== number
)
8791 abbrev
= abbrev
->next
;
8796 /* Returns nonzero if TAG represents a type that we might generate a partial
8800 is_type_tag_for_partial (int tag
)
8805 /* Some types that would be reasonable to generate partial symbols for,
8806 that we don't at present. */
8807 case DW_TAG_array_type
:
8808 case DW_TAG_file_type
:
8809 case DW_TAG_ptr_to_member_type
:
8810 case DW_TAG_set_type
:
8811 case DW_TAG_string_type
:
8812 case DW_TAG_subroutine_type
:
8814 case DW_TAG_base_type
:
8815 case DW_TAG_class_type
:
8816 case DW_TAG_interface_type
:
8817 case DW_TAG_enumeration_type
:
8818 case DW_TAG_structure_type
:
8819 case DW_TAG_subrange_type
:
8820 case DW_TAG_typedef
:
8821 case DW_TAG_union_type
:
8828 /* Load all DIEs that are interesting for partial symbols into memory. */
8830 static struct partial_die_info
*
8831 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8832 int building_psymtab
, struct dwarf2_cu
*cu
)
8834 struct partial_die_info
*part_die
;
8835 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
8836 struct abbrev_info
*abbrev
;
8837 unsigned int bytes_read
;
8838 unsigned int load_all
= 0;
8840 int nesting_level
= 1;
8845 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
8849 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8853 &cu
->comp_unit_obstack
,
8854 hashtab_obstack_allocate
,
8855 dummy_obstack_deallocate
);
8857 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8858 sizeof (struct partial_die_info
));
8862 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
8864 /* A NULL abbrev means the end of a series of children. */
8867 if (--nesting_level
== 0)
8869 /* PART_DIE was probably the last thing allocated on the
8870 comp_unit_obstack, so we could call obstack_free
8871 here. We don't do that because the waste is small,
8872 and will be cleaned up when we're done with this
8873 compilation unit. This way, we're also more robust
8874 against other users of the comp_unit_obstack. */
8877 info_ptr
+= bytes_read
;
8878 last_die
= parent_die
;
8879 parent_die
= parent_die
->die_parent
;
8883 /* Check for template arguments. We never save these; if
8884 they're seen, we just mark the parent, and go on our way. */
8885 if (parent_die
!= NULL
8886 && cu
->language
== language_cplus
8887 && (abbrev
->tag
== DW_TAG_template_type_param
8888 || abbrev
->tag
== DW_TAG_template_value_param
))
8890 parent_die
->has_template_arguments
= 1;
8894 /* We don't need a partial DIE for the template argument. */
8895 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
8901 /* We only recurse into subprograms looking for template arguments.
8902 Skip their other children. */
8904 && cu
->language
== language_cplus
8905 && parent_die
!= NULL
8906 && parent_die
->tag
== DW_TAG_subprogram
)
8908 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8912 /* Check whether this DIE is interesting enough to save. Normally
8913 we would not be interested in members here, but there may be
8914 later variables referencing them via DW_AT_specification (for
8917 && !is_type_tag_for_partial (abbrev
->tag
)
8918 && abbrev
->tag
!= DW_TAG_constant
8919 && abbrev
->tag
!= DW_TAG_enumerator
8920 && abbrev
->tag
!= DW_TAG_subprogram
8921 && abbrev
->tag
!= DW_TAG_lexical_block
8922 && abbrev
->tag
!= DW_TAG_variable
8923 && abbrev
->tag
!= DW_TAG_namespace
8924 && abbrev
->tag
!= DW_TAG_module
8925 && abbrev
->tag
!= DW_TAG_member
)
8927 /* Otherwise we skip to the next sibling, if any. */
8928 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8932 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
8933 buffer
, info_ptr
, cu
);
8935 /* This two-pass algorithm for processing partial symbols has a
8936 high cost in cache pressure. Thus, handle some simple cases
8937 here which cover the majority of C partial symbols. DIEs
8938 which neither have specification tags in them, nor could have
8939 specification tags elsewhere pointing at them, can simply be
8940 processed and discarded.
8942 This segment is also optional; scan_partial_symbols and
8943 add_partial_symbol will handle these DIEs if we chain
8944 them in normally. When compilers which do not emit large
8945 quantities of duplicate debug information are more common,
8946 this code can probably be removed. */
8948 /* Any complete simple types at the top level (pretty much all
8949 of them, for a language without namespaces), can be processed
8951 if (parent_die
== NULL
8952 && part_die
->has_specification
== 0
8953 && part_die
->is_declaration
== 0
8954 && (part_die
->tag
== DW_TAG_typedef
8955 || part_die
->tag
== DW_TAG_base_type
8956 || part_die
->tag
== DW_TAG_subrange_type
))
8958 if (building_psymtab
&& part_die
->name
!= NULL
)
8959 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8960 VAR_DOMAIN
, LOC_TYPEDEF
,
8961 &cu
->objfile
->static_psymbols
,
8962 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8963 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8967 /* If we're at the second level, and we're an enumerator, and
8968 our parent has no specification (meaning possibly lives in a
8969 namespace elsewhere), then we can add the partial symbol now
8970 instead of queueing it. */
8971 if (part_die
->tag
== DW_TAG_enumerator
8972 && parent_die
!= NULL
8973 && parent_die
->die_parent
== NULL
8974 && parent_die
->tag
== DW_TAG_enumeration_type
8975 && parent_die
->has_specification
== 0)
8977 if (part_die
->name
== NULL
)
8978 complaint (&symfile_complaints
,
8979 _("malformed enumerator DIE ignored"));
8980 else if (building_psymtab
)
8981 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8982 VAR_DOMAIN
, LOC_CONST
,
8983 (cu
->language
== language_cplus
8984 || cu
->language
== language_java
)
8985 ? &cu
->objfile
->global_psymbols
8986 : &cu
->objfile
->static_psymbols
,
8987 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8989 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8993 /* We'll save this DIE so link it in. */
8994 part_die
->die_parent
= parent_die
;
8995 part_die
->die_sibling
= NULL
;
8996 part_die
->die_child
= NULL
;
8998 if (last_die
&& last_die
== parent_die
)
8999 last_die
->die_child
= part_die
;
9001 last_die
->die_sibling
= part_die
;
9003 last_die
= part_die
;
9005 if (first_die
== NULL
)
9006 first_die
= part_die
;
9008 /* Maybe add the DIE to the hash table. Not all DIEs that we
9009 find interesting need to be in the hash table, because we
9010 also have the parent/sibling/child chains; only those that we
9011 might refer to by offset later during partial symbol reading.
9013 For now this means things that might have be the target of a
9014 DW_AT_specification, DW_AT_abstract_origin, or
9015 DW_AT_extension. DW_AT_extension will refer only to
9016 namespaces; DW_AT_abstract_origin refers to functions (and
9017 many things under the function DIE, but we do not recurse
9018 into function DIEs during partial symbol reading) and
9019 possibly variables as well; DW_AT_specification refers to
9020 declarations. Declarations ought to have the DW_AT_declaration
9021 flag. It happens that GCC forgets to put it in sometimes, but
9022 only for functions, not for types.
9024 Adding more things than necessary to the hash table is harmless
9025 except for the performance cost. Adding too few will result in
9026 wasted time in find_partial_die, when we reread the compilation
9027 unit with load_all_dies set. */
9030 || abbrev
->tag
== DW_TAG_constant
9031 || abbrev
->tag
== DW_TAG_subprogram
9032 || abbrev
->tag
== DW_TAG_variable
9033 || abbrev
->tag
== DW_TAG_namespace
9034 || part_die
->is_declaration
)
9038 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9039 part_die
->offset
, INSERT
);
9043 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9044 sizeof (struct partial_die_info
));
9046 /* For some DIEs we want to follow their children (if any). For C
9047 we have no reason to follow the children of structures; for other
9048 languages we have to, so that we can get at method physnames
9049 to infer fully qualified class names, for DW_AT_specification,
9050 and for C++ template arguments. For C++, we also look one level
9051 inside functions to find template arguments (if the name of the
9052 function does not already contain the template arguments).
9054 For Ada, we need to scan the children of subprograms and lexical
9055 blocks as well because Ada allows the definition of nested
9056 entities that could be interesting for the debugger, such as
9057 nested subprograms for instance. */
9058 if (last_die
->has_children
9060 || last_die
->tag
== DW_TAG_namespace
9061 || last_die
->tag
== DW_TAG_module
9062 || last_die
->tag
== DW_TAG_enumeration_type
9063 || (cu
->language
== language_cplus
9064 && last_die
->tag
== DW_TAG_subprogram
9065 && (last_die
->name
== NULL
9066 || strchr (last_die
->name
, '<') == NULL
))
9067 || (cu
->language
!= language_c
9068 && (last_die
->tag
== DW_TAG_class_type
9069 || last_die
->tag
== DW_TAG_interface_type
9070 || last_die
->tag
== DW_TAG_structure_type
9071 || last_die
->tag
== DW_TAG_union_type
))
9072 || (cu
->language
== language_ada
9073 && (last_die
->tag
== DW_TAG_subprogram
9074 || last_die
->tag
== DW_TAG_lexical_block
))))
9077 parent_die
= last_die
;
9081 /* Otherwise we skip to the next sibling, if any. */
9082 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9084 /* Back to the top, do it again. */
9088 /* Read a minimal amount of information into the minimal die structure. */
9091 read_partial_die (struct partial_die_info
*part_die
,
9092 struct abbrev_info
*abbrev
,
9093 unsigned int abbrev_len
, bfd
*abfd
,
9094 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9095 struct dwarf2_cu
*cu
)
9098 struct attribute attr
;
9099 int has_low_pc_attr
= 0;
9100 int has_high_pc_attr
= 0;
9102 memset (part_die
, 0, sizeof (struct partial_die_info
));
9104 part_die
->offset
= info_ptr
- buffer
;
9106 info_ptr
+= abbrev_len
;
9111 part_die
->tag
= abbrev
->tag
;
9112 part_die
->has_children
= abbrev
->has_children
;
9114 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9116 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9118 /* Store the data if it is of an attribute we want to keep in a
9119 partial symbol table. */
9123 switch (part_die
->tag
)
9125 case DW_TAG_compile_unit
:
9126 case DW_TAG_type_unit
:
9127 /* Compilation units have a DW_AT_name that is a filename, not
9128 a source language identifier. */
9129 case DW_TAG_enumeration_type
:
9130 case DW_TAG_enumerator
:
9131 /* These tags always have simple identifiers already; no need
9132 to canonicalize them. */
9133 part_die
->name
= DW_STRING (&attr
);
9137 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9138 &cu
->objfile
->objfile_obstack
);
9142 case DW_AT_linkage_name
:
9143 case DW_AT_MIPS_linkage_name
:
9144 /* Note that both forms of linkage name might appear. We
9145 assume they will be the same, and we only store the last
9147 if (cu
->language
== language_ada
)
9148 part_die
->name
= DW_STRING (&attr
);
9149 part_die
->linkage_name
= DW_STRING (&attr
);
9152 has_low_pc_attr
= 1;
9153 part_die
->lowpc
= DW_ADDR (&attr
);
9156 has_high_pc_attr
= 1;
9157 part_die
->highpc
= DW_ADDR (&attr
);
9159 case DW_AT_location
:
9160 /* Support the .debug_loc offsets. */
9161 if (attr_form_is_block (&attr
))
9163 part_die
->locdesc
= DW_BLOCK (&attr
);
9165 else if (attr_form_is_section_offset (&attr
))
9167 dwarf2_complex_location_expr_complaint ();
9171 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9172 "partial symbol information");
9175 case DW_AT_external
:
9176 part_die
->is_external
= DW_UNSND (&attr
);
9178 case DW_AT_declaration
:
9179 part_die
->is_declaration
= DW_UNSND (&attr
);
9182 part_die
->has_type
= 1;
9184 case DW_AT_abstract_origin
:
9185 case DW_AT_specification
:
9186 case DW_AT_extension
:
9187 part_die
->has_specification
= 1;
9188 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9191 /* Ignore absolute siblings, they might point outside of
9192 the current compile unit. */
9193 if (attr
.form
== DW_FORM_ref_addr
)
9194 complaint (&symfile_complaints
,
9195 _("ignoring absolute DW_AT_sibling"));
9197 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9199 case DW_AT_byte_size
:
9200 part_die
->has_byte_size
= 1;
9202 case DW_AT_calling_convention
:
9203 /* DWARF doesn't provide a way to identify a program's source-level
9204 entry point. DW_AT_calling_convention attributes are only meant
9205 to describe functions' calling conventions.
9207 However, because it's a necessary piece of information in
9208 Fortran, and because DW_CC_program is the only piece of debugging
9209 information whose definition refers to a 'main program' at all,
9210 several compilers have begun marking Fortran main programs with
9211 DW_CC_program --- even when those functions use the standard
9212 calling conventions.
9214 So until DWARF specifies a way to provide this information and
9215 compilers pick up the new representation, we'll support this
9217 if (DW_UNSND (&attr
) == DW_CC_program
9218 && cu
->language
== language_fortran
)
9220 set_main_name (part_die
->name
);
9222 /* As this DIE has a static linkage the name would be difficult
9223 to look up later. */
9224 language_of_main
= language_fortran
;
9232 if (has_low_pc_attr
&& has_high_pc_attr
)
9234 /* When using the GNU linker, .gnu.linkonce. sections are used to
9235 eliminate duplicate copies of functions and vtables and such.
9236 The linker will arbitrarily choose one and discard the others.
9237 The AT_*_pc values for such functions refer to local labels in
9238 these sections. If the section from that file was discarded, the
9239 labels are not in the output, so the relocs get a value of 0.
9240 If this is a discarded function, mark the pc bounds as invalid,
9241 so that GDB will ignore it. */
9242 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9244 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9246 complaint (&symfile_complaints
,
9247 _("DW_AT_low_pc %s is zero "
9248 "for DIE at 0x%x [in module %s]"),
9249 paddress (gdbarch
, part_die
->lowpc
),
9250 part_die
->offset
, cu
->objfile
->name
);
9252 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9253 else if (part_die
->lowpc
>= part_die
->highpc
)
9255 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9257 complaint (&symfile_complaints
,
9258 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9259 "for DIE at 0x%x [in module %s]"),
9260 paddress (gdbarch
, part_die
->lowpc
),
9261 paddress (gdbarch
, part_die
->highpc
),
9262 part_die
->offset
, cu
->objfile
->name
);
9265 part_die
->has_pc_info
= 1;
9271 /* Find a cached partial DIE at OFFSET in CU. */
9273 static struct partial_die_info
*
9274 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9276 struct partial_die_info
*lookup_die
= NULL
;
9277 struct partial_die_info part_die
;
9279 part_die
.offset
= offset
;
9280 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9285 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9286 except in the case of .debug_types DIEs which do not reference
9287 outside their CU (they do however referencing other types via
9288 DW_FORM_ref_sig8). */
9290 static struct partial_die_info
*
9291 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9293 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9294 struct partial_die_info
*pd
= NULL
;
9296 if (cu
->per_cu
->from_debug_types
)
9298 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9304 if (offset_in_cu_p (&cu
->header
, offset
))
9306 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9311 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9313 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9314 load_partial_comp_unit (per_cu
, cu
->objfile
);
9316 per_cu
->cu
->last_used
= 0;
9317 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9319 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9321 struct cleanup
*back_to
;
9322 struct partial_die_info comp_unit_die
;
9323 struct abbrev_info
*abbrev
;
9324 unsigned int bytes_read
;
9327 per_cu
->load_all_dies
= 1;
9329 /* Re-read the DIEs. */
9330 back_to
= make_cleanup (null_cleanup
, 0);
9331 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9333 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
9334 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9336 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9337 + per_cu
->cu
->header
.offset
9338 + per_cu
->cu
->header
.first_die_offset
);
9339 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9340 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9341 per_cu
->cu
->objfile
->obfd
,
9342 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9344 if (comp_unit_die
.has_children
)
9345 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
9346 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9348 do_cleanups (back_to
);
9350 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9356 internal_error (__FILE__
, __LINE__
,
9357 _("could not find partial DIE 0x%x "
9358 "in cache [from module %s]\n"),
9359 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9363 /* See if we can figure out if the class lives in a namespace. We do
9364 this by looking for a member function; its demangled name will
9365 contain namespace info, if there is any. */
9368 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9369 struct dwarf2_cu
*cu
)
9371 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9372 what template types look like, because the demangler
9373 frequently doesn't give the same name as the debug info. We
9374 could fix this by only using the demangled name to get the
9375 prefix (but see comment in read_structure_type). */
9377 struct partial_die_info
*real_pdi
;
9378 struct partial_die_info
*child_pdi
;
9380 /* If this DIE (this DIE's specification, if any) has a parent, then
9381 we should not do this. We'll prepend the parent's fully qualified
9382 name when we create the partial symbol. */
9384 real_pdi
= struct_pdi
;
9385 while (real_pdi
->has_specification
)
9386 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9388 if (real_pdi
->die_parent
!= NULL
)
9391 for (child_pdi
= struct_pdi
->die_child
;
9393 child_pdi
= child_pdi
->die_sibling
)
9395 if (child_pdi
->tag
== DW_TAG_subprogram
9396 && child_pdi
->linkage_name
!= NULL
)
9398 char *actual_class_name
9399 = language_class_name_from_physname (cu
->language_defn
,
9400 child_pdi
->linkage_name
);
9401 if (actual_class_name
!= NULL
)
9404 = obsavestring (actual_class_name
,
9405 strlen (actual_class_name
),
9406 &cu
->objfile
->objfile_obstack
);
9407 xfree (actual_class_name
);
9414 /* Adjust PART_DIE before generating a symbol for it. This function
9415 may set the is_external flag or change the DIE's name. */
9418 fixup_partial_die (struct partial_die_info
*part_die
,
9419 struct dwarf2_cu
*cu
)
9421 /* Once we've fixed up a die, there's no point in doing so again.
9422 This also avoids a memory leak if we were to call
9423 guess_partial_die_structure_name multiple times. */
9424 if (part_die
->fixup_called
)
9427 /* If we found a reference attribute and the DIE has no name, try
9428 to find a name in the referred to DIE. */
9430 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9432 struct partial_die_info
*spec_die
;
9434 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9436 fixup_partial_die (spec_die
, cu
);
9440 part_die
->name
= spec_die
->name
;
9442 /* Copy DW_AT_external attribute if it is set. */
9443 if (spec_die
->is_external
)
9444 part_die
->is_external
= spec_die
->is_external
;
9448 /* Set default names for some unnamed DIEs. */
9450 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9451 part_die
->name
= "(anonymous namespace)";
9453 /* If there is no parent die to provide a namespace, and there are
9454 children, see if we can determine the namespace from their linkage
9456 NOTE: We need to do this even if cu->has_namespace_info != 0.
9457 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9458 if (cu
->language
== language_cplus
9459 && dwarf2_per_objfile
->types
.asection
!= NULL
9460 && part_die
->die_parent
== NULL
9461 && part_die
->has_children
9462 && (part_die
->tag
== DW_TAG_class_type
9463 || part_die
->tag
== DW_TAG_structure_type
9464 || part_die
->tag
== DW_TAG_union_type
))
9465 guess_partial_die_structure_name (part_die
, cu
);
9467 /* GCC might emit a nameless struct or union that has a linkage
9468 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
9469 if (part_die
->name
== NULL
9470 && (part_die
->tag
== DW_TAG_structure_type
9471 || part_die
->tag
== DW_TAG_union_type
9472 || part_die
->tag
== DW_TAG_class_type
)
9473 && part_die
->linkage_name
!= NULL
)
9477 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
9480 part_die
->name
= obsavestring (demangled
, strlen (demangled
),
9481 &cu
->objfile
->objfile_obstack
);
9486 part_die
->fixup_called
= 1;
9489 /* Read an attribute value described by an attribute form. */
9492 read_attribute_value (struct attribute
*attr
, unsigned form
,
9493 bfd
*abfd
, gdb_byte
*info_ptr
,
9494 struct dwarf2_cu
*cu
)
9496 struct comp_unit_head
*cu_header
= &cu
->header
;
9497 unsigned int bytes_read
;
9498 struct dwarf_block
*blk
;
9503 case DW_FORM_ref_addr
:
9504 if (cu
->header
.version
== 2)
9505 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9507 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
9508 &cu
->header
, &bytes_read
);
9509 info_ptr
+= bytes_read
;
9512 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9513 info_ptr
+= bytes_read
;
9515 case DW_FORM_block2
:
9516 blk
= dwarf_alloc_block (cu
);
9517 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9519 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9520 info_ptr
+= blk
->size
;
9521 DW_BLOCK (attr
) = blk
;
9523 case DW_FORM_block4
:
9524 blk
= dwarf_alloc_block (cu
);
9525 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9527 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9528 info_ptr
+= blk
->size
;
9529 DW_BLOCK (attr
) = blk
;
9532 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9536 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9540 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9543 case DW_FORM_sec_offset
:
9544 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9545 info_ptr
+= bytes_read
;
9547 case DW_FORM_string
:
9548 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9549 DW_STRING_IS_CANONICAL (attr
) = 0;
9550 info_ptr
+= bytes_read
;
9553 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9555 DW_STRING_IS_CANONICAL (attr
) = 0;
9556 info_ptr
+= bytes_read
;
9558 case DW_FORM_exprloc
:
9560 blk
= dwarf_alloc_block (cu
);
9561 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9562 info_ptr
+= bytes_read
;
9563 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9564 info_ptr
+= blk
->size
;
9565 DW_BLOCK (attr
) = blk
;
9567 case DW_FORM_block1
:
9568 blk
= dwarf_alloc_block (cu
);
9569 blk
->size
= read_1_byte (abfd
, info_ptr
);
9571 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9572 info_ptr
+= blk
->size
;
9573 DW_BLOCK (attr
) = blk
;
9576 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9580 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9583 case DW_FORM_flag_present
:
9584 DW_UNSND (attr
) = 1;
9587 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9588 info_ptr
+= bytes_read
;
9591 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9592 info_ptr
+= bytes_read
;
9595 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9599 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9603 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9607 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9610 case DW_FORM_ref_sig8
:
9611 /* Convert the signature to something we can record in DW_UNSND
9613 NOTE: This is NULL if the type wasn't found. */
9614 DW_SIGNATURED_TYPE (attr
) =
9615 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9618 case DW_FORM_ref_udata
:
9619 DW_ADDR (attr
) = (cu
->header
.offset
9620 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9621 info_ptr
+= bytes_read
;
9623 case DW_FORM_indirect
:
9624 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9625 info_ptr
+= bytes_read
;
9626 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9629 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9630 dwarf_form_name (form
),
9631 bfd_get_filename (abfd
));
9634 /* We have seen instances where the compiler tried to emit a byte
9635 size attribute of -1 which ended up being encoded as an unsigned
9636 0xffffffff. Although 0xffffffff is technically a valid size value,
9637 an object of this size seems pretty unlikely so we can relatively
9638 safely treat these cases as if the size attribute was invalid and
9639 treat them as zero by default. */
9640 if (attr
->name
== DW_AT_byte_size
9641 && form
== DW_FORM_data4
9642 && DW_UNSND (attr
) >= 0xffffffff)
9645 (&symfile_complaints
,
9646 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9647 hex_string (DW_UNSND (attr
)));
9648 DW_UNSND (attr
) = 0;
9654 /* Read an attribute described by an abbreviated attribute. */
9657 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9658 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9660 attr
->name
= abbrev
->name
;
9661 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9664 /* Read dwarf information from a buffer. */
9667 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9669 return bfd_get_8 (abfd
, buf
);
9673 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9675 return bfd_get_signed_8 (abfd
, buf
);
9679 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9681 return bfd_get_16 (abfd
, buf
);
9685 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9687 return bfd_get_signed_16 (abfd
, buf
);
9691 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9693 return bfd_get_32 (abfd
, buf
);
9697 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9699 return bfd_get_signed_32 (abfd
, buf
);
9703 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9705 return bfd_get_64 (abfd
, buf
);
9709 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9710 unsigned int *bytes_read
)
9712 struct comp_unit_head
*cu_header
= &cu
->header
;
9713 CORE_ADDR retval
= 0;
9715 if (cu_header
->signed_addr_p
)
9717 switch (cu_header
->addr_size
)
9720 retval
= bfd_get_signed_16 (abfd
, buf
);
9723 retval
= bfd_get_signed_32 (abfd
, buf
);
9726 retval
= bfd_get_signed_64 (abfd
, buf
);
9729 internal_error (__FILE__
, __LINE__
,
9730 _("read_address: bad switch, signed [in module %s]"),
9731 bfd_get_filename (abfd
));
9736 switch (cu_header
->addr_size
)
9739 retval
= bfd_get_16 (abfd
, buf
);
9742 retval
= bfd_get_32 (abfd
, buf
);
9745 retval
= bfd_get_64 (abfd
, buf
);
9748 internal_error (__FILE__
, __LINE__
,
9749 _("read_address: bad switch, "
9750 "unsigned [in module %s]"),
9751 bfd_get_filename (abfd
));
9755 *bytes_read
= cu_header
->addr_size
;
9759 /* Read the initial length from a section. The (draft) DWARF 3
9760 specification allows the initial length to take up either 4 bytes
9761 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9762 bytes describe the length and all offsets will be 8 bytes in length
9765 An older, non-standard 64-bit format is also handled by this
9766 function. The older format in question stores the initial length
9767 as an 8-byte quantity without an escape value. Lengths greater
9768 than 2^32 aren't very common which means that the initial 4 bytes
9769 is almost always zero. Since a length value of zero doesn't make
9770 sense for the 32-bit format, this initial zero can be considered to
9771 be an escape value which indicates the presence of the older 64-bit
9772 format. As written, the code can't detect (old format) lengths
9773 greater than 4GB. If it becomes necessary to handle lengths
9774 somewhat larger than 4GB, we could allow other small values (such
9775 as the non-sensical values of 1, 2, and 3) to also be used as
9776 escape values indicating the presence of the old format.
9778 The value returned via bytes_read should be used to increment the
9779 relevant pointer after calling read_initial_length().
9781 [ Note: read_initial_length() and read_offset() are based on the
9782 document entitled "DWARF Debugging Information Format", revision
9783 3, draft 8, dated November 19, 2001. This document was obtained
9786 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9788 This document is only a draft and is subject to change. (So beware.)
9790 Details regarding the older, non-standard 64-bit format were
9791 determined empirically by examining 64-bit ELF files produced by
9792 the SGI toolchain on an IRIX 6.5 machine.
9794 - Kevin, July 16, 2002
9798 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
9800 LONGEST length
= bfd_get_32 (abfd
, buf
);
9802 if (length
== 0xffffffff)
9804 length
= bfd_get_64 (abfd
, buf
+ 4);
9807 else if (length
== 0)
9809 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9810 length
= bfd_get_64 (abfd
, buf
);
9821 /* Cover function for read_initial_length.
9822 Returns the length of the object at BUF, and stores the size of the
9823 initial length in *BYTES_READ and stores the size that offsets will be in
9825 If the initial length size is not equivalent to that specified in
9826 CU_HEADER then issue a complaint.
9827 This is useful when reading non-comp-unit headers. */
9830 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
9831 const struct comp_unit_head
*cu_header
,
9832 unsigned int *bytes_read
,
9833 unsigned int *offset_size
)
9835 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
9837 gdb_assert (cu_header
->initial_length_size
== 4
9838 || cu_header
->initial_length_size
== 8
9839 || cu_header
->initial_length_size
== 12);
9841 if (cu_header
->initial_length_size
!= *bytes_read
)
9842 complaint (&symfile_complaints
,
9843 _("intermixed 32-bit and 64-bit DWARF sections"));
9845 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
9849 /* Read an offset from the data stream. The size of the offset is
9850 given by cu_header->offset_size. */
9853 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
9854 unsigned int *bytes_read
)
9856 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
9858 *bytes_read
= cu_header
->offset_size
;
9862 /* Read an offset from the data stream. */
9865 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
9869 switch (offset_size
)
9872 retval
= bfd_get_32 (abfd
, buf
);
9875 retval
= bfd_get_64 (abfd
, buf
);
9878 internal_error (__FILE__
, __LINE__
,
9879 _("read_offset_1: bad switch [in module %s]"),
9880 bfd_get_filename (abfd
));
9887 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
9889 /* If the size of a host char is 8 bits, we can return a pointer
9890 to the buffer, otherwise we have to copy the data to a buffer
9891 allocated on the temporary obstack. */
9892 gdb_assert (HOST_CHAR_BIT
== 8);
9897 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9899 /* If the size of a host char is 8 bits, we can return a pointer
9900 to the string, otherwise we have to copy the string to a buffer
9901 allocated on the temporary obstack. */
9902 gdb_assert (HOST_CHAR_BIT
== 8);
9905 *bytes_read_ptr
= 1;
9908 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
9909 return (char *) buf
;
9913 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
9914 const struct comp_unit_head
*cu_header
,
9915 unsigned int *bytes_read_ptr
)
9917 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
9919 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
9920 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
9922 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9923 bfd_get_filename (abfd
));
9926 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
9928 error (_("DW_FORM_strp pointing outside of "
9929 ".debug_str section [in module %s]"),
9930 bfd_get_filename (abfd
));
9933 gdb_assert (HOST_CHAR_BIT
== 8);
9934 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
9936 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
9939 static unsigned long
9940 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9942 unsigned long result
;
9943 unsigned int num_read
;
9953 byte
= bfd_get_8 (abfd
, buf
);
9956 result
|= ((unsigned long)(byte
& 127) << shift
);
9957 if ((byte
& 128) == 0)
9963 *bytes_read_ptr
= num_read
;
9968 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9971 int i
, shift
, num_read
;
9980 byte
= bfd_get_8 (abfd
, buf
);
9983 result
|= ((long)(byte
& 127) << shift
);
9985 if ((byte
& 128) == 0)
9990 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
9991 result
|= -(((long)1) << shift
);
9992 *bytes_read_ptr
= num_read
;
9996 /* Return a pointer to just past the end of an LEB128 number in BUF. */
9999 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10005 byte
= bfd_get_8 (abfd
, buf
);
10007 if ((byte
& 128) == 0)
10013 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10020 cu
->language
= language_c
;
10022 case DW_LANG_C_plus_plus
:
10023 cu
->language
= language_cplus
;
10026 cu
->language
= language_d
;
10028 case DW_LANG_Fortran77
:
10029 case DW_LANG_Fortran90
:
10030 case DW_LANG_Fortran95
:
10031 cu
->language
= language_fortran
;
10033 case DW_LANG_Mips_Assembler
:
10034 cu
->language
= language_asm
;
10037 cu
->language
= language_java
;
10039 case DW_LANG_Ada83
:
10040 case DW_LANG_Ada95
:
10041 cu
->language
= language_ada
;
10043 case DW_LANG_Modula2
:
10044 cu
->language
= language_m2
;
10046 case DW_LANG_Pascal83
:
10047 cu
->language
= language_pascal
;
10050 cu
->language
= language_objc
;
10052 case DW_LANG_Cobol74
:
10053 case DW_LANG_Cobol85
:
10055 cu
->language
= language_minimal
;
10058 cu
->language_defn
= language_def (cu
->language
);
10061 /* Return the named attribute or NULL if not there. */
10063 static struct attribute
*
10064 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10067 struct attribute
*spec
= NULL
;
10069 for (i
= 0; i
< die
->num_attrs
; ++i
)
10071 if (die
->attrs
[i
].name
== name
)
10072 return &die
->attrs
[i
];
10073 if (die
->attrs
[i
].name
== DW_AT_specification
10074 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10075 spec
= &die
->attrs
[i
];
10080 die
= follow_die_ref (die
, spec
, &cu
);
10081 return dwarf2_attr (die
, name
, cu
);
10087 /* Return the named attribute or NULL if not there,
10088 but do not follow DW_AT_specification, etc.
10089 This is for use in contexts where we're reading .debug_types dies.
10090 Following DW_AT_specification, DW_AT_abstract_origin will take us
10091 back up the chain, and we want to go down. */
10093 static struct attribute
*
10094 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10095 struct dwarf2_cu
*cu
)
10099 for (i
= 0; i
< die
->num_attrs
; ++i
)
10100 if (die
->attrs
[i
].name
== name
)
10101 return &die
->attrs
[i
];
10106 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10107 and holds a non-zero value. This function should only be used for
10108 DW_FORM_flag or DW_FORM_flag_present attributes. */
10111 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10113 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10115 return (attr
&& DW_UNSND (attr
));
10119 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10121 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10122 which value is non-zero. However, we have to be careful with
10123 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10124 (via dwarf2_flag_true_p) follows this attribute. So we may
10125 end up accidently finding a declaration attribute that belongs
10126 to a different DIE referenced by the specification attribute,
10127 even though the given DIE does not have a declaration attribute. */
10128 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10129 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10132 /* Return the die giving the specification for DIE, if there is
10133 one. *SPEC_CU is the CU containing DIE on input, and the CU
10134 containing the return value on output. If there is no
10135 specification, but there is an abstract origin, that is
10138 static struct die_info
*
10139 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10141 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10144 if (spec_attr
== NULL
)
10145 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10147 if (spec_attr
== NULL
)
10150 return follow_die_ref (die
, spec_attr
, spec_cu
);
10153 /* Free the line_header structure *LH, and any arrays and strings it
10155 NOTE: This is also used as a "cleanup" function. */
10158 free_line_header (struct line_header
*lh
)
10160 if (lh
->standard_opcode_lengths
)
10161 xfree (lh
->standard_opcode_lengths
);
10163 /* Remember that all the lh->file_names[i].name pointers are
10164 pointers into debug_line_buffer, and don't need to be freed. */
10165 if (lh
->file_names
)
10166 xfree (lh
->file_names
);
10168 /* Similarly for the include directory names. */
10169 if (lh
->include_dirs
)
10170 xfree (lh
->include_dirs
);
10175 /* Add an entry to LH's include directory table. */
10178 add_include_dir (struct line_header
*lh
, char *include_dir
)
10180 /* Grow the array if necessary. */
10181 if (lh
->include_dirs_size
== 0)
10183 lh
->include_dirs_size
= 1; /* for testing */
10184 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10185 * sizeof (*lh
->include_dirs
));
10187 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10189 lh
->include_dirs_size
*= 2;
10190 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10191 (lh
->include_dirs_size
10192 * sizeof (*lh
->include_dirs
)));
10195 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10198 /* Add an entry to LH's file name table. */
10201 add_file_name (struct line_header
*lh
,
10203 unsigned int dir_index
,
10204 unsigned int mod_time
,
10205 unsigned int length
)
10207 struct file_entry
*fe
;
10209 /* Grow the array if necessary. */
10210 if (lh
->file_names_size
== 0)
10212 lh
->file_names_size
= 1; /* for testing */
10213 lh
->file_names
= xmalloc (lh
->file_names_size
10214 * sizeof (*lh
->file_names
));
10216 else if (lh
->num_file_names
>= lh
->file_names_size
)
10218 lh
->file_names_size
*= 2;
10219 lh
->file_names
= xrealloc (lh
->file_names
,
10220 (lh
->file_names_size
10221 * sizeof (*lh
->file_names
)));
10224 fe
= &lh
->file_names
[lh
->num_file_names
++];
10226 fe
->dir_index
= dir_index
;
10227 fe
->mod_time
= mod_time
;
10228 fe
->length
= length
;
10229 fe
->included_p
= 0;
10233 /* Read the statement program header starting at OFFSET in
10234 .debug_line, according to the endianness of ABFD. Return a pointer
10235 to a struct line_header, allocated using xmalloc.
10237 NOTE: the strings in the include directory and file name tables of
10238 the returned object point into debug_line_buffer, and must not be
10241 static struct line_header
*
10242 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10243 struct dwarf2_cu
*cu
)
10245 struct cleanup
*back_to
;
10246 struct line_header
*lh
;
10247 gdb_byte
*line_ptr
;
10248 unsigned int bytes_read
, offset_size
;
10250 char *cur_dir
, *cur_file
;
10252 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10253 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10255 complaint (&symfile_complaints
, _("missing .debug_line section"));
10259 /* Make sure that at least there's room for the total_length field.
10260 That could be 12 bytes long, but we're just going to fudge that. */
10261 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10263 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10267 lh
= xmalloc (sizeof (*lh
));
10268 memset (lh
, 0, sizeof (*lh
));
10269 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10272 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10274 /* Read in the header. */
10276 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10277 &bytes_read
, &offset_size
);
10278 line_ptr
+= bytes_read
;
10279 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10280 + dwarf2_per_objfile
->line
.size
))
10282 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10285 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10286 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10288 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10289 line_ptr
+= offset_size
;
10290 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10292 if (lh
->version
>= 4)
10294 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10298 lh
->maximum_ops_per_instruction
= 1;
10300 if (lh
->maximum_ops_per_instruction
== 0)
10302 lh
->maximum_ops_per_instruction
= 1;
10303 complaint (&symfile_complaints
,
10304 _("invalid maximum_ops_per_instruction "
10305 "in `.debug_line' section"));
10308 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10310 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10312 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10314 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10316 lh
->standard_opcode_lengths
10317 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10319 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10320 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10322 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10326 /* Read directory table. */
10327 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10329 line_ptr
+= bytes_read
;
10330 add_include_dir (lh
, cur_dir
);
10332 line_ptr
+= bytes_read
;
10334 /* Read file name table. */
10335 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10337 unsigned int dir_index
, mod_time
, length
;
10339 line_ptr
+= bytes_read
;
10340 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10341 line_ptr
+= bytes_read
;
10342 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10343 line_ptr
+= bytes_read
;
10344 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10345 line_ptr
+= bytes_read
;
10347 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10349 line_ptr
+= bytes_read
;
10350 lh
->statement_program_start
= line_ptr
;
10352 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
10353 + dwarf2_per_objfile
->line
.size
))
10354 complaint (&symfile_complaints
,
10355 _("line number info header doesn't "
10356 "fit in `.debug_line' section"));
10358 discard_cleanups (back_to
);
10362 /* This function exists to work around a bug in certain compilers
10363 (particularly GCC 2.95), in which the first line number marker of a
10364 function does not show up until after the prologue, right before
10365 the second line number marker. This function shifts ADDRESS down
10366 to the beginning of the function if necessary, and is called on
10367 addresses passed to record_line. */
10370 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
10372 struct function_range
*fn
;
10374 /* Find the function_range containing address. */
10378 if (!cu
->cached_fn
)
10379 cu
->cached_fn
= cu
->first_fn
;
10381 fn
= cu
->cached_fn
;
10383 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10389 while (fn
&& fn
!= cu
->cached_fn
)
10390 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10400 if (address
!= fn
->lowpc
)
10401 complaint (&symfile_complaints
,
10402 _("misplaced first line number at 0x%lx for '%s'"),
10403 (unsigned long) address
, fn
->name
);
10408 /* Subroutine of dwarf_decode_lines to simplify it.
10409 Return the file name of the psymtab for included file FILE_INDEX
10410 in line header LH of PST.
10411 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10412 If space for the result is malloc'd, it will be freed by a cleanup.
10413 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10416 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10417 const struct partial_symtab
*pst
,
10418 const char *comp_dir
)
10420 const struct file_entry fe
= lh
->file_names
[file_index
];
10421 char *include_name
= fe
.name
;
10422 char *include_name_to_compare
= include_name
;
10423 char *dir_name
= NULL
;
10424 const char *pst_filename
;
10425 char *copied_name
= NULL
;
10429 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10431 if (!IS_ABSOLUTE_PATH (include_name
)
10432 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10434 /* Avoid creating a duplicate psymtab for PST.
10435 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10436 Before we do the comparison, however, we need to account
10437 for DIR_NAME and COMP_DIR.
10438 First prepend dir_name (if non-NULL). If we still don't
10439 have an absolute path prepend comp_dir (if non-NULL).
10440 However, the directory we record in the include-file's
10441 psymtab does not contain COMP_DIR (to match the
10442 corresponding symtab(s)).
10447 bash$ gcc -g ./hello.c
10448 include_name = "hello.c"
10450 DW_AT_comp_dir = comp_dir = "/tmp"
10451 DW_AT_name = "./hello.c" */
10453 if (dir_name
!= NULL
)
10455 include_name
= concat (dir_name
, SLASH_STRING
,
10456 include_name
, (char *)NULL
);
10457 include_name_to_compare
= include_name
;
10458 make_cleanup (xfree
, include_name
);
10460 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10462 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10463 include_name
, (char *)NULL
);
10467 pst_filename
= pst
->filename
;
10468 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10470 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
10471 pst_filename
, (char *)NULL
);
10472 pst_filename
= copied_name
;
10475 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
10477 if (include_name_to_compare
!= include_name
)
10478 xfree (include_name_to_compare
);
10479 if (copied_name
!= NULL
)
10480 xfree (copied_name
);
10484 return include_name
;
10487 /* Ignore this record_line request. */
10490 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10495 /* Decode the Line Number Program (LNP) for the given line_header
10496 structure and CU. The actual information extracted and the type
10497 of structures created from the LNP depends on the value of PST.
10499 1. If PST is NULL, then this procedure uses the data from the program
10500 to create all necessary symbol tables, and their linetables.
10502 2. If PST is not NULL, this procedure reads the program to determine
10503 the list of files included by the unit represented by PST, and
10504 builds all the associated partial symbol tables.
10506 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10507 It is used for relative paths in the line table.
10508 NOTE: When processing partial symtabs (pst != NULL),
10509 comp_dir == pst->dirname.
10511 NOTE: It is important that psymtabs have the same file name (via strcmp)
10512 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10513 symtab we don't use it in the name of the psymtabs we create.
10514 E.g. expand_line_sal requires this when finding psymtabs to expand.
10515 A good testcase for this is mb-inline.exp. */
10518 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
10519 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10521 gdb_byte
*line_ptr
, *extended_end
;
10522 gdb_byte
*line_end
;
10523 unsigned int bytes_read
, extended_len
;
10524 unsigned char op_code
, extended_op
, adj_opcode
;
10525 CORE_ADDR baseaddr
;
10526 struct objfile
*objfile
= cu
->objfile
;
10527 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10528 const int decode_for_pst_p
= (pst
!= NULL
);
10529 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10530 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10533 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10535 line_ptr
= lh
->statement_program_start
;
10536 line_end
= lh
->statement_program_end
;
10538 /* Read the statement sequences until there's nothing left. */
10539 while (line_ptr
< line_end
)
10541 /* state machine registers */
10542 CORE_ADDR address
= 0;
10543 unsigned int file
= 1;
10544 unsigned int line
= 1;
10545 unsigned int column
= 0;
10546 int is_stmt
= lh
->default_is_stmt
;
10547 int basic_block
= 0;
10548 int end_sequence
= 0;
10550 unsigned char op_index
= 0;
10552 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10554 /* Start a subfile for the current file of the state machine. */
10555 /* lh->include_dirs and lh->file_names are 0-based, but the
10556 directory and file name numbers in the statement program
10558 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10562 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10564 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10567 /* Decode the table. */
10568 while (!end_sequence
)
10570 op_code
= read_1_byte (abfd
, line_ptr
);
10572 if (line_ptr
> line_end
)
10574 dwarf2_debug_line_missing_end_sequence_complaint ();
10578 if (op_code
>= lh
->opcode_base
)
10580 /* Special operand. */
10581 adj_opcode
= op_code
- lh
->opcode_base
;
10582 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10583 / lh
->maximum_ops_per_instruction
)
10584 * lh
->minimum_instruction_length
);
10585 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10586 % lh
->maximum_ops_per_instruction
);
10587 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10588 if (lh
->num_file_names
< file
|| file
== 0)
10589 dwarf2_debug_line_missing_file_complaint ();
10590 /* For now we ignore lines not starting on an
10591 instruction boundary. */
10592 else if (op_index
== 0)
10594 lh
->file_names
[file
- 1].included_p
= 1;
10595 if (!decode_for_pst_p
&& is_stmt
)
10597 if (last_subfile
!= current_subfile
)
10599 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10601 (*p_record_line
) (last_subfile
, 0, addr
);
10602 last_subfile
= current_subfile
;
10604 /* Append row to matrix using current values. */
10605 addr
= check_cu_functions (address
, cu
);
10606 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10607 (*p_record_line
) (current_subfile
, line
, addr
);
10612 else switch (op_code
)
10614 case DW_LNS_extended_op
:
10615 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
10617 line_ptr
+= bytes_read
;
10618 extended_end
= line_ptr
+ extended_len
;
10619 extended_op
= read_1_byte (abfd
, line_ptr
);
10621 switch (extended_op
)
10623 case DW_LNE_end_sequence
:
10624 p_record_line
= record_line
;
10627 case DW_LNE_set_address
:
10628 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10630 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10632 /* This line table is for a function which has been
10633 GCd by the linker. Ignore it. PR gdb/12528 */
10636 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
10638 complaint (&symfile_complaints
,
10639 _(".debug_line address at offset 0x%lx is 0 "
10641 line_offset
, cu
->objfile
->name
);
10642 p_record_line
= noop_record_line
;
10646 line_ptr
+= bytes_read
;
10647 address
+= baseaddr
;
10649 case DW_LNE_define_file
:
10652 unsigned int dir_index
, mod_time
, length
;
10654 cur_file
= read_direct_string (abfd
, line_ptr
,
10656 line_ptr
+= bytes_read
;
10658 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10659 line_ptr
+= bytes_read
;
10661 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10662 line_ptr
+= bytes_read
;
10664 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10665 line_ptr
+= bytes_read
;
10666 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10669 case DW_LNE_set_discriminator
:
10670 /* The discriminator is not interesting to the debugger;
10672 line_ptr
= extended_end
;
10675 complaint (&symfile_complaints
,
10676 _("mangled .debug_line section"));
10679 /* Make sure that we parsed the extended op correctly. If e.g.
10680 we expected a different address size than the producer used,
10681 we may have read the wrong number of bytes. */
10682 if (line_ptr
!= extended_end
)
10684 complaint (&symfile_complaints
,
10685 _("mangled .debug_line section"));
10690 if (lh
->num_file_names
< file
|| file
== 0)
10691 dwarf2_debug_line_missing_file_complaint ();
10694 lh
->file_names
[file
- 1].included_p
= 1;
10695 if (!decode_for_pst_p
&& is_stmt
)
10697 if (last_subfile
!= current_subfile
)
10699 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10701 (*p_record_line
) (last_subfile
, 0, addr
);
10702 last_subfile
= current_subfile
;
10704 addr
= check_cu_functions (address
, cu
);
10705 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10706 (*p_record_line
) (current_subfile
, line
, addr
);
10711 case DW_LNS_advance_pc
:
10714 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10716 address
+= (((op_index
+ adjust
)
10717 / lh
->maximum_ops_per_instruction
)
10718 * lh
->minimum_instruction_length
);
10719 op_index
= ((op_index
+ adjust
)
10720 % lh
->maximum_ops_per_instruction
);
10721 line_ptr
+= bytes_read
;
10724 case DW_LNS_advance_line
:
10725 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
10726 line_ptr
+= bytes_read
;
10728 case DW_LNS_set_file
:
10730 /* The arrays lh->include_dirs and lh->file_names are
10731 0-based, but the directory and file name numbers in
10732 the statement program are 1-based. */
10733 struct file_entry
*fe
;
10736 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10737 line_ptr
+= bytes_read
;
10738 if (lh
->num_file_names
< file
|| file
== 0)
10739 dwarf2_debug_line_missing_file_complaint ();
10742 fe
= &lh
->file_names
[file
- 1];
10744 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10745 if (!decode_for_pst_p
)
10747 last_subfile
= current_subfile
;
10748 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10753 case DW_LNS_set_column
:
10754 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10755 line_ptr
+= bytes_read
;
10757 case DW_LNS_negate_stmt
:
10758 is_stmt
= (!is_stmt
);
10760 case DW_LNS_set_basic_block
:
10763 /* Add to the address register of the state machine the
10764 address increment value corresponding to special opcode
10765 255. I.e., this value is scaled by the minimum
10766 instruction length since special opcode 255 would have
10767 scaled the increment. */
10768 case DW_LNS_const_add_pc
:
10770 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
10772 address
+= (((op_index
+ adjust
)
10773 / lh
->maximum_ops_per_instruction
)
10774 * lh
->minimum_instruction_length
);
10775 op_index
= ((op_index
+ adjust
)
10776 % lh
->maximum_ops_per_instruction
);
10779 case DW_LNS_fixed_advance_pc
:
10780 address
+= read_2_bytes (abfd
, line_ptr
);
10786 /* Unknown standard opcode, ignore it. */
10789 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
10791 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10792 line_ptr
+= bytes_read
;
10797 if (lh
->num_file_names
< file
|| file
== 0)
10798 dwarf2_debug_line_missing_file_complaint ();
10801 lh
->file_names
[file
- 1].included_p
= 1;
10802 if (!decode_for_pst_p
)
10804 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10805 (*p_record_line
) (current_subfile
, 0, addr
);
10810 if (decode_for_pst_p
)
10814 /* Now that we're done scanning the Line Header Program, we can
10815 create the psymtab of each included file. */
10816 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
10817 if (lh
->file_names
[file_index
].included_p
== 1)
10819 char *include_name
=
10820 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
10821 if (include_name
!= NULL
)
10822 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
10827 /* Make sure a symtab is created for every file, even files
10828 which contain only variables (i.e. no code with associated
10832 struct file_entry
*fe
;
10834 for (i
= 0; i
< lh
->num_file_names
; i
++)
10838 fe
= &lh
->file_names
[i
];
10840 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10841 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10843 /* Skip the main file; we don't need it, and it must be
10844 allocated last, so that it will show up before the
10845 non-primary symtabs in the objfile's symtab list. */
10846 if (current_subfile
== first_subfile
)
10849 if (current_subfile
->symtab
== NULL
)
10850 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
10852 fe
->symtab
= current_subfile
->symtab
;
10857 /* Start a subfile for DWARF. FILENAME is the name of the file and
10858 DIRNAME the name of the source directory which contains FILENAME
10859 or NULL if not known. COMP_DIR is the compilation directory for the
10860 linetable's compilation unit or NULL if not known.
10861 This routine tries to keep line numbers from identical absolute and
10862 relative file names in a common subfile.
10864 Using the `list' example from the GDB testsuite, which resides in
10865 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10866 of /srcdir/list0.c yields the following debugging information for list0.c:
10868 DW_AT_name: /srcdir/list0.c
10869 DW_AT_comp_dir: /compdir
10870 files.files[0].name: list0.h
10871 files.files[0].dir: /srcdir
10872 files.files[1].name: list0.c
10873 files.files[1].dir: /srcdir
10875 The line number information for list0.c has to end up in a single
10876 subfile, so that `break /srcdir/list0.c:1' works as expected.
10877 start_subfile will ensure that this happens provided that we pass the
10878 concatenation of files.files[1].dir and files.files[1].name as the
10882 dwarf2_start_subfile (char *filename
, const char *dirname
,
10883 const char *comp_dir
)
10887 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10888 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10889 second argument to start_subfile. To be consistent, we do the
10890 same here. In order not to lose the line information directory,
10891 we concatenate it to the filename when it makes sense.
10892 Note that the Dwarf3 standard says (speaking of filenames in line
10893 information): ``The directory index is ignored for file names
10894 that represent full path names''. Thus ignoring dirname in the
10895 `else' branch below isn't an issue. */
10897 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
10898 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
10900 fullname
= filename
;
10902 start_subfile (fullname
, comp_dir
);
10904 if (fullname
!= filename
)
10909 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
10910 struct dwarf2_cu
*cu
)
10912 struct objfile
*objfile
= cu
->objfile
;
10913 struct comp_unit_head
*cu_header
= &cu
->header
;
10915 /* NOTE drow/2003-01-30: There used to be a comment and some special
10916 code here to turn a symbol with DW_AT_external and a
10917 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10918 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10919 with some versions of binutils) where shared libraries could have
10920 relocations against symbols in their debug information - the
10921 minimal symbol would have the right address, but the debug info
10922 would not. It's no longer necessary, because we will explicitly
10923 apply relocations when we read in the debug information now. */
10925 /* A DW_AT_location attribute with no contents indicates that a
10926 variable has been optimized away. */
10927 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
10929 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10933 /* Handle one degenerate form of location expression specially, to
10934 preserve GDB's previous behavior when section offsets are
10935 specified. If this is just a DW_OP_addr then mark this symbol
10938 if (attr_form_is_block (attr
)
10939 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
10940 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
10942 unsigned int dummy
;
10944 SYMBOL_VALUE_ADDRESS (sym
) =
10945 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
10946 SYMBOL_CLASS (sym
) = LOC_STATIC
;
10947 fixup_symbol_section (sym
, objfile
);
10948 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
10949 SYMBOL_SECTION (sym
));
10953 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
10954 expression evaluator, and use LOC_COMPUTED only when necessary
10955 (i.e. when the value of a register or memory location is
10956 referenced, or a thread-local block, etc.). Then again, it might
10957 not be worthwhile. I'm assuming that it isn't unless performance
10958 or memory numbers show me otherwise. */
10960 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
10961 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10964 /* Given a pointer to a DWARF information entry, figure out if we need
10965 to make a symbol table entry for it, and if so, create a new entry
10966 and return a pointer to it.
10967 If TYPE is NULL, determine symbol type from the die, otherwise
10968 used the passed type.
10969 If SPACE is not NULL, use it to hold the new symbol. If it is
10970 NULL, allocate a new symbol on the objfile's obstack. */
10972 static struct symbol
*
10973 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
10974 struct symbol
*space
)
10976 struct objfile
*objfile
= cu
->objfile
;
10977 struct symbol
*sym
= NULL
;
10979 struct attribute
*attr
= NULL
;
10980 struct attribute
*attr2
= NULL
;
10981 CORE_ADDR baseaddr
;
10982 struct pending
**list_to_add
= NULL
;
10984 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10986 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10988 name
= dwarf2_name (die
, cu
);
10991 const char *linkagename
;
10992 int suppress_add
= 0;
10997 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
10998 OBJSTAT (objfile
, n_syms
++);
11000 /* Cache this symbol's name and the name's demangled form (if any). */
11001 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11002 linkagename
= dwarf2_physname (name
, die
, cu
);
11003 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11005 /* Fortran does not have mangling standard and the mangling does differ
11006 between gfortran, iFort etc. */
11007 if (cu
->language
== language_fortran
11008 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11009 symbol_set_demangled_name (&(sym
->ginfo
),
11010 (char *) dwarf2_full_name (name
, die
, cu
),
11013 /* Default assumptions.
11014 Use the passed type or decode it from the die. */
11015 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11016 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11018 SYMBOL_TYPE (sym
) = type
;
11020 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11021 attr
= dwarf2_attr (die
,
11022 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11026 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11029 attr
= dwarf2_attr (die
,
11030 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11034 int file_index
= DW_UNSND (attr
);
11036 if (cu
->line_header
== NULL
11037 || file_index
> cu
->line_header
->num_file_names
)
11038 complaint (&symfile_complaints
,
11039 _("file index out of range"));
11040 else if (file_index
> 0)
11042 struct file_entry
*fe
;
11044 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11045 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11052 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11055 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11057 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11058 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11059 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11060 add_symbol_to_list (sym
, cu
->list_in_scope
);
11062 case DW_TAG_subprogram
:
11063 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11065 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11066 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11067 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11068 || cu
->language
== language_ada
)
11070 /* Subprograms marked external are stored as a global symbol.
11071 Ada subprograms, whether marked external or not, are always
11072 stored as a global symbol, because we want to be able to
11073 access them globally. For instance, we want to be able
11074 to break on a nested subprogram without having to
11075 specify the context. */
11076 list_to_add
= &global_symbols
;
11080 list_to_add
= cu
->list_in_scope
;
11083 case DW_TAG_inlined_subroutine
:
11084 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11086 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11087 SYMBOL_INLINED (sym
) = 1;
11088 /* Do not add the symbol to any lists. It will be found via
11089 BLOCK_FUNCTION from the blockvector. */
11091 case DW_TAG_template_value_param
:
11093 /* Fall through. */
11094 case DW_TAG_constant
:
11095 case DW_TAG_variable
:
11096 case DW_TAG_member
:
11097 /* Compilation with minimal debug info may result in
11098 variables with missing type entries. Change the
11099 misleading `void' type to something sensible. */
11100 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11102 = objfile_type (objfile
)->nodebug_data_symbol
;
11104 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11105 /* In the case of DW_TAG_member, we should only be called for
11106 static const members. */
11107 if (die
->tag
== DW_TAG_member
)
11109 /* dwarf2_add_field uses die_is_declaration,
11110 so we do the same. */
11111 gdb_assert (die_is_declaration (die
, cu
));
11116 dwarf2_const_value (attr
, sym
, cu
);
11117 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11120 if (attr2
&& (DW_UNSND (attr2
) != 0))
11121 list_to_add
= &global_symbols
;
11123 list_to_add
= cu
->list_in_scope
;
11127 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11130 var_decode_location (attr
, sym
, cu
);
11131 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11132 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11133 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11134 && !dwarf2_per_objfile
->has_section_at_zero
)
11136 /* When a static variable is eliminated by the linker,
11137 the corresponding debug information is not stripped
11138 out, but the variable address is set to null;
11139 do not add such variables into symbol table. */
11141 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11143 /* Workaround gfortran PR debug/40040 - it uses
11144 DW_AT_location for variables in -fPIC libraries which may
11145 get overriden by other libraries/executable and get
11146 a different address. Resolve it by the minimal symbol
11147 which may come from inferior's executable using copy
11148 relocation. Make this workaround only for gfortran as for
11149 other compilers GDB cannot guess the minimal symbol
11150 Fortran mangling kind. */
11151 if (cu
->language
== language_fortran
&& die
->parent
11152 && die
->parent
->tag
== DW_TAG_module
11154 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11155 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11157 /* A variable with DW_AT_external is never static,
11158 but it may be block-scoped. */
11159 list_to_add
= (cu
->list_in_scope
== &file_symbols
11160 ? &global_symbols
: cu
->list_in_scope
);
11163 list_to_add
= cu
->list_in_scope
;
11167 /* We do not know the address of this symbol.
11168 If it is an external symbol and we have type information
11169 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11170 The address of the variable will then be determined from
11171 the minimal symbol table whenever the variable is
11173 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11174 if (attr2
&& (DW_UNSND (attr2
) != 0)
11175 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11177 /* A variable with DW_AT_external is never static, but it
11178 may be block-scoped. */
11179 list_to_add
= (cu
->list_in_scope
== &file_symbols
11180 ? &global_symbols
: cu
->list_in_scope
);
11182 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11184 else if (!die_is_declaration (die
, cu
))
11186 /* Use the default LOC_OPTIMIZED_OUT class. */
11187 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11189 list_to_add
= cu
->list_in_scope
;
11193 case DW_TAG_formal_parameter
:
11194 /* If we are inside a function, mark this as an argument. If
11195 not, we might be looking at an argument to an inlined function
11196 when we do not have enough information to show inlined frames;
11197 pretend it's a local variable in that case so that the user can
11199 if (context_stack_depth
> 0
11200 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11201 SYMBOL_IS_ARGUMENT (sym
) = 1;
11202 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11205 var_decode_location (attr
, sym
, cu
);
11207 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11210 dwarf2_const_value (attr
, sym
, cu
);
11212 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
11213 if (attr
&& DW_UNSND (attr
))
11215 struct type
*ref_type
;
11217 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
11218 SYMBOL_TYPE (sym
) = ref_type
;
11221 list_to_add
= cu
->list_in_scope
;
11223 case DW_TAG_unspecified_parameters
:
11224 /* From varargs functions; gdb doesn't seem to have any
11225 interest in this information, so just ignore it for now.
11228 case DW_TAG_template_type_param
:
11230 /* Fall through. */
11231 case DW_TAG_class_type
:
11232 case DW_TAG_interface_type
:
11233 case DW_TAG_structure_type
:
11234 case DW_TAG_union_type
:
11235 case DW_TAG_set_type
:
11236 case DW_TAG_enumeration_type
:
11237 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11238 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11241 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11242 really ever be static objects: otherwise, if you try
11243 to, say, break of a class's method and you're in a file
11244 which doesn't mention that class, it won't work unless
11245 the check for all static symbols in lookup_symbol_aux
11246 saves you. See the OtherFileClass tests in
11247 gdb.c++/namespace.exp. */
11251 list_to_add
= (cu
->list_in_scope
== &file_symbols
11252 && (cu
->language
== language_cplus
11253 || cu
->language
== language_java
)
11254 ? &global_symbols
: cu
->list_in_scope
);
11256 /* The semantics of C++ state that "struct foo {
11257 ... }" also defines a typedef for "foo". A Java
11258 class declaration also defines a typedef for the
11260 if (cu
->language
== language_cplus
11261 || cu
->language
== language_java
11262 || cu
->language
== language_ada
)
11264 /* The symbol's name is already allocated along
11265 with this objfile, so we don't need to
11266 duplicate it for the type. */
11267 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11268 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11273 case DW_TAG_typedef
:
11274 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11275 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11276 list_to_add
= cu
->list_in_scope
;
11278 case DW_TAG_base_type
:
11279 case DW_TAG_subrange_type
:
11280 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11281 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11282 list_to_add
= cu
->list_in_scope
;
11284 case DW_TAG_enumerator
:
11285 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11288 dwarf2_const_value (attr
, sym
, cu
);
11291 /* NOTE: carlton/2003-11-10: See comment above in the
11292 DW_TAG_class_type, etc. block. */
11294 list_to_add
= (cu
->list_in_scope
== &file_symbols
11295 && (cu
->language
== language_cplus
11296 || cu
->language
== language_java
)
11297 ? &global_symbols
: cu
->list_in_scope
);
11300 case DW_TAG_namespace
:
11301 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11302 list_to_add
= &global_symbols
;
11305 /* Not a tag we recognize. Hopefully we aren't processing
11306 trash data, but since we must specifically ignore things
11307 we don't recognize, there is nothing else we should do at
11309 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11310 dwarf_tag_name (die
->tag
));
11316 sym
->hash_next
= objfile
->template_symbols
;
11317 objfile
->template_symbols
= sym
;
11318 list_to_add
= NULL
;
11321 if (list_to_add
!= NULL
)
11322 add_symbol_to_list (sym
, list_to_add
);
11324 /* For the benefit of old versions of GCC, check for anonymous
11325 namespaces based on the demangled name. */
11326 if (!processing_has_namespace_info
11327 && cu
->language
== language_cplus
)
11328 cp_scan_for_anonymous_namespaces (sym
);
11333 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11335 static struct symbol
*
11336 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11338 return new_symbol_full (die
, type
, cu
, NULL
);
11341 /* Given an attr with a DW_FORM_dataN value in host byte order,
11342 zero-extend it as appropriate for the symbol's type. The DWARF
11343 standard (v4) is not entirely clear about the meaning of using
11344 DW_FORM_dataN for a constant with a signed type, where the type is
11345 wider than the data. The conclusion of a discussion on the DWARF
11346 list was that this is unspecified. We choose to always zero-extend
11347 because that is the interpretation long in use by GCC. */
11350 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11351 const char *name
, struct obstack
*obstack
,
11352 struct dwarf2_cu
*cu
, long *value
, int bits
)
11354 struct objfile
*objfile
= cu
->objfile
;
11355 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11356 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11357 LONGEST l
= DW_UNSND (attr
);
11359 if (bits
< sizeof (*value
) * 8)
11361 l
&= ((LONGEST
) 1 << bits
) - 1;
11364 else if (bits
== sizeof (*value
) * 8)
11368 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11369 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11376 /* Read a constant value from an attribute. Either set *VALUE, or if
11377 the value does not fit in *VALUE, set *BYTES - either already
11378 allocated on the objfile obstack, or newly allocated on OBSTACK,
11379 or, set *BATON, if we translated the constant to a location
11383 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11384 const char *name
, struct obstack
*obstack
,
11385 struct dwarf2_cu
*cu
,
11386 long *value
, gdb_byte
**bytes
,
11387 struct dwarf2_locexpr_baton
**baton
)
11389 struct objfile
*objfile
= cu
->objfile
;
11390 struct comp_unit_head
*cu_header
= &cu
->header
;
11391 struct dwarf_block
*blk
;
11392 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
11393 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
11399 switch (attr
->form
)
11405 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
11406 dwarf2_const_value_length_mismatch_complaint (name
,
11407 cu_header
->addr_size
,
11408 TYPE_LENGTH (type
));
11409 /* Symbols of this form are reasonably rare, so we just
11410 piggyback on the existing location code rather than writing
11411 a new implementation of symbol_computed_ops. */
11412 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11413 sizeof (struct dwarf2_locexpr_baton
));
11414 (*baton
)->per_cu
= cu
->per_cu
;
11415 gdb_assert ((*baton
)->per_cu
);
11417 (*baton
)->size
= 2 + cu_header
->addr_size
;
11418 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11419 (*baton
)->data
= data
;
11421 data
[0] = DW_OP_addr
;
11422 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11423 byte_order
, DW_ADDR (attr
));
11424 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11427 case DW_FORM_string
:
11429 /* DW_STRING is already allocated on the objfile obstack, point
11431 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11433 case DW_FORM_block1
:
11434 case DW_FORM_block2
:
11435 case DW_FORM_block4
:
11436 case DW_FORM_block
:
11437 case DW_FORM_exprloc
:
11438 blk
= DW_BLOCK (attr
);
11439 if (TYPE_LENGTH (type
) != blk
->size
)
11440 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11441 TYPE_LENGTH (type
));
11442 *bytes
= blk
->data
;
11445 /* The DW_AT_const_value attributes are supposed to carry the
11446 symbol's value "represented as it would be on the target
11447 architecture." By the time we get here, it's already been
11448 converted to host endianness, so we just need to sign- or
11449 zero-extend it as appropriate. */
11450 case DW_FORM_data1
:
11451 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11452 obstack
, cu
, value
, 8);
11454 case DW_FORM_data2
:
11455 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11456 obstack
, cu
, value
, 16);
11458 case DW_FORM_data4
:
11459 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11460 obstack
, cu
, value
, 32);
11462 case DW_FORM_data8
:
11463 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11464 obstack
, cu
, value
, 64);
11467 case DW_FORM_sdata
:
11468 *value
= DW_SND (attr
);
11471 case DW_FORM_udata
:
11472 *value
= DW_UNSND (attr
);
11476 complaint (&symfile_complaints
,
11477 _("unsupported const value attribute form: '%s'"),
11478 dwarf_form_name (attr
->form
));
11485 /* Copy constant value from an attribute to a symbol. */
11488 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11489 struct dwarf2_cu
*cu
)
11491 struct objfile
*objfile
= cu
->objfile
;
11492 struct comp_unit_head
*cu_header
= &cu
->header
;
11495 struct dwarf2_locexpr_baton
*baton
;
11497 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11498 SYMBOL_PRINT_NAME (sym
),
11499 &objfile
->objfile_obstack
, cu
,
11500 &value
, &bytes
, &baton
);
11504 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11505 SYMBOL_LOCATION_BATON (sym
) = baton
;
11506 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11508 else if (bytes
!= NULL
)
11510 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11511 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11515 SYMBOL_VALUE (sym
) = value
;
11516 SYMBOL_CLASS (sym
) = LOC_CONST
;
11520 /* Return the type of the die in question using its DW_AT_type attribute. */
11522 static struct type
*
11523 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11525 struct attribute
*type_attr
;
11527 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11530 /* A missing DW_AT_type represents a void type. */
11531 return objfile_type (cu
->objfile
)->builtin_void
;
11534 return lookup_die_type (die
, type_attr
, cu
);
11537 /* True iff CU's producer generates GNAT Ada auxiliary information
11538 that allows to find parallel types through that information instead
11539 of having to do expensive parallel lookups by type name. */
11542 need_gnat_info (struct dwarf2_cu
*cu
)
11544 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11545 of GNAT produces this auxiliary information, without any indication
11546 that it is produced. Part of enhancing the FSF version of GNAT
11547 to produce that information will be to put in place an indicator
11548 that we can use in order to determine whether the descriptive type
11549 info is available or not. One suggestion that has been made is
11550 to use a new attribute, attached to the CU die. For now, assume
11551 that the descriptive type info is not available. */
11555 /* Return the auxiliary type of the die in question using its
11556 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11557 attribute is not present. */
11559 static struct type
*
11560 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11562 struct attribute
*type_attr
;
11564 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11568 return lookup_die_type (die
, type_attr
, cu
);
11571 /* If DIE has a descriptive_type attribute, then set the TYPE's
11572 descriptive type accordingly. */
11575 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11576 struct dwarf2_cu
*cu
)
11578 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11580 if (descriptive_type
)
11582 ALLOCATE_GNAT_AUX_TYPE (type
);
11583 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11587 /* Return the containing type of the die in question using its
11588 DW_AT_containing_type attribute. */
11590 static struct type
*
11591 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11593 struct attribute
*type_attr
;
11595 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11597 error (_("Dwarf Error: Problem turning containing type into gdb type "
11598 "[in module %s]"), cu
->objfile
->name
);
11600 return lookup_die_type (die
, type_attr
, cu
);
11603 /* Look up the type of DIE in CU using its type attribute ATTR.
11604 If there is no type substitute an error marker. */
11606 static struct type
*
11607 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11608 struct dwarf2_cu
*cu
)
11610 struct type
*this_type
;
11612 /* First see if we have it cached. */
11614 if (is_ref_attr (attr
))
11616 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11618 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11620 else if (attr
->form
== DW_FORM_ref_sig8
)
11622 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11623 struct dwarf2_cu
*sig_cu
;
11624 unsigned int offset
;
11626 /* sig_type will be NULL if the signatured type is missing from
11628 if (sig_type
== NULL
)
11629 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11630 "at 0x%x [in module %s]"),
11631 die
->offset
, cu
->objfile
->name
);
11633 gdb_assert (sig_type
->per_cu
.from_debug_types
);
11634 offset
= sig_type
->offset
+ sig_type
->type_offset
;
11635 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11639 dump_die_for_error (die
);
11640 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11641 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11644 /* If not cached we need to read it in. */
11646 if (this_type
== NULL
)
11648 struct die_info
*type_die
;
11649 struct dwarf2_cu
*type_cu
= cu
;
11651 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11652 /* If the type is cached, we should have found it above. */
11653 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
11654 this_type
= read_type_die_1 (type_die
, type_cu
);
11657 /* If we still don't have a type use an error marker. */
11659 if (this_type
== NULL
)
11661 char *message
, *saved
;
11663 /* read_type_die already issued a complaint. */
11664 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11668 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
11669 message
, strlen (message
));
11672 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
11678 /* Return the type in DIE, CU.
11679 Returns NULL for invalid types.
11681 This first does a lookup in the appropriate type_hash table,
11682 and only reads the die in if necessary.
11684 NOTE: This can be called when reading in partial or full symbols. */
11686 static struct type
*
11687 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11689 struct type
*this_type
;
11691 this_type
= get_die_type (die
, cu
);
11695 return read_type_die_1 (die
, cu
);
11698 /* Read the type in DIE, CU.
11699 Returns NULL for invalid types. */
11701 static struct type
*
11702 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
11704 struct type
*this_type
= NULL
;
11708 case DW_TAG_class_type
:
11709 case DW_TAG_interface_type
:
11710 case DW_TAG_structure_type
:
11711 case DW_TAG_union_type
:
11712 this_type
= read_structure_type (die
, cu
);
11714 case DW_TAG_enumeration_type
:
11715 this_type
= read_enumeration_type (die
, cu
);
11717 case DW_TAG_subprogram
:
11718 case DW_TAG_subroutine_type
:
11719 case DW_TAG_inlined_subroutine
:
11720 this_type
= read_subroutine_type (die
, cu
);
11722 case DW_TAG_array_type
:
11723 this_type
= read_array_type (die
, cu
);
11725 case DW_TAG_set_type
:
11726 this_type
= read_set_type (die
, cu
);
11728 case DW_TAG_pointer_type
:
11729 this_type
= read_tag_pointer_type (die
, cu
);
11731 case DW_TAG_ptr_to_member_type
:
11732 this_type
= read_tag_ptr_to_member_type (die
, cu
);
11734 case DW_TAG_reference_type
:
11735 this_type
= read_tag_reference_type (die
, cu
);
11737 case DW_TAG_const_type
:
11738 this_type
= read_tag_const_type (die
, cu
);
11740 case DW_TAG_volatile_type
:
11741 this_type
= read_tag_volatile_type (die
, cu
);
11743 case DW_TAG_string_type
:
11744 this_type
= read_tag_string_type (die
, cu
);
11746 case DW_TAG_typedef
:
11747 this_type
= read_typedef (die
, cu
);
11749 case DW_TAG_subrange_type
:
11750 this_type
= read_subrange_type (die
, cu
);
11752 case DW_TAG_base_type
:
11753 this_type
= read_base_type (die
, cu
);
11755 case DW_TAG_unspecified_type
:
11756 this_type
= read_unspecified_type (die
, cu
);
11758 case DW_TAG_namespace
:
11759 this_type
= read_namespace_type (die
, cu
);
11761 case DW_TAG_module
:
11762 this_type
= read_module_type (die
, cu
);
11765 complaint (&symfile_complaints
,
11766 _("unexpected tag in read_type_die: '%s'"),
11767 dwarf_tag_name (die
->tag
));
11774 /* See if we can figure out if the class lives in a namespace. We do
11775 this by looking for a member function; its demangled name will
11776 contain namespace info, if there is any.
11777 Return the computed name or NULL.
11778 Space for the result is allocated on the objfile's obstack.
11779 This is the full-die version of guess_partial_die_structure_name.
11780 In this case we know DIE has no useful parent. */
11783 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11785 struct die_info
*spec_die
;
11786 struct dwarf2_cu
*spec_cu
;
11787 struct die_info
*child
;
11790 spec_die
= die_specification (die
, &spec_cu
);
11791 if (spec_die
!= NULL
)
11797 for (child
= die
->child
;
11799 child
= child
->sibling
)
11801 if (child
->tag
== DW_TAG_subprogram
)
11803 struct attribute
*attr
;
11805 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
11807 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
11811 = language_class_name_from_physname (cu
->language_defn
,
11815 if (actual_name
!= NULL
)
11817 char *die_name
= dwarf2_name (die
, cu
);
11819 if (die_name
!= NULL
11820 && strcmp (die_name
, actual_name
) != 0)
11822 /* Strip off the class name from the full name.
11823 We want the prefix. */
11824 int die_name_len
= strlen (die_name
);
11825 int actual_name_len
= strlen (actual_name
);
11827 /* Test for '::' as a sanity check. */
11828 if (actual_name_len
> die_name_len
+ 2
11829 && actual_name
[actual_name_len
11830 - die_name_len
- 1] == ':')
11832 obsavestring (actual_name
,
11833 actual_name_len
- die_name_len
- 2,
11834 &cu
->objfile
->objfile_obstack
);
11837 xfree (actual_name
);
11846 /* Return the name of the namespace/class that DIE is defined within,
11847 or "" if we can't tell. The caller should not xfree the result.
11849 For example, if we're within the method foo() in the following
11859 then determine_prefix on foo's die will return "N::C". */
11862 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
11864 struct die_info
*parent
, *spec_die
;
11865 struct dwarf2_cu
*spec_cu
;
11866 struct type
*parent_type
;
11868 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
11869 && cu
->language
!= language_fortran
)
11872 /* We have to be careful in the presence of DW_AT_specification.
11873 For example, with GCC 3.4, given the code
11877 // Definition of N::foo.
11881 then we'll have a tree of DIEs like this:
11883 1: DW_TAG_compile_unit
11884 2: DW_TAG_namespace // N
11885 3: DW_TAG_subprogram // declaration of N::foo
11886 4: DW_TAG_subprogram // definition of N::foo
11887 DW_AT_specification // refers to die #3
11889 Thus, when processing die #4, we have to pretend that we're in
11890 the context of its DW_AT_specification, namely the contex of die
11893 spec_die
= die_specification (die
, &spec_cu
);
11894 if (spec_die
== NULL
)
11895 parent
= die
->parent
;
11898 parent
= spec_die
->parent
;
11902 if (parent
== NULL
)
11904 else if (parent
->building_fullname
)
11907 const char *parent_name
;
11909 /* It has been seen on RealView 2.2 built binaries,
11910 DW_TAG_template_type_param types actually _defined_ as
11911 children of the parent class:
11914 template class <class Enum> Class{};
11915 Class<enum E> class_e;
11917 1: DW_TAG_class_type (Class)
11918 2: DW_TAG_enumeration_type (E)
11919 3: DW_TAG_enumerator (enum1:0)
11920 3: DW_TAG_enumerator (enum2:1)
11922 2: DW_TAG_template_type_param
11923 DW_AT_type DW_FORM_ref_udata (E)
11925 Besides being broken debug info, it can put GDB into an
11926 infinite loop. Consider:
11928 When we're building the full name for Class<E>, we'll start
11929 at Class, and go look over its template type parameters,
11930 finding E. We'll then try to build the full name of E, and
11931 reach here. We're now trying to build the full name of E,
11932 and look over the parent DIE for containing scope. In the
11933 broken case, if we followed the parent DIE of E, we'd again
11934 find Class, and once again go look at its template type
11935 arguments, etc., etc. Simply don't consider such parent die
11936 as source-level parent of this die (it can't be, the language
11937 doesn't allow it), and break the loop here. */
11938 name
= dwarf2_name (die
, cu
);
11939 parent_name
= dwarf2_name (parent
, cu
);
11940 complaint (&symfile_complaints
,
11941 _("template param type '%s' defined within parent '%s'"),
11942 name
? name
: "<unknown>",
11943 parent_name
? parent_name
: "<unknown>");
11947 switch (parent
->tag
)
11949 case DW_TAG_namespace
:
11950 parent_type
= read_type_die (parent
, cu
);
11951 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
11952 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
11953 Work around this problem here. */
11954 if (cu
->language
== language_cplus
11955 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
11957 /* We give a name to even anonymous namespaces. */
11958 return TYPE_TAG_NAME (parent_type
);
11959 case DW_TAG_class_type
:
11960 case DW_TAG_interface_type
:
11961 case DW_TAG_structure_type
:
11962 case DW_TAG_union_type
:
11963 case DW_TAG_module
:
11964 parent_type
= read_type_die (parent
, cu
);
11965 if (TYPE_TAG_NAME (parent_type
) != NULL
)
11966 return TYPE_TAG_NAME (parent_type
);
11968 /* An anonymous structure is only allowed non-static data
11969 members; no typedefs, no member functions, et cetera.
11970 So it does not need a prefix. */
11972 case DW_TAG_compile_unit
:
11973 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
11974 if (cu
->language
== language_cplus
11975 && dwarf2_per_objfile
->types
.asection
!= NULL
11976 && die
->child
!= NULL
11977 && (die
->tag
== DW_TAG_class_type
11978 || die
->tag
== DW_TAG_structure_type
11979 || die
->tag
== DW_TAG_union_type
))
11981 char *name
= guess_full_die_structure_name (die
, cu
);
11987 return determine_prefix (parent
, cu
);
11991 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
11992 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
11993 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
11994 an obconcat, otherwise allocate storage for the result. The CU argument is
11995 used to determine the language and hence, the appropriate separator. */
11997 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12000 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12001 int physname
, struct dwarf2_cu
*cu
)
12003 const char *lead
= "";
12006 if (suffix
== NULL
|| suffix
[0] == '\0'
12007 || prefix
== NULL
|| prefix
[0] == '\0')
12009 else if (cu
->language
== language_java
)
12011 else if (cu
->language
== language_fortran
&& physname
)
12013 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12014 DW_AT_MIPS_linkage_name is preferred and used instead. */
12022 if (prefix
== NULL
)
12024 if (suffix
== NULL
)
12030 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12032 strcpy (retval
, lead
);
12033 strcat (retval
, prefix
);
12034 strcat (retval
, sep
);
12035 strcat (retval
, suffix
);
12040 /* We have an obstack. */
12041 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12045 /* Return sibling of die, NULL if no sibling. */
12047 static struct die_info
*
12048 sibling_die (struct die_info
*die
)
12050 return die
->sibling
;
12053 /* Get name of a die, return NULL if not found. */
12056 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12057 struct obstack
*obstack
)
12059 if (name
&& cu
->language
== language_cplus
)
12061 char *canon_name
= cp_canonicalize_string (name
);
12063 if (canon_name
!= NULL
)
12065 if (strcmp (canon_name
, name
) != 0)
12066 name
= obsavestring (canon_name
, strlen (canon_name
),
12068 xfree (canon_name
);
12075 /* Get name of a die, return NULL if not found. */
12078 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12080 struct attribute
*attr
;
12082 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12083 if ((!attr
|| !DW_STRING (attr
))
12084 && die
->tag
!= DW_TAG_class_type
12085 && die
->tag
!= DW_TAG_interface_type
12086 && die
->tag
!= DW_TAG_structure_type
12087 && die
->tag
!= DW_TAG_union_type
)
12092 case DW_TAG_compile_unit
:
12093 /* Compilation units have a DW_AT_name that is a filename, not
12094 a source language identifier. */
12095 case DW_TAG_enumeration_type
:
12096 case DW_TAG_enumerator
:
12097 /* These tags always have simple identifiers already; no need
12098 to canonicalize them. */
12099 return DW_STRING (attr
);
12101 case DW_TAG_subprogram
:
12102 /* Java constructors will all be named "<init>", so return
12103 the class name when we see this special case. */
12104 if (cu
->language
== language_java
12105 && DW_STRING (attr
) != NULL
12106 && strcmp (DW_STRING (attr
), "<init>") == 0)
12108 struct dwarf2_cu
*spec_cu
= cu
;
12109 struct die_info
*spec_die
;
12111 /* GCJ will output '<init>' for Java constructor names.
12112 For this special case, return the name of the parent class. */
12114 /* GCJ may output suprogram DIEs with AT_specification set.
12115 If so, use the name of the specified DIE. */
12116 spec_die
= die_specification (die
, &spec_cu
);
12117 if (spec_die
!= NULL
)
12118 return dwarf2_name (spec_die
, spec_cu
);
12123 if (die
->tag
== DW_TAG_class_type
)
12124 return dwarf2_name (die
, cu
);
12126 while (die
->tag
!= DW_TAG_compile_unit
);
12130 case DW_TAG_class_type
:
12131 case DW_TAG_interface_type
:
12132 case DW_TAG_structure_type
:
12133 case DW_TAG_union_type
:
12134 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12135 structures or unions. These were of the form "._%d" in GCC 4.1,
12136 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12137 and GCC 4.4. We work around this problem by ignoring these. */
12138 if (attr
&& DW_STRING (attr
)
12139 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12140 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12143 /* GCC might emit a nameless typedef that has a linkage name. See
12144 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12145 if (!attr
|| DW_STRING (attr
) == NULL
)
12147 char *demangled
= NULL
;
12149 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12151 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12153 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12156 /* Avoid demangling DW_STRING (attr) the second time on a second
12157 call for the same DIE. */
12158 if (!DW_STRING_IS_CANONICAL (attr
))
12159 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12163 /* FIXME: we already did this for the partial symbol... */
12165 = obsavestring (demangled
, strlen (demangled
),
12166 &cu
->objfile
->objfile_obstack
);
12167 DW_STRING_IS_CANONICAL (attr
) = 1;
12177 if (!DW_STRING_IS_CANONICAL (attr
))
12180 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12181 &cu
->objfile
->objfile_obstack
);
12182 DW_STRING_IS_CANONICAL (attr
) = 1;
12184 return DW_STRING (attr
);
12187 /* Return the die that this die in an extension of, or NULL if there
12188 is none. *EXT_CU is the CU containing DIE on input, and the CU
12189 containing the return value on output. */
12191 static struct die_info
*
12192 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12194 struct attribute
*attr
;
12196 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12200 return follow_die_ref (die
, attr
, ext_cu
);
12203 /* Convert a DIE tag into its string name. */
12206 dwarf_tag_name (unsigned tag
)
12210 case DW_TAG_padding
:
12211 return "DW_TAG_padding";
12212 case DW_TAG_array_type
:
12213 return "DW_TAG_array_type";
12214 case DW_TAG_class_type
:
12215 return "DW_TAG_class_type";
12216 case DW_TAG_entry_point
:
12217 return "DW_TAG_entry_point";
12218 case DW_TAG_enumeration_type
:
12219 return "DW_TAG_enumeration_type";
12220 case DW_TAG_formal_parameter
:
12221 return "DW_TAG_formal_parameter";
12222 case DW_TAG_imported_declaration
:
12223 return "DW_TAG_imported_declaration";
12225 return "DW_TAG_label";
12226 case DW_TAG_lexical_block
:
12227 return "DW_TAG_lexical_block";
12228 case DW_TAG_member
:
12229 return "DW_TAG_member";
12230 case DW_TAG_pointer_type
:
12231 return "DW_TAG_pointer_type";
12232 case DW_TAG_reference_type
:
12233 return "DW_TAG_reference_type";
12234 case DW_TAG_compile_unit
:
12235 return "DW_TAG_compile_unit";
12236 case DW_TAG_string_type
:
12237 return "DW_TAG_string_type";
12238 case DW_TAG_structure_type
:
12239 return "DW_TAG_structure_type";
12240 case DW_TAG_subroutine_type
:
12241 return "DW_TAG_subroutine_type";
12242 case DW_TAG_typedef
:
12243 return "DW_TAG_typedef";
12244 case DW_TAG_union_type
:
12245 return "DW_TAG_union_type";
12246 case DW_TAG_unspecified_parameters
:
12247 return "DW_TAG_unspecified_parameters";
12248 case DW_TAG_variant
:
12249 return "DW_TAG_variant";
12250 case DW_TAG_common_block
:
12251 return "DW_TAG_common_block";
12252 case DW_TAG_common_inclusion
:
12253 return "DW_TAG_common_inclusion";
12254 case DW_TAG_inheritance
:
12255 return "DW_TAG_inheritance";
12256 case DW_TAG_inlined_subroutine
:
12257 return "DW_TAG_inlined_subroutine";
12258 case DW_TAG_module
:
12259 return "DW_TAG_module";
12260 case DW_TAG_ptr_to_member_type
:
12261 return "DW_TAG_ptr_to_member_type";
12262 case DW_TAG_set_type
:
12263 return "DW_TAG_set_type";
12264 case DW_TAG_subrange_type
:
12265 return "DW_TAG_subrange_type";
12266 case DW_TAG_with_stmt
:
12267 return "DW_TAG_with_stmt";
12268 case DW_TAG_access_declaration
:
12269 return "DW_TAG_access_declaration";
12270 case DW_TAG_base_type
:
12271 return "DW_TAG_base_type";
12272 case DW_TAG_catch_block
:
12273 return "DW_TAG_catch_block";
12274 case DW_TAG_const_type
:
12275 return "DW_TAG_const_type";
12276 case DW_TAG_constant
:
12277 return "DW_TAG_constant";
12278 case DW_TAG_enumerator
:
12279 return "DW_TAG_enumerator";
12280 case DW_TAG_file_type
:
12281 return "DW_TAG_file_type";
12282 case DW_TAG_friend
:
12283 return "DW_TAG_friend";
12284 case DW_TAG_namelist
:
12285 return "DW_TAG_namelist";
12286 case DW_TAG_namelist_item
:
12287 return "DW_TAG_namelist_item";
12288 case DW_TAG_packed_type
:
12289 return "DW_TAG_packed_type";
12290 case DW_TAG_subprogram
:
12291 return "DW_TAG_subprogram";
12292 case DW_TAG_template_type_param
:
12293 return "DW_TAG_template_type_param";
12294 case DW_TAG_template_value_param
:
12295 return "DW_TAG_template_value_param";
12296 case DW_TAG_thrown_type
:
12297 return "DW_TAG_thrown_type";
12298 case DW_TAG_try_block
:
12299 return "DW_TAG_try_block";
12300 case DW_TAG_variant_part
:
12301 return "DW_TAG_variant_part";
12302 case DW_TAG_variable
:
12303 return "DW_TAG_variable";
12304 case DW_TAG_volatile_type
:
12305 return "DW_TAG_volatile_type";
12306 case DW_TAG_dwarf_procedure
:
12307 return "DW_TAG_dwarf_procedure";
12308 case DW_TAG_restrict_type
:
12309 return "DW_TAG_restrict_type";
12310 case DW_TAG_interface_type
:
12311 return "DW_TAG_interface_type";
12312 case DW_TAG_namespace
:
12313 return "DW_TAG_namespace";
12314 case DW_TAG_imported_module
:
12315 return "DW_TAG_imported_module";
12316 case DW_TAG_unspecified_type
:
12317 return "DW_TAG_unspecified_type";
12318 case DW_TAG_partial_unit
:
12319 return "DW_TAG_partial_unit";
12320 case DW_TAG_imported_unit
:
12321 return "DW_TAG_imported_unit";
12322 case DW_TAG_condition
:
12323 return "DW_TAG_condition";
12324 case DW_TAG_shared_type
:
12325 return "DW_TAG_shared_type";
12326 case DW_TAG_type_unit
:
12327 return "DW_TAG_type_unit";
12328 case DW_TAG_MIPS_loop
:
12329 return "DW_TAG_MIPS_loop";
12330 case DW_TAG_HP_array_descriptor
:
12331 return "DW_TAG_HP_array_descriptor";
12332 case DW_TAG_format_label
:
12333 return "DW_TAG_format_label";
12334 case DW_TAG_function_template
:
12335 return "DW_TAG_function_template";
12336 case DW_TAG_class_template
:
12337 return "DW_TAG_class_template";
12338 case DW_TAG_GNU_BINCL
:
12339 return "DW_TAG_GNU_BINCL";
12340 case DW_TAG_GNU_EINCL
:
12341 return "DW_TAG_GNU_EINCL";
12342 case DW_TAG_upc_shared_type
:
12343 return "DW_TAG_upc_shared_type";
12344 case DW_TAG_upc_strict_type
:
12345 return "DW_TAG_upc_strict_type";
12346 case DW_TAG_upc_relaxed_type
:
12347 return "DW_TAG_upc_relaxed_type";
12348 case DW_TAG_PGI_kanji_type
:
12349 return "DW_TAG_PGI_kanji_type";
12350 case DW_TAG_PGI_interface_block
:
12351 return "DW_TAG_PGI_interface_block";
12353 return "DW_TAG_<unknown>";
12357 /* Convert a DWARF attribute code into its string name. */
12360 dwarf_attr_name (unsigned attr
)
12364 case DW_AT_sibling
:
12365 return "DW_AT_sibling";
12366 case DW_AT_location
:
12367 return "DW_AT_location";
12369 return "DW_AT_name";
12370 case DW_AT_ordering
:
12371 return "DW_AT_ordering";
12372 case DW_AT_subscr_data
:
12373 return "DW_AT_subscr_data";
12374 case DW_AT_byte_size
:
12375 return "DW_AT_byte_size";
12376 case DW_AT_bit_offset
:
12377 return "DW_AT_bit_offset";
12378 case DW_AT_bit_size
:
12379 return "DW_AT_bit_size";
12380 case DW_AT_element_list
:
12381 return "DW_AT_element_list";
12382 case DW_AT_stmt_list
:
12383 return "DW_AT_stmt_list";
12385 return "DW_AT_low_pc";
12386 case DW_AT_high_pc
:
12387 return "DW_AT_high_pc";
12388 case DW_AT_language
:
12389 return "DW_AT_language";
12391 return "DW_AT_member";
12393 return "DW_AT_discr";
12394 case DW_AT_discr_value
:
12395 return "DW_AT_discr_value";
12396 case DW_AT_visibility
:
12397 return "DW_AT_visibility";
12399 return "DW_AT_import";
12400 case DW_AT_string_length
:
12401 return "DW_AT_string_length";
12402 case DW_AT_common_reference
:
12403 return "DW_AT_common_reference";
12404 case DW_AT_comp_dir
:
12405 return "DW_AT_comp_dir";
12406 case DW_AT_const_value
:
12407 return "DW_AT_const_value";
12408 case DW_AT_containing_type
:
12409 return "DW_AT_containing_type";
12410 case DW_AT_default_value
:
12411 return "DW_AT_default_value";
12413 return "DW_AT_inline";
12414 case DW_AT_is_optional
:
12415 return "DW_AT_is_optional";
12416 case DW_AT_lower_bound
:
12417 return "DW_AT_lower_bound";
12418 case DW_AT_producer
:
12419 return "DW_AT_producer";
12420 case DW_AT_prototyped
:
12421 return "DW_AT_prototyped";
12422 case DW_AT_return_addr
:
12423 return "DW_AT_return_addr";
12424 case DW_AT_start_scope
:
12425 return "DW_AT_start_scope";
12426 case DW_AT_bit_stride
:
12427 return "DW_AT_bit_stride";
12428 case DW_AT_upper_bound
:
12429 return "DW_AT_upper_bound";
12430 case DW_AT_abstract_origin
:
12431 return "DW_AT_abstract_origin";
12432 case DW_AT_accessibility
:
12433 return "DW_AT_accessibility";
12434 case DW_AT_address_class
:
12435 return "DW_AT_address_class";
12436 case DW_AT_artificial
:
12437 return "DW_AT_artificial";
12438 case DW_AT_base_types
:
12439 return "DW_AT_base_types";
12440 case DW_AT_calling_convention
:
12441 return "DW_AT_calling_convention";
12443 return "DW_AT_count";
12444 case DW_AT_data_member_location
:
12445 return "DW_AT_data_member_location";
12446 case DW_AT_decl_column
:
12447 return "DW_AT_decl_column";
12448 case DW_AT_decl_file
:
12449 return "DW_AT_decl_file";
12450 case DW_AT_decl_line
:
12451 return "DW_AT_decl_line";
12452 case DW_AT_declaration
:
12453 return "DW_AT_declaration";
12454 case DW_AT_discr_list
:
12455 return "DW_AT_discr_list";
12456 case DW_AT_encoding
:
12457 return "DW_AT_encoding";
12458 case DW_AT_external
:
12459 return "DW_AT_external";
12460 case DW_AT_frame_base
:
12461 return "DW_AT_frame_base";
12463 return "DW_AT_friend";
12464 case DW_AT_identifier_case
:
12465 return "DW_AT_identifier_case";
12466 case DW_AT_macro_info
:
12467 return "DW_AT_macro_info";
12468 case DW_AT_namelist_items
:
12469 return "DW_AT_namelist_items";
12470 case DW_AT_priority
:
12471 return "DW_AT_priority";
12472 case DW_AT_segment
:
12473 return "DW_AT_segment";
12474 case DW_AT_specification
:
12475 return "DW_AT_specification";
12476 case DW_AT_static_link
:
12477 return "DW_AT_static_link";
12479 return "DW_AT_type";
12480 case DW_AT_use_location
:
12481 return "DW_AT_use_location";
12482 case DW_AT_variable_parameter
:
12483 return "DW_AT_variable_parameter";
12484 case DW_AT_virtuality
:
12485 return "DW_AT_virtuality";
12486 case DW_AT_vtable_elem_location
:
12487 return "DW_AT_vtable_elem_location";
12488 /* DWARF 3 values. */
12489 case DW_AT_allocated
:
12490 return "DW_AT_allocated";
12491 case DW_AT_associated
:
12492 return "DW_AT_associated";
12493 case DW_AT_data_location
:
12494 return "DW_AT_data_location";
12495 case DW_AT_byte_stride
:
12496 return "DW_AT_byte_stride";
12497 case DW_AT_entry_pc
:
12498 return "DW_AT_entry_pc";
12499 case DW_AT_use_UTF8
:
12500 return "DW_AT_use_UTF8";
12501 case DW_AT_extension
:
12502 return "DW_AT_extension";
12504 return "DW_AT_ranges";
12505 case DW_AT_trampoline
:
12506 return "DW_AT_trampoline";
12507 case DW_AT_call_column
:
12508 return "DW_AT_call_column";
12509 case DW_AT_call_file
:
12510 return "DW_AT_call_file";
12511 case DW_AT_call_line
:
12512 return "DW_AT_call_line";
12513 case DW_AT_description
:
12514 return "DW_AT_description";
12515 case DW_AT_binary_scale
:
12516 return "DW_AT_binary_scale";
12517 case DW_AT_decimal_scale
:
12518 return "DW_AT_decimal_scale";
12520 return "DW_AT_small";
12521 case DW_AT_decimal_sign
:
12522 return "DW_AT_decimal_sign";
12523 case DW_AT_digit_count
:
12524 return "DW_AT_digit_count";
12525 case DW_AT_picture_string
:
12526 return "DW_AT_picture_string";
12527 case DW_AT_mutable
:
12528 return "DW_AT_mutable";
12529 case DW_AT_threads_scaled
:
12530 return "DW_AT_threads_scaled";
12531 case DW_AT_explicit
:
12532 return "DW_AT_explicit";
12533 case DW_AT_object_pointer
:
12534 return "DW_AT_object_pointer";
12535 case DW_AT_endianity
:
12536 return "DW_AT_endianity";
12537 case DW_AT_elemental
:
12538 return "DW_AT_elemental";
12540 return "DW_AT_pure";
12541 case DW_AT_recursive
:
12542 return "DW_AT_recursive";
12543 /* DWARF 4 values. */
12544 case DW_AT_signature
:
12545 return "DW_AT_signature";
12546 case DW_AT_linkage_name
:
12547 return "DW_AT_linkage_name";
12548 /* SGI/MIPS extensions. */
12549 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12550 case DW_AT_MIPS_fde
:
12551 return "DW_AT_MIPS_fde";
12553 case DW_AT_MIPS_loop_begin
:
12554 return "DW_AT_MIPS_loop_begin";
12555 case DW_AT_MIPS_tail_loop_begin
:
12556 return "DW_AT_MIPS_tail_loop_begin";
12557 case DW_AT_MIPS_epilog_begin
:
12558 return "DW_AT_MIPS_epilog_begin";
12559 case DW_AT_MIPS_loop_unroll_factor
:
12560 return "DW_AT_MIPS_loop_unroll_factor";
12561 case DW_AT_MIPS_software_pipeline_depth
:
12562 return "DW_AT_MIPS_software_pipeline_depth";
12563 case DW_AT_MIPS_linkage_name
:
12564 return "DW_AT_MIPS_linkage_name";
12565 case DW_AT_MIPS_stride
:
12566 return "DW_AT_MIPS_stride";
12567 case DW_AT_MIPS_abstract_name
:
12568 return "DW_AT_MIPS_abstract_name";
12569 case DW_AT_MIPS_clone_origin
:
12570 return "DW_AT_MIPS_clone_origin";
12571 case DW_AT_MIPS_has_inlines
:
12572 return "DW_AT_MIPS_has_inlines";
12573 /* HP extensions. */
12574 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12575 case DW_AT_HP_block_index
:
12576 return "DW_AT_HP_block_index";
12578 case DW_AT_HP_unmodifiable
:
12579 return "DW_AT_HP_unmodifiable";
12580 case DW_AT_HP_actuals_stmt_list
:
12581 return "DW_AT_HP_actuals_stmt_list";
12582 case DW_AT_HP_proc_per_section
:
12583 return "DW_AT_HP_proc_per_section";
12584 case DW_AT_HP_raw_data_ptr
:
12585 return "DW_AT_HP_raw_data_ptr";
12586 case DW_AT_HP_pass_by_reference
:
12587 return "DW_AT_HP_pass_by_reference";
12588 case DW_AT_HP_opt_level
:
12589 return "DW_AT_HP_opt_level";
12590 case DW_AT_HP_prof_version_id
:
12591 return "DW_AT_HP_prof_version_id";
12592 case DW_AT_HP_opt_flags
:
12593 return "DW_AT_HP_opt_flags";
12594 case DW_AT_HP_cold_region_low_pc
:
12595 return "DW_AT_HP_cold_region_low_pc";
12596 case DW_AT_HP_cold_region_high_pc
:
12597 return "DW_AT_HP_cold_region_high_pc";
12598 case DW_AT_HP_all_variables_modifiable
:
12599 return "DW_AT_HP_all_variables_modifiable";
12600 case DW_AT_HP_linkage_name
:
12601 return "DW_AT_HP_linkage_name";
12602 case DW_AT_HP_prof_flags
:
12603 return "DW_AT_HP_prof_flags";
12604 /* GNU extensions. */
12605 case DW_AT_sf_names
:
12606 return "DW_AT_sf_names";
12607 case DW_AT_src_info
:
12608 return "DW_AT_src_info";
12609 case DW_AT_mac_info
:
12610 return "DW_AT_mac_info";
12611 case DW_AT_src_coords
:
12612 return "DW_AT_src_coords";
12613 case DW_AT_body_begin
:
12614 return "DW_AT_body_begin";
12615 case DW_AT_body_end
:
12616 return "DW_AT_body_end";
12617 case DW_AT_GNU_vector
:
12618 return "DW_AT_GNU_vector";
12619 case DW_AT_GNU_odr_signature
:
12620 return "DW_AT_GNU_odr_signature";
12621 /* VMS extensions. */
12622 case DW_AT_VMS_rtnbeg_pd_address
:
12623 return "DW_AT_VMS_rtnbeg_pd_address";
12624 /* UPC extension. */
12625 case DW_AT_upc_threads_scaled
:
12626 return "DW_AT_upc_threads_scaled";
12627 /* PGI (STMicroelectronics) extensions. */
12628 case DW_AT_PGI_lbase
:
12629 return "DW_AT_PGI_lbase";
12630 case DW_AT_PGI_soffset
:
12631 return "DW_AT_PGI_soffset";
12632 case DW_AT_PGI_lstride
:
12633 return "DW_AT_PGI_lstride";
12635 return "DW_AT_<unknown>";
12639 /* Convert a DWARF value form code into its string name. */
12642 dwarf_form_name (unsigned form
)
12647 return "DW_FORM_addr";
12648 case DW_FORM_block2
:
12649 return "DW_FORM_block2";
12650 case DW_FORM_block4
:
12651 return "DW_FORM_block4";
12652 case DW_FORM_data2
:
12653 return "DW_FORM_data2";
12654 case DW_FORM_data4
:
12655 return "DW_FORM_data4";
12656 case DW_FORM_data8
:
12657 return "DW_FORM_data8";
12658 case DW_FORM_string
:
12659 return "DW_FORM_string";
12660 case DW_FORM_block
:
12661 return "DW_FORM_block";
12662 case DW_FORM_block1
:
12663 return "DW_FORM_block1";
12664 case DW_FORM_data1
:
12665 return "DW_FORM_data1";
12667 return "DW_FORM_flag";
12668 case DW_FORM_sdata
:
12669 return "DW_FORM_sdata";
12671 return "DW_FORM_strp";
12672 case DW_FORM_udata
:
12673 return "DW_FORM_udata";
12674 case DW_FORM_ref_addr
:
12675 return "DW_FORM_ref_addr";
12677 return "DW_FORM_ref1";
12679 return "DW_FORM_ref2";
12681 return "DW_FORM_ref4";
12683 return "DW_FORM_ref8";
12684 case DW_FORM_ref_udata
:
12685 return "DW_FORM_ref_udata";
12686 case DW_FORM_indirect
:
12687 return "DW_FORM_indirect";
12688 case DW_FORM_sec_offset
:
12689 return "DW_FORM_sec_offset";
12690 case DW_FORM_exprloc
:
12691 return "DW_FORM_exprloc";
12692 case DW_FORM_flag_present
:
12693 return "DW_FORM_flag_present";
12694 case DW_FORM_ref_sig8
:
12695 return "DW_FORM_ref_sig8";
12697 return "DW_FORM_<unknown>";
12701 /* Convert a DWARF stack opcode into its string name. */
12704 dwarf_stack_op_name (unsigned op
)
12709 return "DW_OP_addr";
12711 return "DW_OP_deref";
12712 case DW_OP_const1u
:
12713 return "DW_OP_const1u";
12714 case DW_OP_const1s
:
12715 return "DW_OP_const1s";
12716 case DW_OP_const2u
:
12717 return "DW_OP_const2u";
12718 case DW_OP_const2s
:
12719 return "DW_OP_const2s";
12720 case DW_OP_const4u
:
12721 return "DW_OP_const4u";
12722 case DW_OP_const4s
:
12723 return "DW_OP_const4s";
12724 case DW_OP_const8u
:
12725 return "DW_OP_const8u";
12726 case DW_OP_const8s
:
12727 return "DW_OP_const8s";
12729 return "DW_OP_constu";
12731 return "DW_OP_consts";
12733 return "DW_OP_dup";
12735 return "DW_OP_drop";
12737 return "DW_OP_over";
12739 return "DW_OP_pick";
12741 return "DW_OP_swap";
12743 return "DW_OP_rot";
12745 return "DW_OP_xderef";
12747 return "DW_OP_abs";
12749 return "DW_OP_and";
12751 return "DW_OP_div";
12753 return "DW_OP_minus";
12755 return "DW_OP_mod";
12757 return "DW_OP_mul";
12759 return "DW_OP_neg";
12761 return "DW_OP_not";
12765 return "DW_OP_plus";
12766 case DW_OP_plus_uconst
:
12767 return "DW_OP_plus_uconst";
12769 return "DW_OP_shl";
12771 return "DW_OP_shr";
12773 return "DW_OP_shra";
12775 return "DW_OP_xor";
12777 return "DW_OP_bra";
12791 return "DW_OP_skip";
12793 return "DW_OP_lit0";
12795 return "DW_OP_lit1";
12797 return "DW_OP_lit2";
12799 return "DW_OP_lit3";
12801 return "DW_OP_lit4";
12803 return "DW_OP_lit5";
12805 return "DW_OP_lit6";
12807 return "DW_OP_lit7";
12809 return "DW_OP_lit8";
12811 return "DW_OP_lit9";
12813 return "DW_OP_lit10";
12815 return "DW_OP_lit11";
12817 return "DW_OP_lit12";
12819 return "DW_OP_lit13";
12821 return "DW_OP_lit14";
12823 return "DW_OP_lit15";
12825 return "DW_OP_lit16";
12827 return "DW_OP_lit17";
12829 return "DW_OP_lit18";
12831 return "DW_OP_lit19";
12833 return "DW_OP_lit20";
12835 return "DW_OP_lit21";
12837 return "DW_OP_lit22";
12839 return "DW_OP_lit23";
12841 return "DW_OP_lit24";
12843 return "DW_OP_lit25";
12845 return "DW_OP_lit26";
12847 return "DW_OP_lit27";
12849 return "DW_OP_lit28";
12851 return "DW_OP_lit29";
12853 return "DW_OP_lit30";
12855 return "DW_OP_lit31";
12857 return "DW_OP_reg0";
12859 return "DW_OP_reg1";
12861 return "DW_OP_reg2";
12863 return "DW_OP_reg3";
12865 return "DW_OP_reg4";
12867 return "DW_OP_reg5";
12869 return "DW_OP_reg6";
12871 return "DW_OP_reg7";
12873 return "DW_OP_reg8";
12875 return "DW_OP_reg9";
12877 return "DW_OP_reg10";
12879 return "DW_OP_reg11";
12881 return "DW_OP_reg12";
12883 return "DW_OP_reg13";
12885 return "DW_OP_reg14";
12887 return "DW_OP_reg15";
12889 return "DW_OP_reg16";
12891 return "DW_OP_reg17";
12893 return "DW_OP_reg18";
12895 return "DW_OP_reg19";
12897 return "DW_OP_reg20";
12899 return "DW_OP_reg21";
12901 return "DW_OP_reg22";
12903 return "DW_OP_reg23";
12905 return "DW_OP_reg24";
12907 return "DW_OP_reg25";
12909 return "DW_OP_reg26";
12911 return "DW_OP_reg27";
12913 return "DW_OP_reg28";
12915 return "DW_OP_reg29";
12917 return "DW_OP_reg30";
12919 return "DW_OP_reg31";
12921 return "DW_OP_breg0";
12923 return "DW_OP_breg1";
12925 return "DW_OP_breg2";
12927 return "DW_OP_breg3";
12929 return "DW_OP_breg4";
12931 return "DW_OP_breg5";
12933 return "DW_OP_breg6";
12935 return "DW_OP_breg7";
12937 return "DW_OP_breg8";
12939 return "DW_OP_breg9";
12941 return "DW_OP_breg10";
12943 return "DW_OP_breg11";
12945 return "DW_OP_breg12";
12947 return "DW_OP_breg13";
12949 return "DW_OP_breg14";
12951 return "DW_OP_breg15";
12953 return "DW_OP_breg16";
12955 return "DW_OP_breg17";
12957 return "DW_OP_breg18";
12959 return "DW_OP_breg19";
12961 return "DW_OP_breg20";
12963 return "DW_OP_breg21";
12965 return "DW_OP_breg22";
12967 return "DW_OP_breg23";
12969 return "DW_OP_breg24";
12971 return "DW_OP_breg25";
12973 return "DW_OP_breg26";
12975 return "DW_OP_breg27";
12977 return "DW_OP_breg28";
12979 return "DW_OP_breg29";
12981 return "DW_OP_breg30";
12983 return "DW_OP_breg31";
12985 return "DW_OP_regx";
12987 return "DW_OP_fbreg";
12989 return "DW_OP_bregx";
12991 return "DW_OP_piece";
12992 case DW_OP_deref_size
:
12993 return "DW_OP_deref_size";
12994 case DW_OP_xderef_size
:
12995 return "DW_OP_xderef_size";
12997 return "DW_OP_nop";
12998 /* DWARF 3 extensions. */
12999 case DW_OP_push_object_address
:
13000 return "DW_OP_push_object_address";
13002 return "DW_OP_call2";
13004 return "DW_OP_call4";
13005 case DW_OP_call_ref
:
13006 return "DW_OP_call_ref";
13007 case DW_OP_form_tls_address
:
13008 return "DW_OP_form_tls_address";
13009 case DW_OP_call_frame_cfa
:
13010 return "DW_OP_call_frame_cfa";
13011 case DW_OP_bit_piece
:
13012 return "DW_OP_bit_piece";
13013 /* DWARF 4 extensions. */
13014 case DW_OP_implicit_value
:
13015 return "DW_OP_implicit_value";
13016 case DW_OP_stack_value
:
13017 return "DW_OP_stack_value";
13018 /* GNU extensions. */
13019 case DW_OP_GNU_push_tls_address
:
13020 return "DW_OP_GNU_push_tls_address";
13021 case DW_OP_GNU_uninit
:
13022 return "DW_OP_GNU_uninit";
13023 case DW_OP_GNU_implicit_pointer
:
13024 return "DW_OP_GNU_implicit_pointer";
13031 dwarf_bool_name (unsigned mybool
)
13039 /* Convert a DWARF type code into its string name. */
13042 dwarf_type_encoding_name (unsigned enc
)
13047 return "DW_ATE_void";
13048 case DW_ATE_address
:
13049 return "DW_ATE_address";
13050 case DW_ATE_boolean
:
13051 return "DW_ATE_boolean";
13052 case DW_ATE_complex_float
:
13053 return "DW_ATE_complex_float";
13055 return "DW_ATE_float";
13056 case DW_ATE_signed
:
13057 return "DW_ATE_signed";
13058 case DW_ATE_signed_char
:
13059 return "DW_ATE_signed_char";
13060 case DW_ATE_unsigned
:
13061 return "DW_ATE_unsigned";
13062 case DW_ATE_unsigned_char
:
13063 return "DW_ATE_unsigned_char";
13065 case DW_ATE_imaginary_float
:
13066 return "DW_ATE_imaginary_float";
13067 case DW_ATE_packed_decimal
:
13068 return "DW_ATE_packed_decimal";
13069 case DW_ATE_numeric_string
:
13070 return "DW_ATE_numeric_string";
13071 case DW_ATE_edited
:
13072 return "DW_ATE_edited";
13073 case DW_ATE_signed_fixed
:
13074 return "DW_ATE_signed_fixed";
13075 case DW_ATE_unsigned_fixed
:
13076 return "DW_ATE_unsigned_fixed";
13077 case DW_ATE_decimal_float
:
13078 return "DW_ATE_decimal_float";
13081 return "DW_ATE_UTF";
13082 /* HP extensions. */
13083 case DW_ATE_HP_float80
:
13084 return "DW_ATE_HP_float80";
13085 case DW_ATE_HP_complex_float80
:
13086 return "DW_ATE_HP_complex_float80";
13087 case DW_ATE_HP_float128
:
13088 return "DW_ATE_HP_float128";
13089 case DW_ATE_HP_complex_float128
:
13090 return "DW_ATE_HP_complex_float128";
13091 case DW_ATE_HP_floathpintel
:
13092 return "DW_ATE_HP_floathpintel";
13093 case DW_ATE_HP_imaginary_float80
:
13094 return "DW_ATE_HP_imaginary_float80";
13095 case DW_ATE_HP_imaginary_float128
:
13096 return "DW_ATE_HP_imaginary_float128";
13098 return "DW_ATE_<unknown>";
13102 /* Convert a DWARF call frame info operation to its string name. */
13106 dwarf_cfi_name (unsigned cfi_opc
)
13110 case DW_CFA_advance_loc
:
13111 return "DW_CFA_advance_loc";
13112 case DW_CFA_offset
:
13113 return "DW_CFA_offset";
13114 case DW_CFA_restore
:
13115 return "DW_CFA_restore";
13117 return "DW_CFA_nop";
13118 case DW_CFA_set_loc
:
13119 return "DW_CFA_set_loc";
13120 case DW_CFA_advance_loc1
:
13121 return "DW_CFA_advance_loc1";
13122 case DW_CFA_advance_loc2
:
13123 return "DW_CFA_advance_loc2";
13124 case DW_CFA_advance_loc4
:
13125 return "DW_CFA_advance_loc4";
13126 case DW_CFA_offset_extended
:
13127 return "DW_CFA_offset_extended";
13128 case DW_CFA_restore_extended
:
13129 return "DW_CFA_restore_extended";
13130 case DW_CFA_undefined
:
13131 return "DW_CFA_undefined";
13132 case DW_CFA_same_value
:
13133 return "DW_CFA_same_value";
13134 case DW_CFA_register
:
13135 return "DW_CFA_register";
13136 case DW_CFA_remember_state
:
13137 return "DW_CFA_remember_state";
13138 case DW_CFA_restore_state
:
13139 return "DW_CFA_restore_state";
13140 case DW_CFA_def_cfa
:
13141 return "DW_CFA_def_cfa";
13142 case DW_CFA_def_cfa_register
:
13143 return "DW_CFA_def_cfa_register";
13144 case DW_CFA_def_cfa_offset
:
13145 return "DW_CFA_def_cfa_offset";
13147 case DW_CFA_def_cfa_expression
:
13148 return "DW_CFA_def_cfa_expression";
13149 case DW_CFA_expression
:
13150 return "DW_CFA_expression";
13151 case DW_CFA_offset_extended_sf
:
13152 return "DW_CFA_offset_extended_sf";
13153 case DW_CFA_def_cfa_sf
:
13154 return "DW_CFA_def_cfa_sf";
13155 case DW_CFA_def_cfa_offset_sf
:
13156 return "DW_CFA_def_cfa_offset_sf";
13157 case DW_CFA_val_offset
:
13158 return "DW_CFA_val_offset";
13159 case DW_CFA_val_offset_sf
:
13160 return "DW_CFA_val_offset_sf";
13161 case DW_CFA_val_expression
:
13162 return "DW_CFA_val_expression";
13163 /* SGI/MIPS specific. */
13164 case DW_CFA_MIPS_advance_loc8
:
13165 return "DW_CFA_MIPS_advance_loc8";
13166 /* GNU extensions. */
13167 case DW_CFA_GNU_window_save
:
13168 return "DW_CFA_GNU_window_save";
13169 case DW_CFA_GNU_args_size
:
13170 return "DW_CFA_GNU_args_size";
13171 case DW_CFA_GNU_negative_offset_extended
:
13172 return "DW_CFA_GNU_negative_offset_extended";
13174 return "DW_CFA_<unknown>";
13180 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13184 print_spaces (indent
, f
);
13185 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13186 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13188 if (die
->parent
!= NULL
)
13190 print_spaces (indent
, f
);
13191 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13192 die
->parent
->offset
);
13195 print_spaces (indent
, f
);
13196 fprintf_unfiltered (f
, " has children: %s\n",
13197 dwarf_bool_name (die
->child
!= NULL
));
13199 print_spaces (indent
, f
);
13200 fprintf_unfiltered (f
, " attributes:\n");
13202 for (i
= 0; i
< die
->num_attrs
; ++i
)
13204 print_spaces (indent
, f
);
13205 fprintf_unfiltered (f
, " %s (%s) ",
13206 dwarf_attr_name (die
->attrs
[i
].name
),
13207 dwarf_form_name (die
->attrs
[i
].form
));
13209 switch (die
->attrs
[i
].form
)
13211 case DW_FORM_ref_addr
:
13213 fprintf_unfiltered (f
, "address: ");
13214 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13216 case DW_FORM_block2
:
13217 case DW_FORM_block4
:
13218 case DW_FORM_block
:
13219 case DW_FORM_block1
:
13220 fprintf_unfiltered (f
, "block: size %d",
13221 DW_BLOCK (&die
->attrs
[i
])->size
);
13223 case DW_FORM_exprloc
:
13224 fprintf_unfiltered (f
, "expression: size %u",
13225 DW_BLOCK (&die
->attrs
[i
])->size
);
13230 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13231 (long) (DW_ADDR (&die
->attrs
[i
])));
13233 case DW_FORM_data1
:
13234 case DW_FORM_data2
:
13235 case DW_FORM_data4
:
13236 case DW_FORM_data8
:
13237 case DW_FORM_udata
:
13238 case DW_FORM_sdata
:
13239 fprintf_unfiltered (f
, "constant: %s",
13240 pulongest (DW_UNSND (&die
->attrs
[i
])));
13242 case DW_FORM_sec_offset
:
13243 fprintf_unfiltered (f
, "section offset: %s",
13244 pulongest (DW_UNSND (&die
->attrs
[i
])));
13246 case DW_FORM_ref_sig8
:
13247 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13248 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13249 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
13251 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13253 case DW_FORM_string
:
13255 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13256 DW_STRING (&die
->attrs
[i
])
13257 ? DW_STRING (&die
->attrs
[i
]) : "",
13258 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13261 if (DW_UNSND (&die
->attrs
[i
]))
13262 fprintf_unfiltered (f
, "flag: TRUE");
13264 fprintf_unfiltered (f
, "flag: FALSE");
13266 case DW_FORM_flag_present
:
13267 fprintf_unfiltered (f
, "flag: TRUE");
13269 case DW_FORM_indirect
:
13270 /* The reader will have reduced the indirect form to
13271 the "base form" so this form should not occur. */
13272 fprintf_unfiltered (f
,
13273 "unexpected attribute form: DW_FORM_indirect");
13276 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13277 die
->attrs
[i
].form
);
13280 fprintf_unfiltered (f
, "\n");
13285 dump_die_for_error (struct die_info
*die
)
13287 dump_die_shallow (gdb_stderr
, 0, die
);
13291 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13293 int indent
= level
* 4;
13295 gdb_assert (die
!= NULL
);
13297 if (level
>= max_level
)
13300 dump_die_shallow (f
, indent
, die
);
13302 if (die
->child
!= NULL
)
13304 print_spaces (indent
, f
);
13305 fprintf_unfiltered (f
, " Children:");
13306 if (level
+ 1 < max_level
)
13308 fprintf_unfiltered (f
, "\n");
13309 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13313 fprintf_unfiltered (f
,
13314 " [not printed, max nesting level reached]\n");
13318 if (die
->sibling
!= NULL
&& level
> 0)
13320 dump_die_1 (f
, level
, max_level
, die
->sibling
);
13324 /* This is called from the pdie macro in gdbinit.in.
13325 It's not static so gcc will keep a copy callable from gdb. */
13328 dump_die (struct die_info
*die
, int max_level
)
13330 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
13334 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
13338 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
13344 is_ref_attr (struct attribute
*attr
)
13346 switch (attr
->form
)
13348 case DW_FORM_ref_addr
:
13353 case DW_FORM_ref_udata
:
13360 static unsigned int
13361 dwarf2_get_ref_die_offset (struct attribute
*attr
)
13363 if (is_ref_attr (attr
))
13364 return DW_ADDR (attr
);
13366 complaint (&symfile_complaints
,
13367 _("unsupported die ref attribute form: '%s'"),
13368 dwarf_form_name (attr
->form
));
13372 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13373 * the value held by the attribute is not constant. */
13376 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
13378 if (attr
->form
== DW_FORM_sdata
)
13379 return DW_SND (attr
);
13380 else if (attr
->form
== DW_FORM_udata
13381 || attr
->form
== DW_FORM_data1
13382 || attr
->form
== DW_FORM_data2
13383 || attr
->form
== DW_FORM_data4
13384 || attr
->form
== DW_FORM_data8
)
13385 return DW_UNSND (attr
);
13388 complaint (&symfile_complaints
,
13389 _("Attribute value is not a constant (%s)"),
13390 dwarf_form_name (attr
->form
));
13391 return default_value
;
13395 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13396 unit and add it to our queue.
13397 The result is non-zero if PER_CU was queued, otherwise the result is zero
13398 meaning either PER_CU is already queued or it is already loaded. */
13401 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
13402 struct dwarf2_per_cu_data
*per_cu
)
13404 /* We may arrive here during partial symbol reading, if we need full
13405 DIEs to process an unusual case (e.g. template arguments). Do
13406 not queue PER_CU, just tell our caller to load its DIEs. */
13407 if (dwarf2_per_objfile
->reading_partial_symbols
)
13409 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
13414 /* Mark the dependence relation so that we don't flush PER_CU
13416 dwarf2_add_dependence (this_cu
, per_cu
);
13418 /* If it's already on the queue, we have nothing to do. */
13419 if (per_cu
->queued
)
13422 /* If the compilation unit is already loaded, just mark it as
13424 if (per_cu
->cu
!= NULL
)
13426 per_cu
->cu
->last_used
= 0;
13430 /* Add it to the queue. */
13431 queue_comp_unit (per_cu
, this_cu
->objfile
);
13436 /* Follow reference or signature attribute ATTR of SRC_DIE.
13437 On entry *REF_CU is the CU of SRC_DIE.
13438 On exit *REF_CU is the CU of the result. */
13440 static struct die_info
*
13441 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
13442 struct dwarf2_cu
**ref_cu
)
13444 struct die_info
*die
;
13446 if (is_ref_attr (attr
))
13447 die
= follow_die_ref (src_die
, attr
, ref_cu
);
13448 else if (attr
->form
== DW_FORM_ref_sig8
)
13449 die
= follow_die_sig (src_die
, attr
, ref_cu
);
13452 dump_die_for_error (src_die
);
13453 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13454 (*ref_cu
)->objfile
->name
);
13460 /* Follow reference OFFSET.
13461 On entry *REF_CU is the CU of the source die referencing OFFSET.
13462 On exit *REF_CU is the CU of the result.
13463 Returns NULL if OFFSET is invalid. */
13465 static struct die_info
*
13466 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
13468 struct die_info temp_die
;
13469 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
13471 gdb_assert (cu
->per_cu
!= NULL
);
13475 if (cu
->per_cu
->from_debug_types
)
13477 /* .debug_types CUs cannot reference anything outside their CU.
13478 If they need to, they have to reference a signatured type via
13479 DW_FORM_ref_sig8. */
13480 if (! offset_in_cu_p (&cu
->header
, offset
))
13483 else if (! offset_in_cu_p (&cu
->header
, offset
))
13485 struct dwarf2_per_cu_data
*per_cu
;
13487 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
13489 /* If necessary, add it to the queue and load its DIEs. */
13490 if (maybe_queue_comp_unit (cu
, per_cu
))
13491 load_full_comp_unit (per_cu
, cu
->objfile
);
13493 target_cu
= per_cu
->cu
;
13495 else if (cu
->dies
== NULL
)
13497 /* We're loading full DIEs during partial symbol reading. */
13498 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
13499 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
13502 *ref_cu
= target_cu
;
13503 temp_die
.offset
= offset
;
13504 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13507 /* Follow reference attribute ATTR of SRC_DIE.
13508 On entry *REF_CU is the CU of SRC_DIE.
13509 On exit *REF_CU is the CU of the result. */
13511 static struct die_info
*
13512 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13513 struct dwarf2_cu
**ref_cu
)
13515 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13516 struct dwarf2_cu
*cu
= *ref_cu
;
13517 struct die_info
*die
;
13519 die
= follow_die_offset (offset
, ref_cu
);
13521 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13522 "at 0x%x [in module %s]"),
13523 offset
, src_die
->offset
, cu
->objfile
->name
);
13528 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13529 value is intended for DW_OP_call*. */
13531 struct dwarf2_locexpr_baton
13532 dwarf2_fetch_die_location_block (unsigned int offset
,
13533 struct dwarf2_per_cu_data
*per_cu
,
13534 CORE_ADDR (*get_frame_pc
) (void *baton
),
13537 struct dwarf2_cu
*cu
= per_cu
->cu
;
13538 struct die_info
*die
;
13539 struct attribute
*attr
;
13540 struct dwarf2_locexpr_baton retval
;
13542 dw2_setup (per_cu
->objfile
);
13544 die
= follow_die_offset (offset
, &cu
);
13546 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13547 offset
, per_cu
->cu
->objfile
->name
);
13549 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13552 /* DWARF: "If there is no such attribute, then there is no effect.". */
13554 retval
.data
= NULL
;
13557 else if (attr_form_is_section_offset (attr
))
13559 struct dwarf2_loclist_baton loclist_baton
;
13560 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
13563 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
13565 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
13567 retval
.size
= size
;
13571 if (!attr_form_is_block (attr
))
13572 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13573 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13574 offset
, per_cu
->cu
->objfile
->name
);
13576 retval
.data
= DW_BLOCK (attr
)->data
;
13577 retval
.size
= DW_BLOCK (attr
)->size
;
13579 retval
.per_cu
= cu
->per_cu
;
13583 /* Follow the signature attribute ATTR in SRC_DIE.
13584 On entry *REF_CU is the CU of SRC_DIE.
13585 On exit *REF_CU is the CU of the result. */
13587 static struct die_info
*
13588 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
13589 struct dwarf2_cu
**ref_cu
)
13591 struct objfile
*objfile
= (*ref_cu
)->objfile
;
13592 struct die_info temp_die
;
13593 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13594 struct dwarf2_cu
*sig_cu
;
13595 struct die_info
*die
;
13597 /* sig_type will be NULL if the signatured type is missing from
13599 if (sig_type
== NULL
)
13600 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13601 "at 0x%x [in module %s]"),
13602 src_die
->offset
, objfile
->name
);
13604 /* If necessary, add it to the queue and load its DIEs. */
13606 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
13607 read_signatured_type (objfile
, sig_type
);
13609 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
13611 sig_cu
= sig_type
->per_cu
.cu
;
13612 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
13613 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
13620 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
13621 "from DIE at 0x%x [in module %s]"),
13622 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
13625 /* Given an offset of a signatured type, return its signatured_type. */
13627 static struct signatured_type
*
13628 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
13630 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
13631 unsigned int length
, initial_length_size
;
13632 unsigned int sig_offset
;
13633 struct signatured_type find_entry
, *type_sig
;
13635 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
13636 sig_offset
= (initial_length_size
13638 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
13639 + 1 /*address_size*/);
13640 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
13641 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
13643 /* This is only used to lookup previously recorded types.
13644 If we didn't find it, it's our bug. */
13645 gdb_assert (type_sig
!= NULL
);
13646 gdb_assert (offset
== type_sig
->offset
);
13651 /* Read in signatured type at OFFSET and build its CU and die(s). */
13654 read_signatured_type_at_offset (struct objfile
*objfile
,
13655 unsigned int offset
)
13657 struct signatured_type
*type_sig
;
13659 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13661 /* We have the section offset, but we need the signature to do the
13662 hash table lookup. */
13663 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
13665 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13667 read_signatured_type (objfile
, type_sig
);
13669 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
13672 /* Read in a signatured type and build its CU and DIEs. */
13675 read_signatured_type (struct objfile
*objfile
,
13676 struct signatured_type
*type_sig
)
13678 gdb_byte
*types_ptr
;
13679 struct die_reader_specs reader_specs
;
13680 struct dwarf2_cu
*cu
;
13681 ULONGEST signature
;
13682 struct cleanup
*back_to
, *free_cu_cleanup
;
13684 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13685 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
13687 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13689 cu
= xmalloc (sizeof (*cu
));
13690 init_one_comp_unit (cu
, objfile
);
13692 type_sig
->per_cu
.cu
= cu
;
13693 cu
->per_cu
= &type_sig
->per_cu
;
13695 /* If an error occurs while loading, release our storage. */
13696 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
13698 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
13699 types_ptr
, objfile
->obfd
);
13700 gdb_assert (signature
== type_sig
->signature
);
13703 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13707 &cu
->comp_unit_obstack
,
13708 hashtab_obstack_allocate
,
13709 dummy_obstack_deallocate
);
13711 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
13712 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
13714 init_cu_die_reader (&reader_specs
, cu
);
13716 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
13719 /* We try not to read any attributes in this function, because not
13720 all objfiles needed for references have been loaded yet, and symbol
13721 table processing isn't initialized. But we have to set the CU language,
13722 or we won't be able to build types correctly. */
13723 prepare_one_comp_unit (cu
, cu
->dies
);
13725 do_cleanups (back_to
);
13727 /* We've successfully allocated this compilation unit. Let our caller
13728 clean it up when finished with it. */
13729 discard_cleanups (free_cu_cleanup
);
13731 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
13732 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
13735 /* Decode simple location descriptions.
13736 Given a pointer to a dwarf block that defines a location, compute
13737 the location and return the value.
13739 NOTE drow/2003-11-18: This function is called in two situations
13740 now: for the address of static or global variables (partial symbols
13741 only) and for offsets into structures which are expected to be
13742 (more or less) constant. The partial symbol case should go away,
13743 and only the constant case should remain. That will let this
13744 function complain more accurately. A few special modes are allowed
13745 without complaint for global variables (for instance, global
13746 register values and thread-local values).
13748 A location description containing no operations indicates that the
13749 object is optimized out. The return value is 0 for that case.
13750 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13751 callers will only want a very basic result and this can become a
13754 Note that stack[0] is unused except as a default error return. */
13757 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
13759 struct objfile
*objfile
= cu
->objfile
;
13761 int size
= blk
->size
;
13762 gdb_byte
*data
= blk
->data
;
13763 CORE_ADDR stack
[64];
13765 unsigned int bytes_read
, unsnd
;
13771 stack
[++stacki
] = 0;
13810 stack
[++stacki
] = op
- DW_OP_lit0
;
13845 stack
[++stacki
] = op
- DW_OP_reg0
;
13847 dwarf2_complex_location_expr_complaint ();
13851 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13853 stack
[++stacki
] = unsnd
;
13855 dwarf2_complex_location_expr_complaint ();
13859 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
13864 case DW_OP_const1u
:
13865 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
13869 case DW_OP_const1s
:
13870 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
13874 case DW_OP_const2u
:
13875 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
13879 case DW_OP_const2s
:
13880 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
13884 case DW_OP_const4u
:
13885 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
13889 case DW_OP_const4s
:
13890 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
13895 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
13901 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
13906 stack
[stacki
+ 1] = stack
[stacki
];
13911 stack
[stacki
- 1] += stack
[stacki
];
13915 case DW_OP_plus_uconst
:
13916 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
13922 stack
[stacki
- 1] -= stack
[stacki
];
13927 /* If we're not the last op, then we definitely can't encode
13928 this using GDB's address_class enum. This is valid for partial
13929 global symbols, although the variable's address will be bogus
13932 dwarf2_complex_location_expr_complaint ();
13935 case DW_OP_GNU_push_tls_address
:
13936 /* The top of the stack has the offset from the beginning
13937 of the thread control block at which the variable is located. */
13938 /* Nothing should follow this operator, so the top of stack would
13940 /* This is valid for partial global symbols, but the variable's
13941 address will be bogus in the psymtab. */
13943 dwarf2_complex_location_expr_complaint ();
13946 case DW_OP_GNU_uninit
:
13951 const char *name
= dwarf_stack_op_name (op
);
13954 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
13957 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
13961 return (stack
[stacki
]);
13964 /* Enforce maximum stack depth of SIZE-1 to avoid writing
13965 outside of the allocated space. Also enforce minimum>0. */
13966 if (stacki
>= ARRAY_SIZE (stack
) - 1)
13968 complaint (&symfile_complaints
,
13969 _("location description stack overflow"));
13975 complaint (&symfile_complaints
,
13976 _("location description stack underflow"));
13980 return (stack
[stacki
]);
13983 /* memory allocation interface */
13985 static struct dwarf_block
*
13986 dwarf_alloc_block (struct dwarf2_cu
*cu
)
13988 struct dwarf_block
*blk
;
13990 blk
= (struct dwarf_block
*)
13991 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
13995 static struct abbrev_info
*
13996 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
13998 struct abbrev_info
*abbrev
;
14000 abbrev
= (struct abbrev_info
*)
14001 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14002 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14006 static struct die_info
*
14007 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14009 struct die_info
*die
;
14010 size_t size
= sizeof (struct die_info
);
14013 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14015 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14016 memset (die
, 0, sizeof (struct die_info
));
14021 /* Macro support. */
14023 /* Return the full name of file number I in *LH's file name table.
14024 Use COMP_DIR as the name of the current directory of the
14025 compilation. The result is allocated using xmalloc; the caller is
14026 responsible for freeing it. */
14028 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14030 /* Is the file number a valid index into the line header's file name
14031 table? Remember that file numbers start with one, not zero. */
14032 if (1 <= file
&& file
<= lh
->num_file_names
)
14034 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14036 if (IS_ABSOLUTE_PATH (fe
->name
))
14037 return xstrdup (fe
->name
);
14045 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14051 dir_len
= strlen (dir
);
14052 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14053 strcpy (full_name
, dir
);
14054 full_name
[dir_len
] = '/';
14055 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14059 return xstrdup (fe
->name
);
14064 /* The compiler produced a bogus file number. We can at least
14065 record the macro definitions made in the file, even if we
14066 won't be able to find the file by name. */
14067 char fake_name
[80];
14069 sprintf (fake_name
, "<bad macro file number %d>", file
);
14071 complaint (&symfile_complaints
,
14072 _("bad file number in macro information (%d)"),
14075 return xstrdup (fake_name
);
14080 static struct macro_source_file
*
14081 macro_start_file (int file
, int line
,
14082 struct macro_source_file
*current_file
,
14083 const char *comp_dir
,
14084 struct line_header
*lh
, struct objfile
*objfile
)
14086 /* The full name of this source file. */
14087 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14089 /* We don't create a macro table for this compilation unit
14090 at all until we actually get a filename. */
14091 if (! pending_macros
)
14092 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14093 objfile
->macro_cache
);
14095 if (! current_file
)
14096 /* If we have no current file, then this must be the start_file
14097 directive for the compilation unit's main source file. */
14098 current_file
= macro_set_main (pending_macros
, full_name
);
14100 current_file
= macro_include (current_file
, line
, full_name
);
14104 return current_file
;
14108 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14109 followed by a null byte. */
14111 copy_string (const char *buf
, int len
)
14113 char *s
= xmalloc (len
+ 1);
14115 memcpy (s
, buf
, len
);
14121 static const char *
14122 consume_improper_spaces (const char *p
, const char *body
)
14126 complaint (&symfile_complaints
,
14127 _("macro definition contains spaces "
14128 "in formal argument list:\n`%s'"),
14140 parse_macro_definition (struct macro_source_file
*file
, int line
,
14145 /* The body string takes one of two forms. For object-like macro
14146 definitions, it should be:
14148 <macro name> " " <definition>
14150 For function-like macro definitions, it should be:
14152 <macro name> "() " <definition>
14154 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14156 Spaces may appear only where explicitly indicated, and in the
14159 The Dwarf 2 spec says that an object-like macro's name is always
14160 followed by a space, but versions of GCC around March 2002 omit
14161 the space when the macro's definition is the empty string.
14163 The Dwarf 2 spec says that there should be no spaces between the
14164 formal arguments in a function-like macro's formal argument list,
14165 but versions of GCC around March 2002 include spaces after the
14169 /* Find the extent of the macro name. The macro name is terminated
14170 by either a space or null character (for an object-like macro) or
14171 an opening paren (for a function-like macro). */
14172 for (p
= body
; *p
; p
++)
14173 if (*p
== ' ' || *p
== '(')
14176 if (*p
== ' ' || *p
== '\0')
14178 /* It's an object-like macro. */
14179 int name_len
= p
- body
;
14180 char *name
= copy_string (body
, name_len
);
14181 const char *replacement
;
14184 replacement
= body
+ name_len
+ 1;
14187 dwarf2_macro_malformed_definition_complaint (body
);
14188 replacement
= body
+ name_len
;
14191 macro_define_object (file
, line
, name
, replacement
);
14195 else if (*p
== '(')
14197 /* It's a function-like macro. */
14198 char *name
= copy_string (body
, p
- body
);
14201 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14205 p
= consume_improper_spaces (p
, body
);
14207 /* Parse the formal argument list. */
14208 while (*p
&& *p
!= ')')
14210 /* Find the extent of the current argument name. */
14211 const char *arg_start
= p
;
14213 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14216 if (! *p
|| p
== arg_start
)
14217 dwarf2_macro_malformed_definition_complaint (body
);
14220 /* Make sure argv has room for the new argument. */
14221 if (argc
>= argv_size
)
14224 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14227 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14230 p
= consume_improper_spaces (p
, body
);
14232 /* Consume the comma, if present. */
14237 p
= consume_improper_spaces (p
, body
);
14246 /* Perfectly formed definition, no complaints. */
14247 macro_define_function (file
, line
, name
,
14248 argc
, (const char **) argv
,
14250 else if (*p
== '\0')
14252 /* Complain, but do define it. */
14253 dwarf2_macro_malformed_definition_complaint (body
);
14254 macro_define_function (file
, line
, name
,
14255 argc
, (const char **) argv
,
14259 /* Just complain. */
14260 dwarf2_macro_malformed_definition_complaint (body
);
14263 /* Just complain. */
14264 dwarf2_macro_malformed_definition_complaint (body
);
14270 for (i
= 0; i
< argc
; i
++)
14276 dwarf2_macro_malformed_definition_complaint (body
);
14281 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
14282 char *comp_dir
, bfd
*abfd
,
14283 struct dwarf2_cu
*cu
)
14285 gdb_byte
*mac_ptr
, *mac_end
;
14286 struct macro_source_file
*current_file
= 0;
14287 enum dwarf_macinfo_record_type macinfo_type
;
14288 int at_commandline
;
14290 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14291 &dwarf2_per_objfile
->macinfo
);
14292 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
14294 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
14298 /* First pass: Find the name of the base filename.
14299 This filename is needed in order to process all macros whose definition
14300 (or undefinition) comes from the command line. These macros are defined
14301 before the first DW_MACINFO_start_file entry, and yet still need to be
14302 associated to the base file.
14304 To determine the base file name, we scan the macro definitions until we
14305 reach the first DW_MACINFO_start_file entry. We then initialize
14306 CURRENT_FILE accordingly so that any macro definition found before the
14307 first DW_MACINFO_start_file can still be associated to the base file. */
14309 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14310 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
14311 + dwarf2_per_objfile
->macinfo
.size
;
14315 /* Do we at least have room for a macinfo type byte? */
14316 if (mac_ptr
>= mac_end
)
14318 /* Complaint is printed during the second pass as GDB will probably
14319 stop the first pass earlier upon finding
14320 DW_MACINFO_start_file. */
14324 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14327 switch (macinfo_type
)
14329 /* A zero macinfo type indicates the end of the macro
14334 case DW_MACINFO_define
:
14335 case DW_MACINFO_undef
:
14336 /* Only skip the data by MAC_PTR. */
14338 unsigned int bytes_read
;
14340 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14341 mac_ptr
+= bytes_read
;
14342 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14343 mac_ptr
+= bytes_read
;
14347 case DW_MACINFO_start_file
:
14349 unsigned int bytes_read
;
14352 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14353 mac_ptr
+= bytes_read
;
14354 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14355 mac_ptr
+= bytes_read
;
14357 current_file
= macro_start_file (file
, line
, current_file
,
14358 comp_dir
, lh
, cu
->objfile
);
14362 case DW_MACINFO_end_file
:
14363 /* No data to skip by MAC_PTR. */
14366 case DW_MACINFO_vendor_ext
:
14367 /* Only skip the data by MAC_PTR. */
14369 unsigned int bytes_read
;
14371 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14372 mac_ptr
+= bytes_read
;
14373 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14374 mac_ptr
+= bytes_read
;
14381 } while (macinfo_type
!= 0 && current_file
== NULL
);
14383 /* Second pass: Process all entries.
14385 Use the AT_COMMAND_LINE flag to determine whether we are still processing
14386 command-line macro definitions/undefinitions. This flag is unset when we
14387 reach the first DW_MACINFO_start_file entry. */
14389 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14391 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14392 GDB is still reading the definitions from command line. First
14393 DW_MACINFO_start_file will need to be ignored as it was already executed
14394 to create CURRENT_FILE for the main source holding also the command line
14395 definitions. On first met DW_MACINFO_start_file this flag is reset to
14396 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14398 at_commandline
= 1;
14402 /* Do we at least have room for a macinfo type byte? */
14403 if (mac_ptr
>= mac_end
)
14405 dwarf2_macros_too_long_complaint ();
14409 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14412 switch (macinfo_type
)
14414 /* A zero macinfo type indicates the end of the macro
14419 case DW_MACINFO_define
:
14420 case DW_MACINFO_undef
:
14422 unsigned int bytes_read
;
14426 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14427 mac_ptr
+= bytes_read
;
14428 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14429 mac_ptr
+= bytes_read
;
14431 if (! current_file
)
14433 /* DWARF violation as no main source is present. */
14434 complaint (&symfile_complaints
,
14435 _("debug info with no main source gives macro %s "
14437 macinfo_type
== DW_MACINFO_define
?
14439 macinfo_type
== DW_MACINFO_undef
?
14440 _("undefinition") :
14441 _("something-or-other"), line
, body
);
14444 if ((line
== 0 && !at_commandline
)
14445 || (line
!= 0 && at_commandline
))
14446 complaint (&symfile_complaints
,
14447 _("debug info gives %s macro %s with %s line %d: %s"),
14448 at_commandline
? _("command-line") : _("in-file"),
14449 macinfo_type
== DW_MACINFO_define
?
14451 macinfo_type
== DW_MACINFO_undef
?
14452 _("undefinition") :
14453 _("something-or-other"),
14454 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
14456 if (macinfo_type
== DW_MACINFO_define
)
14457 parse_macro_definition (current_file
, line
, body
);
14458 else if (macinfo_type
== DW_MACINFO_undef
)
14459 macro_undef (current_file
, line
, body
);
14463 case DW_MACINFO_start_file
:
14465 unsigned int bytes_read
;
14468 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14469 mac_ptr
+= bytes_read
;
14470 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14471 mac_ptr
+= bytes_read
;
14473 if ((line
== 0 && !at_commandline
)
14474 || (line
!= 0 && at_commandline
))
14475 complaint (&symfile_complaints
,
14476 _("debug info gives source %d included "
14477 "from %s at %s line %d"),
14478 file
, at_commandline
? _("command-line") : _("file"),
14479 line
== 0 ? _("zero") : _("non-zero"), line
);
14481 if (at_commandline
)
14483 /* This DW_MACINFO_start_file was executed in the pass one. */
14484 at_commandline
= 0;
14487 current_file
= macro_start_file (file
, line
,
14488 current_file
, comp_dir
,
14493 case DW_MACINFO_end_file
:
14494 if (! current_file
)
14495 complaint (&symfile_complaints
,
14496 _("macro debug info has an unmatched "
14497 "`close_file' directive"));
14500 current_file
= current_file
->included_by
;
14501 if (! current_file
)
14503 enum dwarf_macinfo_record_type next_type
;
14505 /* GCC circa March 2002 doesn't produce the zero
14506 type byte marking the end of the compilation
14507 unit. Complain if it's not there, but exit no
14510 /* Do we at least have room for a macinfo type byte? */
14511 if (mac_ptr
>= mac_end
)
14513 dwarf2_macros_too_long_complaint ();
14517 /* We don't increment mac_ptr here, so this is just
14519 next_type
= read_1_byte (abfd
, mac_ptr
);
14520 if (next_type
!= 0)
14521 complaint (&symfile_complaints
,
14522 _("no terminating 0-type entry for "
14523 "macros in `.debug_macinfo' section"));
14530 case DW_MACINFO_vendor_ext
:
14532 unsigned int bytes_read
;
14535 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14536 mac_ptr
+= bytes_read
;
14537 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14538 mac_ptr
+= bytes_read
;
14540 /* We don't recognize any vendor extensions. */
14544 } while (macinfo_type
!= 0);
14547 /* Check if the attribute's form is a DW_FORM_block*
14548 if so return true else false. */
14550 attr_form_is_block (struct attribute
*attr
)
14552 return (attr
== NULL
? 0 :
14553 attr
->form
== DW_FORM_block1
14554 || attr
->form
== DW_FORM_block2
14555 || attr
->form
== DW_FORM_block4
14556 || attr
->form
== DW_FORM_block
14557 || attr
->form
== DW_FORM_exprloc
);
14560 /* Return non-zero if ATTR's value is a section offset --- classes
14561 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14562 You may use DW_UNSND (attr) to retrieve such offsets.
14564 Section 7.5.4, "Attribute Encodings", explains that no attribute
14565 may have a value that belongs to more than one of these classes; it
14566 would be ambiguous if we did, because we use the same forms for all
14569 attr_form_is_section_offset (struct attribute
*attr
)
14571 return (attr
->form
== DW_FORM_data4
14572 || attr
->form
== DW_FORM_data8
14573 || attr
->form
== DW_FORM_sec_offset
);
14577 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14578 zero otherwise. When this function returns true, you can apply
14579 dwarf2_get_attr_constant_value to it.
14581 However, note that for some attributes you must check
14582 attr_form_is_section_offset before using this test. DW_FORM_data4
14583 and DW_FORM_data8 are members of both the constant class, and of
14584 the classes that contain offsets into other debug sections
14585 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14586 that, if an attribute's can be either a constant or one of the
14587 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14588 taken as section offsets, not constants. */
14590 attr_form_is_constant (struct attribute
*attr
)
14592 switch (attr
->form
)
14594 case DW_FORM_sdata
:
14595 case DW_FORM_udata
:
14596 case DW_FORM_data1
:
14597 case DW_FORM_data2
:
14598 case DW_FORM_data4
:
14599 case DW_FORM_data8
:
14606 /* A helper function that fills in a dwarf2_loclist_baton. */
14609 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
14610 struct dwarf2_loclist_baton
*baton
,
14611 struct attribute
*attr
)
14613 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14614 &dwarf2_per_objfile
->loc
);
14616 baton
->per_cu
= cu
->per_cu
;
14617 gdb_assert (baton
->per_cu
);
14618 /* We don't know how long the location list is, but make sure we
14619 don't run off the edge of the section. */
14620 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
14621 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
14622 baton
->base_address
= cu
->base_address
;
14626 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
14627 struct dwarf2_cu
*cu
)
14629 if (attr_form_is_section_offset (attr
)
14630 /* ".debug_loc" may not exist at all, or the offset may be outside
14631 the section. If so, fall through to the complaint in the
14633 && DW_UNSND (attr
) < dwarf2_section_size (dwarf2_per_objfile
->objfile
,
14634 &dwarf2_per_objfile
->loc
))
14636 struct dwarf2_loclist_baton
*baton
;
14638 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14639 sizeof (struct dwarf2_loclist_baton
));
14641 fill_in_loclist_baton (cu
, baton
, attr
);
14643 if (cu
->base_known
== 0)
14644 complaint (&symfile_complaints
,
14645 _("Location list used without "
14646 "specifying the CU base address."));
14648 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
14649 SYMBOL_LOCATION_BATON (sym
) = baton
;
14653 struct dwarf2_locexpr_baton
*baton
;
14655 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14656 sizeof (struct dwarf2_locexpr_baton
));
14657 baton
->per_cu
= cu
->per_cu
;
14658 gdb_assert (baton
->per_cu
);
14660 if (attr_form_is_block (attr
))
14662 /* Note that we're just copying the block's data pointer
14663 here, not the actual data. We're still pointing into the
14664 info_buffer for SYM's objfile; right now we never release
14665 that buffer, but when we do clean up properly this may
14667 baton
->size
= DW_BLOCK (attr
)->size
;
14668 baton
->data
= DW_BLOCK (attr
)->data
;
14672 dwarf2_invalid_attrib_class_complaint ("location description",
14673 SYMBOL_NATURAL_NAME (sym
));
14675 baton
->data
= NULL
;
14678 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14679 SYMBOL_LOCATION_BATON (sym
) = baton
;
14683 /* Return the OBJFILE associated with the compilation unit CU. If CU
14684 came from a separate debuginfo file, then the master objfile is
14688 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
14690 struct objfile
*objfile
= per_cu
->objfile
;
14692 /* Return the master objfile, so that we can report and look up the
14693 correct file containing this variable. */
14694 if (objfile
->separate_debug_objfile_backlink
)
14695 objfile
= objfile
->separate_debug_objfile_backlink
;
14700 /* Return the address size given in the compilation unit header for CU. */
14703 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
14706 return per_cu
->cu
->header
.addr_size
;
14709 /* If the CU is not currently read in, we re-read its header. */
14710 struct objfile
*objfile
= per_cu
->objfile
;
14711 struct dwarf2_per_objfile
*per_objfile
14712 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14713 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14714 struct comp_unit_head cu_header
;
14716 memset (&cu_header
, 0, sizeof cu_header
);
14717 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14718 return cu_header
.addr_size
;
14722 /* Return the offset size given in the compilation unit header for CU. */
14725 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
14728 return per_cu
->cu
->header
.offset_size
;
14731 /* If the CU is not currently read in, we re-read its header. */
14732 struct objfile
*objfile
= per_cu
->objfile
;
14733 struct dwarf2_per_objfile
*per_objfile
14734 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14735 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14736 struct comp_unit_head cu_header
;
14738 memset (&cu_header
, 0, sizeof cu_header
);
14739 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14740 return cu_header
.offset_size
;
14744 /* Return the text offset of the CU. The returned offset comes from
14745 this CU's objfile. If this objfile came from a separate debuginfo
14746 file, then the offset may be different from the corresponding
14747 offset in the parent objfile. */
14750 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
14752 struct objfile
*objfile
= per_cu
->objfile
;
14754 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14757 /* Locate the .debug_info compilation unit from CU's objfile which contains
14758 the DIE at OFFSET. Raises an error on failure. */
14760 static struct dwarf2_per_cu_data
*
14761 dwarf2_find_containing_comp_unit (unsigned int offset
,
14762 struct objfile
*objfile
)
14764 struct dwarf2_per_cu_data
*this_cu
;
14768 high
= dwarf2_per_objfile
->n_comp_units
- 1;
14771 int mid
= low
+ (high
- low
) / 2;
14773 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
14778 gdb_assert (low
== high
);
14779 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
14782 error (_("Dwarf Error: could not find partial DIE containing "
14783 "offset 0x%lx [in module %s]"),
14784 (long) offset
, bfd_get_filename (objfile
->obfd
));
14786 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
14787 return dwarf2_per_objfile
->all_comp_units
[low
-1];
14791 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
14792 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
14793 && offset
>= this_cu
->offset
+ this_cu
->length
)
14794 error (_("invalid dwarf2 offset %u"), offset
);
14795 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
14800 /* Locate the compilation unit from OBJFILE which is located at exactly
14801 OFFSET. Raises an error on failure. */
14803 static struct dwarf2_per_cu_data
*
14804 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
14806 struct dwarf2_per_cu_data
*this_cu
;
14808 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
14809 if (this_cu
->offset
!= offset
)
14810 error (_("no compilation unit with offset %u."), offset
);
14814 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
14817 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
14819 memset (cu
, 0, sizeof (*cu
));
14820 cu
->objfile
= objfile
;
14821 obstack_init (&cu
->comp_unit_obstack
);
14824 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
14827 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
14829 struct attribute
*attr
;
14831 /* Set the language we're debugging. */
14832 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
14834 set_cu_language (DW_UNSND (attr
), cu
);
14837 cu
->language
= language_minimal
;
14838 cu
->language_defn
= language_def (cu
->language
);
14842 /* Release one cached compilation unit, CU. We unlink it from the tree
14843 of compilation units, but we don't remove it from the read_in_chain;
14844 the caller is responsible for that.
14845 NOTE: DATA is a void * because this function is also used as a
14846 cleanup routine. */
14849 free_one_comp_unit (void *data
)
14851 struct dwarf2_cu
*cu
= data
;
14853 if (cu
->per_cu
!= NULL
)
14854 cu
->per_cu
->cu
= NULL
;
14857 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14862 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14863 when we're finished with it. We can't free the pointer itself, but be
14864 sure to unlink it from the cache. Also release any associated storage
14865 and perform cache maintenance.
14867 Only used during partial symbol parsing. */
14870 free_stack_comp_unit (void *data
)
14872 struct dwarf2_cu
*cu
= data
;
14874 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14875 cu
->partial_dies
= NULL
;
14877 if (cu
->per_cu
!= NULL
)
14879 /* This compilation unit is on the stack in our caller, so we
14880 should not xfree it. Just unlink it. */
14881 cu
->per_cu
->cu
= NULL
;
14884 /* If we had a per-cu pointer, then we may have other compilation
14885 units loaded, so age them now. */
14886 age_cached_comp_units ();
14890 /* Free all cached compilation units. */
14893 free_cached_comp_units (void *data
)
14895 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14897 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14898 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14899 while (per_cu
!= NULL
)
14901 struct dwarf2_per_cu_data
*next_cu
;
14903 next_cu
= per_cu
->cu
->read_in_chain
;
14905 free_one_comp_unit (per_cu
->cu
);
14906 *last_chain
= next_cu
;
14912 /* Increase the age counter on each cached compilation unit, and free
14913 any that are too old. */
14916 age_cached_comp_units (void)
14918 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14920 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
14921 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14922 while (per_cu
!= NULL
)
14924 per_cu
->cu
->last_used
++;
14925 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
14926 dwarf2_mark (per_cu
->cu
);
14927 per_cu
= per_cu
->cu
->read_in_chain
;
14930 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14931 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14932 while (per_cu
!= NULL
)
14934 struct dwarf2_per_cu_data
*next_cu
;
14936 next_cu
= per_cu
->cu
->read_in_chain
;
14938 if (!per_cu
->cu
->mark
)
14940 free_one_comp_unit (per_cu
->cu
);
14941 *last_chain
= next_cu
;
14944 last_chain
= &per_cu
->cu
->read_in_chain
;
14950 /* Remove a single compilation unit from the cache. */
14953 free_one_cached_comp_unit (void *target_cu
)
14955 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14957 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14958 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14959 while (per_cu
!= NULL
)
14961 struct dwarf2_per_cu_data
*next_cu
;
14963 next_cu
= per_cu
->cu
->read_in_chain
;
14965 if (per_cu
->cu
== target_cu
)
14967 free_one_comp_unit (per_cu
->cu
);
14968 *last_chain
= next_cu
;
14972 last_chain
= &per_cu
->cu
->read_in_chain
;
14978 /* Release all extra memory associated with OBJFILE. */
14981 dwarf2_free_objfile (struct objfile
*objfile
)
14983 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14985 if (dwarf2_per_objfile
== NULL
)
14988 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
14989 free_cached_comp_units (NULL
);
14991 if (dwarf2_per_objfile
->quick_file_names_table
)
14992 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
14994 /* Everything else should be on the objfile obstack. */
14997 /* A pair of DIE offset and GDB type pointer. We store these
14998 in a hash table separate from the DIEs, and preserve them
14999 when the DIEs are flushed out of cache. */
15001 struct dwarf2_offset_and_type
15003 unsigned int offset
;
15007 /* Hash function for a dwarf2_offset_and_type. */
15010 offset_and_type_hash (const void *item
)
15012 const struct dwarf2_offset_and_type
*ofs
= item
;
15014 return ofs
->offset
;
15017 /* Equality function for a dwarf2_offset_and_type. */
15020 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
15022 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
15023 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
15025 return ofs_lhs
->offset
== ofs_rhs
->offset
;
15028 /* Set the type associated with DIE to TYPE. Save it in CU's hash
15029 table if necessary. For convenience, return TYPE.
15031 The DIEs reading must have careful ordering to:
15032 * Not cause infite loops trying to read in DIEs as a prerequisite for
15033 reading current DIE.
15034 * Not trying to dereference contents of still incompletely read in types
15035 while reading in other DIEs.
15036 * Enable referencing still incompletely read in types just by a pointer to
15037 the type without accessing its fields.
15039 Therefore caller should follow these rules:
15040 * Try to fetch any prerequisite types we may need to build this DIE type
15041 before building the type and calling set_die_type.
15042 * After building type call set_die_type for current DIE as soon as
15043 possible before fetching more types to complete the current type.
15044 * Make the type as complete as possible before fetching more types. */
15046 static struct type
*
15047 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
15049 struct dwarf2_offset_and_type
**slot
, ofs
;
15050 struct objfile
*objfile
= cu
->objfile
;
15051 htab_t
*type_hash_ptr
;
15053 /* For Ada types, make sure that the gnat-specific data is always
15054 initialized (if not already set). There are a few types where
15055 we should not be doing so, because the type-specific area is
15056 already used to hold some other piece of info (eg: TYPE_CODE_FLT
15057 where the type-specific area is used to store the floatformat).
15058 But this is not a problem, because the gnat-specific information
15059 is actually not needed for these types. */
15060 if (need_gnat_info (cu
)
15061 && TYPE_CODE (type
) != TYPE_CODE_FUNC
15062 && TYPE_CODE (type
) != TYPE_CODE_FLT
15063 && !HAVE_GNAT_AUX_INFO (type
))
15064 INIT_GNAT_SPECIFIC (type
);
15066 if (cu
->per_cu
->from_debug_types
)
15067 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
15069 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
15071 if (*type_hash_ptr
== NULL
)
15074 = htab_create_alloc_ex (127,
15075 offset_and_type_hash
,
15076 offset_and_type_eq
,
15078 &objfile
->objfile_obstack
,
15079 hashtab_obstack_allocate
,
15080 dummy_obstack_deallocate
);
15083 ofs
.offset
= die
->offset
;
15085 slot
= (struct dwarf2_offset_and_type
**)
15086 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
15088 complaint (&symfile_complaints
,
15089 _("A problem internal to GDB: DIE 0x%x has type already set"),
15091 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
15096 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
15097 table, or return NULL if the die does not have a saved type. */
15099 static struct type
*
15100 get_die_type_at_offset (unsigned int offset
,
15101 struct dwarf2_per_cu_data
*per_cu
)
15103 struct dwarf2_offset_and_type
*slot
, ofs
;
15106 if (per_cu
->from_debug_types
)
15107 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
15109 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
15110 if (type_hash
== NULL
)
15113 ofs
.offset
= offset
;
15114 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
15121 /* Look up the type for DIE in the appropriate type_hash table,
15122 or return NULL if DIE does not have a saved type. */
15124 static struct type
*
15125 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15127 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
15130 /* Add a dependence relationship from CU to REF_PER_CU. */
15133 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
15134 struct dwarf2_per_cu_data
*ref_per_cu
)
15138 if (cu
->dependencies
== NULL
)
15140 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
15141 NULL
, &cu
->comp_unit_obstack
,
15142 hashtab_obstack_allocate
,
15143 dummy_obstack_deallocate
);
15145 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
15147 *slot
= ref_per_cu
;
15150 /* Subroutine of dwarf2_mark to pass to htab_traverse.
15151 Set the mark field in every compilation unit in the
15152 cache that we must keep because we are keeping CU. */
15155 dwarf2_mark_helper (void **slot
, void *data
)
15157 struct dwarf2_per_cu_data
*per_cu
;
15159 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
15160 if (per_cu
->cu
->mark
)
15162 per_cu
->cu
->mark
= 1;
15164 if (per_cu
->cu
->dependencies
!= NULL
)
15165 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15170 /* Set the mark field in CU and in every other compilation unit in the
15171 cache that we must keep because we are keeping CU. */
15174 dwarf2_mark (struct dwarf2_cu
*cu
)
15179 if (cu
->dependencies
!= NULL
)
15180 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15184 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
15188 per_cu
->cu
->mark
= 0;
15189 per_cu
= per_cu
->cu
->read_in_chain
;
15193 /* Trivial hash function for partial_die_info: the hash value of a DIE
15194 is its offset in .debug_info for this objfile. */
15197 partial_die_hash (const void *item
)
15199 const struct partial_die_info
*part_die
= item
;
15201 return part_die
->offset
;
15204 /* Trivial comparison function for partial_die_info structures: two DIEs
15205 are equal if they have the same offset. */
15208 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
15210 const struct partial_die_info
*part_die_lhs
= item_lhs
;
15211 const struct partial_die_info
*part_die_rhs
= item_rhs
;
15213 return part_die_lhs
->offset
== part_die_rhs
->offset
;
15216 static struct cmd_list_element
*set_dwarf2_cmdlist
;
15217 static struct cmd_list_element
*show_dwarf2_cmdlist
;
15220 set_dwarf2_cmd (char *args
, int from_tty
)
15222 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
15226 show_dwarf2_cmd (char *args
, int from_tty
)
15228 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
15231 /* If section described by INFO was mmapped, munmap it now. */
15234 munmap_section_buffer (struct dwarf2_section_info
*info
)
15236 if (info
->was_mmapped
)
15239 intptr_t begin
= (intptr_t) info
->buffer
;
15240 intptr_t map_begin
= begin
& ~(pagesize
- 1);
15241 size_t map_length
= info
->size
+ begin
- map_begin
;
15243 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
15245 /* Without HAVE_MMAP, we should never be here to begin with. */
15246 gdb_assert_not_reached ("no mmap support");
15251 /* munmap debug sections for OBJFILE, if necessary. */
15254 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
15256 struct dwarf2_per_objfile
*data
= d
;
15258 /* This is sorted according to the order they're defined in to make it easier
15259 to keep in sync. */
15260 munmap_section_buffer (&data
->info
);
15261 munmap_section_buffer (&data
->abbrev
);
15262 munmap_section_buffer (&data
->line
);
15263 munmap_section_buffer (&data
->loc
);
15264 munmap_section_buffer (&data
->macinfo
);
15265 munmap_section_buffer (&data
->str
);
15266 munmap_section_buffer (&data
->ranges
);
15267 munmap_section_buffer (&data
->types
);
15268 munmap_section_buffer (&data
->frame
);
15269 munmap_section_buffer (&data
->eh_frame
);
15270 munmap_section_buffer (&data
->gdb_index
);
15274 /* The "save gdb-index" command. */
15276 /* The contents of the hash table we create when building the string
15278 struct strtab_entry
15280 offset_type offset
;
15284 /* Hash function for a strtab_entry. */
15287 hash_strtab_entry (const void *e
)
15289 const struct strtab_entry
*entry
= e
;
15290 return mapped_index_string_hash (entry
->str
);
15293 /* Equality function for a strtab_entry. */
15296 eq_strtab_entry (const void *a
, const void *b
)
15298 const struct strtab_entry
*ea
= a
;
15299 const struct strtab_entry
*eb
= b
;
15300 return !strcmp (ea
->str
, eb
->str
);
15303 /* Create a strtab_entry hash table. */
15306 create_strtab (void)
15308 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
15309 xfree
, xcalloc
, xfree
);
15312 /* Add a string to the constant pool. Return the string's offset in
15316 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
15319 struct strtab_entry entry
;
15320 struct strtab_entry
*result
;
15323 slot
= htab_find_slot (table
, &entry
, INSERT
);
15328 result
= XNEW (struct strtab_entry
);
15329 result
->offset
= obstack_object_size (cpool
);
15331 obstack_grow_str0 (cpool
, str
);
15334 return result
->offset
;
15337 /* An entry in the symbol table. */
15338 struct symtab_index_entry
15340 /* The name of the symbol. */
15342 /* The offset of the name in the constant pool. */
15343 offset_type index_offset
;
15344 /* A sorted vector of the indices of all the CUs that hold an object
15346 VEC (offset_type
) *cu_indices
;
15349 /* The symbol table. This is a power-of-2-sized hash table. */
15350 struct mapped_symtab
15352 offset_type n_elements
;
15354 struct symtab_index_entry
**data
;
15357 /* Hash function for a symtab_index_entry. */
15360 hash_symtab_entry (const void *e
)
15362 const struct symtab_index_entry
*entry
= e
;
15363 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
15364 sizeof (offset_type
) * VEC_length (offset_type
,
15365 entry
->cu_indices
),
15369 /* Equality function for a symtab_index_entry. */
15372 eq_symtab_entry (const void *a
, const void *b
)
15374 const struct symtab_index_entry
*ea
= a
;
15375 const struct symtab_index_entry
*eb
= b
;
15376 int len
= VEC_length (offset_type
, ea
->cu_indices
);
15377 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
15379 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
15380 VEC_address (offset_type
, eb
->cu_indices
),
15381 sizeof (offset_type
) * len
);
15384 /* Destroy a symtab_index_entry. */
15387 delete_symtab_entry (void *p
)
15389 struct symtab_index_entry
*entry
= p
;
15390 VEC_free (offset_type
, entry
->cu_indices
);
15394 /* Create a hash table holding symtab_index_entry objects. */
15397 create_symbol_hash_table (void)
15399 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
15400 delete_symtab_entry
, xcalloc
, xfree
);
15403 /* Create a new mapped symtab object. */
15405 static struct mapped_symtab
*
15406 create_mapped_symtab (void)
15408 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
15409 symtab
->n_elements
= 0;
15410 symtab
->size
= 1024;
15411 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15415 /* Destroy a mapped_symtab. */
15418 cleanup_mapped_symtab (void *p
)
15420 struct mapped_symtab
*symtab
= p
;
15421 /* The contents of the array are freed when the other hash table is
15423 xfree (symtab
->data
);
15427 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
15430 static struct symtab_index_entry
**
15431 find_slot (struct mapped_symtab
*symtab
, const char *name
)
15433 offset_type index
, step
, hash
= mapped_index_string_hash (name
);
15435 index
= hash
& (symtab
->size
- 1);
15436 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
15440 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
15441 return &symtab
->data
[index
];
15442 index
= (index
+ step
) & (symtab
->size
- 1);
15446 /* Expand SYMTAB's hash table. */
15449 hash_expand (struct mapped_symtab
*symtab
)
15451 offset_type old_size
= symtab
->size
;
15453 struct symtab_index_entry
**old_entries
= symtab
->data
;
15456 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15458 for (i
= 0; i
< old_size
; ++i
)
15460 if (old_entries
[i
])
15462 struct symtab_index_entry
**slot
= find_slot (symtab
,
15463 old_entries
[i
]->name
);
15464 *slot
= old_entries
[i
];
15468 xfree (old_entries
);
15471 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
15472 is the index of the CU in which the symbol appears. */
15475 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
15476 offset_type cu_index
)
15478 struct symtab_index_entry
**slot
;
15480 ++symtab
->n_elements
;
15481 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
15482 hash_expand (symtab
);
15484 slot
= find_slot (symtab
, name
);
15487 *slot
= XNEW (struct symtab_index_entry
);
15488 (*slot
)->name
= name
;
15489 (*slot
)->cu_indices
= NULL
;
15491 /* Don't push an index twice. Due to how we add entries we only
15492 have to check the last one. */
15493 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
15494 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
15495 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
15498 /* Add a vector of indices to the constant pool. */
15501 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
15502 struct symtab_index_entry
*entry
)
15506 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
15509 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
15510 offset_type val
= MAYBE_SWAP (len
);
15515 entry
->index_offset
= obstack_object_size (cpool
);
15517 obstack_grow (cpool
, &val
, sizeof (val
));
15519 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
15522 val
= MAYBE_SWAP (iter
);
15523 obstack_grow (cpool
, &val
, sizeof (val
));
15528 struct symtab_index_entry
*old_entry
= *slot
;
15529 entry
->index_offset
= old_entry
->index_offset
;
15532 return entry
->index_offset
;
15535 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15536 constant pool entries going into the obstack CPOOL. */
15539 write_hash_table (struct mapped_symtab
*symtab
,
15540 struct obstack
*output
, struct obstack
*cpool
)
15543 htab_t symbol_hash_table
;
15546 symbol_hash_table
= create_symbol_hash_table ();
15547 str_table
= create_strtab ();
15549 /* We add all the index vectors to the constant pool first, to
15550 ensure alignment is ok. */
15551 for (i
= 0; i
< symtab
->size
; ++i
)
15553 if (symtab
->data
[i
])
15554 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
15557 /* Now write out the hash table. */
15558 for (i
= 0; i
< symtab
->size
; ++i
)
15560 offset_type str_off
, vec_off
;
15562 if (symtab
->data
[i
])
15564 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
15565 vec_off
= symtab
->data
[i
]->index_offset
;
15569 /* While 0 is a valid constant pool index, it is not valid
15570 to have 0 for both offsets. */
15575 str_off
= MAYBE_SWAP (str_off
);
15576 vec_off
= MAYBE_SWAP (vec_off
);
15578 obstack_grow (output
, &str_off
, sizeof (str_off
));
15579 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
15582 htab_delete (str_table
);
15583 htab_delete (symbol_hash_table
);
15586 /* Struct to map psymtab to CU index in the index file. */
15587 struct psymtab_cu_index_map
15589 struct partial_symtab
*psymtab
;
15590 unsigned int cu_index
;
15594 hash_psymtab_cu_index (const void *item
)
15596 const struct psymtab_cu_index_map
*map
= item
;
15598 return htab_hash_pointer (map
->psymtab
);
15602 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
15604 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
15605 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
15607 return lhs
->psymtab
== rhs
->psymtab
;
15610 /* Helper struct for building the address table. */
15611 struct addrmap_index_data
15613 struct objfile
*objfile
;
15614 struct obstack
*addr_obstack
;
15615 htab_t cu_index_htab
;
15617 /* Non-zero if the previous_* fields are valid.
15618 We can't write an entry until we see the next entry (since it is only then
15619 that we know the end of the entry). */
15620 int previous_valid
;
15621 /* Index of the CU in the table of all CUs in the index file. */
15622 unsigned int previous_cu_index
;
15623 /* Start address of the CU. */
15624 CORE_ADDR previous_cu_start
;
15627 /* Write an address entry to OBSTACK. */
15630 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
15631 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
15633 offset_type cu_index_to_write
;
15635 CORE_ADDR baseaddr
;
15637 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15639 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
15640 obstack_grow (obstack
, addr
, 8);
15641 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
15642 obstack_grow (obstack
, addr
, 8);
15643 cu_index_to_write
= MAYBE_SWAP (cu_index
);
15644 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
15647 /* Worker function for traversing an addrmap to build the address table. */
15650 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
15652 struct addrmap_index_data
*data
= datap
;
15653 struct partial_symtab
*pst
= obj
;
15654 offset_type cu_index
;
15657 if (data
->previous_valid
)
15658 add_address_entry (data
->objfile
, data
->addr_obstack
,
15659 data
->previous_cu_start
, start_addr
,
15660 data
->previous_cu_index
);
15662 data
->previous_cu_start
= start_addr
;
15665 struct psymtab_cu_index_map find_map
, *map
;
15666 find_map
.psymtab
= pst
;
15667 map
= htab_find (data
->cu_index_htab
, &find_map
);
15668 gdb_assert (map
!= NULL
);
15669 data
->previous_cu_index
= map
->cu_index
;
15670 data
->previous_valid
= 1;
15673 data
->previous_valid
= 0;
15678 /* Write OBJFILE's address map to OBSTACK.
15679 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
15680 in the index file. */
15683 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
15684 htab_t cu_index_htab
)
15686 struct addrmap_index_data addrmap_index_data
;
15688 /* When writing the address table, we have to cope with the fact that
15689 the addrmap iterator only provides the start of a region; we have to
15690 wait until the next invocation to get the start of the next region. */
15692 addrmap_index_data
.objfile
= objfile
;
15693 addrmap_index_data
.addr_obstack
= obstack
;
15694 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
15695 addrmap_index_data
.previous_valid
= 0;
15697 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
15698 &addrmap_index_data
);
15700 /* It's highly unlikely the last entry (end address = 0xff...ff)
15701 is valid, but we should still handle it.
15702 The end address is recorded as the start of the next region, but that
15703 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
15705 if (addrmap_index_data
.previous_valid
)
15706 add_address_entry (objfile
, obstack
,
15707 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
15708 addrmap_index_data
.previous_cu_index
);
15711 /* Add a list of partial symbols to SYMTAB. */
15714 write_psymbols (struct mapped_symtab
*symtab
,
15716 struct partial_symbol
**psymp
,
15718 offset_type cu_index
,
15721 for (; count
-- > 0; ++psymp
)
15723 void **slot
, *lookup
;
15725 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
15726 error (_("Ada is not currently supported by the index"));
15728 /* We only want to add a given psymbol once. However, we also
15729 want to account for whether it is global or static. So, we
15730 may add it twice, using slightly different values. */
15733 uintptr_t val
= 1 | (uintptr_t) *psymp
;
15735 lookup
= (void *) val
;
15740 /* Only add a given psymbol once. */
15741 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
15745 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
15750 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
15751 exception if there is an error. */
15754 write_obstack (FILE *file
, struct obstack
*obstack
)
15756 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
15758 != obstack_object_size (obstack
))
15759 error (_("couldn't data write to file"));
15762 /* Unlink a file if the argument is not NULL. */
15765 unlink_if_set (void *p
)
15767 char **filename
= p
;
15769 unlink (*filename
);
15772 /* A helper struct used when iterating over debug_types. */
15773 struct signatured_type_index_data
15775 struct objfile
*objfile
;
15776 struct mapped_symtab
*symtab
;
15777 struct obstack
*types_list
;
15782 /* A helper function that writes a single signatured_type to an
15786 write_one_signatured_type (void **slot
, void *d
)
15788 struct signatured_type_index_data
*info
= d
;
15789 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
15790 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
15791 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15794 write_psymbols (info
->symtab
,
15796 info
->objfile
->global_psymbols
.list
15797 + psymtab
->globals_offset
,
15798 psymtab
->n_global_syms
, info
->cu_index
,
15800 write_psymbols (info
->symtab
,
15802 info
->objfile
->static_psymbols
.list
15803 + psymtab
->statics_offset
,
15804 psymtab
->n_static_syms
, info
->cu_index
,
15807 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->offset
);
15808 obstack_grow (info
->types_list
, val
, 8);
15809 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
15810 obstack_grow (info
->types_list
, val
, 8);
15811 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
15812 obstack_grow (info
->types_list
, val
, 8);
15819 /* A cleanup function for an htab_t. */
15822 cleanup_htab (void *arg
)
15827 /* Create an index file for OBJFILE in the directory DIR. */
15830 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
15832 struct cleanup
*cleanup
;
15833 char *filename
, *cleanup_filename
;
15834 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
15835 struct obstack cu_list
, types_cu_list
;
15838 struct mapped_symtab
*symtab
;
15839 offset_type val
, size_of_contents
, total_len
;
15843 htab_t cu_index_htab
;
15844 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
15846 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
15849 if (dwarf2_per_objfile
->using_index
)
15850 error (_("Cannot use an index to create the index"));
15852 if (stat (objfile
->name
, &st
) < 0)
15853 perror_with_name (objfile
->name
);
15855 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
15856 INDEX_SUFFIX
, (char *) NULL
);
15857 cleanup
= make_cleanup (xfree
, filename
);
15859 out_file
= fopen (filename
, "wb");
15861 error (_("Can't open `%s' for writing"), filename
);
15863 cleanup_filename
= filename
;
15864 make_cleanup (unlink_if_set
, &cleanup_filename
);
15866 symtab
= create_mapped_symtab ();
15867 make_cleanup (cleanup_mapped_symtab
, symtab
);
15869 obstack_init (&addr_obstack
);
15870 make_cleanup_obstack_free (&addr_obstack
);
15872 obstack_init (&cu_list
);
15873 make_cleanup_obstack_free (&cu_list
);
15875 obstack_init (&types_cu_list
);
15876 make_cleanup_obstack_free (&types_cu_list
);
15878 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
15879 NULL
, xcalloc
, xfree
);
15880 make_cleanup (cleanup_htab
, psyms_seen
);
15882 /* While we're scanning CU's create a table that maps a psymtab pointer
15883 (which is what addrmap records) to its index (which is what is recorded
15884 in the index file). This will later be needed to write the address
15886 cu_index_htab
= htab_create_alloc (100,
15887 hash_psymtab_cu_index
,
15888 eq_psymtab_cu_index
,
15889 NULL
, xcalloc
, xfree
);
15890 make_cleanup (cleanup_htab
, cu_index_htab
);
15891 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
15892 xmalloc (sizeof (struct psymtab_cu_index_map
)
15893 * dwarf2_per_objfile
->n_comp_units
);
15894 make_cleanup (xfree
, psymtab_cu_index_map
);
15896 /* The CU list is already sorted, so we don't need to do additional
15897 work here. Also, the debug_types entries do not appear in
15898 all_comp_units, but only in their own hash table. */
15899 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
15901 struct dwarf2_per_cu_data
*per_cu
15902 = dwarf2_per_objfile
->all_comp_units
[i
];
15903 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15905 struct psymtab_cu_index_map
*map
;
15908 write_psymbols (symtab
,
15910 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15911 psymtab
->n_global_syms
, i
,
15913 write_psymbols (symtab
,
15915 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15916 psymtab
->n_static_syms
, i
,
15919 map
= &psymtab_cu_index_map
[i
];
15920 map
->psymtab
= psymtab
;
15922 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
15923 gdb_assert (slot
!= NULL
);
15924 gdb_assert (*slot
== NULL
);
15927 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
15928 obstack_grow (&cu_list
, val
, 8);
15929 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
15930 obstack_grow (&cu_list
, val
, 8);
15933 /* Dump the address map. */
15934 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
15936 /* Write out the .debug_type entries, if any. */
15937 if (dwarf2_per_objfile
->signatured_types
)
15939 struct signatured_type_index_data sig_data
;
15941 sig_data
.objfile
= objfile
;
15942 sig_data
.symtab
= symtab
;
15943 sig_data
.types_list
= &types_cu_list
;
15944 sig_data
.psyms_seen
= psyms_seen
;
15945 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
15946 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
15947 write_one_signatured_type
, &sig_data
);
15950 obstack_init (&constant_pool
);
15951 make_cleanup_obstack_free (&constant_pool
);
15952 obstack_init (&symtab_obstack
);
15953 make_cleanup_obstack_free (&symtab_obstack
);
15954 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
15956 obstack_init (&contents
);
15957 make_cleanup_obstack_free (&contents
);
15958 size_of_contents
= 6 * sizeof (offset_type
);
15959 total_len
= size_of_contents
;
15961 /* The version number. */
15962 val
= MAYBE_SWAP (4);
15963 obstack_grow (&contents
, &val
, sizeof (val
));
15965 /* The offset of the CU list from the start of the file. */
15966 val
= MAYBE_SWAP (total_len
);
15967 obstack_grow (&contents
, &val
, sizeof (val
));
15968 total_len
+= obstack_object_size (&cu_list
);
15970 /* The offset of the types CU list from the start of the file. */
15971 val
= MAYBE_SWAP (total_len
);
15972 obstack_grow (&contents
, &val
, sizeof (val
));
15973 total_len
+= obstack_object_size (&types_cu_list
);
15975 /* The offset of the address table from the start of the file. */
15976 val
= MAYBE_SWAP (total_len
);
15977 obstack_grow (&contents
, &val
, sizeof (val
));
15978 total_len
+= obstack_object_size (&addr_obstack
);
15980 /* The offset of the symbol table from the start of the file. */
15981 val
= MAYBE_SWAP (total_len
);
15982 obstack_grow (&contents
, &val
, sizeof (val
));
15983 total_len
+= obstack_object_size (&symtab_obstack
);
15985 /* The offset of the constant pool from the start of the file. */
15986 val
= MAYBE_SWAP (total_len
);
15987 obstack_grow (&contents
, &val
, sizeof (val
));
15988 total_len
+= obstack_object_size (&constant_pool
);
15990 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
15992 write_obstack (out_file
, &contents
);
15993 write_obstack (out_file
, &cu_list
);
15994 write_obstack (out_file
, &types_cu_list
);
15995 write_obstack (out_file
, &addr_obstack
);
15996 write_obstack (out_file
, &symtab_obstack
);
15997 write_obstack (out_file
, &constant_pool
);
16001 /* We want to keep the file, so we set cleanup_filename to NULL
16002 here. See unlink_if_set. */
16003 cleanup_filename
= NULL
;
16005 do_cleanups (cleanup
);
16008 /* The mapped index file format is designed to be directly mmap()able
16009 on any architecture. In most cases, a datum is represented using a
16010 little-endian 32-bit integer value, called an offset_type. Big
16011 endian machines must byte-swap the values before using them.
16012 Exceptions to this rule are noted. The data is laid out such that
16013 alignment is always respected.
16015 A mapped index consists of several sections.
16017 1. The file header. This is a sequence of values, of offset_type
16018 unless otherwise noted:
16020 [0] The version number, currently 4. Versions 1, 2 and 3 are
16022 [1] The offset, from the start of the file, of the CU list.
16023 [2] The offset, from the start of the file, of the types CU list.
16024 Note that this section can be empty, in which case this offset will
16025 be equal to the next offset.
16026 [3] The offset, from the start of the file, of the address section.
16027 [4] The offset, from the start of the file, of the symbol table.
16028 [5] The offset, from the start of the file, of the constant pool.
16030 2. The CU list. This is a sequence of pairs of 64-bit
16031 little-endian values, sorted by the CU offset. The first element
16032 in each pair is the offset of a CU in the .debug_info section. The
16033 second element in each pair is the length of that CU. References
16034 to a CU elsewhere in the map are done using a CU index, which is
16035 just the 0-based index into this table. Note that if there are
16036 type CUs, then conceptually CUs and type CUs form a single list for
16037 the purposes of CU indices.
16039 3. The types CU list. This is a sequence of triplets of 64-bit
16040 little-endian values. In a triplet, the first value is the CU
16041 offset, the second value is the type offset in the CU, and the
16042 third value is the type signature. The types CU list is not
16045 4. The address section. The address section consists of a sequence
16046 of address entries. Each address entry has three elements.
16047 [0] The low address. This is a 64-bit little-endian value.
16048 [1] The high address. This is a 64-bit little-endian value.
16049 Like DW_AT_high_pc, the value is one byte beyond the end.
16050 [2] The CU index. This is an offset_type value.
16052 5. The symbol table. This is a hash table. The size of the hash
16053 table is always a power of 2. The initial hash and the step are
16054 currently defined by the `find_slot' function.
16056 Each slot in the hash table consists of a pair of offset_type
16057 values. The first value is the offset of the symbol's name in the
16058 constant pool. The second value is the offset of the CU vector in
16061 If both values are 0, then this slot in the hash table is empty.
16062 This is ok because while 0 is a valid constant pool index, it
16063 cannot be a valid index for both a string and a CU vector.
16065 A string in the constant pool is stored as a \0-terminated string,
16068 A CU vector in the constant pool is a sequence of offset_type
16069 values. The first value is the number of CU indices in the vector.
16070 Each subsequent value is the index of a CU in the CU list. This
16071 element in the hash table is used to indicate which CUs define the
16074 6. The constant pool. This is simply a bunch of bytes. It is
16075 organized so that alignment is correct: CU vectors are stored
16076 first, followed by strings. */
16079 save_gdb_index_command (char *arg
, int from_tty
)
16081 struct objfile
*objfile
;
16084 error (_("usage: save gdb-index DIRECTORY"));
16086 ALL_OBJFILES (objfile
)
16090 /* If the objfile does not correspond to an actual file, skip it. */
16091 if (stat (objfile
->name
, &st
) < 0)
16094 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16095 if (dwarf2_per_objfile
)
16097 volatile struct gdb_exception except
;
16099 TRY_CATCH (except
, RETURN_MASK_ERROR
)
16101 write_psymtabs_to_index (objfile
, arg
);
16103 if (except
.reason
< 0)
16104 exception_fprintf (gdb_stderr
, except
,
16105 _("Error while writing index for `%s': "),
16113 int dwarf2_always_disassemble
;
16116 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
16117 struct cmd_list_element
*c
, const char *value
)
16119 fprintf_filtered (file
,
16120 _("Whether to always disassemble "
16121 "DWARF expressions is %s.\n"),
16125 void _initialize_dwarf2_read (void);
16128 _initialize_dwarf2_read (void)
16130 struct cmd_list_element
*c
;
16132 dwarf2_objfile_data_key
16133 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
16135 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
16136 Set DWARF 2 specific variables.\n\
16137 Configure DWARF 2 variables such as the cache size"),
16138 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
16139 0/*allow-unknown*/, &maintenance_set_cmdlist
);
16141 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
16142 Show DWARF 2 specific variables\n\
16143 Show DWARF 2 variables such as the cache size"),
16144 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
16145 0/*allow-unknown*/, &maintenance_show_cmdlist
);
16147 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
16148 &dwarf2_max_cache_age
, _("\
16149 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
16150 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
16151 A higher limit means that cached compilation units will be stored\n\
16152 in memory longer, and more total memory will be used. Zero disables\n\
16153 caching, which can slow down startup."),
16155 show_dwarf2_max_cache_age
,
16156 &set_dwarf2_cmdlist
,
16157 &show_dwarf2_cmdlist
);
16159 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
16160 &dwarf2_always_disassemble
, _("\
16161 Set whether `info address' always disassembles DWARF expressions."), _("\
16162 Show whether `info address' always disassembles DWARF expressions."), _("\
16163 When enabled, DWARF expressions are always printed in an assembly-like\n\
16164 syntax. When disabled, expressions will be printed in a more\n\
16165 conversational style, when possible."),
16167 show_dwarf2_always_disassemble
,
16168 &set_dwarf2_cmdlist
,
16169 &show_dwarf2_cmdlist
);
16171 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
16172 Set debugging of the dwarf2 DIE reader."), _("\
16173 Show debugging of the dwarf2 DIE reader."), _("\
16174 When enabled (non-zero), DIEs are dumped after they are read in.\n\
16175 The value is the maximum depth to print."),
16178 &setdebuglist
, &showdebuglist
);
16180 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
16182 Save a gdb-index file.\n\
16183 Usage: save gdb-index DIRECTORY"),
16185 set_cmd_completer (c
, filename_completer
);