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"
62 #include "gdb_string.h"
63 #include "gdb_assert.h"
64 #include <sys/types.h>
71 #define MAP_FAILED ((void *) -1)
75 typedef struct symbol
*symbolp
;
79 /* .debug_info header for a compilation unit
80 Because of alignment constraints, this structure has padding and cannot
81 be mapped directly onto the beginning of the .debug_info section. */
82 typedef struct comp_unit_header
84 unsigned int length
; /* length of the .debug_info
86 unsigned short version
; /* version number -- 2 for DWARF
88 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
89 unsigned char addr_size
; /* byte size of an address -- 4 */
92 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
95 /* .debug_line statement program prologue
96 Because of alignment constraints, this structure has padding and cannot
97 be mapped directly onto the beginning of the .debug_info section. */
98 typedef struct statement_prologue
100 unsigned int total_length
; /* byte length of the statement
102 unsigned short version
; /* version number -- 2 for DWARF
104 unsigned int prologue_length
; /* # bytes between prologue &
106 unsigned char minimum_instruction_length
; /* byte size of
108 unsigned char default_is_stmt
; /* initial value of is_stmt
111 unsigned char line_range
;
112 unsigned char opcode_base
; /* number assigned to first special
114 unsigned char *standard_opcode_lengths
;
118 /* When non-zero, dump DIEs after they are read in. */
119 static int dwarf2_die_debug
= 0;
123 /* When set, the file that we're processing is known to have debugging
124 info for C++ namespaces. GCC 3.3.x did not produce this information,
125 but later versions do. */
127 static int processing_has_namespace_info
;
129 static const struct objfile_data
*dwarf2_objfile_data_key
;
131 struct dwarf2_section_info
137 /* True if we have tried to read this section. */
141 /* All offsets in the index are of this type. It must be
142 architecture-independent. */
143 typedef uint32_t offset_type
;
145 DEF_VEC_I (offset_type
);
147 /* A description of the mapped index. The file format is described in
148 a comment by the code that writes the index. */
151 /* The total length of the buffer. */
153 /* A pointer to the address table data. */
154 const gdb_byte
*address_table
;
155 /* Size of the address table data in bytes. */
156 offset_type address_table_size
;
157 /* The symbol table, implemented as a hash table. */
158 const offset_type
*symbol_table
;
159 /* Size in slots, each slot is 2 offset_types. */
160 offset_type symbol_table_slots
;
161 /* A pointer to the constant pool. */
162 const char *constant_pool
;
165 struct dwarf2_per_objfile
167 struct dwarf2_section_info info
;
168 struct dwarf2_section_info abbrev
;
169 struct dwarf2_section_info line
;
170 struct dwarf2_section_info loc
;
171 struct dwarf2_section_info macinfo
;
172 struct dwarf2_section_info str
;
173 struct dwarf2_section_info ranges
;
174 struct dwarf2_section_info types
;
175 struct dwarf2_section_info frame
;
176 struct dwarf2_section_info eh_frame
;
177 struct dwarf2_section_info gdb_index
;
180 struct objfile
*objfile
;
182 /* A list of all the compilation units. This is used to locate
183 the target compilation unit of a particular reference. */
184 struct dwarf2_per_cu_data
**all_comp_units
;
186 /* The number of compilation units in ALL_COMP_UNITS. */
189 /* The number of .debug_types-related CUs. */
190 int n_type_comp_units
;
192 /* The .debug_types-related CUs. */
193 struct dwarf2_per_cu_data
**type_comp_units
;
195 /* A chain of compilation units that are currently read in, so that
196 they can be freed later. */
197 struct dwarf2_per_cu_data
*read_in_chain
;
199 /* A table mapping .debug_types signatures to its signatured_type entry.
200 This is NULL if the .debug_types section hasn't been read in yet. */
201 htab_t signatured_types
;
203 /* A flag indicating wether this objfile has a section loaded at a
205 int has_section_at_zero
;
207 /* True if we are using the mapped index,
208 or we are faking it for OBJF_READNOW's sake. */
209 unsigned char using_index
;
211 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
212 struct mapped_index
*index_table
;
214 /* When using index_table, this keeps track of all quick_file_names entries.
215 TUs can share line table entries with CUs or other TUs, and there can be
216 a lot more TUs than unique line tables, so we maintain a separate table
217 of all line table entries to support the sharing. */
218 htab_t quick_file_names_table
;
220 /* Set during partial symbol reading, to prevent queueing of full
222 int reading_partial_symbols
;
224 /* Table mapping type .debug_info DIE offsets to types.
225 This is NULL if not allocated yet.
226 It (currently) makes sense to allocate debug_types_type_hash lazily.
227 To keep things simple we allocate both lazily. */
228 htab_t debug_info_type_hash
;
230 /* Table mapping type .debug_types DIE offsets to types.
231 This is NULL if not allocated yet. */
232 htab_t debug_types_type_hash
;
235 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
237 /* names of the debugging sections */
239 /* Note that if the debugging section has been compressed, it might
240 have a name like .zdebug_info. */
242 #define INFO_SECTION "debug_info"
243 #define ABBREV_SECTION "debug_abbrev"
244 #define LINE_SECTION "debug_line"
245 #define LOC_SECTION "debug_loc"
246 #define MACINFO_SECTION "debug_macinfo"
247 #define STR_SECTION "debug_str"
248 #define RANGES_SECTION "debug_ranges"
249 #define TYPES_SECTION "debug_types"
250 #define FRAME_SECTION "debug_frame"
251 #define EH_FRAME_SECTION "eh_frame"
252 #define GDB_INDEX_SECTION "gdb_index"
254 /* local data types */
256 /* We hold several abbreviation tables in memory at the same time. */
257 #ifndef ABBREV_HASH_SIZE
258 #define ABBREV_HASH_SIZE 121
261 /* The data in a compilation unit header, after target2host
262 translation, looks like this. */
263 struct comp_unit_head
267 unsigned char addr_size
;
268 unsigned char signed_addr_p
;
269 unsigned int abbrev_offset
;
271 /* Size of file offsets; either 4 or 8. */
272 unsigned int offset_size
;
274 /* Size of the length field; either 4 or 12. */
275 unsigned int initial_length_size
;
277 /* Offset to the first byte of this compilation unit header in the
278 .debug_info section, for resolving relative reference dies. */
281 /* Offset to first die in this cu from the start of the cu.
282 This will be the first byte following the compilation unit header. */
283 unsigned int first_die_offset
;
286 /* Type used for delaying computation of method physnames.
287 See comments for compute_delayed_physnames. */
288 struct delayed_method_info
290 /* The type to which the method is attached, i.e., its parent class. */
293 /* The index of the method in the type's function fieldlists. */
296 /* The index of the method in the fieldlist. */
299 /* The name of the DIE. */
302 /* The DIE associated with this method. */
303 struct die_info
*die
;
306 typedef struct delayed_method_info delayed_method_info
;
307 DEF_VEC_O (delayed_method_info
);
309 /* Internal state when decoding a particular compilation unit. */
312 /* The objfile containing this compilation unit. */
313 struct objfile
*objfile
;
315 /* The header of the compilation unit. */
316 struct comp_unit_head header
;
318 /* Base address of this compilation unit. */
319 CORE_ADDR base_address
;
321 /* Non-zero if base_address has been set. */
324 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
326 /* The language we are debugging. */
327 enum language language
;
328 const struct language_defn
*language_defn
;
330 const char *producer
;
332 /* The generic symbol table building routines have separate lists for
333 file scope symbols and all all other scopes (local scopes). So
334 we need to select the right one to pass to add_symbol_to_list().
335 We do it by keeping a pointer to the correct list in list_in_scope.
337 FIXME: The original dwarf code just treated the file scope as the
338 first local scope, and all other local scopes as nested local
339 scopes, and worked fine. Check to see if we really need to
340 distinguish these in buildsym.c. */
341 struct pending
**list_in_scope
;
343 /* DWARF abbreviation table associated with this compilation unit. */
344 struct abbrev_info
**dwarf2_abbrevs
;
346 /* Storage for the abbrev table. */
347 struct obstack abbrev_obstack
;
349 /* Hash table holding all the loaded partial DIEs. */
352 /* Storage for things with the same lifetime as this read-in compilation
353 unit, including partial DIEs. */
354 struct obstack comp_unit_obstack
;
356 /* When multiple dwarf2_cu structures are living in memory, this field
357 chains them all together, so that they can be released efficiently.
358 We will probably also want a generation counter so that most-recently-used
359 compilation units are cached... */
360 struct dwarf2_per_cu_data
*read_in_chain
;
362 /* Backchain to our per_cu entry if the tree has been built. */
363 struct dwarf2_per_cu_data
*per_cu
;
365 /* How many compilation units ago was this CU last referenced? */
368 /* A hash table of die offsets for following references. */
371 /* Full DIEs if read in. */
372 struct die_info
*dies
;
374 /* A set of pointers to dwarf2_per_cu_data objects for compilation
375 units referenced by this one. Only set during full symbol processing;
376 partial symbol tables do not have dependencies. */
379 /* Header data from the line table, during full symbol processing. */
380 struct line_header
*line_header
;
382 /* A list of methods which need to have physnames computed
383 after all type information has been read. */
384 VEC (delayed_method_info
) *method_list
;
386 /* Mark used when releasing cached dies. */
387 unsigned int mark
: 1;
389 /* This flag will be set if this compilation unit might include
390 inter-compilation-unit references. */
391 unsigned int has_form_ref_addr
: 1;
393 /* This flag will be set if this compilation unit includes any
394 DW_TAG_namespace DIEs. If we know that there are explicit
395 DIEs for namespaces, we don't need to try to infer them
396 from mangled names. */
397 unsigned int has_namespace_info
: 1;
400 /* Persistent data held for a compilation unit, even when not
401 processing it. We put a pointer to this structure in the
402 read_symtab_private field of the psymtab. If we encounter
403 inter-compilation-unit references, we also maintain a sorted
404 list of all compilation units. */
406 struct dwarf2_per_cu_data
408 /* The start offset and length of this compilation unit. 2**29-1
409 bytes should suffice to store the length of any compilation unit
410 - if it doesn't, GDB will fall over anyway.
411 NOTE: Unlike comp_unit_head.length, this length includes
412 initial_length_size. */
414 unsigned int length
: 29;
416 /* Flag indicating this compilation unit will be read in before
417 any of the current compilation units are processed. */
418 unsigned int queued
: 1;
420 /* This flag will be set if we need to load absolutely all DIEs
421 for this compilation unit, instead of just the ones we think
422 are interesting. It gets set if we look for a DIE in the
423 hash table and don't find it. */
424 unsigned int load_all_dies
: 1;
426 /* Non-zero if this CU is from .debug_types.
427 Otherwise it's from .debug_info. */
428 unsigned int from_debug_types
: 1;
430 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
431 of the CU cache it gets reset to NULL again. */
432 struct dwarf2_cu
*cu
;
434 /* The corresponding objfile. */
435 struct objfile
*objfile
;
437 /* When using partial symbol tables, the 'psymtab' field is active.
438 Otherwise the 'quick' field is active. */
441 /* The partial symbol table associated with this compilation unit,
442 or NULL for partial units (which do not have an associated
444 struct partial_symtab
*psymtab
;
446 /* Data needed by the "quick" functions. */
447 struct dwarf2_per_cu_quick_data
*quick
;
451 /* Entry in the signatured_types hash table. */
453 struct signatured_type
457 /* Offset in .debug_types of the TU (type_unit) for this type. */
460 /* Offset in .debug_types of the type defined by this TU. */
461 unsigned int type_offset
;
463 /* The CU(/TU) of this type. */
464 struct dwarf2_per_cu_data per_cu
;
467 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
468 which are used for both .debug_info and .debug_types dies.
469 All parameters here are unchanging for the life of the call.
470 This struct exists to abstract away the constant parameters of
473 struct die_reader_specs
475 /* The bfd of this objfile. */
478 /* The CU of the DIE we are parsing. */
479 struct dwarf2_cu
*cu
;
481 /* Pointer to start of section buffer.
482 This is either the start of .debug_info or .debug_types. */
483 const gdb_byte
*buffer
;
486 /* The line number information for a compilation unit (found in the
487 .debug_line section) begins with a "statement program header",
488 which contains the following information. */
491 unsigned int total_length
;
492 unsigned short version
;
493 unsigned int header_length
;
494 unsigned char minimum_instruction_length
;
495 unsigned char maximum_ops_per_instruction
;
496 unsigned char default_is_stmt
;
498 unsigned char line_range
;
499 unsigned char opcode_base
;
501 /* standard_opcode_lengths[i] is the number of operands for the
502 standard opcode whose value is i. This means that
503 standard_opcode_lengths[0] is unused, and the last meaningful
504 element is standard_opcode_lengths[opcode_base - 1]. */
505 unsigned char *standard_opcode_lengths
;
507 /* The include_directories table. NOTE! These strings are not
508 allocated with xmalloc; instead, they are pointers into
509 debug_line_buffer. If you try to free them, `free' will get
511 unsigned int num_include_dirs
, include_dirs_size
;
514 /* The file_names table. NOTE! These strings are not allocated
515 with xmalloc; instead, they are pointers into debug_line_buffer.
516 Don't try to free them directly. */
517 unsigned int num_file_names
, file_names_size
;
521 unsigned int dir_index
;
522 unsigned int mod_time
;
524 int included_p
; /* Non-zero if referenced by the Line Number Program. */
525 struct symtab
*symtab
; /* The associated symbol table, if any. */
528 /* The start and end of the statement program following this
529 header. These point into dwarf2_per_objfile->line_buffer. */
530 gdb_byte
*statement_program_start
, *statement_program_end
;
533 /* When we construct a partial symbol table entry we only
534 need this much information. */
535 struct partial_die_info
537 /* Offset of this DIE. */
540 /* DWARF-2 tag for this DIE. */
541 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
543 /* Assorted flags describing the data found in this DIE. */
544 unsigned int has_children
: 1;
545 unsigned int is_external
: 1;
546 unsigned int is_declaration
: 1;
547 unsigned int has_type
: 1;
548 unsigned int has_specification
: 1;
549 unsigned int has_pc_info
: 1;
551 /* Flag set if the SCOPE field of this structure has been
553 unsigned int scope_set
: 1;
555 /* Flag set if the DIE has a byte_size attribute. */
556 unsigned int has_byte_size
: 1;
558 /* Flag set if any of the DIE's children are template arguments. */
559 unsigned int has_template_arguments
: 1;
561 /* Flag set if fixup_partial_die has been called on this die. */
562 unsigned int fixup_called
: 1;
564 /* The name of this DIE. Normally the value of DW_AT_name, but
565 sometimes a default name for unnamed DIEs. */
568 /* The linkage name, if present. */
569 const char *linkage_name
;
571 /* The scope to prepend to our children. This is generally
572 allocated on the comp_unit_obstack, so will disappear
573 when this compilation unit leaves the cache. */
576 /* The location description associated with this DIE, if any. */
577 struct dwarf_block
*locdesc
;
579 /* If HAS_PC_INFO, the PC range associated with this DIE. */
583 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
584 DW_AT_sibling, if any. */
585 /* NOTE: This member isn't strictly necessary, read_partial_die could
586 return DW_AT_sibling values to its caller load_partial_dies. */
589 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
590 DW_AT_specification (or DW_AT_abstract_origin or
592 unsigned int spec_offset
;
594 /* Pointers to this DIE's parent, first child, and next sibling,
596 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
599 /* This data structure holds the information of an abbrev. */
602 unsigned int number
; /* number identifying abbrev */
603 enum dwarf_tag tag
; /* dwarf tag */
604 unsigned short has_children
; /* boolean */
605 unsigned short num_attrs
; /* number of attributes */
606 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
607 struct abbrev_info
*next
; /* next in chain */
612 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
613 ENUM_BITFIELD(dwarf_form
) form
: 16;
616 /* Attributes have a name and a value */
619 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
620 ENUM_BITFIELD(dwarf_form
) form
: 15;
622 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
623 field should be in u.str (existing only for DW_STRING) but it is kept
624 here for better struct attribute alignment. */
625 unsigned int string_is_canonical
: 1;
630 struct dwarf_block
*blk
;
634 struct signatured_type
*signatured_type
;
639 /* This data structure holds a complete die structure. */
642 /* DWARF-2 tag for this DIE. */
643 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
645 /* Number of attributes */
646 unsigned char num_attrs
;
648 /* True if we're presently building the full type name for the
649 type derived from this DIE. */
650 unsigned char building_fullname
: 1;
655 /* Offset in .debug_info or .debug_types section. */
658 /* The dies in a compilation unit form an n-ary tree. PARENT
659 points to this die's parent; CHILD points to the first child of
660 this node; and all the children of a given node are chained
661 together via their SIBLING fields. */
662 struct die_info
*child
; /* Its first child, if any. */
663 struct die_info
*sibling
; /* Its next sibling, if any. */
664 struct die_info
*parent
; /* Its parent, if any. */
666 /* An array of attributes, with NUM_ATTRS elements. There may be
667 zero, but it's not common and zero-sized arrays are not
668 sufficiently portable C. */
669 struct attribute attrs
[1];
672 struct function_range
675 CORE_ADDR lowpc
, highpc
;
677 struct function_range
*next
;
680 /* Get at parts of an attribute structure */
682 #define DW_STRING(attr) ((attr)->u.str)
683 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
684 #define DW_UNSND(attr) ((attr)->u.unsnd)
685 #define DW_BLOCK(attr) ((attr)->u.blk)
686 #define DW_SND(attr) ((attr)->u.snd)
687 #define DW_ADDR(attr) ((attr)->u.addr)
688 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
690 /* Blocks are a bunch of untyped bytes. */
697 #ifndef ATTR_ALLOC_CHUNK
698 #define ATTR_ALLOC_CHUNK 4
701 /* Allocate fields for structs, unions and enums in this size. */
702 #ifndef DW_FIELD_ALLOC_CHUNK
703 #define DW_FIELD_ALLOC_CHUNK 4
706 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
707 but this would require a corresponding change in unpack_field_as_long
709 static int bits_per_byte
= 8;
711 /* The routines that read and process dies for a C struct or C++ class
712 pass lists of data member fields and lists of member function fields
713 in an instance of a field_info structure, as defined below. */
716 /* List of data member and baseclasses fields. */
719 struct nextfield
*next
;
724 *fields
, *baseclasses
;
726 /* Number of fields (including baseclasses). */
729 /* Number of baseclasses. */
732 /* Set if the accesibility of one of the fields is not public. */
733 int non_public_fields
;
735 /* Member function fields array, entries are allocated in the order they
736 are encountered in the object file. */
739 struct nextfnfield
*next
;
740 struct fn_field fnfield
;
744 /* Member function fieldlist array, contains name of possibly overloaded
745 member function, number of overloaded member functions and a pointer
746 to the head of the member function field chain. */
751 struct nextfnfield
*head
;
755 /* Number of entries in the fnfieldlists array. */
758 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
759 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
760 struct typedef_field_list
762 struct typedef_field field
;
763 struct typedef_field_list
*next
;
766 unsigned typedef_field_list_count
;
769 /* One item on the queue of compilation units to read in full symbols
771 struct dwarf2_queue_item
773 struct dwarf2_per_cu_data
*per_cu
;
774 struct dwarf2_queue_item
*next
;
777 /* The current queue. */
778 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
780 /* Loaded secondary compilation units are kept in memory until they
781 have not been referenced for the processing of this many
782 compilation units. Set this to zero to disable caching. Cache
783 sizes of up to at least twenty will improve startup time for
784 typical inter-CU-reference binaries, at an obvious memory cost. */
785 static int dwarf2_max_cache_age
= 5;
787 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
788 struct cmd_list_element
*c
, const char *value
)
790 fprintf_filtered (file
, _("The upper bound on the age of cached "
791 "dwarf2 compilation units is %s.\n"),
796 /* Various complaints about symbol reading that don't abort the process */
799 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
801 complaint (&symfile_complaints
,
802 _("statement list doesn't fit in .debug_line section"));
806 dwarf2_debug_line_missing_file_complaint (void)
808 complaint (&symfile_complaints
,
809 _(".debug_line section has line data without a file"));
813 dwarf2_debug_line_missing_end_sequence_complaint (void)
815 complaint (&symfile_complaints
,
816 _(".debug_line section has line "
817 "program sequence without an end"));
821 dwarf2_complex_location_expr_complaint (void)
823 complaint (&symfile_complaints
, _("location expression too complex"));
827 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
830 complaint (&symfile_complaints
,
831 _("const value length mismatch for '%s', got %d, expected %d"),
836 dwarf2_macros_too_long_complaint (void)
838 complaint (&symfile_complaints
,
839 _("macro info runs off end of `.debug_macinfo' section"));
843 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
845 complaint (&symfile_complaints
,
846 _("macro debug info contains a "
847 "malformed macro definition:\n`%s'"),
852 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
854 complaint (&symfile_complaints
,
855 _("invalid attribute class or form for '%s' in '%s'"),
859 /* local function prototypes */
861 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
863 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
866 static void dwarf2_build_psymtabs_hard (struct objfile
*);
868 static void scan_partial_symbols (struct partial_die_info
*,
869 CORE_ADDR
*, CORE_ADDR
*,
870 int, struct dwarf2_cu
*);
872 static void add_partial_symbol (struct partial_die_info
*,
875 static void add_partial_namespace (struct partial_die_info
*pdi
,
876 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
877 int need_pc
, struct dwarf2_cu
*cu
);
879 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
880 CORE_ADDR
*highpc
, int need_pc
,
881 struct dwarf2_cu
*cu
);
883 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
884 struct dwarf2_cu
*cu
);
886 static void add_partial_subprogram (struct partial_die_info
*pdi
,
887 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
888 int need_pc
, struct dwarf2_cu
*cu
);
890 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
891 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
892 bfd
*abfd
, struct dwarf2_cu
*cu
);
894 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
896 static void psymtab_to_symtab_1 (struct partial_symtab
*);
898 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
900 static void dwarf2_free_abbrev_table (void *);
902 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
905 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
908 static struct partial_die_info
*load_partial_dies (bfd
*,
909 gdb_byte
*, gdb_byte
*,
910 int, struct dwarf2_cu
*);
912 static gdb_byte
*read_partial_die (struct partial_die_info
*,
913 struct abbrev_info
*abbrev
,
915 gdb_byte
*, gdb_byte
*,
918 static struct partial_die_info
*find_partial_die (unsigned int,
921 static void fixup_partial_die (struct partial_die_info
*,
924 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
925 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
927 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
928 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
930 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
932 static int read_1_signed_byte (bfd
*, gdb_byte
*);
934 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
936 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
938 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
940 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
943 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
945 static LONGEST read_checked_initial_length_and_offset
946 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
947 unsigned int *, unsigned int *);
949 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
952 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
954 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
956 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
958 static char *read_indirect_string (bfd
*, gdb_byte
*,
959 const struct comp_unit_head
*,
962 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
964 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
966 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
968 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
970 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
973 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
977 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
978 struct dwarf2_cu
*cu
);
980 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
982 static struct die_info
*die_specification (struct die_info
*die
,
983 struct dwarf2_cu
**);
985 static void free_line_header (struct line_header
*lh
);
987 static void add_file_name (struct line_header
*, char *, unsigned int,
988 unsigned int, unsigned int);
990 static struct line_header
*(dwarf_decode_line_header
991 (unsigned int offset
,
992 bfd
*abfd
, struct dwarf2_cu
*cu
));
994 static void dwarf_decode_lines (struct line_header
*, const char *, bfd
*,
995 struct dwarf2_cu
*, struct partial_symtab
*);
997 static void dwarf2_start_subfile (char *, const char *, const char *);
999 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1000 struct dwarf2_cu
*);
1002 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1003 struct dwarf2_cu
*, struct symbol
*);
1005 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1006 struct dwarf2_cu
*);
1008 static void dwarf2_const_value_attr (struct attribute
*attr
,
1011 struct obstack
*obstack
,
1012 struct dwarf2_cu
*cu
, long *value
,
1014 struct dwarf2_locexpr_baton
**baton
);
1016 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1018 static int need_gnat_info (struct dwarf2_cu
*);
1020 static struct type
*die_descriptive_type (struct die_info
*,
1021 struct dwarf2_cu
*);
1023 static void set_descriptive_type (struct type
*, struct die_info
*,
1024 struct dwarf2_cu
*);
1026 static struct type
*die_containing_type (struct die_info
*,
1027 struct dwarf2_cu
*);
1029 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1030 struct dwarf2_cu
*);
1032 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1034 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1036 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1038 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1039 const char *suffix
, int physname
,
1040 struct dwarf2_cu
*cu
);
1042 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1044 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1046 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1048 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1050 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1051 struct dwarf2_cu
*, struct partial_symtab
*);
1053 static int dwarf2_get_pc_bounds (struct die_info
*,
1054 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1055 struct partial_symtab
*);
1057 static void get_scope_pc_bounds (struct die_info
*,
1058 CORE_ADDR
*, CORE_ADDR
*,
1059 struct dwarf2_cu
*);
1061 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1062 CORE_ADDR
, struct dwarf2_cu
*);
1064 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1065 struct dwarf2_cu
*);
1067 static void dwarf2_attach_fields_to_type (struct field_info
*,
1068 struct type
*, struct dwarf2_cu
*);
1070 static void dwarf2_add_member_fn (struct field_info
*,
1071 struct die_info
*, struct type
*,
1072 struct dwarf2_cu
*);
1074 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1076 struct dwarf2_cu
*);
1078 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1080 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1082 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1084 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1086 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1088 static struct type
*read_module_type (struct die_info
*die
,
1089 struct dwarf2_cu
*cu
);
1091 static const char *namespace_name (struct die_info
*die
,
1092 int *is_anonymous
, struct dwarf2_cu
*);
1094 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1096 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1098 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1099 struct dwarf2_cu
*);
1101 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1103 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1105 gdb_byte
**new_info_ptr
,
1106 struct die_info
*parent
);
1108 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1110 gdb_byte
**new_info_ptr
,
1111 struct die_info
*parent
);
1113 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1115 gdb_byte
**new_info_ptr
,
1116 struct die_info
*parent
);
1118 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1119 struct die_info
**, gdb_byte
*,
1122 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1124 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1127 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1129 static const char *dwarf2_full_name (char *name
,
1130 struct die_info
*die
,
1131 struct dwarf2_cu
*cu
);
1133 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1134 struct dwarf2_cu
**);
1136 static char *dwarf_tag_name (unsigned int);
1138 static char *dwarf_attr_name (unsigned int);
1140 static char *dwarf_form_name (unsigned int);
1142 static char *dwarf_bool_name (unsigned int);
1144 static char *dwarf_type_encoding_name (unsigned int);
1147 static char *dwarf_cfi_name (unsigned int);
1150 static struct die_info
*sibling_die (struct die_info
*);
1152 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1154 static void dump_die_for_error (struct die_info
*);
1156 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1159 /*static*/ void dump_die (struct die_info
*, int max_level
);
1161 static void store_in_ref_table (struct die_info
*,
1162 struct dwarf2_cu
*);
1164 static int is_ref_attr (struct attribute
*);
1166 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1168 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1170 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1172 struct dwarf2_cu
**);
1174 static struct die_info
*follow_die_ref (struct die_info
*,
1176 struct dwarf2_cu
**);
1178 static struct die_info
*follow_die_sig (struct die_info
*,
1180 struct dwarf2_cu
**);
1182 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1183 unsigned int offset
);
1185 static void read_signatured_type (struct objfile
*,
1186 struct signatured_type
*type_sig
);
1188 /* memory allocation interface */
1190 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1192 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1194 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1196 static void initialize_cu_func_list (struct dwarf2_cu
*);
1198 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1199 struct dwarf2_cu
*);
1201 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1202 char *, bfd
*, struct dwarf2_cu
*);
1204 static int attr_form_is_block (struct attribute
*);
1206 static int attr_form_is_section_offset (struct attribute
*);
1208 static int attr_form_is_constant (struct attribute
*);
1210 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1211 struct dwarf2_loclist_baton
*baton
,
1212 struct attribute
*attr
);
1214 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1216 struct dwarf2_cu
*cu
);
1218 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1219 struct abbrev_info
*abbrev
,
1220 struct dwarf2_cu
*cu
);
1222 static void free_stack_comp_unit (void *);
1224 static hashval_t
partial_die_hash (const void *item
);
1226 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1228 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1229 (unsigned int offset
, struct objfile
*objfile
);
1231 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1232 (unsigned int offset
, struct objfile
*objfile
);
1234 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1235 struct objfile
*objfile
);
1237 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1238 struct die_info
*comp_unit_die
);
1240 static void free_one_comp_unit (void *);
1242 static void free_cached_comp_units (void *);
1244 static void age_cached_comp_units (void);
1246 static void free_one_cached_comp_unit (void *);
1248 static struct type
*set_die_type (struct die_info
*, struct type
*,
1249 struct dwarf2_cu
*);
1251 static void create_all_comp_units (struct objfile
*);
1253 static int create_debug_types_hash_table (struct objfile
*objfile
);
1255 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1258 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1260 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1261 struct dwarf2_per_cu_data
*);
1263 static void dwarf2_mark (struct dwarf2_cu
*);
1265 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1267 static struct type
*get_die_type_at_offset (unsigned int,
1268 struct dwarf2_per_cu_data
*per_cu
);
1270 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1272 static void dwarf2_release_queue (void *dummy
);
1274 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1275 struct objfile
*objfile
);
1277 static void process_queue (struct objfile
*objfile
);
1279 static void find_file_and_directory (struct die_info
*die
,
1280 struct dwarf2_cu
*cu
,
1281 char **name
, char **comp_dir
);
1283 static char *file_full_name (int file
, struct line_header
*lh
,
1284 const char *comp_dir
);
1286 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1289 unsigned int buffer_size
,
1292 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1293 struct dwarf2_cu
*cu
);
1295 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1299 /* Convert VALUE between big- and little-endian. */
1301 byte_swap (offset_type value
)
1305 result
= (value
& 0xff) << 24;
1306 result
|= (value
& 0xff00) << 8;
1307 result
|= (value
& 0xff0000) >> 8;
1308 result
|= (value
& 0xff000000) >> 24;
1312 #define MAYBE_SWAP(V) byte_swap (V)
1315 #define MAYBE_SWAP(V) (V)
1316 #endif /* WORDS_BIGENDIAN */
1318 /* The suffix for an index file. */
1319 #define INDEX_SUFFIX ".gdb-index"
1321 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1322 struct dwarf2_cu
*cu
);
1324 /* Try to locate the sections we need for DWARF 2 debugging
1325 information and return true if we have enough to do something. */
1328 dwarf2_has_info (struct objfile
*objfile
)
1330 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1331 if (!dwarf2_per_objfile
)
1333 /* Initialize per-objfile state. */
1334 struct dwarf2_per_objfile
*data
1335 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1337 memset (data
, 0, sizeof (*data
));
1338 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1339 dwarf2_per_objfile
= data
;
1341 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1342 dwarf2_per_objfile
->objfile
= objfile
;
1344 return (dwarf2_per_objfile
->info
.asection
!= NULL
1345 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1348 /* When loading sections, we can either look for ".<name>", or for
1349 * ".z<name>", which indicates a compressed section. */
1352 section_is_p (const char *section_name
, const char *name
)
1354 return (section_name
[0] == '.'
1355 && (strcmp (section_name
+ 1, name
) == 0
1356 || (section_name
[1] == 'z'
1357 && strcmp (section_name
+ 2, name
) == 0)));
1360 /* This function is mapped across the sections and remembers the
1361 offset and size of each of the debugging sections we are interested
1365 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1367 if (section_is_p (sectp
->name
, INFO_SECTION
))
1369 dwarf2_per_objfile
->info
.asection
= sectp
;
1370 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1372 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1374 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1375 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1377 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1379 dwarf2_per_objfile
->line
.asection
= sectp
;
1380 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1382 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1384 dwarf2_per_objfile
->loc
.asection
= sectp
;
1385 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1387 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1389 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1390 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1392 else if (section_is_p (sectp
->name
, STR_SECTION
))
1394 dwarf2_per_objfile
->str
.asection
= sectp
;
1395 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1397 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1399 dwarf2_per_objfile
->frame
.asection
= sectp
;
1400 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1402 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1404 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1406 if (aflag
& SEC_HAS_CONTENTS
)
1408 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1409 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1412 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1414 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1415 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1417 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1419 dwarf2_per_objfile
->types
.asection
= sectp
;
1420 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1422 else if (section_is_p (sectp
->name
, GDB_INDEX_SECTION
))
1424 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1425 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1428 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1429 && bfd_section_vma (abfd
, sectp
) == 0)
1430 dwarf2_per_objfile
->has_section_at_zero
= 1;
1433 /* Decompress a section that was compressed using zlib. Store the
1434 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1437 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1438 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1440 bfd
*abfd
= objfile
->obfd
;
1442 error (_("Support for zlib-compressed DWARF data (from '%s') "
1443 "is disabled in this copy of GDB"),
1444 bfd_get_filename (abfd
));
1446 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1447 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1448 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1449 bfd_size_type uncompressed_size
;
1450 gdb_byte
*uncompressed_buffer
;
1453 int header_size
= 12;
1455 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1456 || bfd_bread (compressed_buffer
,
1457 compressed_size
, abfd
) != compressed_size
)
1458 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1459 bfd_get_filename (abfd
));
1461 /* Read the zlib header. In this case, it should be "ZLIB" followed
1462 by the uncompressed section size, 8 bytes in big-endian order. */
1463 if (compressed_size
< header_size
1464 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1465 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1466 bfd_get_filename (abfd
));
1467 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1468 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1469 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1470 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1471 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1472 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1473 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1474 uncompressed_size
+= compressed_buffer
[11];
1476 /* It is possible the section consists of several compressed
1477 buffers concatenated together, so we uncompress in a loop. */
1481 strm
.avail_in
= compressed_size
- header_size
;
1482 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1483 strm
.avail_out
= uncompressed_size
;
1484 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1486 rc
= inflateInit (&strm
);
1487 while (strm
.avail_in
> 0)
1490 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1491 bfd_get_filename (abfd
), rc
);
1492 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1493 + (uncompressed_size
- strm
.avail_out
));
1494 rc
= inflate (&strm
, Z_FINISH
);
1495 if (rc
!= Z_STREAM_END
)
1496 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1497 bfd_get_filename (abfd
), rc
);
1498 rc
= inflateReset (&strm
);
1500 rc
= inflateEnd (&strm
);
1502 || strm
.avail_out
!= 0)
1503 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1504 bfd_get_filename (abfd
), rc
);
1506 do_cleanups (cleanup
);
1507 *outbuf
= uncompressed_buffer
;
1508 *outsize
= uncompressed_size
;
1512 /* Read the contents of the section SECTP from object file specified by
1513 OBJFILE, store info about the section into INFO.
1514 If the section is compressed, uncompress it before returning. */
1517 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1519 bfd
*abfd
= objfile
->obfd
;
1520 asection
*sectp
= info
->asection
;
1521 gdb_byte
*buf
, *retbuf
;
1522 unsigned char header
[4];
1526 info
->buffer
= NULL
;
1527 info
->was_mmapped
= 0;
1530 if (info
->asection
== NULL
|| info
->size
== 0)
1533 /* Check if the file has a 4-byte header indicating compression. */
1534 if (info
->size
> sizeof (header
)
1535 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1536 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1538 /* Upon decompression, update the buffer and its size. */
1539 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1541 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1549 pagesize
= getpagesize ();
1551 /* Only try to mmap sections which are large enough: we don't want to
1552 waste space due to fragmentation. Also, only try mmap for sections
1553 without relocations. */
1555 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1557 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1558 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1559 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1560 MAP_PRIVATE
, pg_offset
);
1562 if (retbuf
!= MAP_FAILED
)
1564 info
->was_mmapped
= 1;
1565 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1566 #if HAVE_POSIX_MADVISE
1567 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1574 /* If we get here, we are a normal, not-compressed section. */
1576 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1578 /* When debugging .o files, we may need to apply relocations; see
1579 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1580 We never compress sections in .o files, so we only need to
1581 try this when the section is not compressed. */
1582 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1585 info
->buffer
= retbuf
;
1589 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1590 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1591 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1592 bfd_get_filename (abfd
));
1595 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1599 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1600 asection
**sectp
, gdb_byte
**bufp
,
1601 bfd_size_type
*sizep
)
1603 struct dwarf2_per_objfile
*data
1604 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1605 struct dwarf2_section_info
*info
;
1607 /* We may see an objfile without any DWARF, in which case we just
1616 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1617 info
= &data
->eh_frame
;
1618 else if (section_is_p (section_name
, FRAME_SECTION
))
1619 info
= &data
->frame
;
1621 gdb_assert_not_reached ("unexpected section");
1623 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1624 /* We haven't read this section in yet. Do it now. */
1625 dwarf2_read_section (objfile
, info
);
1627 *sectp
= info
->asection
;
1628 *bufp
= info
->buffer
;
1629 *sizep
= info
->size
;
1633 /* DWARF quick_symbols_functions support. */
1635 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1636 unique line tables, so we maintain a separate table of all .debug_line
1637 derived entries to support the sharing.
1638 All the quick functions need is the list of file names. We discard the
1639 line_header when we're done and don't need to record it here. */
1640 struct quick_file_names
1642 /* The offset in .debug_line of the line table. We hash on this. */
1643 unsigned int offset
;
1645 /* The number of entries in file_names, real_names. */
1646 unsigned int num_file_names
;
1648 /* The file names from the line table, after being run through
1650 const char **file_names
;
1652 /* The file names from the line table after being run through
1653 gdb_realpath. These are computed lazily. */
1654 const char **real_names
;
1657 /* When using the index (and thus not using psymtabs), each CU has an
1658 object of this type. This is used to hold information needed by
1659 the various "quick" methods. */
1660 struct dwarf2_per_cu_quick_data
1662 /* The file table. This can be NULL if there was no file table
1663 or it's currently not read in.
1664 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1665 struct quick_file_names
*file_names
;
1667 /* The corresponding symbol table. This is NULL if symbols for this
1668 CU have not yet been read. */
1669 struct symtab
*symtab
;
1671 /* A temporary mark bit used when iterating over all CUs in
1672 expand_symtabs_matching. */
1673 unsigned int mark
: 1;
1675 /* True if we've tried to read the file table and found there isn't one.
1676 There will be no point in trying to read it again next time. */
1677 unsigned int no_file_data
: 1;
1680 /* Hash function for a quick_file_names. */
1683 hash_file_name_entry (const void *e
)
1685 const struct quick_file_names
*file_data
= e
;
1687 return file_data
->offset
;
1690 /* Equality function for a quick_file_names. */
1693 eq_file_name_entry (const void *a
, const void *b
)
1695 const struct quick_file_names
*ea
= a
;
1696 const struct quick_file_names
*eb
= b
;
1698 return ea
->offset
== eb
->offset
;
1701 /* Delete function for a quick_file_names. */
1704 delete_file_name_entry (void *e
)
1706 struct quick_file_names
*file_data
= e
;
1709 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1711 xfree ((void*) file_data
->file_names
[i
]);
1712 if (file_data
->real_names
)
1713 xfree ((void*) file_data
->real_names
[i
]);
1716 /* The space for the struct itself lives on objfile_obstack,
1717 so we don't free it here. */
1720 /* Create a quick_file_names hash table. */
1723 create_quick_file_names_table (unsigned int nr_initial_entries
)
1725 return htab_create_alloc (nr_initial_entries
,
1726 hash_file_name_entry
, eq_file_name_entry
,
1727 delete_file_name_entry
, xcalloc
, xfree
);
1730 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1734 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1735 struct dwarf2_per_cu_data
*per_cu
)
1737 struct cleanup
*back_to
;
1739 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1741 queue_comp_unit (per_cu
, objfile
);
1743 if (per_cu
->from_debug_types
)
1744 read_signatured_type_at_offset (objfile
, per_cu
->offset
);
1746 load_full_comp_unit (per_cu
, objfile
);
1748 process_queue (objfile
);
1750 /* Age the cache, releasing compilation units that have not
1751 been used recently. */
1752 age_cached_comp_units ();
1754 do_cleanups (back_to
);
1757 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1758 the objfile from which this CU came. Returns the resulting symbol
1761 static struct symtab
*
1762 dw2_instantiate_symtab (struct objfile
*objfile
,
1763 struct dwarf2_per_cu_data
*per_cu
)
1765 if (!per_cu
->v
.quick
->symtab
)
1767 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1768 increment_reading_symtab ();
1769 dw2_do_instantiate_symtab (objfile
, per_cu
);
1770 do_cleanups (back_to
);
1772 return per_cu
->v
.quick
->symtab
;
1775 /* Return the CU given its index. */
1777 static struct dwarf2_per_cu_data
*
1778 dw2_get_cu (int index
)
1780 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1782 index
-= dwarf2_per_objfile
->n_comp_units
;
1783 return dwarf2_per_objfile
->type_comp_units
[index
];
1785 return dwarf2_per_objfile
->all_comp_units
[index
];
1788 /* A helper function that knows how to read a 64-bit value in a way
1789 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1793 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1795 if (sizeof (ULONGEST
) < 8)
1799 /* Ignore the upper 4 bytes if they are all zero. */
1800 for (i
= 0; i
< 4; ++i
)
1801 if (bytes
[i
+ 4] != 0)
1804 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1807 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1811 /* Read the CU list from the mapped index, and use it to create all
1812 the CU objects for this objfile. Return 0 if something went wrong,
1813 1 if everything went ok. */
1816 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1817 offset_type cu_list_elements
)
1821 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1822 dwarf2_per_objfile
->all_comp_units
1823 = obstack_alloc (&objfile
->objfile_obstack
,
1824 dwarf2_per_objfile
->n_comp_units
1825 * sizeof (struct dwarf2_per_cu_data
*));
1827 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1829 struct dwarf2_per_cu_data
*the_cu
;
1830 ULONGEST offset
, length
;
1832 if (!extract_cu_value (cu_list
, &offset
)
1833 || !extract_cu_value (cu_list
+ 8, &length
))
1837 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1838 struct dwarf2_per_cu_data
);
1839 the_cu
->offset
= offset
;
1840 the_cu
->length
= length
;
1841 the_cu
->objfile
= objfile
;
1842 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1843 struct dwarf2_per_cu_quick_data
);
1844 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1850 /* Create the signatured type hash table from the index. */
1853 create_signatured_type_table_from_index (struct objfile
*objfile
,
1854 const gdb_byte
*bytes
,
1855 offset_type elements
)
1858 htab_t sig_types_hash
;
1860 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1861 dwarf2_per_objfile
->type_comp_units
1862 = obstack_alloc (&objfile
->objfile_obstack
,
1863 dwarf2_per_objfile
->n_type_comp_units
1864 * sizeof (struct dwarf2_per_cu_data
*));
1866 sig_types_hash
= allocate_signatured_type_table (objfile
);
1868 for (i
= 0; i
< elements
; i
+= 3)
1870 struct signatured_type
*type_sig
;
1871 ULONGEST offset
, type_offset
, signature
;
1874 if (!extract_cu_value (bytes
, &offset
)
1875 || !extract_cu_value (bytes
+ 8, &type_offset
))
1877 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1880 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1881 struct signatured_type
);
1882 type_sig
->signature
= signature
;
1883 type_sig
->offset
= offset
;
1884 type_sig
->type_offset
= type_offset
;
1885 type_sig
->per_cu
.from_debug_types
= 1;
1886 type_sig
->per_cu
.offset
= offset
;
1887 type_sig
->per_cu
.objfile
= objfile
;
1888 type_sig
->per_cu
.v
.quick
1889 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1890 struct dwarf2_per_cu_quick_data
);
1892 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1895 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1898 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1903 /* Read the address map data from the mapped index, and use it to
1904 populate the objfile's psymtabs_addrmap. */
1907 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1909 const gdb_byte
*iter
, *end
;
1910 struct obstack temp_obstack
;
1911 struct addrmap
*mutable_map
;
1912 struct cleanup
*cleanup
;
1915 obstack_init (&temp_obstack
);
1916 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1917 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1919 iter
= index
->address_table
;
1920 end
= iter
+ index
->address_table_size
;
1922 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1926 ULONGEST hi
, lo
, cu_index
;
1927 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1929 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1931 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1934 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1935 dw2_get_cu (cu_index
));
1938 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1939 &objfile
->objfile_obstack
);
1940 do_cleanups (cleanup
);
1943 /* The hash function for strings in the mapped index. This is the
1944 same as the hashtab.c hash function, but we keep a separate copy to
1945 maintain control over the implementation. This is necessary
1946 because the hash function is tied to the format of the mapped index
1950 mapped_index_string_hash (const void *p
)
1952 const unsigned char *str
= (const unsigned char *) p
;
1956 while ((c
= *str
++) != 0)
1957 r
= r
* 67 + c
- 113;
1962 /* Find a slot in the mapped index INDEX for the object named NAME.
1963 If NAME is found, set *VEC_OUT to point to the CU vector in the
1964 constant pool and return 1. If NAME cannot be found, return 0. */
1967 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
1968 offset_type
**vec_out
)
1970 offset_type hash
= mapped_index_string_hash (name
);
1971 offset_type slot
, step
;
1973 slot
= hash
& (index
->symbol_table_slots
- 1);
1974 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
1978 /* Convert a slot number to an offset into the table. */
1979 offset_type i
= 2 * slot
;
1981 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
1984 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
1985 if (!strcmp (name
, str
))
1987 *vec_out
= (offset_type
*) (index
->constant_pool
1988 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
1992 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
1996 /* Read the index file. If everything went ok, initialize the "quick"
1997 elements of all the CUs and return 1. Otherwise, return 0. */
2000 dwarf2_read_index (struct objfile
*objfile
)
2003 struct mapped_index
*map
;
2004 offset_type
*metadata
;
2005 const gdb_byte
*cu_list
;
2006 const gdb_byte
*types_list
= NULL
;
2007 offset_type version
, cu_list_elements
;
2008 offset_type types_list_elements
= 0;
2011 if (dwarf2_per_objfile
->gdb_index
.asection
== NULL
2012 || dwarf2_per_objfile
->gdb_index
.size
== 0)
2015 /* Older elfutils strip versions could keep the section in the main
2016 executable while splitting it for the separate debug info file. */
2017 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2018 & SEC_HAS_CONTENTS
) == 0)
2021 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2023 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2024 /* Version check. */
2025 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2026 /* Versions earlier than 3 emitted every copy of a psymbol. This
2027 causes the index to behave very poorly for certain requests. So,
2028 it seems better to just ignore such indices. */
2031 /* Indexes with higher version than the one supported by GDB may be no
2032 longer backward compatible. */
2036 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2037 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2039 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2042 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2043 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2047 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2048 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2049 - MAYBE_SWAP (metadata
[i
]))
2053 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2054 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2055 - MAYBE_SWAP (metadata
[i
]));
2058 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2059 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2060 - MAYBE_SWAP (metadata
[i
]))
2061 / (2 * sizeof (offset_type
)));
2064 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2066 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2069 if (types_list_elements
2070 && !create_signatured_type_table_from_index (objfile
, types_list
,
2071 types_list_elements
))
2074 create_addrmap_from_index (objfile
, map
);
2076 dwarf2_per_objfile
->index_table
= map
;
2077 dwarf2_per_objfile
->using_index
= 1;
2078 dwarf2_per_objfile
->quick_file_names_table
=
2079 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2084 /* A helper for the "quick" functions which sets the global
2085 dwarf2_per_objfile according to OBJFILE. */
2088 dw2_setup (struct objfile
*objfile
)
2090 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2091 gdb_assert (dwarf2_per_objfile
);
2094 /* A helper for the "quick" functions which attempts to read the line
2095 table for THIS_CU. */
2097 static struct quick_file_names
*
2098 dw2_get_file_names (struct objfile
*objfile
,
2099 struct dwarf2_per_cu_data
*this_cu
)
2101 bfd
*abfd
= objfile
->obfd
;
2102 struct line_header
*lh
;
2103 struct attribute
*attr
;
2104 struct cleanup
*cleanups
;
2105 struct die_info
*comp_unit_die
;
2106 struct dwarf2_section_info
* sec
;
2107 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2108 int has_children
, i
;
2109 struct dwarf2_cu cu
;
2110 unsigned int bytes_read
, buffer_size
;
2111 struct die_reader_specs reader_specs
;
2112 char *name
, *comp_dir
;
2114 struct quick_file_names
*qfn
;
2115 unsigned int line_offset
;
2117 if (this_cu
->v
.quick
->file_names
!= NULL
)
2118 return this_cu
->v
.quick
->file_names
;
2119 /* If we know there is no line data, no point in looking again. */
2120 if (this_cu
->v
.quick
->no_file_data
)
2123 init_one_comp_unit (&cu
, objfile
);
2124 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2126 if (this_cu
->from_debug_types
)
2127 sec
= &dwarf2_per_objfile
->types
;
2129 sec
= &dwarf2_per_objfile
->info
;
2130 dwarf2_read_section (objfile
, sec
);
2131 buffer_size
= sec
->size
;
2132 buffer
= sec
->buffer
;
2133 info_ptr
= buffer
+ this_cu
->offset
;
2134 beg_of_comp_unit
= info_ptr
;
2136 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2137 buffer
, buffer_size
,
2140 /* Complete the cu_header. */
2141 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2142 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2145 cu
.per_cu
= this_cu
;
2147 dwarf2_read_abbrevs (abfd
, &cu
);
2148 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2150 if (this_cu
->from_debug_types
)
2151 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2152 init_cu_die_reader (&reader_specs
, &cu
);
2153 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2159 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2162 struct quick_file_names find_entry
;
2164 line_offset
= DW_UNSND (attr
);
2166 /* We may have already read in this line header (TU line header sharing).
2167 If we have we're done. */
2168 find_entry
.offset
= line_offset
;
2169 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2170 &find_entry
, INSERT
);
2173 do_cleanups (cleanups
);
2174 this_cu
->v
.quick
->file_names
= *slot
;
2178 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2182 do_cleanups (cleanups
);
2183 this_cu
->v
.quick
->no_file_data
= 1;
2187 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2188 qfn
->offset
= line_offset
;
2189 gdb_assert (slot
!= NULL
);
2192 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2194 qfn
->num_file_names
= lh
->num_file_names
;
2195 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2196 lh
->num_file_names
* sizeof (char *));
2197 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2198 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2199 qfn
->real_names
= NULL
;
2201 free_line_header (lh
);
2202 do_cleanups (cleanups
);
2204 this_cu
->v
.quick
->file_names
= qfn
;
2208 /* A helper for the "quick" functions which computes and caches the
2209 real path for a given file name from the line table. */
2212 dw2_get_real_path (struct objfile
*objfile
,
2213 struct quick_file_names
*qfn
, int index
)
2215 if (qfn
->real_names
== NULL
)
2216 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2217 qfn
->num_file_names
, sizeof (char *));
2219 if (qfn
->real_names
[index
] == NULL
)
2220 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2222 return qfn
->real_names
[index
];
2225 static struct symtab
*
2226 dw2_find_last_source_symtab (struct objfile
*objfile
)
2230 dw2_setup (objfile
);
2231 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2232 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2235 /* Traversal function for dw2_forget_cached_source_info. */
2238 dw2_free_cached_file_names (void **slot
, void *info
)
2240 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2242 if (file_data
->real_names
)
2246 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2248 xfree ((void*) file_data
->real_names
[i
]);
2249 file_data
->real_names
[i
] = NULL
;
2257 dw2_forget_cached_source_info (struct objfile
*objfile
)
2259 dw2_setup (objfile
);
2261 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2262 dw2_free_cached_file_names
, NULL
);
2266 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2267 const char *full_path
, const char *real_path
,
2268 struct symtab
**result
)
2271 int check_basename
= lbasename (name
) == name
;
2272 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2274 dw2_setup (objfile
);
2276 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2277 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2280 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2281 struct quick_file_names
*file_data
;
2283 if (per_cu
->v
.quick
->symtab
)
2286 file_data
= dw2_get_file_names (objfile
, per_cu
);
2287 if (file_data
== NULL
)
2290 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2292 const char *this_name
= file_data
->file_names
[j
];
2294 if (FILENAME_CMP (name
, this_name
) == 0)
2296 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2300 if (check_basename
&& ! base_cu
2301 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2304 if (full_path
!= NULL
)
2306 const char *this_real_name
= dw2_get_real_path (objfile
,
2309 if (this_real_name
!= NULL
2310 && FILENAME_CMP (full_path
, this_real_name
) == 0)
2312 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2317 if (real_path
!= NULL
)
2319 const char *this_real_name
= dw2_get_real_path (objfile
,
2322 if (this_real_name
!= NULL
2323 && FILENAME_CMP (real_path
, this_real_name
) == 0)
2325 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2334 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2341 static struct symtab
*
2342 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2343 const char *name
, domain_enum domain
)
2345 /* We do all the work in the pre_expand_symtabs_matching hook
2350 /* A helper function that expands all symtabs that hold an object
2354 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2356 dw2_setup (objfile
);
2358 /* index_table is NULL if OBJF_READNOW. */
2359 if (dwarf2_per_objfile
->index_table
)
2363 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2366 offset_type i
, len
= MAYBE_SWAP (*vec
);
2367 for (i
= 0; i
< len
; ++i
)
2369 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2370 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2372 dw2_instantiate_symtab (objfile
, per_cu
);
2379 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2380 int kind
, const char *name
,
2383 dw2_do_expand_symtabs_matching (objfile
, name
);
2387 dw2_print_stats (struct objfile
*objfile
)
2391 dw2_setup (objfile
);
2393 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2394 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2396 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2398 if (!per_cu
->v
.quick
->symtab
)
2401 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2405 dw2_dump (struct objfile
*objfile
)
2407 /* Nothing worth printing. */
2411 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2412 struct section_offsets
*delta
)
2414 /* There's nothing to relocate here. */
2418 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2419 const char *func_name
)
2421 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2425 dw2_expand_all_symtabs (struct objfile
*objfile
)
2429 dw2_setup (objfile
);
2431 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2432 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2434 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2436 dw2_instantiate_symtab (objfile
, per_cu
);
2441 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2442 const char *filename
)
2446 dw2_setup (objfile
);
2448 /* We don't need to consider type units here.
2449 This is only called for examining code, e.g. expand_line_sal.
2450 There can be an order of magnitude (or more) more type units
2451 than comp units, and we avoid them if we can. */
2453 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2456 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2457 struct quick_file_names
*file_data
;
2459 if (per_cu
->v
.quick
->symtab
)
2462 file_data
= dw2_get_file_names (objfile
, per_cu
);
2463 if (file_data
== NULL
)
2466 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2468 const char *this_name
= file_data
->file_names
[j
];
2469 if (FILENAME_CMP (this_name
, filename
) == 0)
2471 dw2_instantiate_symtab (objfile
, per_cu
);
2479 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2481 struct dwarf2_per_cu_data
*per_cu
;
2483 struct quick_file_names
*file_data
;
2485 dw2_setup (objfile
);
2487 /* index_table is NULL if OBJF_READNOW. */
2488 if (!dwarf2_per_objfile
->index_table
)
2491 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2495 /* Note that this just looks at the very first one named NAME -- but
2496 actually we are looking for a function. find_main_filename
2497 should be rewritten so that it doesn't require a custom hook. It
2498 could just use the ordinary symbol tables. */
2499 /* vec[0] is the length, which must always be >0. */
2500 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2502 file_data
= dw2_get_file_names (objfile
, per_cu
);
2503 if (file_data
== NULL
)
2506 return file_data
->file_names
[file_data
->num_file_names
- 1];
2510 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2511 struct objfile
*objfile
, int global
,
2512 int (*callback
) (struct block
*,
2513 struct symbol
*, void *),
2514 void *data
, symbol_compare_ftype
*match
,
2515 symbol_compare_ftype
*ordered_compare
)
2517 /* Currently unimplemented; used for Ada. The function can be called if the
2518 current language is Ada for a non-Ada objfile using GNU index. As Ada
2519 does not look for non-Ada symbols this function should just return. */
2523 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2524 int (*file_matcher
) (const char *, void *),
2525 int (*name_matcher
) (const char *, void *),
2531 struct mapped_index
*index
;
2533 dw2_setup (objfile
);
2535 /* index_table is NULL if OBJF_READNOW. */
2536 if (!dwarf2_per_objfile
->index_table
)
2538 index
= dwarf2_per_objfile
->index_table
;
2540 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2541 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2544 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2545 struct quick_file_names
*file_data
;
2547 per_cu
->v
.quick
->mark
= 0;
2548 if (per_cu
->v
.quick
->symtab
)
2551 file_data
= dw2_get_file_names (objfile
, per_cu
);
2552 if (file_data
== NULL
)
2555 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2557 if (file_matcher (file_data
->file_names
[j
], data
))
2559 per_cu
->v
.quick
->mark
= 1;
2565 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2567 offset_type idx
= 2 * iter
;
2569 offset_type
*vec
, vec_len
, vec_idx
;
2571 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2574 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2576 if (! (*name_matcher
) (name
, data
))
2579 /* The name was matched, now expand corresponding CUs that were
2581 vec
= (offset_type
*) (index
->constant_pool
2582 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2583 vec_len
= MAYBE_SWAP (vec
[0]);
2584 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2586 struct dwarf2_per_cu_data
*per_cu
;
2588 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2589 if (per_cu
->v
.quick
->mark
)
2590 dw2_instantiate_symtab (objfile
, per_cu
);
2595 static struct symtab
*
2596 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2597 struct minimal_symbol
*msymbol
,
2599 struct obj_section
*section
,
2602 struct dwarf2_per_cu_data
*data
;
2604 dw2_setup (objfile
);
2606 if (!objfile
->psymtabs_addrmap
)
2609 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2613 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2614 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2615 paddress (get_objfile_arch (objfile
), pc
));
2617 return dw2_instantiate_symtab (objfile
, data
);
2621 dw2_map_symbol_names (struct objfile
*objfile
,
2622 void (*fun
) (const char *, void *),
2626 struct mapped_index
*index
;
2628 dw2_setup (objfile
);
2630 /* index_table is NULL if OBJF_READNOW. */
2631 if (!dwarf2_per_objfile
->index_table
)
2633 index
= dwarf2_per_objfile
->index_table
;
2635 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2637 offset_type idx
= 2 * iter
;
2639 offset_type
*vec
, vec_len
, vec_idx
;
2641 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2644 name
= (index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]));
2646 (*fun
) (name
, data
);
2651 dw2_map_symbol_filenames (struct objfile
*objfile
,
2652 void (*fun
) (const char *, const char *, void *),
2657 dw2_setup (objfile
);
2659 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2660 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2663 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2664 struct quick_file_names
*file_data
;
2666 if (per_cu
->v
.quick
->symtab
)
2669 file_data
= dw2_get_file_names (objfile
, per_cu
);
2670 if (file_data
== NULL
)
2673 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2675 const char *this_real_name
= dw2_get_real_path (objfile
, file_data
,
2677 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2683 dw2_has_symbols (struct objfile
*objfile
)
2688 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2691 dw2_find_last_source_symtab
,
2692 dw2_forget_cached_source_info
,
2695 dw2_pre_expand_symtabs_matching
,
2699 dw2_expand_symtabs_for_function
,
2700 dw2_expand_all_symtabs
,
2701 dw2_expand_symtabs_with_filename
,
2702 dw2_find_symbol_file
,
2703 dw2_map_matching_symbols
,
2704 dw2_expand_symtabs_matching
,
2705 dw2_find_pc_sect_symtab
,
2706 dw2_map_symbol_names
,
2707 dw2_map_symbol_filenames
2710 /* Initialize for reading DWARF for this objfile. Return 0 if this
2711 file will use psymtabs, or 1 if using the GNU index. */
2714 dwarf2_initialize_objfile (struct objfile
*objfile
)
2716 /* If we're about to read full symbols, don't bother with the
2717 indices. In this case we also don't care if some other debug
2718 format is making psymtabs, because they are all about to be
2720 if ((objfile
->flags
& OBJF_READNOW
))
2724 dwarf2_per_objfile
->using_index
= 1;
2725 create_all_comp_units (objfile
);
2726 create_debug_types_hash_table (objfile
);
2727 dwarf2_per_objfile
->quick_file_names_table
=
2728 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2730 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2731 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2733 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2735 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2736 struct dwarf2_per_cu_quick_data
);
2739 /* Return 1 so that gdb sees the "quick" functions. However,
2740 these functions will be no-ops because we will have expanded
2745 if (dwarf2_read_index (objfile
))
2748 dwarf2_build_psymtabs (objfile
);
2754 /* Build a partial symbol table. */
2757 dwarf2_build_psymtabs (struct objfile
*objfile
)
2759 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2761 init_psymbol_list (objfile
, 1024);
2764 dwarf2_build_psymtabs_hard (objfile
);
2767 /* Return TRUE if OFFSET is within CU_HEADER. */
2770 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2772 unsigned int bottom
= cu_header
->offset
;
2773 unsigned int top
= (cu_header
->offset
2775 + cu_header
->initial_length_size
);
2777 return (offset
>= bottom
&& offset
< top
);
2780 /* Read in the comp unit header information from the debug_info at info_ptr.
2781 NOTE: This leaves members offset, first_die_offset to be filled in
2785 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2786 gdb_byte
*info_ptr
, bfd
*abfd
)
2789 unsigned int bytes_read
;
2791 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2792 cu_header
->initial_length_size
= bytes_read
;
2793 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2794 info_ptr
+= bytes_read
;
2795 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2797 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2799 info_ptr
+= bytes_read
;
2800 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2802 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2803 if (signed_addr
< 0)
2804 internal_error (__FILE__
, __LINE__
,
2805 _("read_comp_unit_head: dwarf from non elf file"));
2806 cu_header
->signed_addr_p
= signed_addr
;
2812 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2813 gdb_byte
*buffer
, unsigned int buffer_size
,
2816 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2818 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2820 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2821 error (_("Dwarf Error: wrong version in compilation unit header "
2822 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2823 bfd_get_filename (abfd
));
2825 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
2826 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2827 "(offset 0x%lx + 6) [in module %s]"),
2828 (long) header
->abbrev_offset
,
2829 (long) (beg_of_comp_unit
- buffer
),
2830 bfd_get_filename (abfd
));
2832 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2833 > buffer
+ buffer_size
)
2834 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2835 "(offset 0x%lx + 0) [in module %s]"),
2836 (long) header
->length
,
2837 (long) (beg_of_comp_unit
- buffer
),
2838 bfd_get_filename (abfd
));
2843 /* Read in the types comp unit header information from .debug_types entry at
2844 types_ptr. The result is a pointer to one past the end of the header. */
2847 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2848 ULONGEST
*signature
,
2849 gdb_byte
*types_ptr
, bfd
*abfd
)
2851 gdb_byte
*initial_types_ptr
= types_ptr
;
2853 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2854 &dwarf2_per_objfile
->types
);
2855 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2857 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2859 *signature
= read_8_bytes (abfd
, types_ptr
);
2861 types_ptr
+= cu_header
->offset_size
;
2862 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2867 /* Allocate a new partial symtab for file named NAME and mark this new
2868 partial symtab as being an include of PST. */
2871 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2872 struct objfile
*objfile
)
2874 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2876 subpst
->section_offsets
= pst
->section_offsets
;
2877 subpst
->textlow
= 0;
2878 subpst
->texthigh
= 0;
2880 subpst
->dependencies
= (struct partial_symtab
**)
2881 obstack_alloc (&objfile
->objfile_obstack
,
2882 sizeof (struct partial_symtab
*));
2883 subpst
->dependencies
[0] = pst
;
2884 subpst
->number_of_dependencies
= 1;
2886 subpst
->globals_offset
= 0;
2887 subpst
->n_global_syms
= 0;
2888 subpst
->statics_offset
= 0;
2889 subpst
->n_static_syms
= 0;
2890 subpst
->symtab
= NULL
;
2891 subpst
->read_symtab
= pst
->read_symtab
;
2894 /* No private part is necessary for include psymtabs. This property
2895 can be used to differentiate between such include psymtabs and
2896 the regular ones. */
2897 subpst
->read_symtab_private
= NULL
;
2900 /* Read the Line Number Program data and extract the list of files
2901 included by the source file represented by PST. Build an include
2902 partial symtab for each of these included files. */
2905 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2906 struct die_info
*die
,
2907 struct partial_symtab
*pst
)
2909 struct objfile
*objfile
= cu
->objfile
;
2910 bfd
*abfd
= objfile
->obfd
;
2911 struct line_header
*lh
= NULL
;
2912 struct attribute
*attr
;
2914 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2917 unsigned int line_offset
= DW_UNSND (attr
);
2919 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2922 return; /* No linetable, so no includes. */
2924 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2925 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
2927 free_line_header (lh
);
2931 hash_type_signature (const void *item
)
2933 const struct signatured_type
*type_sig
= item
;
2935 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2936 return type_sig
->signature
;
2940 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2942 const struct signatured_type
*lhs
= item_lhs
;
2943 const struct signatured_type
*rhs
= item_rhs
;
2945 return lhs
->signature
== rhs
->signature
;
2948 /* Allocate a hash table for signatured types. */
2951 allocate_signatured_type_table (struct objfile
*objfile
)
2953 return htab_create_alloc_ex (41,
2954 hash_type_signature
,
2957 &objfile
->objfile_obstack
,
2958 hashtab_obstack_allocate
,
2959 dummy_obstack_deallocate
);
2962 /* A helper function to add a signatured type CU to a list. */
2965 add_signatured_type_cu_to_list (void **slot
, void *datum
)
2967 struct signatured_type
*sigt
= *slot
;
2968 struct dwarf2_per_cu_data
***datap
= datum
;
2970 **datap
= &sigt
->per_cu
;
2976 /* Create the hash table of all entries in the .debug_types section.
2977 The result is zero if there is an error (e.g. missing .debug_types section),
2978 otherwise non-zero. */
2981 create_debug_types_hash_table (struct objfile
*objfile
)
2985 struct dwarf2_per_cu_data
**iter
;
2987 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
2988 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
2990 if (info_ptr
== NULL
)
2992 dwarf2_per_objfile
->signatured_types
= NULL
;
2996 types_htab
= allocate_signatured_type_table (objfile
);
2998 if (dwarf2_die_debug
)
2999 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3001 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
3002 + dwarf2_per_objfile
->types
.size
)
3004 unsigned int offset
;
3005 unsigned int offset_size
;
3006 unsigned int type_offset
;
3007 unsigned int length
, initial_length_size
;
3008 unsigned short version
;
3010 struct signatured_type
*type_sig
;
3012 gdb_byte
*ptr
= info_ptr
;
3014 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
3016 /* We need to read the type's signature in order to build the hash
3017 table, but we don't need to read anything else just yet. */
3019 /* Sanity check to ensure entire cu is present. */
3020 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
3021 if (ptr
+ length
+ initial_length_size
3022 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
3024 complaint (&symfile_complaints
,
3025 _("debug type entry runs off end "
3026 "of `.debug_types' section, ignored"));
3030 offset_size
= initial_length_size
== 4 ? 4 : 8;
3031 ptr
+= initial_length_size
;
3032 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3034 ptr
+= offset_size
; /* abbrev offset */
3035 ptr
+= 1; /* address size */
3036 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3038 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3040 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3041 memset (type_sig
, 0, sizeof (*type_sig
));
3042 type_sig
->signature
= signature
;
3043 type_sig
->offset
= offset
;
3044 type_sig
->type_offset
= type_offset
;
3045 type_sig
->per_cu
.objfile
= objfile
;
3046 type_sig
->per_cu
.from_debug_types
= 1;
3048 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3049 gdb_assert (slot
!= NULL
);
3052 if (dwarf2_die_debug
)
3053 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3054 offset
, phex (signature
, sizeof (signature
)));
3056 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3059 dwarf2_per_objfile
->signatured_types
= types_htab
;
3061 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3062 dwarf2_per_objfile
->type_comp_units
3063 = obstack_alloc (&objfile
->objfile_obstack
,
3064 dwarf2_per_objfile
->n_type_comp_units
3065 * sizeof (struct dwarf2_per_cu_data
*));
3066 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3067 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3068 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3069 == dwarf2_per_objfile
->n_type_comp_units
);
3074 /* Lookup a signature based type.
3075 Returns NULL if SIG is not present in the table. */
3077 static struct signatured_type
*
3078 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3080 struct signatured_type find_entry
, *entry
;
3082 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3084 complaint (&symfile_complaints
,
3085 _("missing `.debug_types' section for DW_FORM_sig8 die"));
3089 find_entry
.signature
= sig
;
3090 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3094 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3097 init_cu_die_reader (struct die_reader_specs
*reader
,
3098 struct dwarf2_cu
*cu
)
3100 reader
->abfd
= cu
->objfile
->obfd
;
3102 if (cu
->per_cu
->from_debug_types
)
3104 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3105 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
3109 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3110 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3114 /* Find the base address of the compilation unit for range lists and
3115 location lists. It will normally be specified by DW_AT_low_pc.
3116 In DWARF-3 draft 4, the base address could be overridden by
3117 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3118 compilation units with discontinuous ranges. */
3121 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3123 struct attribute
*attr
;
3126 cu
->base_address
= 0;
3128 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3131 cu
->base_address
= DW_ADDR (attr
);
3136 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3139 cu
->base_address
= DW_ADDR (attr
);
3145 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3146 to combine the common parts.
3147 Process a compilation unit for a psymtab.
3148 BUFFER is a pointer to the beginning of the dwarf section buffer,
3149 either .debug_info or debug_types.
3150 INFO_PTR is a pointer to the start of the CU.
3151 Returns a pointer to the next CU. */
3154 process_psymtab_comp_unit (struct objfile
*objfile
,
3155 struct dwarf2_per_cu_data
*this_cu
,
3156 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3157 unsigned int buffer_size
)
3159 bfd
*abfd
= objfile
->obfd
;
3160 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3161 struct die_info
*comp_unit_die
;
3162 struct partial_symtab
*pst
;
3164 struct cleanup
*back_to_inner
;
3165 struct dwarf2_cu cu
;
3166 int has_children
, has_pc_info
;
3167 struct attribute
*attr
;
3168 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3169 struct die_reader_specs reader_specs
;
3171 init_one_comp_unit (&cu
, objfile
);
3172 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3174 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3175 buffer
, buffer_size
,
3178 /* Complete the cu_header. */
3179 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3180 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3182 cu
.list_in_scope
= &file_symbols
;
3184 /* If this compilation unit was already read in, free the
3185 cached copy in order to read it in again. This is
3186 necessary because we skipped some symbols when we first
3187 read in the compilation unit (see load_partial_dies).
3188 This problem could be avoided, but the benefit is
3190 if (this_cu
->cu
!= NULL
)
3191 free_one_cached_comp_unit (this_cu
->cu
);
3193 /* Note that this is a pointer to our stack frame, being
3194 added to a global data structure. It will be cleaned up
3195 in free_stack_comp_unit when we finish with this
3196 compilation unit. */
3198 cu
.per_cu
= this_cu
;
3200 /* Read the abbrevs for this compilation unit into a table. */
3201 dwarf2_read_abbrevs (abfd
, &cu
);
3202 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3204 /* Read the compilation unit die. */
3205 if (this_cu
->from_debug_types
)
3206 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3207 init_cu_die_reader (&reader_specs
, &cu
);
3208 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3211 if (this_cu
->from_debug_types
)
3213 /* offset,length haven't been set yet for type units. */
3214 this_cu
->offset
= cu
.header
.offset
;
3215 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3217 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3219 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3220 + cu
.header
.initial_length_size
);
3221 do_cleanups (back_to_inner
);
3225 prepare_one_comp_unit (&cu
, comp_unit_die
);
3227 /* Allocate a new partial symbol table structure. */
3228 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3229 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3230 (attr
!= NULL
) ? DW_STRING (attr
) : "",
3231 /* TEXTLOW and TEXTHIGH are set below. */
3233 objfile
->global_psymbols
.next
,
3234 objfile
->static_psymbols
.next
);
3236 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3238 pst
->dirname
= DW_STRING (attr
);
3240 pst
->read_symtab_private
= this_cu
;
3242 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3244 /* Store the function that reads in the rest of the symbol table */
3245 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3247 this_cu
->v
.psymtab
= pst
;
3249 dwarf2_find_base_address (comp_unit_die
, &cu
);
3251 /* Possibly set the default values of LOWPC and HIGHPC from
3253 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3254 &best_highpc
, &cu
, pst
);
3255 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3256 /* Store the contiguous range if it is not empty; it can be empty for
3257 CUs with no code. */
3258 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3259 best_lowpc
+ baseaddr
,
3260 best_highpc
+ baseaddr
- 1, pst
);
3262 /* Check if comp unit has_children.
3263 If so, read the rest of the partial symbols from this comp unit.
3264 If not, there's no more debug_info for this comp unit. */
3267 struct partial_die_info
*first_die
;
3268 CORE_ADDR lowpc
, highpc
;
3270 lowpc
= ((CORE_ADDR
) -1);
3271 highpc
= ((CORE_ADDR
) 0);
3273 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3275 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3276 ! has_pc_info
, &cu
);
3278 /* If we didn't find a lowpc, set it to highpc to avoid
3279 complaints from `maint check'. */
3280 if (lowpc
== ((CORE_ADDR
) -1))
3283 /* If the compilation unit didn't have an explicit address range,
3284 then use the information extracted from its child dies. */
3288 best_highpc
= highpc
;
3291 pst
->textlow
= best_lowpc
+ baseaddr
;
3292 pst
->texthigh
= best_highpc
+ baseaddr
;
3294 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3295 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3296 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3297 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3298 sort_pst_symbols (pst
);
3300 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3301 + cu
.header
.initial_length_size
);
3303 if (this_cu
->from_debug_types
)
3305 /* It's not clear we want to do anything with stmt lists here.
3306 Waiting to see what gcc ultimately does. */
3310 /* Get the list of files included in the current compilation unit,
3311 and build a psymtab for each of them. */
3312 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3315 do_cleanups (back_to_inner
);
3320 /* Traversal function for htab_traverse_noresize.
3321 Process one .debug_types comp-unit. */
3324 process_type_comp_unit (void **slot
, void *info
)
3326 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3327 struct objfile
*objfile
= (struct objfile
*) info
;
3328 struct dwarf2_per_cu_data
*this_cu
;
3330 this_cu
= &entry
->per_cu
;
3332 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3333 process_psymtab_comp_unit (objfile
, this_cu
,
3334 dwarf2_per_objfile
->types
.buffer
,
3335 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
3336 dwarf2_per_objfile
->types
.size
);
3341 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3342 Build partial symbol tables for the .debug_types comp-units. */
3345 build_type_psymtabs (struct objfile
*objfile
)
3347 if (! create_debug_types_hash_table (objfile
))
3350 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3351 process_type_comp_unit
, objfile
);
3354 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3357 psymtabs_addrmap_cleanup (void *o
)
3359 struct objfile
*objfile
= o
;
3361 objfile
->psymtabs_addrmap
= NULL
;
3364 /* Build the partial symbol table by doing a quick pass through the
3365 .debug_info and .debug_abbrev sections. */
3368 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3371 struct cleanup
*back_to
, *addrmap_cleanup
;
3372 struct obstack temp_obstack
;
3374 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3376 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3377 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3379 /* Any cached compilation units will be linked by the per-objfile
3380 read_in_chain. Make sure to free them when we're done. */
3381 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3383 build_type_psymtabs (objfile
);
3385 create_all_comp_units (objfile
);
3387 /* Create a temporary address map on a temporary obstack. We later
3388 copy this to the final obstack. */
3389 obstack_init (&temp_obstack
);
3390 make_cleanup_obstack_free (&temp_obstack
);
3391 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3392 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3394 /* Since the objects we're extracting from .debug_info vary in
3395 length, only the individual functions to extract them (like
3396 read_comp_unit_head and load_partial_die) can really know whether
3397 the buffer is large enough to hold another complete object.
3399 At the moment, they don't actually check that. If .debug_info
3400 holds just one extra byte after the last compilation unit's dies,
3401 then read_comp_unit_head will happily read off the end of the
3402 buffer. read_partial_die is similarly casual. Those functions
3405 For this loop condition, simply checking whether there's any data
3406 left at all should be sufficient. */
3408 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3409 + dwarf2_per_objfile
->info
.size
))
3411 struct dwarf2_per_cu_data
*this_cu
;
3413 this_cu
= dwarf2_find_comp_unit (info_ptr
3414 - dwarf2_per_objfile
->info
.buffer
,
3417 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3418 dwarf2_per_objfile
->info
.buffer
,
3420 dwarf2_per_objfile
->info
.size
);
3423 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3424 &objfile
->objfile_obstack
);
3425 discard_cleanups (addrmap_cleanup
);
3427 do_cleanups (back_to
);
3430 /* Load the partial DIEs for a secondary CU into memory. */
3433 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3434 struct objfile
*objfile
)
3436 bfd
*abfd
= objfile
->obfd
;
3437 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3438 struct die_info
*comp_unit_die
;
3439 struct dwarf2_cu
*cu
;
3440 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3442 struct die_reader_specs reader_specs
;
3445 gdb_assert (! this_cu
->from_debug_types
);
3447 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3448 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3449 beg_of_comp_unit
= info_ptr
;
3451 if (this_cu
->cu
== NULL
)
3453 cu
= xmalloc (sizeof (*cu
));
3454 init_one_comp_unit (cu
, objfile
);
3458 /* If an error occurs while loading, release our storage. */
3459 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3461 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3462 dwarf2_per_objfile
->info
.buffer
,
3463 dwarf2_per_objfile
->info
.size
,
3466 /* Complete the cu_header. */
3467 cu
->header
.offset
= this_cu
->offset
;
3468 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3470 /* Link this compilation unit into the compilation unit tree. */
3472 cu
->per_cu
= this_cu
;
3474 /* Link this CU into read_in_chain. */
3475 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3476 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3481 info_ptr
+= cu
->header
.first_die_offset
;
3484 /* Read the abbrevs for this compilation unit into a table. */
3485 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3486 dwarf2_read_abbrevs (abfd
, cu
);
3487 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3489 /* Read the compilation unit die. */
3490 init_cu_die_reader (&reader_specs
, cu
);
3491 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3494 prepare_one_comp_unit (cu
, comp_unit_die
);
3496 /* Check if comp unit has_children.
3497 If so, read the rest of the partial symbols from this comp unit.
3498 If not, there's no more debug_info for this comp unit. */
3500 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3502 do_cleanups (free_abbrevs_cleanup
);
3506 /* We've successfully allocated this compilation unit. Let our
3507 caller clean it up when finished with it. */
3508 discard_cleanups (free_cu_cleanup
);
3512 /* Create a list of all compilation units in OBJFILE. We do this only
3513 if an inter-comp-unit reference is found; presumably if there is one,
3514 there will be many, and one will occur early in the .debug_info section.
3515 So there's no point in building this list incrementally. */
3518 create_all_comp_units (struct objfile
*objfile
)
3522 struct dwarf2_per_cu_data
**all_comp_units
;
3525 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3526 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3530 all_comp_units
= xmalloc (n_allocated
3531 * sizeof (struct dwarf2_per_cu_data
*));
3533 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3534 + dwarf2_per_objfile
->info
.size
)
3536 unsigned int length
, initial_length_size
;
3537 struct dwarf2_per_cu_data
*this_cu
;
3538 unsigned int offset
;
3540 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3542 /* Read just enough information to find out where the next
3543 compilation unit is. */
3544 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3545 &initial_length_size
);
3547 /* Save the compilation unit for later lookup. */
3548 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3549 sizeof (struct dwarf2_per_cu_data
));
3550 memset (this_cu
, 0, sizeof (*this_cu
));
3551 this_cu
->offset
= offset
;
3552 this_cu
->length
= length
+ initial_length_size
;
3553 this_cu
->objfile
= objfile
;
3555 if (n_comp_units
== n_allocated
)
3558 all_comp_units
= xrealloc (all_comp_units
,
3560 * sizeof (struct dwarf2_per_cu_data
*));
3562 all_comp_units
[n_comp_units
++] = this_cu
;
3564 info_ptr
= info_ptr
+ this_cu
->length
;
3567 dwarf2_per_objfile
->all_comp_units
3568 = obstack_alloc (&objfile
->objfile_obstack
,
3569 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3570 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3571 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3572 xfree (all_comp_units
);
3573 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3576 /* Process all loaded DIEs for compilation unit CU, starting at
3577 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3578 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3579 DW_AT_ranges). If NEED_PC is set, then this function will set
3580 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3581 and record the covered ranges in the addrmap. */
3584 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3585 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3587 struct partial_die_info
*pdi
;
3589 /* Now, march along the PDI's, descending into ones which have
3590 interesting children but skipping the children of the other ones,
3591 until we reach the end of the compilation unit. */
3597 fixup_partial_die (pdi
, cu
);
3599 /* Anonymous namespaces or modules have no name but have interesting
3600 children, so we need to look at them. Ditto for anonymous
3603 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3604 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3608 case DW_TAG_subprogram
:
3609 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3611 case DW_TAG_constant
:
3612 case DW_TAG_variable
:
3613 case DW_TAG_typedef
:
3614 case DW_TAG_union_type
:
3615 if (!pdi
->is_declaration
)
3617 add_partial_symbol (pdi
, cu
);
3620 case DW_TAG_class_type
:
3621 case DW_TAG_interface_type
:
3622 case DW_TAG_structure_type
:
3623 if (!pdi
->is_declaration
)
3625 add_partial_symbol (pdi
, cu
);
3628 case DW_TAG_enumeration_type
:
3629 if (!pdi
->is_declaration
)
3630 add_partial_enumeration (pdi
, cu
);
3632 case DW_TAG_base_type
:
3633 case DW_TAG_subrange_type
:
3634 /* File scope base type definitions are added to the partial
3636 add_partial_symbol (pdi
, cu
);
3638 case DW_TAG_namespace
:
3639 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3642 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3649 /* If the die has a sibling, skip to the sibling. */
3651 pdi
= pdi
->die_sibling
;
3655 /* Functions used to compute the fully scoped name of a partial DIE.
3657 Normally, this is simple. For C++, the parent DIE's fully scoped
3658 name is concatenated with "::" and the partial DIE's name. For
3659 Java, the same thing occurs except that "." is used instead of "::".
3660 Enumerators are an exception; they use the scope of their parent
3661 enumeration type, i.e. the name of the enumeration type is not
3662 prepended to the enumerator.
3664 There are two complexities. One is DW_AT_specification; in this
3665 case "parent" means the parent of the target of the specification,
3666 instead of the direct parent of the DIE. The other is compilers
3667 which do not emit DW_TAG_namespace; in this case we try to guess
3668 the fully qualified name of structure types from their members'
3669 linkage names. This must be done using the DIE's children rather
3670 than the children of any DW_AT_specification target. We only need
3671 to do this for structures at the top level, i.e. if the target of
3672 any DW_AT_specification (if any; otherwise the DIE itself) does not
3675 /* Compute the scope prefix associated with PDI's parent, in
3676 compilation unit CU. The result will be allocated on CU's
3677 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3678 field. NULL is returned if no prefix is necessary. */
3680 partial_die_parent_scope (struct partial_die_info
*pdi
,
3681 struct dwarf2_cu
*cu
)
3683 char *grandparent_scope
;
3684 struct partial_die_info
*parent
, *real_pdi
;
3686 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3687 then this means the parent of the specification DIE. */
3690 while (real_pdi
->has_specification
)
3691 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3693 parent
= real_pdi
->die_parent
;
3697 if (parent
->scope_set
)
3698 return parent
->scope
;
3700 fixup_partial_die (parent
, cu
);
3702 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3704 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3705 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3706 Work around this problem here. */
3707 if (cu
->language
== language_cplus
3708 && parent
->tag
== DW_TAG_namespace
3709 && strcmp (parent
->name
, "::") == 0
3710 && grandparent_scope
== NULL
)
3712 parent
->scope
= NULL
;
3713 parent
->scope_set
= 1;
3717 if (parent
->tag
== DW_TAG_namespace
3718 || parent
->tag
== DW_TAG_module
3719 || parent
->tag
== DW_TAG_structure_type
3720 || parent
->tag
== DW_TAG_class_type
3721 || parent
->tag
== DW_TAG_interface_type
3722 || parent
->tag
== DW_TAG_union_type
3723 || parent
->tag
== DW_TAG_enumeration_type
)
3725 if (grandparent_scope
== NULL
)
3726 parent
->scope
= parent
->name
;
3728 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3730 parent
->name
, 0, cu
);
3732 else if (parent
->tag
== DW_TAG_enumerator
)
3733 /* Enumerators should not get the name of the enumeration as a prefix. */
3734 parent
->scope
= grandparent_scope
;
3737 /* FIXME drow/2004-04-01: What should we be doing with
3738 function-local names? For partial symbols, we should probably be
3740 complaint (&symfile_complaints
,
3741 _("unhandled containing DIE tag %d for DIE at %d"),
3742 parent
->tag
, pdi
->offset
);
3743 parent
->scope
= grandparent_scope
;
3746 parent
->scope_set
= 1;
3747 return parent
->scope
;
3750 /* Return the fully scoped name associated with PDI, from compilation unit
3751 CU. The result will be allocated with malloc. */
3753 partial_die_full_name (struct partial_die_info
*pdi
,
3754 struct dwarf2_cu
*cu
)
3758 /* If this is a template instantiation, we can not work out the
3759 template arguments from partial DIEs. So, unfortunately, we have
3760 to go through the full DIEs. At least any work we do building
3761 types here will be reused if full symbols are loaded later. */
3762 if (pdi
->has_template_arguments
)
3764 fixup_partial_die (pdi
, cu
);
3766 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3768 struct die_info
*die
;
3769 struct attribute attr
;
3770 struct dwarf2_cu
*ref_cu
= cu
;
3773 attr
.form
= DW_FORM_ref_addr
;
3774 attr
.u
.addr
= pdi
->offset
;
3775 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3777 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3781 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3782 if (parent_scope
== NULL
)
3785 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3789 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3791 struct objfile
*objfile
= cu
->objfile
;
3793 char *actual_name
= NULL
;
3794 const struct partial_symbol
*psym
= NULL
;
3796 int built_actual_name
= 0;
3798 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3800 actual_name
= partial_die_full_name (pdi
, cu
);
3802 built_actual_name
= 1;
3804 if (actual_name
== NULL
)
3805 actual_name
= pdi
->name
;
3809 case DW_TAG_subprogram
:
3810 if (pdi
->is_external
|| cu
->language
== language_ada
)
3812 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3813 of the global scope. But in Ada, we want to be able to access
3814 nested procedures globally. So all Ada subprograms are stored
3815 in the global scope. */
3816 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3817 mst_text, objfile); */
3818 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3820 VAR_DOMAIN
, LOC_BLOCK
,
3821 &objfile
->global_psymbols
,
3822 0, pdi
->lowpc
+ baseaddr
,
3823 cu
->language
, objfile
);
3827 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3828 mst_file_text, objfile); */
3829 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3831 VAR_DOMAIN
, LOC_BLOCK
,
3832 &objfile
->static_psymbols
,
3833 0, pdi
->lowpc
+ baseaddr
,
3834 cu
->language
, objfile
);
3837 case DW_TAG_constant
:
3839 struct psymbol_allocation_list
*list
;
3841 if (pdi
->is_external
)
3842 list
= &objfile
->global_psymbols
;
3844 list
= &objfile
->static_psymbols
;
3845 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3846 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
3847 list
, 0, 0, cu
->language
, objfile
);
3851 case DW_TAG_variable
:
3853 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3857 && !dwarf2_per_objfile
->has_section_at_zero
)
3859 /* A global or static variable may also have been stripped
3860 out by the linker if unused, in which case its address
3861 will be nullified; do not add such variables into partial
3862 symbol table then. */
3864 else if (pdi
->is_external
)
3867 Don't enter into the minimal symbol tables as there is
3868 a minimal symbol table entry from the ELF symbols already.
3869 Enter into partial symbol table if it has a location
3870 descriptor or a type.
3871 If the location descriptor is missing, new_symbol will create
3872 a LOC_UNRESOLVED symbol, the address of the variable will then
3873 be determined from the minimal symbol table whenever the variable
3875 The address for the partial symbol table entry is not
3876 used by GDB, but it comes in handy for debugging partial symbol
3879 if (pdi
->locdesc
|| pdi
->has_type
)
3880 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3882 VAR_DOMAIN
, LOC_STATIC
,
3883 &objfile
->global_psymbols
,
3885 cu
->language
, objfile
);
3889 /* Static Variable. Skip symbols without location descriptors. */
3890 if (pdi
->locdesc
== NULL
)
3892 if (built_actual_name
)
3893 xfree (actual_name
);
3896 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
3897 mst_file_data, objfile); */
3898 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3900 VAR_DOMAIN
, LOC_STATIC
,
3901 &objfile
->static_psymbols
,
3903 cu
->language
, objfile
);
3906 case DW_TAG_typedef
:
3907 case DW_TAG_base_type
:
3908 case DW_TAG_subrange_type
:
3909 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3911 VAR_DOMAIN
, LOC_TYPEDEF
,
3912 &objfile
->static_psymbols
,
3913 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3915 case DW_TAG_namespace
:
3916 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3918 VAR_DOMAIN
, LOC_TYPEDEF
,
3919 &objfile
->global_psymbols
,
3920 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3922 case DW_TAG_class_type
:
3923 case DW_TAG_interface_type
:
3924 case DW_TAG_structure_type
:
3925 case DW_TAG_union_type
:
3926 case DW_TAG_enumeration_type
:
3927 /* Skip external references. The DWARF standard says in the section
3928 about "Structure, Union, and Class Type Entries": "An incomplete
3929 structure, union or class type is represented by a structure,
3930 union or class entry that does not have a byte size attribute
3931 and that has a DW_AT_declaration attribute." */
3932 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3934 if (built_actual_name
)
3935 xfree (actual_name
);
3939 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3940 static vs. global. */
3941 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3943 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3944 (cu
->language
== language_cplus
3945 || cu
->language
== language_java
)
3946 ? &objfile
->global_psymbols
3947 : &objfile
->static_psymbols
,
3948 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3951 case DW_TAG_enumerator
:
3952 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3954 VAR_DOMAIN
, LOC_CONST
,
3955 (cu
->language
== language_cplus
3956 || cu
->language
== language_java
)
3957 ? &objfile
->global_psymbols
3958 : &objfile
->static_psymbols
,
3959 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3965 if (built_actual_name
)
3966 xfree (actual_name
);
3969 /* Read a partial die corresponding to a namespace; also, add a symbol
3970 corresponding to that namespace to the symbol table. NAMESPACE is
3971 the name of the enclosing namespace. */
3974 add_partial_namespace (struct partial_die_info
*pdi
,
3975 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3976 int need_pc
, struct dwarf2_cu
*cu
)
3978 /* Add a symbol for the namespace. */
3980 add_partial_symbol (pdi
, cu
);
3982 /* Now scan partial symbols in that namespace. */
3984 if (pdi
->has_children
)
3985 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3988 /* Read a partial die corresponding to a Fortran module. */
3991 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
3992 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3994 /* Now scan partial symbols in that module. */
3996 if (pdi
->has_children
)
3997 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4000 /* Read a partial die corresponding to a subprogram and create a partial
4001 symbol for that subprogram. When the CU language allows it, this
4002 routine also defines a partial symbol for each nested subprogram
4003 that this subprogram contains.
4005 DIE my also be a lexical block, in which case we simply search
4006 recursively for suprograms defined inside that lexical block.
4007 Again, this is only performed when the CU language allows this
4008 type of definitions. */
4011 add_partial_subprogram (struct partial_die_info
*pdi
,
4012 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4013 int need_pc
, struct dwarf2_cu
*cu
)
4015 if (pdi
->tag
== DW_TAG_subprogram
)
4017 if (pdi
->has_pc_info
)
4019 if (pdi
->lowpc
< *lowpc
)
4020 *lowpc
= pdi
->lowpc
;
4021 if (pdi
->highpc
> *highpc
)
4022 *highpc
= pdi
->highpc
;
4026 struct objfile
*objfile
= cu
->objfile
;
4028 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4029 SECT_OFF_TEXT (objfile
));
4030 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4031 pdi
->lowpc
+ baseaddr
,
4032 pdi
->highpc
- 1 + baseaddr
,
4033 cu
->per_cu
->v
.psymtab
);
4035 if (!pdi
->is_declaration
)
4036 /* Ignore subprogram DIEs that do not have a name, they are
4037 illegal. Do not emit a complaint at this point, we will
4038 do so when we convert this psymtab into a symtab. */
4040 add_partial_symbol (pdi
, cu
);
4044 if (! pdi
->has_children
)
4047 if (cu
->language
== language_ada
)
4049 pdi
= pdi
->die_child
;
4052 fixup_partial_die (pdi
, cu
);
4053 if (pdi
->tag
== DW_TAG_subprogram
4054 || pdi
->tag
== DW_TAG_lexical_block
)
4055 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4056 pdi
= pdi
->die_sibling
;
4061 /* Read a partial die corresponding to an enumeration type. */
4064 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4065 struct dwarf2_cu
*cu
)
4067 struct partial_die_info
*pdi
;
4069 if (enum_pdi
->name
!= NULL
)
4070 add_partial_symbol (enum_pdi
, cu
);
4072 pdi
= enum_pdi
->die_child
;
4075 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4076 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4078 add_partial_symbol (pdi
, cu
);
4079 pdi
= pdi
->die_sibling
;
4083 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4084 Return the corresponding abbrev, or NULL if the number is zero (indicating
4085 an empty DIE). In either case *BYTES_READ will be set to the length of
4086 the initial number. */
4088 static struct abbrev_info
*
4089 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4090 struct dwarf2_cu
*cu
)
4092 bfd
*abfd
= cu
->objfile
->obfd
;
4093 unsigned int abbrev_number
;
4094 struct abbrev_info
*abbrev
;
4096 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4098 if (abbrev_number
== 0)
4101 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4104 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4105 abbrev_number
, bfd_get_filename (abfd
));
4111 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4112 Returns a pointer to the end of a series of DIEs, terminated by an empty
4113 DIE. Any children of the skipped DIEs will also be skipped. */
4116 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4118 struct abbrev_info
*abbrev
;
4119 unsigned int bytes_read
;
4123 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4125 return info_ptr
+ bytes_read
;
4127 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4131 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4132 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4133 abbrev corresponding to that skipped uleb128 should be passed in
4134 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4138 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4139 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4141 unsigned int bytes_read
;
4142 struct attribute attr
;
4143 bfd
*abfd
= cu
->objfile
->obfd
;
4144 unsigned int form
, i
;
4146 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4148 /* The only abbrev we care about is DW_AT_sibling. */
4149 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4151 read_attribute (&attr
, &abbrev
->attrs
[i
],
4152 abfd
, info_ptr
, cu
);
4153 if (attr
.form
== DW_FORM_ref_addr
)
4154 complaint (&symfile_complaints
,
4155 _("ignoring absolute DW_AT_sibling"));
4157 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4160 /* If it isn't DW_AT_sibling, skip this attribute. */
4161 form
= abbrev
->attrs
[i
].form
;
4165 case DW_FORM_ref_addr
:
4166 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4167 and later it is offset sized. */
4168 if (cu
->header
.version
== 2)
4169 info_ptr
+= cu
->header
.addr_size
;
4171 info_ptr
+= cu
->header
.offset_size
;
4174 info_ptr
+= cu
->header
.addr_size
;
4181 case DW_FORM_flag_present
:
4196 case DW_FORM_string
:
4197 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4198 info_ptr
+= bytes_read
;
4200 case DW_FORM_sec_offset
:
4202 info_ptr
+= cu
->header
.offset_size
;
4204 case DW_FORM_exprloc
:
4206 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4207 info_ptr
+= bytes_read
;
4209 case DW_FORM_block1
:
4210 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4212 case DW_FORM_block2
:
4213 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4215 case DW_FORM_block4
:
4216 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4220 case DW_FORM_ref_udata
:
4221 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4223 case DW_FORM_indirect
:
4224 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4225 info_ptr
+= bytes_read
;
4226 /* We need to continue parsing from here, so just go back to
4228 goto skip_attribute
;
4231 error (_("Dwarf Error: Cannot handle %s "
4232 "in DWARF reader [in module %s]"),
4233 dwarf_form_name (form
),
4234 bfd_get_filename (abfd
));
4238 if (abbrev
->has_children
)
4239 return skip_children (buffer
, info_ptr
, cu
);
4244 /* Locate ORIG_PDI's sibling.
4245 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4249 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4250 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4251 bfd
*abfd
, struct dwarf2_cu
*cu
)
4253 /* Do we know the sibling already? */
4255 if (orig_pdi
->sibling
)
4256 return orig_pdi
->sibling
;
4258 /* Are there any children to deal with? */
4260 if (!orig_pdi
->has_children
)
4263 /* Skip the children the long way. */
4265 return skip_children (buffer
, info_ptr
, cu
);
4268 /* Expand this partial symbol table into a full symbol table. */
4271 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4277 warning (_("bug: psymtab for %s is already read in."),
4284 printf_filtered (_("Reading in symbols for %s..."),
4286 gdb_flush (gdb_stdout
);
4289 /* Restore our global data. */
4290 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4291 dwarf2_objfile_data_key
);
4293 /* If this psymtab is constructed from a debug-only objfile, the
4294 has_section_at_zero flag will not necessarily be correct. We
4295 can get the correct value for this flag by looking at the data
4296 associated with the (presumably stripped) associated objfile. */
4297 if (pst
->objfile
->separate_debug_objfile_backlink
)
4299 struct dwarf2_per_objfile
*dpo_backlink
4300 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4301 dwarf2_objfile_data_key
);
4303 dwarf2_per_objfile
->has_section_at_zero
4304 = dpo_backlink
->has_section_at_zero
;
4307 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4309 psymtab_to_symtab_1 (pst
);
4311 /* Finish up the debug error message. */
4313 printf_filtered (_("done.\n"));
4318 /* Add PER_CU to the queue. */
4321 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4323 struct dwarf2_queue_item
*item
;
4326 item
= xmalloc (sizeof (*item
));
4327 item
->per_cu
= per_cu
;
4330 if (dwarf2_queue
== NULL
)
4331 dwarf2_queue
= item
;
4333 dwarf2_queue_tail
->next
= item
;
4335 dwarf2_queue_tail
= item
;
4338 /* Process the queue. */
4341 process_queue (struct objfile
*objfile
)
4343 struct dwarf2_queue_item
*item
, *next_item
;
4345 /* The queue starts out with one item, but following a DIE reference
4346 may load a new CU, adding it to the end of the queue. */
4347 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4349 if (dwarf2_per_objfile
->using_index
4350 ? !item
->per_cu
->v
.quick
->symtab
4351 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4352 process_full_comp_unit (item
->per_cu
);
4354 item
->per_cu
->queued
= 0;
4355 next_item
= item
->next
;
4359 dwarf2_queue_tail
= NULL
;
4362 /* Free all allocated queue entries. This function only releases anything if
4363 an error was thrown; if the queue was processed then it would have been
4364 freed as we went along. */
4367 dwarf2_release_queue (void *dummy
)
4369 struct dwarf2_queue_item
*item
, *last
;
4371 item
= dwarf2_queue
;
4374 /* Anything still marked queued is likely to be in an
4375 inconsistent state, so discard it. */
4376 if (item
->per_cu
->queued
)
4378 if (item
->per_cu
->cu
!= NULL
)
4379 free_one_cached_comp_unit (item
->per_cu
->cu
);
4380 item
->per_cu
->queued
= 0;
4388 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4391 /* Read in full symbols for PST, and anything it depends on. */
4394 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4396 struct dwarf2_per_cu_data
*per_cu
;
4397 struct cleanup
*back_to
;
4400 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4401 if (!pst
->dependencies
[i
]->readin
)
4403 /* Inform about additional files that need to be read in. */
4406 /* FIXME: i18n: Need to make this a single string. */
4407 fputs_filtered (" ", gdb_stdout
);
4409 fputs_filtered ("and ", gdb_stdout
);
4411 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4412 wrap_here (""); /* Flush output */
4413 gdb_flush (gdb_stdout
);
4415 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4418 per_cu
= pst
->read_symtab_private
;
4422 /* It's an include file, no symbols to read for it.
4423 Everything is in the parent symtab. */
4428 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4431 /* Load the DIEs associated with PER_CU into memory. */
4434 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
4435 struct objfile
*objfile
)
4437 bfd
*abfd
= objfile
->obfd
;
4438 struct dwarf2_cu
*cu
;
4439 unsigned int offset
;
4440 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4441 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4442 struct attribute
*attr
;
4445 gdb_assert (! per_cu
->from_debug_types
);
4447 /* Set local variables from the partial symbol table info. */
4448 offset
= per_cu
->offset
;
4450 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4451 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4452 beg_of_comp_unit
= info_ptr
;
4454 if (per_cu
->cu
== NULL
)
4456 cu
= xmalloc (sizeof (*cu
));
4457 init_one_comp_unit (cu
, objfile
);
4461 /* If an error occurs while loading, release our storage. */
4462 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4464 /* Read in the comp_unit header. */
4465 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4467 /* Complete the cu_header. */
4468 cu
->header
.offset
= offset
;
4469 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4471 /* Read the abbrevs for this compilation unit. */
4472 dwarf2_read_abbrevs (abfd
, cu
);
4473 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4475 /* Link this compilation unit into the compilation unit tree. */
4477 cu
->per_cu
= per_cu
;
4479 /* Link this CU into read_in_chain. */
4480 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4481 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4486 info_ptr
+= cu
->header
.first_die_offset
;
4489 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4491 /* We try not to read any attributes in this function, because not
4492 all objfiles needed for references have been loaded yet, and symbol
4493 table processing isn't initialized. But we have to set the CU language,
4494 or we won't be able to build types correctly. */
4495 prepare_one_comp_unit (cu
, cu
->dies
);
4497 /* Similarly, if we do not read the producer, we can not apply
4498 producer-specific interpretation. */
4499 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4501 cu
->producer
= DW_STRING (attr
);
4505 do_cleanups (free_abbrevs_cleanup
);
4507 /* We've successfully allocated this compilation unit. Let our
4508 caller clean it up when finished with it. */
4509 discard_cleanups (free_cu_cleanup
);
4513 /* Add a DIE to the delayed physname list. */
4516 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4517 const char *name
, struct die_info
*die
,
4518 struct dwarf2_cu
*cu
)
4520 struct delayed_method_info mi
;
4522 mi
.fnfield_index
= fnfield_index
;
4526 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4529 /* A cleanup for freeing the delayed method list. */
4532 free_delayed_list (void *ptr
)
4534 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4535 if (cu
->method_list
!= NULL
)
4537 VEC_free (delayed_method_info
, cu
->method_list
);
4538 cu
->method_list
= NULL
;
4542 /* Compute the physnames of any methods on the CU's method list.
4544 The computation of method physnames is delayed in order to avoid the
4545 (bad) condition that one of the method's formal parameters is of an as yet
4549 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4552 struct delayed_method_info
*mi
;
4553 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4556 struct fn_fieldlist
*fn_flp
4557 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4558 physname
= (char *) dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4559 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4563 /* Generate full symbol information for PST and CU, whose DIEs have
4564 already been loaded into memory. */
4567 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4569 struct dwarf2_cu
*cu
= per_cu
->cu
;
4570 struct objfile
*objfile
= per_cu
->objfile
;
4571 CORE_ADDR lowpc
, highpc
;
4572 struct symtab
*symtab
;
4573 struct cleanup
*back_to
, *delayed_list_cleanup
;
4576 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4579 back_to
= make_cleanup (really_free_pendings
, NULL
);
4580 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4582 cu
->list_in_scope
= &file_symbols
;
4584 dwarf2_find_base_address (cu
->dies
, cu
);
4586 /* Do line number decoding in read_file_scope () */
4587 process_die (cu
->dies
, cu
);
4589 /* Now that we have processed all the DIEs in the CU, all the types
4590 should be complete, and it should now be safe to compute all of the
4592 compute_delayed_physnames (cu
);
4593 do_cleanups (delayed_list_cleanup
);
4595 /* Some compilers don't define a DW_AT_high_pc attribute for the
4596 compilation unit. If the DW_AT_high_pc is missing, synthesize
4597 it, by scanning the DIE's below the compilation unit. */
4598 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4600 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4602 /* Set symtab language to language from DW_AT_language.
4603 If the compilation is from a C file generated by language preprocessors,
4604 do not set the language if it was already deduced by start_subfile. */
4606 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4608 symtab
->language
= cu
->language
;
4611 if (dwarf2_per_objfile
->using_index
)
4612 per_cu
->v
.quick
->symtab
= symtab
;
4615 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4616 pst
->symtab
= symtab
;
4620 do_cleanups (back_to
);
4623 /* Process a die and its children. */
4626 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4630 case DW_TAG_padding
:
4632 case DW_TAG_compile_unit
:
4633 read_file_scope (die
, cu
);
4635 case DW_TAG_type_unit
:
4636 read_type_unit_scope (die
, cu
);
4638 case DW_TAG_subprogram
:
4639 case DW_TAG_inlined_subroutine
:
4640 read_func_scope (die
, cu
);
4642 case DW_TAG_lexical_block
:
4643 case DW_TAG_try_block
:
4644 case DW_TAG_catch_block
:
4645 read_lexical_block_scope (die
, cu
);
4647 case DW_TAG_class_type
:
4648 case DW_TAG_interface_type
:
4649 case DW_TAG_structure_type
:
4650 case DW_TAG_union_type
:
4651 process_structure_scope (die
, cu
);
4653 case DW_TAG_enumeration_type
:
4654 process_enumeration_scope (die
, cu
);
4657 /* These dies have a type, but processing them does not create
4658 a symbol or recurse to process the children. Therefore we can
4659 read them on-demand through read_type_die. */
4660 case DW_TAG_subroutine_type
:
4661 case DW_TAG_set_type
:
4662 case DW_TAG_array_type
:
4663 case DW_TAG_pointer_type
:
4664 case DW_TAG_ptr_to_member_type
:
4665 case DW_TAG_reference_type
:
4666 case DW_TAG_string_type
:
4669 case DW_TAG_base_type
:
4670 case DW_TAG_subrange_type
:
4671 case DW_TAG_typedef
:
4672 /* Add a typedef symbol for the type definition, if it has a
4674 new_symbol (die
, read_type_die (die
, cu
), cu
);
4676 case DW_TAG_common_block
:
4677 read_common_block (die
, cu
);
4679 case DW_TAG_common_inclusion
:
4681 case DW_TAG_namespace
:
4682 processing_has_namespace_info
= 1;
4683 read_namespace (die
, cu
);
4686 processing_has_namespace_info
= 1;
4687 read_module (die
, cu
);
4689 case DW_TAG_imported_declaration
:
4690 case DW_TAG_imported_module
:
4691 processing_has_namespace_info
= 1;
4692 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4693 || cu
->language
!= language_fortran
))
4694 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4695 dwarf_tag_name (die
->tag
));
4696 read_import_statement (die
, cu
);
4699 new_symbol (die
, NULL
, cu
);
4704 /* A helper function for dwarf2_compute_name which determines whether DIE
4705 needs to have the name of the scope prepended to the name listed in the
4709 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4711 struct attribute
*attr
;
4715 case DW_TAG_namespace
:
4716 case DW_TAG_typedef
:
4717 case DW_TAG_class_type
:
4718 case DW_TAG_interface_type
:
4719 case DW_TAG_structure_type
:
4720 case DW_TAG_union_type
:
4721 case DW_TAG_enumeration_type
:
4722 case DW_TAG_enumerator
:
4723 case DW_TAG_subprogram
:
4727 case DW_TAG_variable
:
4728 case DW_TAG_constant
:
4729 /* We only need to prefix "globally" visible variables. These include
4730 any variable marked with DW_AT_external or any variable that
4731 lives in a namespace. [Variables in anonymous namespaces
4732 require prefixing, but they are not DW_AT_external.] */
4734 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4736 struct dwarf2_cu
*spec_cu
= cu
;
4738 return die_needs_namespace (die_specification (die
, &spec_cu
),
4742 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4743 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4744 && die
->parent
->tag
!= DW_TAG_module
)
4746 /* A variable in a lexical block of some kind does not need a
4747 namespace, even though in C++ such variables may be external
4748 and have a mangled name. */
4749 if (die
->parent
->tag
== DW_TAG_lexical_block
4750 || die
->parent
->tag
== DW_TAG_try_block
4751 || die
->parent
->tag
== DW_TAG_catch_block
4752 || die
->parent
->tag
== DW_TAG_subprogram
)
4761 /* Retrieve the last character from a mem_file. */
4764 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4766 char *last_char_p
= (char *) object
;
4769 *last_char_p
= buffer
[length
- 1];
4772 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4773 compute the physname for the object, which include a method's
4774 formal parameters (C++/Java) and return type (Java).
4776 For Ada, return the DIE's linkage name rather than the fully qualified
4777 name. PHYSNAME is ignored..
4779 The result is allocated on the objfile_obstack and canonicalized. */
4782 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4786 name
= dwarf2_name (die
, cu
);
4788 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4789 compute it by typename_concat inside GDB. */
4790 if (cu
->language
== language_ada
4791 || (cu
->language
== language_fortran
&& physname
))
4793 /* For Ada unit, we prefer the linkage name over the name, as
4794 the former contains the exported name, which the user expects
4795 to be able to reference. Ideally, we want the user to be able
4796 to reference this entity using either natural or linkage name,
4797 but we haven't started looking at this enhancement yet. */
4798 struct attribute
*attr
;
4800 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4802 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4803 if (attr
&& DW_STRING (attr
))
4804 return DW_STRING (attr
);
4807 /* These are the only languages we know how to qualify names in. */
4809 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4810 || cu
->language
== language_fortran
))
4812 if (die_needs_namespace (die
, cu
))
4816 struct ui_file
*buf
;
4818 prefix
= determine_prefix (die
, cu
);
4819 buf
= mem_fileopen ();
4820 if (*prefix
!= '\0')
4822 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4825 fputs_unfiltered (prefixed_name
, buf
);
4826 xfree (prefixed_name
);
4829 fputs_unfiltered (name
? name
: "", buf
);
4831 /* Template parameters may be specified in the DIE's DW_AT_name, or
4832 as children with DW_TAG_template_type_param or
4833 DW_TAG_value_type_param. If the latter, add them to the name
4834 here. If the name already has template parameters, then
4835 skip this step; some versions of GCC emit both, and
4836 it is more efficient to use the pre-computed name.
4838 Something to keep in mind about this process: it is very
4839 unlikely, or in some cases downright impossible, to produce
4840 something that will match the mangled name of a function.
4841 If the definition of the function has the same debug info,
4842 we should be able to match up with it anyway. But fallbacks
4843 using the minimal symbol, for instance to find a method
4844 implemented in a stripped copy of libstdc++, will not work.
4845 If we do not have debug info for the definition, we will have to
4846 match them up some other way.
4848 When we do name matching there is a related problem with function
4849 templates; two instantiated function templates are allowed to
4850 differ only by their return types, which we do not add here. */
4852 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
4854 struct attribute
*attr
;
4855 struct die_info
*child
;
4858 die
->building_fullname
= 1;
4860 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
4865 struct dwarf2_locexpr_baton
*baton
;
4868 if (child
->tag
!= DW_TAG_template_type_param
4869 && child
->tag
!= DW_TAG_template_value_param
)
4874 fputs_unfiltered ("<", buf
);
4878 fputs_unfiltered (", ", buf
);
4880 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
4883 complaint (&symfile_complaints
,
4884 _("template parameter missing DW_AT_type"));
4885 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
4888 type
= die_type (child
, cu
);
4890 if (child
->tag
== DW_TAG_template_type_param
)
4892 c_print_type (type
, "", buf
, -1, 0);
4896 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
4899 complaint (&symfile_complaints
,
4900 _("template parameter missing "
4901 "DW_AT_const_value"));
4902 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
4906 dwarf2_const_value_attr (attr
, type
, name
,
4907 &cu
->comp_unit_obstack
, cu
,
4908 &value
, &bytes
, &baton
);
4910 if (TYPE_NOSIGN (type
))
4911 /* GDB prints characters as NUMBER 'CHAR'. If that's
4912 changed, this can use value_print instead. */
4913 c_printchar (value
, type
, buf
);
4916 struct value_print_options opts
;
4919 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
4923 else if (bytes
!= NULL
)
4925 v
= allocate_value (type
);
4926 memcpy (value_contents_writeable (v
), bytes
,
4927 TYPE_LENGTH (type
));
4930 v
= value_from_longest (type
, value
);
4932 /* Specify decimal so that we do not depend on
4934 get_formatted_print_options (&opts
, 'd');
4936 value_print (v
, buf
, &opts
);
4942 die
->building_fullname
= 0;
4946 /* Close the argument list, with a space if necessary
4947 (nested templates). */
4948 char last_char
= '\0';
4949 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
4950 if (last_char
== '>')
4951 fputs_unfiltered (" >", buf
);
4953 fputs_unfiltered (">", buf
);
4957 /* For Java and C++ methods, append formal parameter type
4958 information, if PHYSNAME. */
4960 if (physname
&& die
->tag
== DW_TAG_subprogram
4961 && (cu
->language
== language_cplus
4962 || cu
->language
== language_java
))
4964 struct type
*type
= read_type_die (die
, cu
);
4966 c_type_print_args (type
, buf
, 0, cu
->language
);
4968 if (cu
->language
== language_java
)
4970 /* For java, we must append the return type to method
4972 if (die
->tag
== DW_TAG_subprogram
)
4973 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
4976 else if (cu
->language
== language_cplus
)
4978 /* Assume that an artificial first parameter is
4979 "this", but do not crash if it is not. RealView
4980 marks unnamed (and thus unused) parameters as
4981 artificial; there is no way to differentiate
4983 if (TYPE_NFIELDS (type
) > 0
4984 && TYPE_FIELD_ARTIFICIAL (type
, 0)
4985 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
4986 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
4988 fputs_unfiltered (" const", buf
);
4992 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
4994 ui_file_delete (buf
);
4996 if (cu
->language
== language_cplus
)
4999 = dwarf2_canonicalize_name (name
, cu
,
5000 &cu
->objfile
->objfile_obstack
);
5011 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5012 If scope qualifiers are appropriate they will be added. The result
5013 will be allocated on the objfile_obstack, or NULL if the DIE does
5014 not have a name. NAME may either be from a previous call to
5015 dwarf2_name or NULL.
5017 The output string will be canonicalized (if C++/Java). */
5020 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5022 return dwarf2_compute_name (name
, die
, cu
, 0);
5025 /* Construct a physname for the given DIE in CU. NAME may either be
5026 from a previous call to dwarf2_name or NULL. The result will be
5027 allocated on the objfile_objstack or NULL if the DIE does not have a
5030 The output string will be canonicalized (if C++/Java). */
5033 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5035 return dwarf2_compute_name (name
, die
, cu
, 1);
5038 /* Read the import statement specified by the given die and record it. */
5041 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5043 struct attribute
*import_attr
;
5044 struct die_info
*imported_die
;
5045 struct dwarf2_cu
*imported_cu
;
5046 const char *imported_name
;
5047 const char *imported_name_prefix
;
5048 const char *canonical_name
;
5049 const char *import_alias
;
5050 const char *imported_declaration
= NULL
;
5051 const char *import_prefix
;
5055 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5056 if (import_attr
== NULL
)
5058 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5059 dwarf_tag_name (die
->tag
));
5064 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5065 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5066 if (imported_name
== NULL
)
5068 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5070 The import in the following code:
5084 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5085 <52> DW_AT_decl_file : 1
5086 <53> DW_AT_decl_line : 6
5087 <54> DW_AT_import : <0x75>
5088 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5090 <5b> DW_AT_decl_file : 1
5091 <5c> DW_AT_decl_line : 2
5092 <5d> DW_AT_type : <0x6e>
5094 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5095 <76> DW_AT_byte_size : 4
5096 <77> DW_AT_encoding : 5 (signed)
5098 imports the wrong die ( 0x75 instead of 0x58 ).
5099 This case will be ignored until the gcc bug is fixed. */
5103 /* Figure out the local name after import. */
5104 import_alias
= dwarf2_name (die
, cu
);
5106 /* Figure out where the statement is being imported to. */
5107 import_prefix
= determine_prefix (die
, cu
);
5109 /* Figure out what the scope of the imported die is and prepend it
5110 to the name of the imported die. */
5111 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5113 if (imported_die
->tag
!= DW_TAG_namespace
5114 && imported_die
->tag
!= DW_TAG_module
)
5116 imported_declaration
= imported_name
;
5117 canonical_name
= imported_name_prefix
;
5119 else if (strlen (imported_name_prefix
) > 0)
5121 temp
= alloca (strlen (imported_name_prefix
)
5122 + 2 + strlen (imported_name
) + 1);
5123 strcpy (temp
, imported_name_prefix
);
5124 strcat (temp
, "::");
5125 strcat (temp
, imported_name
);
5126 canonical_name
= temp
;
5129 canonical_name
= imported_name
;
5131 cp_add_using_directive (import_prefix
,
5134 imported_declaration
,
5135 &cu
->objfile
->objfile_obstack
);
5139 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5141 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5144 /* Cleanup function for read_file_scope. */
5147 free_cu_line_header (void *arg
)
5149 struct dwarf2_cu
*cu
= arg
;
5151 free_line_header (cu
->line_header
);
5152 cu
->line_header
= NULL
;
5156 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5157 char **name
, char **comp_dir
)
5159 struct attribute
*attr
;
5164 /* Find the filename. Do not use dwarf2_name here, since the filename
5165 is not a source language identifier. */
5166 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5169 *name
= DW_STRING (attr
);
5172 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5174 *comp_dir
= DW_STRING (attr
);
5175 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5177 *comp_dir
= ldirname (*name
);
5178 if (*comp_dir
!= NULL
)
5179 make_cleanup (xfree
, *comp_dir
);
5181 if (*comp_dir
!= NULL
)
5183 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5184 directory, get rid of it. */
5185 char *cp
= strchr (*comp_dir
, ':');
5187 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5192 *name
= "<unknown>";
5195 /* Process DW_TAG_compile_unit. */
5198 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5200 struct objfile
*objfile
= cu
->objfile
;
5201 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5202 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5203 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5204 struct attribute
*attr
;
5206 char *comp_dir
= NULL
;
5207 struct die_info
*child_die
;
5208 bfd
*abfd
= objfile
->obfd
;
5209 struct line_header
*line_header
= 0;
5212 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5214 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5216 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5217 from finish_block. */
5218 if (lowpc
== ((CORE_ADDR
) -1))
5223 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5225 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5228 set_cu_language (DW_UNSND (attr
), cu
);
5231 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5233 cu
->producer
= DW_STRING (attr
);
5235 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5236 standardised yet. As a workaround for the language detection we fall
5237 back to the DW_AT_producer string. */
5238 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5239 cu
->language
= language_opencl
;
5241 /* We assume that we're processing GCC output. */
5242 processing_gcc_compilation
= 2;
5244 processing_has_namespace_info
= 0;
5246 start_symtab (name
, comp_dir
, lowpc
);
5247 record_debugformat ("DWARF 2");
5248 record_producer (cu
->producer
);
5250 initialize_cu_func_list (cu
);
5252 /* Decode line number information if present. We do this before
5253 processing child DIEs, so that the line header table is available
5254 for DW_AT_decl_file. */
5255 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5258 unsigned int line_offset
= DW_UNSND (attr
);
5259 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5262 cu
->line_header
= line_header
;
5263 make_cleanup (free_cu_line_header
, cu
);
5264 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5268 /* Process all dies in compilation unit. */
5269 if (die
->child
!= NULL
)
5271 child_die
= die
->child
;
5272 while (child_die
&& child_die
->tag
)
5274 process_die (child_die
, cu
);
5275 child_die
= sibling_die (child_die
);
5279 /* Decode macro information, if present. Dwarf 2 macro information
5280 refers to information in the line number info statement program
5281 header, so we can only read it if we've read the header
5283 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5284 if (attr
&& line_header
)
5286 unsigned int macro_offset
= DW_UNSND (attr
);
5288 dwarf_decode_macros (line_header
, macro_offset
,
5289 comp_dir
, abfd
, cu
);
5291 do_cleanups (back_to
);
5294 /* Process DW_TAG_type_unit.
5295 For TUs we want to skip the first top level sibling if it's not the
5296 actual type being defined by this TU. In this case the first top
5297 level sibling is there to provide context only. */
5300 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5302 struct objfile
*objfile
= cu
->objfile
;
5303 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5305 struct attribute
*attr
;
5307 char *comp_dir
= NULL
;
5308 struct die_info
*child_die
;
5309 bfd
*abfd
= objfile
->obfd
;
5311 /* start_symtab needs a low pc, but we don't really have one.
5312 Do what read_file_scope would do in the absence of such info. */
5313 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5315 /* Find the filename. Do not use dwarf2_name here, since the filename
5316 is not a source language identifier. */
5317 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5319 name
= DW_STRING (attr
);
5321 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5323 comp_dir
= DW_STRING (attr
);
5324 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5326 comp_dir
= ldirname (name
);
5327 if (comp_dir
!= NULL
)
5328 make_cleanup (xfree
, comp_dir
);
5334 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5336 set_cu_language (DW_UNSND (attr
), cu
);
5338 /* This isn't technically needed today. It is done for symmetry
5339 with read_file_scope. */
5340 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5342 cu
->producer
= DW_STRING (attr
);
5344 /* We assume that we're processing GCC output. */
5345 processing_gcc_compilation
= 2;
5347 processing_has_namespace_info
= 0;
5349 start_symtab (name
, comp_dir
, lowpc
);
5350 record_debugformat ("DWARF 2");
5351 record_producer (cu
->producer
);
5353 /* Process the dies in the type unit. */
5354 if (die
->child
== NULL
)
5356 dump_die_for_error (die
);
5357 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5358 bfd_get_filename (abfd
));
5361 child_die
= die
->child
;
5363 while (child_die
&& child_die
->tag
)
5365 process_die (child_die
, cu
);
5367 child_die
= sibling_die (child_die
);
5370 do_cleanups (back_to
);
5374 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5375 struct dwarf2_cu
*cu
)
5377 struct function_range
*thisfn
;
5379 thisfn
= (struct function_range
*)
5380 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5381 thisfn
->name
= name
;
5382 thisfn
->lowpc
= lowpc
;
5383 thisfn
->highpc
= highpc
;
5384 thisfn
->seen_line
= 0;
5385 thisfn
->next
= NULL
;
5387 if (cu
->last_fn
== NULL
)
5388 cu
->first_fn
= thisfn
;
5390 cu
->last_fn
->next
= thisfn
;
5392 cu
->last_fn
= thisfn
;
5395 /* qsort helper for inherit_abstract_dies. */
5398 unsigned_int_compar (const void *ap
, const void *bp
)
5400 unsigned int a
= *(unsigned int *) ap
;
5401 unsigned int b
= *(unsigned int *) bp
;
5403 return (a
> b
) - (b
> a
);
5406 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5407 Inherit only the children of the DW_AT_abstract_origin DIE not being
5408 already referenced by DW_AT_abstract_origin from the children of the
5412 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5414 struct die_info
*child_die
;
5415 unsigned die_children_count
;
5416 /* CU offsets which were referenced by children of the current DIE. */
5418 unsigned *offsets_end
, *offsetp
;
5419 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5420 struct die_info
*origin_die
;
5421 /* Iterator of the ORIGIN_DIE children. */
5422 struct die_info
*origin_child_die
;
5423 struct cleanup
*cleanups
;
5424 struct attribute
*attr
;
5425 struct dwarf2_cu
*origin_cu
;
5426 struct pending
**origin_previous_list_in_scope
;
5428 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5432 /* Note that following die references may follow to a die in a
5436 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5438 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5440 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5441 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5443 if (die
->tag
!= origin_die
->tag
5444 && !(die
->tag
== DW_TAG_inlined_subroutine
5445 && origin_die
->tag
== DW_TAG_subprogram
))
5446 complaint (&symfile_complaints
,
5447 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5448 die
->offset
, origin_die
->offset
);
5450 child_die
= die
->child
;
5451 die_children_count
= 0;
5452 while (child_die
&& child_die
->tag
)
5454 child_die
= sibling_die (child_die
);
5455 die_children_count
++;
5457 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5458 cleanups
= make_cleanup (xfree
, offsets
);
5460 offsets_end
= offsets
;
5461 child_die
= die
->child
;
5462 while (child_die
&& child_die
->tag
)
5464 /* For each CHILD_DIE, find the corresponding child of
5465 ORIGIN_DIE. If there is more than one layer of
5466 DW_AT_abstract_origin, follow them all; there shouldn't be,
5467 but GCC versions at least through 4.4 generate this (GCC PR
5469 struct die_info
*child_origin_die
= child_die
;
5470 struct dwarf2_cu
*child_origin_cu
= cu
;
5474 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5478 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5482 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5483 counterpart may exist. */
5484 if (child_origin_die
!= child_die
)
5486 if (child_die
->tag
!= child_origin_die
->tag
5487 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5488 && child_origin_die
->tag
== DW_TAG_subprogram
))
5489 complaint (&symfile_complaints
,
5490 _("Child DIE 0x%x and its abstract origin 0x%x have "
5491 "different tags"), child_die
->offset
,
5492 child_origin_die
->offset
);
5493 if (child_origin_die
->parent
!= origin_die
)
5494 complaint (&symfile_complaints
,
5495 _("Child DIE 0x%x and its abstract origin 0x%x have "
5496 "different parents"), child_die
->offset
,
5497 child_origin_die
->offset
);
5499 *offsets_end
++ = child_origin_die
->offset
;
5501 child_die
= sibling_die (child_die
);
5503 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5504 unsigned_int_compar
);
5505 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5506 if (offsetp
[-1] == *offsetp
)
5507 complaint (&symfile_complaints
,
5508 _("Multiple children of DIE 0x%x refer "
5509 "to DIE 0x%x as their abstract origin"),
5510 die
->offset
, *offsetp
);
5513 origin_child_die
= origin_die
->child
;
5514 while (origin_child_die
&& origin_child_die
->tag
)
5516 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5517 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5519 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5521 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5522 process_die (origin_child_die
, origin_cu
);
5524 origin_child_die
= sibling_die (origin_child_die
);
5526 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5528 do_cleanups (cleanups
);
5532 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5534 struct objfile
*objfile
= cu
->objfile
;
5535 struct context_stack
*new;
5538 struct die_info
*child_die
;
5539 struct attribute
*attr
, *call_line
, *call_file
;
5542 struct block
*block
;
5543 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5544 VEC (symbolp
) *template_args
= NULL
;
5545 struct template_symbol
*templ_func
= NULL
;
5549 /* If we do not have call site information, we can't show the
5550 caller of this inlined function. That's too confusing, so
5551 only use the scope for local variables. */
5552 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5553 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5554 if (call_line
== NULL
|| call_file
== NULL
)
5556 read_lexical_block_scope (die
, cu
);
5561 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5563 name
= dwarf2_name (die
, cu
);
5565 /* Ignore functions with missing or empty names. These are actually
5566 illegal according to the DWARF standard. */
5569 complaint (&symfile_complaints
,
5570 _("missing name for subprogram DIE at %d"), die
->offset
);
5574 /* Ignore functions with missing or invalid low and high pc attributes. */
5575 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5577 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5578 if (!attr
|| !DW_UNSND (attr
))
5579 complaint (&symfile_complaints
,
5580 _("cannot get low and high bounds "
5581 "for subprogram DIE at %d"),
5589 /* Record the function range for dwarf_decode_lines. */
5590 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5592 /* If we have any template arguments, then we must allocate a
5593 different sort of symbol. */
5594 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5596 if (child_die
->tag
== DW_TAG_template_type_param
5597 || child_die
->tag
== DW_TAG_template_value_param
)
5599 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5600 struct template_symbol
);
5601 templ_func
->base
.is_cplus_template_function
= 1;
5606 new = push_context (0, lowpc
);
5607 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5608 (struct symbol
*) templ_func
);
5610 /* If there is a location expression for DW_AT_frame_base, record
5612 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5614 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5615 expression is being recorded directly in the function's symbol
5616 and not in a separate frame-base object. I guess this hack is
5617 to avoid adding some sort of frame-base adjunct/annex to the
5618 function's symbol :-(. The problem with doing this is that it
5619 results in a function symbol with a location expression that
5620 has nothing to do with the location of the function, ouch! The
5621 relationship should be: a function's symbol has-a frame base; a
5622 frame-base has-a location expression. */
5623 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5625 cu
->list_in_scope
= &local_symbols
;
5627 if (die
->child
!= NULL
)
5629 child_die
= die
->child
;
5630 while (child_die
&& child_die
->tag
)
5632 if (child_die
->tag
== DW_TAG_template_type_param
5633 || child_die
->tag
== DW_TAG_template_value_param
)
5635 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5638 VEC_safe_push (symbolp
, template_args
, arg
);
5641 process_die (child_die
, cu
);
5642 child_die
= sibling_die (child_die
);
5646 inherit_abstract_dies (die
, cu
);
5648 /* If we have a DW_AT_specification, we might need to import using
5649 directives from the context of the specification DIE. See the
5650 comment in determine_prefix. */
5651 if (cu
->language
== language_cplus
5652 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5654 struct dwarf2_cu
*spec_cu
= cu
;
5655 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5659 child_die
= spec_die
->child
;
5660 while (child_die
&& child_die
->tag
)
5662 if (child_die
->tag
== DW_TAG_imported_module
)
5663 process_die (child_die
, spec_cu
);
5664 child_die
= sibling_die (child_die
);
5667 /* In some cases, GCC generates specification DIEs that
5668 themselves contain DW_AT_specification attributes. */
5669 spec_die
= die_specification (spec_die
, &spec_cu
);
5673 new = pop_context ();
5674 /* Make a block for the local symbols within. */
5675 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5676 lowpc
, highpc
, objfile
);
5678 /* For C++, set the block's scope. */
5679 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5680 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5681 determine_prefix (die
, cu
),
5682 processing_has_namespace_info
);
5684 /* If we have address ranges, record them. */
5685 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5687 /* Attach template arguments to function. */
5688 if (! VEC_empty (symbolp
, template_args
))
5690 gdb_assert (templ_func
!= NULL
);
5692 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5693 templ_func
->template_arguments
5694 = obstack_alloc (&objfile
->objfile_obstack
,
5695 (templ_func
->n_template_arguments
5696 * sizeof (struct symbol
*)));
5697 memcpy (templ_func
->template_arguments
,
5698 VEC_address (symbolp
, template_args
),
5699 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5700 VEC_free (symbolp
, template_args
);
5703 /* In C++, we can have functions nested inside functions (e.g., when
5704 a function declares a class that has methods). This means that
5705 when we finish processing a function scope, we may need to go
5706 back to building a containing block's symbol lists. */
5707 local_symbols
= new->locals
;
5708 param_symbols
= new->params
;
5709 using_directives
= new->using_directives
;
5711 /* If we've finished processing a top-level function, subsequent
5712 symbols go in the file symbol list. */
5713 if (outermost_context_p ())
5714 cu
->list_in_scope
= &file_symbols
;
5717 /* Process all the DIES contained within a lexical block scope. Start
5718 a new scope, process the dies, and then close the scope. */
5721 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5723 struct objfile
*objfile
= cu
->objfile
;
5724 struct context_stack
*new;
5725 CORE_ADDR lowpc
, highpc
;
5726 struct die_info
*child_die
;
5729 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5731 /* Ignore blocks with missing or invalid low and high pc attributes. */
5732 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5733 as multiple lexical blocks? Handling children in a sane way would
5734 be nasty. Might be easier to properly extend generic blocks to
5736 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5741 push_context (0, lowpc
);
5742 if (die
->child
!= NULL
)
5744 child_die
= die
->child
;
5745 while (child_die
&& child_die
->tag
)
5747 process_die (child_die
, cu
);
5748 child_die
= sibling_die (child_die
);
5751 new = pop_context ();
5753 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5756 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5759 /* Note that recording ranges after traversing children, as we
5760 do here, means that recording a parent's ranges entails
5761 walking across all its children's ranges as they appear in
5762 the address map, which is quadratic behavior.
5764 It would be nicer to record the parent's ranges before
5765 traversing its children, simply overriding whatever you find
5766 there. But since we don't even decide whether to create a
5767 block until after we've traversed its children, that's hard
5769 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5771 local_symbols
= new->locals
;
5772 using_directives
= new->using_directives
;
5775 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5776 Return 1 if the attributes are present and valid, otherwise, return 0.
5777 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5780 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5781 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5782 struct partial_symtab
*ranges_pst
)
5784 struct objfile
*objfile
= cu
->objfile
;
5785 struct comp_unit_head
*cu_header
= &cu
->header
;
5786 bfd
*obfd
= objfile
->obfd
;
5787 unsigned int addr_size
= cu_header
->addr_size
;
5788 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5789 /* Base address selection entry. */
5800 found_base
= cu
->base_known
;
5801 base
= cu
->base_address
;
5803 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5804 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5806 complaint (&symfile_complaints
,
5807 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5811 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5813 /* Read in the largest possible address. */
5814 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5815 if ((marker
& mask
) == mask
)
5817 /* If we found the largest possible address, then
5818 read the base address. */
5819 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5820 buffer
+= 2 * addr_size
;
5821 offset
+= 2 * addr_size
;
5827 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5831 CORE_ADDR range_beginning
, range_end
;
5833 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5834 buffer
+= addr_size
;
5835 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5836 buffer
+= addr_size
;
5837 offset
+= 2 * addr_size
;
5839 /* An end of list marker is a pair of zero addresses. */
5840 if (range_beginning
== 0 && range_end
== 0)
5841 /* Found the end of list entry. */
5844 /* Each base address selection entry is a pair of 2 values.
5845 The first is the largest possible address, the second is
5846 the base address. Check for a base address here. */
5847 if ((range_beginning
& mask
) == mask
)
5849 /* If we found the largest possible address, then
5850 read the base address. */
5851 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5858 /* We have no valid base address for the ranges
5860 complaint (&symfile_complaints
,
5861 _("Invalid .debug_ranges data (no base address)"));
5865 range_beginning
+= base
;
5868 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
5869 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5870 range_beginning
+ baseaddr
,
5871 range_end
- 1 + baseaddr
,
5874 /* FIXME: This is recording everything as a low-high
5875 segment of consecutive addresses. We should have a
5876 data structure for discontiguous block ranges
5880 low
= range_beginning
;
5886 if (range_beginning
< low
)
5887 low
= range_beginning
;
5888 if (range_end
> high
)
5894 /* If the first entry is an end-of-list marker, the range
5895 describes an empty scope, i.e. no instructions. */
5901 *high_return
= high
;
5905 /* Get low and high pc attributes from a die. Return 1 if the attributes
5906 are present and valid, otherwise, return 0. Return -1 if the range is
5907 discontinuous, i.e. derived from DW_AT_ranges information. */
5909 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5910 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5911 struct partial_symtab
*pst
)
5913 struct attribute
*attr
;
5918 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5921 high
= DW_ADDR (attr
);
5922 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5924 low
= DW_ADDR (attr
);
5926 /* Found high w/o low attribute. */
5929 /* Found consecutive range of addresses. */
5934 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5937 /* Value of the DW_AT_ranges attribute is the offset in the
5938 .debug_ranges section. */
5939 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
5941 /* Found discontinuous range of addresses. */
5949 /* When using the GNU linker, .gnu.linkonce. sections are used to
5950 eliminate duplicate copies of functions and vtables and such.
5951 The linker will arbitrarily choose one and discard the others.
5952 The AT_*_pc values for such functions refer to local labels in
5953 these sections. If the section from that file was discarded, the
5954 labels are not in the output, so the relocs get a value of 0.
5955 If this is a discarded function, mark the pc bounds as invalid,
5956 so that GDB will ignore it. */
5957 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
5965 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
5966 its low and high PC addresses. Do nothing if these addresses could not
5967 be determined. Otherwise, set LOWPC to the low address if it is smaller,
5968 and HIGHPC to the high address if greater than HIGHPC. */
5971 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
5972 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5973 struct dwarf2_cu
*cu
)
5975 CORE_ADDR low
, high
;
5976 struct die_info
*child
= die
->child
;
5978 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
5980 *lowpc
= min (*lowpc
, low
);
5981 *highpc
= max (*highpc
, high
);
5984 /* If the language does not allow nested subprograms (either inside
5985 subprograms or lexical blocks), we're done. */
5986 if (cu
->language
!= language_ada
)
5989 /* Check all the children of the given DIE. If it contains nested
5990 subprograms, then check their pc bounds. Likewise, we need to
5991 check lexical blocks as well, as they may also contain subprogram
5993 while (child
&& child
->tag
)
5995 if (child
->tag
== DW_TAG_subprogram
5996 || child
->tag
== DW_TAG_lexical_block
)
5997 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
5998 child
= sibling_die (child
);
6002 /* Get the low and high pc's represented by the scope DIE, and store
6003 them in *LOWPC and *HIGHPC. If the correct values can't be
6004 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6007 get_scope_pc_bounds (struct die_info
*die
,
6008 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6009 struct dwarf2_cu
*cu
)
6011 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6012 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6013 CORE_ADDR current_low
, current_high
;
6015 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6017 best_low
= current_low
;
6018 best_high
= current_high
;
6022 struct die_info
*child
= die
->child
;
6024 while (child
&& child
->tag
)
6026 switch (child
->tag
) {
6027 case DW_TAG_subprogram
:
6028 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6030 case DW_TAG_namespace
:
6032 /* FIXME: carlton/2004-01-16: Should we do this for
6033 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6034 that current GCC's always emit the DIEs corresponding
6035 to definitions of methods of classes as children of a
6036 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6037 the DIEs giving the declarations, which could be
6038 anywhere). But I don't see any reason why the
6039 standards says that they have to be there. */
6040 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6042 if (current_low
!= ((CORE_ADDR
) -1))
6044 best_low
= min (best_low
, current_low
);
6045 best_high
= max (best_high
, current_high
);
6053 child
= sibling_die (child
);
6058 *highpc
= best_high
;
6061 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6064 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6065 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6067 struct attribute
*attr
;
6069 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6072 CORE_ADDR high
= DW_ADDR (attr
);
6074 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6077 CORE_ADDR low
= DW_ADDR (attr
);
6079 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6083 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6086 bfd
*obfd
= cu
->objfile
->obfd
;
6088 /* The value of the DW_AT_ranges attribute is the offset of the
6089 address range list in the .debug_ranges section. */
6090 unsigned long offset
= DW_UNSND (attr
);
6091 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6093 /* For some target architectures, but not others, the
6094 read_address function sign-extends the addresses it returns.
6095 To recognize base address selection entries, we need a
6097 unsigned int addr_size
= cu
->header
.addr_size
;
6098 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6100 /* The base address, to which the next pair is relative. Note
6101 that this 'base' is a DWARF concept: most entries in a range
6102 list are relative, to reduce the number of relocs against the
6103 debugging information. This is separate from this function's
6104 'baseaddr' argument, which GDB uses to relocate debugging
6105 information from a shared library based on the address at
6106 which the library was loaded. */
6107 CORE_ADDR base
= cu
->base_address
;
6108 int base_known
= cu
->base_known
;
6110 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6111 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6113 complaint (&symfile_complaints
,
6114 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6121 unsigned int bytes_read
;
6122 CORE_ADDR start
, end
;
6124 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6125 buffer
+= bytes_read
;
6126 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6127 buffer
+= bytes_read
;
6129 /* Did we find the end of the range list? */
6130 if (start
== 0 && end
== 0)
6133 /* Did we find a base address selection entry? */
6134 else if ((start
& base_select_mask
) == base_select_mask
)
6140 /* We found an ordinary address range. */
6145 complaint (&symfile_complaints
,
6146 _("Invalid .debug_ranges data "
6147 "(no base address)"));
6151 record_block_range (block
,
6152 baseaddr
+ base
+ start
,
6153 baseaddr
+ base
+ end
- 1);
6159 /* Add an aggregate field to the field list. */
6162 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6163 struct dwarf2_cu
*cu
)
6165 struct objfile
*objfile
= cu
->objfile
;
6166 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6167 struct nextfield
*new_field
;
6168 struct attribute
*attr
;
6170 char *fieldname
= "";
6172 /* Allocate a new field list entry and link it in. */
6173 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6174 make_cleanup (xfree
, new_field
);
6175 memset (new_field
, 0, sizeof (struct nextfield
));
6177 if (die
->tag
== DW_TAG_inheritance
)
6179 new_field
->next
= fip
->baseclasses
;
6180 fip
->baseclasses
= new_field
;
6184 new_field
->next
= fip
->fields
;
6185 fip
->fields
= new_field
;
6189 /* Handle accessibility and virtuality of field.
6190 The default accessibility for members is public, the default
6191 accessibility for inheritance is private. */
6192 if (die
->tag
!= DW_TAG_inheritance
)
6193 new_field
->accessibility
= DW_ACCESS_public
;
6195 new_field
->accessibility
= DW_ACCESS_private
;
6196 new_field
->virtuality
= DW_VIRTUALITY_none
;
6198 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6200 new_field
->accessibility
= DW_UNSND (attr
);
6201 if (new_field
->accessibility
!= DW_ACCESS_public
)
6202 fip
->non_public_fields
= 1;
6203 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6205 new_field
->virtuality
= DW_UNSND (attr
);
6207 fp
= &new_field
->field
;
6209 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6211 /* Data member other than a C++ static data member. */
6213 /* Get type of field. */
6214 fp
->type
= die_type (die
, cu
);
6216 SET_FIELD_BITPOS (*fp
, 0);
6218 /* Get bit size of field (zero if none). */
6219 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6222 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6226 FIELD_BITSIZE (*fp
) = 0;
6229 /* Get bit offset of field. */
6230 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6233 int byte_offset
= 0;
6235 if (attr_form_is_section_offset (attr
))
6236 dwarf2_complex_location_expr_complaint ();
6237 else if (attr_form_is_constant (attr
))
6238 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6239 else if (attr_form_is_block (attr
))
6240 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6242 dwarf2_complex_location_expr_complaint ();
6244 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6246 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6249 if (gdbarch_bits_big_endian (gdbarch
))
6251 /* For big endian bits, the DW_AT_bit_offset gives the
6252 additional bit offset from the MSB of the containing
6253 anonymous object to the MSB of the field. We don't
6254 have to do anything special since we don't need to
6255 know the size of the anonymous object. */
6256 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6260 /* For little endian bits, compute the bit offset to the
6261 MSB of the anonymous object, subtract off the number of
6262 bits from the MSB of the field to the MSB of the
6263 object, and then subtract off the number of bits of
6264 the field itself. The result is the bit offset of
6265 the LSB of the field. */
6267 int bit_offset
= DW_UNSND (attr
);
6269 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6272 /* The size of the anonymous object containing
6273 the bit field is explicit, so use the
6274 indicated size (in bytes). */
6275 anonymous_size
= DW_UNSND (attr
);
6279 /* The size of the anonymous object containing
6280 the bit field must be inferred from the type
6281 attribute of the data member containing the
6283 anonymous_size
= TYPE_LENGTH (fp
->type
);
6285 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6286 - bit_offset
- FIELD_BITSIZE (*fp
);
6290 /* Get name of field. */
6291 fieldname
= dwarf2_name (die
, cu
);
6292 if (fieldname
== NULL
)
6295 /* The name is already allocated along with this objfile, so we don't
6296 need to duplicate it for the type. */
6297 fp
->name
= fieldname
;
6299 /* Change accessibility for artificial fields (e.g. virtual table
6300 pointer or virtual base class pointer) to private. */
6301 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6303 FIELD_ARTIFICIAL (*fp
) = 1;
6304 new_field
->accessibility
= DW_ACCESS_private
;
6305 fip
->non_public_fields
= 1;
6308 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6310 /* C++ static member. */
6312 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6313 is a declaration, but all versions of G++ as of this writing
6314 (so through at least 3.2.1) incorrectly generate
6315 DW_TAG_variable tags. */
6319 /* Get name of field. */
6320 fieldname
= dwarf2_name (die
, cu
);
6321 if (fieldname
== NULL
)
6324 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6326 /* Only create a symbol if this is an external value.
6327 new_symbol checks this and puts the value in the global symbol
6328 table, which we want. If it is not external, new_symbol
6329 will try to put the value in cu->list_in_scope which is wrong. */
6330 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6332 /* A static const member, not much different than an enum as far as
6333 we're concerned, except that we can support more types. */
6334 new_symbol (die
, NULL
, cu
);
6337 /* Get physical name. */
6338 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6340 /* The name is already allocated along with this objfile, so we don't
6341 need to duplicate it for the type. */
6342 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6343 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6344 FIELD_NAME (*fp
) = fieldname
;
6346 else if (die
->tag
== DW_TAG_inheritance
)
6348 /* C++ base class field. */
6349 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6352 int byte_offset
= 0;
6354 if (attr_form_is_section_offset (attr
))
6355 dwarf2_complex_location_expr_complaint ();
6356 else if (attr_form_is_constant (attr
))
6357 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6358 else if (attr_form_is_block (attr
))
6359 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6361 dwarf2_complex_location_expr_complaint ();
6363 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6365 FIELD_BITSIZE (*fp
) = 0;
6366 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6367 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6368 fip
->nbaseclasses
++;
6372 /* Add a typedef defined in the scope of the FIP's class. */
6375 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6376 struct dwarf2_cu
*cu
)
6378 struct objfile
*objfile
= cu
->objfile
;
6379 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6380 struct typedef_field_list
*new_field
;
6381 struct attribute
*attr
;
6382 struct typedef_field
*fp
;
6383 char *fieldname
= "";
6385 /* Allocate a new field list entry and link it in. */
6386 new_field
= xzalloc (sizeof (*new_field
));
6387 make_cleanup (xfree
, new_field
);
6389 gdb_assert (die
->tag
== DW_TAG_typedef
);
6391 fp
= &new_field
->field
;
6393 /* Get name of field. */
6394 fp
->name
= dwarf2_name (die
, cu
);
6395 if (fp
->name
== NULL
)
6398 fp
->type
= read_type_die (die
, cu
);
6400 new_field
->next
= fip
->typedef_field_list
;
6401 fip
->typedef_field_list
= new_field
;
6402 fip
->typedef_field_list_count
++;
6405 /* Create the vector of fields, and attach it to the type. */
6408 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6409 struct dwarf2_cu
*cu
)
6411 int nfields
= fip
->nfields
;
6413 /* Record the field count, allocate space for the array of fields,
6414 and create blank accessibility bitfields if necessary. */
6415 TYPE_NFIELDS (type
) = nfields
;
6416 TYPE_FIELDS (type
) = (struct field
*)
6417 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6418 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6420 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6422 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6424 TYPE_FIELD_PRIVATE_BITS (type
) =
6425 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6426 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6428 TYPE_FIELD_PROTECTED_BITS (type
) =
6429 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6430 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6432 TYPE_FIELD_IGNORE_BITS (type
) =
6433 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6434 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6437 /* If the type has baseclasses, allocate and clear a bit vector for
6438 TYPE_FIELD_VIRTUAL_BITS. */
6439 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6441 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6442 unsigned char *pointer
;
6444 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6445 pointer
= TYPE_ALLOC (type
, num_bytes
);
6446 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6447 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6448 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6451 /* Copy the saved-up fields into the field vector. Start from the head of
6452 the list, adding to the tail of the field array, so that they end up in
6453 the same order in the array in which they were added to the list. */
6454 while (nfields
-- > 0)
6456 struct nextfield
*fieldp
;
6460 fieldp
= fip
->fields
;
6461 fip
->fields
= fieldp
->next
;
6465 fieldp
= fip
->baseclasses
;
6466 fip
->baseclasses
= fieldp
->next
;
6469 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6470 switch (fieldp
->accessibility
)
6472 case DW_ACCESS_private
:
6473 if (cu
->language
!= language_ada
)
6474 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6477 case DW_ACCESS_protected
:
6478 if (cu
->language
!= language_ada
)
6479 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6482 case DW_ACCESS_public
:
6486 /* Unknown accessibility. Complain and treat it as public. */
6488 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6489 fieldp
->accessibility
);
6493 if (nfields
< fip
->nbaseclasses
)
6495 switch (fieldp
->virtuality
)
6497 case DW_VIRTUALITY_virtual
:
6498 case DW_VIRTUALITY_pure_virtual
:
6499 if (cu
->language
== language_ada
)
6500 error ("unexpected virtuality in component of Ada type");
6501 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6508 /* Add a member function to the proper fieldlist. */
6511 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6512 struct type
*type
, struct dwarf2_cu
*cu
)
6514 struct objfile
*objfile
= cu
->objfile
;
6515 struct attribute
*attr
;
6516 struct fnfieldlist
*flp
;
6518 struct fn_field
*fnp
;
6520 struct nextfnfield
*new_fnfield
;
6521 struct type
*this_type
;
6523 if (cu
->language
== language_ada
)
6524 error ("unexpected member function in Ada type");
6526 /* Get name of member function. */
6527 fieldname
= dwarf2_name (die
, cu
);
6528 if (fieldname
== NULL
)
6531 /* Look up member function name in fieldlist. */
6532 for (i
= 0; i
< fip
->nfnfields
; i
++)
6534 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6538 /* Create new list element if necessary. */
6539 if (i
< fip
->nfnfields
)
6540 flp
= &fip
->fnfieldlists
[i
];
6543 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6545 fip
->fnfieldlists
= (struct fnfieldlist
*)
6546 xrealloc (fip
->fnfieldlists
,
6547 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6548 * sizeof (struct fnfieldlist
));
6549 if (fip
->nfnfields
== 0)
6550 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6552 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6553 flp
->name
= fieldname
;
6556 i
= fip
->nfnfields
++;
6559 /* Create a new member function field and chain it to the field list
6561 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6562 make_cleanup (xfree
, new_fnfield
);
6563 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6564 new_fnfield
->next
= flp
->head
;
6565 flp
->head
= new_fnfield
;
6568 /* Fill in the member function field info. */
6569 fnp
= &new_fnfield
->fnfield
;
6571 /* Delay processing of the physname until later. */
6572 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
6574 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
6579 char *physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6580 fnp
->physname
= physname
? physname
: "";
6583 fnp
->type
= alloc_type (objfile
);
6584 this_type
= read_type_die (die
, cu
);
6585 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6587 int nparams
= TYPE_NFIELDS (this_type
);
6589 /* TYPE is the domain of this method, and THIS_TYPE is the type
6590 of the method itself (TYPE_CODE_METHOD). */
6591 smash_to_method_type (fnp
->type
, type
,
6592 TYPE_TARGET_TYPE (this_type
),
6593 TYPE_FIELDS (this_type
),
6594 TYPE_NFIELDS (this_type
),
6595 TYPE_VARARGS (this_type
));
6597 /* Handle static member functions.
6598 Dwarf2 has no clean way to discern C++ static and non-static
6599 member functions. G++ helps GDB by marking the first
6600 parameter for non-static member functions (which is the
6601 this pointer) as artificial. We obtain this information
6602 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6603 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6604 fnp
->voffset
= VOFFSET_STATIC
;
6607 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
6608 dwarf2_full_name (fieldname
, die
, cu
));
6610 /* Get fcontext from DW_AT_containing_type if present. */
6611 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6612 fnp
->fcontext
= die_containing_type (die
, cu
);
6614 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
6615 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6617 /* Get accessibility. */
6618 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6621 switch (DW_UNSND (attr
))
6623 case DW_ACCESS_private
:
6624 fnp
->is_private
= 1;
6626 case DW_ACCESS_protected
:
6627 fnp
->is_protected
= 1;
6632 /* Check for artificial methods. */
6633 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
6634 if (attr
&& DW_UNSND (attr
) != 0)
6635 fnp
->is_artificial
= 1;
6637 /* Get index in virtual function table if it is a virtual member
6638 function. For older versions of GCC, this is an offset in the
6639 appropriate virtual table, as specified by DW_AT_containing_type.
6640 For everyone else, it is an expression to be evaluated relative
6641 to the object address. */
6643 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
6646 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
6648 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
6650 /* Old-style GCC. */
6651 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
6653 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6654 || (DW_BLOCK (attr
)->size
> 1
6655 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
6656 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
6658 struct dwarf_block blk
;
6661 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6663 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
6664 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
6665 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6666 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
6667 dwarf2_complex_location_expr_complaint ();
6669 fnp
->voffset
/= cu
->header
.addr_size
;
6673 dwarf2_complex_location_expr_complaint ();
6676 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
6678 else if (attr_form_is_section_offset (attr
))
6680 dwarf2_complex_location_expr_complaint ();
6684 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6690 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6691 if (attr
&& DW_UNSND (attr
))
6693 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6694 complaint (&symfile_complaints
,
6695 _("Member function \"%s\" (offset %d) is virtual "
6696 "but the vtable offset is not specified"),
6697 fieldname
, die
->offset
);
6698 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6699 TYPE_CPLUS_DYNAMIC (type
) = 1;
6704 /* Create the vector of member function fields, and attach it to the type. */
6707 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6708 struct dwarf2_cu
*cu
)
6710 struct fnfieldlist
*flp
;
6711 int total_length
= 0;
6714 if (cu
->language
== language_ada
)
6715 error ("unexpected member functions in Ada type");
6717 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6718 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6719 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6721 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6723 struct nextfnfield
*nfp
= flp
->head
;
6724 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6727 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6728 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6729 fn_flp
->fn_fields
= (struct fn_field
*)
6730 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6731 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6732 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6734 total_length
+= flp
->length
;
6737 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6738 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6741 /* Returns non-zero if NAME is the name of a vtable member in CU's
6742 language, zero otherwise. */
6744 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6746 static const char vptr
[] = "_vptr";
6747 static const char vtable
[] = "vtable";
6749 /* Look for the C++ and Java forms of the vtable. */
6750 if ((cu
->language
== language_java
6751 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6752 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6753 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6759 /* GCC outputs unnamed structures that are really pointers to member
6760 functions, with the ABI-specified layout. If TYPE describes
6761 such a structure, smash it into a member function type.
6763 GCC shouldn't do this; it should just output pointer to member DIEs.
6764 This is GCC PR debug/28767. */
6767 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6769 struct type
*pfn_type
, *domain_type
, *new_type
;
6771 /* Check for a structure with no name and two children. */
6772 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6775 /* Check for __pfn and __delta members. */
6776 if (TYPE_FIELD_NAME (type
, 0) == NULL
6777 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6778 || TYPE_FIELD_NAME (type
, 1) == NULL
6779 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6782 /* Find the type of the method. */
6783 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6784 if (pfn_type
== NULL
6785 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6786 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6789 /* Look for the "this" argument. */
6790 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6791 if (TYPE_NFIELDS (pfn_type
) == 0
6792 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6793 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6796 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6797 new_type
= alloc_type (objfile
);
6798 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6799 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6800 TYPE_VARARGS (pfn_type
));
6801 smash_to_methodptr_type (type
, new_type
);
6804 /* Called when we find the DIE that starts a structure or union scope
6805 (definition) to create a type for the structure or union. Fill in
6806 the type's name and general properties; the members will not be
6807 processed until process_structure_type.
6809 NOTE: we need to call these functions regardless of whether or not the
6810 DIE has a DW_AT_name attribute, since it might be an anonymous
6811 structure or union. This gets the type entered into our set of
6814 However, if the structure is incomplete (an opaque struct/union)
6815 then suppress creating a symbol table entry for it since gdb only
6816 wants to find the one with the complete definition. Note that if
6817 it is complete, we just call new_symbol, which does it's own
6818 checking about whether the struct/union is anonymous or not (and
6819 suppresses creating a symbol table entry itself). */
6821 static struct type
*
6822 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6824 struct objfile
*objfile
= cu
->objfile
;
6826 struct attribute
*attr
;
6829 /* If the definition of this type lives in .debug_types, read that type.
6830 Don't follow DW_AT_specification though, that will take us back up
6831 the chain and we want to go down. */
6832 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6835 struct dwarf2_cu
*type_cu
= cu
;
6836 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6838 /* We could just recurse on read_structure_type, but we need to call
6839 get_die_type to ensure only one type for this DIE is created.
6840 This is important, for example, because for c++ classes we need
6841 TYPE_NAME set which is only done by new_symbol. Blech. */
6842 type
= read_type_die (type_die
, type_cu
);
6844 /* TYPE_CU may not be the same as CU.
6845 Ensure TYPE is recorded in CU's type_hash table. */
6846 return set_die_type (die
, type
, cu
);
6849 type
= alloc_type (objfile
);
6850 INIT_CPLUS_SPECIFIC (type
);
6852 name
= dwarf2_name (die
, cu
);
6855 if (cu
->language
== language_cplus
6856 || cu
->language
== language_java
)
6858 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
6860 /* dwarf2_full_name might have already finished building the DIE's
6861 type. If so, there is no need to continue. */
6862 if (get_die_type (die
, cu
) != NULL
)
6863 return get_die_type (die
, cu
);
6865 TYPE_TAG_NAME (type
) = full_name
;
6866 if (die
->tag
== DW_TAG_structure_type
6867 || die
->tag
== DW_TAG_class_type
)
6868 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6872 /* The name is already allocated along with this objfile, so
6873 we don't need to duplicate it for the type. */
6874 TYPE_TAG_NAME (type
) = (char *) name
;
6875 if (die
->tag
== DW_TAG_class_type
)
6876 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6880 if (die
->tag
== DW_TAG_structure_type
)
6882 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
6884 else if (die
->tag
== DW_TAG_union_type
)
6886 TYPE_CODE (type
) = TYPE_CODE_UNION
;
6890 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
6893 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
6894 TYPE_DECLARED_CLASS (type
) = 1;
6896 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6899 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6903 TYPE_LENGTH (type
) = 0;
6906 TYPE_STUB_SUPPORTED (type
) = 1;
6907 if (die_is_declaration (die
, cu
))
6908 TYPE_STUB (type
) = 1;
6909 else if (attr
== NULL
&& die
->child
== NULL
6910 && producer_is_realview (cu
->producer
))
6911 /* RealView does not output the required DW_AT_declaration
6912 on incomplete types. */
6913 TYPE_STUB (type
) = 1;
6915 /* We need to add the type field to the die immediately so we don't
6916 infinitely recurse when dealing with pointers to the structure
6917 type within the structure itself. */
6918 set_die_type (die
, type
, cu
);
6920 /* set_die_type should be already done. */
6921 set_descriptive_type (type
, die
, cu
);
6926 /* Finish creating a structure or union type, including filling in
6927 its members and creating a symbol for it. */
6930 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6932 struct objfile
*objfile
= cu
->objfile
;
6933 struct die_info
*child_die
= die
->child
;
6936 type
= get_die_type (die
, cu
);
6938 type
= read_structure_type (die
, cu
);
6940 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
6942 struct field_info fi
;
6943 struct die_info
*child_die
;
6944 VEC (symbolp
) *template_args
= NULL
;
6945 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6947 memset (&fi
, 0, sizeof (struct field_info
));
6949 child_die
= die
->child
;
6951 while (child_die
&& child_die
->tag
)
6953 if (child_die
->tag
== DW_TAG_member
6954 || child_die
->tag
== DW_TAG_variable
)
6956 /* NOTE: carlton/2002-11-05: A C++ static data member
6957 should be a DW_TAG_member that is a declaration, but
6958 all versions of G++ as of this writing (so through at
6959 least 3.2.1) incorrectly generate DW_TAG_variable
6960 tags for them instead. */
6961 dwarf2_add_field (&fi
, child_die
, cu
);
6963 else if (child_die
->tag
== DW_TAG_subprogram
)
6965 /* C++ member function. */
6966 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
6968 else if (child_die
->tag
== DW_TAG_inheritance
)
6970 /* C++ base class field. */
6971 dwarf2_add_field (&fi
, child_die
, cu
);
6973 else if (child_die
->tag
== DW_TAG_typedef
)
6974 dwarf2_add_typedef (&fi
, child_die
, cu
);
6975 else if (child_die
->tag
== DW_TAG_template_type_param
6976 || child_die
->tag
== DW_TAG_template_value_param
)
6978 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6981 VEC_safe_push (symbolp
, template_args
, arg
);
6984 child_die
= sibling_die (child_die
);
6987 /* Attach template arguments to type. */
6988 if (! VEC_empty (symbolp
, template_args
))
6990 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6991 TYPE_N_TEMPLATE_ARGUMENTS (type
)
6992 = VEC_length (symbolp
, template_args
);
6993 TYPE_TEMPLATE_ARGUMENTS (type
)
6994 = obstack_alloc (&objfile
->objfile_obstack
,
6995 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6996 * sizeof (struct symbol
*)));
6997 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
6998 VEC_address (symbolp
, template_args
),
6999 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7000 * sizeof (struct symbol
*)));
7001 VEC_free (symbolp
, template_args
);
7004 /* Attach fields and member functions to the type. */
7006 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7009 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7011 /* Get the type which refers to the base class (possibly this
7012 class itself) which contains the vtable pointer for the current
7013 class from the DW_AT_containing_type attribute. This use of
7014 DW_AT_containing_type is a GNU extension. */
7016 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7018 struct type
*t
= die_containing_type (die
, cu
);
7020 TYPE_VPTR_BASETYPE (type
) = t
;
7025 /* Our own class provides vtbl ptr. */
7026 for (i
= TYPE_NFIELDS (t
) - 1;
7027 i
>= TYPE_N_BASECLASSES (t
);
7030 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7032 if (is_vtable_name (fieldname
, cu
))
7034 TYPE_VPTR_FIELDNO (type
) = i
;
7039 /* Complain if virtual function table field not found. */
7040 if (i
< TYPE_N_BASECLASSES (t
))
7041 complaint (&symfile_complaints
,
7042 _("virtual function table pointer "
7043 "not found when defining class '%s'"),
7044 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7049 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7052 else if (cu
->producer
7053 && strncmp (cu
->producer
,
7054 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7056 /* The IBM XLC compiler does not provide direct indication
7057 of the containing type, but the vtable pointer is
7058 always named __vfp. */
7062 for (i
= TYPE_NFIELDS (type
) - 1;
7063 i
>= TYPE_N_BASECLASSES (type
);
7066 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7068 TYPE_VPTR_FIELDNO (type
) = i
;
7069 TYPE_VPTR_BASETYPE (type
) = type
;
7076 /* Copy fi.typedef_field_list linked list elements content into the
7077 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7078 if (fi
.typedef_field_list
)
7080 int i
= fi
.typedef_field_list_count
;
7082 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7083 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7084 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7085 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7087 /* Reverse the list order to keep the debug info elements order. */
7090 struct typedef_field
*dest
, *src
;
7092 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7093 src
= &fi
.typedef_field_list
->field
;
7094 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7099 do_cleanups (back_to
);
7102 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
7104 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7105 snapshots) has been known to create a die giving a declaration
7106 for a class that has, as a child, a die giving a definition for a
7107 nested class. So we have to process our children even if the
7108 current die is a declaration. Normally, of course, a declaration
7109 won't have any children at all. */
7111 while (child_die
!= NULL
&& child_die
->tag
)
7113 if (child_die
->tag
== DW_TAG_member
7114 || child_die
->tag
== DW_TAG_variable
7115 || child_die
->tag
== DW_TAG_inheritance
7116 || child_die
->tag
== DW_TAG_template_value_param
7117 || child_die
->tag
== DW_TAG_template_type_param
)
7122 process_die (child_die
, cu
);
7124 child_die
= sibling_die (child_die
);
7127 /* Do not consider external references. According to the DWARF standard,
7128 these DIEs are identified by the fact that they have no byte_size
7129 attribute, and a declaration attribute. */
7130 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7131 || !die_is_declaration (die
, cu
))
7132 new_symbol (die
, type
, cu
);
7135 /* Given a DW_AT_enumeration_type die, set its type. We do not
7136 complete the type's fields yet, or create any symbols. */
7138 static struct type
*
7139 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7141 struct objfile
*objfile
= cu
->objfile
;
7143 struct attribute
*attr
;
7146 /* If the definition of this type lives in .debug_types, read that type.
7147 Don't follow DW_AT_specification though, that will take us back up
7148 the chain and we want to go down. */
7149 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7152 struct dwarf2_cu
*type_cu
= cu
;
7153 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7155 type
= read_type_die (type_die
, type_cu
);
7157 /* TYPE_CU may not be the same as CU.
7158 Ensure TYPE is recorded in CU's type_hash table. */
7159 return set_die_type (die
, type
, cu
);
7162 type
= alloc_type (objfile
);
7164 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7165 name
= dwarf2_full_name (NULL
, die
, cu
);
7167 TYPE_TAG_NAME (type
) = (char *) name
;
7169 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7172 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7176 TYPE_LENGTH (type
) = 0;
7179 /* The enumeration DIE can be incomplete. In Ada, any type can be
7180 declared as private in the package spec, and then defined only
7181 inside the package body. Such types are known as Taft Amendment
7182 Types. When another package uses such a type, an incomplete DIE
7183 may be generated by the compiler. */
7184 if (die_is_declaration (die
, cu
))
7185 TYPE_STUB (type
) = 1;
7187 return set_die_type (die
, type
, cu
);
7190 /* Given a pointer to a die which begins an enumeration, process all
7191 the dies that define the members of the enumeration, and create the
7192 symbol for the enumeration type.
7194 NOTE: We reverse the order of the element list. */
7197 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7199 struct type
*this_type
;
7201 this_type
= get_die_type (die
, cu
);
7202 if (this_type
== NULL
)
7203 this_type
= read_enumeration_type (die
, cu
);
7205 if (die
->child
!= NULL
)
7207 struct die_info
*child_die
;
7209 struct field
*fields
= NULL
;
7211 int unsigned_enum
= 1;
7214 child_die
= die
->child
;
7215 while (child_die
&& child_die
->tag
)
7217 if (child_die
->tag
!= DW_TAG_enumerator
)
7219 process_die (child_die
, cu
);
7223 name
= dwarf2_name (child_die
, cu
);
7226 sym
= new_symbol (child_die
, this_type
, cu
);
7227 if (SYMBOL_VALUE (sym
) < 0)
7230 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7232 fields
= (struct field
*)
7234 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7235 * sizeof (struct field
));
7238 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7239 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7240 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7241 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7247 child_die
= sibling_die (child_die
);
7252 TYPE_NFIELDS (this_type
) = num_fields
;
7253 TYPE_FIELDS (this_type
) = (struct field
*)
7254 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7255 memcpy (TYPE_FIELDS (this_type
), fields
,
7256 sizeof (struct field
) * num_fields
);
7260 TYPE_UNSIGNED (this_type
) = 1;
7263 new_symbol (die
, this_type
, cu
);
7266 /* Extract all information from a DW_TAG_array_type DIE and put it in
7267 the DIE's type field. For now, this only handles one dimensional
7270 static struct type
*
7271 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7273 struct objfile
*objfile
= cu
->objfile
;
7274 struct die_info
*child_die
;
7276 struct type
*element_type
, *range_type
, *index_type
;
7277 struct type
**range_types
= NULL
;
7278 struct attribute
*attr
;
7280 struct cleanup
*back_to
;
7283 element_type
= die_type (die
, cu
);
7285 /* The die_type call above may have already set the type for this DIE. */
7286 type
= get_die_type (die
, cu
);
7290 /* Irix 6.2 native cc creates array types without children for
7291 arrays with unspecified length. */
7292 if (die
->child
== NULL
)
7294 index_type
= objfile_type (objfile
)->builtin_int
;
7295 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7296 type
= create_array_type (NULL
, element_type
, range_type
);
7297 return set_die_type (die
, type
, cu
);
7300 back_to
= make_cleanup (null_cleanup
, NULL
);
7301 child_die
= die
->child
;
7302 while (child_die
&& child_die
->tag
)
7304 if (child_die
->tag
== DW_TAG_subrange_type
)
7306 struct type
*child_type
= read_type_die (child_die
, cu
);
7308 if (child_type
!= NULL
)
7310 /* The range type was succesfully read. Save it for
7311 the array type creation. */
7312 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7314 range_types
= (struct type
**)
7315 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7316 * sizeof (struct type
*));
7318 make_cleanup (free_current_contents
, &range_types
);
7320 range_types
[ndim
++] = child_type
;
7323 child_die
= sibling_die (child_die
);
7326 /* Dwarf2 dimensions are output from left to right, create the
7327 necessary array types in backwards order. */
7329 type
= element_type
;
7331 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7336 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7341 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7344 /* Understand Dwarf2 support for vector types (like they occur on
7345 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7346 array type. This is not part of the Dwarf2/3 standard yet, but a
7347 custom vendor extension. The main difference between a regular
7348 array and the vector variant is that vectors are passed by value
7350 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7352 make_vector_type (type
);
7354 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7355 implementation may choose to implement triple vectors using this
7357 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7360 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
7361 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7363 complaint (&symfile_complaints
,
7364 _("DW_AT_byte_size for array type smaller "
7365 "than the total size of elements"));
7368 name
= dwarf2_name (die
, cu
);
7370 TYPE_NAME (type
) = name
;
7372 /* Install the type in the die. */
7373 set_die_type (die
, type
, cu
);
7375 /* set_die_type should be already done. */
7376 set_descriptive_type (type
, die
, cu
);
7378 do_cleanups (back_to
);
7383 static enum dwarf_array_dim_ordering
7384 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7386 struct attribute
*attr
;
7388 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7390 if (attr
) return DW_SND (attr
);
7393 GNU F77 is a special case, as at 08/2004 array type info is the
7394 opposite order to the dwarf2 specification, but data is still
7395 laid out as per normal fortran.
7397 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7401 if (cu
->language
== language_fortran
7402 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7404 return DW_ORD_row_major
;
7407 switch (cu
->language_defn
->la_array_ordering
)
7409 case array_column_major
:
7410 return DW_ORD_col_major
;
7411 case array_row_major
:
7413 return DW_ORD_row_major
;
7417 /* Extract all information from a DW_TAG_set_type DIE and put it in
7418 the DIE's type field. */
7420 static struct type
*
7421 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7423 struct type
*domain_type
, *set_type
;
7424 struct attribute
*attr
;
7426 domain_type
= die_type (die
, cu
);
7428 /* The die_type call above may have already set the type for this DIE. */
7429 set_type
= get_die_type (die
, cu
);
7433 set_type
= create_set_type (NULL
, domain_type
);
7435 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7437 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7439 return set_die_type (die
, set_type
, cu
);
7442 /* First cut: install each common block member as a global variable. */
7445 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7447 struct die_info
*child_die
;
7448 struct attribute
*attr
;
7450 CORE_ADDR base
= (CORE_ADDR
) 0;
7452 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7455 /* Support the .debug_loc offsets */
7456 if (attr_form_is_block (attr
))
7458 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7460 else if (attr_form_is_section_offset (attr
))
7462 dwarf2_complex_location_expr_complaint ();
7466 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7467 "common block member");
7470 if (die
->child
!= NULL
)
7472 child_die
= die
->child
;
7473 while (child_die
&& child_die
->tag
)
7475 sym
= new_symbol (child_die
, NULL
, cu
);
7476 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
7477 if (sym
!= NULL
&& attr
!= NULL
)
7479 CORE_ADDR byte_offset
= 0;
7481 if (attr_form_is_section_offset (attr
))
7482 dwarf2_complex_location_expr_complaint ();
7483 else if (attr_form_is_constant (attr
))
7484 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
7485 else if (attr_form_is_block (attr
))
7486 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7488 dwarf2_complex_location_expr_complaint ();
7490 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
7491 add_symbol_to_list (sym
, &global_symbols
);
7493 child_die
= sibling_die (child_die
);
7498 /* Create a type for a C++ namespace. */
7500 static struct type
*
7501 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7503 struct objfile
*objfile
= cu
->objfile
;
7504 const char *previous_prefix
, *name
;
7508 /* For extensions, reuse the type of the original namespace. */
7509 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7511 struct die_info
*ext_die
;
7512 struct dwarf2_cu
*ext_cu
= cu
;
7514 ext_die
= dwarf2_extension (die
, &ext_cu
);
7515 type
= read_type_die (ext_die
, ext_cu
);
7517 /* EXT_CU may not be the same as CU.
7518 Ensure TYPE is recorded in CU's type_hash table. */
7519 return set_die_type (die
, type
, cu
);
7522 name
= namespace_name (die
, &is_anonymous
, cu
);
7524 /* Now build the name of the current namespace. */
7526 previous_prefix
= determine_prefix (die
, cu
);
7527 if (previous_prefix
[0] != '\0')
7528 name
= typename_concat (&objfile
->objfile_obstack
,
7529 previous_prefix
, name
, 0, cu
);
7531 /* Create the type. */
7532 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7534 TYPE_NAME (type
) = (char *) name
;
7535 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7537 return set_die_type (die
, type
, cu
);
7540 /* Read a C++ namespace. */
7543 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7545 struct objfile
*objfile
= cu
->objfile
;
7549 /* Add a symbol associated to this if we haven't seen the namespace
7550 before. Also, add a using directive if it's an anonymous
7553 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7557 type
= read_type_die (die
, cu
);
7558 new_symbol (die
, type
, cu
);
7560 name
= namespace_name (die
, &is_anonymous
, cu
);
7563 const char *previous_prefix
= determine_prefix (die
, cu
);
7565 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7566 NULL
, &objfile
->objfile_obstack
);
7570 if (die
->child
!= NULL
)
7572 struct die_info
*child_die
= die
->child
;
7574 while (child_die
&& child_die
->tag
)
7576 process_die (child_die
, cu
);
7577 child_die
= sibling_die (child_die
);
7582 /* Read a Fortran module as type. This DIE can be only a declaration used for
7583 imported module. Still we need that type as local Fortran "use ... only"
7584 declaration imports depend on the created type in determine_prefix. */
7586 static struct type
*
7587 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7589 struct objfile
*objfile
= cu
->objfile
;
7593 module_name
= dwarf2_name (die
, cu
);
7595 complaint (&symfile_complaints
,
7596 _("DW_TAG_module has no name, offset 0x%x"),
7598 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7600 /* determine_prefix uses TYPE_TAG_NAME. */
7601 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7603 return set_die_type (die
, type
, cu
);
7606 /* Read a Fortran module. */
7609 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7611 struct die_info
*child_die
= die
->child
;
7613 while (child_die
&& child_die
->tag
)
7615 process_die (child_die
, cu
);
7616 child_die
= sibling_die (child_die
);
7620 /* Return the name of the namespace represented by DIE. Set
7621 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7625 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
7627 struct die_info
*current_die
;
7628 const char *name
= NULL
;
7630 /* Loop through the extensions until we find a name. */
7632 for (current_die
= die
;
7633 current_die
!= NULL
;
7634 current_die
= dwarf2_extension (die
, &cu
))
7636 name
= dwarf2_name (current_die
, cu
);
7641 /* Is it an anonymous namespace? */
7643 *is_anonymous
= (name
== NULL
);
7645 name
= "(anonymous namespace)";
7650 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7651 the user defined type vector. */
7653 static struct type
*
7654 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7656 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7657 struct comp_unit_head
*cu_header
= &cu
->header
;
7659 struct attribute
*attr_byte_size
;
7660 struct attribute
*attr_address_class
;
7661 int byte_size
, addr_class
;
7662 struct type
*target_type
;
7664 target_type
= die_type (die
, cu
);
7666 /* The die_type call above may have already set the type for this DIE. */
7667 type
= get_die_type (die
, cu
);
7671 type
= lookup_pointer_type (target_type
);
7673 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7675 byte_size
= DW_UNSND (attr_byte_size
);
7677 byte_size
= cu_header
->addr_size
;
7679 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
7680 if (attr_address_class
)
7681 addr_class
= DW_UNSND (attr_address_class
);
7683 addr_class
= DW_ADDR_none
;
7685 /* If the pointer size or address class is different than the
7686 default, create a type variant marked as such and set the
7687 length accordingly. */
7688 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
7690 if (gdbarch_address_class_type_flags_p (gdbarch
))
7694 type_flags
= gdbarch_address_class_type_flags
7695 (gdbarch
, byte_size
, addr_class
);
7696 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
7698 type
= make_type_with_address_space (type
, type_flags
);
7700 else if (TYPE_LENGTH (type
) != byte_size
)
7702 complaint (&symfile_complaints
,
7703 _("invalid pointer size %d"), byte_size
);
7707 /* Should we also complain about unhandled address classes? */
7711 TYPE_LENGTH (type
) = byte_size
;
7712 return set_die_type (die
, type
, cu
);
7715 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7716 the user defined type vector. */
7718 static struct type
*
7719 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7722 struct type
*to_type
;
7723 struct type
*domain
;
7725 to_type
= die_type (die
, cu
);
7726 domain
= die_containing_type (die
, cu
);
7728 /* The calls above may have already set the type for this DIE. */
7729 type
= get_die_type (die
, cu
);
7733 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
7734 type
= lookup_methodptr_type (to_type
);
7736 type
= lookup_memberptr_type (to_type
, domain
);
7738 return set_die_type (die
, type
, cu
);
7741 /* Extract all information from a DW_TAG_reference_type DIE and add to
7742 the user defined type vector. */
7744 static struct type
*
7745 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7747 struct comp_unit_head
*cu_header
= &cu
->header
;
7748 struct type
*type
, *target_type
;
7749 struct attribute
*attr
;
7751 target_type
= die_type (die
, cu
);
7753 /* The die_type call above may have already set the type for this DIE. */
7754 type
= get_die_type (die
, cu
);
7758 type
= lookup_reference_type (target_type
);
7759 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7762 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7766 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7768 return set_die_type (die
, type
, cu
);
7771 static struct type
*
7772 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7774 struct type
*base_type
, *cv_type
;
7776 base_type
= die_type (die
, cu
);
7778 /* The die_type call above may have already set the type for this DIE. */
7779 cv_type
= get_die_type (die
, cu
);
7783 /* In case the const qualifier is applied to an array type, the element type
7784 is so qualified, not the array type (section 6.7.3 of C99). */
7785 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
7787 struct type
*el_type
, *inner_array
;
7789 base_type
= copy_type (base_type
);
7790 inner_array
= base_type
;
7792 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
7794 TYPE_TARGET_TYPE (inner_array
) =
7795 copy_type (TYPE_TARGET_TYPE (inner_array
));
7796 inner_array
= TYPE_TARGET_TYPE (inner_array
);
7799 el_type
= TYPE_TARGET_TYPE (inner_array
);
7800 TYPE_TARGET_TYPE (inner_array
) =
7801 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
7803 return set_die_type (die
, base_type
, cu
);
7806 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7807 return set_die_type (die
, cv_type
, cu
);
7810 static struct type
*
7811 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7813 struct type
*base_type
, *cv_type
;
7815 base_type
= die_type (die
, cu
);
7817 /* The die_type call above may have already set the type for this DIE. */
7818 cv_type
= get_die_type (die
, cu
);
7822 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7823 return set_die_type (die
, cv_type
, cu
);
7826 /* Extract all information from a DW_TAG_string_type DIE and add to
7827 the user defined type vector. It isn't really a user defined type,
7828 but it behaves like one, with other DIE's using an AT_user_def_type
7829 attribute to reference it. */
7831 static struct type
*
7832 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7834 struct objfile
*objfile
= cu
->objfile
;
7835 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7836 struct type
*type
, *range_type
, *index_type
, *char_type
;
7837 struct attribute
*attr
;
7838 unsigned int length
;
7840 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7843 length
= DW_UNSND (attr
);
7847 /* check for the DW_AT_byte_size attribute */
7848 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7851 length
= DW_UNSND (attr
);
7859 index_type
= objfile_type (objfile
)->builtin_int
;
7860 range_type
= create_range_type (NULL
, index_type
, 1, length
);
7861 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
7862 type
= create_string_type (NULL
, char_type
, range_type
);
7864 return set_die_type (die
, type
, cu
);
7867 /* Handle DIES due to C code like:
7871 int (*funcp)(int a, long l);
7875 ('funcp' generates a DW_TAG_subroutine_type DIE)
7878 static struct type
*
7879 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7881 struct type
*type
; /* Type that this function returns */
7882 struct type
*ftype
; /* Function that returns above type */
7883 struct attribute
*attr
;
7885 type
= die_type (die
, cu
);
7887 /* The die_type call above may have already set the type for this DIE. */
7888 ftype
= get_die_type (die
, cu
);
7892 ftype
= lookup_function_type (type
);
7894 /* All functions in C++, Pascal and Java have prototypes. */
7895 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
7896 if ((attr
&& (DW_UNSND (attr
) != 0))
7897 || cu
->language
== language_cplus
7898 || cu
->language
== language_java
7899 || cu
->language
== language_pascal
)
7900 TYPE_PROTOTYPED (ftype
) = 1;
7901 else if (producer_is_realview (cu
->producer
))
7902 /* RealView does not emit DW_AT_prototyped. We can not
7903 distinguish prototyped and unprototyped functions; default to
7904 prototyped, since that is more common in modern code (and
7905 RealView warns about unprototyped functions). */
7906 TYPE_PROTOTYPED (ftype
) = 1;
7908 /* Store the calling convention in the type if it's available in
7909 the subroutine die. Otherwise set the calling convention to
7910 the default value DW_CC_normal. */
7911 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
7912 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
7914 /* We need to add the subroutine type to the die immediately so
7915 we don't infinitely recurse when dealing with parameters
7916 declared as the same subroutine type. */
7917 set_die_type (die
, ftype
, cu
);
7919 if (die
->child
!= NULL
)
7921 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
7922 struct die_info
*child_die
;
7923 int nparams
, iparams
;
7925 /* Count the number of parameters.
7926 FIXME: GDB currently ignores vararg functions, but knows about
7927 vararg member functions. */
7929 child_die
= die
->child
;
7930 while (child_die
&& child_die
->tag
)
7932 if (child_die
->tag
== DW_TAG_formal_parameter
)
7934 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
7935 TYPE_VARARGS (ftype
) = 1;
7936 child_die
= sibling_die (child_die
);
7939 /* Allocate storage for parameters and fill them in. */
7940 TYPE_NFIELDS (ftype
) = nparams
;
7941 TYPE_FIELDS (ftype
) = (struct field
*)
7942 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
7944 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7945 even if we error out during the parameters reading below. */
7946 for (iparams
= 0; iparams
< nparams
; iparams
++)
7947 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
7950 child_die
= die
->child
;
7951 while (child_die
&& child_die
->tag
)
7953 if (child_die
->tag
== DW_TAG_formal_parameter
)
7955 struct type
*arg_type
;
7957 /* DWARF version 2 has no clean way to discern C++
7958 static and non-static member functions. G++ helps
7959 GDB by marking the first parameter for non-static
7960 member functions (which is the this pointer) as
7961 artificial. We pass this information to
7962 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
7964 DWARF version 3 added DW_AT_object_pointer, which GCC
7965 4.5 does not yet generate. */
7966 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
7968 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
7971 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
7973 /* GCC/43521: In java, the formal parameter
7974 "this" is sometimes not marked with DW_AT_artificial. */
7975 if (cu
->language
== language_java
)
7977 const char *name
= dwarf2_name (child_die
, cu
);
7979 if (name
&& !strcmp (name
, "this"))
7980 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
7983 arg_type
= die_type (child_die
, cu
);
7985 /* RealView does not mark THIS as const, which the testsuite
7986 expects. GCC marks THIS as const in method definitions,
7987 but not in the class specifications (GCC PR 43053). */
7988 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
7989 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
7992 struct dwarf2_cu
*arg_cu
= cu
;
7993 const char *name
= dwarf2_name (child_die
, cu
);
7995 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
7998 /* If the compiler emits this, use it. */
7999 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8002 else if (name
&& strcmp (name
, "this") == 0)
8003 /* Function definitions will have the argument names. */
8005 else if (name
== NULL
&& iparams
== 0)
8006 /* Declarations may not have the names, so like
8007 elsewhere in GDB, assume an artificial first
8008 argument is "this". */
8012 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8016 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8019 child_die
= sibling_die (child_die
);
8026 static struct type
*
8027 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8029 struct objfile
*objfile
= cu
->objfile
;
8030 const char *name
= NULL
;
8031 struct type
*this_type
;
8033 name
= dwarf2_full_name (NULL
, die
, cu
);
8034 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8035 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8036 TYPE_NAME (this_type
) = (char *) name
;
8037 set_die_type (die
, this_type
, cu
);
8038 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
8042 /* Find a representation of a given base type and install
8043 it in the TYPE field of the die. */
8045 static struct type
*
8046 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8048 struct objfile
*objfile
= cu
->objfile
;
8050 struct attribute
*attr
;
8051 int encoding
= 0, size
= 0;
8053 enum type_code code
= TYPE_CODE_INT
;
8055 struct type
*target_type
= NULL
;
8057 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8060 encoding
= DW_UNSND (attr
);
8062 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8065 size
= DW_UNSND (attr
);
8067 name
= dwarf2_name (die
, cu
);
8070 complaint (&symfile_complaints
,
8071 _("DW_AT_name missing from DW_TAG_base_type"));
8076 case DW_ATE_address
:
8077 /* Turn DW_ATE_address into a void * pointer. */
8078 code
= TYPE_CODE_PTR
;
8079 type_flags
|= TYPE_FLAG_UNSIGNED
;
8080 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8082 case DW_ATE_boolean
:
8083 code
= TYPE_CODE_BOOL
;
8084 type_flags
|= TYPE_FLAG_UNSIGNED
;
8086 case DW_ATE_complex_float
:
8087 code
= TYPE_CODE_COMPLEX
;
8088 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8090 case DW_ATE_decimal_float
:
8091 code
= TYPE_CODE_DECFLOAT
;
8094 code
= TYPE_CODE_FLT
;
8098 case DW_ATE_unsigned
:
8099 type_flags
|= TYPE_FLAG_UNSIGNED
;
8101 case DW_ATE_signed_char
:
8102 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8103 || cu
->language
== language_pascal
)
8104 code
= TYPE_CODE_CHAR
;
8106 case DW_ATE_unsigned_char
:
8107 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8108 || cu
->language
== language_pascal
)
8109 code
= TYPE_CODE_CHAR
;
8110 type_flags
|= TYPE_FLAG_UNSIGNED
;
8113 /* We just treat this as an integer and then recognize the
8114 type by name elsewhere. */
8118 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8119 dwarf_type_encoding_name (encoding
));
8123 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8124 TYPE_NAME (type
) = name
;
8125 TYPE_TARGET_TYPE (type
) = target_type
;
8127 if (name
&& strcmp (name
, "char") == 0)
8128 TYPE_NOSIGN (type
) = 1;
8130 return set_die_type (die
, type
, cu
);
8133 /* Read the given DW_AT_subrange DIE. */
8135 static struct type
*
8136 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8138 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8139 struct type
*base_type
;
8140 struct type
*range_type
;
8141 struct attribute
*attr
;
8145 LONGEST negative_mask
;
8147 base_type
= die_type (die
, cu
);
8148 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8149 check_typedef (base_type
);
8151 /* The die_type call above may have already set the type for this DIE. */
8152 range_type
= get_die_type (die
, cu
);
8156 if (cu
->language
== language_fortran
)
8158 /* FORTRAN implies a lower bound of 1, if not given. */
8162 /* FIXME: For variable sized arrays either of these could be
8163 a variable rather than a constant value. We'll allow it,
8164 but we don't know how to handle it. */
8165 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8167 low
= dwarf2_get_attr_constant_value (attr
, 0);
8169 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8172 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
8174 /* GCC encodes arrays with unspecified or dynamic length
8175 with a DW_FORM_block1 attribute or a reference attribute.
8176 FIXME: GDB does not yet know how to handle dynamic
8177 arrays properly, treat them as arrays with unspecified
8180 FIXME: jimb/2003-09-22: GDB does not really know
8181 how to handle arrays of unspecified length
8182 either; we just represent them as zero-length
8183 arrays. Choose an appropriate upper bound given
8184 the lower bound we've computed above. */
8188 high
= dwarf2_get_attr_constant_value (attr
, 1);
8192 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8195 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8196 high
= low
+ count
- 1;
8200 /* Dwarf-2 specifications explicitly allows to create subrange types
8201 without specifying a base type.
8202 In that case, the base type must be set to the type of
8203 the lower bound, upper bound or count, in that order, if any of these
8204 three attributes references an object that has a type.
8205 If no base type is found, the Dwarf-2 specifications say that
8206 a signed integer type of size equal to the size of an address should
8208 For the following C code: `extern char gdb_int [];'
8209 GCC produces an empty range DIE.
8210 FIXME: muller/2010-05-28: Possible references to object for low bound,
8211 high bound or count are not yet handled by this code.
8213 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8215 struct objfile
*objfile
= cu
->objfile
;
8216 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8217 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8218 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8220 /* Test "int", "long int", and "long long int" objfile types,
8221 and select the first one having a size above or equal to the
8222 architecture address size. */
8223 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8224 base_type
= int_type
;
8227 int_type
= objfile_type (objfile
)->builtin_long
;
8228 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8229 base_type
= int_type
;
8232 int_type
= objfile_type (objfile
)->builtin_long_long
;
8233 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8234 base_type
= int_type
;
8240 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8241 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8242 low
|= negative_mask
;
8243 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8244 high
|= negative_mask
;
8246 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8248 /* Mark arrays with dynamic length at least as an array of unspecified
8249 length. GDB could check the boundary but before it gets implemented at
8250 least allow accessing the array elements. */
8251 if (attr
&& attr
->form
== DW_FORM_block1
)
8252 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8254 name
= dwarf2_name (die
, cu
);
8256 TYPE_NAME (range_type
) = name
;
8258 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8260 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8262 set_die_type (die
, range_type
, cu
);
8264 /* set_die_type should be already done. */
8265 set_descriptive_type (range_type
, die
, cu
);
8270 static struct type
*
8271 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8275 /* For now, we only support the C meaning of an unspecified type: void. */
8277 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8278 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8280 return set_die_type (die
, type
, cu
);
8283 /* Trivial hash function for die_info: the hash value of a DIE
8284 is its offset in .debug_info for this objfile. */
8287 die_hash (const void *item
)
8289 const struct die_info
*die
= item
;
8294 /* Trivial comparison function for die_info structures: two DIEs
8295 are equal if they have the same offset. */
8298 die_eq (const void *item_lhs
, const void *item_rhs
)
8300 const struct die_info
*die_lhs
= item_lhs
;
8301 const struct die_info
*die_rhs
= item_rhs
;
8303 return die_lhs
->offset
== die_rhs
->offset
;
8306 /* Read a whole compilation unit into a linked list of dies. */
8308 static struct die_info
*
8309 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8311 struct die_reader_specs reader_specs
;
8312 int read_abbrevs
= 0;
8313 struct cleanup
*back_to
= NULL
;
8314 struct die_info
*die
;
8316 if (cu
->dwarf2_abbrevs
== NULL
)
8318 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8319 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8323 gdb_assert (cu
->die_hash
== NULL
);
8325 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8329 &cu
->comp_unit_obstack
,
8330 hashtab_obstack_allocate
,
8331 dummy_obstack_deallocate
);
8333 init_cu_die_reader (&reader_specs
, cu
);
8335 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8338 do_cleanups (back_to
);
8343 /* Main entry point for reading a DIE and all children.
8344 Read the DIE and dump it if requested. */
8346 static struct die_info
*
8347 read_die_and_children (const struct die_reader_specs
*reader
,
8349 gdb_byte
**new_info_ptr
,
8350 struct die_info
*parent
)
8352 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8353 new_info_ptr
, parent
);
8355 if (dwarf2_die_debug
)
8357 fprintf_unfiltered (gdb_stdlog
,
8358 "\nRead die from %s of %s:\n",
8359 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8361 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8363 : "unknown section",
8364 reader
->abfd
->filename
);
8365 dump_die (result
, dwarf2_die_debug
);
8371 /* Read a single die and all its descendents. Set the die's sibling
8372 field to NULL; set other fields in the die correctly, and set all
8373 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8374 location of the info_ptr after reading all of those dies. PARENT
8375 is the parent of the die in question. */
8377 static struct die_info
*
8378 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8380 gdb_byte
**new_info_ptr
,
8381 struct die_info
*parent
)
8383 struct die_info
*die
;
8387 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8390 *new_info_ptr
= cur_ptr
;
8393 store_in_ref_table (die
, reader
->cu
);
8396 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8400 *new_info_ptr
= cur_ptr
;
8403 die
->sibling
= NULL
;
8404 die
->parent
= parent
;
8408 /* Read a die, all of its descendents, and all of its siblings; set
8409 all of the fields of all of the dies correctly. Arguments are as
8410 in read_die_and_children. */
8412 static struct die_info
*
8413 read_die_and_siblings (const struct die_reader_specs
*reader
,
8415 gdb_byte
**new_info_ptr
,
8416 struct die_info
*parent
)
8418 struct die_info
*first_die
, *last_sibling
;
8422 first_die
= last_sibling
= NULL
;
8426 struct die_info
*die
8427 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8431 *new_info_ptr
= cur_ptr
;
8438 last_sibling
->sibling
= die
;
8444 /* Read the die from the .debug_info section buffer. Set DIEP to
8445 point to a newly allocated die with its information, except for its
8446 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8447 whether the die has children or not. */
8450 read_full_die (const struct die_reader_specs
*reader
,
8451 struct die_info
**diep
, gdb_byte
*info_ptr
,
8454 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8455 struct abbrev_info
*abbrev
;
8456 struct die_info
*die
;
8457 struct dwarf2_cu
*cu
= reader
->cu
;
8458 bfd
*abfd
= reader
->abfd
;
8460 offset
= info_ptr
- reader
->buffer
;
8461 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8462 info_ptr
+= bytes_read
;
8470 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8472 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8474 bfd_get_filename (abfd
));
8476 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8477 die
->offset
= offset
;
8478 die
->tag
= abbrev
->tag
;
8479 die
->abbrev
= abbrev_number
;
8481 die
->num_attrs
= abbrev
->num_attrs
;
8483 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8484 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8485 abfd
, info_ptr
, cu
);
8488 *has_children
= abbrev
->has_children
;
8492 /* In DWARF version 2, the description of the debugging information is
8493 stored in a separate .debug_abbrev section. Before we read any
8494 dies from a section we read in all abbreviations and install them
8495 in a hash table. This function also sets flags in CU describing
8496 the data found in the abbrev table. */
8499 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8501 struct comp_unit_head
*cu_header
= &cu
->header
;
8502 gdb_byte
*abbrev_ptr
;
8503 struct abbrev_info
*cur_abbrev
;
8504 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8505 unsigned int abbrev_form
, hash_number
;
8506 struct attr_abbrev
*cur_attrs
;
8507 unsigned int allocated_attrs
;
8509 /* Initialize dwarf2 abbrevs */
8510 obstack_init (&cu
->abbrev_obstack
);
8511 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8513 * sizeof (struct abbrev_info
*)));
8514 memset (cu
->dwarf2_abbrevs
, 0,
8515 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8517 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8518 &dwarf2_per_objfile
->abbrev
);
8519 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8520 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8521 abbrev_ptr
+= bytes_read
;
8523 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8524 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8526 /* loop until we reach an abbrev number of 0 */
8527 while (abbrev_number
)
8529 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8531 /* read in abbrev header */
8532 cur_abbrev
->number
= abbrev_number
;
8533 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8534 abbrev_ptr
+= bytes_read
;
8535 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8538 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8539 cu
->has_namespace_info
= 1;
8541 /* now read in declarations */
8542 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8543 abbrev_ptr
+= bytes_read
;
8544 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8545 abbrev_ptr
+= bytes_read
;
8548 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8550 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8552 = xrealloc (cur_attrs
, (allocated_attrs
8553 * sizeof (struct attr_abbrev
)));
8556 /* Record whether this compilation unit might have
8557 inter-compilation-unit references. If we don't know what form
8558 this attribute will have, then it might potentially be a
8559 DW_FORM_ref_addr, so we conservatively expect inter-CU
8562 if (abbrev_form
== DW_FORM_ref_addr
8563 || abbrev_form
== DW_FORM_indirect
)
8564 cu
->has_form_ref_addr
= 1;
8566 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8567 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8568 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8569 abbrev_ptr
+= bytes_read
;
8570 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8571 abbrev_ptr
+= bytes_read
;
8574 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8575 (cur_abbrev
->num_attrs
8576 * sizeof (struct attr_abbrev
)));
8577 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8578 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8580 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8581 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8582 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8584 /* Get next abbreviation.
8585 Under Irix6 the abbreviations for a compilation unit are not
8586 always properly terminated with an abbrev number of 0.
8587 Exit loop if we encounter an abbreviation which we have
8588 already read (which means we are about to read the abbreviations
8589 for the next compile unit) or if the end of the abbreviation
8590 table is reached. */
8591 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8592 >= dwarf2_per_objfile
->abbrev
.size
)
8594 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8595 abbrev_ptr
+= bytes_read
;
8596 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
8603 /* Release the memory used by the abbrev table for a compilation unit. */
8606 dwarf2_free_abbrev_table (void *ptr_to_cu
)
8608 struct dwarf2_cu
*cu
= ptr_to_cu
;
8610 obstack_free (&cu
->abbrev_obstack
, NULL
);
8611 cu
->dwarf2_abbrevs
= NULL
;
8614 /* Lookup an abbrev_info structure in the abbrev hash table. */
8616 static struct abbrev_info
*
8617 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
8619 unsigned int hash_number
;
8620 struct abbrev_info
*abbrev
;
8622 hash_number
= number
% ABBREV_HASH_SIZE
;
8623 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
8627 if (abbrev
->number
== number
)
8630 abbrev
= abbrev
->next
;
8635 /* Returns nonzero if TAG represents a type that we might generate a partial
8639 is_type_tag_for_partial (int tag
)
8644 /* Some types that would be reasonable to generate partial symbols for,
8645 that we don't at present. */
8646 case DW_TAG_array_type
:
8647 case DW_TAG_file_type
:
8648 case DW_TAG_ptr_to_member_type
:
8649 case DW_TAG_set_type
:
8650 case DW_TAG_string_type
:
8651 case DW_TAG_subroutine_type
:
8653 case DW_TAG_base_type
:
8654 case DW_TAG_class_type
:
8655 case DW_TAG_interface_type
:
8656 case DW_TAG_enumeration_type
:
8657 case DW_TAG_structure_type
:
8658 case DW_TAG_subrange_type
:
8659 case DW_TAG_typedef
:
8660 case DW_TAG_union_type
:
8667 /* Load all DIEs that are interesting for partial symbols into memory. */
8669 static struct partial_die_info
*
8670 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8671 int building_psymtab
, struct dwarf2_cu
*cu
)
8673 struct partial_die_info
*part_die
;
8674 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
8675 struct abbrev_info
*abbrev
;
8676 unsigned int bytes_read
;
8677 unsigned int load_all
= 0;
8679 int nesting_level
= 1;
8684 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
8688 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8692 &cu
->comp_unit_obstack
,
8693 hashtab_obstack_allocate
,
8694 dummy_obstack_deallocate
);
8696 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8697 sizeof (struct partial_die_info
));
8701 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
8703 /* A NULL abbrev means the end of a series of children. */
8706 if (--nesting_level
== 0)
8708 /* PART_DIE was probably the last thing allocated on the
8709 comp_unit_obstack, so we could call obstack_free
8710 here. We don't do that because the waste is small,
8711 and will be cleaned up when we're done with this
8712 compilation unit. This way, we're also more robust
8713 against other users of the comp_unit_obstack. */
8716 info_ptr
+= bytes_read
;
8717 last_die
= parent_die
;
8718 parent_die
= parent_die
->die_parent
;
8722 /* Check for template arguments. We never save these; if
8723 they're seen, we just mark the parent, and go on our way. */
8724 if (parent_die
!= NULL
8725 && cu
->language
== language_cplus
8726 && (abbrev
->tag
== DW_TAG_template_type_param
8727 || abbrev
->tag
== DW_TAG_template_value_param
))
8729 parent_die
->has_template_arguments
= 1;
8733 /* We don't need a partial DIE for the template argument. */
8734 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
8740 /* We only recurse into subprograms looking for template arguments.
8741 Skip their other children. */
8743 && cu
->language
== language_cplus
8744 && parent_die
!= NULL
8745 && parent_die
->tag
== DW_TAG_subprogram
)
8747 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8751 /* Check whether this DIE is interesting enough to save. Normally
8752 we would not be interested in members here, but there may be
8753 later variables referencing them via DW_AT_specification (for
8756 && !is_type_tag_for_partial (abbrev
->tag
)
8757 && abbrev
->tag
!= DW_TAG_constant
8758 && abbrev
->tag
!= DW_TAG_enumerator
8759 && abbrev
->tag
!= DW_TAG_subprogram
8760 && abbrev
->tag
!= DW_TAG_lexical_block
8761 && abbrev
->tag
!= DW_TAG_variable
8762 && abbrev
->tag
!= DW_TAG_namespace
8763 && abbrev
->tag
!= DW_TAG_module
8764 && abbrev
->tag
!= DW_TAG_member
)
8766 /* Otherwise we skip to the next sibling, if any. */
8767 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8771 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
8772 buffer
, info_ptr
, cu
);
8774 /* This two-pass algorithm for processing partial symbols has a
8775 high cost in cache pressure. Thus, handle some simple cases
8776 here which cover the majority of C partial symbols. DIEs
8777 which neither have specification tags in them, nor could have
8778 specification tags elsewhere pointing at them, can simply be
8779 processed and discarded.
8781 This segment is also optional; scan_partial_symbols and
8782 add_partial_symbol will handle these DIEs if we chain
8783 them in normally. When compilers which do not emit large
8784 quantities of duplicate debug information are more common,
8785 this code can probably be removed. */
8787 /* Any complete simple types at the top level (pretty much all
8788 of them, for a language without namespaces), can be processed
8790 if (parent_die
== NULL
8791 && part_die
->has_specification
== 0
8792 && part_die
->is_declaration
== 0
8793 && (part_die
->tag
== DW_TAG_typedef
8794 || part_die
->tag
== DW_TAG_base_type
8795 || part_die
->tag
== DW_TAG_subrange_type
))
8797 if (building_psymtab
&& part_die
->name
!= NULL
)
8798 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8799 VAR_DOMAIN
, LOC_TYPEDEF
,
8800 &cu
->objfile
->static_psymbols
,
8801 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8802 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8806 /* If we're at the second level, and we're an enumerator, and
8807 our parent has no specification (meaning possibly lives in a
8808 namespace elsewhere), then we can add the partial symbol now
8809 instead of queueing it. */
8810 if (part_die
->tag
== DW_TAG_enumerator
8811 && parent_die
!= NULL
8812 && parent_die
->die_parent
== NULL
8813 && parent_die
->tag
== DW_TAG_enumeration_type
8814 && parent_die
->has_specification
== 0)
8816 if (part_die
->name
== NULL
)
8817 complaint (&symfile_complaints
,
8818 _("malformed enumerator DIE ignored"));
8819 else if (building_psymtab
)
8820 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8821 VAR_DOMAIN
, LOC_CONST
,
8822 (cu
->language
== language_cplus
8823 || cu
->language
== language_java
)
8824 ? &cu
->objfile
->global_psymbols
8825 : &cu
->objfile
->static_psymbols
,
8826 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8828 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8832 /* We'll save this DIE so link it in. */
8833 part_die
->die_parent
= parent_die
;
8834 part_die
->die_sibling
= NULL
;
8835 part_die
->die_child
= NULL
;
8837 if (last_die
&& last_die
== parent_die
)
8838 last_die
->die_child
= part_die
;
8840 last_die
->die_sibling
= part_die
;
8842 last_die
= part_die
;
8844 if (first_die
== NULL
)
8845 first_die
= part_die
;
8847 /* Maybe add the DIE to the hash table. Not all DIEs that we
8848 find interesting need to be in the hash table, because we
8849 also have the parent/sibling/child chains; only those that we
8850 might refer to by offset later during partial symbol reading.
8852 For now this means things that might have be the target of a
8853 DW_AT_specification, DW_AT_abstract_origin, or
8854 DW_AT_extension. DW_AT_extension will refer only to
8855 namespaces; DW_AT_abstract_origin refers to functions (and
8856 many things under the function DIE, but we do not recurse
8857 into function DIEs during partial symbol reading) and
8858 possibly variables as well; DW_AT_specification refers to
8859 declarations. Declarations ought to have the DW_AT_declaration
8860 flag. It happens that GCC forgets to put it in sometimes, but
8861 only for functions, not for types.
8863 Adding more things than necessary to the hash table is harmless
8864 except for the performance cost. Adding too few will result in
8865 wasted time in find_partial_die, when we reread the compilation
8866 unit with load_all_dies set. */
8869 || abbrev
->tag
== DW_TAG_constant
8870 || abbrev
->tag
== DW_TAG_subprogram
8871 || abbrev
->tag
== DW_TAG_variable
8872 || abbrev
->tag
== DW_TAG_namespace
8873 || part_die
->is_declaration
)
8877 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
8878 part_die
->offset
, INSERT
);
8882 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8883 sizeof (struct partial_die_info
));
8885 /* For some DIEs we want to follow their children (if any). For C
8886 we have no reason to follow the children of structures; for other
8887 languages we have to, so that we can get at method physnames
8888 to infer fully qualified class names, for DW_AT_specification,
8889 and for C++ template arguments. For C++, we also look one level
8890 inside functions to find template arguments (if the name of the
8891 function does not already contain the template arguments).
8893 For Ada, we need to scan the children of subprograms and lexical
8894 blocks as well because Ada allows the definition of nested
8895 entities that could be interesting for the debugger, such as
8896 nested subprograms for instance. */
8897 if (last_die
->has_children
8899 || last_die
->tag
== DW_TAG_namespace
8900 || last_die
->tag
== DW_TAG_module
8901 || last_die
->tag
== DW_TAG_enumeration_type
8902 || (cu
->language
== language_cplus
8903 && last_die
->tag
== DW_TAG_subprogram
8904 && (last_die
->name
== NULL
8905 || strchr (last_die
->name
, '<') == NULL
))
8906 || (cu
->language
!= language_c
8907 && (last_die
->tag
== DW_TAG_class_type
8908 || last_die
->tag
== DW_TAG_interface_type
8909 || last_die
->tag
== DW_TAG_structure_type
8910 || last_die
->tag
== DW_TAG_union_type
))
8911 || (cu
->language
== language_ada
8912 && (last_die
->tag
== DW_TAG_subprogram
8913 || last_die
->tag
== DW_TAG_lexical_block
))))
8916 parent_die
= last_die
;
8920 /* Otherwise we skip to the next sibling, if any. */
8921 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
8923 /* Back to the top, do it again. */
8927 /* Read a minimal amount of information into the minimal die structure. */
8930 read_partial_die (struct partial_die_info
*part_die
,
8931 struct abbrev_info
*abbrev
,
8932 unsigned int abbrev_len
, bfd
*abfd
,
8933 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8934 struct dwarf2_cu
*cu
)
8937 struct attribute attr
;
8938 int has_low_pc_attr
= 0;
8939 int has_high_pc_attr
= 0;
8941 memset (part_die
, 0, sizeof (struct partial_die_info
));
8943 part_die
->offset
= info_ptr
- buffer
;
8945 info_ptr
+= abbrev_len
;
8950 part_die
->tag
= abbrev
->tag
;
8951 part_die
->has_children
= abbrev
->has_children
;
8953 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8955 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
8957 /* Store the data if it is of an attribute we want to keep in a
8958 partial symbol table. */
8962 switch (part_die
->tag
)
8964 case DW_TAG_compile_unit
:
8965 case DW_TAG_type_unit
:
8966 /* Compilation units have a DW_AT_name that is a filename, not
8967 a source language identifier. */
8968 case DW_TAG_enumeration_type
:
8969 case DW_TAG_enumerator
:
8970 /* These tags always have simple identifiers already; no need
8971 to canonicalize them. */
8972 part_die
->name
= DW_STRING (&attr
);
8976 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
8977 &cu
->objfile
->objfile_obstack
);
8981 case DW_AT_linkage_name
:
8982 case DW_AT_MIPS_linkage_name
:
8983 /* Note that both forms of linkage name might appear. We
8984 assume they will be the same, and we only store the last
8986 if (cu
->language
== language_ada
)
8987 part_die
->name
= DW_STRING (&attr
);
8988 part_die
->linkage_name
= DW_STRING (&attr
);
8991 has_low_pc_attr
= 1;
8992 part_die
->lowpc
= DW_ADDR (&attr
);
8995 has_high_pc_attr
= 1;
8996 part_die
->highpc
= DW_ADDR (&attr
);
8998 case DW_AT_location
:
8999 /* Support the .debug_loc offsets */
9000 if (attr_form_is_block (&attr
))
9002 part_die
->locdesc
= DW_BLOCK (&attr
);
9004 else if (attr_form_is_section_offset (&attr
))
9006 dwarf2_complex_location_expr_complaint ();
9010 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9011 "partial symbol information");
9014 case DW_AT_external
:
9015 part_die
->is_external
= DW_UNSND (&attr
);
9017 case DW_AT_declaration
:
9018 part_die
->is_declaration
= DW_UNSND (&attr
);
9021 part_die
->has_type
= 1;
9023 case DW_AT_abstract_origin
:
9024 case DW_AT_specification
:
9025 case DW_AT_extension
:
9026 part_die
->has_specification
= 1;
9027 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9030 /* Ignore absolute siblings, they might point outside of
9031 the current compile unit. */
9032 if (attr
.form
== DW_FORM_ref_addr
)
9033 complaint (&symfile_complaints
,
9034 _("ignoring absolute DW_AT_sibling"));
9036 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9038 case DW_AT_byte_size
:
9039 part_die
->has_byte_size
= 1;
9041 case DW_AT_calling_convention
:
9042 /* DWARF doesn't provide a way to identify a program's source-level
9043 entry point. DW_AT_calling_convention attributes are only meant
9044 to describe functions' calling conventions.
9046 However, because it's a necessary piece of information in
9047 Fortran, and because DW_CC_program is the only piece of debugging
9048 information whose definition refers to a 'main program' at all,
9049 several compilers have begun marking Fortran main programs with
9050 DW_CC_program --- even when those functions use the standard
9051 calling conventions.
9053 So until DWARF specifies a way to provide this information and
9054 compilers pick up the new representation, we'll support this
9056 if (DW_UNSND (&attr
) == DW_CC_program
9057 && cu
->language
== language_fortran
)
9059 set_main_name (part_die
->name
);
9061 /* As this DIE has a static linkage the name would be difficult
9062 to look up later. */
9063 language_of_main
= language_fortran
;
9071 /* When using the GNU linker, .gnu.linkonce. sections are used to
9072 eliminate duplicate copies of functions and vtables and such.
9073 The linker will arbitrarily choose one and discard the others.
9074 The AT_*_pc values for such functions refer to local labels in
9075 these sections. If the section from that file was discarded, the
9076 labels are not in the output, so the relocs get a value of 0.
9077 If this is a discarded function, mark the pc bounds as invalid,
9078 so that GDB will ignore it. */
9079 if (has_low_pc_attr
&& has_high_pc_attr
9080 && part_die
->lowpc
< part_die
->highpc
9081 && (part_die
->lowpc
!= 0
9082 || dwarf2_per_objfile
->has_section_at_zero
))
9083 part_die
->has_pc_info
= 1;
9088 /* Find a cached partial DIE at OFFSET in CU. */
9090 static struct partial_die_info
*
9091 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9093 struct partial_die_info
*lookup_die
= NULL
;
9094 struct partial_die_info part_die
;
9096 part_die
.offset
= offset
;
9097 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9102 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9103 except in the case of .debug_types DIEs which do not reference
9104 outside their CU (they do however referencing other types via
9107 static struct partial_die_info
*
9108 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9110 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9111 struct partial_die_info
*pd
= NULL
;
9113 if (cu
->per_cu
->from_debug_types
)
9115 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9121 if (offset_in_cu_p (&cu
->header
, offset
))
9123 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9128 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9130 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9131 load_partial_comp_unit (per_cu
, cu
->objfile
);
9133 per_cu
->cu
->last_used
= 0;
9134 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9136 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9138 struct cleanup
*back_to
;
9139 struct partial_die_info comp_unit_die
;
9140 struct abbrev_info
*abbrev
;
9141 unsigned int bytes_read
;
9144 per_cu
->load_all_dies
= 1;
9146 /* Re-read the DIEs. */
9147 back_to
= make_cleanup (null_cleanup
, 0);
9148 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9150 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
9151 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9153 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9154 + per_cu
->cu
->header
.offset
9155 + per_cu
->cu
->header
.first_die_offset
);
9156 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9157 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9158 per_cu
->cu
->objfile
->obfd
,
9159 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9161 if (comp_unit_die
.has_children
)
9162 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
9163 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9165 do_cleanups (back_to
);
9167 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9173 internal_error (__FILE__
, __LINE__
,
9174 _("could not find partial DIE 0x%x "
9175 "in cache [from module %s]\n"),
9176 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9180 /* See if we can figure out if the class lives in a namespace. We do
9181 this by looking for a member function; its demangled name will
9182 contain namespace info, if there is any. */
9185 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9186 struct dwarf2_cu
*cu
)
9188 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9189 what template types look like, because the demangler
9190 frequently doesn't give the same name as the debug info. We
9191 could fix this by only using the demangled name to get the
9192 prefix (but see comment in read_structure_type). */
9194 struct partial_die_info
*real_pdi
;
9195 struct partial_die_info
*child_pdi
;
9197 /* If this DIE (this DIE's specification, if any) has a parent, then
9198 we should not do this. We'll prepend the parent's fully qualified
9199 name when we create the partial symbol. */
9201 real_pdi
= struct_pdi
;
9202 while (real_pdi
->has_specification
)
9203 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9205 if (real_pdi
->die_parent
!= NULL
)
9208 for (child_pdi
= struct_pdi
->die_child
;
9210 child_pdi
= child_pdi
->die_sibling
)
9212 if (child_pdi
->tag
== DW_TAG_subprogram
9213 && child_pdi
->linkage_name
!= NULL
)
9215 char *actual_class_name
9216 = language_class_name_from_physname (cu
->language_defn
,
9217 child_pdi
->linkage_name
);
9218 if (actual_class_name
!= NULL
)
9221 = obsavestring (actual_class_name
,
9222 strlen (actual_class_name
),
9223 &cu
->objfile
->objfile_obstack
);
9224 xfree (actual_class_name
);
9231 /* Adjust PART_DIE before generating a symbol for it. This function
9232 may set the is_external flag or change the DIE's name. */
9235 fixup_partial_die (struct partial_die_info
*part_die
,
9236 struct dwarf2_cu
*cu
)
9238 /* Once we've fixed up a die, there's no point in doing so again.
9239 This also avoids a memory leak if we were to call
9240 guess_partial_die_structure_name multiple times. */
9241 if (part_die
->fixup_called
)
9244 /* If we found a reference attribute and the DIE has no name, try
9245 to find a name in the referred to DIE. */
9247 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9249 struct partial_die_info
*spec_die
;
9251 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9253 fixup_partial_die (spec_die
, cu
);
9257 part_die
->name
= spec_die
->name
;
9259 /* Copy DW_AT_external attribute if it is set. */
9260 if (spec_die
->is_external
)
9261 part_die
->is_external
= spec_die
->is_external
;
9265 /* Set default names for some unnamed DIEs. */
9267 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9268 part_die
->name
= "(anonymous namespace)";
9270 /* If there is no parent die to provide a namespace, and there are
9271 children, see if we can determine the namespace from their linkage
9273 NOTE: We need to do this even if cu->has_namespace_info != 0.
9274 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9275 if (cu
->language
== language_cplus
9276 && dwarf2_per_objfile
->types
.asection
!= NULL
9277 && part_die
->die_parent
== NULL
9278 && part_die
->has_children
9279 && (part_die
->tag
== DW_TAG_class_type
9280 || part_die
->tag
== DW_TAG_structure_type
9281 || part_die
->tag
== DW_TAG_union_type
))
9282 guess_partial_die_structure_name (part_die
, cu
);
9284 part_die
->fixup_called
= 1;
9287 /* Read an attribute value described by an attribute form. */
9290 read_attribute_value (struct attribute
*attr
, unsigned form
,
9291 bfd
*abfd
, gdb_byte
*info_ptr
,
9292 struct dwarf2_cu
*cu
)
9294 struct comp_unit_head
*cu_header
= &cu
->header
;
9295 unsigned int bytes_read
;
9296 struct dwarf_block
*blk
;
9301 case DW_FORM_ref_addr
:
9302 if (cu
->header
.version
== 2)
9303 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9305 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
9306 &cu
->header
, &bytes_read
);
9307 info_ptr
+= bytes_read
;
9310 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9311 info_ptr
+= bytes_read
;
9313 case DW_FORM_block2
:
9314 blk
= dwarf_alloc_block (cu
);
9315 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9317 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9318 info_ptr
+= blk
->size
;
9319 DW_BLOCK (attr
) = blk
;
9321 case DW_FORM_block4
:
9322 blk
= dwarf_alloc_block (cu
);
9323 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9325 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9326 info_ptr
+= blk
->size
;
9327 DW_BLOCK (attr
) = blk
;
9330 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9334 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9338 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9341 case DW_FORM_sec_offset
:
9342 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9343 info_ptr
+= bytes_read
;
9345 case DW_FORM_string
:
9346 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9347 DW_STRING_IS_CANONICAL (attr
) = 0;
9348 info_ptr
+= bytes_read
;
9351 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9353 DW_STRING_IS_CANONICAL (attr
) = 0;
9354 info_ptr
+= bytes_read
;
9356 case DW_FORM_exprloc
:
9358 blk
= dwarf_alloc_block (cu
);
9359 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9360 info_ptr
+= bytes_read
;
9361 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9362 info_ptr
+= blk
->size
;
9363 DW_BLOCK (attr
) = blk
;
9365 case DW_FORM_block1
:
9366 blk
= dwarf_alloc_block (cu
);
9367 blk
->size
= read_1_byte (abfd
, info_ptr
);
9369 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9370 info_ptr
+= blk
->size
;
9371 DW_BLOCK (attr
) = blk
;
9374 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9378 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9381 case DW_FORM_flag_present
:
9382 DW_UNSND (attr
) = 1;
9385 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9386 info_ptr
+= bytes_read
;
9389 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9390 info_ptr
+= bytes_read
;
9393 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9397 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9401 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9405 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9409 /* Convert the signature to something we can record in DW_UNSND
9411 NOTE: This is NULL if the type wasn't found. */
9412 DW_SIGNATURED_TYPE (attr
) =
9413 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9416 case DW_FORM_ref_udata
:
9417 DW_ADDR (attr
) = (cu
->header
.offset
9418 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9419 info_ptr
+= bytes_read
;
9421 case DW_FORM_indirect
:
9422 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9423 info_ptr
+= bytes_read
;
9424 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9427 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9428 dwarf_form_name (form
),
9429 bfd_get_filename (abfd
));
9432 /* We have seen instances where the compiler tried to emit a byte
9433 size attribute of -1 which ended up being encoded as an unsigned
9434 0xffffffff. Although 0xffffffff is technically a valid size value,
9435 an object of this size seems pretty unlikely so we can relatively
9436 safely treat these cases as if the size attribute was invalid and
9437 treat them as zero by default. */
9438 if (attr
->name
== DW_AT_byte_size
9439 && form
== DW_FORM_data4
9440 && DW_UNSND (attr
) >= 0xffffffff)
9443 (&symfile_complaints
,
9444 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9445 hex_string (DW_UNSND (attr
)));
9446 DW_UNSND (attr
) = 0;
9452 /* Read an attribute described by an abbreviated attribute. */
9455 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9456 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9458 attr
->name
= abbrev
->name
;
9459 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9462 /* read dwarf information from a buffer */
9465 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9467 return bfd_get_8 (abfd
, buf
);
9471 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9473 return bfd_get_signed_8 (abfd
, buf
);
9477 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9479 return bfd_get_16 (abfd
, buf
);
9483 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9485 return bfd_get_signed_16 (abfd
, buf
);
9489 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9491 return bfd_get_32 (abfd
, buf
);
9495 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9497 return bfd_get_signed_32 (abfd
, buf
);
9501 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9503 return bfd_get_64 (abfd
, buf
);
9507 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9508 unsigned int *bytes_read
)
9510 struct comp_unit_head
*cu_header
= &cu
->header
;
9511 CORE_ADDR retval
= 0;
9513 if (cu_header
->signed_addr_p
)
9515 switch (cu_header
->addr_size
)
9518 retval
= bfd_get_signed_16 (abfd
, buf
);
9521 retval
= bfd_get_signed_32 (abfd
, buf
);
9524 retval
= bfd_get_signed_64 (abfd
, buf
);
9527 internal_error (__FILE__
, __LINE__
,
9528 _("read_address: bad switch, signed [in module %s]"),
9529 bfd_get_filename (abfd
));
9534 switch (cu_header
->addr_size
)
9537 retval
= bfd_get_16 (abfd
, buf
);
9540 retval
= bfd_get_32 (abfd
, buf
);
9543 retval
= bfd_get_64 (abfd
, buf
);
9546 internal_error (__FILE__
, __LINE__
,
9547 _("read_address: bad switch, unsigned [in module %s]"),
9548 bfd_get_filename (abfd
));
9552 *bytes_read
= cu_header
->addr_size
;
9556 /* Read the initial length from a section. The (draft) DWARF 3
9557 specification allows the initial length to take up either 4 bytes
9558 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9559 bytes describe the length and all offsets will be 8 bytes in length
9562 An older, non-standard 64-bit format is also handled by this
9563 function. The older format in question stores the initial length
9564 as an 8-byte quantity without an escape value. Lengths greater
9565 than 2^32 aren't very common which means that the initial 4 bytes
9566 is almost always zero. Since a length value of zero doesn't make
9567 sense for the 32-bit format, this initial zero can be considered to
9568 be an escape value which indicates the presence of the older 64-bit
9569 format. As written, the code can't detect (old format) lengths
9570 greater than 4GB. If it becomes necessary to handle lengths
9571 somewhat larger than 4GB, we could allow other small values (such
9572 as the non-sensical values of 1, 2, and 3) to also be used as
9573 escape values indicating the presence of the old format.
9575 The value returned via bytes_read should be used to increment the
9576 relevant pointer after calling read_initial_length().
9578 [ Note: read_initial_length() and read_offset() are based on the
9579 document entitled "DWARF Debugging Information Format", revision
9580 3, draft 8, dated November 19, 2001. This document was obtained
9583 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9585 This document is only a draft and is subject to change. (So beware.)
9587 Details regarding the older, non-standard 64-bit format were
9588 determined empirically by examining 64-bit ELF files produced by
9589 the SGI toolchain on an IRIX 6.5 machine.
9591 - Kevin, July 16, 2002
9595 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
9597 LONGEST length
= bfd_get_32 (abfd
, buf
);
9599 if (length
== 0xffffffff)
9601 length
= bfd_get_64 (abfd
, buf
+ 4);
9604 else if (length
== 0)
9606 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9607 length
= bfd_get_64 (abfd
, buf
);
9618 /* Cover function for read_initial_length.
9619 Returns the length of the object at BUF, and stores the size of the
9620 initial length in *BYTES_READ and stores the size that offsets will be in
9622 If the initial length size is not equivalent to that specified in
9623 CU_HEADER then issue a complaint.
9624 This is useful when reading non-comp-unit headers. */
9627 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
9628 const struct comp_unit_head
*cu_header
,
9629 unsigned int *bytes_read
,
9630 unsigned int *offset_size
)
9632 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
9634 gdb_assert (cu_header
->initial_length_size
== 4
9635 || cu_header
->initial_length_size
== 8
9636 || cu_header
->initial_length_size
== 12);
9638 if (cu_header
->initial_length_size
!= *bytes_read
)
9639 complaint (&symfile_complaints
,
9640 _("intermixed 32-bit and 64-bit DWARF sections"));
9642 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
9646 /* Read an offset from the data stream. The size of the offset is
9647 given by cu_header->offset_size. */
9650 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
9651 unsigned int *bytes_read
)
9653 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
9655 *bytes_read
= cu_header
->offset_size
;
9659 /* Read an offset from the data stream. */
9662 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
9666 switch (offset_size
)
9669 retval
= bfd_get_32 (abfd
, buf
);
9672 retval
= bfd_get_64 (abfd
, buf
);
9675 internal_error (__FILE__
, __LINE__
,
9676 _("read_offset_1: bad switch [in module %s]"),
9677 bfd_get_filename (abfd
));
9684 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
9686 /* If the size of a host char is 8 bits, we can return a pointer
9687 to the buffer, otherwise we have to copy the data to a buffer
9688 allocated on the temporary obstack. */
9689 gdb_assert (HOST_CHAR_BIT
== 8);
9694 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9696 /* If the size of a host char is 8 bits, we can return a pointer
9697 to the string, otherwise we have to copy the string to a buffer
9698 allocated on the temporary obstack. */
9699 gdb_assert (HOST_CHAR_BIT
== 8);
9702 *bytes_read_ptr
= 1;
9705 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
9706 return (char *) buf
;
9710 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
9711 const struct comp_unit_head
*cu_header
,
9712 unsigned int *bytes_read_ptr
)
9714 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
9716 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
9717 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
9719 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9720 bfd_get_filename (abfd
));
9723 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
9725 error (_("DW_FORM_strp pointing outside of "
9726 ".debug_str section [in module %s]"),
9727 bfd_get_filename (abfd
));
9730 gdb_assert (HOST_CHAR_BIT
== 8);
9731 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
9733 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
9736 static unsigned long
9737 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9739 unsigned long result
;
9740 unsigned int num_read
;
9750 byte
= bfd_get_8 (abfd
, buf
);
9753 result
|= ((unsigned long)(byte
& 127) << shift
);
9754 if ((byte
& 128) == 0)
9760 *bytes_read_ptr
= num_read
;
9765 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9768 int i
, shift
, num_read
;
9777 byte
= bfd_get_8 (abfd
, buf
);
9780 result
|= ((long)(byte
& 127) << shift
);
9782 if ((byte
& 128) == 0)
9787 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
9788 result
|= -(((long)1) << shift
);
9789 *bytes_read_ptr
= num_read
;
9793 /* Return a pointer to just past the end of an LEB128 number in BUF. */
9796 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
9802 byte
= bfd_get_8 (abfd
, buf
);
9804 if ((byte
& 128) == 0)
9810 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
9817 cu
->language
= language_c
;
9819 case DW_LANG_C_plus_plus
:
9820 cu
->language
= language_cplus
;
9823 cu
->language
= language_d
;
9825 case DW_LANG_Fortran77
:
9826 case DW_LANG_Fortran90
:
9827 case DW_LANG_Fortran95
:
9828 cu
->language
= language_fortran
;
9830 case DW_LANG_Mips_Assembler
:
9831 cu
->language
= language_asm
;
9834 cu
->language
= language_java
;
9838 cu
->language
= language_ada
;
9840 case DW_LANG_Modula2
:
9841 cu
->language
= language_m2
;
9843 case DW_LANG_Pascal83
:
9844 cu
->language
= language_pascal
;
9847 cu
->language
= language_objc
;
9849 case DW_LANG_Cobol74
:
9850 case DW_LANG_Cobol85
:
9852 cu
->language
= language_minimal
;
9855 cu
->language_defn
= language_def (cu
->language
);
9858 /* Return the named attribute or NULL if not there. */
9860 static struct attribute
*
9861 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
9864 struct attribute
*spec
= NULL
;
9866 for (i
= 0; i
< die
->num_attrs
; ++i
)
9868 if (die
->attrs
[i
].name
== name
)
9869 return &die
->attrs
[i
];
9870 if (die
->attrs
[i
].name
== DW_AT_specification
9871 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
9872 spec
= &die
->attrs
[i
];
9877 die
= follow_die_ref (die
, spec
, &cu
);
9878 return dwarf2_attr (die
, name
, cu
);
9884 /* Return the named attribute or NULL if not there,
9885 but do not follow DW_AT_specification, etc.
9886 This is for use in contexts where we're reading .debug_types dies.
9887 Following DW_AT_specification, DW_AT_abstract_origin will take us
9888 back up the chain, and we want to go down. */
9890 static struct attribute
*
9891 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
9892 struct dwarf2_cu
*cu
)
9896 for (i
= 0; i
< die
->num_attrs
; ++i
)
9897 if (die
->attrs
[i
].name
== name
)
9898 return &die
->attrs
[i
];
9903 /* Return non-zero iff the attribute NAME is defined for the given DIE,
9904 and holds a non-zero value. This function should only be used for
9905 DW_FORM_flag or DW_FORM_flag_present attributes. */
9908 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
9910 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
9912 return (attr
&& DW_UNSND (attr
));
9916 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
9918 /* A DIE is a declaration if it has a DW_AT_declaration attribute
9919 which value is non-zero. However, we have to be careful with
9920 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
9921 (via dwarf2_flag_true_p) follows this attribute. So we may
9922 end up accidently finding a declaration attribute that belongs
9923 to a different DIE referenced by the specification attribute,
9924 even though the given DIE does not have a declaration attribute. */
9925 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
9926 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
9929 /* Return the die giving the specification for DIE, if there is
9930 one. *SPEC_CU is the CU containing DIE on input, and the CU
9931 containing the return value on output. If there is no
9932 specification, but there is an abstract origin, that is
9935 static struct die_info
*
9936 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
9938 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
9941 if (spec_attr
== NULL
)
9942 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
9944 if (spec_attr
== NULL
)
9947 return follow_die_ref (die
, spec_attr
, spec_cu
);
9950 /* Free the line_header structure *LH, and any arrays and strings it
9952 NOTE: This is also used as a "cleanup" function. */
9955 free_line_header (struct line_header
*lh
)
9957 if (lh
->standard_opcode_lengths
)
9958 xfree (lh
->standard_opcode_lengths
);
9960 /* Remember that all the lh->file_names[i].name pointers are
9961 pointers into debug_line_buffer, and don't need to be freed. */
9963 xfree (lh
->file_names
);
9965 /* Similarly for the include directory names. */
9966 if (lh
->include_dirs
)
9967 xfree (lh
->include_dirs
);
9972 /* Add an entry to LH's include directory table. */
9975 add_include_dir (struct line_header
*lh
, char *include_dir
)
9977 /* Grow the array if necessary. */
9978 if (lh
->include_dirs_size
== 0)
9980 lh
->include_dirs_size
= 1; /* for testing */
9981 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
9982 * sizeof (*lh
->include_dirs
));
9984 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
9986 lh
->include_dirs_size
*= 2;
9987 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
9988 (lh
->include_dirs_size
9989 * sizeof (*lh
->include_dirs
)));
9992 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
9995 /* Add an entry to LH's file name table. */
9998 add_file_name (struct line_header
*lh
,
10000 unsigned int dir_index
,
10001 unsigned int mod_time
,
10002 unsigned int length
)
10004 struct file_entry
*fe
;
10006 /* Grow the array if necessary. */
10007 if (lh
->file_names_size
== 0)
10009 lh
->file_names_size
= 1; /* for testing */
10010 lh
->file_names
= xmalloc (lh
->file_names_size
10011 * sizeof (*lh
->file_names
));
10013 else if (lh
->num_file_names
>= lh
->file_names_size
)
10015 lh
->file_names_size
*= 2;
10016 lh
->file_names
= xrealloc (lh
->file_names
,
10017 (lh
->file_names_size
10018 * sizeof (*lh
->file_names
)));
10021 fe
= &lh
->file_names
[lh
->num_file_names
++];
10023 fe
->dir_index
= dir_index
;
10024 fe
->mod_time
= mod_time
;
10025 fe
->length
= length
;
10026 fe
->included_p
= 0;
10030 /* Read the statement program header starting at OFFSET in
10031 .debug_line, according to the endianness of ABFD. Return a pointer
10032 to a struct line_header, allocated using xmalloc.
10034 NOTE: the strings in the include directory and file name tables of
10035 the returned object point into debug_line_buffer, and must not be
10038 static struct line_header
*
10039 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10040 struct dwarf2_cu
*cu
)
10042 struct cleanup
*back_to
;
10043 struct line_header
*lh
;
10044 gdb_byte
*line_ptr
;
10045 unsigned int bytes_read
, offset_size
;
10047 char *cur_dir
, *cur_file
;
10049 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10050 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10052 complaint (&symfile_complaints
, _("missing .debug_line section"));
10056 /* Make sure that at least there's room for the total_length field.
10057 That could be 12 bytes long, but we're just going to fudge that. */
10058 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10060 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10064 lh
= xmalloc (sizeof (*lh
));
10065 memset (lh
, 0, sizeof (*lh
));
10066 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10069 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10071 /* Read in the header. */
10073 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10074 &bytes_read
, &offset_size
);
10075 line_ptr
+= bytes_read
;
10076 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10077 + dwarf2_per_objfile
->line
.size
))
10079 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10082 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10083 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10085 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10086 line_ptr
+= offset_size
;
10087 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10089 if (lh
->version
>= 4)
10091 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10095 lh
->maximum_ops_per_instruction
= 1;
10097 if (lh
->maximum_ops_per_instruction
== 0)
10099 lh
->maximum_ops_per_instruction
= 1;
10100 complaint (&symfile_complaints
,
10101 _("invalid maximum_ops_per_instruction "
10102 "in `.debug_line' section"));
10105 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10107 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10109 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10111 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10113 lh
->standard_opcode_lengths
10114 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10116 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10117 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10119 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10123 /* Read directory table. */
10124 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10126 line_ptr
+= bytes_read
;
10127 add_include_dir (lh
, cur_dir
);
10129 line_ptr
+= bytes_read
;
10131 /* Read file name table. */
10132 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10134 unsigned int dir_index
, mod_time
, length
;
10136 line_ptr
+= bytes_read
;
10137 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10138 line_ptr
+= bytes_read
;
10139 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10140 line_ptr
+= bytes_read
;
10141 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10142 line_ptr
+= bytes_read
;
10144 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10146 line_ptr
+= bytes_read
;
10147 lh
->statement_program_start
= line_ptr
;
10149 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
10150 + dwarf2_per_objfile
->line
.size
))
10151 complaint (&symfile_complaints
,
10152 _("line number info header doesn't "
10153 "fit in `.debug_line' section"));
10155 discard_cleanups (back_to
);
10159 /* This function exists to work around a bug in certain compilers
10160 (particularly GCC 2.95), in which the first line number marker of a
10161 function does not show up until after the prologue, right before
10162 the second line number marker. This function shifts ADDRESS down
10163 to the beginning of the function if necessary, and is called on
10164 addresses passed to record_line. */
10167 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
10169 struct function_range
*fn
;
10171 /* Find the function_range containing address. */
10175 if (!cu
->cached_fn
)
10176 cu
->cached_fn
= cu
->first_fn
;
10178 fn
= cu
->cached_fn
;
10180 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10186 while (fn
&& fn
!= cu
->cached_fn
)
10187 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10197 if (address
!= fn
->lowpc
)
10198 complaint (&symfile_complaints
,
10199 _("misplaced first line number at 0x%lx for '%s'"),
10200 (unsigned long) address
, fn
->name
);
10205 /* Subroutine of dwarf_decode_lines to simplify it.
10206 Return the file name of the psymtab for included file FILE_INDEX
10207 in line header LH of PST.
10208 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10209 If space for the result is malloc'd, it will be freed by a cleanup.
10210 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10213 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10214 const struct partial_symtab
*pst
,
10215 const char *comp_dir
)
10217 const struct file_entry fe
= lh
->file_names
[file_index
];
10218 char *include_name
= fe
.name
;
10219 char *include_name_to_compare
= include_name
;
10220 char *dir_name
= NULL
;
10221 const char *pst_filename
;
10222 char *copied_name
= NULL
;
10226 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10228 if (!IS_ABSOLUTE_PATH (include_name
)
10229 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10231 /* Avoid creating a duplicate psymtab for PST.
10232 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10233 Before we do the comparison, however, we need to account
10234 for DIR_NAME and COMP_DIR.
10235 First prepend dir_name (if non-NULL). If we still don't
10236 have an absolute path prepend comp_dir (if non-NULL).
10237 However, the directory we record in the include-file's
10238 psymtab does not contain COMP_DIR (to match the
10239 corresponding symtab(s)).
10244 bash$ gcc -g ./hello.c
10245 include_name = "hello.c"
10247 DW_AT_comp_dir = comp_dir = "/tmp"
10248 DW_AT_name = "./hello.c" */
10250 if (dir_name
!= NULL
)
10252 include_name
= concat (dir_name
, SLASH_STRING
,
10253 include_name
, (char *)NULL
);
10254 include_name_to_compare
= include_name
;
10255 make_cleanup (xfree
, include_name
);
10257 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10259 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10260 include_name
, (char *)NULL
);
10264 pst_filename
= pst
->filename
;
10265 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10267 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
10268 pst_filename
, (char *)NULL
);
10269 pst_filename
= copied_name
;
10272 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
10274 if (include_name_to_compare
!= include_name
)
10275 xfree (include_name_to_compare
);
10276 if (copied_name
!= NULL
)
10277 xfree (copied_name
);
10281 return include_name
;
10284 /* Decode the Line Number Program (LNP) for the given line_header
10285 structure and CU. The actual information extracted and the type
10286 of structures created from the LNP depends on the value of PST.
10288 1. If PST is NULL, then this procedure uses the data from the program
10289 to create all necessary symbol tables, and their linetables.
10291 2. If PST is not NULL, this procedure reads the program to determine
10292 the list of files included by the unit represented by PST, and
10293 builds all the associated partial symbol tables.
10295 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10296 It is used for relative paths in the line table.
10297 NOTE: When processing partial symtabs (pst != NULL),
10298 comp_dir == pst->dirname.
10300 NOTE: It is important that psymtabs have the same file name (via strcmp)
10301 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10302 symtab we don't use it in the name of the psymtabs we create.
10303 E.g. expand_line_sal requires this when finding psymtabs to expand.
10304 A good testcase for this is mb-inline.exp. */
10307 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
10308 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10310 gdb_byte
*line_ptr
, *extended_end
;
10311 gdb_byte
*line_end
;
10312 unsigned int bytes_read
, extended_len
;
10313 unsigned char op_code
, extended_op
, adj_opcode
;
10314 CORE_ADDR baseaddr
;
10315 struct objfile
*objfile
= cu
->objfile
;
10316 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10317 const int decode_for_pst_p
= (pst
!= NULL
);
10318 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10320 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10322 line_ptr
= lh
->statement_program_start
;
10323 line_end
= lh
->statement_program_end
;
10325 /* Read the statement sequences until there's nothing left. */
10326 while (line_ptr
< line_end
)
10328 /* state machine registers */
10329 CORE_ADDR address
= 0;
10330 unsigned int file
= 1;
10331 unsigned int line
= 1;
10332 unsigned int column
= 0;
10333 int is_stmt
= lh
->default_is_stmt
;
10334 int basic_block
= 0;
10335 int end_sequence
= 0;
10337 unsigned char op_index
= 0;
10339 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10341 /* Start a subfile for the current file of the state machine. */
10342 /* lh->include_dirs and lh->file_names are 0-based, but the
10343 directory and file name numbers in the statement program
10345 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10349 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10351 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10354 /* Decode the table. */
10355 while (!end_sequence
)
10357 op_code
= read_1_byte (abfd
, line_ptr
);
10359 if (line_ptr
> line_end
)
10361 dwarf2_debug_line_missing_end_sequence_complaint ();
10365 if (op_code
>= lh
->opcode_base
)
10367 /* Special operand. */
10368 adj_opcode
= op_code
- lh
->opcode_base
;
10369 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10370 / lh
->maximum_ops_per_instruction
)
10371 * lh
->minimum_instruction_length
);
10372 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10373 % lh
->maximum_ops_per_instruction
);
10374 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10375 if (lh
->num_file_names
< file
|| file
== 0)
10376 dwarf2_debug_line_missing_file_complaint ();
10377 /* For now we ignore lines not starting on an
10378 instruction boundary. */
10379 else if (op_index
== 0)
10381 lh
->file_names
[file
- 1].included_p
= 1;
10382 if (!decode_for_pst_p
&& is_stmt
)
10384 if (last_subfile
!= current_subfile
)
10386 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10388 record_line (last_subfile
, 0, addr
);
10389 last_subfile
= current_subfile
;
10391 /* Append row to matrix using current values. */
10392 addr
= check_cu_functions (address
, cu
);
10393 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10394 record_line (current_subfile
, line
, addr
);
10399 else switch (op_code
)
10401 case DW_LNS_extended_op
:
10402 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
10404 line_ptr
+= bytes_read
;
10405 extended_end
= line_ptr
+ extended_len
;
10406 extended_op
= read_1_byte (abfd
, line_ptr
);
10408 switch (extended_op
)
10410 case DW_LNE_end_sequence
:
10413 case DW_LNE_set_address
:
10414 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10416 line_ptr
+= bytes_read
;
10417 address
+= baseaddr
;
10419 case DW_LNE_define_file
:
10422 unsigned int dir_index
, mod_time
, length
;
10424 cur_file
= read_direct_string (abfd
, line_ptr
,
10426 line_ptr
+= bytes_read
;
10428 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10429 line_ptr
+= bytes_read
;
10431 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10432 line_ptr
+= bytes_read
;
10434 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10435 line_ptr
+= bytes_read
;
10436 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10439 case DW_LNE_set_discriminator
:
10440 /* The discriminator is not interesting to the debugger;
10442 line_ptr
= extended_end
;
10445 complaint (&symfile_complaints
,
10446 _("mangled .debug_line section"));
10449 /* Make sure that we parsed the extended op correctly. If e.g.
10450 we expected a different address size than the producer used,
10451 we may have read the wrong number of bytes. */
10452 if (line_ptr
!= extended_end
)
10454 complaint (&symfile_complaints
,
10455 _("mangled .debug_line section"));
10460 if (lh
->num_file_names
< file
|| file
== 0)
10461 dwarf2_debug_line_missing_file_complaint ();
10464 lh
->file_names
[file
- 1].included_p
= 1;
10465 if (!decode_for_pst_p
&& is_stmt
)
10467 if (last_subfile
!= current_subfile
)
10469 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10471 record_line (last_subfile
, 0, addr
);
10472 last_subfile
= current_subfile
;
10474 addr
= check_cu_functions (address
, cu
);
10475 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10476 record_line (current_subfile
, line
, addr
);
10481 case DW_LNS_advance_pc
:
10484 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10486 address
+= (((op_index
+ adjust
)
10487 / lh
->maximum_ops_per_instruction
)
10488 * lh
->minimum_instruction_length
);
10489 op_index
= ((op_index
+ adjust
)
10490 % lh
->maximum_ops_per_instruction
);
10491 line_ptr
+= bytes_read
;
10494 case DW_LNS_advance_line
:
10495 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
10496 line_ptr
+= bytes_read
;
10498 case DW_LNS_set_file
:
10500 /* The arrays lh->include_dirs and lh->file_names are
10501 0-based, but the directory and file name numbers in
10502 the statement program are 1-based. */
10503 struct file_entry
*fe
;
10506 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10507 line_ptr
+= bytes_read
;
10508 if (lh
->num_file_names
< file
|| file
== 0)
10509 dwarf2_debug_line_missing_file_complaint ();
10512 fe
= &lh
->file_names
[file
- 1];
10514 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10515 if (!decode_for_pst_p
)
10517 last_subfile
= current_subfile
;
10518 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10523 case DW_LNS_set_column
:
10524 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10525 line_ptr
+= bytes_read
;
10527 case DW_LNS_negate_stmt
:
10528 is_stmt
= (!is_stmt
);
10530 case DW_LNS_set_basic_block
:
10533 /* Add to the address register of the state machine the
10534 address increment value corresponding to special opcode
10535 255. I.e., this value is scaled by the minimum
10536 instruction length since special opcode 255 would have
10537 scaled the the increment. */
10538 case DW_LNS_const_add_pc
:
10540 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
10542 address
+= (((op_index
+ adjust
)
10543 / lh
->maximum_ops_per_instruction
)
10544 * lh
->minimum_instruction_length
);
10545 op_index
= ((op_index
+ adjust
)
10546 % lh
->maximum_ops_per_instruction
);
10549 case DW_LNS_fixed_advance_pc
:
10550 address
+= read_2_bytes (abfd
, line_ptr
);
10556 /* Unknown standard opcode, ignore it. */
10559 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
10561 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10562 line_ptr
+= bytes_read
;
10567 if (lh
->num_file_names
< file
|| file
== 0)
10568 dwarf2_debug_line_missing_file_complaint ();
10571 lh
->file_names
[file
- 1].included_p
= 1;
10572 if (!decode_for_pst_p
)
10574 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10575 record_line (current_subfile
, 0, addr
);
10580 if (decode_for_pst_p
)
10584 /* Now that we're done scanning the Line Header Program, we can
10585 create the psymtab of each included file. */
10586 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
10587 if (lh
->file_names
[file_index
].included_p
== 1)
10589 char *include_name
=
10590 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
10591 if (include_name
!= NULL
)
10592 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
10597 /* Make sure a symtab is created for every file, even files
10598 which contain only variables (i.e. no code with associated
10602 struct file_entry
*fe
;
10604 for (i
= 0; i
< lh
->num_file_names
; i
++)
10608 fe
= &lh
->file_names
[i
];
10610 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10611 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10613 /* Skip the main file; we don't need it, and it must be
10614 allocated last, so that it will show up before the
10615 non-primary symtabs in the objfile's symtab list. */
10616 if (current_subfile
== first_subfile
)
10619 if (current_subfile
->symtab
== NULL
)
10620 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
10622 fe
->symtab
= current_subfile
->symtab
;
10627 /* Start a subfile for DWARF. FILENAME is the name of the file and
10628 DIRNAME the name of the source directory which contains FILENAME
10629 or NULL if not known. COMP_DIR is the compilation directory for the
10630 linetable's compilation unit or NULL if not known.
10631 This routine tries to keep line numbers from identical absolute and
10632 relative file names in a common subfile.
10634 Using the `list' example from the GDB testsuite, which resides in
10635 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10636 of /srcdir/list0.c yields the following debugging information for list0.c:
10638 DW_AT_name: /srcdir/list0.c
10639 DW_AT_comp_dir: /compdir
10640 files.files[0].name: list0.h
10641 files.files[0].dir: /srcdir
10642 files.files[1].name: list0.c
10643 files.files[1].dir: /srcdir
10645 The line number information for list0.c has to end up in a single
10646 subfile, so that `break /srcdir/list0.c:1' works as expected.
10647 start_subfile will ensure that this happens provided that we pass the
10648 concatenation of files.files[1].dir and files.files[1].name as the
10652 dwarf2_start_subfile (char *filename
, const char *dirname
,
10653 const char *comp_dir
)
10657 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10658 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10659 second argument to start_subfile. To be consistent, we do the
10660 same here. In order not to lose the line information directory,
10661 we concatenate it to the filename when it makes sense.
10662 Note that the Dwarf3 standard says (speaking of filenames in line
10663 information): ``The directory index is ignored for file names
10664 that represent full path names''. Thus ignoring dirname in the
10665 `else' branch below isn't an issue. */
10667 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
10668 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
10670 fullname
= filename
;
10672 start_subfile (fullname
, comp_dir
);
10674 if (fullname
!= filename
)
10679 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
10680 struct dwarf2_cu
*cu
)
10682 struct objfile
*objfile
= cu
->objfile
;
10683 struct comp_unit_head
*cu_header
= &cu
->header
;
10685 /* NOTE drow/2003-01-30: There used to be a comment and some special
10686 code here to turn a symbol with DW_AT_external and a
10687 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10688 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10689 with some versions of binutils) where shared libraries could have
10690 relocations against symbols in their debug information - the
10691 minimal symbol would have the right address, but the debug info
10692 would not. It's no longer necessary, because we will explicitly
10693 apply relocations when we read in the debug information now. */
10695 /* A DW_AT_location attribute with no contents indicates that a
10696 variable has been optimized away. */
10697 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
10699 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10703 /* Handle one degenerate form of location expression specially, to
10704 preserve GDB's previous behavior when section offsets are
10705 specified. If this is just a DW_OP_addr then mark this symbol
10708 if (attr_form_is_block (attr
)
10709 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
10710 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
10712 unsigned int dummy
;
10714 SYMBOL_VALUE_ADDRESS (sym
) =
10715 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
10716 SYMBOL_CLASS (sym
) = LOC_STATIC
;
10717 fixup_symbol_section (sym
, objfile
);
10718 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
10719 SYMBOL_SECTION (sym
));
10723 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
10724 expression evaluator, and use LOC_COMPUTED only when necessary
10725 (i.e. when the value of a register or memory location is
10726 referenced, or a thread-local block, etc.). Then again, it might
10727 not be worthwhile. I'm assuming that it isn't unless performance
10728 or memory numbers show me otherwise. */
10730 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
10731 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10734 /* Given a pointer to a DWARF information entry, figure out if we need
10735 to make a symbol table entry for it, and if so, create a new entry
10736 and return a pointer to it.
10737 If TYPE is NULL, determine symbol type from the die, otherwise
10738 used the passed type.
10739 If SPACE is not NULL, use it to hold the new symbol. If it is
10740 NULL, allocate a new symbol on the objfile's obstack. */
10742 static struct symbol
*
10743 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
10744 struct symbol
*space
)
10746 struct objfile
*objfile
= cu
->objfile
;
10747 struct symbol
*sym
= NULL
;
10749 struct attribute
*attr
= NULL
;
10750 struct attribute
*attr2
= NULL
;
10751 CORE_ADDR baseaddr
;
10752 struct pending
**list_to_add
= NULL
;
10754 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10756 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10758 name
= dwarf2_name (die
, cu
);
10761 const char *linkagename
;
10762 int suppress_add
= 0;
10767 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
10768 OBJSTAT (objfile
, n_syms
++);
10770 /* Cache this symbol's name and the name's demangled form (if any). */
10771 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
10772 linkagename
= dwarf2_physname (name
, die
, cu
);
10773 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
10775 /* Fortran does not have mangling standard and the mangling does differ
10776 between gfortran, iFort etc. */
10777 if (cu
->language
== language_fortran
10778 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
10779 symbol_set_demangled_name (&(sym
->ginfo
),
10780 (char *) dwarf2_full_name (name
, die
, cu
),
10783 /* Default assumptions.
10784 Use the passed type or decode it from the die. */
10785 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10786 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10788 SYMBOL_TYPE (sym
) = type
;
10790 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
10791 attr
= dwarf2_attr (die
,
10792 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
10796 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
10799 attr
= dwarf2_attr (die
,
10800 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
10804 int file_index
= DW_UNSND (attr
);
10806 if (cu
->line_header
== NULL
10807 || file_index
> cu
->line_header
->num_file_names
)
10808 complaint (&symfile_complaints
,
10809 _("file index out of range"));
10810 else if (file_index
> 0)
10812 struct file_entry
*fe
;
10814 fe
= &cu
->line_header
->file_names
[file_index
- 1];
10815 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
10822 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10825 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
10827 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
10828 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
10829 SYMBOL_CLASS (sym
) = LOC_LABEL
;
10830 add_symbol_to_list (sym
, cu
->list_in_scope
);
10832 case DW_TAG_subprogram
:
10833 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10835 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10836 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10837 if ((attr2
&& (DW_UNSND (attr2
) != 0))
10838 || cu
->language
== language_ada
)
10840 /* Subprograms marked external are stored as a global symbol.
10841 Ada subprograms, whether marked external or not, are always
10842 stored as a global symbol, because we want to be able to
10843 access them globally. For instance, we want to be able
10844 to break on a nested subprogram without having to
10845 specify the context. */
10846 list_to_add
= &global_symbols
;
10850 list_to_add
= cu
->list_in_scope
;
10853 case DW_TAG_inlined_subroutine
:
10854 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10856 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10857 SYMBOL_INLINED (sym
) = 1;
10858 /* Do not add the symbol to any lists. It will be found via
10859 BLOCK_FUNCTION from the blockvector. */
10861 case DW_TAG_template_value_param
:
10863 /* Fall through. */
10864 case DW_TAG_constant
:
10865 case DW_TAG_variable
:
10866 case DW_TAG_member
:
10867 /* Compilation with minimal debug info may result in variables
10868 with missing type entries. Change the misleading `void' type
10869 to something sensible. */
10870 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
10872 = objfile_type (objfile
)->nodebug_data_symbol
;
10874 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10875 /* In the case of DW_TAG_member, we should only be called for
10876 static const members. */
10877 if (die
->tag
== DW_TAG_member
)
10879 /* dwarf2_add_field uses die_is_declaration,
10880 so we do the same. */
10881 gdb_assert (die_is_declaration (die
, cu
));
10886 dwarf2_const_value (attr
, sym
, cu
);
10887 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10890 if (attr2
&& (DW_UNSND (attr2
) != 0))
10891 list_to_add
= &global_symbols
;
10893 list_to_add
= cu
->list_in_scope
;
10897 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10900 var_decode_location (attr
, sym
, cu
);
10901 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10902 if (SYMBOL_CLASS (sym
) == LOC_STATIC
10903 && SYMBOL_VALUE_ADDRESS (sym
) == 0
10904 && !dwarf2_per_objfile
->has_section_at_zero
)
10906 /* When a static variable is eliminated by the linker,
10907 the corresponding debug information is not stripped
10908 out, but the variable address is set to null;
10909 do not add such variables into symbol table. */
10911 else if (attr2
&& (DW_UNSND (attr2
) != 0))
10913 /* Workaround gfortran PR debug/40040 - it uses
10914 DW_AT_location for variables in -fPIC libraries which may
10915 get overriden by other libraries/executable and get
10916 a different address. Resolve it by the minimal symbol
10917 which may come from inferior's executable using copy
10918 relocation. Make this workaround only for gfortran as for
10919 other compilers GDB cannot guess the minimal symbol
10920 Fortran mangling kind. */
10921 if (cu
->language
== language_fortran
&& die
->parent
10922 && die
->parent
->tag
== DW_TAG_module
10924 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
10925 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10927 /* A variable with DW_AT_external is never static,
10928 but it may be block-scoped. */
10929 list_to_add
= (cu
->list_in_scope
== &file_symbols
10930 ? &global_symbols
: cu
->list_in_scope
);
10933 list_to_add
= cu
->list_in_scope
;
10937 /* We do not know the address of this symbol.
10938 If it is an external symbol and we have type information
10939 for it, enter the symbol as a LOC_UNRESOLVED symbol.
10940 The address of the variable will then be determined from
10941 the minimal symbol table whenever the variable is
10943 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10944 if (attr2
&& (DW_UNSND (attr2
) != 0)
10945 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
10947 /* A variable with DW_AT_external is never static, but it
10948 may be block-scoped. */
10949 list_to_add
= (cu
->list_in_scope
== &file_symbols
10950 ? &global_symbols
: cu
->list_in_scope
);
10952 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10954 else if (!die_is_declaration (die
, cu
))
10956 /* Use the default LOC_OPTIMIZED_OUT class. */
10957 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
10959 list_to_add
= cu
->list_in_scope
;
10963 case DW_TAG_formal_parameter
:
10964 /* If we are inside a function, mark this as an argument. If
10965 not, we might be looking at an argument to an inlined function
10966 when we do not have enough information to show inlined frames;
10967 pretend it's a local variable in that case so that the user can
10969 if (context_stack_depth
> 0
10970 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
10971 SYMBOL_IS_ARGUMENT (sym
) = 1;
10972 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10975 var_decode_location (attr
, sym
, cu
);
10977 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10980 dwarf2_const_value (attr
, sym
, cu
);
10982 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
10983 if (attr
&& DW_UNSND (attr
))
10985 struct type
*ref_type
;
10987 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
10988 SYMBOL_TYPE (sym
) = ref_type
;
10991 list_to_add
= cu
->list_in_scope
;
10993 case DW_TAG_unspecified_parameters
:
10994 /* From varargs functions; gdb doesn't seem to have any
10995 interest in this information, so just ignore it for now.
10998 case DW_TAG_template_type_param
:
11000 /* Fall through. */
11001 case DW_TAG_class_type
:
11002 case DW_TAG_interface_type
:
11003 case DW_TAG_structure_type
:
11004 case DW_TAG_union_type
:
11005 case DW_TAG_set_type
:
11006 case DW_TAG_enumeration_type
:
11007 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11008 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11011 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11012 really ever be static objects: otherwise, if you try
11013 to, say, break of a class's method and you're in a file
11014 which doesn't mention that class, it won't work unless
11015 the check for all static symbols in lookup_symbol_aux
11016 saves you. See the OtherFileClass tests in
11017 gdb.c++/namespace.exp. */
11021 list_to_add
= (cu
->list_in_scope
== &file_symbols
11022 && (cu
->language
== language_cplus
11023 || cu
->language
== language_java
)
11024 ? &global_symbols
: cu
->list_in_scope
);
11026 /* The semantics of C++ state that "struct foo {
11027 ... }" also defines a typedef for "foo". A Java
11028 class declaration also defines a typedef for the
11030 if (cu
->language
== language_cplus
11031 || cu
->language
== language_java
11032 || cu
->language
== language_ada
)
11034 /* The symbol's name is already allocated along
11035 with this objfile, so we don't need to
11036 duplicate it for the type. */
11037 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11038 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11043 case DW_TAG_typedef
:
11044 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11045 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11046 list_to_add
= cu
->list_in_scope
;
11048 case DW_TAG_base_type
:
11049 case DW_TAG_subrange_type
:
11050 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11051 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11052 list_to_add
= cu
->list_in_scope
;
11054 case DW_TAG_enumerator
:
11055 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11058 dwarf2_const_value (attr
, sym
, cu
);
11061 /* NOTE: carlton/2003-11-10: See comment above in the
11062 DW_TAG_class_type, etc. block. */
11064 list_to_add
= (cu
->list_in_scope
== &file_symbols
11065 && (cu
->language
== language_cplus
11066 || cu
->language
== language_java
)
11067 ? &global_symbols
: cu
->list_in_scope
);
11070 case DW_TAG_namespace
:
11071 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11072 list_to_add
= &global_symbols
;
11075 /* Not a tag we recognize. Hopefully we aren't processing
11076 trash data, but since we must specifically ignore things
11077 we don't recognize, there is nothing else we should do at
11079 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11080 dwarf_tag_name (die
->tag
));
11086 sym
->hash_next
= objfile
->template_symbols
;
11087 objfile
->template_symbols
= sym
;
11088 list_to_add
= NULL
;
11091 if (list_to_add
!= NULL
)
11092 add_symbol_to_list (sym
, list_to_add
);
11094 /* For the benefit of old versions of GCC, check for anonymous
11095 namespaces based on the demangled name. */
11096 if (!processing_has_namespace_info
11097 && cu
->language
== language_cplus
)
11098 cp_scan_for_anonymous_namespaces (sym
);
11103 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11105 static struct symbol
*
11106 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11108 return new_symbol_full (die
, type
, cu
, NULL
);
11111 /* Given an attr with a DW_FORM_dataN value in host byte order,
11112 zero-extend it as appropriate for the symbol's type. The DWARF
11113 standard (v4) is not entirely clear about the meaning of using
11114 DW_FORM_dataN for a constant with a signed type, where the type is
11115 wider than the data. The conclusion of a discussion on the DWARF
11116 list was that this is unspecified. We choose to always zero-extend
11117 because that is the interpretation long in use by GCC. */
11120 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11121 const char *name
, struct obstack
*obstack
,
11122 struct dwarf2_cu
*cu
, long *value
, int bits
)
11124 struct objfile
*objfile
= cu
->objfile
;
11125 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11126 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11127 LONGEST l
= DW_UNSND (attr
);
11129 if (bits
< sizeof (*value
) * 8)
11131 l
&= ((LONGEST
) 1 << bits
) - 1;
11134 else if (bits
== sizeof (*value
) * 8)
11138 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11139 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11146 /* Read a constant value from an attribute. Either set *VALUE, or if
11147 the value does not fit in *VALUE, set *BYTES - either already
11148 allocated on the objfile obstack, or newly allocated on OBSTACK,
11149 or, set *BATON, if we translated the constant to a location
11153 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11154 const char *name
, struct obstack
*obstack
,
11155 struct dwarf2_cu
*cu
,
11156 long *value
, gdb_byte
**bytes
,
11157 struct dwarf2_locexpr_baton
**baton
)
11159 struct objfile
*objfile
= cu
->objfile
;
11160 struct comp_unit_head
*cu_header
= &cu
->header
;
11161 struct dwarf_block
*blk
;
11162 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
11163 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
11169 switch (attr
->form
)
11175 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
11176 dwarf2_const_value_length_mismatch_complaint (name
,
11177 cu_header
->addr_size
,
11178 TYPE_LENGTH (type
));
11179 /* Symbols of this form are reasonably rare, so we just
11180 piggyback on the existing location code rather than writing
11181 a new implementation of symbol_computed_ops. */
11182 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11183 sizeof (struct dwarf2_locexpr_baton
));
11184 (*baton
)->per_cu
= cu
->per_cu
;
11185 gdb_assert ((*baton
)->per_cu
);
11187 (*baton
)->size
= 2 + cu_header
->addr_size
;
11188 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11189 (*baton
)->data
= data
;
11191 data
[0] = DW_OP_addr
;
11192 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11193 byte_order
, DW_ADDR (attr
));
11194 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11197 case DW_FORM_string
:
11199 /* DW_STRING is already allocated on the objfile obstack, point
11201 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11203 case DW_FORM_block1
:
11204 case DW_FORM_block2
:
11205 case DW_FORM_block4
:
11206 case DW_FORM_block
:
11207 case DW_FORM_exprloc
:
11208 blk
= DW_BLOCK (attr
);
11209 if (TYPE_LENGTH (type
) != blk
->size
)
11210 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11211 TYPE_LENGTH (type
));
11212 *bytes
= blk
->data
;
11215 /* The DW_AT_const_value attributes are supposed to carry the
11216 symbol's value "represented as it would be on the target
11217 architecture." By the time we get here, it's already been
11218 converted to host endianness, so we just need to sign- or
11219 zero-extend it as appropriate. */
11220 case DW_FORM_data1
:
11221 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11222 obstack
, cu
, value
, 8);
11224 case DW_FORM_data2
:
11225 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11226 obstack
, cu
, value
, 16);
11228 case DW_FORM_data4
:
11229 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11230 obstack
, cu
, value
, 32);
11232 case DW_FORM_data8
:
11233 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11234 obstack
, cu
, value
, 64);
11237 case DW_FORM_sdata
:
11238 *value
= DW_SND (attr
);
11241 case DW_FORM_udata
:
11242 *value
= DW_UNSND (attr
);
11246 complaint (&symfile_complaints
,
11247 _("unsupported const value attribute form: '%s'"),
11248 dwarf_form_name (attr
->form
));
11255 /* Copy constant value from an attribute to a symbol. */
11258 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11259 struct dwarf2_cu
*cu
)
11261 struct objfile
*objfile
= cu
->objfile
;
11262 struct comp_unit_head
*cu_header
= &cu
->header
;
11265 struct dwarf2_locexpr_baton
*baton
;
11267 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11268 SYMBOL_PRINT_NAME (sym
),
11269 &objfile
->objfile_obstack
, cu
,
11270 &value
, &bytes
, &baton
);
11274 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11275 SYMBOL_LOCATION_BATON (sym
) = baton
;
11276 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11278 else if (bytes
!= NULL
)
11280 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11281 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11285 SYMBOL_VALUE (sym
) = value
;
11286 SYMBOL_CLASS (sym
) = LOC_CONST
;
11290 /* Return the type of the die in question using its DW_AT_type attribute. */
11292 static struct type
*
11293 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11295 struct attribute
*type_attr
;
11297 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11300 /* A missing DW_AT_type represents a void type. */
11301 return objfile_type (cu
->objfile
)->builtin_void
;
11304 return lookup_die_type (die
, type_attr
, cu
);
11307 /* True iff CU's producer generates GNAT Ada auxiliary information
11308 that allows to find parallel types through that information instead
11309 of having to do expensive parallel lookups by type name. */
11312 need_gnat_info (struct dwarf2_cu
*cu
)
11314 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11315 of GNAT produces this auxiliary information, without any indication
11316 that it is produced. Part of enhancing the FSF version of GNAT
11317 to produce that information will be to put in place an indicator
11318 that we can use in order to determine whether the descriptive type
11319 info is available or not. One suggestion that has been made is
11320 to use a new attribute, attached to the CU die. For now, assume
11321 that the descriptive type info is not available. */
11325 /* Return the auxiliary type of the die in question using its
11326 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11327 attribute is not present. */
11329 static struct type
*
11330 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11332 struct attribute
*type_attr
;
11334 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11338 return lookup_die_type (die
, type_attr
, cu
);
11341 /* If DIE has a descriptive_type attribute, then set the TYPE's
11342 descriptive type accordingly. */
11345 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11346 struct dwarf2_cu
*cu
)
11348 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11350 if (descriptive_type
)
11352 ALLOCATE_GNAT_AUX_TYPE (type
);
11353 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11357 /* Return the containing type of the die in question using its
11358 DW_AT_containing_type attribute. */
11360 static struct type
*
11361 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11363 struct attribute
*type_attr
;
11365 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11367 error (_("Dwarf Error: Problem turning containing type into gdb type "
11368 "[in module %s]"), cu
->objfile
->name
);
11370 return lookup_die_type (die
, type_attr
, cu
);
11373 /* Look up the type of DIE in CU using its type attribute ATTR.
11374 If there is no type substitute an error marker. */
11376 static struct type
*
11377 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11378 struct dwarf2_cu
*cu
)
11380 struct type
*this_type
;
11382 /* First see if we have it cached. */
11384 if (is_ref_attr (attr
))
11386 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11388 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11390 else if (attr
->form
== DW_FORM_sig8
)
11392 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11393 struct dwarf2_cu
*sig_cu
;
11394 unsigned int offset
;
11396 /* sig_type will be NULL if the signatured type is missing from
11398 if (sig_type
== NULL
)
11399 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11400 "at 0x%x [in module %s]"),
11401 die
->offset
, cu
->objfile
->name
);
11403 gdb_assert (sig_type
->per_cu
.from_debug_types
);
11404 offset
= sig_type
->offset
+ sig_type
->type_offset
;
11405 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11409 dump_die_for_error (die
);
11410 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11411 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11414 /* If not cached we need to read it in. */
11416 if (this_type
== NULL
)
11418 struct die_info
*type_die
;
11419 struct dwarf2_cu
*type_cu
= cu
;
11421 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11422 /* If the type is cached, we should have found it above. */
11423 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
11424 this_type
= read_type_die_1 (type_die
, type_cu
);
11427 /* If we still don't have a type use an error marker. */
11429 if (this_type
== NULL
)
11431 char *message
, *saved
;
11433 /* read_type_die already issued a complaint. */
11434 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11438 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
11439 message
, strlen (message
));
11442 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
11448 /* Return the type in DIE, CU.
11449 Returns NULL for invalid types.
11451 This first does a lookup in the appropriate type_hash table,
11452 and only reads the die in if necessary.
11454 NOTE: This can be called when reading in partial or full symbols. */
11456 static struct type
*
11457 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11459 struct type
*this_type
;
11461 this_type
= get_die_type (die
, cu
);
11465 return read_type_die_1 (die
, cu
);
11468 /* Read the type in DIE, CU.
11469 Returns NULL for invalid types. */
11471 static struct type
*
11472 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
11474 struct type
*this_type
= NULL
;
11478 case DW_TAG_class_type
:
11479 case DW_TAG_interface_type
:
11480 case DW_TAG_structure_type
:
11481 case DW_TAG_union_type
:
11482 this_type
= read_structure_type (die
, cu
);
11484 case DW_TAG_enumeration_type
:
11485 this_type
= read_enumeration_type (die
, cu
);
11487 case DW_TAG_subprogram
:
11488 case DW_TAG_subroutine_type
:
11489 case DW_TAG_inlined_subroutine
:
11490 this_type
= read_subroutine_type (die
, cu
);
11492 case DW_TAG_array_type
:
11493 this_type
= read_array_type (die
, cu
);
11495 case DW_TAG_set_type
:
11496 this_type
= read_set_type (die
, cu
);
11498 case DW_TAG_pointer_type
:
11499 this_type
= read_tag_pointer_type (die
, cu
);
11501 case DW_TAG_ptr_to_member_type
:
11502 this_type
= read_tag_ptr_to_member_type (die
, cu
);
11504 case DW_TAG_reference_type
:
11505 this_type
= read_tag_reference_type (die
, cu
);
11507 case DW_TAG_const_type
:
11508 this_type
= read_tag_const_type (die
, cu
);
11510 case DW_TAG_volatile_type
:
11511 this_type
= read_tag_volatile_type (die
, cu
);
11513 case DW_TAG_string_type
:
11514 this_type
= read_tag_string_type (die
, cu
);
11516 case DW_TAG_typedef
:
11517 this_type
= read_typedef (die
, cu
);
11519 case DW_TAG_subrange_type
:
11520 this_type
= read_subrange_type (die
, cu
);
11522 case DW_TAG_base_type
:
11523 this_type
= read_base_type (die
, cu
);
11525 case DW_TAG_unspecified_type
:
11526 this_type
= read_unspecified_type (die
, cu
);
11528 case DW_TAG_namespace
:
11529 this_type
= read_namespace_type (die
, cu
);
11531 case DW_TAG_module
:
11532 this_type
= read_module_type (die
, cu
);
11535 complaint (&symfile_complaints
,
11536 _("unexpected tag in read_type_die: '%s'"),
11537 dwarf_tag_name (die
->tag
));
11544 /* See if we can figure out if the class lives in a namespace. We do
11545 this by looking for a member function; its demangled name will
11546 contain namespace info, if there is any.
11547 Return the computed name or NULL.
11548 Space for the result is allocated on the objfile's obstack.
11549 This is the full-die version of guess_partial_die_structure_name.
11550 In this case we know DIE has no useful parent. */
11553 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11555 struct die_info
*spec_die
;
11556 struct dwarf2_cu
*spec_cu
;
11557 struct die_info
*child
;
11560 spec_die
= die_specification (die
, &spec_cu
);
11561 if (spec_die
!= NULL
)
11567 for (child
= die
->child
;
11569 child
= child
->sibling
)
11571 if (child
->tag
== DW_TAG_subprogram
)
11573 struct attribute
*attr
;
11575 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
11577 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
11581 = language_class_name_from_physname (cu
->language_defn
,
11585 if (actual_name
!= NULL
)
11587 char *die_name
= dwarf2_name (die
, cu
);
11589 if (die_name
!= NULL
11590 && strcmp (die_name
, actual_name
) != 0)
11592 /* Strip off the class name from the full name.
11593 We want the prefix. */
11594 int die_name_len
= strlen (die_name
);
11595 int actual_name_len
= strlen (actual_name
);
11597 /* Test for '::' as a sanity check. */
11598 if (actual_name_len
> die_name_len
+ 2
11599 && actual_name
[actual_name_len
11600 - die_name_len
- 1] == ':')
11602 obsavestring (actual_name
,
11603 actual_name_len
- die_name_len
- 2,
11604 &cu
->objfile
->objfile_obstack
);
11607 xfree (actual_name
);
11616 /* Return the name of the namespace/class that DIE is defined within,
11617 or "" if we can't tell. The caller should not xfree the result.
11619 For example, if we're within the method foo() in the following
11629 then determine_prefix on foo's die will return "N::C". */
11632 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
11634 struct die_info
*parent
, *spec_die
;
11635 struct dwarf2_cu
*spec_cu
;
11636 struct type
*parent_type
;
11638 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
11639 && cu
->language
!= language_fortran
)
11642 /* We have to be careful in the presence of DW_AT_specification.
11643 For example, with GCC 3.4, given the code
11647 // Definition of N::foo.
11651 then we'll have a tree of DIEs like this:
11653 1: DW_TAG_compile_unit
11654 2: DW_TAG_namespace // N
11655 3: DW_TAG_subprogram // declaration of N::foo
11656 4: DW_TAG_subprogram // definition of N::foo
11657 DW_AT_specification // refers to die #3
11659 Thus, when processing die #4, we have to pretend that we're in
11660 the context of its DW_AT_specification, namely the contex of die
11663 spec_die
= die_specification (die
, &spec_cu
);
11664 if (spec_die
== NULL
)
11665 parent
= die
->parent
;
11668 parent
= spec_die
->parent
;
11672 if (parent
== NULL
)
11674 else if (parent
->building_fullname
)
11677 const char *parent_name
;
11679 /* It has been seen on RealView 2.2 built binaries,
11680 DW_TAG_template_type_param types actually _defined_ as
11681 children of the parent class:
11684 template class <class Enum> Class{};
11685 Class<enum E> class_e;
11687 1: DW_TAG_class_type (Class)
11688 2: DW_TAG_enumeration_type (E)
11689 3: DW_TAG_enumerator (enum1:0)
11690 3: DW_TAG_enumerator (enum2:1)
11692 2: DW_TAG_template_type_param
11693 DW_AT_type DW_FORM_ref_udata (E)
11695 Besides being broken debug info, it can put GDB into an
11696 infinite loop. Consider:
11698 When we're building the full name for Class<E>, we'll start
11699 at Class, and go look over its template type parameters,
11700 finding E. We'll then try to build the full name of E, and
11701 reach here. We're now trying to build the full name of E,
11702 and look over the parent DIE for containing scope. In the
11703 broken case, if we followed the parent DIE of E, we'd again
11704 find Class, and once again go look at its template type
11705 arguments, etc., etc. Simply don't consider such parent die
11706 as source-level parent of this die (it can't be, the language
11707 doesn't allow it), and break the loop here. */
11708 name
= dwarf2_name (die
, cu
);
11709 parent_name
= dwarf2_name (parent
, cu
);
11710 complaint (&symfile_complaints
,
11711 _("template param type '%s' defined within parent '%s'"),
11712 name
? name
: "<unknown>",
11713 parent_name
? parent_name
: "<unknown>");
11717 switch (parent
->tag
)
11719 case DW_TAG_namespace
:
11720 parent_type
= read_type_die (parent
, cu
);
11721 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
11722 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
11723 Work around this problem here. */
11724 if (cu
->language
== language_cplus
11725 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
11727 /* We give a name to even anonymous namespaces. */
11728 return TYPE_TAG_NAME (parent_type
);
11729 case DW_TAG_class_type
:
11730 case DW_TAG_interface_type
:
11731 case DW_TAG_structure_type
:
11732 case DW_TAG_union_type
:
11733 case DW_TAG_module
:
11734 parent_type
= read_type_die (parent
, cu
);
11735 if (TYPE_TAG_NAME (parent_type
) != NULL
)
11736 return TYPE_TAG_NAME (parent_type
);
11738 /* An anonymous structure is only allowed non-static data
11739 members; no typedefs, no member functions, et cetera.
11740 So it does not need a prefix. */
11742 case DW_TAG_compile_unit
:
11743 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
11744 if (cu
->language
== language_cplus
11745 && dwarf2_per_objfile
->types
.asection
!= NULL
11746 && die
->child
!= NULL
11747 && (die
->tag
== DW_TAG_class_type
11748 || die
->tag
== DW_TAG_structure_type
11749 || die
->tag
== DW_TAG_union_type
))
11751 char *name
= guess_full_die_structure_name (die
, cu
);
11757 return determine_prefix (parent
, cu
);
11761 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
11762 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
11763 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
11764 an obconcat, otherwise allocate storage for the result. The CU argument is
11765 used to determine the language and hence, the appropriate separator. */
11767 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
11770 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
11771 int physname
, struct dwarf2_cu
*cu
)
11773 const char *lead
= "";
11776 if (suffix
== NULL
|| suffix
[0] == '\0'
11777 || prefix
== NULL
|| prefix
[0] == '\0')
11779 else if (cu
->language
== language_java
)
11781 else if (cu
->language
== language_fortran
&& physname
)
11783 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
11784 DW_AT_MIPS_linkage_name is preferred and used instead. */
11792 if (prefix
== NULL
)
11794 if (suffix
== NULL
)
11800 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
11802 strcpy (retval
, lead
);
11803 strcat (retval
, prefix
);
11804 strcat (retval
, sep
);
11805 strcat (retval
, suffix
);
11810 /* We have an obstack. */
11811 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
11815 /* Return sibling of die, NULL if no sibling. */
11817 static struct die_info
*
11818 sibling_die (struct die_info
*die
)
11820 return die
->sibling
;
11823 /* Get name of a die, return NULL if not found. */
11826 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
11827 struct obstack
*obstack
)
11829 if (name
&& cu
->language
== language_cplus
)
11831 char *canon_name
= cp_canonicalize_string (name
);
11833 if (canon_name
!= NULL
)
11835 if (strcmp (canon_name
, name
) != 0)
11836 name
= obsavestring (canon_name
, strlen (canon_name
),
11838 xfree (canon_name
);
11845 /* Get name of a die, return NULL if not found. */
11848 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11850 struct attribute
*attr
;
11852 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11853 if (!attr
|| !DW_STRING (attr
))
11858 case DW_TAG_compile_unit
:
11859 /* Compilation units have a DW_AT_name that is a filename, not
11860 a source language identifier. */
11861 case DW_TAG_enumeration_type
:
11862 case DW_TAG_enumerator
:
11863 /* These tags always have simple identifiers already; no need
11864 to canonicalize them. */
11865 return DW_STRING (attr
);
11867 case DW_TAG_subprogram
:
11868 /* Java constructors will all be named "<init>", so return
11869 the class name when we see this special case. */
11870 if (cu
->language
== language_java
11871 && DW_STRING (attr
) != NULL
11872 && strcmp (DW_STRING (attr
), "<init>") == 0)
11874 struct dwarf2_cu
*spec_cu
= cu
;
11875 struct die_info
*spec_die
;
11877 /* GCJ will output '<init>' for Java constructor names.
11878 For this special case, return the name of the parent class. */
11880 /* GCJ may output suprogram DIEs with AT_specification set.
11881 If so, use the name of the specified DIE. */
11882 spec_die
= die_specification (die
, &spec_cu
);
11883 if (spec_die
!= NULL
)
11884 return dwarf2_name (spec_die
, spec_cu
);
11889 if (die
->tag
== DW_TAG_class_type
)
11890 return dwarf2_name (die
, cu
);
11892 while (die
->tag
!= DW_TAG_compile_unit
);
11896 case DW_TAG_class_type
:
11897 case DW_TAG_interface_type
:
11898 case DW_TAG_structure_type
:
11899 case DW_TAG_union_type
:
11900 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
11901 structures or unions. These were of the form "._%d" in GCC 4.1,
11902 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
11903 and GCC 4.4. We work around this problem by ignoring these. */
11904 if (strncmp (DW_STRING (attr
), "._", 2) == 0
11905 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
11913 if (!DW_STRING_IS_CANONICAL (attr
))
11916 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
11917 &cu
->objfile
->objfile_obstack
);
11918 DW_STRING_IS_CANONICAL (attr
) = 1;
11920 return DW_STRING (attr
);
11923 /* Return the die that this die in an extension of, or NULL if there
11924 is none. *EXT_CU is the CU containing DIE on input, and the CU
11925 containing the return value on output. */
11927 static struct die_info
*
11928 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
11930 struct attribute
*attr
;
11932 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
11936 return follow_die_ref (die
, attr
, ext_cu
);
11939 /* Convert a DIE tag into its string name. */
11942 dwarf_tag_name (unsigned tag
)
11946 case DW_TAG_padding
:
11947 return "DW_TAG_padding";
11948 case DW_TAG_array_type
:
11949 return "DW_TAG_array_type";
11950 case DW_TAG_class_type
:
11951 return "DW_TAG_class_type";
11952 case DW_TAG_entry_point
:
11953 return "DW_TAG_entry_point";
11954 case DW_TAG_enumeration_type
:
11955 return "DW_TAG_enumeration_type";
11956 case DW_TAG_formal_parameter
:
11957 return "DW_TAG_formal_parameter";
11958 case DW_TAG_imported_declaration
:
11959 return "DW_TAG_imported_declaration";
11961 return "DW_TAG_label";
11962 case DW_TAG_lexical_block
:
11963 return "DW_TAG_lexical_block";
11964 case DW_TAG_member
:
11965 return "DW_TAG_member";
11966 case DW_TAG_pointer_type
:
11967 return "DW_TAG_pointer_type";
11968 case DW_TAG_reference_type
:
11969 return "DW_TAG_reference_type";
11970 case DW_TAG_compile_unit
:
11971 return "DW_TAG_compile_unit";
11972 case DW_TAG_string_type
:
11973 return "DW_TAG_string_type";
11974 case DW_TAG_structure_type
:
11975 return "DW_TAG_structure_type";
11976 case DW_TAG_subroutine_type
:
11977 return "DW_TAG_subroutine_type";
11978 case DW_TAG_typedef
:
11979 return "DW_TAG_typedef";
11980 case DW_TAG_union_type
:
11981 return "DW_TAG_union_type";
11982 case DW_TAG_unspecified_parameters
:
11983 return "DW_TAG_unspecified_parameters";
11984 case DW_TAG_variant
:
11985 return "DW_TAG_variant";
11986 case DW_TAG_common_block
:
11987 return "DW_TAG_common_block";
11988 case DW_TAG_common_inclusion
:
11989 return "DW_TAG_common_inclusion";
11990 case DW_TAG_inheritance
:
11991 return "DW_TAG_inheritance";
11992 case DW_TAG_inlined_subroutine
:
11993 return "DW_TAG_inlined_subroutine";
11994 case DW_TAG_module
:
11995 return "DW_TAG_module";
11996 case DW_TAG_ptr_to_member_type
:
11997 return "DW_TAG_ptr_to_member_type";
11998 case DW_TAG_set_type
:
11999 return "DW_TAG_set_type";
12000 case DW_TAG_subrange_type
:
12001 return "DW_TAG_subrange_type";
12002 case DW_TAG_with_stmt
:
12003 return "DW_TAG_with_stmt";
12004 case DW_TAG_access_declaration
:
12005 return "DW_TAG_access_declaration";
12006 case DW_TAG_base_type
:
12007 return "DW_TAG_base_type";
12008 case DW_TAG_catch_block
:
12009 return "DW_TAG_catch_block";
12010 case DW_TAG_const_type
:
12011 return "DW_TAG_const_type";
12012 case DW_TAG_constant
:
12013 return "DW_TAG_constant";
12014 case DW_TAG_enumerator
:
12015 return "DW_TAG_enumerator";
12016 case DW_TAG_file_type
:
12017 return "DW_TAG_file_type";
12018 case DW_TAG_friend
:
12019 return "DW_TAG_friend";
12020 case DW_TAG_namelist
:
12021 return "DW_TAG_namelist";
12022 case DW_TAG_namelist_item
:
12023 return "DW_TAG_namelist_item";
12024 case DW_TAG_packed_type
:
12025 return "DW_TAG_packed_type";
12026 case DW_TAG_subprogram
:
12027 return "DW_TAG_subprogram";
12028 case DW_TAG_template_type_param
:
12029 return "DW_TAG_template_type_param";
12030 case DW_TAG_template_value_param
:
12031 return "DW_TAG_template_value_param";
12032 case DW_TAG_thrown_type
:
12033 return "DW_TAG_thrown_type";
12034 case DW_TAG_try_block
:
12035 return "DW_TAG_try_block";
12036 case DW_TAG_variant_part
:
12037 return "DW_TAG_variant_part";
12038 case DW_TAG_variable
:
12039 return "DW_TAG_variable";
12040 case DW_TAG_volatile_type
:
12041 return "DW_TAG_volatile_type";
12042 case DW_TAG_dwarf_procedure
:
12043 return "DW_TAG_dwarf_procedure";
12044 case DW_TAG_restrict_type
:
12045 return "DW_TAG_restrict_type";
12046 case DW_TAG_interface_type
:
12047 return "DW_TAG_interface_type";
12048 case DW_TAG_namespace
:
12049 return "DW_TAG_namespace";
12050 case DW_TAG_imported_module
:
12051 return "DW_TAG_imported_module";
12052 case DW_TAG_unspecified_type
:
12053 return "DW_TAG_unspecified_type";
12054 case DW_TAG_partial_unit
:
12055 return "DW_TAG_partial_unit";
12056 case DW_TAG_imported_unit
:
12057 return "DW_TAG_imported_unit";
12058 case DW_TAG_condition
:
12059 return "DW_TAG_condition";
12060 case DW_TAG_shared_type
:
12061 return "DW_TAG_shared_type";
12062 case DW_TAG_type_unit
:
12063 return "DW_TAG_type_unit";
12064 case DW_TAG_MIPS_loop
:
12065 return "DW_TAG_MIPS_loop";
12066 case DW_TAG_HP_array_descriptor
:
12067 return "DW_TAG_HP_array_descriptor";
12068 case DW_TAG_format_label
:
12069 return "DW_TAG_format_label";
12070 case DW_TAG_function_template
:
12071 return "DW_TAG_function_template";
12072 case DW_TAG_class_template
:
12073 return "DW_TAG_class_template";
12074 case DW_TAG_GNU_BINCL
:
12075 return "DW_TAG_GNU_BINCL";
12076 case DW_TAG_GNU_EINCL
:
12077 return "DW_TAG_GNU_EINCL";
12078 case DW_TAG_upc_shared_type
:
12079 return "DW_TAG_upc_shared_type";
12080 case DW_TAG_upc_strict_type
:
12081 return "DW_TAG_upc_strict_type";
12082 case DW_TAG_upc_relaxed_type
:
12083 return "DW_TAG_upc_relaxed_type";
12084 case DW_TAG_PGI_kanji_type
:
12085 return "DW_TAG_PGI_kanji_type";
12086 case DW_TAG_PGI_interface_block
:
12087 return "DW_TAG_PGI_interface_block";
12089 return "DW_TAG_<unknown>";
12093 /* Convert a DWARF attribute code into its string name. */
12096 dwarf_attr_name (unsigned attr
)
12100 case DW_AT_sibling
:
12101 return "DW_AT_sibling";
12102 case DW_AT_location
:
12103 return "DW_AT_location";
12105 return "DW_AT_name";
12106 case DW_AT_ordering
:
12107 return "DW_AT_ordering";
12108 case DW_AT_subscr_data
:
12109 return "DW_AT_subscr_data";
12110 case DW_AT_byte_size
:
12111 return "DW_AT_byte_size";
12112 case DW_AT_bit_offset
:
12113 return "DW_AT_bit_offset";
12114 case DW_AT_bit_size
:
12115 return "DW_AT_bit_size";
12116 case DW_AT_element_list
:
12117 return "DW_AT_element_list";
12118 case DW_AT_stmt_list
:
12119 return "DW_AT_stmt_list";
12121 return "DW_AT_low_pc";
12122 case DW_AT_high_pc
:
12123 return "DW_AT_high_pc";
12124 case DW_AT_language
:
12125 return "DW_AT_language";
12127 return "DW_AT_member";
12129 return "DW_AT_discr";
12130 case DW_AT_discr_value
:
12131 return "DW_AT_discr_value";
12132 case DW_AT_visibility
:
12133 return "DW_AT_visibility";
12135 return "DW_AT_import";
12136 case DW_AT_string_length
:
12137 return "DW_AT_string_length";
12138 case DW_AT_common_reference
:
12139 return "DW_AT_common_reference";
12140 case DW_AT_comp_dir
:
12141 return "DW_AT_comp_dir";
12142 case DW_AT_const_value
:
12143 return "DW_AT_const_value";
12144 case DW_AT_containing_type
:
12145 return "DW_AT_containing_type";
12146 case DW_AT_default_value
:
12147 return "DW_AT_default_value";
12149 return "DW_AT_inline";
12150 case DW_AT_is_optional
:
12151 return "DW_AT_is_optional";
12152 case DW_AT_lower_bound
:
12153 return "DW_AT_lower_bound";
12154 case DW_AT_producer
:
12155 return "DW_AT_producer";
12156 case DW_AT_prototyped
:
12157 return "DW_AT_prototyped";
12158 case DW_AT_return_addr
:
12159 return "DW_AT_return_addr";
12160 case DW_AT_start_scope
:
12161 return "DW_AT_start_scope";
12162 case DW_AT_bit_stride
:
12163 return "DW_AT_bit_stride";
12164 case DW_AT_upper_bound
:
12165 return "DW_AT_upper_bound";
12166 case DW_AT_abstract_origin
:
12167 return "DW_AT_abstract_origin";
12168 case DW_AT_accessibility
:
12169 return "DW_AT_accessibility";
12170 case DW_AT_address_class
:
12171 return "DW_AT_address_class";
12172 case DW_AT_artificial
:
12173 return "DW_AT_artificial";
12174 case DW_AT_base_types
:
12175 return "DW_AT_base_types";
12176 case DW_AT_calling_convention
:
12177 return "DW_AT_calling_convention";
12179 return "DW_AT_count";
12180 case DW_AT_data_member_location
:
12181 return "DW_AT_data_member_location";
12182 case DW_AT_decl_column
:
12183 return "DW_AT_decl_column";
12184 case DW_AT_decl_file
:
12185 return "DW_AT_decl_file";
12186 case DW_AT_decl_line
:
12187 return "DW_AT_decl_line";
12188 case DW_AT_declaration
:
12189 return "DW_AT_declaration";
12190 case DW_AT_discr_list
:
12191 return "DW_AT_discr_list";
12192 case DW_AT_encoding
:
12193 return "DW_AT_encoding";
12194 case DW_AT_external
:
12195 return "DW_AT_external";
12196 case DW_AT_frame_base
:
12197 return "DW_AT_frame_base";
12199 return "DW_AT_friend";
12200 case DW_AT_identifier_case
:
12201 return "DW_AT_identifier_case";
12202 case DW_AT_macro_info
:
12203 return "DW_AT_macro_info";
12204 case DW_AT_namelist_items
:
12205 return "DW_AT_namelist_items";
12206 case DW_AT_priority
:
12207 return "DW_AT_priority";
12208 case DW_AT_segment
:
12209 return "DW_AT_segment";
12210 case DW_AT_specification
:
12211 return "DW_AT_specification";
12212 case DW_AT_static_link
:
12213 return "DW_AT_static_link";
12215 return "DW_AT_type";
12216 case DW_AT_use_location
:
12217 return "DW_AT_use_location";
12218 case DW_AT_variable_parameter
:
12219 return "DW_AT_variable_parameter";
12220 case DW_AT_virtuality
:
12221 return "DW_AT_virtuality";
12222 case DW_AT_vtable_elem_location
:
12223 return "DW_AT_vtable_elem_location";
12224 /* DWARF 3 values. */
12225 case DW_AT_allocated
:
12226 return "DW_AT_allocated";
12227 case DW_AT_associated
:
12228 return "DW_AT_associated";
12229 case DW_AT_data_location
:
12230 return "DW_AT_data_location";
12231 case DW_AT_byte_stride
:
12232 return "DW_AT_byte_stride";
12233 case DW_AT_entry_pc
:
12234 return "DW_AT_entry_pc";
12235 case DW_AT_use_UTF8
:
12236 return "DW_AT_use_UTF8";
12237 case DW_AT_extension
:
12238 return "DW_AT_extension";
12240 return "DW_AT_ranges";
12241 case DW_AT_trampoline
:
12242 return "DW_AT_trampoline";
12243 case DW_AT_call_column
:
12244 return "DW_AT_call_column";
12245 case DW_AT_call_file
:
12246 return "DW_AT_call_file";
12247 case DW_AT_call_line
:
12248 return "DW_AT_call_line";
12249 case DW_AT_description
:
12250 return "DW_AT_description";
12251 case DW_AT_binary_scale
:
12252 return "DW_AT_binary_scale";
12253 case DW_AT_decimal_scale
:
12254 return "DW_AT_decimal_scale";
12256 return "DW_AT_small";
12257 case DW_AT_decimal_sign
:
12258 return "DW_AT_decimal_sign";
12259 case DW_AT_digit_count
:
12260 return "DW_AT_digit_count";
12261 case DW_AT_picture_string
:
12262 return "DW_AT_picture_string";
12263 case DW_AT_mutable
:
12264 return "DW_AT_mutable";
12265 case DW_AT_threads_scaled
:
12266 return "DW_AT_threads_scaled";
12267 case DW_AT_explicit
:
12268 return "DW_AT_explicit";
12269 case DW_AT_object_pointer
:
12270 return "DW_AT_object_pointer";
12271 case DW_AT_endianity
:
12272 return "DW_AT_endianity";
12273 case DW_AT_elemental
:
12274 return "DW_AT_elemental";
12276 return "DW_AT_pure";
12277 case DW_AT_recursive
:
12278 return "DW_AT_recursive";
12279 /* DWARF 4 values. */
12280 case DW_AT_signature
:
12281 return "DW_AT_signature";
12282 case DW_AT_linkage_name
:
12283 return "DW_AT_linkage_name";
12284 /* SGI/MIPS extensions. */
12285 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12286 case DW_AT_MIPS_fde
:
12287 return "DW_AT_MIPS_fde";
12289 case DW_AT_MIPS_loop_begin
:
12290 return "DW_AT_MIPS_loop_begin";
12291 case DW_AT_MIPS_tail_loop_begin
:
12292 return "DW_AT_MIPS_tail_loop_begin";
12293 case DW_AT_MIPS_epilog_begin
:
12294 return "DW_AT_MIPS_epilog_begin";
12295 case DW_AT_MIPS_loop_unroll_factor
:
12296 return "DW_AT_MIPS_loop_unroll_factor";
12297 case DW_AT_MIPS_software_pipeline_depth
:
12298 return "DW_AT_MIPS_software_pipeline_depth";
12299 case DW_AT_MIPS_linkage_name
:
12300 return "DW_AT_MIPS_linkage_name";
12301 case DW_AT_MIPS_stride
:
12302 return "DW_AT_MIPS_stride";
12303 case DW_AT_MIPS_abstract_name
:
12304 return "DW_AT_MIPS_abstract_name";
12305 case DW_AT_MIPS_clone_origin
:
12306 return "DW_AT_MIPS_clone_origin";
12307 case DW_AT_MIPS_has_inlines
:
12308 return "DW_AT_MIPS_has_inlines";
12309 /* HP extensions. */
12310 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12311 case DW_AT_HP_block_index
:
12312 return "DW_AT_HP_block_index";
12314 case DW_AT_HP_unmodifiable
:
12315 return "DW_AT_HP_unmodifiable";
12316 case DW_AT_HP_actuals_stmt_list
:
12317 return "DW_AT_HP_actuals_stmt_list";
12318 case DW_AT_HP_proc_per_section
:
12319 return "DW_AT_HP_proc_per_section";
12320 case DW_AT_HP_raw_data_ptr
:
12321 return "DW_AT_HP_raw_data_ptr";
12322 case DW_AT_HP_pass_by_reference
:
12323 return "DW_AT_HP_pass_by_reference";
12324 case DW_AT_HP_opt_level
:
12325 return "DW_AT_HP_opt_level";
12326 case DW_AT_HP_prof_version_id
:
12327 return "DW_AT_HP_prof_version_id";
12328 case DW_AT_HP_opt_flags
:
12329 return "DW_AT_HP_opt_flags";
12330 case DW_AT_HP_cold_region_low_pc
:
12331 return "DW_AT_HP_cold_region_low_pc";
12332 case DW_AT_HP_cold_region_high_pc
:
12333 return "DW_AT_HP_cold_region_high_pc";
12334 case DW_AT_HP_all_variables_modifiable
:
12335 return "DW_AT_HP_all_variables_modifiable";
12336 case DW_AT_HP_linkage_name
:
12337 return "DW_AT_HP_linkage_name";
12338 case DW_AT_HP_prof_flags
:
12339 return "DW_AT_HP_prof_flags";
12340 /* GNU extensions. */
12341 case DW_AT_sf_names
:
12342 return "DW_AT_sf_names";
12343 case DW_AT_src_info
:
12344 return "DW_AT_src_info";
12345 case DW_AT_mac_info
:
12346 return "DW_AT_mac_info";
12347 case DW_AT_src_coords
:
12348 return "DW_AT_src_coords";
12349 case DW_AT_body_begin
:
12350 return "DW_AT_body_begin";
12351 case DW_AT_body_end
:
12352 return "DW_AT_body_end";
12353 case DW_AT_GNU_vector
:
12354 return "DW_AT_GNU_vector";
12355 case DW_AT_GNU_odr_signature
:
12356 return "DW_AT_GNU_odr_signature";
12357 /* VMS extensions. */
12358 case DW_AT_VMS_rtnbeg_pd_address
:
12359 return "DW_AT_VMS_rtnbeg_pd_address";
12360 /* UPC extension. */
12361 case DW_AT_upc_threads_scaled
:
12362 return "DW_AT_upc_threads_scaled";
12363 /* PGI (STMicroelectronics) extensions. */
12364 case DW_AT_PGI_lbase
:
12365 return "DW_AT_PGI_lbase";
12366 case DW_AT_PGI_soffset
:
12367 return "DW_AT_PGI_soffset";
12368 case DW_AT_PGI_lstride
:
12369 return "DW_AT_PGI_lstride";
12371 return "DW_AT_<unknown>";
12375 /* Convert a DWARF value form code into its string name. */
12378 dwarf_form_name (unsigned form
)
12383 return "DW_FORM_addr";
12384 case DW_FORM_block2
:
12385 return "DW_FORM_block2";
12386 case DW_FORM_block4
:
12387 return "DW_FORM_block4";
12388 case DW_FORM_data2
:
12389 return "DW_FORM_data2";
12390 case DW_FORM_data4
:
12391 return "DW_FORM_data4";
12392 case DW_FORM_data8
:
12393 return "DW_FORM_data8";
12394 case DW_FORM_string
:
12395 return "DW_FORM_string";
12396 case DW_FORM_block
:
12397 return "DW_FORM_block";
12398 case DW_FORM_block1
:
12399 return "DW_FORM_block1";
12400 case DW_FORM_data1
:
12401 return "DW_FORM_data1";
12403 return "DW_FORM_flag";
12404 case DW_FORM_sdata
:
12405 return "DW_FORM_sdata";
12407 return "DW_FORM_strp";
12408 case DW_FORM_udata
:
12409 return "DW_FORM_udata";
12410 case DW_FORM_ref_addr
:
12411 return "DW_FORM_ref_addr";
12413 return "DW_FORM_ref1";
12415 return "DW_FORM_ref2";
12417 return "DW_FORM_ref4";
12419 return "DW_FORM_ref8";
12420 case DW_FORM_ref_udata
:
12421 return "DW_FORM_ref_udata";
12422 case DW_FORM_indirect
:
12423 return "DW_FORM_indirect";
12424 case DW_FORM_sec_offset
:
12425 return "DW_FORM_sec_offset";
12426 case DW_FORM_exprloc
:
12427 return "DW_FORM_exprloc";
12428 case DW_FORM_flag_present
:
12429 return "DW_FORM_flag_present";
12431 return "DW_FORM_sig8";
12433 return "DW_FORM_<unknown>";
12437 /* Convert a DWARF stack opcode into its string name. */
12440 dwarf_stack_op_name (unsigned op
, int def
)
12445 return "DW_OP_addr";
12447 return "DW_OP_deref";
12448 case DW_OP_const1u
:
12449 return "DW_OP_const1u";
12450 case DW_OP_const1s
:
12451 return "DW_OP_const1s";
12452 case DW_OP_const2u
:
12453 return "DW_OP_const2u";
12454 case DW_OP_const2s
:
12455 return "DW_OP_const2s";
12456 case DW_OP_const4u
:
12457 return "DW_OP_const4u";
12458 case DW_OP_const4s
:
12459 return "DW_OP_const4s";
12460 case DW_OP_const8u
:
12461 return "DW_OP_const8u";
12462 case DW_OP_const8s
:
12463 return "DW_OP_const8s";
12465 return "DW_OP_constu";
12467 return "DW_OP_consts";
12469 return "DW_OP_dup";
12471 return "DW_OP_drop";
12473 return "DW_OP_over";
12475 return "DW_OP_pick";
12477 return "DW_OP_swap";
12479 return "DW_OP_rot";
12481 return "DW_OP_xderef";
12483 return "DW_OP_abs";
12485 return "DW_OP_and";
12487 return "DW_OP_div";
12489 return "DW_OP_minus";
12491 return "DW_OP_mod";
12493 return "DW_OP_mul";
12495 return "DW_OP_neg";
12497 return "DW_OP_not";
12501 return "DW_OP_plus";
12502 case DW_OP_plus_uconst
:
12503 return "DW_OP_plus_uconst";
12505 return "DW_OP_shl";
12507 return "DW_OP_shr";
12509 return "DW_OP_shra";
12511 return "DW_OP_xor";
12513 return "DW_OP_bra";
12527 return "DW_OP_skip";
12529 return "DW_OP_lit0";
12531 return "DW_OP_lit1";
12533 return "DW_OP_lit2";
12535 return "DW_OP_lit3";
12537 return "DW_OP_lit4";
12539 return "DW_OP_lit5";
12541 return "DW_OP_lit6";
12543 return "DW_OP_lit7";
12545 return "DW_OP_lit8";
12547 return "DW_OP_lit9";
12549 return "DW_OP_lit10";
12551 return "DW_OP_lit11";
12553 return "DW_OP_lit12";
12555 return "DW_OP_lit13";
12557 return "DW_OP_lit14";
12559 return "DW_OP_lit15";
12561 return "DW_OP_lit16";
12563 return "DW_OP_lit17";
12565 return "DW_OP_lit18";
12567 return "DW_OP_lit19";
12569 return "DW_OP_lit20";
12571 return "DW_OP_lit21";
12573 return "DW_OP_lit22";
12575 return "DW_OP_lit23";
12577 return "DW_OP_lit24";
12579 return "DW_OP_lit25";
12581 return "DW_OP_lit26";
12583 return "DW_OP_lit27";
12585 return "DW_OP_lit28";
12587 return "DW_OP_lit29";
12589 return "DW_OP_lit30";
12591 return "DW_OP_lit31";
12593 return "DW_OP_reg0";
12595 return "DW_OP_reg1";
12597 return "DW_OP_reg2";
12599 return "DW_OP_reg3";
12601 return "DW_OP_reg4";
12603 return "DW_OP_reg5";
12605 return "DW_OP_reg6";
12607 return "DW_OP_reg7";
12609 return "DW_OP_reg8";
12611 return "DW_OP_reg9";
12613 return "DW_OP_reg10";
12615 return "DW_OP_reg11";
12617 return "DW_OP_reg12";
12619 return "DW_OP_reg13";
12621 return "DW_OP_reg14";
12623 return "DW_OP_reg15";
12625 return "DW_OP_reg16";
12627 return "DW_OP_reg17";
12629 return "DW_OP_reg18";
12631 return "DW_OP_reg19";
12633 return "DW_OP_reg20";
12635 return "DW_OP_reg21";
12637 return "DW_OP_reg22";
12639 return "DW_OP_reg23";
12641 return "DW_OP_reg24";
12643 return "DW_OP_reg25";
12645 return "DW_OP_reg26";
12647 return "DW_OP_reg27";
12649 return "DW_OP_reg28";
12651 return "DW_OP_reg29";
12653 return "DW_OP_reg30";
12655 return "DW_OP_reg31";
12657 return "DW_OP_breg0";
12659 return "DW_OP_breg1";
12661 return "DW_OP_breg2";
12663 return "DW_OP_breg3";
12665 return "DW_OP_breg4";
12667 return "DW_OP_breg5";
12669 return "DW_OP_breg6";
12671 return "DW_OP_breg7";
12673 return "DW_OP_breg8";
12675 return "DW_OP_breg9";
12677 return "DW_OP_breg10";
12679 return "DW_OP_breg11";
12681 return "DW_OP_breg12";
12683 return "DW_OP_breg13";
12685 return "DW_OP_breg14";
12687 return "DW_OP_breg15";
12689 return "DW_OP_breg16";
12691 return "DW_OP_breg17";
12693 return "DW_OP_breg18";
12695 return "DW_OP_breg19";
12697 return "DW_OP_breg20";
12699 return "DW_OP_breg21";
12701 return "DW_OP_breg22";
12703 return "DW_OP_breg23";
12705 return "DW_OP_breg24";
12707 return "DW_OP_breg25";
12709 return "DW_OP_breg26";
12711 return "DW_OP_breg27";
12713 return "DW_OP_breg28";
12715 return "DW_OP_breg29";
12717 return "DW_OP_breg30";
12719 return "DW_OP_breg31";
12721 return "DW_OP_regx";
12723 return "DW_OP_fbreg";
12725 return "DW_OP_bregx";
12727 return "DW_OP_piece";
12728 case DW_OP_deref_size
:
12729 return "DW_OP_deref_size";
12730 case DW_OP_xderef_size
:
12731 return "DW_OP_xderef_size";
12733 return "DW_OP_nop";
12734 /* DWARF 3 extensions. */
12735 case DW_OP_push_object_address
:
12736 return "DW_OP_push_object_address";
12738 return "DW_OP_call2";
12740 return "DW_OP_call4";
12741 case DW_OP_call_ref
:
12742 return "DW_OP_call_ref";
12743 case DW_OP_form_tls_address
:
12744 return "DW_OP_form_tls_address";
12745 case DW_OP_call_frame_cfa
:
12746 return "DW_OP_call_frame_cfa";
12747 case DW_OP_bit_piece
:
12748 return "DW_OP_bit_piece";
12749 /* DWARF 4 extensions. */
12750 case DW_OP_implicit_value
:
12751 return "DW_OP_implicit_value";
12752 case DW_OP_stack_value
:
12753 return "DW_OP_stack_value";
12754 /* GNU extensions. */
12755 case DW_OP_GNU_push_tls_address
:
12756 return "DW_OP_GNU_push_tls_address";
12757 case DW_OP_GNU_uninit
:
12758 return "DW_OP_GNU_uninit";
12759 case DW_OP_GNU_implicit_pointer
:
12760 return "DW_OP_GNU_implicit_pointer";
12762 return def
? "OP_<unknown>" : NULL
;
12767 dwarf_bool_name (unsigned mybool
)
12775 /* Convert a DWARF type code into its string name. */
12778 dwarf_type_encoding_name (unsigned enc
)
12783 return "DW_ATE_void";
12784 case DW_ATE_address
:
12785 return "DW_ATE_address";
12786 case DW_ATE_boolean
:
12787 return "DW_ATE_boolean";
12788 case DW_ATE_complex_float
:
12789 return "DW_ATE_complex_float";
12791 return "DW_ATE_float";
12792 case DW_ATE_signed
:
12793 return "DW_ATE_signed";
12794 case DW_ATE_signed_char
:
12795 return "DW_ATE_signed_char";
12796 case DW_ATE_unsigned
:
12797 return "DW_ATE_unsigned";
12798 case DW_ATE_unsigned_char
:
12799 return "DW_ATE_unsigned_char";
12801 case DW_ATE_imaginary_float
:
12802 return "DW_ATE_imaginary_float";
12803 case DW_ATE_packed_decimal
:
12804 return "DW_ATE_packed_decimal";
12805 case DW_ATE_numeric_string
:
12806 return "DW_ATE_numeric_string";
12807 case DW_ATE_edited
:
12808 return "DW_ATE_edited";
12809 case DW_ATE_signed_fixed
:
12810 return "DW_ATE_signed_fixed";
12811 case DW_ATE_unsigned_fixed
:
12812 return "DW_ATE_unsigned_fixed";
12813 case DW_ATE_decimal_float
:
12814 return "DW_ATE_decimal_float";
12817 return "DW_ATE_UTF";
12818 /* HP extensions. */
12819 case DW_ATE_HP_float80
:
12820 return "DW_ATE_HP_float80";
12821 case DW_ATE_HP_complex_float80
:
12822 return "DW_ATE_HP_complex_float80";
12823 case DW_ATE_HP_float128
:
12824 return "DW_ATE_HP_float128";
12825 case DW_ATE_HP_complex_float128
:
12826 return "DW_ATE_HP_complex_float128";
12827 case DW_ATE_HP_floathpintel
:
12828 return "DW_ATE_HP_floathpintel";
12829 case DW_ATE_HP_imaginary_float80
:
12830 return "DW_ATE_HP_imaginary_float80";
12831 case DW_ATE_HP_imaginary_float128
:
12832 return "DW_ATE_HP_imaginary_float128";
12834 return "DW_ATE_<unknown>";
12838 /* Convert a DWARF call frame info operation to its string name. */
12842 dwarf_cfi_name (unsigned cfi_opc
)
12846 case DW_CFA_advance_loc
:
12847 return "DW_CFA_advance_loc";
12848 case DW_CFA_offset
:
12849 return "DW_CFA_offset";
12850 case DW_CFA_restore
:
12851 return "DW_CFA_restore";
12853 return "DW_CFA_nop";
12854 case DW_CFA_set_loc
:
12855 return "DW_CFA_set_loc";
12856 case DW_CFA_advance_loc1
:
12857 return "DW_CFA_advance_loc1";
12858 case DW_CFA_advance_loc2
:
12859 return "DW_CFA_advance_loc2";
12860 case DW_CFA_advance_loc4
:
12861 return "DW_CFA_advance_loc4";
12862 case DW_CFA_offset_extended
:
12863 return "DW_CFA_offset_extended";
12864 case DW_CFA_restore_extended
:
12865 return "DW_CFA_restore_extended";
12866 case DW_CFA_undefined
:
12867 return "DW_CFA_undefined";
12868 case DW_CFA_same_value
:
12869 return "DW_CFA_same_value";
12870 case DW_CFA_register
:
12871 return "DW_CFA_register";
12872 case DW_CFA_remember_state
:
12873 return "DW_CFA_remember_state";
12874 case DW_CFA_restore_state
:
12875 return "DW_CFA_restore_state";
12876 case DW_CFA_def_cfa
:
12877 return "DW_CFA_def_cfa";
12878 case DW_CFA_def_cfa_register
:
12879 return "DW_CFA_def_cfa_register";
12880 case DW_CFA_def_cfa_offset
:
12881 return "DW_CFA_def_cfa_offset";
12883 case DW_CFA_def_cfa_expression
:
12884 return "DW_CFA_def_cfa_expression";
12885 case DW_CFA_expression
:
12886 return "DW_CFA_expression";
12887 case DW_CFA_offset_extended_sf
:
12888 return "DW_CFA_offset_extended_sf";
12889 case DW_CFA_def_cfa_sf
:
12890 return "DW_CFA_def_cfa_sf";
12891 case DW_CFA_def_cfa_offset_sf
:
12892 return "DW_CFA_def_cfa_offset_sf";
12893 case DW_CFA_val_offset
:
12894 return "DW_CFA_val_offset";
12895 case DW_CFA_val_offset_sf
:
12896 return "DW_CFA_val_offset_sf";
12897 case DW_CFA_val_expression
:
12898 return "DW_CFA_val_expression";
12899 /* SGI/MIPS specific. */
12900 case DW_CFA_MIPS_advance_loc8
:
12901 return "DW_CFA_MIPS_advance_loc8";
12902 /* GNU extensions. */
12903 case DW_CFA_GNU_window_save
:
12904 return "DW_CFA_GNU_window_save";
12905 case DW_CFA_GNU_args_size
:
12906 return "DW_CFA_GNU_args_size";
12907 case DW_CFA_GNU_negative_offset_extended
:
12908 return "DW_CFA_GNU_negative_offset_extended";
12910 return "DW_CFA_<unknown>";
12916 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
12920 print_spaces (indent
, f
);
12921 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
12922 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
12924 if (die
->parent
!= NULL
)
12926 print_spaces (indent
, f
);
12927 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
12928 die
->parent
->offset
);
12931 print_spaces (indent
, f
);
12932 fprintf_unfiltered (f
, " has children: %s\n",
12933 dwarf_bool_name (die
->child
!= NULL
));
12935 print_spaces (indent
, f
);
12936 fprintf_unfiltered (f
, " attributes:\n");
12938 for (i
= 0; i
< die
->num_attrs
; ++i
)
12940 print_spaces (indent
, f
);
12941 fprintf_unfiltered (f
, " %s (%s) ",
12942 dwarf_attr_name (die
->attrs
[i
].name
),
12943 dwarf_form_name (die
->attrs
[i
].form
));
12945 switch (die
->attrs
[i
].form
)
12947 case DW_FORM_ref_addr
:
12949 fprintf_unfiltered (f
, "address: ");
12950 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
12952 case DW_FORM_block2
:
12953 case DW_FORM_block4
:
12954 case DW_FORM_block
:
12955 case DW_FORM_block1
:
12956 fprintf_unfiltered (f
, "block: size %d",
12957 DW_BLOCK (&die
->attrs
[i
])->size
);
12959 case DW_FORM_exprloc
:
12960 fprintf_unfiltered (f
, "expression: size %u",
12961 DW_BLOCK (&die
->attrs
[i
])->size
);
12966 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
12967 (long) (DW_ADDR (&die
->attrs
[i
])));
12969 case DW_FORM_data1
:
12970 case DW_FORM_data2
:
12971 case DW_FORM_data4
:
12972 case DW_FORM_data8
:
12973 case DW_FORM_udata
:
12974 case DW_FORM_sdata
:
12975 fprintf_unfiltered (f
, "constant: %s",
12976 pulongest (DW_UNSND (&die
->attrs
[i
])));
12978 case DW_FORM_sec_offset
:
12979 fprintf_unfiltered (f
, "section offset: %s",
12980 pulongest (DW_UNSND (&die
->attrs
[i
])));
12983 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
12984 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
12985 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
12987 fprintf_unfiltered (f
, "signatured type, offset: unknown");
12989 case DW_FORM_string
:
12991 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
12992 DW_STRING (&die
->attrs
[i
])
12993 ? DW_STRING (&die
->attrs
[i
]) : "",
12994 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
12997 if (DW_UNSND (&die
->attrs
[i
]))
12998 fprintf_unfiltered (f
, "flag: TRUE");
13000 fprintf_unfiltered (f
, "flag: FALSE");
13002 case DW_FORM_flag_present
:
13003 fprintf_unfiltered (f
, "flag: TRUE");
13005 case DW_FORM_indirect
:
13006 /* the reader will have reduced the indirect form to
13007 the "base form" so this form should not occur */
13008 fprintf_unfiltered (f
,
13009 "unexpected attribute form: DW_FORM_indirect");
13012 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13013 die
->attrs
[i
].form
);
13016 fprintf_unfiltered (f
, "\n");
13021 dump_die_for_error (struct die_info
*die
)
13023 dump_die_shallow (gdb_stderr
, 0, die
);
13027 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13029 int indent
= level
* 4;
13031 gdb_assert (die
!= NULL
);
13033 if (level
>= max_level
)
13036 dump_die_shallow (f
, indent
, die
);
13038 if (die
->child
!= NULL
)
13040 print_spaces (indent
, f
);
13041 fprintf_unfiltered (f
, " Children:");
13042 if (level
+ 1 < max_level
)
13044 fprintf_unfiltered (f
, "\n");
13045 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13049 fprintf_unfiltered (f
,
13050 " [not printed, max nesting level reached]\n");
13054 if (die
->sibling
!= NULL
&& level
> 0)
13056 dump_die_1 (f
, level
, max_level
, die
->sibling
);
13060 /* This is called from the pdie macro in gdbinit.in.
13061 It's not static so gcc will keep a copy callable from gdb. */
13064 dump_die (struct die_info
*die
, int max_level
)
13066 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
13070 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
13074 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
13080 is_ref_attr (struct attribute
*attr
)
13082 switch (attr
->form
)
13084 case DW_FORM_ref_addr
:
13089 case DW_FORM_ref_udata
:
13096 static unsigned int
13097 dwarf2_get_ref_die_offset (struct attribute
*attr
)
13099 if (is_ref_attr (attr
))
13100 return DW_ADDR (attr
);
13102 complaint (&symfile_complaints
,
13103 _("unsupported die ref attribute form: '%s'"),
13104 dwarf_form_name (attr
->form
));
13108 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13109 * the value held by the attribute is not constant. */
13112 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
13114 if (attr
->form
== DW_FORM_sdata
)
13115 return DW_SND (attr
);
13116 else if (attr
->form
== DW_FORM_udata
13117 || attr
->form
== DW_FORM_data1
13118 || attr
->form
== DW_FORM_data2
13119 || attr
->form
== DW_FORM_data4
13120 || attr
->form
== DW_FORM_data8
)
13121 return DW_UNSND (attr
);
13124 complaint (&symfile_complaints
,
13125 _("Attribute value is not a constant (%s)"),
13126 dwarf_form_name (attr
->form
));
13127 return default_value
;
13131 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13132 unit and add it to our queue.
13133 The result is non-zero if PER_CU was queued, otherwise the result is zero
13134 meaning either PER_CU is already queued or it is already loaded. */
13137 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
13138 struct dwarf2_per_cu_data
*per_cu
)
13140 /* We may arrive here during partial symbol reading, if we need full
13141 DIEs to process an unusual case (e.g. template arguments). Do
13142 not queue PER_CU, just tell our caller to load its DIEs. */
13143 if (dwarf2_per_objfile
->reading_partial_symbols
)
13145 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
13150 /* Mark the dependence relation so that we don't flush PER_CU
13152 dwarf2_add_dependence (this_cu
, per_cu
);
13154 /* If it's already on the queue, we have nothing to do. */
13155 if (per_cu
->queued
)
13158 /* If the compilation unit is already loaded, just mark it as
13160 if (per_cu
->cu
!= NULL
)
13162 per_cu
->cu
->last_used
= 0;
13166 /* Add it to the queue. */
13167 queue_comp_unit (per_cu
, this_cu
->objfile
);
13172 /* Follow reference or signature attribute ATTR of SRC_DIE.
13173 On entry *REF_CU is the CU of SRC_DIE.
13174 On exit *REF_CU is the CU of the result. */
13176 static struct die_info
*
13177 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
13178 struct dwarf2_cu
**ref_cu
)
13180 struct die_info
*die
;
13182 if (is_ref_attr (attr
))
13183 die
= follow_die_ref (src_die
, attr
, ref_cu
);
13184 else if (attr
->form
== DW_FORM_sig8
)
13185 die
= follow_die_sig (src_die
, attr
, ref_cu
);
13188 dump_die_for_error (src_die
);
13189 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13190 (*ref_cu
)->objfile
->name
);
13196 /* Follow reference OFFSET.
13197 On entry *REF_CU is the CU of the source die referencing OFFSET.
13198 On exit *REF_CU is the CU of the result.
13199 Returns NULL if OFFSET is invalid. */
13201 static struct die_info
*
13202 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
13204 struct die_info temp_die
;
13205 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
13207 gdb_assert (cu
->per_cu
!= NULL
);
13211 if (cu
->per_cu
->from_debug_types
)
13213 /* .debug_types CUs cannot reference anything outside their CU.
13214 If they need to, they have to reference a signatured type via
13216 if (! offset_in_cu_p (&cu
->header
, offset
))
13219 else if (! offset_in_cu_p (&cu
->header
, offset
))
13221 struct dwarf2_per_cu_data
*per_cu
;
13223 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
13225 /* If necessary, add it to the queue and load its DIEs. */
13226 if (maybe_queue_comp_unit (cu
, per_cu
))
13227 load_full_comp_unit (per_cu
, cu
->objfile
);
13229 target_cu
= per_cu
->cu
;
13231 else if (cu
->dies
== NULL
)
13233 /* We're loading full DIEs during partial symbol reading. */
13234 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
13235 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
13238 *ref_cu
= target_cu
;
13239 temp_die
.offset
= offset
;
13240 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13243 /* Follow reference attribute ATTR of SRC_DIE.
13244 On entry *REF_CU is the CU of SRC_DIE.
13245 On exit *REF_CU is the CU of the result. */
13247 static struct die_info
*
13248 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13249 struct dwarf2_cu
**ref_cu
)
13251 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13252 struct dwarf2_cu
*cu
= *ref_cu
;
13253 struct die_info
*die
;
13255 die
= follow_die_offset (offset
, ref_cu
);
13257 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13258 "at 0x%x [in module %s]"),
13259 offset
, src_die
->offset
, cu
->objfile
->name
);
13264 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13265 value is intended for DW_OP_call*. */
13267 struct dwarf2_locexpr_baton
13268 dwarf2_fetch_die_location_block (unsigned int offset
,
13269 struct dwarf2_per_cu_data
*per_cu
,
13270 CORE_ADDR (*get_frame_pc
) (void *baton
),
13273 struct dwarf2_cu
*cu
= per_cu
->cu
;
13274 struct die_info
*die
;
13275 struct attribute
*attr
;
13276 struct dwarf2_locexpr_baton retval
;
13278 dw2_setup (per_cu
->objfile
);
13280 die
= follow_die_offset (offset
, &cu
);
13282 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13283 offset
, per_cu
->cu
->objfile
->name
);
13285 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13288 /* DWARF: "If there is no such attribute, then there is no effect.". */
13290 retval
.data
= NULL
;
13293 else if (attr_form_is_section_offset (attr
))
13295 struct dwarf2_loclist_baton loclist_baton
;
13296 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
13299 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
13301 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
13303 retval
.size
= size
;
13307 if (!attr_form_is_block (attr
))
13308 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13309 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13310 offset
, per_cu
->cu
->objfile
->name
);
13312 retval
.data
= DW_BLOCK (attr
)->data
;
13313 retval
.size
= DW_BLOCK (attr
)->size
;
13315 retval
.per_cu
= cu
->per_cu
;
13319 /* Follow the signature attribute ATTR in SRC_DIE.
13320 On entry *REF_CU is the CU of SRC_DIE.
13321 On exit *REF_CU is the CU of the result. */
13323 static struct die_info
*
13324 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
13325 struct dwarf2_cu
**ref_cu
)
13327 struct objfile
*objfile
= (*ref_cu
)->objfile
;
13328 struct die_info temp_die
;
13329 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13330 struct dwarf2_cu
*sig_cu
;
13331 struct die_info
*die
;
13333 /* sig_type will be NULL if the signatured type is missing from
13335 if (sig_type
== NULL
)
13336 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13337 "at 0x%x [in module %s]"),
13338 src_die
->offset
, objfile
->name
);
13340 /* If necessary, add it to the queue and load its DIEs. */
13342 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
13343 read_signatured_type (objfile
, sig_type
);
13345 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
13347 sig_cu
= sig_type
->per_cu
.cu
;
13348 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
13349 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
13356 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
13357 "from DIE at 0x%x [in module %s]"),
13358 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
13361 /* Given an offset of a signatured type, return its signatured_type. */
13363 static struct signatured_type
*
13364 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
13366 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
13367 unsigned int length
, initial_length_size
;
13368 unsigned int sig_offset
;
13369 struct signatured_type find_entry
, *type_sig
;
13371 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
13372 sig_offset
= (initial_length_size
13374 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
13375 + 1 /*address_size*/);
13376 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
13377 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
13379 /* This is only used to lookup previously recorded types.
13380 If we didn't find it, it's our bug. */
13381 gdb_assert (type_sig
!= NULL
);
13382 gdb_assert (offset
== type_sig
->offset
);
13387 /* Read in signatured type at OFFSET and build its CU and die(s). */
13390 read_signatured_type_at_offset (struct objfile
*objfile
,
13391 unsigned int offset
)
13393 struct signatured_type
*type_sig
;
13395 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13397 /* We have the section offset, but we need the signature to do the
13398 hash table lookup. */
13399 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
13401 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13403 read_signatured_type (objfile
, type_sig
);
13405 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
13408 /* Read in a signatured type and build its CU and DIEs. */
13411 read_signatured_type (struct objfile
*objfile
,
13412 struct signatured_type
*type_sig
)
13414 gdb_byte
*types_ptr
;
13415 struct die_reader_specs reader_specs
;
13416 struct dwarf2_cu
*cu
;
13417 ULONGEST signature
;
13418 struct cleanup
*back_to
, *free_cu_cleanup
;
13420 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13421 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
13423 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13425 cu
= xmalloc (sizeof (*cu
));
13426 init_one_comp_unit (cu
, objfile
);
13428 type_sig
->per_cu
.cu
= cu
;
13429 cu
->per_cu
= &type_sig
->per_cu
;
13431 /* If an error occurs while loading, release our storage. */
13432 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
13434 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
13435 types_ptr
, objfile
->obfd
);
13436 gdb_assert (signature
== type_sig
->signature
);
13439 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13443 &cu
->comp_unit_obstack
,
13444 hashtab_obstack_allocate
,
13445 dummy_obstack_deallocate
);
13447 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
13448 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
13450 init_cu_die_reader (&reader_specs
, cu
);
13452 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
13455 /* We try not to read any attributes in this function, because not
13456 all objfiles needed for references have been loaded yet, and symbol
13457 table processing isn't initialized. But we have to set the CU language,
13458 or we won't be able to build types correctly. */
13459 prepare_one_comp_unit (cu
, cu
->dies
);
13461 do_cleanups (back_to
);
13463 /* We've successfully allocated this compilation unit. Let our caller
13464 clean it up when finished with it. */
13465 discard_cleanups (free_cu_cleanup
);
13467 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
13468 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
13471 /* Decode simple location descriptions.
13472 Given a pointer to a dwarf block that defines a location, compute
13473 the location and return the value.
13475 NOTE drow/2003-11-18: This function is called in two situations
13476 now: for the address of static or global variables (partial symbols
13477 only) and for offsets into structures which are expected to be
13478 (more or less) constant. The partial symbol case should go away,
13479 and only the constant case should remain. That will let this
13480 function complain more accurately. A few special modes are allowed
13481 without complaint for global variables (for instance, global
13482 register values and thread-local values).
13484 A location description containing no operations indicates that the
13485 object is optimized out. The return value is 0 for that case.
13486 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13487 callers will only want a very basic result and this can become a
13490 Note that stack[0] is unused except as a default error return. */
13493 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
13495 struct objfile
*objfile
= cu
->objfile
;
13497 int size
= blk
->size
;
13498 gdb_byte
*data
= blk
->data
;
13499 CORE_ADDR stack
[64];
13501 unsigned int bytes_read
, unsnd
;
13507 stack
[++stacki
] = 0;
13546 stack
[++stacki
] = op
- DW_OP_lit0
;
13581 stack
[++stacki
] = op
- DW_OP_reg0
;
13583 dwarf2_complex_location_expr_complaint ();
13587 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13589 stack
[++stacki
] = unsnd
;
13591 dwarf2_complex_location_expr_complaint ();
13595 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
13600 case DW_OP_const1u
:
13601 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
13605 case DW_OP_const1s
:
13606 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
13610 case DW_OP_const2u
:
13611 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
13615 case DW_OP_const2s
:
13616 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
13620 case DW_OP_const4u
:
13621 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
13625 case DW_OP_const4s
:
13626 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
13631 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
13637 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
13642 stack
[stacki
+ 1] = stack
[stacki
];
13647 stack
[stacki
- 1] += stack
[stacki
];
13651 case DW_OP_plus_uconst
:
13652 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
13658 stack
[stacki
- 1] -= stack
[stacki
];
13663 /* If we're not the last op, then we definitely can't encode
13664 this using GDB's address_class enum. This is valid for partial
13665 global symbols, although the variable's address will be bogus
13668 dwarf2_complex_location_expr_complaint ();
13671 case DW_OP_GNU_push_tls_address
:
13672 /* The top of the stack has the offset from the beginning
13673 of the thread control block at which the variable is located. */
13674 /* Nothing should follow this operator, so the top of stack would
13676 /* This is valid for partial global symbols, but the variable's
13677 address will be bogus in the psymtab. */
13679 dwarf2_complex_location_expr_complaint ();
13682 case DW_OP_GNU_uninit
:
13686 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
13687 dwarf_stack_op_name (op
, 1));
13688 return (stack
[stacki
]);
13691 /* Enforce maximum stack depth of SIZE-1 to avoid writing
13692 outside of the allocated space. Also enforce minimum>0. */
13693 if (stacki
>= ARRAY_SIZE (stack
) - 1)
13695 complaint (&symfile_complaints
,
13696 _("location description stack overflow"));
13702 complaint (&symfile_complaints
,
13703 _("location description stack underflow"));
13707 return (stack
[stacki
]);
13710 /* memory allocation interface */
13712 static struct dwarf_block
*
13713 dwarf_alloc_block (struct dwarf2_cu
*cu
)
13715 struct dwarf_block
*blk
;
13717 blk
= (struct dwarf_block
*)
13718 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
13722 static struct abbrev_info
*
13723 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
13725 struct abbrev_info
*abbrev
;
13727 abbrev
= (struct abbrev_info
*)
13728 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
13729 memset (abbrev
, 0, sizeof (struct abbrev_info
));
13733 static struct die_info
*
13734 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
13736 struct die_info
*die
;
13737 size_t size
= sizeof (struct die_info
);
13740 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
13742 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
13743 memset (die
, 0, sizeof (struct die_info
));
13748 /* Macro support. */
13750 /* Return the full name of file number I in *LH's file name table.
13751 Use COMP_DIR as the name of the current directory of the
13752 compilation. The result is allocated using xmalloc; the caller is
13753 responsible for freeing it. */
13755 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
13757 /* Is the file number a valid index into the line header's file name
13758 table? Remember that file numbers start with one, not zero. */
13759 if (1 <= file
&& file
<= lh
->num_file_names
)
13761 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13763 if (IS_ABSOLUTE_PATH (fe
->name
))
13764 return xstrdup (fe
->name
);
13772 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13778 dir_len
= strlen (dir
);
13779 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
13780 strcpy (full_name
, dir
);
13781 full_name
[dir_len
] = '/';
13782 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
13786 return xstrdup (fe
->name
);
13791 /* The compiler produced a bogus file number. We can at least
13792 record the macro definitions made in the file, even if we
13793 won't be able to find the file by name. */
13794 char fake_name
[80];
13796 sprintf (fake_name
, "<bad macro file number %d>", file
);
13798 complaint (&symfile_complaints
,
13799 _("bad file number in macro information (%d)"),
13802 return xstrdup (fake_name
);
13807 static struct macro_source_file
*
13808 macro_start_file (int file
, int line
,
13809 struct macro_source_file
*current_file
,
13810 const char *comp_dir
,
13811 struct line_header
*lh
, struct objfile
*objfile
)
13813 /* The full name of this source file. */
13814 char *full_name
= file_full_name (file
, lh
, comp_dir
);
13816 /* We don't create a macro table for this compilation unit
13817 at all until we actually get a filename. */
13818 if (! pending_macros
)
13819 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
13820 objfile
->macro_cache
);
13822 if (! current_file
)
13823 /* If we have no current file, then this must be the start_file
13824 directive for the compilation unit's main source file. */
13825 current_file
= macro_set_main (pending_macros
, full_name
);
13827 current_file
= macro_include (current_file
, line
, full_name
);
13831 return current_file
;
13835 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
13836 followed by a null byte. */
13838 copy_string (const char *buf
, int len
)
13840 char *s
= xmalloc (len
+ 1);
13842 memcpy (s
, buf
, len
);
13848 static const char *
13849 consume_improper_spaces (const char *p
, const char *body
)
13853 complaint (&symfile_complaints
,
13854 _("macro definition contains spaces "
13855 "in formal argument list:\n`%s'"),
13867 parse_macro_definition (struct macro_source_file
*file
, int line
,
13872 /* The body string takes one of two forms. For object-like macro
13873 definitions, it should be:
13875 <macro name> " " <definition>
13877 For function-like macro definitions, it should be:
13879 <macro name> "() " <definition>
13881 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
13883 Spaces may appear only where explicitly indicated, and in the
13886 The Dwarf 2 spec says that an object-like macro's name is always
13887 followed by a space, but versions of GCC around March 2002 omit
13888 the space when the macro's definition is the empty string.
13890 The Dwarf 2 spec says that there should be no spaces between the
13891 formal arguments in a function-like macro's formal argument list,
13892 but versions of GCC around March 2002 include spaces after the
13896 /* Find the extent of the macro name. The macro name is terminated
13897 by either a space or null character (for an object-like macro) or
13898 an opening paren (for a function-like macro). */
13899 for (p
= body
; *p
; p
++)
13900 if (*p
== ' ' || *p
== '(')
13903 if (*p
== ' ' || *p
== '\0')
13905 /* It's an object-like macro. */
13906 int name_len
= p
- body
;
13907 char *name
= copy_string (body
, name_len
);
13908 const char *replacement
;
13911 replacement
= body
+ name_len
+ 1;
13914 dwarf2_macro_malformed_definition_complaint (body
);
13915 replacement
= body
+ name_len
;
13918 macro_define_object (file
, line
, name
, replacement
);
13922 else if (*p
== '(')
13924 /* It's a function-like macro. */
13925 char *name
= copy_string (body
, p
- body
);
13928 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
13932 p
= consume_improper_spaces (p
, body
);
13934 /* Parse the formal argument list. */
13935 while (*p
&& *p
!= ')')
13937 /* Find the extent of the current argument name. */
13938 const char *arg_start
= p
;
13940 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
13943 if (! *p
|| p
== arg_start
)
13944 dwarf2_macro_malformed_definition_complaint (body
);
13947 /* Make sure argv has room for the new argument. */
13948 if (argc
>= argv_size
)
13951 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
13954 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
13957 p
= consume_improper_spaces (p
, body
);
13959 /* Consume the comma, if present. */
13964 p
= consume_improper_spaces (p
, body
);
13973 /* Perfectly formed definition, no complaints. */
13974 macro_define_function (file
, line
, name
,
13975 argc
, (const char **) argv
,
13977 else if (*p
== '\0')
13979 /* Complain, but do define it. */
13980 dwarf2_macro_malformed_definition_complaint (body
);
13981 macro_define_function (file
, line
, name
,
13982 argc
, (const char **) argv
,
13986 /* Just complain. */
13987 dwarf2_macro_malformed_definition_complaint (body
);
13990 /* Just complain. */
13991 dwarf2_macro_malformed_definition_complaint (body
);
13997 for (i
= 0; i
< argc
; i
++)
14003 dwarf2_macro_malformed_definition_complaint (body
);
14008 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
14009 char *comp_dir
, bfd
*abfd
,
14010 struct dwarf2_cu
*cu
)
14012 gdb_byte
*mac_ptr
, *mac_end
;
14013 struct macro_source_file
*current_file
= 0;
14014 enum dwarf_macinfo_record_type macinfo_type
;
14015 int at_commandline
;
14017 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14018 &dwarf2_per_objfile
->macinfo
);
14019 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
14021 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
14025 /* First pass: Find the name of the base filename.
14026 This filename is needed in order to process all macros whose definition
14027 (or undefinition) comes from the command line. These macros are defined
14028 before the first DW_MACINFO_start_file entry, and yet still need to be
14029 associated to the base file.
14031 To determine the base file name, we scan the macro definitions until we
14032 reach the first DW_MACINFO_start_file entry. We then initialize
14033 CURRENT_FILE accordingly so that any macro definition found before the
14034 first DW_MACINFO_start_file can still be associated to the base file. */
14036 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14037 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
14038 + dwarf2_per_objfile
->macinfo
.size
;
14042 /* Do we at least have room for a macinfo type byte? */
14043 if (mac_ptr
>= mac_end
)
14045 /* Complaint is printed during the second pass as GDB will probably
14046 stop the first pass earlier upon finding
14047 DW_MACINFO_start_file. */
14051 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14054 switch (macinfo_type
)
14056 /* A zero macinfo type indicates the end of the macro
14061 case DW_MACINFO_define
:
14062 case DW_MACINFO_undef
:
14063 /* Only skip the data by MAC_PTR. */
14065 unsigned int bytes_read
;
14067 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14068 mac_ptr
+= bytes_read
;
14069 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14070 mac_ptr
+= bytes_read
;
14074 case DW_MACINFO_start_file
:
14076 unsigned int bytes_read
;
14079 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14080 mac_ptr
+= bytes_read
;
14081 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14082 mac_ptr
+= bytes_read
;
14084 current_file
= macro_start_file (file
, line
, current_file
,
14085 comp_dir
, lh
, cu
->objfile
);
14089 case DW_MACINFO_end_file
:
14090 /* No data to skip by MAC_PTR. */
14093 case DW_MACINFO_vendor_ext
:
14094 /* Only skip the data by MAC_PTR. */
14096 unsigned int bytes_read
;
14098 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14099 mac_ptr
+= bytes_read
;
14100 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14101 mac_ptr
+= bytes_read
;
14108 } while (macinfo_type
!= 0 && current_file
== NULL
);
14110 /* Second pass: Process all entries.
14112 Use the AT_COMMAND_LINE flag to determine whether we are still processing
14113 command-line macro definitions/undefinitions. This flag is unset when we
14114 reach the first DW_MACINFO_start_file entry. */
14116 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14118 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14119 GDB is still reading the definitions from command line. First
14120 DW_MACINFO_start_file will need to be ignored as it was already executed
14121 to create CURRENT_FILE for the main source holding also the command line
14122 definitions. On first met DW_MACINFO_start_file this flag is reset to
14123 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14125 at_commandline
= 1;
14129 /* Do we at least have room for a macinfo type byte? */
14130 if (mac_ptr
>= mac_end
)
14132 dwarf2_macros_too_long_complaint ();
14136 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14139 switch (macinfo_type
)
14141 /* A zero macinfo type indicates the end of the macro
14146 case DW_MACINFO_define
:
14147 case DW_MACINFO_undef
:
14149 unsigned int bytes_read
;
14153 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14154 mac_ptr
+= bytes_read
;
14155 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14156 mac_ptr
+= bytes_read
;
14158 if (! current_file
)
14160 /* DWARF violation as no main source is present. */
14161 complaint (&symfile_complaints
,
14162 _("debug info with no main source gives macro %s "
14164 macinfo_type
== DW_MACINFO_define
?
14166 macinfo_type
== DW_MACINFO_undef
?
14167 _("undefinition") :
14168 _("something-or-other"), line
, body
);
14171 if ((line
== 0 && !at_commandline
)
14172 || (line
!= 0 && at_commandline
))
14173 complaint (&symfile_complaints
,
14174 _("debug info gives %s macro %s with %s line %d: %s"),
14175 at_commandline
? _("command-line") : _("in-file"),
14176 macinfo_type
== DW_MACINFO_define
?
14178 macinfo_type
== DW_MACINFO_undef
?
14179 _("undefinition") :
14180 _("something-or-other"),
14181 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
14183 if (macinfo_type
== DW_MACINFO_define
)
14184 parse_macro_definition (current_file
, line
, body
);
14185 else if (macinfo_type
== DW_MACINFO_undef
)
14186 macro_undef (current_file
, line
, body
);
14190 case DW_MACINFO_start_file
:
14192 unsigned int bytes_read
;
14195 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14196 mac_ptr
+= bytes_read
;
14197 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14198 mac_ptr
+= bytes_read
;
14200 if ((line
== 0 && !at_commandline
)
14201 || (line
!= 0 && at_commandline
))
14202 complaint (&symfile_complaints
,
14203 _("debug info gives source %d included "
14204 "from %s at %s line %d"),
14205 file
, at_commandline
? _("command-line") : _("file"),
14206 line
== 0 ? _("zero") : _("non-zero"), line
);
14208 if (at_commandline
)
14210 /* This DW_MACINFO_start_file was executed in the pass one. */
14211 at_commandline
= 0;
14214 current_file
= macro_start_file (file
, line
,
14215 current_file
, comp_dir
,
14220 case DW_MACINFO_end_file
:
14221 if (! current_file
)
14222 complaint (&symfile_complaints
,
14223 _("macro debug info has an unmatched "
14224 "`close_file' directive"));
14227 current_file
= current_file
->included_by
;
14228 if (! current_file
)
14230 enum dwarf_macinfo_record_type next_type
;
14232 /* GCC circa March 2002 doesn't produce the zero
14233 type byte marking the end of the compilation
14234 unit. Complain if it's not there, but exit no
14237 /* Do we at least have room for a macinfo type byte? */
14238 if (mac_ptr
>= mac_end
)
14240 dwarf2_macros_too_long_complaint ();
14244 /* We don't increment mac_ptr here, so this is just
14246 next_type
= read_1_byte (abfd
, mac_ptr
);
14247 if (next_type
!= 0)
14248 complaint (&symfile_complaints
,
14249 _("no terminating 0-type entry for "
14250 "macros in `.debug_macinfo' section"));
14257 case DW_MACINFO_vendor_ext
:
14259 unsigned int bytes_read
;
14263 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14264 mac_ptr
+= bytes_read
;
14265 string
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14266 mac_ptr
+= bytes_read
;
14268 /* We don't recognize any vendor extensions. */
14272 } while (macinfo_type
!= 0);
14275 /* Check if the attribute's form is a DW_FORM_block*
14276 if so return true else false. */
14278 attr_form_is_block (struct attribute
*attr
)
14280 return (attr
== NULL
? 0 :
14281 attr
->form
== DW_FORM_block1
14282 || attr
->form
== DW_FORM_block2
14283 || attr
->form
== DW_FORM_block4
14284 || attr
->form
== DW_FORM_block
14285 || attr
->form
== DW_FORM_exprloc
);
14288 /* Return non-zero if ATTR's value is a section offset --- classes
14289 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14290 You may use DW_UNSND (attr) to retrieve such offsets.
14292 Section 7.5.4, "Attribute Encodings", explains that no attribute
14293 may have a value that belongs to more than one of these classes; it
14294 would be ambiguous if we did, because we use the same forms for all
14297 attr_form_is_section_offset (struct attribute
*attr
)
14299 return (attr
->form
== DW_FORM_data4
14300 || attr
->form
== DW_FORM_data8
14301 || attr
->form
== DW_FORM_sec_offset
);
14305 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14306 zero otherwise. When this function returns true, you can apply
14307 dwarf2_get_attr_constant_value to it.
14309 However, note that for some attributes you must check
14310 attr_form_is_section_offset before using this test. DW_FORM_data4
14311 and DW_FORM_data8 are members of both the constant class, and of
14312 the classes that contain offsets into other debug sections
14313 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14314 that, if an attribute's can be either a constant or one of the
14315 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14316 taken as section offsets, not constants. */
14318 attr_form_is_constant (struct attribute
*attr
)
14320 switch (attr
->form
)
14322 case DW_FORM_sdata
:
14323 case DW_FORM_udata
:
14324 case DW_FORM_data1
:
14325 case DW_FORM_data2
:
14326 case DW_FORM_data4
:
14327 case DW_FORM_data8
:
14334 /* A helper function that fills in a dwarf2_loclist_baton. */
14337 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
14338 struct dwarf2_loclist_baton
*baton
,
14339 struct attribute
*attr
)
14341 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14342 &dwarf2_per_objfile
->loc
);
14344 baton
->per_cu
= cu
->per_cu
;
14345 gdb_assert (baton
->per_cu
);
14346 /* We don't know how long the location list is, but make sure we
14347 don't run off the edge of the section. */
14348 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
14349 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
14350 baton
->base_address
= cu
->base_address
;
14354 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
14355 struct dwarf2_cu
*cu
)
14357 if (attr_form_is_section_offset (attr
)
14358 /* ".debug_loc" may not exist at all, or the offset may be outside
14359 the section. If so, fall through to the complaint in the
14361 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
14363 struct dwarf2_loclist_baton
*baton
;
14365 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14366 sizeof (struct dwarf2_loclist_baton
));
14368 fill_in_loclist_baton (cu
, baton
, attr
);
14370 if (cu
->base_known
== 0)
14371 complaint (&symfile_complaints
,
14372 _("Location list used without "
14373 "specifying the CU base address."));
14375 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
14376 SYMBOL_LOCATION_BATON (sym
) = baton
;
14380 struct dwarf2_locexpr_baton
*baton
;
14382 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14383 sizeof (struct dwarf2_locexpr_baton
));
14384 baton
->per_cu
= cu
->per_cu
;
14385 gdb_assert (baton
->per_cu
);
14387 if (attr_form_is_block (attr
))
14389 /* Note that we're just copying the block's data pointer
14390 here, not the actual data. We're still pointing into the
14391 info_buffer for SYM's objfile; right now we never release
14392 that buffer, but when we do clean up properly this may
14394 baton
->size
= DW_BLOCK (attr
)->size
;
14395 baton
->data
= DW_BLOCK (attr
)->data
;
14399 dwarf2_invalid_attrib_class_complaint ("location description",
14400 SYMBOL_NATURAL_NAME (sym
));
14402 baton
->data
= NULL
;
14405 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14406 SYMBOL_LOCATION_BATON (sym
) = baton
;
14410 /* Return the OBJFILE associated with the compilation unit CU. If CU
14411 came from a separate debuginfo file, then the master objfile is
14415 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
14417 struct objfile
*objfile
= per_cu
->objfile
;
14419 /* Return the master objfile, so that we can report and look up the
14420 correct file containing this variable. */
14421 if (objfile
->separate_debug_objfile_backlink
)
14422 objfile
= objfile
->separate_debug_objfile_backlink
;
14427 /* Return the address size given in the compilation unit header for CU. */
14430 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
14433 return per_cu
->cu
->header
.addr_size
;
14436 /* If the CU is not currently read in, we re-read its header. */
14437 struct objfile
*objfile
= per_cu
->objfile
;
14438 struct dwarf2_per_objfile
*per_objfile
14439 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14440 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14441 struct comp_unit_head cu_header
;
14443 memset (&cu_header
, 0, sizeof cu_header
);
14444 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14445 return cu_header
.addr_size
;
14449 /* Return the offset size given in the compilation unit header for CU. */
14452 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
14455 return per_cu
->cu
->header
.offset_size
;
14458 /* If the CU is not currently read in, we re-read its header. */
14459 struct objfile
*objfile
= per_cu
->objfile
;
14460 struct dwarf2_per_objfile
*per_objfile
14461 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14462 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14463 struct comp_unit_head cu_header
;
14465 memset (&cu_header
, 0, sizeof cu_header
);
14466 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14467 return cu_header
.offset_size
;
14471 /* Return the text offset of the CU. The returned offset comes from
14472 this CU's objfile. If this objfile came from a separate debuginfo
14473 file, then the offset may be different from the corresponding
14474 offset in the parent objfile. */
14477 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
14479 struct objfile
*objfile
= per_cu
->objfile
;
14481 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14484 /* Locate the .debug_info compilation unit from CU's objfile which contains
14485 the DIE at OFFSET. Raises an error on failure. */
14487 static struct dwarf2_per_cu_data
*
14488 dwarf2_find_containing_comp_unit (unsigned int offset
,
14489 struct objfile
*objfile
)
14491 struct dwarf2_per_cu_data
*this_cu
;
14495 high
= dwarf2_per_objfile
->n_comp_units
- 1;
14498 int mid
= low
+ (high
- low
) / 2;
14500 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
14505 gdb_assert (low
== high
);
14506 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
14509 error (_("Dwarf Error: could not find partial DIE containing "
14510 "offset 0x%lx [in module %s]"),
14511 (long) offset
, bfd_get_filename (objfile
->obfd
));
14513 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
14514 return dwarf2_per_objfile
->all_comp_units
[low
-1];
14518 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
14519 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
14520 && offset
>= this_cu
->offset
+ this_cu
->length
)
14521 error (_("invalid dwarf2 offset %u"), offset
);
14522 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
14527 /* Locate the compilation unit from OBJFILE which is located at exactly
14528 OFFSET. Raises an error on failure. */
14530 static struct dwarf2_per_cu_data
*
14531 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
14533 struct dwarf2_per_cu_data
*this_cu
;
14535 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
14536 if (this_cu
->offset
!= offset
)
14537 error (_("no compilation unit with offset %u."), offset
);
14541 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
14544 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
14546 memset (cu
, 0, sizeof (*cu
));
14547 cu
->objfile
= objfile
;
14548 obstack_init (&cu
->comp_unit_obstack
);
14551 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
14554 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
14556 struct attribute
*attr
;
14558 /* Set the language we're debugging. */
14559 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
14561 set_cu_language (DW_UNSND (attr
), cu
);
14563 set_cu_language (language_minimal
, cu
);
14566 /* Release one cached compilation unit, CU. We unlink it from the tree
14567 of compilation units, but we don't remove it from the read_in_chain;
14568 the caller is responsible for that.
14569 NOTE: DATA is a void * because this function is also used as a
14570 cleanup routine. */
14573 free_one_comp_unit (void *data
)
14575 struct dwarf2_cu
*cu
= data
;
14577 if (cu
->per_cu
!= NULL
)
14578 cu
->per_cu
->cu
= NULL
;
14581 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14586 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14587 when we're finished with it. We can't free the pointer itself, but be
14588 sure to unlink it from the cache. Also release any associated storage
14589 and perform cache maintenance.
14591 Only used during partial symbol parsing. */
14594 free_stack_comp_unit (void *data
)
14596 struct dwarf2_cu
*cu
= data
;
14598 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14599 cu
->partial_dies
= NULL
;
14601 if (cu
->per_cu
!= NULL
)
14603 /* This compilation unit is on the stack in our caller, so we
14604 should not xfree it. Just unlink it. */
14605 cu
->per_cu
->cu
= NULL
;
14608 /* If we had a per-cu pointer, then we may have other compilation
14609 units loaded, so age them now. */
14610 age_cached_comp_units ();
14614 /* Free all cached compilation units. */
14617 free_cached_comp_units (void *data
)
14619 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14621 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14622 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14623 while (per_cu
!= NULL
)
14625 struct dwarf2_per_cu_data
*next_cu
;
14627 next_cu
= per_cu
->cu
->read_in_chain
;
14629 free_one_comp_unit (per_cu
->cu
);
14630 *last_chain
= next_cu
;
14636 /* Increase the age counter on each cached compilation unit, and free
14637 any that are too old. */
14640 age_cached_comp_units (void)
14642 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14644 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
14645 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14646 while (per_cu
!= NULL
)
14648 per_cu
->cu
->last_used
++;
14649 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
14650 dwarf2_mark (per_cu
->cu
);
14651 per_cu
= per_cu
->cu
->read_in_chain
;
14654 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14655 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14656 while (per_cu
!= NULL
)
14658 struct dwarf2_per_cu_data
*next_cu
;
14660 next_cu
= per_cu
->cu
->read_in_chain
;
14662 if (!per_cu
->cu
->mark
)
14664 free_one_comp_unit (per_cu
->cu
);
14665 *last_chain
= next_cu
;
14668 last_chain
= &per_cu
->cu
->read_in_chain
;
14674 /* Remove a single compilation unit from the cache. */
14677 free_one_cached_comp_unit (void *target_cu
)
14679 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14681 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14682 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14683 while (per_cu
!= NULL
)
14685 struct dwarf2_per_cu_data
*next_cu
;
14687 next_cu
= per_cu
->cu
->read_in_chain
;
14689 if (per_cu
->cu
== target_cu
)
14691 free_one_comp_unit (per_cu
->cu
);
14692 *last_chain
= next_cu
;
14696 last_chain
= &per_cu
->cu
->read_in_chain
;
14702 /* Release all extra memory associated with OBJFILE. */
14705 dwarf2_free_objfile (struct objfile
*objfile
)
14707 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14709 if (dwarf2_per_objfile
== NULL
)
14712 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
14713 free_cached_comp_units (NULL
);
14715 if (dwarf2_per_objfile
->quick_file_names_table
)
14716 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
14718 /* Everything else should be on the objfile obstack. */
14721 /* A pair of DIE offset and GDB type pointer. We store these
14722 in a hash table separate from the DIEs, and preserve them
14723 when the DIEs are flushed out of cache. */
14725 struct dwarf2_offset_and_type
14727 unsigned int offset
;
14731 /* Hash function for a dwarf2_offset_and_type. */
14734 offset_and_type_hash (const void *item
)
14736 const struct dwarf2_offset_and_type
*ofs
= item
;
14738 return ofs
->offset
;
14741 /* Equality function for a dwarf2_offset_and_type. */
14744 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
14746 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
14747 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
14749 return ofs_lhs
->offset
== ofs_rhs
->offset
;
14752 /* Set the type associated with DIE to TYPE. Save it in CU's hash
14753 table if necessary. For convenience, return TYPE.
14755 The DIEs reading must have careful ordering to:
14756 * Not cause infite loops trying to read in DIEs as a prerequisite for
14757 reading current DIE.
14758 * Not trying to dereference contents of still incompletely read in types
14759 while reading in other DIEs.
14760 * Enable referencing still incompletely read in types just by a pointer to
14761 the type without accessing its fields.
14763 Therefore caller should follow these rules:
14764 * Try to fetch any prerequisite types we may need to build this DIE type
14765 before building the type and calling set_die_type.
14766 * After building type call set_die_type for current DIE as soon as
14767 possible before fetching more types to complete the current type.
14768 * Make the type as complete as possible before fetching more types. */
14770 static struct type
*
14771 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14773 struct dwarf2_offset_and_type
**slot
, ofs
;
14774 struct objfile
*objfile
= cu
->objfile
;
14775 htab_t
*type_hash_ptr
;
14777 /* For Ada types, make sure that the gnat-specific data is always
14778 initialized (if not already set). There are a few types where
14779 we should not be doing so, because the type-specific area is
14780 already used to hold some other piece of info (eg: TYPE_CODE_FLT
14781 where the type-specific area is used to store the floatformat).
14782 But this is not a problem, because the gnat-specific information
14783 is actually not needed for these types. */
14784 if (need_gnat_info (cu
)
14785 && TYPE_CODE (type
) != TYPE_CODE_FUNC
14786 && TYPE_CODE (type
) != TYPE_CODE_FLT
14787 && !HAVE_GNAT_AUX_INFO (type
))
14788 INIT_GNAT_SPECIFIC (type
);
14790 if (cu
->per_cu
->from_debug_types
)
14791 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
14793 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
14795 if (*type_hash_ptr
== NULL
)
14798 = htab_create_alloc_ex (127,
14799 offset_and_type_hash
,
14800 offset_and_type_eq
,
14802 &objfile
->objfile_obstack
,
14803 hashtab_obstack_allocate
,
14804 dummy_obstack_deallocate
);
14807 ofs
.offset
= die
->offset
;
14809 slot
= (struct dwarf2_offset_and_type
**)
14810 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
14812 complaint (&symfile_complaints
,
14813 _("A problem internal to GDB: DIE 0x%x has type already set"),
14815 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
14820 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
14821 table, or return NULL if the die does not have a saved type. */
14823 static struct type
*
14824 get_die_type_at_offset (unsigned int offset
,
14825 struct dwarf2_per_cu_data
*per_cu
)
14827 struct dwarf2_offset_and_type
*slot
, ofs
;
14830 if (per_cu
->from_debug_types
)
14831 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
14833 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
14834 if (type_hash
== NULL
)
14837 ofs
.offset
= offset
;
14838 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
14845 /* Look up the type for DIE in the appropriate type_hash table,
14846 or return NULL if DIE does not have a saved type. */
14848 static struct type
*
14849 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14851 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
14854 /* Add a dependence relationship from CU to REF_PER_CU. */
14857 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
14858 struct dwarf2_per_cu_data
*ref_per_cu
)
14862 if (cu
->dependencies
== NULL
)
14864 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
14865 NULL
, &cu
->comp_unit_obstack
,
14866 hashtab_obstack_allocate
,
14867 dummy_obstack_deallocate
);
14869 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
14871 *slot
= ref_per_cu
;
14874 /* Subroutine of dwarf2_mark to pass to htab_traverse.
14875 Set the mark field in every compilation unit in the
14876 cache that we must keep because we are keeping CU. */
14879 dwarf2_mark_helper (void **slot
, void *data
)
14881 struct dwarf2_per_cu_data
*per_cu
;
14883 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
14884 if (per_cu
->cu
->mark
)
14886 per_cu
->cu
->mark
= 1;
14888 if (per_cu
->cu
->dependencies
!= NULL
)
14889 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14894 /* Set the mark field in CU and in every other compilation unit in the
14895 cache that we must keep because we are keeping CU. */
14898 dwarf2_mark (struct dwarf2_cu
*cu
)
14903 if (cu
->dependencies
!= NULL
)
14904 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14908 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
14912 per_cu
->cu
->mark
= 0;
14913 per_cu
= per_cu
->cu
->read_in_chain
;
14917 /* Trivial hash function for partial_die_info: the hash value of a DIE
14918 is its offset in .debug_info for this objfile. */
14921 partial_die_hash (const void *item
)
14923 const struct partial_die_info
*part_die
= item
;
14925 return part_die
->offset
;
14928 /* Trivial comparison function for partial_die_info structures: two DIEs
14929 are equal if they have the same offset. */
14932 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
14934 const struct partial_die_info
*part_die_lhs
= item_lhs
;
14935 const struct partial_die_info
*part_die_rhs
= item_rhs
;
14937 return part_die_lhs
->offset
== part_die_rhs
->offset
;
14940 static struct cmd_list_element
*set_dwarf2_cmdlist
;
14941 static struct cmd_list_element
*show_dwarf2_cmdlist
;
14944 set_dwarf2_cmd (char *args
, int from_tty
)
14946 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
14950 show_dwarf2_cmd (char *args
, int from_tty
)
14952 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
14955 /* If section described by INFO was mmapped, munmap it now. */
14958 munmap_section_buffer (struct dwarf2_section_info
*info
)
14960 if (info
->was_mmapped
)
14963 intptr_t begin
= (intptr_t) info
->buffer
;
14964 intptr_t map_begin
= begin
& ~(pagesize
- 1);
14965 size_t map_length
= info
->size
+ begin
- map_begin
;
14967 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
14969 /* Without HAVE_MMAP, we should never be here to begin with. */
14970 gdb_assert_not_reached ("no mmap support");
14975 /* munmap debug sections for OBJFILE, if necessary. */
14978 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
14980 struct dwarf2_per_objfile
*data
= d
;
14982 /* This is sorted according to the order they're defined in to make it easier
14983 to keep in sync. */
14984 munmap_section_buffer (&data
->info
);
14985 munmap_section_buffer (&data
->abbrev
);
14986 munmap_section_buffer (&data
->line
);
14987 munmap_section_buffer (&data
->loc
);
14988 munmap_section_buffer (&data
->macinfo
);
14989 munmap_section_buffer (&data
->str
);
14990 munmap_section_buffer (&data
->ranges
);
14991 munmap_section_buffer (&data
->types
);
14992 munmap_section_buffer (&data
->frame
);
14993 munmap_section_buffer (&data
->eh_frame
);
14994 munmap_section_buffer (&data
->gdb_index
);
14998 /* The "save gdb-index" command. */
15000 /* The contents of the hash table we create when building the string
15002 struct strtab_entry
15004 offset_type offset
;
15008 /* Hash function for a strtab_entry. */
15011 hash_strtab_entry (const void *e
)
15013 const struct strtab_entry
*entry
= e
;
15014 return mapped_index_string_hash (entry
->str
);
15017 /* Equality function for a strtab_entry. */
15020 eq_strtab_entry (const void *a
, const void *b
)
15022 const struct strtab_entry
*ea
= a
;
15023 const struct strtab_entry
*eb
= b
;
15024 return !strcmp (ea
->str
, eb
->str
);
15027 /* Create a strtab_entry hash table. */
15030 create_strtab (void)
15032 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
15033 xfree
, xcalloc
, xfree
);
15036 /* Add a string to the constant pool. Return the string's offset in
15040 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
15043 struct strtab_entry entry
;
15044 struct strtab_entry
*result
;
15047 slot
= htab_find_slot (table
, &entry
, INSERT
);
15052 result
= XNEW (struct strtab_entry
);
15053 result
->offset
= obstack_object_size (cpool
);
15055 obstack_grow_str0 (cpool
, str
);
15058 return result
->offset
;
15061 /* An entry in the symbol table. */
15062 struct symtab_index_entry
15064 /* The name of the symbol. */
15066 /* The offset of the name in the constant pool. */
15067 offset_type index_offset
;
15068 /* A sorted vector of the indices of all the CUs that hold an object
15070 VEC (offset_type
) *cu_indices
;
15073 /* The symbol table. This is a power-of-2-sized hash table. */
15074 struct mapped_symtab
15076 offset_type n_elements
;
15078 struct symtab_index_entry
**data
;
15081 /* Hash function for a symtab_index_entry. */
15084 hash_symtab_entry (const void *e
)
15086 const struct symtab_index_entry
*entry
= e
;
15087 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
15088 sizeof (offset_type
) * VEC_length (offset_type
,
15089 entry
->cu_indices
),
15093 /* Equality function for a symtab_index_entry. */
15096 eq_symtab_entry (const void *a
, const void *b
)
15098 const struct symtab_index_entry
*ea
= a
;
15099 const struct symtab_index_entry
*eb
= b
;
15100 int len
= VEC_length (offset_type
, ea
->cu_indices
);
15101 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
15103 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
15104 VEC_address (offset_type
, eb
->cu_indices
),
15105 sizeof (offset_type
) * len
);
15108 /* Destroy a symtab_index_entry. */
15111 delete_symtab_entry (void *p
)
15113 struct symtab_index_entry
*entry
= p
;
15114 VEC_free (offset_type
, entry
->cu_indices
);
15118 /* Create a hash table holding symtab_index_entry objects. */
15121 create_symbol_hash_table (void)
15123 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
15124 delete_symtab_entry
, xcalloc
, xfree
);
15127 /* Create a new mapped symtab object. */
15129 static struct mapped_symtab
*
15130 create_mapped_symtab (void)
15132 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
15133 symtab
->n_elements
= 0;
15134 symtab
->size
= 1024;
15135 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15139 /* Destroy a mapped_symtab. */
15142 cleanup_mapped_symtab (void *p
)
15144 struct mapped_symtab
*symtab
= p
;
15145 /* The contents of the array are freed when the other hash table is
15147 xfree (symtab
->data
);
15151 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
15154 static struct symtab_index_entry
**
15155 find_slot (struct mapped_symtab
*symtab
, const char *name
)
15157 offset_type index
, step
, hash
= mapped_index_string_hash (name
);
15159 index
= hash
& (symtab
->size
- 1);
15160 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
15164 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
15165 return &symtab
->data
[index
];
15166 index
= (index
+ step
) & (symtab
->size
- 1);
15170 /* Expand SYMTAB's hash table. */
15173 hash_expand (struct mapped_symtab
*symtab
)
15175 offset_type old_size
= symtab
->size
;
15177 struct symtab_index_entry
**old_entries
= symtab
->data
;
15180 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15182 for (i
= 0; i
< old_size
; ++i
)
15184 if (old_entries
[i
])
15186 struct symtab_index_entry
**slot
= find_slot (symtab
,
15187 old_entries
[i
]->name
);
15188 *slot
= old_entries
[i
];
15192 xfree (old_entries
);
15195 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
15196 is the index of the CU in which the symbol appears. */
15199 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
15200 offset_type cu_index
)
15202 struct symtab_index_entry
**slot
;
15204 ++symtab
->n_elements
;
15205 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
15206 hash_expand (symtab
);
15208 slot
= find_slot (symtab
, name
);
15211 *slot
= XNEW (struct symtab_index_entry
);
15212 (*slot
)->name
= name
;
15213 (*slot
)->cu_indices
= NULL
;
15215 /* Don't push an index twice. Due to how we add entries we only
15216 have to check the last one. */
15217 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
15218 || VEC_length (offset_type
, (*slot
)->cu_indices
) != cu_index
)
15219 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
15222 /* Add a vector of indices to the constant pool. */
15225 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
15226 struct symtab_index_entry
*entry
)
15230 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
15233 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
15234 offset_type val
= MAYBE_SWAP (len
);
15239 entry
->index_offset
= obstack_object_size (cpool
);
15241 obstack_grow (cpool
, &val
, sizeof (val
));
15243 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
15246 val
= MAYBE_SWAP (iter
);
15247 obstack_grow (cpool
, &val
, sizeof (val
));
15252 struct symtab_index_entry
*old_entry
= *slot
;
15253 entry
->index_offset
= old_entry
->index_offset
;
15256 return entry
->index_offset
;
15259 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15260 constant pool entries going into the obstack CPOOL. */
15263 write_hash_table (struct mapped_symtab
*symtab
,
15264 struct obstack
*output
, struct obstack
*cpool
)
15267 htab_t symbol_hash_table
;
15270 symbol_hash_table
= create_symbol_hash_table ();
15271 str_table
= create_strtab ();
15273 /* We add all the index vectors to the constant pool first, to
15274 ensure alignment is ok. */
15275 for (i
= 0; i
< symtab
->size
; ++i
)
15277 if (symtab
->data
[i
])
15278 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
15281 /* Now write out the hash table. */
15282 for (i
= 0; i
< symtab
->size
; ++i
)
15284 offset_type str_off
, vec_off
;
15286 if (symtab
->data
[i
])
15288 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
15289 vec_off
= symtab
->data
[i
]->index_offset
;
15293 /* While 0 is a valid constant pool index, it is not valid
15294 to have 0 for both offsets. */
15299 str_off
= MAYBE_SWAP (str_off
);
15300 vec_off
= MAYBE_SWAP (vec_off
);
15302 obstack_grow (output
, &str_off
, sizeof (str_off
));
15303 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
15306 htab_delete (str_table
);
15307 htab_delete (symbol_hash_table
);
15310 /* Struct to map psymtab to CU index in the index file. */
15311 struct psymtab_cu_index_map
15313 struct partial_symtab
*psymtab
;
15314 unsigned int cu_index
;
15318 hash_psymtab_cu_index (const void *item
)
15320 const struct psymtab_cu_index_map
*map
= item
;
15322 return htab_hash_pointer (map
->psymtab
);
15326 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
15328 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
15329 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
15331 return lhs
->psymtab
== rhs
->psymtab
;
15334 /* Helper struct for building the address table. */
15335 struct addrmap_index_data
15337 struct objfile
*objfile
;
15338 struct obstack
*addr_obstack
;
15339 htab_t cu_index_htab
;
15341 /* Non-zero if the previous_* fields are valid.
15342 We can't write an entry until we see the next entry (since it is only then
15343 that we know the end of the entry). */
15344 int previous_valid
;
15345 /* Index of the CU in the table of all CUs in the index file. */
15346 unsigned int previous_cu_index
;
15347 /* Start address of the CU. */
15348 CORE_ADDR previous_cu_start
;
15351 /* Write an address entry to OBSTACK. */
15354 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
15355 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
15357 offset_type cu_index_to_write
;
15359 CORE_ADDR baseaddr
;
15361 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15363 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
15364 obstack_grow (obstack
, addr
, 8);
15365 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
15366 obstack_grow (obstack
, addr
, 8);
15367 cu_index_to_write
= MAYBE_SWAP (cu_index
);
15368 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
15371 /* Worker function for traversing an addrmap to build the address table. */
15374 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
15376 struct addrmap_index_data
*data
= datap
;
15377 struct partial_symtab
*pst
= obj
;
15378 offset_type cu_index
;
15381 if (data
->previous_valid
)
15382 add_address_entry (data
->objfile
, data
->addr_obstack
,
15383 data
->previous_cu_start
, start_addr
,
15384 data
->previous_cu_index
);
15386 data
->previous_cu_start
= start_addr
;
15389 struct psymtab_cu_index_map find_map
, *map
;
15390 find_map
.psymtab
= pst
;
15391 map
= htab_find (data
->cu_index_htab
, &find_map
);
15392 gdb_assert (map
!= NULL
);
15393 data
->previous_cu_index
= map
->cu_index
;
15394 data
->previous_valid
= 1;
15397 data
->previous_valid
= 0;
15402 /* Write OBJFILE's address map to OBSTACK.
15403 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
15404 in the index file. */
15407 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
15408 htab_t cu_index_htab
)
15410 struct addrmap_index_data addrmap_index_data
;
15412 /* When writing the address table, we have to cope with the fact that
15413 the addrmap iterator only provides the start of a region; we have to
15414 wait until the next invocation to get the start of the next region. */
15416 addrmap_index_data
.objfile
= objfile
;
15417 addrmap_index_data
.addr_obstack
= obstack
;
15418 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
15419 addrmap_index_data
.previous_valid
= 0;
15421 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
15422 &addrmap_index_data
);
15424 /* It's highly unlikely the last entry (end address = 0xff...ff)
15425 is valid, but we should still handle it.
15426 The end address is recorded as the start of the next region, but that
15427 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
15429 if (addrmap_index_data
.previous_valid
)
15430 add_address_entry (objfile
, obstack
,
15431 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
15432 addrmap_index_data
.previous_cu_index
);
15435 /* Add a list of partial symbols to SYMTAB. */
15438 write_psymbols (struct mapped_symtab
*symtab
,
15440 struct partial_symbol
**psymp
,
15442 offset_type cu_index
,
15445 for (; count
-- > 0; ++psymp
)
15447 void **slot
, *lookup
;
15449 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
15450 error (_("Ada is not currently supported by the index"));
15452 /* We only want to add a given psymbol once. However, we also
15453 want to account for whether it is global or static. So, we
15454 may add it twice, using slightly different values. */
15457 uintptr_t val
= 1 | (uintptr_t) *psymp
;
15459 lookup
= (void *) val
;
15464 /* Only add a given psymbol once. */
15465 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
15469 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
15474 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
15475 exception if there is an error. */
15478 write_obstack (FILE *file
, struct obstack
*obstack
)
15480 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
15482 != obstack_object_size (obstack
))
15483 error (_("couldn't data write to file"));
15486 /* Unlink a file if the argument is not NULL. */
15489 unlink_if_set (void *p
)
15491 char **filename
= p
;
15493 unlink (*filename
);
15496 /* A helper struct used when iterating over debug_types. */
15497 struct signatured_type_index_data
15499 struct objfile
*objfile
;
15500 struct mapped_symtab
*symtab
;
15501 struct obstack
*types_list
;
15506 /* A helper function that writes a single signatured_type to an
15510 write_one_signatured_type (void **slot
, void *d
)
15512 struct signatured_type_index_data
*info
= d
;
15513 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
15514 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
15515 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15518 write_psymbols (info
->symtab
,
15520 info
->objfile
->global_psymbols
.list
15521 + psymtab
->globals_offset
,
15522 psymtab
->n_global_syms
, info
->cu_index
,
15524 write_psymbols (info
->symtab
,
15526 info
->objfile
->static_psymbols
.list
15527 + psymtab
->statics_offset
,
15528 psymtab
->n_static_syms
, info
->cu_index
,
15531 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->offset
);
15532 obstack_grow (info
->types_list
, val
, 8);
15533 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
15534 obstack_grow (info
->types_list
, val
, 8);
15535 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
15536 obstack_grow (info
->types_list
, val
, 8);
15543 /* A cleanup function for an htab_t. */
15546 cleanup_htab (void *arg
)
15551 /* Create an index file for OBJFILE in the directory DIR. */
15554 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
15556 struct cleanup
*cleanup
;
15557 char *filename
, *cleanup_filename
;
15558 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
15559 struct obstack cu_list
, types_cu_list
;
15562 struct mapped_symtab
*symtab
;
15563 offset_type val
, size_of_contents
, total_len
;
15567 htab_t cu_index_htab
;
15568 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
15570 if (!objfile
->psymtabs
)
15572 if (dwarf2_per_objfile
->using_index
)
15573 error (_("Cannot use an index to create the index"));
15575 if (stat (objfile
->name
, &st
) < 0)
15576 perror_with_name (objfile
->name
);
15578 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
15579 INDEX_SUFFIX
, (char *) NULL
);
15580 cleanup
= make_cleanup (xfree
, filename
);
15582 out_file
= fopen (filename
, "wb");
15584 error (_("Can't open `%s' for writing"), filename
);
15586 cleanup_filename
= filename
;
15587 make_cleanup (unlink_if_set
, &cleanup_filename
);
15589 symtab
= create_mapped_symtab ();
15590 make_cleanup (cleanup_mapped_symtab
, symtab
);
15592 obstack_init (&addr_obstack
);
15593 make_cleanup_obstack_free (&addr_obstack
);
15595 obstack_init (&cu_list
);
15596 make_cleanup_obstack_free (&cu_list
);
15598 obstack_init (&types_cu_list
);
15599 make_cleanup_obstack_free (&types_cu_list
);
15601 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
15602 NULL
, xcalloc
, xfree
);
15603 make_cleanup (cleanup_htab
, psyms_seen
);
15605 /* While we're scanning CU's create a table that maps a psymtab pointer
15606 (which is what addrmap records) to its index (which is what is recorded
15607 in the index file). This will later be needed to write the address
15609 cu_index_htab
= htab_create_alloc (100,
15610 hash_psymtab_cu_index
,
15611 eq_psymtab_cu_index
,
15612 NULL
, xcalloc
, xfree
);
15613 make_cleanup (cleanup_htab
, cu_index_htab
);
15614 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
15615 xmalloc (sizeof (struct psymtab_cu_index_map
)
15616 * dwarf2_per_objfile
->n_comp_units
);
15617 make_cleanup (xfree
, psymtab_cu_index_map
);
15619 /* The CU list is already sorted, so we don't need to do additional
15620 work here. Also, the debug_types entries do not appear in
15621 all_comp_units, but only in their own hash table. */
15622 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
15624 struct dwarf2_per_cu_data
*per_cu
15625 = dwarf2_per_objfile
->all_comp_units
[i
];
15626 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15628 struct psymtab_cu_index_map
*map
;
15631 write_psymbols (symtab
,
15633 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15634 psymtab
->n_global_syms
, i
,
15636 write_psymbols (symtab
,
15638 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15639 psymtab
->n_static_syms
, i
,
15642 map
= &psymtab_cu_index_map
[i
];
15643 map
->psymtab
= psymtab
;
15645 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
15646 gdb_assert (slot
!= NULL
);
15647 gdb_assert (*slot
== NULL
);
15650 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
15651 obstack_grow (&cu_list
, val
, 8);
15652 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
15653 obstack_grow (&cu_list
, val
, 8);
15656 /* Dump the address map. */
15657 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
15659 /* Write out the .debug_type entries, if any. */
15660 if (dwarf2_per_objfile
->signatured_types
)
15662 struct signatured_type_index_data sig_data
;
15664 sig_data
.objfile
= objfile
;
15665 sig_data
.symtab
= symtab
;
15666 sig_data
.types_list
= &types_cu_list
;
15667 sig_data
.psyms_seen
= psyms_seen
;
15668 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
15669 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
15670 write_one_signatured_type
, &sig_data
);
15673 obstack_init (&constant_pool
);
15674 make_cleanup_obstack_free (&constant_pool
);
15675 obstack_init (&symtab_obstack
);
15676 make_cleanup_obstack_free (&symtab_obstack
);
15677 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
15679 obstack_init (&contents
);
15680 make_cleanup_obstack_free (&contents
);
15681 size_of_contents
= 6 * sizeof (offset_type
);
15682 total_len
= size_of_contents
;
15684 /* The version number. */
15685 val
= MAYBE_SWAP (3);
15686 obstack_grow (&contents
, &val
, sizeof (val
));
15688 /* The offset of the CU list from the start of the file. */
15689 val
= MAYBE_SWAP (total_len
);
15690 obstack_grow (&contents
, &val
, sizeof (val
));
15691 total_len
+= obstack_object_size (&cu_list
);
15693 /* The offset of the types CU list from the start of the file. */
15694 val
= MAYBE_SWAP (total_len
);
15695 obstack_grow (&contents
, &val
, sizeof (val
));
15696 total_len
+= obstack_object_size (&types_cu_list
);
15698 /* The offset of the address table from the start of the file. */
15699 val
= MAYBE_SWAP (total_len
);
15700 obstack_grow (&contents
, &val
, sizeof (val
));
15701 total_len
+= obstack_object_size (&addr_obstack
);
15703 /* The offset of the symbol table from the start of the file. */
15704 val
= MAYBE_SWAP (total_len
);
15705 obstack_grow (&contents
, &val
, sizeof (val
));
15706 total_len
+= obstack_object_size (&symtab_obstack
);
15708 /* The offset of the constant pool from the start of the file. */
15709 val
= MAYBE_SWAP (total_len
);
15710 obstack_grow (&contents
, &val
, sizeof (val
));
15711 total_len
+= obstack_object_size (&constant_pool
);
15713 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
15715 write_obstack (out_file
, &contents
);
15716 write_obstack (out_file
, &cu_list
);
15717 write_obstack (out_file
, &types_cu_list
);
15718 write_obstack (out_file
, &addr_obstack
);
15719 write_obstack (out_file
, &symtab_obstack
);
15720 write_obstack (out_file
, &constant_pool
);
15724 /* We want to keep the file, so we set cleanup_filename to NULL
15725 here. See unlink_if_set. */
15726 cleanup_filename
= NULL
;
15728 do_cleanups (cleanup
);
15731 /* The mapped index file format is designed to be directly mmap()able
15732 on any architecture. In most cases, a datum is represented using a
15733 little-endian 32-bit integer value, called an offset_type. Big
15734 endian machines must byte-swap the values before using them.
15735 Exceptions to this rule are noted. The data is laid out such that
15736 alignment is always respected.
15738 A mapped index consists of several sections.
15740 1. The file header. This is a sequence of values, of offset_type
15741 unless otherwise noted:
15743 [0] The version number, currently 3. Versions 1 and 2 are
15745 [1] The offset, from the start of the file, of the CU list.
15746 [2] The offset, from the start of the file, of the types CU list.
15747 Note that this section can be empty, in which case this offset will
15748 be equal to the next offset.
15749 [3] The offset, from the start of the file, of the address section.
15750 [4] The offset, from the start of the file, of the symbol table.
15751 [5] The offset, from the start of the file, of the constant pool.
15753 2. The CU list. This is a sequence of pairs of 64-bit
15754 little-endian values, sorted by the CU offset. The first element
15755 in each pair is the offset of a CU in the .debug_info section. The
15756 second element in each pair is the length of that CU. References
15757 to a CU elsewhere in the map are done using a CU index, which is
15758 just the 0-based index into this table. Note that if there are
15759 type CUs, then conceptually CUs and type CUs form a single list for
15760 the purposes of CU indices.
15762 3. The types CU list. This is a sequence of triplets of 64-bit
15763 little-endian values. In a triplet, the first value is the CU
15764 offset, the second value is the type offset in the CU, and the
15765 third value is the type signature. The types CU list is not
15768 4. The address section. The address section consists of a sequence
15769 of address entries. Each address entry has three elements.
15770 [0] The low address. This is a 64-bit little-endian value.
15771 [1] The high address. This is a 64-bit little-endian value.
15772 Like DW_AT_high_pc, the value is one byte beyond the end.
15773 [2] The CU index. This is an offset_type value.
15775 5. The symbol table. This is a hash table. The size of the hash
15776 table is always a power of 2. The initial hash and the step are
15777 currently defined by the `find_slot' function.
15779 Each slot in the hash table consists of a pair of offset_type
15780 values. The first value is the offset of the symbol's name in the
15781 constant pool. The second value is the offset of the CU vector in
15784 If both values are 0, then this slot in the hash table is empty.
15785 This is ok because while 0 is a valid constant pool index, it
15786 cannot be a valid index for both a string and a CU vector.
15788 A string in the constant pool is stored as a \0-terminated string,
15791 A CU vector in the constant pool is a sequence of offset_type
15792 values. The first value is the number of CU indices in the vector.
15793 Each subsequent value is the index of a CU in the CU list. This
15794 element in the hash table is used to indicate which CUs define the
15797 6. The constant pool. This is simply a bunch of bytes. It is
15798 organized so that alignment is correct: CU vectors are stored
15799 first, followed by strings. */
15802 save_gdb_index_command (char *arg
, int from_tty
)
15804 struct objfile
*objfile
;
15807 error (_("usage: save gdb-index DIRECTORY"));
15809 ALL_OBJFILES (objfile
)
15813 /* If the objfile does not correspond to an actual file, skip it. */
15814 if (stat (objfile
->name
, &st
) < 0)
15817 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15818 if (dwarf2_per_objfile
)
15820 volatile struct gdb_exception except
;
15822 TRY_CATCH (except
, RETURN_MASK_ERROR
)
15824 write_psymtabs_to_index (objfile
, arg
);
15826 if (except
.reason
< 0)
15827 exception_fprintf (gdb_stderr
, except
,
15828 _("Error while writing index for `%s': "),
15836 int dwarf2_always_disassemble
;
15839 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
15840 struct cmd_list_element
*c
, const char *value
)
15842 fprintf_filtered (file
,
15843 _("Whether to always disassemble "
15844 "DWARF expressions is %s.\n"),
15848 void _initialize_dwarf2_read (void);
15851 _initialize_dwarf2_read (void)
15853 struct cmd_list_element
*c
;
15855 dwarf2_objfile_data_key
15856 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
15858 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
15859 Set DWARF 2 specific variables.\n\
15860 Configure DWARF 2 variables such as the cache size"),
15861 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
15862 0/*allow-unknown*/, &maintenance_set_cmdlist
);
15864 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
15865 Show DWARF 2 specific variables\n\
15866 Show DWARF 2 variables such as the cache size"),
15867 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
15868 0/*allow-unknown*/, &maintenance_show_cmdlist
);
15870 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
15871 &dwarf2_max_cache_age
, _("\
15872 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
15873 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
15874 A higher limit means that cached compilation units will be stored\n\
15875 in memory longer, and more total memory will be used. Zero disables\n\
15876 caching, which can slow down startup."),
15878 show_dwarf2_max_cache_age
,
15879 &set_dwarf2_cmdlist
,
15880 &show_dwarf2_cmdlist
);
15882 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
15883 &dwarf2_always_disassemble
, _("\
15884 Set whether `info address' always disassembles DWARF expressions."), _("\
15885 Show whether `info address' always disassembles DWARF expressions."), _("\
15886 When enabled, DWARF expressions are always printed in an assembly-like\n\
15887 syntax. When disabled, expressions will be printed in a more\n\
15888 conversational style, when possible."),
15890 show_dwarf2_always_disassemble
,
15891 &set_dwarf2_cmdlist
,
15892 &show_dwarf2_cmdlist
);
15894 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
15895 Set debugging of the dwarf2 DIE reader."), _("\
15896 Show debugging of the dwarf2 DIE reader."), _("\
15897 When enabled (non-zero), DIEs are dumped after they are read in.\n\
15898 The value is the maximum depth to print."),
15901 &setdebuglist
, &showdebuglist
);
15903 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
15905 Save a gdb-index file.\n\
15906 Usage: save gdb-index DIRECTORY"),
15908 set_cmd_completer (c
, filename_completer
);