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
468 al. which are used for both .debug_info and .debug_types dies.
469 All parameters here are unchanging for the life of the call. This
470 struct exists to abstract away the constant parameters of die
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 /* A helper function that decides whether a section is empty. */
1515 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1517 return info
->asection
== NULL
|| info
->size
== 0;
1520 /* Read the contents of the section SECTP from object file specified by
1521 OBJFILE, store info about the section into INFO.
1522 If the section is compressed, uncompress it before returning. */
1525 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1527 bfd
*abfd
= objfile
->obfd
;
1528 asection
*sectp
= info
->asection
;
1529 gdb_byte
*buf
, *retbuf
;
1530 unsigned char header
[4];
1534 info
->buffer
= NULL
;
1535 info
->was_mmapped
= 0;
1538 if (dwarf2_section_empty_p (info
))
1541 /* Check if the file has a 4-byte header indicating compression. */
1542 if (info
->size
> sizeof (header
)
1543 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1544 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1546 /* Upon decompression, update the buffer and its size. */
1547 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1549 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1557 pagesize
= getpagesize ();
1559 /* Only try to mmap sections which are large enough: we don't want to
1560 waste space due to fragmentation. Also, only try mmap for sections
1561 without relocations. */
1563 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1565 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1566 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1567 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1568 MAP_PRIVATE
, pg_offset
);
1570 if (retbuf
!= MAP_FAILED
)
1572 info
->was_mmapped
= 1;
1573 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1574 #if HAVE_POSIX_MADVISE
1575 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1582 /* If we get here, we are a normal, not-compressed section. */
1584 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1586 /* When debugging .o files, we may need to apply relocations; see
1587 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1588 We never compress sections in .o files, so we only need to
1589 try this when the section is not compressed. */
1590 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1593 info
->buffer
= retbuf
;
1597 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1598 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1599 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1600 bfd_get_filename (abfd
));
1603 /* A helper function that returns the size of a section in a safe way.
1604 If you are positive that the section has been read before using the
1605 size, then it is safe to refer to the dwarf2_section_info object's
1606 "size" field directly. In other cases, you must call this
1607 function, because for compressed sections the size field is not set
1608 correctly until the section has been read. */
1610 static bfd_size_type
1611 dwarf2_section_size (struct objfile
*objfile
,
1612 struct dwarf2_section_info
*info
)
1615 dwarf2_read_section (objfile
, info
);
1619 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1623 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1624 asection
**sectp
, gdb_byte
**bufp
,
1625 bfd_size_type
*sizep
)
1627 struct dwarf2_per_objfile
*data
1628 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1629 struct dwarf2_section_info
*info
;
1631 /* We may see an objfile without any DWARF, in which case we just
1640 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1641 info
= &data
->eh_frame
;
1642 else if (section_is_p (section_name
, FRAME_SECTION
))
1643 info
= &data
->frame
;
1645 gdb_assert_not_reached ("unexpected section");
1647 dwarf2_read_section (objfile
, info
);
1649 *sectp
= info
->asection
;
1650 *bufp
= info
->buffer
;
1651 *sizep
= info
->size
;
1655 /* DWARF quick_symbols_functions support. */
1657 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1658 unique line tables, so we maintain a separate table of all .debug_line
1659 derived entries to support the sharing.
1660 All the quick functions need is the list of file names. We discard the
1661 line_header when we're done and don't need to record it here. */
1662 struct quick_file_names
1664 /* The offset in .debug_line of the line table. We hash on this. */
1665 unsigned int offset
;
1667 /* The number of entries in file_names, real_names. */
1668 unsigned int num_file_names
;
1670 /* The file names from the line table, after being run through
1672 const char **file_names
;
1674 /* The file names from the line table after being run through
1675 gdb_realpath. These are computed lazily. */
1676 const char **real_names
;
1679 /* When using the index (and thus not using psymtabs), each CU has an
1680 object of this type. This is used to hold information needed by
1681 the various "quick" methods. */
1682 struct dwarf2_per_cu_quick_data
1684 /* The file table. This can be NULL if there was no file table
1685 or it's currently not read in.
1686 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1687 struct quick_file_names
*file_names
;
1689 /* The corresponding symbol table. This is NULL if symbols for this
1690 CU have not yet been read. */
1691 struct symtab
*symtab
;
1693 /* A temporary mark bit used when iterating over all CUs in
1694 expand_symtabs_matching. */
1695 unsigned int mark
: 1;
1697 /* True if we've tried to read the file table and found there isn't one.
1698 There will be no point in trying to read it again next time. */
1699 unsigned int no_file_data
: 1;
1702 /* Hash function for a quick_file_names. */
1705 hash_file_name_entry (const void *e
)
1707 const struct quick_file_names
*file_data
= e
;
1709 return file_data
->offset
;
1712 /* Equality function for a quick_file_names. */
1715 eq_file_name_entry (const void *a
, const void *b
)
1717 const struct quick_file_names
*ea
= a
;
1718 const struct quick_file_names
*eb
= b
;
1720 return ea
->offset
== eb
->offset
;
1723 /* Delete function for a quick_file_names. */
1726 delete_file_name_entry (void *e
)
1728 struct quick_file_names
*file_data
= e
;
1731 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1733 xfree ((void*) file_data
->file_names
[i
]);
1734 if (file_data
->real_names
)
1735 xfree ((void*) file_data
->real_names
[i
]);
1738 /* The space for the struct itself lives on objfile_obstack,
1739 so we don't free it here. */
1742 /* Create a quick_file_names hash table. */
1745 create_quick_file_names_table (unsigned int nr_initial_entries
)
1747 return htab_create_alloc (nr_initial_entries
,
1748 hash_file_name_entry
, eq_file_name_entry
,
1749 delete_file_name_entry
, xcalloc
, xfree
);
1752 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1756 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1757 struct dwarf2_per_cu_data
*per_cu
)
1759 struct cleanup
*back_to
;
1761 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1763 queue_comp_unit (per_cu
, objfile
);
1765 if (per_cu
->from_debug_types
)
1766 read_signatured_type_at_offset (objfile
, per_cu
->offset
);
1768 load_full_comp_unit (per_cu
, objfile
);
1770 process_queue (objfile
);
1772 /* Age the cache, releasing compilation units that have not
1773 been used recently. */
1774 age_cached_comp_units ();
1776 do_cleanups (back_to
);
1779 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1780 the objfile from which this CU came. Returns the resulting symbol
1783 static struct symtab
*
1784 dw2_instantiate_symtab (struct objfile
*objfile
,
1785 struct dwarf2_per_cu_data
*per_cu
)
1787 if (!per_cu
->v
.quick
->symtab
)
1789 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1790 increment_reading_symtab ();
1791 dw2_do_instantiate_symtab (objfile
, per_cu
);
1792 do_cleanups (back_to
);
1794 return per_cu
->v
.quick
->symtab
;
1797 /* Return the CU given its index. */
1799 static struct dwarf2_per_cu_data
*
1800 dw2_get_cu (int index
)
1802 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1804 index
-= dwarf2_per_objfile
->n_comp_units
;
1805 return dwarf2_per_objfile
->type_comp_units
[index
];
1807 return dwarf2_per_objfile
->all_comp_units
[index
];
1810 /* A helper function that knows how to read a 64-bit value in a way
1811 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1815 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1817 if (sizeof (ULONGEST
) < 8)
1821 /* Ignore the upper 4 bytes if they are all zero. */
1822 for (i
= 0; i
< 4; ++i
)
1823 if (bytes
[i
+ 4] != 0)
1826 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1829 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1833 /* Read the CU list from the mapped index, and use it to create all
1834 the CU objects for this objfile. Return 0 if something went wrong,
1835 1 if everything went ok. */
1838 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1839 offset_type cu_list_elements
)
1843 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1844 dwarf2_per_objfile
->all_comp_units
1845 = obstack_alloc (&objfile
->objfile_obstack
,
1846 dwarf2_per_objfile
->n_comp_units
1847 * sizeof (struct dwarf2_per_cu_data
*));
1849 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1851 struct dwarf2_per_cu_data
*the_cu
;
1852 ULONGEST offset
, length
;
1854 if (!extract_cu_value (cu_list
, &offset
)
1855 || !extract_cu_value (cu_list
+ 8, &length
))
1859 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1860 struct dwarf2_per_cu_data
);
1861 the_cu
->offset
= offset
;
1862 the_cu
->length
= length
;
1863 the_cu
->objfile
= objfile
;
1864 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1865 struct dwarf2_per_cu_quick_data
);
1866 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1872 /* Create the signatured type hash table from the index. */
1875 create_signatured_type_table_from_index (struct objfile
*objfile
,
1876 const gdb_byte
*bytes
,
1877 offset_type elements
)
1880 htab_t sig_types_hash
;
1882 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1883 dwarf2_per_objfile
->type_comp_units
1884 = obstack_alloc (&objfile
->objfile_obstack
,
1885 dwarf2_per_objfile
->n_type_comp_units
1886 * sizeof (struct dwarf2_per_cu_data
*));
1888 sig_types_hash
= allocate_signatured_type_table (objfile
);
1890 for (i
= 0; i
< elements
; i
+= 3)
1892 struct signatured_type
*type_sig
;
1893 ULONGEST offset
, type_offset
, signature
;
1896 if (!extract_cu_value (bytes
, &offset
)
1897 || !extract_cu_value (bytes
+ 8, &type_offset
))
1899 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1902 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1903 struct signatured_type
);
1904 type_sig
->signature
= signature
;
1905 type_sig
->offset
= offset
;
1906 type_sig
->type_offset
= type_offset
;
1907 type_sig
->per_cu
.from_debug_types
= 1;
1908 type_sig
->per_cu
.offset
= offset
;
1909 type_sig
->per_cu
.objfile
= objfile
;
1910 type_sig
->per_cu
.v
.quick
1911 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1912 struct dwarf2_per_cu_quick_data
);
1914 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1917 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1920 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1925 /* Read the address map data from the mapped index, and use it to
1926 populate the objfile's psymtabs_addrmap. */
1929 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1931 const gdb_byte
*iter
, *end
;
1932 struct obstack temp_obstack
;
1933 struct addrmap
*mutable_map
;
1934 struct cleanup
*cleanup
;
1937 obstack_init (&temp_obstack
);
1938 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1939 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1941 iter
= index
->address_table
;
1942 end
= iter
+ index
->address_table_size
;
1944 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1948 ULONGEST hi
, lo
, cu_index
;
1949 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1951 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1953 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1956 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1957 dw2_get_cu (cu_index
));
1960 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1961 &objfile
->objfile_obstack
);
1962 do_cleanups (cleanup
);
1965 /* The hash function for strings in the mapped index. This is the
1966 same as the hashtab.c hash function, but we keep a separate copy to
1967 maintain control over the implementation. This is necessary
1968 because the hash function is tied to the format of the mapped index
1972 mapped_index_string_hash (const void *p
)
1974 const unsigned char *str
= (const unsigned char *) p
;
1978 while ((c
= *str
++) != 0)
1979 r
= r
* 67 + c
- 113;
1984 /* Find a slot in the mapped index INDEX for the object named NAME.
1985 If NAME is found, set *VEC_OUT to point to the CU vector in the
1986 constant pool and return 1. If NAME cannot be found, return 0. */
1989 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
1990 offset_type
**vec_out
)
1992 offset_type hash
= mapped_index_string_hash (name
);
1993 offset_type slot
, step
;
1995 slot
= hash
& (index
->symbol_table_slots
- 1);
1996 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2000 /* Convert a slot number to an offset into the table. */
2001 offset_type i
= 2 * slot
;
2003 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2006 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2007 if (!strcmp (name
, str
))
2009 *vec_out
= (offset_type
*) (index
->constant_pool
2010 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2014 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2018 /* Read the index file. If everything went ok, initialize the "quick"
2019 elements of all the CUs and return 1. Otherwise, return 0. */
2022 dwarf2_read_index (struct objfile
*objfile
)
2025 struct mapped_index
*map
;
2026 offset_type
*metadata
;
2027 const gdb_byte
*cu_list
;
2028 const gdb_byte
*types_list
= NULL
;
2029 offset_type version
, cu_list_elements
;
2030 offset_type types_list_elements
= 0;
2033 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2036 /* Older elfutils strip versions could keep the section in the main
2037 executable while splitting it for the separate debug info file. */
2038 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2039 & SEC_HAS_CONTENTS
) == 0)
2042 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2044 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2045 /* Version check. */
2046 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2047 /* Versions earlier than 3 emitted every copy of a psymbol. This
2048 causes the index to behave very poorly for certain requests. Version 4
2049 contained incomplete addrmap. So, it seems better to just ignore such
2053 /* Indexes with higher version than the one supported by GDB may be no
2054 longer backward compatible. */
2058 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2059 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2061 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2064 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2065 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2069 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2070 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2071 - MAYBE_SWAP (metadata
[i
]))
2075 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2076 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2077 - MAYBE_SWAP (metadata
[i
]));
2080 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2081 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2082 - MAYBE_SWAP (metadata
[i
]))
2083 / (2 * sizeof (offset_type
)));
2086 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2088 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2091 if (types_list_elements
2092 && !create_signatured_type_table_from_index (objfile
, types_list
,
2093 types_list_elements
))
2096 create_addrmap_from_index (objfile
, map
);
2098 dwarf2_per_objfile
->index_table
= map
;
2099 dwarf2_per_objfile
->using_index
= 1;
2100 dwarf2_per_objfile
->quick_file_names_table
=
2101 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2106 /* A helper for the "quick" functions which sets the global
2107 dwarf2_per_objfile according to OBJFILE. */
2110 dw2_setup (struct objfile
*objfile
)
2112 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2113 gdb_assert (dwarf2_per_objfile
);
2116 /* A helper for the "quick" functions which attempts to read the line
2117 table for THIS_CU. */
2119 static struct quick_file_names
*
2120 dw2_get_file_names (struct objfile
*objfile
,
2121 struct dwarf2_per_cu_data
*this_cu
)
2123 bfd
*abfd
= objfile
->obfd
;
2124 struct line_header
*lh
;
2125 struct attribute
*attr
;
2126 struct cleanup
*cleanups
;
2127 struct die_info
*comp_unit_die
;
2128 struct dwarf2_section_info
* sec
;
2129 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2130 int has_children
, i
;
2131 struct dwarf2_cu cu
;
2132 unsigned int bytes_read
, buffer_size
;
2133 struct die_reader_specs reader_specs
;
2134 char *name
, *comp_dir
;
2136 struct quick_file_names
*qfn
;
2137 unsigned int line_offset
;
2139 if (this_cu
->v
.quick
->file_names
!= NULL
)
2140 return this_cu
->v
.quick
->file_names
;
2141 /* If we know there is no line data, no point in looking again. */
2142 if (this_cu
->v
.quick
->no_file_data
)
2145 init_one_comp_unit (&cu
, objfile
);
2146 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2148 if (this_cu
->from_debug_types
)
2149 sec
= &dwarf2_per_objfile
->types
;
2151 sec
= &dwarf2_per_objfile
->info
;
2152 dwarf2_read_section (objfile
, sec
);
2153 buffer_size
= sec
->size
;
2154 buffer
= sec
->buffer
;
2155 info_ptr
= buffer
+ this_cu
->offset
;
2156 beg_of_comp_unit
= info_ptr
;
2158 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2159 buffer
, buffer_size
,
2162 /* Complete the cu_header. */
2163 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2164 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2167 cu
.per_cu
= this_cu
;
2169 dwarf2_read_abbrevs (abfd
, &cu
);
2170 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2172 if (this_cu
->from_debug_types
)
2173 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2174 init_cu_die_reader (&reader_specs
, &cu
);
2175 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2181 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2184 struct quick_file_names find_entry
;
2186 line_offset
= DW_UNSND (attr
);
2188 /* We may have already read in this line header (TU line header sharing).
2189 If we have we're done. */
2190 find_entry
.offset
= line_offset
;
2191 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2192 &find_entry
, INSERT
);
2195 do_cleanups (cleanups
);
2196 this_cu
->v
.quick
->file_names
= *slot
;
2200 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2204 do_cleanups (cleanups
);
2205 this_cu
->v
.quick
->no_file_data
= 1;
2209 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2210 qfn
->offset
= line_offset
;
2211 gdb_assert (slot
!= NULL
);
2214 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2216 qfn
->num_file_names
= lh
->num_file_names
;
2217 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2218 lh
->num_file_names
* sizeof (char *));
2219 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2220 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2221 qfn
->real_names
= NULL
;
2223 free_line_header (lh
);
2224 do_cleanups (cleanups
);
2226 this_cu
->v
.quick
->file_names
= qfn
;
2230 /* A helper for the "quick" functions which computes and caches the
2231 real path for a given file name from the line table. */
2234 dw2_get_real_path (struct objfile
*objfile
,
2235 struct quick_file_names
*qfn
, int index
)
2237 if (qfn
->real_names
== NULL
)
2238 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2239 qfn
->num_file_names
, sizeof (char *));
2241 if (qfn
->real_names
[index
] == NULL
)
2242 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2244 return qfn
->real_names
[index
];
2247 static struct symtab
*
2248 dw2_find_last_source_symtab (struct objfile
*objfile
)
2252 dw2_setup (objfile
);
2253 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2254 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2257 /* Traversal function for dw2_forget_cached_source_info. */
2260 dw2_free_cached_file_names (void **slot
, void *info
)
2262 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2264 if (file_data
->real_names
)
2268 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2270 xfree ((void*) file_data
->real_names
[i
]);
2271 file_data
->real_names
[i
] = NULL
;
2279 dw2_forget_cached_source_info (struct objfile
*objfile
)
2281 dw2_setup (objfile
);
2283 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2284 dw2_free_cached_file_names
, NULL
);
2288 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2289 const char *full_path
, const char *real_path
,
2290 struct symtab
**result
)
2293 int check_basename
= lbasename (name
) == name
;
2294 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2296 dw2_setup (objfile
);
2298 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2299 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2302 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2303 struct quick_file_names
*file_data
;
2305 if (per_cu
->v
.quick
->symtab
)
2308 file_data
= dw2_get_file_names (objfile
, per_cu
);
2309 if (file_data
== NULL
)
2312 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2314 const char *this_name
= file_data
->file_names
[j
];
2316 if (FILENAME_CMP (name
, this_name
) == 0)
2318 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2322 if (check_basename
&& ! base_cu
2323 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2326 if (full_path
!= NULL
)
2328 const char *this_real_name
= dw2_get_real_path (objfile
,
2331 if (this_real_name
!= NULL
2332 && FILENAME_CMP (full_path
, this_real_name
) == 0)
2334 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2339 if (real_path
!= NULL
)
2341 const char *this_real_name
= dw2_get_real_path (objfile
,
2344 if (this_real_name
!= NULL
2345 && FILENAME_CMP (real_path
, this_real_name
) == 0)
2347 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2356 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2363 static struct symtab
*
2364 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2365 const char *name
, domain_enum domain
)
2367 /* We do all the work in the pre_expand_symtabs_matching hook
2372 /* A helper function that expands all symtabs that hold an object
2376 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2378 dw2_setup (objfile
);
2380 /* index_table is NULL if OBJF_READNOW. */
2381 if (dwarf2_per_objfile
->index_table
)
2385 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2388 offset_type i
, len
= MAYBE_SWAP (*vec
);
2389 for (i
= 0; i
< len
; ++i
)
2391 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2392 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2394 dw2_instantiate_symtab (objfile
, per_cu
);
2401 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2402 int kind
, const char *name
,
2405 dw2_do_expand_symtabs_matching (objfile
, name
);
2409 dw2_print_stats (struct objfile
*objfile
)
2413 dw2_setup (objfile
);
2415 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2416 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2418 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2420 if (!per_cu
->v
.quick
->symtab
)
2423 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2427 dw2_dump (struct objfile
*objfile
)
2429 /* Nothing worth printing. */
2433 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2434 struct section_offsets
*delta
)
2436 /* There's nothing to relocate here. */
2440 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2441 const char *func_name
)
2443 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2447 dw2_expand_all_symtabs (struct objfile
*objfile
)
2451 dw2_setup (objfile
);
2453 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2454 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2456 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2458 dw2_instantiate_symtab (objfile
, per_cu
);
2463 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2464 const char *filename
)
2468 dw2_setup (objfile
);
2470 /* We don't need to consider type units here.
2471 This is only called for examining code, e.g. expand_line_sal.
2472 There can be an order of magnitude (or more) more type units
2473 than comp units, and we avoid them if we can. */
2475 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2478 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2479 struct quick_file_names
*file_data
;
2481 if (per_cu
->v
.quick
->symtab
)
2484 file_data
= dw2_get_file_names (objfile
, per_cu
);
2485 if (file_data
== NULL
)
2488 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2490 const char *this_name
= file_data
->file_names
[j
];
2491 if (FILENAME_CMP (this_name
, filename
) == 0)
2493 dw2_instantiate_symtab (objfile
, per_cu
);
2501 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2503 struct dwarf2_per_cu_data
*per_cu
;
2505 struct quick_file_names
*file_data
;
2507 dw2_setup (objfile
);
2509 /* index_table is NULL if OBJF_READNOW. */
2510 if (!dwarf2_per_objfile
->index_table
)
2513 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2517 /* Note that this just looks at the very first one named NAME -- but
2518 actually we are looking for a function. find_main_filename
2519 should be rewritten so that it doesn't require a custom hook. It
2520 could just use the ordinary symbol tables. */
2521 /* vec[0] is the length, which must always be >0. */
2522 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2524 file_data
= dw2_get_file_names (objfile
, per_cu
);
2525 if (file_data
== NULL
)
2528 return file_data
->file_names
[file_data
->num_file_names
- 1];
2532 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2533 struct objfile
*objfile
, int global
,
2534 int (*callback
) (struct block
*,
2535 struct symbol
*, void *),
2536 void *data
, symbol_compare_ftype
*match
,
2537 symbol_compare_ftype
*ordered_compare
)
2539 /* Currently unimplemented; used for Ada. The function can be called if the
2540 current language is Ada for a non-Ada objfile using GNU index. As Ada
2541 does not look for non-Ada symbols this function should just return. */
2545 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2546 int (*file_matcher
) (const char *, void *),
2547 int (*name_matcher
) (const char *, void *),
2553 struct mapped_index
*index
;
2555 dw2_setup (objfile
);
2557 /* index_table is NULL if OBJF_READNOW. */
2558 if (!dwarf2_per_objfile
->index_table
)
2560 index
= dwarf2_per_objfile
->index_table
;
2562 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2563 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2566 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2567 struct quick_file_names
*file_data
;
2569 per_cu
->v
.quick
->mark
= 0;
2570 if (per_cu
->v
.quick
->symtab
)
2573 file_data
= dw2_get_file_names (objfile
, per_cu
);
2574 if (file_data
== NULL
)
2577 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2579 if (file_matcher (file_data
->file_names
[j
], data
))
2581 per_cu
->v
.quick
->mark
= 1;
2587 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2589 offset_type idx
= 2 * iter
;
2591 offset_type
*vec
, vec_len
, vec_idx
;
2593 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2596 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2598 if (! (*name_matcher
) (name
, data
))
2601 /* The name was matched, now expand corresponding CUs that were
2603 vec
= (offset_type
*) (index
->constant_pool
2604 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2605 vec_len
= MAYBE_SWAP (vec
[0]);
2606 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2608 struct dwarf2_per_cu_data
*per_cu
;
2610 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2611 if (per_cu
->v
.quick
->mark
)
2612 dw2_instantiate_symtab (objfile
, per_cu
);
2617 static struct symtab
*
2618 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2619 struct minimal_symbol
*msymbol
,
2621 struct obj_section
*section
,
2624 struct dwarf2_per_cu_data
*data
;
2626 dw2_setup (objfile
);
2628 if (!objfile
->psymtabs_addrmap
)
2631 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2635 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2636 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2637 paddress (get_objfile_arch (objfile
), pc
));
2639 return dw2_instantiate_symtab (objfile
, data
);
2643 dw2_map_symbol_names (struct objfile
*objfile
,
2644 void (*fun
) (const char *, void *),
2648 struct mapped_index
*index
;
2650 dw2_setup (objfile
);
2652 /* index_table is NULL if OBJF_READNOW. */
2653 if (!dwarf2_per_objfile
->index_table
)
2655 index
= dwarf2_per_objfile
->index_table
;
2657 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2659 offset_type idx
= 2 * iter
;
2661 offset_type
*vec
, vec_len
, vec_idx
;
2663 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2666 name
= (index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]));
2668 (*fun
) (name
, data
);
2673 dw2_map_symbol_filenames (struct objfile
*objfile
,
2674 void (*fun
) (const char *, const char *, void *),
2679 dw2_setup (objfile
);
2681 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2682 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2685 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2686 struct quick_file_names
*file_data
;
2688 if (per_cu
->v
.quick
->symtab
)
2691 file_data
= dw2_get_file_names (objfile
, per_cu
);
2692 if (file_data
== NULL
)
2695 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2697 const char *this_real_name
= dw2_get_real_path (objfile
, file_data
,
2699 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2705 dw2_has_symbols (struct objfile
*objfile
)
2710 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2713 dw2_find_last_source_symtab
,
2714 dw2_forget_cached_source_info
,
2717 dw2_pre_expand_symtabs_matching
,
2721 dw2_expand_symtabs_for_function
,
2722 dw2_expand_all_symtabs
,
2723 dw2_expand_symtabs_with_filename
,
2724 dw2_find_symbol_file
,
2725 dw2_map_matching_symbols
,
2726 dw2_expand_symtabs_matching
,
2727 dw2_find_pc_sect_symtab
,
2728 dw2_map_symbol_names
,
2729 dw2_map_symbol_filenames
2732 /* Initialize for reading DWARF for this objfile. Return 0 if this
2733 file will use psymtabs, or 1 if using the GNU index. */
2736 dwarf2_initialize_objfile (struct objfile
*objfile
)
2738 /* If we're about to read full symbols, don't bother with the
2739 indices. In this case we also don't care if some other debug
2740 format is making psymtabs, because they are all about to be
2742 if ((objfile
->flags
& OBJF_READNOW
))
2746 dwarf2_per_objfile
->using_index
= 1;
2747 create_all_comp_units (objfile
);
2748 create_debug_types_hash_table (objfile
);
2749 dwarf2_per_objfile
->quick_file_names_table
=
2750 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2752 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2753 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2755 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2757 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2758 struct dwarf2_per_cu_quick_data
);
2761 /* Return 1 so that gdb sees the "quick" functions. However,
2762 these functions will be no-ops because we will have expanded
2767 if (dwarf2_read_index (objfile
))
2770 dwarf2_build_psymtabs (objfile
);
2776 /* Build a partial symbol table. */
2779 dwarf2_build_psymtabs (struct objfile
*objfile
)
2781 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2783 init_psymbol_list (objfile
, 1024);
2786 dwarf2_build_psymtabs_hard (objfile
);
2789 /* Return TRUE if OFFSET is within CU_HEADER. */
2792 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2794 unsigned int bottom
= cu_header
->offset
;
2795 unsigned int top
= (cu_header
->offset
2797 + cu_header
->initial_length_size
);
2799 return (offset
>= bottom
&& offset
< top
);
2802 /* Read in the comp unit header information from the debug_info at info_ptr.
2803 NOTE: This leaves members offset, first_die_offset to be filled in
2807 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2808 gdb_byte
*info_ptr
, bfd
*abfd
)
2811 unsigned int bytes_read
;
2813 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2814 cu_header
->initial_length_size
= bytes_read
;
2815 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2816 info_ptr
+= bytes_read
;
2817 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2819 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2821 info_ptr
+= bytes_read
;
2822 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2824 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2825 if (signed_addr
< 0)
2826 internal_error (__FILE__
, __LINE__
,
2827 _("read_comp_unit_head: dwarf from non elf file"));
2828 cu_header
->signed_addr_p
= signed_addr
;
2834 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2835 gdb_byte
*buffer
, unsigned int buffer_size
,
2838 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2840 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2842 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2843 error (_("Dwarf Error: wrong version in compilation unit header "
2844 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2845 bfd_get_filename (abfd
));
2847 if (header
->abbrev_offset
2848 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
2849 &dwarf2_per_objfile
->abbrev
))
2850 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2851 "(offset 0x%lx + 6) [in module %s]"),
2852 (long) header
->abbrev_offset
,
2853 (long) (beg_of_comp_unit
- buffer
),
2854 bfd_get_filename (abfd
));
2856 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2857 > buffer
+ buffer_size
)
2858 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2859 "(offset 0x%lx + 0) [in module %s]"),
2860 (long) header
->length
,
2861 (long) (beg_of_comp_unit
- buffer
),
2862 bfd_get_filename (abfd
));
2867 /* Read in the types comp unit header information from .debug_types entry at
2868 types_ptr. The result is a pointer to one past the end of the header. */
2871 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2872 ULONGEST
*signature
,
2873 gdb_byte
*types_ptr
, bfd
*abfd
)
2875 gdb_byte
*initial_types_ptr
= types_ptr
;
2877 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2878 &dwarf2_per_objfile
->types
);
2879 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2881 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2883 *signature
= read_8_bytes (abfd
, types_ptr
);
2885 types_ptr
+= cu_header
->offset_size
;
2886 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2891 /* Allocate a new partial symtab for file named NAME and mark this new
2892 partial symtab as being an include of PST. */
2895 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2896 struct objfile
*objfile
)
2898 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2900 subpst
->section_offsets
= pst
->section_offsets
;
2901 subpst
->textlow
= 0;
2902 subpst
->texthigh
= 0;
2904 subpst
->dependencies
= (struct partial_symtab
**)
2905 obstack_alloc (&objfile
->objfile_obstack
,
2906 sizeof (struct partial_symtab
*));
2907 subpst
->dependencies
[0] = pst
;
2908 subpst
->number_of_dependencies
= 1;
2910 subpst
->globals_offset
= 0;
2911 subpst
->n_global_syms
= 0;
2912 subpst
->statics_offset
= 0;
2913 subpst
->n_static_syms
= 0;
2914 subpst
->symtab
= NULL
;
2915 subpst
->read_symtab
= pst
->read_symtab
;
2918 /* No private part is necessary for include psymtabs. This property
2919 can be used to differentiate between such include psymtabs and
2920 the regular ones. */
2921 subpst
->read_symtab_private
= NULL
;
2924 /* Read the Line Number Program data and extract the list of files
2925 included by the source file represented by PST. Build an include
2926 partial symtab for each of these included files. */
2929 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2930 struct die_info
*die
,
2931 struct partial_symtab
*pst
)
2933 struct objfile
*objfile
= cu
->objfile
;
2934 bfd
*abfd
= objfile
->obfd
;
2935 struct line_header
*lh
= NULL
;
2936 struct attribute
*attr
;
2938 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2941 unsigned int line_offset
= DW_UNSND (attr
);
2943 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2946 return; /* No linetable, so no includes. */
2948 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2949 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
2951 free_line_header (lh
);
2955 hash_type_signature (const void *item
)
2957 const struct signatured_type
*type_sig
= item
;
2959 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2960 return type_sig
->signature
;
2964 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2966 const struct signatured_type
*lhs
= item_lhs
;
2967 const struct signatured_type
*rhs
= item_rhs
;
2969 return lhs
->signature
== rhs
->signature
;
2972 /* Allocate a hash table for signatured types. */
2975 allocate_signatured_type_table (struct objfile
*objfile
)
2977 return htab_create_alloc_ex (41,
2978 hash_type_signature
,
2981 &objfile
->objfile_obstack
,
2982 hashtab_obstack_allocate
,
2983 dummy_obstack_deallocate
);
2986 /* A helper function to add a signatured type CU to a list. */
2989 add_signatured_type_cu_to_list (void **slot
, void *datum
)
2991 struct signatured_type
*sigt
= *slot
;
2992 struct dwarf2_per_cu_data
***datap
= datum
;
2994 **datap
= &sigt
->per_cu
;
3000 /* Create the hash table of all entries in the .debug_types section.
3001 The result is zero if there is an error (e.g. missing .debug_types section),
3002 otherwise non-zero. */
3005 create_debug_types_hash_table (struct objfile
*objfile
)
3009 struct dwarf2_per_cu_data
**iter
;
3011 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
3012 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
3014 if (info_ptr
== NULL
)
3016 dwarf2_per_objfile
->signatured_types
= NULL
;
3020 types_htab
= allocate_signatured_type_table (objfile
);
3022 if (dwarf2_die_debug
)
3023 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3025 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
3026 + dwarf2_per_objfile
->types
.size
)
3028 unsigned int offset
;
3029 unsigned int offset_size
;
3030 unsigned int type_offset
;
3031 unsigned int length
, initial_length_size
;
3032 unsigned short version
;
3034 struct signatured_type
*type_sig
;
3036 gdb_byte
*ptr
= info_ptr
;
3038 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
3040 /* We need to read the type's signature in order to build the hash
3041 table, but we don't need to read anything else just yet. */
3043 /* Sanity check to ensure entire cu is present. */
3044 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
3045 if (ptr
+ length
+ initial_length_size
3046 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
3048 complaint (&symfile_complaints
,
3049 _("debug type entry runs off end "
3050 "of `.debug_types' section, ignored"));
3054 offset_size
= initial_length_size
== 4 ? 4 : 8;
3055 ptr
+= initial_length_size
;
3056 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3058 ptr
+= offset_size
; /* abbrev offset */
3059 ptr
+= 1; /* address size */
3060 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3062 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3064 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3065 memset (type_sig
, 0, sizeof (*type_sig
));
3066 type_sig
->signature
= signature
;
3067 type_sig
->offset
= offset
;
3068 type_sig
->type_offset
= type_offset
;
3069 type_sig
->per_cu
.objfile
= objfile
;
3070 type_sig
->per_cu
.from_debug_types
= 1;
3072 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3073 gdb_assert (slot
!= NULL
);
3076 if (dwarf2_die_debug
)
3077 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3078 offset
, phex (signature
, sizeof (signature
)));
3080 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3083 dwarf2_per_objfile
->signatured_types
= types_htab
;
3085 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3086 dwarf2_per_objfile
->type_comp_units
3087 = obstack_alloc (&objfile
->objfile_obstack
,
3088 dwarf2_per_objfile
->n_type_comp_units
3089 * sizeof (struct dwarf2_per_cu_data
*));
3090 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3091 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3092 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3093 == dwarf2_per_objfile
->n_type_comp_units
);
3098 /* Lookup a signature based type.
3099 Returns NULL if SIG is not present in the table. */
3101 static struct signatured_type
*
3102 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3104 struct signatured_type find_entry
, *entry
;
3106 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3108 complaint (&symfile_complaints
,
3109 _("missing `.debug_types' section for DW_FORM_sig8 die"));
3113 find_entry
.signature
= sig
;
3114 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3118 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3121 init_cu_die_reader (struct die_reader_specs
*reader
,
3122 struct dwarf2_cu
*cu
)
3124 reader
->abfd
= cu
->objfile
->obfd
;
3126 if (cu
->per_cu
->from_debug_types
)
3128 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3129 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
3133 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3134 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3138 /* Find the base address of the compilation unit for range lists and
3139 location lists. It will normally be specified by DW_AT_low_pc.
3140 In DWARF-3 draft 4, the base address could be overridden by
3141 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3142 compilation units with discontinuous ranges. */
3145 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3147 struct attribute
*attr
;
3150 cu
->base_address
= 0;
3152 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3155 cu
->base_address
= DW_ADDR (attr
);
3160 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3163 cu
->base_address
= DW_ADDR (attr
);
3169 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3170 to combine the common parts.
3171 Process a compilation unit for a psymtab.
3172 BUFFER is a pointer to the beginning of the dwarf section buffer,
3173 either .debug_info or debug_types.
3174 INFO_PTR is a pointer to the start of the CU.
3175 Returns a pointer to the next CU. */
3178 process_psymtab_comp_unit (struct objfile
*objfile
,
3179 struct dwarf2_per_cu_data
*this_cu
,
3180 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3181 unsigned int buffer_size
)
3183 bfd
*abfd
= objfile
->obfd
;
3184 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3185 struct die_info
*comp_unit_die
;
3186 struct partial_symtab
*pst
;
3188 struct cleanup
*back_to_inner
;
3189 struct dwarf2_cu cu
;
3190 int has_children
, has_pc_info
;
3191 struct attribute
*attr
;
3192 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3193 struct die_reader_specs reader_specs
;
3195 init_one_comp_unit (&cu
, objfile
);
3196 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3198 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3199 buffer
, buffer_size
,
3202 /* Complete the cu_header. */
3203 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3204 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3206 cu
.list_in_scope
= &file_symbols
;
3208 /* If this compilation unit was already read in, free the
3209 cached copy in order to read it in again. This is
3210 necessary because we skipped some symbols when we first
3211 read in the compilation unit (see load_partial_dies).
3212 This problem could be avoided, but the benefit is
3214 if (this_cu
->cu
!= NULL
)
3215 free_one_cached_comp_unit (this_cu
->cu
);
3217 /* Note that this is a pointer to our stack frame, being
3218 added to a global data structure. It will be cleaned up
3219 in free_stack_comp_unit when we finish with this
3220 compilation unit. */
3222 cu
.per_cu
= this_cu
;
3224 /* Read the abbrevs for this compilation unit into a table. */
3225 dwarf2_read_abbrevs (abfd
, &cu
);
3226 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3228 /* Read the compilation unit die. */
3229 if (this_cu
->from_debug_types
)
3230 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3231 init_cu_die_reader (&reader_specs
, &cu
);
3232 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3235 if (this_cu
->from_debug_types
)
3237 /* offset,length haven't been set yet for type units. */
3238 this_cu
->offset
= cu
.header
.offset
;
3239 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3241 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3243 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3244 + cu
.header
.initial_length_size
);
3245 do_cleanups (back_to_inner
);
3249 prepare_one_comp_unit (&cu
, comp_unit_die
);
3251 /* Allocate a new partial symbol table structure. */
3252 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3253 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3254 (attr
!= NULL
) ? DW_STRING (attr
) : "",
3255 /* TEXTLOW and TEXTHIGH are set below. */
3257 objfile
->global_psymbols
.next
,
3258 objfile
->static_psymbols
.next
);
3260 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3262 pst
->dirname
= DW_STRING (attr
);
3264 pst
->read_symtab_private
= this_cu
;
3266 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3268 /* Store the function that reads in the rest of the symbol table. */
3269 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3271 this_cu
->v
.psymtab
= pst
;
3273 dwarf2_find_base_address (comp_unit_die
, &cu
);
3275 /* Possibly set the default values of LOWPC and HIGHPC from
3277 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3278 &best_highpc
, &cu
, pst
);
3279 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3280 /* Store the contiguous range if it is not empty; it can be empty for
3281 CUs with no code. */
3282 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3283 best_lowpc
+ baseaddr
,
3284 best_highpc
+ baseaddr
- 1, pst
);
3286 /* Check if comp unit has_children.
3287 If so, read the rest of the partial symbols from this comp unit.
3288 If not, there's no more debug_info for this comp unit. */
3291 struct partial_die_info
*first_die
;
3292 CORE_ADDR lowpc
, highpc
;
3294 lowpc
= ((CORE_ADDR
) -1);
3295 highpc
= ((CORE_ADDR
) 0);
3297 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3299 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3300 ! has_pc_info
, &cu
);
3302 /* If we didn't find a lowpc, set it to highpc to avoid
3303 complaints from `maint check'. */
3304 if (lowpc
== ((CORE_ADDR
) -1))
3307 /* If the compilation unit didn't have an explicit address range,
3308 then use the information extracted from its child dies. */
3312 best_highpc
= highpc
;
3315 pst
->textlow
= best_lowpc
+ baseaddr
;
3316 pst
->texthigh
= best_highpc
+ baseaddr
;
3318 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3319 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3320 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3321 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3322 sort_pst_symbols (pst
);
3324 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3325 + cu
.header
.initial_length_size
);
3327 if (this_cu
->from_debug_types
)
3329 /* It's not clear we want to do anything with stmt lists here.
3330 Waiting to see what gcc ultimately does. */
3334 /* Get the list of files included in the current compilation unit,
3335 and build a psymtab for each of them. */
3336 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3339 do_cleanups (back_to_inner
);
3344 /* Traversal function for htab_traverse_noresize.
3345 Process one .debug_types comp-unit. */
3348 process_type_comp_unit (void **slot
, void *info
)
3350 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3351 struct objfile
*objfile
= (struct objfile
*) info
;
3352 struct dwarf2_per_cu_data
*this_cu
;
3354 this_cu
= &entry
->per_cu
;
3356 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3357 process_psymtab_comp_unit (objfile
, this_cu
,
3358 dwarf2_per_objfile
->types
.buffer
,
3359 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
3360 dwarf2_per_objfile
->types
.size
);
3365 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3366 Build partial symbol tables for the .debug_types comp-units. */
3369 build_type_psymtabs (struct objfile
*objfile
)
3371 if (! create_debug_types_hash_table (objfile
))
3374 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3375 process_type_comp_unit
, objfile
);
3378 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3381 psymtabs_addrmap_cleanup (void *o
)
3383 struct objfile
*objfile
= o
;
3385 objfile
->psymtabs_addrmap
= NULL
;
3388 /* Build the partial symbol table by doing a quick pass through the
3389 .debug_info and .debug_abbrev sections. */
3392 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3395 struct cleanup
*back_to
, *addrmap_cleanup
;
3396 struct obstack temp_obstack
;
3398 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3400 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3401 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3403 /* Any cached compilation units will be linked by the per-objfile
3404 read_in_chain. Make sure to free them when we're done. */
3405 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3407 build_type_psymtabs (objfile
);
3409 create_all_comp_units (objfile
);
3411 /* Create a temporary address map on a temporary obstack. We later
3412 copy this to the final obstack. */
3413 obstack_init (&temp_obstack
);
3414 make_cleanup_obstack_free (&temp_obstack
);
3415 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3416 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3418 /* Since the objects we're extracting from .debug_info vary in
3419 length, only the individual functions to extract them (like
3420 read_comp_unit_head and load_partial_die) can really know whether
3421 the buffer is large enough to hold another complete object.
3423 At the moment, they don't actually check that. If .debug_info
3424 holds just one extra byte after the last compilation unit's dies,
3425 then read_comp_unit_head will happily read off the end of the
3426 buffer. read_partial_die is similarly casual. Those functions
3429 For this loop condition, simply checking whether there's any data
3430 left at all should be sufficient. */
3432 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3433 + dwarf2_per_objfile
->info
.size
))
3435 struct dwarf2_per_cu_data
*this_cu
;
3437 this_cu
= dwarf2_find_comp_unit (info_ptr
3438 - dwarf2_per_objfile
->info
.buffer
,
3441 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3442 dwarf2_per_objfile
->info
.buffer
,
3444 dwarf2_per_objfile
->info
.size
);
3447 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3448 &objfile
->objfile_obstack
);
3449 discard_cleanups (addrmap_cleanup
);
3451 do_cleanups (back_to
);
3454 /* Load the partial DIEs for a secondary CU into memory. */
3457 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3458 struct objfile
*objfile
)
3460 bfd
*abfd
= objfile
->obfd
;
3461 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3462 struct die_info
*comp_unit_die
;
3463 struct dwarf2_cu
*cu
;
3464 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3466 struct die_reader_specs reader_specs
;
3469 gdb_assert (! this_cu
->from_debug_types
);
3471 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3472 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3473 beg_of_comp_unit
= info_ptr
;
3475 if (this_cu
->cu
== NULL
)
3477 cu
= xmalloc (sizeof (*cu
));
3478 init_one_comp_unit (cu
, objfile
);
3482 /* If an error occurs while loading, release our storage. */
3483 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3485 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3486 dwarf2_per_objfile
->info
.buffer
,
3487 dwarf2_per_objfile
->info
.size
,
3490 /* Complete the cu_header. */
3491 cu
->header
.offset
= this_cu
->offset
;
3492 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3494 /* Link this compilation unit into the compilation unit tree. */
3496 cu
->per_cu
= this_cu
;
3498 /* Link this CU into read_in_chain. */
3499 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3500 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3505 info_ptr
+= cu
->header
.first_die_offset
;
3508 /* Read the abbrevs for this compilation unit into a table. */
3509 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3510 dwarf2_read_abbrevs (abfd
, cu
);
3511 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3513 /* Read the compilation unit die. */
3514 init_cu_die_reader (&reader_specs
, cu
);
3515 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3518 prepare_one_comp_unit (cu
, comp_unit_die
);
3520 /* Check if comp unit has_children.
3521 If so, read the rest of the partial symbols from this comp unit.
3522 If not, there's no more debug_info for this comp unit. */
3524 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3526 do_cleanups (free_abbrevs_cleanup
);
3530 /* We've successfully allocated this compilation unit. Let our
3531 caller clean it up when finished with it. */
3532 discard_cleanups (free_cu_cleanup
);
3536 /* Create a list of all compilation units in OBJFILE. We do this only
3537 if an inter-comp-unit reference is found; presumably if there is one,
3538 there will be many, and one will occur early in the .debug_info section.
3539 So there's no point in building this list incrementally. */
3542 create_all_comp_units (struct objfile
*objfile
)
3546 struct dwarf2_per_cu_data
**all_comp_units
;
3549 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3550 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3554 all_comp_units
= xmalloc (n_allocated
3555 * sizeof (struct dwarf2_per_cu_data
*));
3557 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3558 + dwarf2_per_objfile
->info
.size
)
3560 unsigned int length
, initial_length_size
;
3561 struct dwarf2_per_cu_data
*this_cu
;
3562 unsigned int offset
;
3564 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3566 /* Read just enough information to find out where the next
3567 compilation unit is. */
3568 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3569 &initial_length_size
);
3571 /* Save the compilation unit for later lookup. */
3572 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3573 sizeof (struct dwarf2_per_cu_data
));
3574 memset (this_cu
, 0, sizeof (*this_cu
));
3575 this_cu
->offset
= offset
;
3576 this_cu
->length
= length
+ initial_length_size
;
3577 this_cu
->objfile
= objfile
;
3579 if (n_comp_units
== n_allocated
)
3582 all_comp_units
= xrealloc (all_comp_units
,
3584 * sizeof (struct dwarf2_per_cu_data
*));
3586 all_comp_units
[n_comp_units
++] = this_cu
;
3588 info_ptr
= info_ptr
+ this_cu
->length
;
3591 dwarf2_per_objfile
->all_comp_units
3592 = obstack_alloc (&objfile
->objfile_obstack
,
3593 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3594 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3595 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3596 xfree (all_comp_units
);
3597 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3600 /* Process all loaded DIEs for compilation unit CU, starting at
3601 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3602 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3603 DW_AT_ranges). If NEED_PC is set, then this function will set
3604 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3605 and record the covered ranges in the addrmap. */
3608 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3609 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3611 struct partial_die_info
*pdi
;
3613 /* Now, march along the PDI's, descending into ones which have
3614 interesting children but skipping the children of the other ones,
3615 until we reach the end of the compilation unit. */
3621 fixup_partial_die (pdi
, cu
);
3623 /* Anonymous namespaces or modules have no name but have interesting
3624 children, so we need to look at them. Ditto for anonymous
3627 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3628 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3632 case DW_TAG_subprogram
:
3633 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3635 case DW_TAG_constant
:
3636 case DW_TAG_variable
:
3637 case DW_TAG_typedef
:
3638 case DW_TAG_union_type
:
3639 if (!pdi
->is_declaration
)
3641 add_partial_symbol (pdi
, cu
);
3644 case DW_TAG_class_type
:
3645 case DW_TAG_interface_type
:
3646 case DW_TAG_structure_type
:
3647 if (!pdi
->is_declaration
)
3649 add_partial_symbol (pdi
, cu
);
3652 case DW_TAG_enumeration_type
:
3653 if (!pdi
->is_declaration
)
3654 add_partial_enumeration (pdi
, cu
);
3656 case DW_TAG_base_type
:
3657 case DW_TAG_subrange_type
:
3658 /* File scope base type definitions are added to the partial
3660 add_partial_symbol (pdi
, cu
);
3662 case DW_TAG_namespace
:
3663 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3666 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3673 /* If the die has a sibling, skip to the sibling. */
3675 pdi
= pdi
->die_sibling
;
3679 /* Functions used to compute the fully scoped name of a partial DIE.
3681 Normally, this is simple. For C++, the parent DIE's fully scoped
3682 name is concatenated with "::" and the partial DIE's name. For
3683 Java, the same thing occurs except that "." is used instead of "::".
3684 Enumerators are an exception; they use the scope of their parent
3685 enumeration type, i.e. the name of the enumeration type is not
3686 prepended to the enumerator.
3688 There are two complexities. One is DW_AT_specification; in this
3689 case "parent" means the parent of the target of the specification,
3690 instead of the direct parent of the DIE. The other is compilers
3691 which do not emit DW_TAG_namespace; in this case we try to guess
3692 the fully qualified name of structure types from their members'
3693 linkage names. This must be done using the DIE's children rather
3694 than the children of any DW_AT_specification target. We only need
3695 to do this for structures at the top level, i.e. if the target of
3696 any DW_AT_specification (if any; otherwise the DIE itself) does not
3699 /* Compute the scope prefix associated with PDI's parent, in
3700 compilation unit CU. The result will be allocated on CU's
3701 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3702 field. NULL is returned if no prefix is necessary. */
3704 partial_die_parent_scope (struct partial_die_info
*pdi
,
3705 struct dwarf2_cu
*cu
)
3707 char *grandparent_scope
;
3708 struct partial_die_info
*parent
, *real_pdi
;
3710 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3711 then this means the parent of the specification DIE. */
3714 while (real_pdi
->has_specification
)
3715 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3717 parent
= real_pdi
->die_parent
;
3721 if (parent
->scope_set
)
3722 return parent
->scope
;
3724 fixup_partial_die (parent
, cu
);
3726 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3728 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3729 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3730 Work around this problem here. */
3731 if (cu
->language
== language_cplus
3732 && parent
->tag
== DW_TAG_namespace
3733 && strcmp (parent
->name
, "::") == 0
3734 && grandparent_scope
== NULL
)
3736 parent
->scope
= NULL
;
3737 parent
->scope_set
= 1;
3741 if (parent
->tag
== DW_TAG_namespace
3742 || parent
->tag
== DW_TAG_module
3743 || parent
->tag
== DW_TAG_structure_type
3744 || parent
->tag
== DW_TAG_class_type
3745 || parent
->tag
== DW_TAG_interface_type
3746 || parent
->tag
== DW_TAG_union_type
3747 || parent
->tag
== DW_TAG_enumeration_type
)
3749 if (grandparent_scope
== NULL
)
3750 parent
->scope
= parent
->name
;
3752 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3754 parent
->name
, 0, cu
);
3756 else if (parent
->tag
== DW_TAG_enumerator
)
3757 /* Enumerators should not get the name of the enumeration as a prefix. */
3758 parent
->scope
= grandparent_scope
;
3761 /* FIXME drow/2004-04-01: What should we be doing with
3762 function-local names? For partial symbols, we should probably be
3764 complaint (&symfile_complaints
,
3765 _("unhandled containing DIE tag %d for DIE at %d"),
3766 parent
->tag
, pdi
->offset
);
3767 parent
->scope
= grandparent_scope
;
3770 parent
->scope_set
= 1;
3771 return parent
->scope
;
3774 /* Return the fully scoped name associated with PDI, from compilation unit
3775 CU. The result will be allocated with malloc. */
3777 partial_die_full_name (struct partial_die_info
*pdi
,
3778 struct dwarf2_cu
*cu
)
3782 /* If this is a template instantiation, we can not work out the
3783 template arguments from partial DIEs. So, unfortunately, we have
3784 to go through the full DIEs. At least any work we do building
3785 types here will be reused if full symbols are loaded later. */
3786 if (pdi
->has_template_arguments
)
3788 fixup_partial_die (pdi
, cu
);
3790 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3792 struct die_info
*die
;
3793 struct attribute attr
;
3794 struct dwarf2_cu
*ref_cu
= cu
;
3797 attr
.form
= DW_FORM_ref_addr
;
3798 attr
.u
.addr
= pdi
->offset
;
3799 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3801 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3805 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3806 if (parent_scope
== NULL
)
3809 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3813 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3815 struct objfile
*objfile
= cu
->objfile
;
3817 char *actual_name
= NULL
;
3818 const struct partial_symbol
*psym
= NULL
;
3820 int built_actual_name
= 0;
3822 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3824 actual_name
= partial_die_full_name (pdi
, cu
);
3826 built_actual_name
= 1;
3828 if (actual_name
== NULL
)
3829 actual_name
= pdi
->name
;
3833 case DW_TAG_subprogram
:
3834 if (pdi
->is_external
|| cu
->language
== language_ada
)
3836 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3837 of the global scope. But in Ada, we want to be able to access
3838 nested procedures globally. So all Ada subprograms are stored
3839 in the global scope. */
3840 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3841 mst_text, objfile); */
3842 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3844 VAR_DOMAIN
, LOC_BLOCK
,
3845 &objfile
->global_psymbols
,
3846 0, pdi
->lowpc
+ baseaddr
,
3847 cu
->language
, objfile
);
3851 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3852 mst_file_text, objfile); */
3853 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3855 VAR_DOMAIN
, LOC_BLOCK
,
3856 &objfile
->static_psymbols
,
3857 0, pdi
->lowpc
+ baseaddr
,
3858 cu
->language
, objfile
);
3861 case DW_TAG_constant
:
3863 struct psymbol_allocation_list
*list
;
3865 if (pdi
->is_external
)
3866 list
= &objfile
->global_psymbols
;
3868 list
= &objfile
->static_psymbols
;
3869 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3870 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
3871 list
, 0, 0, cu
->language
, objfile
);
3875 case DW_TAG_variable
:
3877 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3881 && !dwarf2_per_objfile
->has_section_at_zero
)
3883 /* A global or static variable may also have been stripped
3884 out by the linker if unused, in which case its address
3885 will be nullified; do not add such variables into partial
3886 symbol table then. */
3888 else if (pdi
->is_external
)
3891 Don't enter into the minimal symbol tables as there is
3892 a minimal symbol table entry from the ELF symbols already.
3893 Enter into partial symbol table if it has a location
3894 descriptor or a type.
3895 If the location descriptor is missing, new_symbol will create
3896 a LOC_UNRESOLVED symbol, the address of the variable will then
3897 be determined from the minimal symbol table whenever the variable
3899 The address for the partial symbol table entry is not
3900 used by GDB, but it comes in handy for debugging partial symbol
3903 if (pdi
->locdesc
|| pdi
->has_type
)
3904 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3906 VAR_DOMAIN
, LOC_STATIC
,
3907 &objfile
->global_psymbols
,
3909 cu
->language
, objfile
);
3913 /* Static Variable. Skip symbols without location descriptors. */
3914 if (pdi
->locdesc
== NULL
)
3916 if (built_actual_name
)
3917 xfree (actual_name
);
3920 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
3921 mst_file_data, objfile); */
3922 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3924 VAR_DOMAIN
, LOC_STATIC
,
3925 &objfile
->static_psymbols
,
3927 cu
->language
, objfile
);
3930 case DW_TAG_typedef
:
3931 case DW_TAG_base_type
:
3932 case DW_TAG_subrange_type
:
3933 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3935 VAR_DOMAIN
, LOC_TYPEDEF
,
3936 &objfile
->static_psymbols
,
3937 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3939 case DW_TAG_namespace
:
3940 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3942 VAR_DOMAIN
, LOC_TYPEDEF
,
3943 &objfile
->global_psymbols
,
3944 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3946 case DW_TAG_class_type
:
3947 case DW_TAG_interface_type
:
3948 case DW_TAG_structure_type
:
3949 case DW_TAG_union_type
:
3950 case DW_TAG_enumeration_type
:
3951 /* Skip external references. The DWARF standard says in the section
3952 about "Structure, Union, and Class Type Entries": "An incomplete
3953 structure, union or class type is represented by a structure,
3954 union or class entry that does not have a byte size attribute
3955 and that has a DW_AT_declaration attribute." */
3956 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3958 if (built_actual_name
)
3959 xfree (actual_name
);
3963 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3964 static vs. global. */
3965 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3967 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3968 (cu
->language
== language_cplus
3969 || cu
->language
== language_java
)
3970 ? &objfile
->global_psymbols
3971 : &objfile
->static_psymbols
,
3972 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3975 case DW_TAG_enumerator
:
3976 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3978 VAR_DOMAIN
, LOC_CONST
,
3979 (cu
->language
== language_cplus
3980 || cu
->language
== language_java
)
3981 ? &objfile
->global_psymbols
3982 : &objfile
->static_psymbols
,
3983 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3989 if (built_actual_name
)
3990 xfree (actual_name
);
3993 /* Read a partial die corresponding to a namespace; also, add a symbol
3994 corresponding to that namespace to the symbol table. NAMESPACE is
3995 the name of the enclosing namespace. */
3998 add_partial_namespace (struct partial_die_info
*pdi
,
3999 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4000 int need_pc
, struct dwarf2_cu
*cu
)
4002 /* Add a symbol for the namespace. */
4004 add_partial_symbol (pdi
, cu
);
4006 /* Now scan partial symbols in that namespace. */
4008 if (pdi
->has_children
)
4009 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4012 /* Read a partial die corresponding to a Fortran module. */
4015 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4016 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4018 /* Now scan partial symbols in that module. */
4020 if (pdi
->has_children
)
4021 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4024 /* Read a partial die corresponding to a subprogram and create a partial
4025 symbol for that subprogram. When the CU language allows it, this
4026 routine also defines a partial symbol for each nested subprogram
4027 that this subprogram contains.
4029 DIE my also be a lexical block, in which case we simply search
4030 recursively for suprograms defined inside that lexical block.
4031 Again, this is only performed when the CU language allows this
4032 type of definitions. */
4035 add_partial_subprogram (struct partial_die_info
*pdi
,
4036 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4037 int need_pc
, struct dwarf2_cu
*cu
)
4039 if (pdi
->tag
== DW_TAG_subprogram
)
4041 if (pdi
->has_pc_info
)
4043 if (pdi
->lowpc
< *lowpc
)
4044 *lowpc
= pdi
->lowpc
;
4045 if (pdi
->highpc
> *highpc
)
4046 *highpc
= pdi
->highpc
;
4050 struct objfile
*objfile
= cu
->objfile
;
4052 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4053 SECT_OFF_TEXT (objfile
));
4054 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4055 pdi
->lowpc
+ baseaddr
,
4056 pdi
->highpc
- 1 + baseaddr
,
4057 cu
->per_cu
->v
.psymtab
);
4059 if (!pdi
->is_declaration
)
4060 /* Ignore subprogram DIEs that do not have a name, they are
4061 illegal. Do not emit a complaint at this point, we will
4062 do so when we convert this psymtab into a symtab. */
4064 add_partial_symbol (pdi
, cu
);
4068 if (! pdi
->has_children
)
4071 if (cu
->language
== language_ada
)
4073 pdi
= pdi
->die_child
;
4076 fixup_partial_die (pdi
, cu
);
4077 if (pdi
->tag
== DW_TAG_subprogram
4078 || pdi
->tag
== DW_TAG_lexical_block
)
4079 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4080 pdi
= pdi
->die_sibling
;
4085 /* Read a partial die corresponding to an enumeration type. */
4088 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4089 struct dwarf2_cu
*cu
)
4091 struct partial_die_info
*pdi
;
4093 if (enum_pdi
->name
!= NULL
)
4094 add_partial_symbol (enum_pdi
, cu
);
4096 pdi
= enum_pdi
->die_child
;
4099 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4100 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4102 add_partial_symbol (pdi
, cu
);
4103 pdi
= pdi
->die_sibling
;
4107 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4108 Return the corresponding abbrev, or NULL if the number is zero (indicating
4109 an empty DIE). In either case *BYTES_READ will be set to the length of
4110 the initial number. */
4112 static struct abbrev_info
*
4113 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4114 struct dwarf2_cu
*cu
)
4116 bfd
*abfd
= cu
->objfile
->obfd
;
4117 unsigned int abbrev_number
;
4118 struct abbrev_info
*abbrev
;
4120 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4122 if (abbrev_number
== 0)
4125 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4128 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4129 abbrev_number
, bfd_get_filename (abfd
));
4135 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4136 Returns a pointer to the end of a series of DIEs, terminated by an empty
4137 DIE. Any children of the skipped DIEs will also be skipped. */
4140 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4142 struct abbrev_info
*abbrev
;
4143 unsigned int bytes_read
;
4147 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4149 return info_ptr
+ bytes_read
;
4151 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4155 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4156 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4157 abbrev corresponding to that skipped uleb128 should be passed in
4158 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4162 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4163 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4165 unsigned int bytes_read
;
4166 struct attribute attr
;
4167 bfd
*abfd
= cu
->objfile
->obfd
;
4168 unsigned int form
, i
;
4170 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4172 /* The only abbrev we care about is DW_AT_sibling. */
4173 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4175 read_attribute (&attr
, &abbrev
->attrs
[i
],
4176 abfd
, info_ptr
, cu
);
4177 if (attr
.form
== DW_FORM_ref_addr
)
4178 complaint (&symfile_complaints
,
4179 _("ignoring absolute DW_AT_sibling"));
4181 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4184 /* If it isn't DW_AT_sibling, skip this attribute. */
4185 form
= abbrev
->attrs
[i
].form
;
4189 case DW_FORM_ref_addr
:
4190 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4191 and later it is offset sized. */
4192 if (cu
->header
.version
== 2)
4193 info_ptr
+= cu
->header
.addr_size
;
4195 info_ptr
+= cu
->header
.offset_size
;
4198 info_ptr
+= cu
->header
.addr_size
;
4205 case DW_FORM_flag_present
:
4220 case DW_FORM_string
:
4221 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4222 info_ptr
+= bytes_read
;
4224 case DW_FORM_sec_offset
:
4226 info_ptr
+= cu
->header
.offset_size
;
4228 case DW_FORM_exprloc
:
4230 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4231 info_ptr
+= bytes_read
;
4233 case DW_FORM_block1
:
4234 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4236 case DW_FORM_block2
:
4237 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4239 case DW_FORM_block4
:
4240 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4244 case DW_FORM_ref_udata
:
4245 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4247 case DW_FORM_indirect
:
4248 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4249 info_ptr
+= bytes_read
;
4250 /* We need to continue parsing from here, so just go back to
4252 goto skip_attribute
;
4255 error (_("Dwarf Error: Cannot handle %s "
4256 "in DWARF reader [in module %s]"),
4257 dwarf_form_name (form
),
4258 bfd_get_filename (abfd
));
4262 if (abbrev
->has_children
)
4263 return skip_children (buffer
, info_ptr
, cu
);
4268 /* Locate ORIG_PDI's sibling.
4269 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4273 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4274 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4275 bfd
*abfd
, struct dwarf2_cu
*cu
)
4277 /* Do we know the sibling already? */
4279 if (orig_pdi
->sibling
)
4280 return orig_pdi
->sibling
;
4282 /* Are there any children to deal with? */
4284 if (!orig_pdi
->has_children
)
4287 /* Skip the children the long way. */
4289 return skip_children (buffer
, info_ptr
, cu
);
4292 /* Expand this partial symbol table into a full symbol table. */
4295 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4301 warning (_("bug: psymtab for %s is already read in."),
4308 printf_filtered (_("Reading in symbols for %s..."),
4310 gdb_flush (gdb_stdout
);
4313 /* Restore our global data. */
4314 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4315 dwarf2_objfile_data_key
);
4317 /* If this psymtab is constructed from a debug-only objfile, the
4318 has_section_at_zero flag will not necessarily be correct. We
4319 can get the correct value for this flag by looking at the data
4320 associated with the (presumably stripped) associated objfile. */
4321 if (pst
->objfile
->separate_debug_objfile_backlink
)
4323 struct dwarf2_per_objfile
*dpo_backlink
4324 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4325 dwarf2_objfile_data_key
);
4327 dwarf2_per_objfile
->has_section_at_zero
4328 = dpo_backlink
->has_section_at_zero
;
4331 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4333 psymtab_to_symtab_1 (pst
);
4335 /* Finish up the debug error message. */
4337 printf_filtered (_("done.\n"));
4342 /* Add PER_CU to the queue. */
4345 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4347 struct dwarf2_queue_item
*item
;
4350 item
= xmalloc (sizeof (*item
));
4351 item
->per_cu
= per_cu
;
4354 if (dwarf2_queue
== NULL
)
4355 dwarf2_queue
= item
;
4357 dwarf2_queue_tail
->next
= item
;
4359 dwarf2_queue_tail
= item
;
4362 /* Process the queue. */
4365 process_queue (struct objfile
*objfile
)
4367 struct dwarf2_queue_item
*item
, *next_item
;
4369 /* The queue starts out with one item, but following a DIE reference
4370 may load a new CU, adding it to the end of the queue. */
4371 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4373 if (dwarf2_per_objfile
->using_index
4374 ? !item
->per_cu
->v
.quick
->symtab
4375 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4376 process_full_comp_unit (item
->per_cu
);
4378 item
->per_cu
->queued
= 0;
4379 next_item
= item
->next
;
4383 dwarf2_queue_tail
= NULL
;
4386 /* Free all allocated queue entries. This function only releases anything if
4387 an error was thrown; if the queue was processed then it would have been
4388 freed as we went along. */
4391 dwarf2_release_queue (void *dummy
)
4393 struct dwarf2_queue_item
*item
, *last
;
4395 item
= dwarf2_queue
;
4398 /* Anything still marked queued is likely to be in an
4399 inconsistent state, so discard it. */
4400 if (item
->per_cu
->queued
)
4402 if (item
->per_cu
->cu
!= NULL
)
4403 free_one_cached_comp_unit (item
->per_cu
->cu
);
4404 item
->per_cu
->queued
= 0;
4412 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4415 /* Read in full symbols for PST, and anything it depends on. */
4418 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4420 struct dwarf2_per_cu_data
*per_cu
;
4421 struct cleanup
*back_to
;
4424 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4425 if (!pst
->dependencies
[i
]->readin
)
4427 /* Inform about additional files that need to be read in. */
4430 /* FIXME: i18n: Need to make this a single string. */
4431 fputs_filtered (" ", gdb_stdout
);
4433 fputs_filtered ("and ", gdb_stdout
);
4435 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4436 wrap_here (""); /* Flush output. */
4437 gdb_flush (gdb_stdout
);
4439 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4442 per_cu
= pst
->read_symtab_private
;
4446 /* It's an include file, no symbols to read for it.
4447 Everything is in the parent symtab. */
4452 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4455 /* Load the DIEs associated with PER_CU into memory. */
4458 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
4459 struct objfile
*objfile
)
4461 bfd
*abfd
= objfile
->obfd
;
4462 struct dwarf2_cu
*cu
;
4463 unsigned int offset
;
4464 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4465 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4466 struct attribute
*attr
;
4469 gdb_assert (! per_cu
->from_debug_types
);
4471 /* Set local variables from the partial symbol table info. */
4472 offset
= per_cu
->offset
;
4474 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4475 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4476 beg_of_comp_unit
= info_ptr
;
4478 if (per_cu
->cu
== NULL
)
4480 cu
= xmalloc (sizeof (*cu
));
4481 init_one_comp_unit (cu
, objfile
);
4485 /* If an error occurs while loading, release our storage. */
4486 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4488 /* Read in the comp_unit header. */
4489 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4491 /* Complete the cu_header. */
4492 cu
->header
.offset
= offset
;
4493 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4495 /* Read the abbrevs for this compilation unit. */
4496 dwarf2_read_abbrevs (abfd
, cu
);
4497 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4499 /* Link this compilation unit into the compilation unit tree. */
4501 cu
->per_cu
= per_cu
;
4503 /* Link this CU into read_in_chain. */
4504 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4505 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4510 info_ptr
+= cu
->header
.first_die_offset
;
4513 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4515 /* We try not to read any attributes in this function, because not
4516 all objfiles needed for references have been loaded yet, and symbol
4517 table processing isn't initialized. But we have to set the CU language,
4518 or we won't be able to build types correctly. */
4519 prepare_one_comp_unit (cu
, cu
->dies
);
4521 /* Similarly, if we do not read the producer, we can not apply
4522 producer-specific interpretation. */
4523 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4525 cu
->producer
= DW_STRING (attr
);
4529 do_cleanups (free_abbrevs_cleanup
);
4531 /* We've successfully allocated this compilation unit. Let our
4532 caller clean it up when finished with it. */
4533 discard_cleanups (free_cu_cleanup
);
4537 /* Add a DIE to the delayed physname list. */
4540 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4541 const char *name
, struct die_info
*die
,
4542 struct dwarf2_cu
*cu
)
4544 struct delayed_method_info mi
;
4546 mi
.fnfield_index
= fnfield_index
;
4550 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4553 /* A cleanup for freeing the delayed method list. */
4556 free_delayed_list (void *ptr
)
4558 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4559 if (cu
->method_list
!= NULL
)
4561 VEC_free (delayed_method_info
, cu
->method_list
);
4562 cu
->method_list
= NULL
;
4566 /* Compute the physnames of any methods on the CU's method list.
4568 The computation of method physnames is delayed in order to avoid the
4569 (bad) condition that one of the method's formal parameters is of an as yet
4573 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4576 struct delayed_method_info
*mi
;
4577 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4580 struct fn_fieldlist
*fn_flp
4581 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4582 physname
= (char *) dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4583 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4587 /* Generate full symbol information for PST and CU, whose DIEs have
4588 already been loaded into memory. */
4591 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4593 struct dwarf2_cu
*cu
= per_cu
->cu
;
4594 struct objfile
*objfile
= per_cu
->objfile
;
4595 CORE_ADDR lowpc
, highpc
;
4596 struct symtab
*symtab
;
4597 struct cleanup
*back_to
, *delayed_list_cleanup
;
4600 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4603 back_to
= make_cleanup (really_free_pendings
, NULL
);
4604 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4606 cu
->list_in_scope
= &file_symbols
;
4608 dwarf2_find_base_address (cu
->dies
, cu
);
4610 /* Do line number decoding in read_file_scope () */
4611 process_die (cu
->dies
, cu
);
4613 /* Now that we have processed all the DIEs in the CU, all the types
4614 should be complete, and it should now be safe to compute all of the
4616 compute_delayed_physnames (cu
);
4617 do_cleanups (delayed_list_cleanup
);
4619 /* Some compilers don't define a DW_AT_high_pc attribute for the
4620 compilation unit. If the DW_AT_high_pc is missing, synthesize
4621 it, by scanning the DIE's below the compilation unit. */
4622 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4624 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4626 /* Set symtab language to language from DW_AT_language.
4627 If the compilation is from a C file generated by language preprocessors,
4628 do not set the language if it was already deduced by start_subfile. */
4630 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4632 symtab
->language
= cu
->language
;
4635 if (dwarf2_per_objfile
->using_index
)
4636 per_cu
->v
.quick
->symtab
= symtab
;
4639 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4640 pst
->symtab
= symtab
;
4644 do_cleanups (back_to
);
4647 /* Process a die and its children. */
4650 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4654 case DW_TAG_padding
:
4656 case DW_TAG_compile_unit
:
4657 read_file_scope (die
, cu
);
4659 case DW_TAG_type_unit
:
4660 read_type_unit_scope (die
, cu
);
4662 case DW_TAG_subprogram
:
4663 case DW_TAG_inlined_subroutine
:
4664 read_func_scope (die
, cu
);
4666 case DW_TAG_lexical_block
:
4667 case DW_TAG_try_block
:
4668 case DW_TAG_catch_block
:
4669 read_lexical_block_scope (die
, cu
);
4671 case DW_TAG_class_type
:
4672 case DW_TAG_interface_type
:
4673 case DW_TAG_structure_type
:
4674 case DW_TAG_union_type
:
4675 process_structure_scope (die
, cu
);
4677 case DW_TAG_enumeration_type
:
4678 process_enumeration_scope (die
, cu
);
4681 /* These dies have a type, but processing them does not create
4682 a symbol or recurse to process the children. Therefore we can
4683 read them on-demand through read_type_die. */
4684 case DW_TAG_subroutine_type
:
4685 case DW_TAG_set_type
:
4686 case DW_TAG_array_type
:
4687 case DW_TAG_pointer_type
:
4688 case DW_TAG_ptr_to_member_type
:
4689 case DW_TAG_reference_type
:
4690 case DW_TAG_string_type
:
4693 case DW_TAG_base_type
:
4694 case DW_TAG_subrange_type
:
4695 case DW_TAG_typedef
:
4696 /* Add a typedef symbol for the type definition, if it has a
4698 new_symbol (die
, read_type_die (die
, cu
), cu
);
4700 case DW_TAG_common_block
:
4701 read_common_block (die
, cu
);
4703 case DW_TAG_common_inclusion
:
4705 case DW_TAG_namespace
:
4706 processing_has_namespace_info
= 1;
4707 read_namespace (die
, cu
);
4710 processing_has_namespace_info
= 1;
4711 read_module (die
, cu
);
4713 case DW_TAG_imported_declaration
:
4714 case DW_TAG_imported_module
:
4715 processing_has_namespace_info
= 1;
4716 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4717 || cu
->language
!= language_fortran
))
4718 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4719 dwarf_tag_name (die
->tag
));
4720 read_import_statement (die
, cu
);
4723 new_symbol (die
, NULL
, cu
);
4728 /* A helper function for dwarf2_compute_name which determines whether DIE
4729 needs to have the name of the scope prepended to the name listed in the
4733 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4735 struct attribute
*attr
;
4739 case DW_TAG_namespace
:
4740 case DW_TAG_typedef
:
4741 case DW_TAG_class_type
:
4742 case DW_TAG_interface_type
:
4743 case DW_TAG_structure_type
:
4744 case DW_TAG_union_type
:
4745 case DW_TAG_enumeration_type
:
4746 case DW_TAG_enumerator
:
4747 case DW_TAG_subprogram
:
4751 case DW_TAG_variable
:
4752 case DW_TAG_constant
:
4753 /* We only need to prefix "globally" visible variables. These include
4754 any variable marked with DW_AT_external or any variable that
4755 lives in a namespace. [Variables in anonymous namespaces
4756 require prefixing, but they are not DW_AT_external.] */
4758 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4760 struct dwarf2_cu
*spec_cu
= cu
;
4762 return die_needs_namespace (die_specification (die
, &spec_cu
),
4766 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4767 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4768 && die
->parent
->tag
!= DW_TAG_module
)
4770 /* A variable in a lexical block of some kind does not need a
4771 namespace, even though in C++ such variables may be external
4772 and have a mangled name. */
4773 if (die
->parent
->tag
== DW_TAG_lexical_block
4774 || die
->parent
->tag
== DW_TAG_try_block
4775 || die
->parent
->tag
== DW_TAG_catch_block
4776 || die
->parent
->tag
== DW_TAG_subprogram
)
4785 /* Retrieve the last character from a mem_file. */
4788 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4790 char *last_char_p
= (char *) object
;
4793 *last_char_p
= buffer
[length
- 1];
4796 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4797 compute the physname for the object, which include a method's
4798 formal parameters (C++/Java) and return type (Java).
4800 For Ada, return the DIE's linkage name rather than the fully qualified
4801 name. PHYSNAME is ignored..
4803 The result is allocated on the objfile_obstack and canonicalized. */
4806 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4810 name
= dwarf2_name (die
, cu
);
4812 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4813 compute it by typename_concat inside GDB. */
4814 if (cu
->language
== language_ada
4815 || (cu
->language
== language_fortran
&& physname
))
4817 /* For Ada unit, we prefer the linkage name over the name, as
4818 the former contains the exported name, which the user expects
4819 to be able to reference. Ideally, we want the user to be able
4820 to reference this entity using either natural or linkage name,
4821 but we haven't started looking at this enhancement yet. */
4822 struct attribute
*attr
;
4824 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4826 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4827 if (attr
&& DW_STRING (attr
))
4828 return DW_STRING (attr
);
4831 /* These are the only languages we know how to qualify names in. */
4833 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4834 || cu
->language
== language_fortran
))
4836 if (die_needs_namespace (die
, cu
))
4840 struct ui_file
*buf
;
4842 prefix
= determine_prefix (die
, cu
);
4843 buf
= mem_fileopen ();
4844 if (*prefix
!= '\0')
4846 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4849 fputs_unfiltered (prefixed_name
, buf
);
4850 xfree (prefixed_name
);
4853 fputs_unfiltered (name
? name
: "", buf
);
4855 /* Template parameters may be specified in the DIE's DW_AT_name, or
4856 as children with DW_TAG_template_type_param or
4857 DW_TAG_value_type_param. If the latter, add them to the name
4858 here. If the name already has template parameters, then
4859 skip this step; some versions of GCC emit both, and
4860 it is more efficient to use the pre-computed name.
4862 Something to keep in mind about this process: it is very
4863 unlikely, or in some cases downright impossible, to produce
4864 something that will match the mangled name of a function.
4865 If the definition of the function has the same debug info,
4866 we should be able to match up with it anyway. But fallbacks
4867 using the minimal symbol, for instance to find a method
4868 implemented in a stripped copy of libstdc++, will not work.
4869 If we do not have debug info for the definition, we will have to
4870 match them up some other way.
4872 When we do name matching there is a related problem with function
4873 templates; two instantiated function templates are allowed to
4874 differ only by their return types, which we do not add here. */
4876 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
4878 struct attribute
*attr
;
4879 struct die_info
*child
;
4882 die
->building_fullname
= 1;
4884 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
4889 struct dwarf2_locexpr_baton
*baton
;
4892 if (child
->tag
!= DW_TAG_template_type_param
4893 && child
->tag
!= DW_TAG_template_value_param
)
4898 fputs_unfiltered ("<", buf
);
4902 fputs_unfiltered (", ", buf
);
4904 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
4907 complaint (&symfile_complaints
,
4908 _("template parameter missing DW_AT_type"));
4909 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
4912 type
= die_type (child
, cu
);
4914 if (child
->tag
== DW_TAG_template_type_param
)
4916 c_print_type (type
, "", buf
, -1, 0);
4920 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
4923 complaint (&symfile_complaints
,
4924 _("template parameter missing "
4925 "DW_AT_const_value"));
4926 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
4930 dwarf2_const_value_attr (attr
, type
, name
,
4931 &cu
->comp_unit_obstack
, cu
,
4932 &value
, &bytes
, &baton
);
4934 if (TYPE_NOSIGN (type
))
4935 /* GDB prints characters as NUMBER 'CHAR'. If that's
4936 changed, this can use value_print instead. */
4937 c_printchar (value
, type
, buf
);
4940 struct value_print_options opts
;
4943 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
4947 else if (bytes
!= NULL
)
4949 v
= allocate_value (type
);
4950 memcpy (value_contents_writeable (v
), bytes
,
4951 TYPE_LENGTH (type
));
4954 v
= value_from_longest (type
, value
);
4956 /* Specify decimal so that we do not depend on
4958 get_formatted_print_options (&opts
, 'd');
4960 value_print (v
, buf
, &opts
);
4966 die
->building_fullname
= 0;
4970 /* Close the argument list, with a space if necessary
4971 (nested templates). */
4972 char last_char
= '\0';
4973 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
4974 if (last_char
== '>')
4975 fputs_unfiltered (" >", buf
);
4977 fputs_unfiltered (">", buf
);
4981 /* For Java and C++ methods, append formal parameter type
4982 information, if PHYSNAME. */
4984 if (physname
&& die
->tag
== DW_TAG_subprogram
4985 && (cu
->language
== language_cplus
4986 || cu
->language
== language_java
))
4988 struct type
*type
= read_type_die (die
, cu
);
4990 c_type_print_args (type
, buf
, 0, cu
->language
);
4992 if (cu
->language
== language_java
)
4994 /* For java, we must append the return type to method
4996 if (die
->tag
== DW_TAG_subprogram
)
4997 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5000 else if (cu
->language
== language_cplus
)
5002 /* Assume that an artificial first parameter is
5003 "this", but do not crash if it is not. RealView
5004 marks unnamed (and thus unused) parameters as
5005 artificial; there is no way to differentiate
5007 if (TYPE_NFIELDS (type
) > 0
5008 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5009 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5010 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5012 fputs_unfiltered (" const", buf
);
5016 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
5018 ui_file_delete (buf
);
5020 if (cu
->language
== language_cplus
)
5023 = dwarf2_canonicalize_name (name
, cu
,
5024 &cu
->objfile
->objfile_obstack
);
5035 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5036 If scope qualifiers are appropriate they will be added. The result
5037 will be allocated on the objfile_obstack, or NULL if the DIE does
5038 not have a name. NAME may either be from a previous call to
5039 dwarf2_name or NULL.
5041 The output string will be canonicalized (if C++/Java). */
5044 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5046 return dwarf2_compute_name (name
, die
, cu
, 0);
5049 /* Construct a physname for the given DIE in CU. NAME may either be
5050 from a previous call to dwarf2_name or NULL. The result will be
5051 allocated on the objfile_objstack or NULL if the DIE does not have a
5054 The output string will be canonicalized (if C++/Java). */
5057 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5059 return dwarf2_compute_name (name
, die
, cu
, 1);
5062 /* Read the import statement specified by the given die and record it. */
5065 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5067 struct attribute
*import_attr
;
5068 struct die_info
*imported_die
;
5069 struct dwarf2_cu
*imported_cu
;
5070 const char *imported_name
;
5071 const char *imported_name_prefix
;
5072 const char *canonical_name
;
5073 const char *import_alias
;
5074 const char *imported_declaration
= NULL
;
5075 const char *import_prefix
;
5079 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5080 if (import_attr
== NULL
)
5082 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5083 dwarf_tag_name (die
->tag
));
5088 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5089 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5090 if (imported_name
== NULL
)
5092 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5094 The import in the following code:
5108 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5109 <52> DW_AT_decl_file : 1
5110 <53> DW_AT_decl_line : 6
5111 <54> DW_AT_import : <0x75>
5112 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5114 <5b> DW_AT_decl_file : 1
5115 <5c> DW_AT_decl_line : 2
5116 <5d> DW_AT_type : <0x6e>
5118 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5119 <76> DW_AT_byte_size : 4
5120 <77> DW_AT_encoding : 5 (signed)
5122 imports the wrong die ( 0x75 instead of 0x58 ).
5123 This case will be ignored until the gcc bug is fixed. */
5127 /* Figure out the local name after import. */
5128 import_alias
= dwarf2_name (die
, cu
);
5130 /* Figure out where the statement is being imported to. */
5131 import_prefix
= determine_prefix (die
, cu
);
5133 /* Figure out what the scope of the imported die is and prepend it
5134 to the name of the imported die. */
5135 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5137 if (imported_die
->tag
!= DW_TAG_namespace
5138 && imported_die
->tag
!= DW_TAG_module
)
5140 imported_declaration
= imported_name
;
5141 canonical_name
= imported_name_prefix
;
5143 else if (strlen (imported_name_prefix
) > 0)
5145 temp
= alloca (strlen (imported_name_prefix
)
5146 + 2 + strlen (imported_name
) + 1);
5147 strcpy (temp
, imported_name_prefix
);
5148 strcat (temp
, "::");
5149 strcat (temp
, imported_name
);
5150 canonical_name
= temp
;
5153 canonical_name
= imported_name
;
5155 cp_add_using_directive (import_prefix
,
5158 imported_declaration
,
5159 &cu
->objfile
->objfile_obstack
);
5163 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5165 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5168 /* Cleanup function for read_file_scope. */
5171 free_cu_line_header (void *arg
)
5173 struct dwarf2_cu
*cu
= arg
;
5175 free_line_header (cu
->line_header
);
5176 cu
->line_header
= NULL
;
5180 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5181 char **name
, char **comp_dir
)
5183 struct attribute
*attr
;
5188 /* Find the filename. Do not use dwarf2_name here, since the filename
5189 is not a source language identifier. */
5190 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5193 *name
= DW_STRING (attr
);
5196 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5198 *comp_dir
= DW_STRING (attr
);
5199 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5201 *comp_dir
= ldirname (*name
);
5202 if (*comp_dir
!= NULL
)
5203 make_cleanup (xfree
, *comp_dir
);
5205 if (*comp_dir
!= NULL
)
5207 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5208 directory, get rid of it. */
5209 char *cp
= strchr (*comp_dir
, ':');
5211 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5216 *name
= "<unknown>";
5219 /* Process DW_TAG_compile_unit. */
5222 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5224 struct objfile
*objfile
= cu
->objfile
;
5225 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5226 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5227 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5228 struct attribute
*attr
;
5230 char *comp_dir
= NULL
;
5231 struct die_info
*child_die
;
5232 bfd
*abfd
= objfile
->obfd
;
5233 struct line_header
*line_header
= 0;
5236 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5238 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5240 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5241 from finish_block. */
5242 if (lowpc
== ((CORE_ADDR
) -1))
5247 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5249 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5252 set_cu_language (DW_UNSND (attr
), cu
);
5255 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5257 cu
->producer
= DW_STRING (attr
);
5259 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5260 standardised yet. As a workaround for the language detection we fall
5261 back to the DW_AT_producer string. */
5262 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5263 cu
->language
= language_opencl
;
5265 /* We assume that we're processing GCC output. */
5266 processing_gcc_compilation
= 2;
5268 processing_has_namespace_info
= 0;
5270 start_symtab (name
, comp_dir
, lowpc
);
5271 record_debugformat ("DWARF 2");
5272 record_producer (cu
->producer
);
5274 initialize_cu_func_list (cu
);
5276 /* Decode line number information if present. We do this before
5277 processing child DIEs, so that the line header table is available
5278 for DW_AT_decl_file. */
5279 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5282 unsigned int line_offset
= DW_UNSND (attr
);
5283 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5286 cu
->line_header
= line_header
;
5287 make_cleanup (free_cu_line_header
, cu
);
5288 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5292 /* Process all dies in compilation unit. */
5293 if (die
->child
!= NULL
)
5295 child_die
= die
->child
;
5296 while (child_die
&& child_die
->tag
)
5298 process_die (child_die
, cu
);
5299 child_die
= sibling_die (child_die
);
5303 /* Decode macro information, if present. Dwarf 2 macro information
5304 refers to information in the line number info statement program
5305 header, so we can only read it if we've read the header
5307 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5308 if (attr
&& line_header
)
5310 unsigned int macro_offset
= DW_UNSND (attr
);
5312 dwarf_decode_macros (line_header
, macro_offset
,
5313 comp_dir
, abfd
, cu
);
5315 do_cleanups (back_to
);
5318 /* Process DW_TAG_type_unit.
5319 For TUs we want to skip the first top level sibling if it's not the
5320 actual type being defined by this TU. In this case the first top
5321 level sibling is there to provide context only. */
5324 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5326 struct objfile
*objfile
= cu
->objfile
;
5327 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5329 struct attribute
*attr
;
5331 char *comp_dir
= NULL
;
5332 struct die_info
*child_die
;
5333 bfd
*abfd
= objfile
->obfd
;
5335 /* start_symtab needs a low pc, but we don't really have one.
5336 Do what read_file_scope would do in the absence of such info. */
5337 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5339 /* Find the filename. Do not use dwarf2_name here, since the filename
5340 is not a source language identifier. */
5341 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5343 name
= DW_STRING (attr
);
5345 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5347 comp_dir
= DW_STRING (attr
);
5348 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5350 comp_dir
= ldirname (name
);
5351 if (comp_dir
!= NULL
)
5352 make_cleanup (xfree
, comp_dir
);
5358 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5360 set_cu_language (DW_UNSND (attr
), cu
);
5362 /* This isn't technically needed today. It is done for symmetry
5363 with read_file_scope. */
5364 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5366 cu
->producer
= DW_STRING (attr
);
5368 /* We assume that we're processing GCC output. */
5369 processing_gcc_compilation
= 2;
5371 processing_has_namespace_info
= 0;
5373 start_symtab (name
, comp_dir
, lowpc
);
5374 record_debugformat ("DWARF 2");
5375 record_producer (cu
->producer
);
5377 /* Process the dies in the type unit. */
5378 if (die
->child
== NULL
)
5380 dump_die_for_error (die
);
5381 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5382 bfd_get_filename (abfd
));
5385 child_die
= die
->child
;
5387 while (child_die
&& child_die
->tag
)
5389 process_die (child_die
, cu
);
5391 child_die
= sibling_die (child_die
);
5394 do_cleanups (back_to
);
5398 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5399 struct dwarf2_cu
*cu
)
5401 struct function_range
*thisfn
;
5403 thisfn
= (struct function_range
*)
5404 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5405 thisfn
->name
= name
;
5406 thisfn
->lowpc
= lowpc
;
5407 thisfn
->highpc
= highpc
;
5408 thisfn
->seen_line
= 0;
5409 thisfn
->next
= NULL
;
5411 if (cu
->last_fn
== NULL
)
5412 cu
->first_fn
= thisfn
;
5414 cu
->last_fn
->next
= thisfn
;
5416 cu
->last_fn
= thisfn
;
5419 /* qsort helper for inherit_abstract_dies. */
5422 unsigned_int_compar (const void *ap
, const void *bp
)
5424 unsigned int a
= *(unsigned int *) ap
;
5425 unsigned int b
= *(unsigned int *) bp
;
5427 return (a
> b
) - (b
> a
);
5430 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5431 Inherit only the children of the DW_AT_abstract_origin DIE not being
5432 already referenced by DW_AT_abstract_origin from the children of the
5436 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5438 struct die_info
*child_die
;
5439 unsigned die_children_count
;
5440 /* CU offsets which were referenced by children of the current DIE. */
5442 unsigned *offsets_end
, *offsetp
;
5443 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5444 struct die_info
*origin_die
;
5445 /* Iterator of the ORIGIN_DIE children. */
5446 struct die_info
*origin_child_die
;
5447 struct cleanup
*cleanups
;
5448 struct attribute
*attr
;
5449 struct dwarf2_cu
*origin_cu
;
5450 struct pending
**origin_previous_list_in_scope
;
5452 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5456 /* Note that following die references may follow to a die in a
5460 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5462 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5464 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5465 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5467 if (die
->tag
!= origin_die
->tag
5468 && !(die
->tag
== DW_TAG_inlined_subroutine
5469 && origin_die
->tag
== DW_TAG_subprogram
))
5470 complaint (&symfile_complaints
,
5471 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5472 die
->offset
, origin_die
->offset
);
5474 child_die
= die
->child
;
5475 die_children_count
= 0;
5476 while (child_die
&& child_die
->tag
)
5478 child_die
= sibling_die (child_die
);
5479 die_children_count
++;
5481 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5482 cleanups
= make_cleanup (xfree
, offsets
);
5484 offsets_end
= offsets
;
5485 child_die
= die
->child
;
5486 while (child_die
&& child_die
->tag
)
5488 /* For each CHILD_DIE, find the corresponding child of
5489 ORIGIN_DIE. If there is more than one layer of
5490 DW_AT_abstract_origin, follow them all; there shouldn't be,
5491 but GCC versions at least through 4.4 generate this (GCC PR
5493 struct die_info
*child_origin_die
= child_die
;
5494 struct dwarf2_cu
*child_origin_cu
= cu
;
5498 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5502 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5506 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5507 counterpart may exist. */
5508 if (child_origin_die
!= child_die
)
5510 if (child_die
->tag
!= child_origin_die
->tag
5511 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5512 && child_origin_die
->tag
== DW_TAG_subprogram
))
5513 complaint (&symfile_complaints
,
5514 _("Child DIE 0x%x and its abstract origin 0x%x have "
5515 "different tags"), child_die
->offset
,
5516 child_origin_die
->offset
);
5517 if (child_origin_die
->parent
!= origin_die
)
5518 complaint (&symfile_complaints
,
5519 _("Child DIE 0x%x and its abstract origin 0x%x have "
5520 "different parents"), child_die
->offset
,
5521 child_origin_die
->offset
);
5523 *offsets_end
++ = child_origin_die
->offset
;
5525 child_die
= sibling_die (child_die
);
5527 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5528 unsigned_int_compar
);
5529 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5530 if (offsetp
[-1] == *offsetp
)
5531 complaint (&symfile_complaints
,
5532 _("Multiple children of DIE 0x%x refer "
5533 "to DIE 0x%x as their abstract origin"),
5534 die
->offset
, *offsetp
);
5537 origin_child_die
= origin_die
->child
;
5538 while (origin_child_die
&& origin_child_die
->tag
)
5540 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5541 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5543 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5545 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5546 process_die (origin_child_die
, origin_cu
);
5548 origin_child_die
= sibling_die (origin_child_die
);
5550 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5552 do_cleanups (cleanups
);
5556 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5558 struct objfile
*objfile
= cu
->objfile
;
5559 struct context_stack
*new;
5562 struct die_info
*child_die
;
5563 struct attribute
*attr
, *call_line
, *call_file
;
5566 struct block
*block
;
5567 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5568 VEC (symbolp
) *template_args
= NULL
;
5569 struct template_symbol
*templ_func
= NULL
;
5573 /* If we do not have call site information, we can't show the
5574 caller of this inlined function. That's too confusing, so
5575 only use the scope for local variables. */
5576 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5577 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5578 if (call_line
== NULL
|| call_file
== NULL
)
5580 read_lexical_block_scope (die
, cu
);
5585 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5587 name
= dwarf2_name (die
, cu
);
5589 /* Ignore functions with missing or empty names. These are actually
5590 illegal according to the DWARF standard. */
5593 complaint (&symfile_complaints
,
5594 _("missing name for subprogram DIE at %d"), die
->offset
);
5598 /* Ignore functions with missing or invalid low and high pc attributes. */
5599 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5601 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5602 if (!attr
|| !DW_UNSND (attr
))
5603 complaint (&symfile_complaints
,
5604 _("cannot get low and high bounds "
5605 "for subprogram DIE at %d"),
5613 /* Record the function range for dwarf_decode_lines. */
5614 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5616 /* If we have any template arguments, then we must allocate a
5617 different sort of symbol. */
5618 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5620 if (child_die
->tag
== DW_TAG_template_type_param
5621 || child_die
->tag
== DW_TAG_template_value_param
)
5623 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5624 struct template_symbol
);
5625 templ_func
->base
.is_cplus_template_function
= 1;
5630 new = push_context (0, lowpc
);
5631 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5632 (struct symbol
*) templ_func
);
5634 /* If there is a location expression for DW_AT_frame_base, record
5636 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5638 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5639 expression is being recorded directly in the function's symbol
5640 and not in a separate frame-base object. I guess this hack is
5641 to avoid adding some sort of frame-base adjunct/annex to the
5642 function's symbol :-(. The problem with doing this is that it
5643 results in a function symbol with a location expression that
5644 has nothing to do with the location of the function, ouch! The
5645 relationship should be: a function's symbol has-a frame base; a
5646 frame-base has-a location expression. */
5647 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5649 cu
->list_in_scope
= &local_symbols
;
5651 if (die
->child
!= NULL
)
5653 child_die
= die
->child
;
5654 while (child_die
&& child_die
->tag
)
5656 if (child_die
->tag
== DW_TAG_template_type_param
5657 || child_die
->tag
== DW_TAG_template_value_param
)
5659 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5662 VEC_safe_push (symbolp
, template_args
, arg
);
5665 process_die (child_die
, cu
);
5666 child_die
= sibling_die (child_die
);
5670 inherit_abstract_dies (die
, cu
);
5672 /* If we have a DW_AT_specification, we might need to import using
5673 directives from the context of the specification DIE. See the
5674 comment in determine_prefix. */
5675 if (cu
->language
== language_cplus
5676 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5678 struct dwarf2_cu
*spec_cu
= cu
;
5679 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5683 child_die
= spec_die
->child
;
5684 while (child_die
&& child_die
->tag
)
5686 if (child_die
->tag
== DW_TAG_imported_module
)
5687 process_die (child_die
, spec_cu
);
5688 child_die
= sibling_die (child_die
);
5691 /* In some cases, GCC generates specification DIEs that
5692 themselves contain DW_AT_specification attributes. */
5693 spec_die
= die_specification (spec_die
, &spec_cu
);
5697 new = pop_context ();
5698 /* Make a block for the local symbols within. */
5699 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5700 lowpc
, highpc
, objfile
);
5702 /* For C++, set the block's scope. */
5703 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5704 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5705 determine_prefix (die
, cu
),
5706 processing_has_namespace_info
);
5708 /* If we have address ranges, record them. */
5709 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5711 /* Attach template arguments to function. */
5712 if (! VEC_empty (symbolp
, template_args
))
5714 gdb_assert (templ_func
!= NULL
);
5716 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5717 templ_func
->template_arguments
5718 = obstack_alloc (&objfile
->objfile_obstack
,
5719 (templ_func
->n_template_arguments
5720 * sizeof (struct symbol
*)));
5721 memcpy (templ_func
->template_arguments
,
5722 VEC_address (symbolp
, template_args
),
5723 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5724 VEC_free (symbolp
, template_args
);
5727 /* In C++, we can have functions nested inside functions (e.g., when
5728 a function declares a class that has methods). This means that
5729 when we finish processing a function scope, we may need to go
5730 back to building a containing block's symbol lists. */
5731 local_symbols
= new->locals
;
5732 param_symbols
= new->params
;
5733 using_directives
= new->using_directives
;
5735 /* If we've finished processing a top-level function, subsequent
5736 symbols go in the file symbol list. */
5737 if (outermost_context_p ())
5738 cu
->list_in_scope
= &file_symbols
;
5741 /* Process all the DIES contained within a lexical block scope. Start
5742 a new scope, process the dies, and then close the scope. */
5745 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5747 struct objfile
*objfile
= cu
->objfile
;
5748 struct context_stack
*new;
5749 CORE_ADDR lowpc
, highpc
;
5750 struct die_info
*child_die
;
5753 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5755 /* Ignore blocks with missing or invalid low and high pc attributes. */
5756 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5757 as multiple lexical blocks? Handling children in a sane way would
5758 be nasty. Might be easier to properly extend generic blocks to
5760 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5765 push_context (0, lowpc
);
5766 if (die
->child
!= NULL
)
5768 child_die
= die
->child
;
5769 while (child_die
&& child_die
->tag
)
5771 process_die (child_die
, cu
);
5772 child_die
= sibling_die (child_die
);
5775 new = pop_context ();
5777 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5780 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5783 /* Note that recording ranges after traversing children, as we
5784 do here, means that recording a parent's ranges entails
5785 walking across all its children's ranges as they appear in
5786 the address map, which is quadratic behavior.
5788 It would be nicer to record the parent's ranges before
5789 traversing its children, simply overriding whatever you find
5790 there. But since we don't even decide whether to create a
5791 block until after we've traversed its children, that's hard
5793 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5795 local_symbols
= new->locals
;
5796 using_directives
= new->using_directives
;
5799 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5800 Return 1 if the attributes are present and valid, otherwise, return 0.
5801 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5804 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5805 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5806 struct partial_symtab
*ranges_pst
)
5808 struct objfile
*objfile
= cu
->objfile
;
5809 struct comp_unit_head
*cu_header
= &cu
->header
;
5810 bfd
*obfd
= objfile
->obfd
;
5811 unsigned int addr_size
= cu_header
->addr_size
;
5812 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5813 /* Base address selection entry. */
5824 found_base
= cu
->base_known
;
5825 base
= cu
->base_address
;
5827 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5828 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5830 complaint (&symfile_complaints
,
5831 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5835 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5837 /* Read in the largest possible address. */
5838 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5839 if ((marker
& mask
) == mask
)
5841 /* If we found the largest possible address, then
5842 read the base address. */
5843 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5844 buffer
+= 2 * addr_size
;
5845 offset
+= 2 * addr_size
;
5851 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5855 CORE_ADDR range_beginning
, range_end
;
5857 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5858 buffer
+= addr_size
;
5859 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5860 buffer
+= addr_size
;
5861 offset
+= 2 * addr_size
;
5863 /* An end of list marker is a pair of zero addresses. */
5864 if (range_beginning
== 0 && range_end
== 0)
5865 /* Found the end of list entry. */
5868 /* Each base address selection entry is a pair of 2 values.
5869 The first is the largest possible address, the second is
5870 the base address. Check for a base address here. */
5871 if ((range_beginning
& mask
) == mask
)
5873 /* If we found the largest possible address, then
5874 read the base address. */
5875 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5882 /* We have no valid base address for the ranges
5884 complaint (&symfile_complaints
,
5885 _("Invalid .debug_ranges data (no base address)"));
5889 if (range_beginning
> range_end
)
5891 /* Inverted range entries are invalid. */
5892 complaint (&symfile_complaints
,
5893 _("Invalid .debug_ranges data (inverted range)"));
5897 /* Empty range entries have no effect. */
5898 if (range_beginning
== range_end
)
5901 range_beginning
+= base
;
5904 if (ranges_pst
!= NULL
)
5905 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5906 range_beginning
+ baseaddr
,
5907 range_end
- 1 + baseaddr
,
5910 /* FIXME: This is recording everything as a low-high
5911 segment of consecutive addresses. We should have a
5912 data structure for discontiguous block ranges
5916 low
= range_beginning
;
5922 if (range_beginning
< low
)
5923 low
= range_beginning
;
5924 if (range_end
> high
)
5930 /* If the first entry is an end-of-list marker, the range
5931 describes an empty scope, i.e. no instructions. */
5937 *high_return
= high
;
5941 /* Get low and high pc attributes from a die. Return 1 if the attributes
5942 are present and valid, otherwise, return 0. Return -1 if the range is
5943 discontinuous, i.e. derived from DW_AT_ranges information. */
5945 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5946 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5947 struct partial_symtab
*pst
)
5949 struct attribute
*attr
;
5954 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5957 high
= DW_ADDR (attr
);
5958 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5960 low
= DW_ADDR (attr
);
5962 /* Found high w/o low attribute. */
5965 /* Found consecutive range of addresses. */
5970 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5973 /* Value of the DW_AT_ranges attribute is the offset in the
5974 .debug_ranges section. */
5975 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
5977 /* Found discontinuous range of addresses. */
5985 /* When using the GNU linker, .gnu.linkonce. sections are used to
5986 eliminate duplicate copies of functions and vtables and such.
5987 The linker will arbitrarily choose one and discard the others.
5988 The AT_*_pc values for such functions refer to local labels in
5989 these sections. If the section from that file was discarded, the
5990 labels are not in the output, so the relocs get a value of 0.
5991 If this is a discarded function, mark the pc bounds as invalid,
5992 so that GDB will ignore it. */
5993 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6001 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6002 its low and high PC addresses. Do nothing if these addresses could not
6003 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6004 and HIGHPC to the high address if greater than HIGHPC. */
6007 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6008 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6009 struct dwarf2_cu
*cu
)
6011 CORE_ADDR low
, high
;
6012 struct die_info
*child
= die
->child
;
6014 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6016 *lowpc
= min (*lowpc
, low
);
6017 *highpc
= max (*highpc
, high
);
6020 /* If the language does not allow nested subprograms (either inside
6021 subprograms or lexical blocks), we're done. */
6022 if (cu
->language
!= language_ada
)
6025 /* Check all the children of the given DIE. If it contains nested
6026 subprograms, then check their pc bounds. Likewise, we need to
6027 check lexical blocks as well, as they may also contain subprogram
6029 while (child
&& child
->tag
)
6031 if (child
->tag
== DW_TAG_subprogram
6032 || child
->tag
== DW_TAG_lexical_block
)
6033 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6034 child
= sibling_die (child
);
6038 /* Get the low and high pc's represented by the scope DIE, and store
6039 them in *LOWPC and *HIGHPC. If the correct values can't be
6040 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6043 get_scope_pc_bounds (struct die_info
*die
,
6044 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6045 struct dwarf2_cu
*cu
)
6047 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6048 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6049 CORE_ADDR current_low
, current_high
;
6051 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6053 best_low
= current_low
;
6054 best_high
= current_high
;
6058 struct die_info
*child
= die
->child
;
6060 while (child
&& child
->tag
)
6062 switch (child
->tag
) {
6063 case DW_TAG_subprogram
:
6064 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6066 case DW_TAG_namespace
:
6068 /* FIXME: carlton/2004-01-16: Should we do this for
6069 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6070 that current GCC's always emit the DIEs corresponding
6071 to definitions of methods of classes as children of a
6072 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6073 the DIEs giving the declarations, which could be
6074 anywhere). But I don't see any reason why the
6075 standards says that they have to be there. */
6076 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6078 if (current_low
!= ((CORE_ADDR
) -1))
6080 best_low
= min (best_low
, current_low
);
6081 best_high
= max (best_high
, current_high
);
6089 child
= sibling_die (child
);
6094 *highpc
= best_high
;
6097 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6100 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6101 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6103 struct attribute
*attr
;
6105 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6108 CORE_ADDR high
= DW_ADDR (attr
);
6110 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6113 CORE_ADDR low
= DW_ADDR (attr
);
6115 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6119 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6122 bfd
*obfd
= cu
->objfile
->obfd
;
6124 /* The value of the DW_AT_ranges attribute is the offset of the
6125 address range list in the .debug_ranges section. */
6126 unsigned long offset
= DW_UNSND (attr
);
6127 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6129 /* For some target architectures, but not others, the
6130 read_address function sign-extends the addresses it returns.
6131 To recognize base address selection entries, we need a
6133 unsigned int addr_size
= cu
->header
.addr_size
;
6134 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6136 /* The base address, to which the next pair is relative. Note
6137 that this 'base' is a DWARF concept: most entries in a range
6138 list are relative, to reduce the number of relocs against the
6139 debugging information. This is separate from this function's
6140 'baseaddr' argument, which GDB uses to relocate debugging
6141 information from a shared library based on the address at
6142 which the library was loaded. */
6143 CORE_ADDR base
= cu
->base_address
;
6144 int base_known
= cu
->base_known
;
6146 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6147 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6149 complaint (&symfile_complaints
,
6150 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6157 unsigned int bytes_read
;
6158 CORE_ADDR start
, end
;
6160 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6161 buffer
+= bytes_read
;
6162 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6163 buffer
+= bytes_read
;
6165 /* Did we find the end of the range list? */
6166 if (start
== 0 && end
== 0)
6169 /* Did we find a base address selection entry? */
6170 else if ((start
& base_select_mask
) == base_select_mask
)
6176 /* We found an ordinary address range. */
6181 complaint (&symfile_complaints
,
6182 _("Invalid .debug_ranges data "
6183 "(no base address)"));
6189 /* Inverted range entries are invalid. */
6190 complaint (&symfile_complaints
,
6191 _("Invalid .debug_ranges data "
6192 "(inverted range)"));
6196 /* Empty range entries have no effect. */
6200 record_block_range (block
,
6201 baseaddr
+ base
+ start
,
6202 baseaddr
+ base
+ end
- 1);
6208 /* Add an aggregate field to the field list. */
6211 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6212 struct dwarf2_cu
*cu
)
6214 struct objfile
*objfile
= cu
->objfile
;
6215 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6216 struct nextfield
*new_field
;
6217 struct attribute
*attr
;
6219 char *fieldname
= "";
6221 /* Allocate a new field list entry and link it in. */
6222 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6223 make_cleanup (xfree
, new_field
);
6224 memset (new_field
, 0, sizeof (struct nextfield
));
6226 if (die
->tag
== DW_TAG_inheritance
)
6228 new_field
->next
= fip
->baseclasses
;
6229 fip
->baseclasses
= new_field
;
6233 new_field
->next
= fip
->fields
;
6234 fip
->fields
= new_field
;
6238 /* Handle accessibility and virtuality of field.
6239 The default accessibility for members is public, the default
6240 accessibility for inheritance is private. */
6241 if (die
->tag
!= DW_TAG_inheritance
)
6242 new_field
->accessibility
= DW_ACCESS_public
;
6244 new_field
->accessibility
= DW_ACCESS_private
;
6245 new_field
->virtuality
= DW_VIRTUALITY_none
;
6247 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6249 new_field
->accessibility
= DW_UNSND (attr
);
6250 if (new_field
->accessibility
!= DW_ACCESS_public
)
6251 fip
->non_public_fields
= 1;
6252 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6254 new_field
->virtuality
= DW_UNSND (attr
);
6256 fp
= &new_field
->field
;
6258 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6260 /* Data member other than a C++ static data member. */
6262 /* Get type of field. */
6263 fp
->type
= die_type (die
, cu
);
6265 SET_FIELD_BITPOS (*fp
, 0);
6267 /* Get bit size of field (zero if none). */
6268 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6271 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6275 FIELD_BITSIZE (*fp
) = 0;
6278 /* Get bit offset of field. */
6279 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6282 int byte_offset
= 0;
6284 if (attr_form_is_section_offset (attr
))
6285 dwarf2_complex_location_expr_complaint ();
6286 else if (attr_form_is_constant (attr
))
6287 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6288 else if (attr_form_is_block (attr
))
6289 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6291 dwarf2_complex_location_expr_complaint ();
6293 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6295 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6298 if (gdbarch_bits_big_endian (gdbarch
))
6300 /* For big endian bits, the DW_AT_bit_offset gives the
6301 additional bit offset from the MSB of the containing
6302 anonymous object to the MSB of the field. We don't
6303 have to do anything special since we don't need to
6304 know the size of the anonymous object. */
6305 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6309 /* For little endian bits, compute the bit offset to the
6310 MSB of the anonymous object, subtract off the number of
6311 bits from the MSB of the field to the MSB of the
6312 object, and then subtract off the number of bits of
6313 the field itself. The result is the bit offset of
6314 the LSB of the field. */
6316 int bit_offset
= DW_UNSND (attr
);
6318 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6321 /* The size of the anonymous object containing
6322 the bit field is explicit, so use the
6323 indicated size (in bytes). */
6324 anonymous_size
= DW_UNSND (attr
);
6328 /* The size of the anonymous object containing
6329 the bit field must be inferred from the type
6330 attribute of the data member containing the
6332 anonymous_size
= TYPE_LENGTH (fp
->type
);
6334 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6335 - bit_offset
- FIELD_BITSIZE (*fp
);
6339 /* Get name of field. */
6340 fieldname
= dwarf2_name (die
, cu
);
6341 if (fieldname
== NULL
)
6344 /* The name is already allocated along with this objfile, so we don't
6345 need to duplicate it for the type. */
6346 fp
->name
= fieldname
;
6348 /* Change accessibility for artificial fields (e.g. virtual table
6349 pointer or virtual base class pointer) to private. */
6350 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6352 FIELD_ARTIFICIAL (*fp
) = 1;
6353 new_field
->accessibility
= DW_ACCESS_private
;
6354 fip
->non_public_fields
= 1;
6357 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6359 /* C++ static member. */
6361 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6362 is a declaration, but all versions of G++ as of this writing
6363 (so through at least 3.2.1) incorrectly generate
6364 DW_TAG_variable tags. */
6368 /* Get name of field. */
6369 fieldname
= dwarf2_name (die
, cu
);
6370 if (fieldname
== NULL
)
6373 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6375 /* Only create a symbol if this is an external value.
6376 new_symbol checks this and puts the value in the global symbol
6377 table, which we want. If it is not external, new_symbol
6378 will try to put the value in cu->list_in_scope which is wrong. */
6379 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6381 /* A static const member, not much different than an enum as far as
6382 we're concerned, except that we can support more types. */
6383 new_symbol (die
, NULL
, cu
);
6386 /* Get physical name. */
6387 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6389 /* The name is already allocated along with this objfile, so we don't
6390 need to duplicate it for the type. */
6391 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6392 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6393 FIELD_NAME (*fp
) = fieldname
;
6395 else if (die
->tag
== DW_TAG_inheritance
)
6397 /* C++ base class field. */
6398 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6401 int byte_offset
= 0;
6403 if (attr_form_is_section_offset (attr
))
6404 dwarf2_complex_location_expr_complaint ();
6405 else if (attr_form_is_constant (attr
))
6406 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6407 else if (attr_form_is_block (attr
))
6408 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6410 dwarf2_complex_location_expr_complaint ();
6412 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6414 FIELD_BITSIZE (*fp
) = 0;
6415 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6416 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6417 fip
->nbaseclasses
++;
6421 /* Add a typedef defined in the scope of the FIP's class. */
6424 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6425 struct dwarf2_cu
*cu
)
6427 struct objfile
*objfile
= cu
->objfile
;
6428 struct typedef_field_list
*new_field
;
6429 struct attribute
*attr
;
6430 struct typedef_field
*fp
;
6431 char *fieldname
= "";
6433 /* Allocate a new field list entry and link it in. */
6434 new_field
= xzalloc (sizeof (*new_field
));
6435 make_cleanup (xfree
, new_field
);
6437 gdb_assert (die
->tag
== DW_TAG_typedef
);
6439 fp
= &new_field
->field
;
6441 /* Get name of field. */
6442 fp
->name
= dwarf2_name (die
, cu
);
6443 if (fp
->name
== NULL
)
6446 fp
->type
= read_type_die (die
, cu
);
6448 new_field
->next
= fip
->typedef_field_list
;
6449 fip
->typedef_field_list
= new_field
;
6450 fip
->typedef_field_list_count
++;
6453 /* Create the vector of fields, and attach it to the type. */
6456 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6457 struct dwarf2_cu
*cu
)
6459 int nfields
= fip
->nfields
;
6461 /* Record the field count, allocate space for the array of fields,
6462 and create blank accessibility bitfields if necessary. */
6463 TYPE_NFIELDS (type
) = nfields
;
6464 TYPE_FIELDS (type
) = (struct field
*)
6465 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6466 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6468 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6470 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6472 TYPE_FIELD_PRIVATE_BITS (type
) =
6473 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6474 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6476 TYPE_FIELD_PROTECTED_BITS (type
) =
6477 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6478 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6480 TYPE_FIELD_IGNORE_BITS (type
) =
6481 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6482 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6485 /* If the type has baseclasses, allocate and clear a bit vector for
6486 TYPE_FIELD_VIRTUAL_BITS. */
6487 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6489 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6490 unsigned char *pointer
;
6492 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6493 pointer
= TYPE_ALLOC (type
, num_bytes
);
6494 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6495 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6496 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6499 /* Copy the saved-up fields into the field vector. Start from the head of
6500 the list, adding to the tail of the field array, so that they end up in
6501 the same order in the array in which they were added to the list. */
6502 while (nfields
-- > 0)
6504 struct nextfield
*fieldp
;
6508 fieldp
= fip
->fields
;
6509 fip
->fields
= fieldp
->next
;
6513 fieldp
= fip
->baseclasses
;
6514 fip
->baseclasses
= fieldp
->next
;
6517 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6518 switch (fieldp
->accessibility
)
6520 case DW_ACCESS_private
:
6521 if (cu
->language
!= language_ada
)
6522 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6525 case DW_ACCESS_protected
:
6526 if (cu
->language
!= language_ada
)
6527 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6530 case DW_ACCESS_public
:
6534 /* Unknown accessibility. Complain and treat it as public. */
6536 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6537 fieldp
->accessibility
);
6541 if (nfields
< fip
->nbaseclasses
)
6543 switch (fieldp
->virtuality
)
6545 case DW_VIRTUALITY_virtual
:
6546 case DW_VIRTUALITY_pure_virtual
:
6547 if (cu
->language
== language_ada
)
6548 error (_("unexpected virtuality in component of Ada type"));
6549 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6556 /* Add a member function to the proper fieldlist. */
6559 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6560 struct type
*type
, struct dwarf2_cu
*cu
)
6562 struct objfile
*objfile
= cu
->objfile
;
6563 struct attribute
*attr
;
6564 struct fnfieldlist
*flp
;
6566 struct fn_field
*fnp
;
6568 struct nextfnfield
*new_fnfield
;
6569 struct type
*this_type
;
6571 if (cu
->language
== language_ada
)
6572 error (_("unexpected member function in Ada type"));
6574 /* Get name of member function. */
6575 fieldname
= dwarf2_name (die
, cu
);
6576 if (fieldname
== NULL
)
6579 /* Look up member function name in fieldlist. */
6580 for (i
= 0; i
< fip
->nfnfields
; i
++)
6582 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6586 /* Create new list element if necessary. */
6587 if (i
< fip
->nfnfields
)
6588 flp
= &fip
->fnfieldlists
[i
];
6591 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6593 fip
->fnfieldlists
= (struct fnfieldlist
*)
6594 xrealloc (fip
->fnfieldlists
,
6595 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6596 * sizeof (struct fnfieldlist
));
6597 if (fip
->nfnfields
== 0)
6598 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6600 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6601 flp
->name
= fieldname
;
6604 i
= fip
->nfnfields
++;
6607 /* Create a new member function field and chain it to the field list
6609 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6610 make_cleanup (xfree
, new_fnfield
);
6611 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6612 new_fnfield
->next
= flp
->head
;
6613 flp
->head
= new_fnfield
;
6616 /* Fill in the member function field info. */
6617 fnp
= &new_fnfield
->fnfield
;
6619 /* Delay processing of the physname until later. */
6620 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
6622 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
6627 char *physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6628 fnp
->physname
= physname
? physname
: "";
6631 fnp
->type
= alloc_type (objfile
);
6632 this_type
= read_type_die (die
, cu
);
6633 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6635 int nparams
= TYPE_NFIELDS (this_type
);
6637 /* TYPE is the domain of this method, and THIS_TYPE is the type
6638 of the method itself (TYPE_CODE_METHOD). */
6639 smash_to_method_type (fnp
->type
, type
,
6640 TYPE_TARGET_TYPE (this_type
),
6641 TYPE_FIELDS (this_type
),
6642 TYPE_NFIELDS (this_type
),
6643 TYPE_VARARGS (this_type
));
6645 /* Handle static member functions.
6646 Dwarf2 has no clean way to discern C++ static and non-static
6647 member functions. G++ helps GDB by marking the first
6648 parameter for non-static member functions (which is the this
6649 pointer) as artificial. We obtain this information from
6650 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6651 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6652 fnp
->voffset
= VOFFSET_STATIC
;
6655 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
6656 dwarf2_full_name (fieldname
, die
, cu
));
6658 /* Get fcontext from DW_AT_containing_type if present. */
6659 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6660 fnp
->fcontext
= die_containing_type (die
, cu
);
6662 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
6663 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6665 /* Get accessibility. */
6666 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6669 switch (DW_UNSND (attr
))
6671 case DW_ACCESS_private
:
6672 fnp
->is_private
= 1;
6674 case DW_ACCESS_protected
:
6675 fnp
->is_protected
= 1;
6680 /* Check for artificial methods. */
6681 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
6682 if (attr
&& DW_UNSND (attr
) != 0)
6683 fnp
->is_artificial
= 1;
6685 /* Get index in virtual function table if it is a virtual member
6686 function. For older versions of GCC, this is an offset in the
6687 appropriate virtual table, as specified by DW_AT_containing_type.
6688 For everyone else, it is an expression to be evaluated relative
6689 to the object address. */
6691 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
6694 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
6696 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
6698 /* Old-style GCC. */
6699 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
6701 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6702 || (DW_BLOCK (attr
)->size
> 1
6703 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
6704 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
6706 struct dwarf_block blk
;
6709 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6711 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
6712 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
6713 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6714 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
6715 dwarf2_complex_location_expr_complaint ();
6717 fnp
->voffset
/= cu
->header
.addr_size
;
6721 dwarf2_complex_location_expr_complaint ();
6724 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
6726 else if (attr_form_is_section_offset (attr
))
6728 dwarf2_complex_location_expr_complaint ();
6732 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6738 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6739 if (attr
&& DW_UNSND (attr
))
6741 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6742 complaint (&symfile_complaints
,
6743 _("Member function \"%s\" (offset %d) is virtual "
6744 "but the vtable offset is not specified"),
6745 fieldname
, die
->offset
);
6746 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6747 TYPE_CPLUS_DYNAMIC (type
) = 1;
6752 /* Create the vector of member function fields, and attach it to the type. */
6755 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6756 struct dwarf2_cu
*cu
)
6758 struct fnfieldlist
*flp
;
6759 int total_length
= 0;
6762 if (cu
->language
== language_ada
)
6763 error (_("unexpected member functions in Ada type"));
6765 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6766 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6767 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6769 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6771 struct nextfnfield
*nfp
= flp
->head
;
6772 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6775 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6776 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6777 fn_flp
->fn_fields
= (struct fn_field
*)
6778 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6779 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6780 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6782 total_length
+= flp
->length
;
6785 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6786 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6789 /* Returns non-zero if NAME is the name of a vtable member in CU's
6790 language, zero otherwise. */
6792 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6794 static const char vptr
[] = "_vptr";
6795 static const char vtable
[] = "vtable";
6797 /* Look for the C++ and Java forms of the vtable. */
6798 if ((cu
->language
== language_java
6799 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6800 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6801 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6807 /* GCC outputs unnamed structures that are really pointers to member
6808 functions, with the ABI-specified layout. If TYPE describes
6809 such a structure, smash it into a member function type.
6811 GCC shouldn't do this; it should just output pointer to member DIEs.
6812 This is GCC PR debug/28767. */
6815 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6817 struct type
*pfn_type
, *domain_type
, *new_type
;
6819 /* Check for a structure with no name and two children. */
6820 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6823 /* Check for __pfn and __delta members. */
6824 if (TYPE_FIELD_NAME (type
, 0) == NULL
6825 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6826 || TYPE_FIELD_NAME (type
, 1) == NULL
6827 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6830 /* Find the type of the method. */
6831 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6832 if (pfn_type
== NULL
6833 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6834 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6837 /* Look for the "this" argument. */
6838 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6839 if (TYPE_NFIELDS (pfn_type
) == 0
6840 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6841 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6844 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6845 new_type
= alloc_type (objfile
);
6846 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6847 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6848 TYPE_VARARGS (pfn_type
));
6849 smash_to_methodptr_type (type
, new_type
);
6852 /* Called when we find the DIE that starts a structure or union scope
6853 (definition) to create a type for the structure or union. Fill in
6854 the type's name and general properties; the members will not be
6855 processed until process_structure_type.
6857 NOTE: we need to call these functions regardless of whether or not the
6858 DIE has a DW_AT_name attribute, since it might be an anonymous
6859 structure or union. This gets the type entered into our set of
6862 However, if the structure is incomplete (an opaque struct/union)
6863 then suppress creating a symbol table entry for it since gdb only
6864 wants to find the one with the complete definition. Note that if
6865 it is complete, we just call new_symbol, which does it's own
6866 checking about whether the struct/union is anonymous or not (and
6867 suppresses creating a symbol table entry itself). */
6869 static struct type
*
6870 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6872 struct objfile
*objfile
= cu
->objfile
;
6874 struct attribute
*attr
;
6877 /* If the definition of this type lives in .debug_types, read that type.
6878 Don't follow DW_AT_specification though, that will take us back up
6879 the chain and we want to go down. */
6880 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6883 struct dwarf2_cu
*type_cu
= cu
;
6884 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6886 /* We could just recurse on read_structure_type, but we need to call
6887 get_die_type to ensure only one type for this DIE is created.
6888 This is important, for example, because for c++ classes we need
6889 TYPE_NAME set which is only done by new_symbol. Blech. */
6890 type
= read_type_die (type_die
, type_cu
);
6892 /* TYPE_CU may not be the same as CU.
6893 Ensure TYPE is recorded in CU's type_hash table. */
6894 return set_die_type (die
, type
, cu
);
6897 type
= alloc_type (objfile
);
6898 INIT_CPLUS_SPECIFIC (type
);
6900 name
= dwarf2_name (die
, cu
);
6903 if (cu
->language
== language_cplus
6904 || cu
->language
== language_java
)
6906 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
6908 /* dwarf2_full_name might have already finished building the DIE's
6909 type. If so, there is no need to continue. */
6910 if (get_die_type (die
, cu
) != NULL
)
6911 return get_die_type (die
, cu
);
6913 TYPE_TAG_NAME (type
) = full_name
;
6914 if (die
->tag
== DW_TAG_structure_type
6915 || die
->tag
== DW_TAG_class_type
)
6916 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6920 /* The name is already allocated along with this objfile, so
6921 we don't need to duplicate it for the type. */
6922 TYPE_TAG_NAME (type
) = (char *) name
;
6923 if (die
->tag
== DW_TAG_class_type
)
6924 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6928 if (die
->tag
== DW_TAG_structure_type
)
6930 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
6932 else if (die
->tag
== DW_TAG_union_type
)
6934 TYPE_CODE (type
) = TYPE_CODE_UNION
;
6938 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
6941 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
6942 TYPE_DECLARED_CLASS (type
) = 1;
6944 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6947 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6951 TYPE_LENGTH (type
) = 0;
6954 TYPE_STUB_SUPPORTED (type
) = 1;
6955 if (die_is_declaration (die
, cu
))
6956 TYPE_STUB (type
) = 1;
6957 else if (attr
== NULL
&& die
->child
== NULL
6958 && producer_is_realview (cu
->producer
))
6959 /* RealView does not output the required DW_AT_declaration
6960 on incomplete types. */
6961 TYPE_STUB (type
) = 1;
6963 /* We need to add the type field to the die immediately so we don't
6964 infinitely recurse when dealing with pointers to the structure
6965 type within the structure itself. */
6966 set_die_type (die
, type
, cu
);
6968 /* set_die_type should be already done. */
6969 set_descriptive_type (type
, die
, cu
);
6974 /* Finish creating a structure or union type, including filling in
6975 its members and creating a symbol for it. */
6978 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6980 struct objfile
*objfile
= cu
->objfile
;
6981 struct die_info
*child_die
= die
->child
;
6984 type
= get_die_type (die
, cu
);
6986 type
= read_structure_type (die
, cu
);
6988 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
6990 struct field_info fi
;
6991 struct die_info
*child_die
;
6992 VEC (symbolp
) *template_args
= NULL
;
6993 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6995 memset (&fi
, 0, sizeof (struct field_info
));
6997 child_die
= die
->child
;
6999 while (child_die
&& child_die
->tag
)
7001 if (child_die
->tag
== DW_TAG_member
7002 || child_die
->tag
== DW_TAG_variable
)
7004 /* NOTE: carlton/2002-11-05: A C++ static data member
7005 should be a DW_TAG_member that is a declaration, but
7006 all versions of G++ as of this writing (so through at
7007 least 3.2.1) incorrectly generate DW_TAG_variable
7008 tags for them instead. */
7009 dwarf2_add_field (&fi
, child_die
, cu
);
7011 else if (child_die
->tag
== DW_TAG_subprogram
)
7013 /* C++ member function. */
7014 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7016 else if (child_die
->tag
== DW_TAG_inheritance
)
7018 /* C++ base class field. */
7019 dwarf2_add_field (&fi
, child_die
, cu
);
7021 else if (child_die
->tag
== DW_TAG_typedef
)
7022 dwarf2_add_typedef (&fi
, child_die
, cu
);
7023 else if (child_die
->tag
== DW_TAG_template_type_param
7024 || child_die
->tag
== DW_TAG_template_value_param
)
7026 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7029 VEC_safe_push (symbolp
, template_args
, arg
);
7032 child_die
= sibling_die (child_die
);
7035 /* Attach template arguments to type. */
7036 if (! VEC_empty (symbolp
, template_args
))
7038 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7039 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7040 = VEC_length (symbolp
, template_args
);
7041 TYPE_TEMPLATE_ARGUMENTS (type
)
7042 = obstack_alloc (&objfile
->objfile_obstack
,
7043 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7044 * sizeof (struct symbol
*)));
7045 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7046 VEC_address (symbolp
, template_args
),
7047 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7048 * sizeof (struct symbol
*)));
7049 VEC_free (symbolp
, template_args
);
7052 /* Attach fields and member functions to the type. */
7054 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7057 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7059 /* Get the type which refers to the base class (possibly this
7060 class itself) which contains the vtable pointer for the current
7061 class from the DW_AT_containing_type attribute. This use of
7062 DW_AT_containing_type is a GNU extension. */
7064 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7066 struct type
*t
= die_containing_type (die
, cu
);
7068 TYPE_VPTR_BASETYPE (type
) = t
;
7073 /* Our own class provides vtbl ptr. */
7074 for (i
= TYPE_NFIELDS (t
) - 1;
7075 i
>= TYPE_N_BASECLASSES (t
);
7078 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7080 if (is_vtable_name (fieldname
, cu
))
7082 TYPE_VPTR_FIELDNO (type
) = i
;
7087 /* Complain if virtual function table field not found. */
7088 if (i
< TYPE_N_BASECLASSES (t
))
7089 complaint (&symfile_complaints
,
7090 _("virtual function table pointer "
7091 "not found when defining class '%s'"),
7092 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7097 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7100 else if (cu
->producer
7101 && strncmp (cu
->producer
,
7102 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7104 /* The IBM XLC compiler does not provide direct indication
7105 of the containing type, but the vtable pointer is
7106 always named __vfp. */
7110 for (i
= TYPE_NFIELDS (type
) - 1;
7111 i
>= TYPE_N_BASECLASSES (type
);
7114 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7116 TYPE_VPTR_FIELDNO (type
) = i
;
7117 TYPE_VPTR_BASETYPE (type
) = type
;
7124 /* Copy fi.typedef_field_list linked list elements content into the
7125 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7126 if (fi
.typedef_field_list
)
7128 int i
= fi
.typedef_field_list_count
;
7130 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7131 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7132 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7133 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7135 /* Reverse the list order to keep the debug info elements order. */
7138 struct typedef_field
*dest
, *src
;
7140 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7141 src
= &fi
.typedef_field_list
->field
;
7142 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7147 do_cleanups (back_to
);
7150 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
7152 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7153 snapshots) has been known to create a die giving a declaration
7154 for a class that has, as a child, a die giving a definition for a
7155 nested class. So we have to process our children even if the
7156 current die is a declaration. Normally, of course, a declaration
7157 won't have any children at all. */
7159 while (child_die
!= NULL
&& child_die
->tag
)
7161 if (child_die
->tag
== DW_TAG_member
7162 || child_die
->tag
== DW_TAG_variable
7163 || child_die
->tag
== DW_TAG_inheritance
7164 || child_die
->tag
== DW_TAG_template_value_param
7165 || child_die
->tag
== DW_TAG_template_type_param
)
7170 process_die (child_die
, cu
);
7172 child_die
= sibling_die (child_die
);
7175 /* Do not consider external references. According to the DWARF standard,
7176 these DIEs are identified by the fact that they have no byte_size
7177 attribute, and a declaration attribute. */
7178 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7179 || !die_is_declaration (die
, cu
))
7180 new_symbol (die
, type
, cu
);
7183 /* Given a DW_AT_enumeration_type die, set its type. We do not
7184 complete the type's fields yet, or create any symbols. */
7186 static struct type
*
7187 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7189 struct objfile
*objfile
= cu
->objfile
;
7191 struct attribute
*attr
;
7194 /* If the definition of this type lives in .debug_types, read that type.
7195 Don't follow DW_AT_specification though, that will take us back up
7196 the chain and we want to go down. */
7197 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7200 struct dwarf2_cu
*type_cu
= cu
;
7201 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7203 type
= read_type_die (type_die
, type_cu
);
7205 /* TYPE_CU may not be the same as CU.
7206 Ensure TYPE is recorded in CU's type_hash table. */
7207 return set_die_type (die
, type
, cu
);
7210 type
= alloc_type (objfile
);
7212 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7213 name
= dwarf2_full_name (NULL
, die
, cu
);
7215 TYPE_TAG_NAME (type
) = (char *) name
;
7217 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7220 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7224 TYPE_LENGTH (type
) = 0;
7227 /* The enumeration DIE can be incomplete. In Ada, any type can be
7228 declared as private in the package spec, and then defined only
7229 inside the package body. Such types are known as Taft Amendment
7230 Types. When another package uses such a type, an incomplete DIE
7231 may be generated by the compiler. */
7232 if (die_is_declaration (die
, cu
))
7233 TYPE_STUB (type
) = 1;
7235 return set_die_type (die
, type
, cu
);
7238 /* Given a pointer to a die which begins an enumeration, process all
7239 the dies that define the members of the enumeration, and create the
7240 symbol for the enumeration type.
7242 NOTE: We reverse the order of the element list. */
7245 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7247 struct type
*this_type
;
7249 this_type
= get_die_type (die
, cu
);
7250 if (this_type
== NULL
)
7251 this_type
= read_enumeration_type (die
, cu
);
7253 if (die
->child
!= NULL
)
7255 struct die_info
*child_die
;
7257 struct field
*fields
= NULL
;
7259 int unsigned_enum
= 1;
7262 child_die
= die
->child
;
7263 while (child_die
&& child_die
->tag
)
7265 if (child_die
->tag
!= DW_TAG_enumerator
)
7267 process_die (child_die
, cu
);
7271 name
= dwarf2_name (child_die
, cu
);
7274 sym
= new_symbol (child_die
, this_type
, cu
);
7275 if (SYMBOL_VALUE (sym
) < 0)
7278 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7280 fields
= (struct field
*)
7282 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7283 * sizeof (struct field
));
7286 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7287 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7288 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7289 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7295 child_die
= sibling_die (child_die
);
7300 TYPE_NFIELDS (this_type
) = num_fields
;
7301 TYPE_FIELDS (this_type
) = (struct field
*)
7302 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7303 memcpy (TYPE_FIELDS (this_type
), fields
,
7304 sizeof (struct field
) * num_fields
);
7308 TYPE_UNSIGNED (this_type
) = 1;
7311 new_symbol (die
, this_type
, cu
);
7314 /* Extract all information from a DW_TAG_array_type DIE and put it in
7315 the DIE's type field. For now, this only handles one dimensional
7318 static struct type
*
7319 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7321 struct objfile
*objfile
= cu
->objfile
;
7322 struct die_info
*child_die
;
7324 struct type
*element_type
, *range_type
, *index_type
;
7325 struct type
**range_types
= NULL
;
7326 struct attribute
*attr
;
7328 struct cleanup
*back_to
;
7331 element_type
= die_type (die
, cu
);
7333 /* The die_type call above may have already set the type for this DIE. */
7334 type
= get_die_type (die
, cu
);
7338 /* Irix 6.2 native cc creates array types without children for
7339 arrays with unspecified length. */
7340 if (die
->child
== NULL
)
7342 index_type
= objfile_type (objfile
)->builtin_int
;
7343 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7344 type
= create_array_type (NULL
, element_type
, range_type
);
7345 return set_die_type (die
, type
, cu
);
7348 back_to
= make_cleanup (null_cleanup
, NULL
);
7349 child_die
= die
->child
;
7350 while (child_die
&& child_die
->tag
)
7352 if (child_die
->tag
== DW_TAG_subrange_type
)
7354 struct type
*child_type
= read_type_die (child_die
, cu
);
7356 if (child_type
!= NULL
)
7358 /* The range type was succesfully read. Save it for the
7359 array type creation. */
7360 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7362 range_types
= (struct type
**)
7363 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7364 * sizeof (struct type
*));
7366 make_cleanup (free_current_contents
, &range_types
);
7368 range_types
[ndim
++] = child_type
;
7371 child_die
= sibling_die (child_die
);
7374 /* Dwarf2 dimensions are output from left to right, create the
7375 necessary array types in backwards order. */
7377 type
= element_type
;
7379 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7384 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7389 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7392 /* Understand Dwarf2 support for vector types (like they occur on
7393 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7394 array type. This is not part of the Dwarf2/3 standard yet, but a
7395 custom vendor extension. The main difference between a regular
7396 array and the vector variant is that vectors are passed by value
7398 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7400 make_vector_type (type
);
7402 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7403 implementation may choose to implement triple vectors using this
7405 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7408 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
7409 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7411 complaint (&symfile_complaints
,
7412 _("DW_AT_byte_size for array type smaller "
7413 "than the total size of elements"));
7416 name
= dwarf2_name (die
, cu
);
7418 TYPE_NAME (type
) = name
;
7420 /* Install the type in the die. */
7421 set_die_type (die
, type
, cu
);
7423 /* set_die_type should be already done. */
7424 set_descriptive_type (type
, die
, cu
);
7426 do_cleanups (back_to
);
7431 static enum dwarf_array_dim_ordering
7432 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7434 struct attribute
*attr
;
7436 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7438 if (attr
) return DW_SND (attr
);
7440 /* GNU F77 is a special case, as at 08/2004 array type info is the
7441 opposite order to the dwarf2 specification, but data is still
7442 laid out as per normal fortran.
7444 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7445 version checking. */
7447 if (cu
->language
== language_fortran
7448 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7450 return DW_ORD_row_major
;
7453 switch (cu
->language_defn
->la_array_ordering
)
7455 case array_column_major
:
7456 return DW_ORD_col_major
;
7457 case array_row_major
:
7459 return DW_ORD_row_major
;
7463 /* Extract all information from a DW_TAG_set_type DIE and put it in
7464 the DIE's type field. */
7466 static struct type
*
7467 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7469 struct type
*domain_type
, *set_type
;
7470 struct attribute
*attr
;
7472 domain_type
= die_type (die
, cu
);
7474 /* The die_type call above may have already set the type for this DIE. */
7475 set_type
= get_die_type (die
, cu
);
7479 set_type
= create_set_type (NULL
, domain_type
);
7481 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7483 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7485 return set_die_type (die
, set_type
, cu
);
7488 /* First cut: install each common block member as a global variable. */
7491 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7493 struct die_info
*child_die
;
7494 struct attribute
*attr
;
7496 CORE_ADDR base
= (CORE_ADDR
) 0;
7498 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7501 /* Support the .debug_loc offsets. */
7502 if (attr_form_is_block (attr
))
7504 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7506 else if (attr_form_is_section_offset (attr
))
7508 dwarf2_complex_location_expr_complaint ();
7512 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7513 "common block member");
7516 if (die
->child
!= NULL
)
7518 child_die
= die
->child
;
7519 while (child_die
&& child_die
->tag
)
7521 sym
= new_symbol (child_die
, NULL
, cu
);
7522 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
7523 if (sym
!= NULL
&& attr
!= NULL
)
7525 CORE_ADDR byte_offset
= 0;
7527 if (attr_form_is_section_offset (attr
))
7528 dwarf2_complex_location_expr_complaint ();
7529 else if (attr_form_is_constant (attr
))
7530 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
7531 else if (attr_form_is_block (attr
))
7532 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7534 dwarf2_complex_location_expr_complaint ();
7536 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
7537 add_symbol_to_list (sym
, &global_symbols
);
7539 child_die
= sibling_die (child_die
);
7544 /* Create a type for a C++ namespace. */
7546 static struct type
*
7547 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7549 struct objfile
*objfile
= cu
->objfile
;
7550 const char *previous_prefix
, *name
;
7554 /* For extensions, reuse the type of the original namespace. */
7555 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7557 struct die_info
*ext_die
;
7558 struct dwarf2_cu
*ext_cu
= cu
;
7560 ext_die
= dwarf2_extension (die
, &ext_cu
);
7561 type
= read_type_die (ext_die
, ext_cu
);
7563 /* EXT_CU may not be the same as CU.
7564 Ensure TYPE is recorded in CU's type_hash table. */
7565 return set_die_type (die
, type
, cu
);
7568 name
= namespace_name (die
, &is_anonymous
, cu
);
7570 /* Now build the name of the current namespace. */
7572 previous_prefix
= determine_prefix (die
, cu
);
7573 if (previous_prefix
[0] != '\0')
7574 name
= typename_concat (&objfile
->objfile_obstack
,
7575 previous_prefix
, name
, 0, cu
);
7577 /* Create the type. */
7578 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7580 TYPE_NAME (type
) = (char *) name
;
7581 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7583 return set_die_type (die
, type
, cu
);
7586 /* Read a C++ namespace. */
7589 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7591 struct objfile
*objfile
= cu
->objfile
;
7594 /* Add a symbol associated to this if we haven't seen the namespace
7595 before. Also, add a using directive if it's an anonymous
7598 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7602 type
= read_type_die (die
, cu
);
7603 new_symbol (die
, type
, cu
);
7605 namespace_name (die
, &is_anonymous
, cu
);
7608 const char *previous_prefix
= determine_prefix (die
, cu
);
7610 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7611 NULL
, &objfile
->objfile_obstack
);
7615 if (die
->child
!= NULL
)
7617 struct die_info
*child_die
= die
->child
;
7619 while (child_die
&& child_die
->tag
)
7621 process_die (child_die
, cu
);
7622 child_die
= sibling_die (child_die
);
7627 /* Read a Fortran module as type. This DIE can be only a declaration used for
7628 imported module. Still we need that type as local Fortran "use ... only"
7629 declaration imports depend on the created type in determine_prefix. */
7631 static struct type
*
7632 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7634 struct objfile
*objfile
= cu
->objfile
;
7638 module_name
= dwarf2_name (die
, cu
);
7640 complaint (&symfile_complaints
,
7641 _("DW_TAG_module has no name, offset 0x%x"),
7643 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7645 /* determine_prefix uses TYPE_TAG_NAME. */
7646 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7648 return set_die_type (die
, type
, cu
);
7651 /* Read a Fortran module. */
7654 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7656 struct die_info
*child_die
= die
->child
;
7658 while (child_die
&& child_die
->tag
)
7660 process_die (child_die
, cu
);
7661 child_die
= sibling_die (child_die
);
7665 /* Return the name of the namespace represented by DIE. Set
7666 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7670 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
7672 struct die_info
*current_die
;
7673 const char *name
= NULL
;
7675 /* Loop through the extensions until we find a name. */
7677 for (current_die
= die
;
7678 current_die
!= NULL
;
7679 current_die
= dwarf2_extension (die
, &cu
))
7681 name
= dwarf2_name (current_die
, cu
);
7686 /* Is it an anonymous namespace? */
7688 *is_anonymous
= (name
== NULL
);
7690 name
= "(anonymous namespace)";
7695 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7696 the user defined type vector. */
7698 static struct type
*
7699 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7701 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7702 struct comp_unit_head
*cu_header
= &cu
->header
;
7704 struct attribute
*attr_byte_size
;
7705 struct attribute
*attr_address_class
;
7706 int byte_size
, addr_class
;
7707 struct type
*target_type
;
7709 target_type
= die_type (die
, cu
);
7711 /* The die_type call above may have already set the type for this DIE. */
7712 type
= get_die_type (die
, cu
);
7716 type
= lookup_pointer_type (target_type
);
7718 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7720 byte_size
= DW_UNSND (attr_byte_size
);
7722 byte_size
= cu_header
->addr_size
;
7724 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
7725 if (attr_address_class
)
7726 addr_class
= DW_UNSND (attr_address_class
);
7728 addr_class
= DW_ADDR_none
;
7730 /* If the pointer size or address class is different than the
7731 default, create a type variant marked as such and set the
7732 length accordingly. */
7733 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
7735 if (gdbarch_address_class_type_flags_p (gdbarch
))
7739 type_flags
= gdbarch_address_class_type_flags
7740 (gdbarch
, byte_size
, addr_class
);
7741 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
7743 type
= make_type_with_address_space (type
, type_flags
);
7745 else if (TYPE_LENGTH (type
) != byte_size
)
7747 complaint (&symfile_complaints
,
7748 _("invalid pointer size %d"), byte_size
);
7752 /* Should we also complain about unhandled address classes? */
7756 TYPE_LENGTH (type
) = byte_size
;
7757 return set_die_type (die
, type
, cu
);
7760 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7761 the user defined type vector. */
7763 static struct type
*
7764 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7767 struct type
*to_type
;
7768 struct type
*domain
;
7770 to_type
= die_type (die
, cu
);
7771 domain
= die_containing_type (die
, cu
);
7773 /* The calls above may have already set the type for this DIE. */
7774 type
= get_die_type (die
, cu
);
7778 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
7779 type
= lookup_methodptr_type (to_type
);
7781 type
= lookup_memberptr_type (to_type
, domain
);
7783 return set_die_type (die
, type
, cu
);
7786 /* Extract all information from a DW_TAG_reference_type DIE and add to
7787 the user defined type vector. */
7789 static struct type
*
7790 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7792 struct comp_unit_head
*cu_header
= &cu
->header
;
7793 struct type
*type
, *target_type
;
7794 struct attribute
*attr
;
7796 target_type
= die_type (die
, cu
);
7798 /* The die_type call above may have already set the type for this DIE. */
7799 type
= get_die_type (die
, cu
);
7803 type
= lookup_reference_type (target_type
);
7804 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7807 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7811 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7813 return set_die_type (die
, type
, cu
);
7816 static struct type
*
7817 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7819 struct type
*base_type
, *cv_type
;
7821 base_type
= die_type (die
, cu
);
7823 /* The die_type call above may have already set the type for this DIE. */
7824 cv_type
= get_die_type (die
, cu
);
7828 /* In case the const qualifier is applied to an array type, the element type
7829 is so qualified, not the array type (section 6.7.3 of C99). */
7830 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
7832 struct type
*el_type
, *inner_array
;
7834 base_type
= copy_type (base_type
);
7835 inner_array
= base_type
;
7837 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
7839 TYPE_TARGET_TYPE (inner_array
) =
7840 copy_type (TYPE_TARGET_TYPE (inner_array
));
7841 inner_array
= TYPE_TARGET_TYPE (inner_array
);
7844 el_type
= TYPE_TARGET_TYPE (inner_array
);
7845 TYPE_TARGET_TYPE (inner_array
) =
7846 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
7848 return set_die_type (die
, base_type
, cu
);
7851 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7852 return set_die_type (die
, cv_type
, cu
);
7855 static struct type
*
7856 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7858 struct type
*base_type
, *cv_type
;
7860 base_type
= die_type (die
, cu
);
7862 /* The die_type call above may have already set the type for this DIE. */
7863 cv_type
= get_die_type (die
, cu
);
7867 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7868 return set_die_type (die
, cv_type
, cu
);
7871 /* Extract all information from a DW_TAG_string_type DIE and add to
7872 the user defined type vector. It isn't really a user defined type,
7873 but it behaves like one, with other DIE's using an AT_user_def_type
7874 attribute to reference it. */
7876 static struct type
*
7877 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7879 struct objfile
*objfile
= cu
->objfile
;
7880 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7881 struct type
*type
, *range_type
, *index_type
, *char_type
;
7882 struct attribute
*attr
;
7883 unsigned int length
;
7885 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7888 length
= DW_UNSND (attr
);
7892 /* Check for the DW_AT_byte_size attribute. */
7893 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7896 length
= DW_UNSND (attr
);
7904 index_type
= objfile_type (objfile
)->builtin_int
;
7905 range_type
= create_range_type (NULL
, index_type
, 1, length
);
7906 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
7907 type
= create_string_type (NULL
, char_type
, range_type
);
7909 return set_die_type (die
, type
, cu
);
7912 /* Handle DIES due to C code like:
7916 int (*funcp)(int a, long l);
7920 ('funcp' generates a DW_TAG_subroutine_type DIE). */
7922 static struct type
*
7923 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7925 struct type
*type
; /* Type that this function returns. */
7926 struct type
*ftype
; /* Function that returns above type. */
7927 struct attribute
*attr
;
7929 type
= die_type (die
, cu
);
7931 /* The die_type call above may have already set the type for this DIE. */
7932 ftype
= get_die_type (die
, cu
);
7936 ftype
= lookup_function_type (type
);
7938 /* All functions in C++, Pascal and Java have prototypes. */
7939 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
7940 if ((attr
&& (DW_UNSND (attr
) != 0))
7941 || cu
->language
== language_cplus
7942 || cu
->language
== language_java
7943 || cu
->language
== language_pascal
)
7944 TYPE_PROTOTYPED (ftype
) = 1;
7945 else if (producer_is_realview (cu
->producer
))
7946 /* RealView does not emit DW_AT_prototyped. We can not
7947 distinguish prototyped and unprototyped functions; default to
7948 prototyped, since that is more common in modern code (and
7949 RealView warns about unprototyped functions). */
7950 TYPE_PROTOTYPED (ftype
) = 1;
7952 /* Store the calling convention in the type if it's available in
7953 the subroutine die. Otherwise set the calling convention to
7954 the default value DW_CC_normal. */
7955 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
7957 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
7958 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
7959 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
7961 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
7963 /* We need to add the subroutine type to the die immediately so
7964 we don't infinitely recurse when dealing with parameters
7965 declared as the same subroutine type. */
7966 set_die_type (die
, ftype
, cu
);
7968 if (die
->child
!= NULL
)
7970 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
7971 struct die_info
*child_die
;
7972 int nparams
, iparams
;
7974 /* Count the number of parameters.
7975 FIXME: GDB currently ignores vararg functions, but knows about
7976 vararg member functions. */
7978 child_die
= die
->child
;
7979 while (child_die
&& child_die
->tag
)
7981 if (child_die
->tag
== DW_TAG_formal_parameter
)
7983 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
7984 TYPE_VARARGS (ftype
) = 1;
7985 child_die
= sibling_die (child_die
);
7988 /* Allocate storage for parameters and fill them in. */
7989 TYPE_NFIELDS (ftype
) = nparams
;
7990 TYPE_FIELDS (ftype
) = (struct field
*)
7991 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
7993 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7994 even if we error out during the parameters reading below. */
7995 for (iparams
= 0; iparams
< nparams
; iparams
++)
7996 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
7999 child_die
= die
->child
;
8000 while (child_die
&& child_die
->tag
)
8002 if (child_die
->tag
== DW_TAG_formal_parameter
)
8004 struct type
*arg_type
;
8006 /* DWARF version 2 has no clean way to discern C++
8007 static and non-static member functions. G++ helps
8008 GDB by marking the first parameter for non-static
8009 member functions (which is the this pointer) as
8010 artificial. We pass this information to
8011 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8013 DWARF version 3 added DW_AT_object_pointer, which GCC
8014 4.5 does not yet generate. */
8015 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8017 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8020 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8022 /* GCC/43521: In java, the formal parameter
8023 "this" is sometimes not marked with DW_AT_artificial. */
8024 if (cu
->language
== language_java
)
8026 const char *name
= dwarf2_name (child_die
, cu
);
8028 if (name
&& !strcmp (name
, "this"))
8029 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8032 arg_type
= die_type (child_die
, cu
);
8034 /* RealView does not mark THIS as const, which the testsuite
8035 expects. GCC marks THIS as const in method definitions,
8036 but not in the class specifications (GCC PR 43053). */
8037 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8038 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8041 struct dwarf2_cu
*arg_cu
= cu
;
8042 const char *name
= dwarf2_name (child_die
, cu
);
8044 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8047 /* If the compiler emits this, use it. */
8048 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8051 else if (name
&& strcmp (name
, "this") == 0)
8052 /* Function definitions will have the argument names. */
8054 else if (name
== NULL
&& iparams
== 0)
8055 /* Declarations may not have the names, so like
8056 elsewhere in GDB, assume an artificial first
8057 argument is "this". */
8061 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8065 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8068 child_die
= sibling_die (child_die
);
8075 static struct type
*
8076 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8078 struct objfile
*objfile
= cu
->objfile
;
8079 const char *name
= NULL
;
8080 struct type
*this_type
;
8082 name
= dwarf2_full_name (NULL
, die
, cu
);
8083 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8084 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8085 TYPE_NAME (this_type
) = (char *) name
;
8086 set_die_type (die
, this_type
, cu
);
8087 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
8091 /* Find a representation of a given base type and install
8092 it in the TYPE field of the die. */
8094 static struct type
*
8095 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8097 struct objfile
*objfile
= cu
->objfile
;
8099 struct attribute
*attr
;
8100 int encoding
= 0, size
= 0;
8102 enum type_code code
= TYPE_CODE_INT
;
8104 struct type
*target_type
= NULL
;
8106 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8109 encoding
= DW_UNSND (attr
);
8111 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8114 size
= DW_UNSND (attr
);
8116 name
= dwarf2_name (die
, cu
);
8119 complaint (&symfile_complaints
,
8120 _("DW_AT_name missing from DW_TAG_base_type"));
8125 case DW_ATE_address
:
8126 /* Turn DW_ATE_address into a void * pointer. */
8127 code
= TYPE_CODE_PTR
;
8128 type_flags
|= TYPE_FLAG_UNSIGNED
;
8129 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8131 case DW_ATE_boolean
:
8132 code
= TYPE_CODE_BOOL
;
8133 type_flags
|= TYPE_FLAG_UNSIGNED
;
8135 case DW_ATE_complex_float
:
8136 code
= TYPE_CODE_COMPLEX
;
8137 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8139 case DW_ATE_decimal_float
:
8140 code
= TYPE_CODE_DECFLOAT
;
8143 code
= TYPE_CODE_FLT
;
8147 case DW_ATE_unsigned
:
8148 type_flags
|= TYPE_FLAG_UNSIGNED
;
8150 case DW_ATE_signed_char
:
8151 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8152 || cu
->language
== language_pascal
)
8153 code
= TYPE_CODE_CHAR
;
8155 case DW_ATE_unsigned_char
:
8156 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8157 || cu
->language
== language_pascal
)
8158 code
= TYPE_CODE_CHAR
;
8159 type_flags
|= TYPE_FLAG_UNSIGNED
;
8162 /* We just treat this as an integer and then recognize the
8163 type by name elsewhere. */
8167 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8168 dwarf_type_encoding_name (encoding
));
8172 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8173 TYPE_NAME (type
) = name
;
8174 TYPE_TARGET_TYPE (type
) = target_type
;
8176 if (name
&& strcmp (name
, "char") == 0)
8177 TYPE_NOSIGN (type
) = 1;
8179 return set_die_type (die
, type
, cu
);
8182 /* Read the given DW_AT_subrange DIE. */
8184 static struct type
*
8185 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8187 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8188 struct type
*base_type
;
8189 struct type
*range_type
;
8190 struct attribute
*attr
;
8194 LONGEST negative_mask
;
8196 base_type
= die_type (die
, cu
);
8197 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8198 check_typedef (base_type
);
8200 /* The die_type call above may have already set the type for this DIE. */
8201 range_type
= get_die_type (die
, cu
);
8205 if (cu
->language
== language_fortran
)
8207 /* FORTRAN implies a lower bound of 1, if not given. */
8211 /* FIXME: For variable sized arrays either of these could be
8212 a variable rather than a constant value. We'll allow it,
8213 but we don't know how to handle it. */
8214 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8216 low
= dwarf2_get_attr_constant_value (attr
, 0);
8218 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8221 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
8223 /* GCC encodes arrays with unspecified or dynamic length
8224 with a DW_FORM_block1 attribute or a reference attribute.
8225 FIXME: GDB does not yet know how to handle dynamic
8226 arrays properly, treat them as arrays with unspecified
8229 FIXME: jimb/2003-09-22: GDB does not really know
8230 how to handle arrays of unspecified length
8231 either; we just represent them as zero-length
8232 arrays. Choose an appropriate upper bound given
8233 the lower bound we've computed above. */
8237 high
= dwarf2_get_attr_constant_value (attr
, 1);
8241 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8244 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8245 high
= low
+ count
- 1;
8249 /* Unspecified array length. */
8254 /* Dwarf-2 specifications explicitly allows to create subrange types
8255 without specifying a base type.
8256 In that case, the base type must be set to the type of
8257 the lower bound, upper bound or count, in that order, if any of these
8258 three attributes references an object that has a type.
8259 If no base type is found, the Dwarf-2 specifications say that
8260 a signed integer type of size equal to the size of an address should
8262 For the following C code: `extern char gdb_int [];'
8263 GCC produces an empty range DIE.
8264 FIXME: muller/2010-05-28: Possible references to object for low bound,
8265 high bound or count are not yet handled by this code. */
8266 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8268 struct objfile
*objfile
= cu
->objfile
;
8269 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8270 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8271 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8273 /* Test "int", "long int", and "long long int" objfile types,
8274 and select the first one having a size above or equal to the
8275 architecture address size. */
8276 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8277 base_type
= int_type
;
8280 int_type
= objfile_type (objfile
)->builtin_long
;
8281 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8282 base_type
= int_type
;
8285 int_type
= objfile_type (objfile
)->builtin_long_long
;
8286 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8287 base_type
= int_type
;
8293 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8294 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8295 low
|= negative_mask
;
8296 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8297 high
|= negative_mask
;
8299 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8301 /* Mark arrays with dynamic length at least as an array of unspecified
8302 length. GDB could check the boundary but before it gets implemented at
8303 least allow accessing the array elements. */
8304 if (attr
&& attr
->form
== DW_FORM_block1
)
8305 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8307 /* Ada expects an empty array on no boundary attributes. */
8308 if (attr
== NULL
&& cu
->language
!= language_ada
)
8309 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8311 name
= dwarf2_name (die
, cu
);
8313 TYPE_NAME (range_type
) = name
;
8315 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8317 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8319 set_die_type (die
, range_type
, cu
);
8321 /* set_die_type should be already done. */
8322 set_descriptive_type (range_type
, die
, cu
);
8327 static struct type
*
8328 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8332 /* For now, we only support the C meaning of an unspecified type: void. */
8334 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8335 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8337 return set_die_type (die
, type
, cu
);
8340 /* Trivial hash function for die_info: the hash value of a DIE
8341 is its offset in .debug_info for this objfile. */
8344 die_hash (const void *item
)
8346 const struct die_info
*die
= item
;
8351 /* Trivial comparison function for die_info structures: two DIEs
8352 are equal if they have the same offset. */
8355 die_eq (const void *item_lhs
, const void *item_rhs
)
8357 const struct die_info
*die_lhs
= item_lhs
;
8358 const struct die_info
*die_rhs
= item_rhs
;
8360 return die_lhs
->offset
== die_rhs
->offset
;
8363 /* Read a whole compilation unit into a linked list of dies. */
8365 static struct die_info
*
8366 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8368 struct die_reader_specs reader_specs
;
8369 int read_abbrevs
= 0;
8370 struct cleanup
*back_to
= NULL
;
8371 struct die_info
*die
;
8373 if (cu
->dwarf2_abbrevs
== NULL
)
8375 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8376 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8380 gdb_assert (cu
->die_hash
== NULL
);
8382 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8386 &cu
->comp_unit_obstack
,
8387 hashtab_obstack_allocate
,
8388 dummy_obstack_deallocate
);
8390 init_cu_die_reader (&reader_specs
, cu
);
8392 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8395 do_cleanups (back_to
);
8400 /* Main entry point for reading a DIE and all children.
8401 Read the DIE and dump it if requested. */
8403 static struct die_info
*
8404 read_die_and_children (const struct die_reader_specs
*reader
,
8406 gdb_byte
**new_info_ptr
,
8407 struct die_info
*parent
)
8409 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8410 new_info_ptr
, parent
);
8412 if (dwarf2_die_debug
)
8414 fprintf_unfiltered (gdb_stdlog
,
8415 "\nRead die from %s of %s:\n",
8416 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8418 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8420 : "unknown section",
8421 reader
->abfd
->filename
);
8422 dump_die (result
, dwarf2_die_debug
);
8428 /* Read a single die and all its descendents. Set the die's sibling
8429 field to NULL; set other fields in the die correctly, and set all
8430 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8431 location of the info_ptr after reading all of those dies. PARENT
8432 is the parent of the die in question. */
8434 static struct die_info
*
8435 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8437 gdb_byte
**new_info_ptr
,
8438 struct die_info
*parent
)
8440 struct die_info
*die
;
8444 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8447 *new_info_ptr
= cur_ptr
;
8450 store_in_ref_table (die
, reader
->cu
);
8453 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8457 *new_info_ptr
= cur_ptr
;
8460 die
->sibling
= NULL
;
8461 die
->parent
= parent
;
8465 /* Read a die, all of its descendents, and all of its siblings; set
8466 all of the fields of all of the dies correctly. Arguments are as
8467 in read_die_and_children. */
8469 static struct die_info
*
8470 read_die_and_siblings (const struct die_reader_specs
*reader
,
8472 gdb_byte
**new_info_ptr
,
8473 struct die_info
*parent
)
8475 struct die_info
*first_die
, *last_sibling
;
8479 first_die
= last_sibling
= NULL
;
8483 struct die_info
*die
8484 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8488 *new_info_ptr
= cur_ptr
;
8495 last_sibling
->sibling
= die
;
8501 /* Read the die from the .debug_info section buffer. Set DIEP to
8502 point to a newly allocated die with its information, except for its
8503 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8504 whether the die has children or not. */
8507 read_full_die (const struct die_reader_specs
*reader
,
8508 struct die_info
**diep
, gdb_byte
*info_ptr
,
8511 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8512 struct abbrev_info
*abbrev
;
8513 struct die_info
*die
;
8514 struct dwarf2_cu
*cu
= reader
->cu
;
8515 bfd
*abfd
= reader
->abfd
;
8517 offset
= info_ptr
- reader
->buffer
;
8518 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8519 info_ptr
+= bytes_read
;
8527 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8529 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8531 bfd_get_filename (abfd
));
8533 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8534 die
->offset
= offset
;
8535 die
->tag
= abbrev
->tag
;
8536 die
->abbrev
= abbrev_number
;
8538 die
->num_attrs
= abbrev
->num_attrs
;
8540 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8541 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8542 abfd
, info_ptr
, cu
);
8545 *has_children
= abbrev
->has_children
;
8549 /* In DWARF version 2, the description of the debugging information is
8550 stored in a separate .debug_abbrev section. Before we read any
8551 dies from a section we read in all abbreviations and install them
8552 in a hash table. This function also sets flags in CU describing
8553 the data found in the abbrev table. */
8556 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8558 struct comp_unit_head
*cu_header
= &cu
->header
;
8559 gdb_byte
*abbrev_ptr
;
8560 struct abbrev_info
*cur_abbrev
;
8561 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8562 unsigned int abbrev_form
, hash_number
;
8563 struct attr_abbrev
*cur_attrs
;
8564 unsigned int allocated_attrs
;
8566 /* Initialize dwarf2 abbrevs. */
8567 obstack_init (&cu
->abbrev_obstack
);
8568 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8570 * sizeof (struct abbrev_info
*)));
8571 memset (cu
->dwarf2_abbrevs
, 0,
8572 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8574 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8575 &dwarf2_per_objfile
->abbrev
);
8576 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8577 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8578 abbrev_ptr
+= bytes_read
;
8580 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8581 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8583 /* Loop until we reach an abbrev number of 0. */
8584 while (abbrev_number
)
8586 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8588 /* read in abbrev header */
8589 cur_abbrev
->number
= abbrev_number
;
8590 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8591 abbrev_ptr
+= bytes_read
;
8592 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8595 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8596 cu
->has_namespace_info
= 1;
8598 /* now read in declarations */
8599 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8600 abbrev_ptr
+= bytes_read
;
8601 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8602 abbrev_ptr
+= bytes_read
;
8605 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8607 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8609 = xrealloc (cur_attrs
, (allocated_attrs
8610 * sizeof (struct attr_abbrev
)));
8613 /* Record whether this compilation unit might have
8614 inter-compilation-unit references. If we don't know what form
8615 this attribute will have, then it might potentially be a
8616 DW_FORM_ref_addr, so we conservatively expect inter-CU
8619 if (abbrev_form
== DW_FORM_ref_addr
8620 || abbrev_form
== DW_FORM_indirect
)
8621 cu
->has_form_ref_addr
= 1;
8623 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8624 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8625 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8626 abbrev_ptr
+= bytes_read
;
8627 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8628 abbrev_ptr
+= bytes_read
;
8631 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8632 (cur_abbrev
->num_attrs
8633 * sizeof (struct attr_abbrev
)));
8634 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8635 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8637 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8638 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8639 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8641 /* Get next abbreviation.
8642 Under Irix6 the abbreviations for a compilation unit are not
8643 always properly terminated with an abbrev number of 0.
8644 Exit loop if we encounter an abbreviation which we have
8645 already read (which means we are about to read the abbreviations
8646 for the next compile unit) or if the end of the abbreviation
8647 table is reached. */
8648 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8649 >= dwarf2_per_objfile
->abbrev
.size
)
8651 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8652 abbrev_ptr
+= bytes_read
;
8653 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
8660 /* Release the memory used by the abbrev table for a compilation unit. */
8663 dwarf2_free_abbrev_table (void *ptr_to_cu
)
8665 struct dwarf2_cu
*cu
= ptr_to_cu
;
8667 obstack_free (&cu
->abbrev_obstack
, NULL
);
8668 cu
->dwarf2_abbrevs
= NULL
;
8671 /* Lookup an abbrev_info structure in the abbrev hash table. */
8673 static struct abbrev_info
*
8674 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
8676 unsigned int hash_number
;
8677 struct abbrev_info
*abbrev
;
8679 hash_number
= number
% ABBREV_HASH_SIZE
;
8680 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
8684 if (abbrev
->number
== number
)
8687 abbrev
= abbrev
->next
;
8692 /* Returns nonzero if TAG represents a type that we might generate a partial
8696 is_type_tag_for_partial (int tag
)
8701 /* Some types that would be reasonable to generate partial symbols for,
8702 that we don't at present. */
8703 case DW_TAG_array_type
:
8704 case DW_TAG_file_type
:
8705 case DW_TAG_ptr_to_member_type
:
8706 case DW_TAG_set_type
:
8707 case DW_TAG_string_type
:
8708 case DW_TAG_subroutine_type
:
8710 case DW_TAG_base_type
:
8711 case DW_TAG_class_type
:
8712 case DW_TAG_interface_type
:
8713 case DW_TAG_enumeration_type
:
8714 case DW_TAG_structure_type
:
8715 case DW_TAG_subrange_type
:
8716 case DW_TAG_typedef
:
8717 case DW_TAG_union_type
:
8724 /* Load all DIEs that are interesting for partial symbols into memory. */
8726 static struct partial_die_info
*
8727 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8728 int building_psymtab
, struct dwarf2_cu
*cu
)
8730 struct partial_die_info
*part_die
;
8731 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
8732 struct abbrev_info
*abbrev
;
8733 unsigned int bytes_read
;
8734 unsigned int load_all
= 0;
8736 int nesting_level
= 1;
8741 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
8745 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8749 &cu
->comp_unit_obstack
,
8750 hashtab_obstack_allocate
,
8751 dummy_obstack_deallocate
);
8753 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8754 sizeof (struct partial_die_info
));
8758 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
8760 /* A NULL abbrev means the end of a series of children. */
8763 if (--nesting_level
== 0)
8765 /* PART_DIE was probably the last thing allocated on the
8766 comp_unit_obstack, so we could call obstack_free
8767 here. We don't do that because the waste is small,
8768 and will be cleaned up when we're done with this
8769 compilation unit. This way, we're also more robust
8770 against other users of the comp_unit_obstack. */
8773 info_ptr
+= bytes_read
;
8774 last_die
= parent_die
;
8775 parent_die
= parent_die
->die_parent
;
8779 /* Check for template arguments. We never save these; if
8780 they're seen, we just mark the parent, and go on our way. */
8781 if (parent_die
!= NULL
8782 && cu
->language
== language_cplus
8783 && (abbrev
->tag
== DW_TAG_template_type_param
8784 || abbrev
->tag
== DW_TAG_template_value_param
))
8786 parent_die
->has_template_arguments
= 1;
8790 /* We don't need a partial DIE for the template argument. */
8791 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
8797 /* We only recurse into subprograms looking for template arguments.
8798 Skip their other children. */
8800 && cu
->language
== language_cplus
8801 && parent_die
!= NULL
8802 && parent_die
->tag
== DW_TAG_subprogram
)
8804 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8808 /* Check whether this DIE is interesting enough to save. Normally
8809 we would not be interested in members here, but there may be
8810 later variables referencing them via DW_AT_specification (for
8813 && !is_type_tag_for_partial (abbrev
->tag
)
8814 && abbrev
->tag
!= DW_TAG_constant
8815 && abbrev
->tag
!= DW_TAG_enumerator
8816 && abbrev
->tag
!= DW_TAG_subprogram
8817 && abbrev
->tag
!= DW_TAG_lexical_block
8818 && abbrev
->tag
!= DW_TAG_variable
8819 && abbrev
->tag
!= DW_TAG_namespace
8820 && abbrev
->tag
!= DW_TAG_module
8821 && abbrev
->tag
!= DW_TAG_member
)
8823 /* Otherwise we skip to the next sibling, if any. */
8824 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8828 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
8829 buffer
, info_ptr
, cu
);
8831 /* This two-pass algorithm for processing partial symbols has a
8832 high cost in cache pressure. Thus, handle some simple cases
8833 here which cover the majority of C partial symbols. DIEs
8834 which neither have specification tags in them, nor could have
8835 specification tags elsewhere pointing at them, can simply be
8836 processed and discarded.
8838 This segment is also optional; scan_partial_symbols and
8839 add_partial_symbol will handle these DIEs if we chain
8840 them in normally. When compilers which do not emit large
8841 quantities of duplicate debug information are more common,
8842 this code can probably be removed. */
8844 /* Any complete simple types at the top level (pretty much all
8845 of them, for a language without namespaces), can be processed
8847 if (parent_die
== NULL
8848 && part_die
->has_specification
== 0
8849 && part_die
->is_declaration
== 0
8850 && (part_die
->tag
== DW_TAG_typedef
8851 || part_die
->tag
== DW_TAG_base_type
8852 || part_die
->tag
== DW_TAG_subrange_type
))
8854 if (building_psymtab
&& part_die
->name
!= NULL
)
8855 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8856 VAR_DOMAIN
, LOC_TYPEDEF
,
8857 &cu
->objfile
->static_psymbols
,
8858 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8859 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8863 /* If we're at the second level, and we're an enumerator, and
8864 our parent has no specification (meaning possibly lives in a
8865 namespace elsewhere), then we can add the partial symbol now
8866 instead of queueing it. */
8867 if (part_die
->tag
== DW_TAG_enumerator
8868 && parent_die
!= NULL
8869 && parent_die
->die_parent
== NULL
8870 && parent_die
->tag
== DW_TAG_enumeration_type
8871 && parent_die
->has_specification
== 0)
8873 if (part_die
->name
== NULL
)
8874 complaint (&symfile_complaints
,
8875 _("malformed enumerator DIE ignored"));
8876 else if (building_psymtab
)
8877 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8878 VAR_DOMAIN
, LOC_CONST
,
8879 (cu
->language
== language_cplus
8880 || cu
->language
== language_java
)
8881 ? &cu
->objfile
->global_psymbols
8882 : &cu
->objfile
->static_psymbols
,
8883 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8885 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8889 /* We'll save this DIE so link it in. */
8890 part_die
->die_parent
= parent_die
;
8891 part_die
->die_sibling
= NULL
;
8892 part_die
->die_child
= NULL
;
8894 if (last_die
&& last_die
== parent_die
)
8895 last_die
->die_child
= part_die
;
8897 last_die
->die_sibling
= part_die
;
8899 last_die
= part_die
;
8901 if (first_die
== NULL
)
8902 first_die
= part_die
;
8904 /* Maybe add the DIE to the hash table. Not all DIEs that we
8905 find interesting need to be in the hash table, because we
8906 also have the parent/sibling/child chains; only those that we
8907 might refer to by offset later during partial symbol reading.
8909 For now this means things that might have be the target of a
8910 DW_AT_specification, DW_AT_abstract_origin, or
8911 DW_AT_extension. DW_AT_extension will refer only to
8912 namespaces; DW_AT_abstract_origin refers to functions (and
8913 many things under the function DIE, but we do not recurse
8914 into function DIEs during partial symbol reading) and
8915 possibly variables as well; DW_AT_specification refers to
8916 declarations. Declarations ought to have the DW_AT_declaration
8917 flag. It happens that GCC forgets to put it in sometimes, but
8918 only for functions, not for types.
8920 Adding more things than necessary to the hash table is harmless
8921 except for the performance cost. Adding too few will result in
8922 wasted time in find_partial_die, when we reread the compilation
8923 unit with load_all_dies set. */
8926 || abbrev
->tag
== DW_TAG_constant
8927 || abbrev
->tag
== DW_TAG_subprogram
8928 || abbrev
->tag
== DW_TAG_variable
8929 || abbrev
->tag
== DW_TAG_namespace
8930 || part_die
->is_declaration
)
8934 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
8935 part_die
->offset
, INSERT
);
8939 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8940 sizeof (struct partial_die_info
));
8942 /* For some DIEs we want to follow their children (if any). For C
8943 we have no reason to follow the children of structures; for other
8944 languages we have to, so that we can get at method physnames
8945 to infer fully qualified class names, for DW_AT_specification,
8946 and for C++ template arguments. For C++, we also look one level
8947 inside functions to find template arguments (if the name of the
8948 function does not already contain the template arguments).
8950 For Ada, we need to scan the children of subprograms and lexical
8951 blocks as well because Ada allows the definition of nested
8952 entities that could be interesting for the debugger, such as
8953 nested subprograms for instance. */
8954 if (last_die
->has_children
8956 || last_die
->tag
== DW_TAG_namespace
8957 || last_die
->tag
== DW_TAG_module
8958 || last_die
->tag
== DW_TAG_enumeration_type
8959 || (cu
->language
== language_cplus
8960 && last_die
->tag
== DW_TAG_subprogram
8961 && (last_die
->name
== NULL
8962 || strchr (last_die
->name
, '<') == NULL
))
8963 || (cu
->language
!= language_c
8964 && (last_die
->tag
== DW_TAG_class_type
8965 || last_die
->tag
== DW_TAG_interface_type
8966 || last_die
->tag
== DW_TAG_structure_type
8967 || last_die
->tag
== DW_TAG_union_type
))
8968 || (cu
->language
== language_ada
8969 && (last_die
->tag
== DW_TAG_subprogram
8970 || last_die
->tag
== DW_TAG_lexical_block
))))
8973 parent_die
= last_die
;
8977 /* Otherwise we skip to the next sibling, if any. */
8978 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
8980 /* Back to the top, do it again. */
8984 /* Read a minimal amount of information into the minimal die structure. */
8987 read_partial_die (struct partial_die_info
*part_die
,
8988 struct abbrev_info
*abbrev
,
8989 unsigned int abbrev_len
, bfd
*abfd
,
8990 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8991 struct dwarf2_cu
*cu
)
8994 struct attribute attr
;
8995 int has_low_pc_attr
= 0;
8996 int has_high_pc_attr
= 0;
8998 memset (part_die
, 0, sizeof (struct partial_die_info
));
9000 part_die
->offset
= info_ptr
- buffer
;
9002 info_ptr
+= abbrev_len
;
9007 part_die
->tag
= abbrev
->tag
;
9008 part_die
->has_children
= abbrev
->has_children
;
9010 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9012 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9014 /* Store the data if it is of an attribute we want to keep in a
9015 partial symbol table. */
9019 switch (part_die
->tag
)
9021 case DW_TAG_compile_unit
:
9022 case DW_TAG_type_unit
:
9023 /* Compilation units have a DW_AT_name that is a filename, not
9024 a source language identifier. */
9025 case DW_TAG_enumeration_type
:
9026 case DW_TAG_enumerator
:
9027 /* These tags always have simple identifiers already; no need
9028 to canonicalize them. */
9029 part_die
->name
= DW_STRING (&attr
);
9033 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9034 &cu
->objfile
->objfile_obstack
);
9038 case DW_AT_linkage_name
:
9039 case DW_AT_MIPS_linkage_name
:
9040 /* Note that both forms of linkage name might appear. We
9041 assume they will be the same, and we only store the last
9043 if (cu
->language
== language_ada
)
9044 part_die
->name
= DW_STRING (&attr
);
9045 part_die
->linkage_name
= DW_STRING (&attr
);
9048 has_low_pc_attr
= 1;
9049 part_die
->lowpc
= DW_ADDR (&attr
);
9052 has_high_pc_attr
= 1;
9053 part_die
->highpc
= DW_ADDR (&attr
);
9055 case DW_AT_location
:
9056 /* Support the .debug_loc offsets. */
9057 if (attr_form_is_block (&attr
))
9059 part_die
->locdesc
= DW_BLOCK (&attr
);
9061 else if (attr_form_is_section_offset (&attr
))
9063 dwarf2_complex_location_expr_complaint ();
9067 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9068 "partial symbol information");
9071 case DW_AT_external
:
9072 part_die
->is_external
= DW_UNSND (&attr
);
9074 case DW_AT_declaration
:
9075 part_die
->is_declaration
= DW_UNSND (&attr
);
9078 part_die
->has_type
= 1;
9080 case DW_AT_abstract_origin
:
9081 case DW_AT_specification
:
9082 case DW_AT_extension
:
9083 part_die
->has_specification
= 1;
9084 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9087 /* Ignore absolute siblings, they might point outside of
9088 the current compile unit. */
9089 if (attr
.form
== DW_FORM_ref_addr
)
9090 complaint (&symfile_complaints
,
9091 _("ignoring absolute DW_AT_sibling"));
9093 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9095 case DW_AT_byte_size
:
9096 part_die
->has_byte_size
= 1;
9098 case DW_AT_calling_convention
:
9099 /* DWARF doesn't provide a way to identify a program's source-level
9100 entry point. DW_AT_calling_convention attributes are only meant
9101 to describe functions' calling conventions.
9103 However, because it's a necessary piece of information in
9104 Fortran, and because DW_CC_program is the only piece of debugging
9105 information whose definition refers to a 'main program' at all,
9106 several compilers have begun marking Fortran main programs with
9107 DW_CC_program --- even when those functions use the standard
9108 calling conventions.
9110 So until DWARF specifies a way to provide this information and
9111 compilers pick up the new representation, we'll support this
9113 if (DW_UNSND (&attr
) == DW_CC_program
9114 && cu
->language
== language_fortran
)
9116 set_main_name (part_die
->name
);
9118 /* As this DIE has a static linkage the name would be difficult
9119 to look up later. */
9120 language_of_main
= language_fortran
;
9128 /* When using the GNU linker, .gnu.linkonce. sections are used to
9129 eliminate duplicate copies of functions and vtables and such.
9130 The linker will arbitrarily choose one and discard the others.
9131 The AT_*_pc values for such functions refer to local labels in
9132 these sections. If the section from that file was discarded, the
9133 labels are not in the output, so the relocs get a value of 0.
9134 If this is a discarded function, mark the pc bounds as invalid,
9135 so that GDB will ignore it. */
9136 if (has_low_pc_attr
&& has_high_pc_attr
9137 && part_die
->lowpc
< part_die
->highpc
9138 && (part_die
->lowpc
!= 0
9139 || dwarf2_per_objfile
->has_section_at_zero
))
9140 part_die
->has_pc_info
= 1;
9145 /* Find a cached partial DIE at OFFSET in CU. */
9147 static struct partial_die_info
*
9148 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9150 struct partial_die_info
*lookup_die
= NULL
;
9151 struct partial_die_info part_die
;
9153 part_die
.offset
= offset
;
9154 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9159 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9160 except in the case of .debug_types DIEs which do not reference
9161 outside their CU (they do however referencing other types via
9164 static struct partial_die_info
*
9165 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9167 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9168 struct partial_die_info
*pd
= NULL
;
9170 if (cu
->per_cu
->from_debug_types
)
9172 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9178 if (offset_in_cu_p (&cu
->header
, offset
))
9180 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9185 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9187 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9188 load_partial_comp_unit (per_cu
, cu
->objfile
);
9190 per_cu
->cu
->last_used
= 0;
9191 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9193 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9195 struct cleanup
*back_to
;
9196 struct partial_die_info comp_unit_die
;
9197 struct abbrev_info
*abbrev
;
9198 unsigned int bytes_read
;
9201 per_cu
->load_all_dies
= 1;
9203 /* Re-read the DIEs. */
9204 back_to
= make_cleanup (null_cleanup
, 0);
9205 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9207 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
9208 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9210 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9211 + per_cu
->cu
->header
.offset
9212 + per_cu
->cu
->header
.first_die_offset
);
9213 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9214 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9215 per_cu
->cu
->objfile
->obfd
,
9216 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9218 if (comp_unit_die
.has_children
)
9219 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
9220 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9222 do_cleanups (back_to
);
9224 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9230 internal_error (__FILE__
, __LINE__
,
9231 _("could not find partial DIE 0x%x "
9232 "in cache [from module %s]\n"),
9233 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9237 /* See if we can figure out if the class lives in a namespace. We do
9238 this by looking for a member function; its demangled name will
9239 contain namespace info, if there is any. */
9242 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9243 struct dwarf2_cu
*cu
)
9245 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9246 what template types look like, because the demangler
9247 frequently doesn't give the same name as the debug info. We
9248 could fix this by only using the demangled name to get the
9249 prefix (but see comment in read_structure_type). */
9251 struct partial_die_info
*real_pdi
;
9252 struct partial_die_info
*child_pdi
;
9254 /* If this DIE (this DIE's specification, if any) has a parent, then
9255 we should not do this. We'll prepend the parent's fully qualified
9256 name when we create the partial symbol. */
9258 real_pdi
= struct_pdi
;
9259 while (real_pdi
->has_specification
)
9260 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9262 if (real_pdi
->die_parent
!= NULL
)
9265 for (child_pdi
= struct_pdi
->die_child
;
9267 child_pdi
= child_pdi
->die_sibling
)
9269 if (child_pdi
->tag
== DW_TAG_subprogram
9270 && child_pdi
->linkage_name
!= NULL
)
9272 char *actual_class_name
9273 = language_class_name_from_physname (cu
->language_defn
,
9274 child_pdi
->linkage_name
);
9275 if (actual_class_name
!= NULL
)
9278 = obsavestring (actual_class_name
,
9279 strlen (actual_class_name
),
9280 &cu
->objfile
->objfile_obstack
);
9281 xfree (actual_class_name
);
9288 /* Adjust PART_DIE before generating a symbol for it. This function
9289 may set the is_external flag or change the DIE's name. */
9292 fixup_partial_die (struct partial_die_info
*part_die
,
9293 struct dwarf2_cu
*cu
)
9295 /* Once we've fixed up a die, there's no point in doing so again.
9296 This also avoids a memory leak if we were to call
9297 guess_partial_die_structure_name multiple times. */
9298 if (part_die
->fixup_called
)
9301 /* If we found a reference attribute and the DIE has no name, try
9302 to find a name in the referred to DIE. */
9304 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9306 struct partial_die_info
*spec_die
;
9308 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9310 fixup_partial_die (spec_die
, cu
);
9314 part_die
->name
= spec_die
->name
;
9316 /* Copy DW_AT_external attribute if it is set. */
9317 if (spec_die
->is_external
)
9318 part_die
->is_external
= spec_die
->is_external
;
9322 /* Set default names for some unnamed DIEs. */
9324 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9325 part_die
->name
= "(anonymous namespace)";
9327 /* If there is no parent die to provide a namespace, and there are
9328 children, see if we can determine the namespace from their linkage
9330 NOTE: We need to do this even if cu->has_namespace_info != 0.
9331 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9332 if (cu
->language
== language_cplus
9333 && dwarf2_per_objfile
->types
.asection
!= NULL
9334 && part_die
->die_parent
== NULL
9335 && part_die
->has_children
9336 && (part_die
->tag
== DW_TAG_class_type
9337 || part_die
->tag
== DW_TAG_structure_type
9338 || part_die
->tag
== DW_TAG_union_type
))
9339 guess_partial_die_structure_name (part_die
, cu
);
9341 part_die
->fixup_called
= 1;
9344 /* Read an attribute value described by an attribute form. */
9347 read_attribute_value (struct attribute
*attr
, unsigned form
,
9348 bfd
*abfd
, gdb_byte
*info_ptr
,
9349 struct dwarf2_cu
*cu
)
9351 struct comp_unit_head
*cu_header
= &cu
->header
;
9352 unsigned int bytes_read
;
9353 struct dwarf_block
*blk
;
9358 case DW_FORM_ref_addr
:
9359 if (cu
->header
.version
== 2)
9360 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9362 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
9363 &cu
->header
, &bytes_read
);
9364 info_ptr
+= bytes_read
;
9367 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9368 info_ptr
+= bytes_read
;
9370 case DW_FORM_block2
:
9371 blk
= dwarf_alloc_block (cu
);
9372 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9374 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9375 info_ptr
+= blk
->size
;
9376 DW_BLOCK (attr
) = blk
;
9378 case DW_FORM_block4
:
9379 blk
= dwarf_alloc_block (cu
);
9380 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9382 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9383 info_ptr
+= blk
->size
;
9384 DW_BLOCK (attr
) = blk
;
9387 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9391 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9395 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9398 case DW_FORM_sec_offset
:
9399 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9400 info_ptr
+= bytes_read
;
9402 case DW_FORM_string
:
9403 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9404 DW_STRING_IS_CANONICAL (attr
) = 0;
9405 info_ptr
+= bytes_read
;
9408 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9410 DW_STRING_IS_CANONICAL (attr
) = 0;
9411 info_ptr
+= bytes_read
;
9413 case DW_FORM_exprloc
:
9415 blk
= dwarf_alloc_block (cu
);
9416 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9417 info_ptr
+= bytes_read
;
9418 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9419 info_ptr
+= blk
->size
;
9420 DW_BLOCK (attr
) = blk
;
9422 case DW_FORM_block1
:
9423 blk
= dwarf_alloc_block (cu
);
9424 blk
->size
= read_1_byte (abfd
, info_ptr
);
9426 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9427 info_ptr
+= blk
->size
;
9428 DW_BLOCK (attr
) = blk
;
9431 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9435 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9438 case DW_FORM_flag_present
:
9439 DW_UNSND (attr
) = 1;
9442 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9443 info_ptr
+= bytes_read
;
9446 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9447 info_ptr
+= bytes_read
;
9450 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9454 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9458 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9462 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9466 /* Convert the signature to something we can record in DW_UNSND
9468 NOTE: This is NULL if the type wasn't found. */
9469 DW_SIGNATURED_TYPE (attr
) =
9470 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9473 case DW_FORM_ref_udata
:
9474 DW_ADDR (attr
) = (cu
->header
.offset
9475 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9476 info_ptr
+= bytes_read
;
9478 case DW_FORM_indirect
:
9479 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9480 info_ptr
+= bytes_read
;
9481 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9484 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9485 dwarf_form_name (form
),
9486 bfd_get_filename (abfd
));
9489 /* We have seen instances where the compiler tried to emit a byte
9490 size attribute of -1 which ended up being encoded as an unsigned
9491 0xffffffff. Although 0xffffffff is technically a valid size value,
9492 an object of this size seems pretty unlikely so we can relatively
9493 safely treat these cases as if the size attribute was invalid and
9494 treat them as zero by default. */
9495 if (attr
->name
== DW_AT_byte_size
9496 && form
== DW_FORM_data4
9497 && DW_UNSND (attr
) >= 0xffffffff)
9500 (&symfile_complaints
,
9501 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9502 hex_string (DW_UNSND (attr
)));
9503 DW_UNSND (attr
) = 0;
9509 /* Read an attribute described by an abbreviated attribute. */
9512 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9513 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9515 attr
->name
= abbrev
->name
;
9516 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9519 /* Read dwarf information from a buffer. */
9522 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9524 return bfd_get_8 (abfd
, buf
);
9528 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9530 return bfd_get_signed_8 (abfd
, buf
);
9534 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9536 return bfd_get_16 (abfd
, buf
);
9540 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9542 return bfd_get_signed_16 (abfd
, buf
);
9546 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9548 return bfd_get_32 (abfd
, buf
);
9552 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9554 return bfd_get_signed_32 (abfd
, buf
);
9558 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9560 return bfd_get_64 (abfd
, buf
);
9564 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9565 unsigned int *bytes_read
)
9567 struct comp_unit_head
*cu_header
= &cu
->header
;
9568 CORE_ADDR retval
= 0;
9570 if (cu_header
->signed_addr_p
)
9572 switch (cu_header
->addr_size
)
9575 retval
= bfd_get_signed_16 (abfd
, buf
);
9578 retval
= bfd_get_signed_32 (abfd
, buf
);
9581 retval
= bfd_get_signed_64 (abfd
, buf
);
9584 internal_error (__FILE__
, __LINE__
,
9585 _("read_address: bad switch, signed [in module %s]"),
9586 bfd_get_filename (abfd
));
9591 switch (cu_header
->addr_size
)
9594 retval
= bfd_get_16 (abfd
, buf
);
9597 retval
= bfd_get_32 (abfd
, buf
);
9600 retval
= bfd_get_64 (abfd
, buf
);
9603 internal_error (__FILE__
, __LINE__
,
9604 _("read_address: bad switch, "
9605 "unsigned [in module %s]"),
9606 bfd_get_filename (abfd
));
9610 *bytes_read
= cu_header
->addr_size
;
9614 /* Read the initial length from a section. The (draft) DWARF 3
9615 specification allows the initial length to take up either 4 bytes
9616 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9617 bytes describe the length and all offsets will be 8 bytes in length
9620 An older, non-standard 64-bit format is also handled by this
9621 function. The older format in question stores the initial length
9622 as an 8-byte quantity without an escape value. Lengths greater
9623 than 2^32 aren't very common which means that the initial 4 bytes
9624 is almost always zero. Since a length value of zero doesn't make
9625 sense for the 32-bit format, this initial zero can be considered to
9626 be an escape value which indicates the presence of the older 64-bit
9627 format. As written, the code can't detect (old format) lengths
9628 greater than 4GB. If it becomes necessary to handle lengths
9629 somewhat larger than 4GB, we could allow other small values (such
9630 as the non-sensical values of 1, 2, and 3) to also be used as
9631 escape values indicating the presence of the old format.
9633 The value returned via bytes_read should be used to increment the
9634 relevant pointer after calling read_initial_length().
9636 [ Note: read_initial_length() and read_offset() are based on the
9637 document entitled "DWARF Debugging Information Format", revision
9638 3, draft 8, dated November 19, 2001. This document was obtained
9641 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9643 This document is only a draft and is subject to change. (So beware.)
9645 Details regarding the older, non-standard 64-bit format were
9646 determined empirically by examining 64-bit ELF files produced by
9647 the SGI toolchain on an IRIX 6.5 machine.
9649 - Kevin, July 16, 2002
9653 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
9655 LONGEST length
= bfd_get_32 (abfd
, buf
);
9657 if (length
== 0xffffffff)
9659 length
= bfd_get_64 (abfd
, buf
+ 4);
9662 else if (length
== 0)
9664 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9665 length
= bfd_get_64 (abfd
, buf
);
9676 /* Cover function for read_initial_length.
9677 Returns the length of the object at BUF, and stores the size of the
9678 initial length in *BYTES_READ and stores the size that offsets will be in
9680 If the initial length size is not equivalent to that specified in
9681 CU_HEADER then issue a complaint.
9682 This is useful when reading non-comp-unit headers. */
9685 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
9686 const struct comp_unit_head
*cu_header
,
9687 unsigned int *bytes_read
,
9688 unsigned int *offset_size
)
9690 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
9692 gdb_assert (cu_header
->initial_length_size
== 4
9693 || cu_header
->initial_length_size
== 8
9694 || cu_header
->initial_length_size
== 12);
9696 if (cu_header
->initial_length_size
!= *bytes_read
)
9697 complaint (&symfile_complaints
,
9698 _("intermixed 32-bit and 64-bit DWARF sections"));
9700 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
9704 /* Read an offset from the data stream. The size of the offset is
9705 given by cu_header->offset_size. */
9708 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
9709 unsigned int *bytes_read
)
9711 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
9713 *bytes_read
= cu_header
->offset_size
;
9717 /* Read an offset from the data stream. */
9720 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
9724 switch (offset_size
)
9727 retval
= bfd_get_32 (abfd
, buf
);
9730 retval
= bfd_get_64 (abfd
, buf
);
9733 internal_error (__FILE__
, __LINE__
,
9734 _("read_offset_1: bad switch [in module %s]"),
9735 bfd_get_filename (abfd
));
9742 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
9744 /* If the size of a host char is 8 bits, we can return a pointer
9745 to the buffer, otherwise we have to copy the data to a buffer
9746 allocated on the temporary obstack. */
9747 gdb_assert (HOST_CHAR_BIT
== 8);
9752 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9754 /* If the size of a host char is 8 bits, we can return a pointer
9755 to the string, otherwise we have to copy the string to a buffer
9756 allocated on the temporary obstack. */
9757 gdb_assert (HOST_CHAR_BIT
== 8);
9760 *bytes_read_ptr
= 1;
9763 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
9764 return (char *) buf
;
9768 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
9769 const struct comp_unit_head
*cu_header
,
9770 unsigned int *bytes_read_ptr
)
9772 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
9774 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
9775 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
9777 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9778 bfd_get_filename (abfd
));
9781 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
9783 error (_("DW_FORM_strp pointing outside of "
9784 ".debug_str section [in module %s]"),
9785 bfd_get_filename (abfd
));
9788 gdb_assert (HOST_CHAR_BIT
== 8);
9789 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
9791 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
9794 static unsigned long
9795 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9797 unsigned long result
;
9798 unsigned int num_read
;
9808 byte
= bfd_get_8 (abfd
, buf
);
9811 result
|= ((unsigned long)(byte
& 127) << shift
);
9812 if ((byte
& 128) == 0)
9818 *bytes_read_ptr
= num_read
;
9823 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9826 int i
, shift
, num_read
;
9835 byte
= bfd_get_8 (abfd
, buf
);
9838 result
|= ((long)(byte
& 127) << shift
);
9840 if ((byte
& 128) == 0)
9845 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
9846 result
|= -(((long)1) << shift
);
9847 *bytes_read_ptr
= num_read
;
9851 /* Return a pointer to just past the end of an LEB128 number in BUF. */
9854 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
9860 byte
= bfd_get_8 (abfd
, buf
);
9862 if ((byte
& 128) == 0)
9868 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
9875 cu
->language
= language_c
;
9877 case DW_LANG_C_plus_plus
:
9878 cu
->language
= language_cplus
;
9881 cu
->language
= language_d
;
9883 case DW_LANG_Fortran77
:
9884 case DW_LANG_Fortran90
:
9885 case DW_LANG_Fortran95
:
9886 cu
->language
= language_fortran
;
9888 case DW_LANG_Mips_Assembler
:
9889 cu
->language
= language_asm
;
9892 cu
->language
= language_java
;
9896 cu
->language
= language_ada
;
9898 case DW_LANG_Modula2
:
9899 cu
->language
= language_m2
;
9901 case DW_LANG_Pascal83
:
9902 cu
->language
= language_pascal
;
9905 cu
->language
= language_objc
;
9907 case DW_LANG_Cobol74
:
9908 case DW_LANG_Cobol85
:
9910 cu
->language
= language_minimal
;
9913 cu
->language_defn
= language_def (cu
->language
);
9916 /* Return the named attribute or NULL if not there. */
9918 static struct attribute
*
9919 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
9922 struct attribute
*spec
= NULL
;
9924 for (i
= 0; i
< die
->num_attrs
; ++i
)
9926 if (die
->attrs
[i
].name
== name
)
9927 return &die
->attrs
[i
];
9928 if (die
->attrs
[i
].name
== DW_AT_specification
9929 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
9930 spec
= &die
->attrs
[i
];
9935 die
= follow_die_ref (die
, spec
, &cu
);
9936 return dwarf2_attr (die
, name
, cu
);
9942 /* Return the named attribute or NULL if not there,
9943 but do not follow DW_AT_specification, etc.
9944 This is for use in contexts where we're reading .debug_types dies.
9945 Following DW_AT_specification, DW_AT_abstract_origin will take us
9946 back up the chain, and we want to go down. */
9948 static struct attribute
*
9949 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
9950 struct dwarf2_cu
*cu
)
9954 for (i
= 0; i
< die
->num_attrs
; ++i
)
9955 if (die
->attrs
[i
].name
== name
)
9956 return &die
->attrs
[i
];
9961 /* Return non-zero iff the attribute NAME is defined for the given DIE,
9962 and holds a non-zero value. This function should only be used for
9963 DW_FORM_flag or DW_FORM_flag_present attributes. */
9966 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
9968 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
9970 return (attr
&& DW_UNSND (attr
));
9974 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
9976 /* A DIE is a declaration if it has a DW_AT_declaration attribute
9977 which value is non-zero. However, we have to be careful with
9978 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
9979 (via dwarf2_flag_true_p) follows this attribute. So we may
9980 end up accidently finding a declaration attribute that belongs
9981 to a different DIE referenced by the specification attribute,
9982 even though the given DIE does not have a declaration attribute. */
9983 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
9984 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
9987 /* Return the die giving the specification for DIE, if there is
9988 one. *SPEC_CU is the CU containing DIE on input, and the CU
9989 containing the return value on output. If there is no
9990 specification, but there is an abstract origin, that is
9993 static struct die_info
*
9994 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
9996 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
9999 if (spec_attr
== NULL
)
10000 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10002 if (spec_attr
== NULL
)
10005 return follow_die_ref (die
, spec_attr
, spec_cu
);
10008 /* Free the line_header structure *LH, and any arrays and strings it
10010 NOTE: This is also used as a "cleanup" function. */
10013 free_line_header (struct line_header
*lh
)
10015 if (lh
->standard_opcode_lengths
)
10016 xfree (lh
->standard_opcode_lengths
);
10018 /* Remember that all the lh->file_names[i].name pointers are
10019 pointers into debug_line_buffer, and don't need to be freed. */
10020 if (lh
->file_names
)
10021 xfree (lh
->file_names
);
10023 /* Similarly for the include directory names. */
10024 if (lh
->include_dirs
)
10025 xfree (lh
->include_dirs
);
10030 /* Add an entry to LH's include directory table. */
10033 add_include_dir (struct line_header
*lh
, char *include_dir
)
10035 /* Grow the array if necessary. */
10036 if (lh
->include_dirs_size
== 0)
10038 lh
->include_dirs_size
= 1; /* for testing */
10039 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10040 * sizeof (*lh
->include_dirs
));
10042 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10044 lh
->include_dirs_size
*= 2;
10045 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10046 (lh
->include_dirs_size
10047 * sizeof (*lh
->include_dirs
)));
10050 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10053 /* Add an entry to LH's file name table. */
10056 add_file_name (struct line_header
*lh
,
10058 unsigned int dir_index
,
10059 unsigned int mod_time
,
10060 unsigned int length
)
10062 struct file_entry
*fe
;
10064 /* Grow the array if necessary. */
10065 if (lh
->file_names_size
== 0)
10067 lh
->file_names_size
= 1; /* for testing */
10068 lh
->file_names
= xmalloc (lh
->file_names_size
10069 * sizeof (*lh
->file_names
));
10071 else if (lh
->num_file_names
>= lh
->file_names_size
)
10073 lh
->file_names_size
*= 2;
10074 lh
->file_names
= xrealloc (lh
->file_names
,
10075 (lh
->file_names_size
10076 * sizeof (*lh
->file_names
)));
10079 fe
= &lh
->file_names
[lh
->num_file_names
++];
10081 fe
->dir_index
= dir_index
;
10082 fe
->mod_time
= mod_time
;
10083 fe
->length
= length
;
10084 fe
->included_p
= 0;
10088 /* Read the statement program header starting at OFFSET in
10089 .debug_line, according to the endianness of ABFD. Return a pointer
10090 to a struct line_header, allocated using xmalloc.
10092 NOTE: the strings in the include directory and file name tables of
10093 the returned object point into debug_line_buffer, and must not be
10096 static struct line_header
*
10097 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10098 struct dwarf2_cu
*cu
)
10100 struct cleanup
*back_to
;
10101 struct line_header
*lh
;
10102 gdb_byte
*line_ptr
;
10103 unsigned int bytes_read
, offset_size
;
10105 char *cur_dir
, *cur_file
;
10107 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10108 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10110 complaint (&symfile_complaints
, _("missing .debug_line section"));
10114 /* Make sure that at least there's room for the total_length field.
10115 That could be 12 bytes long, but we're just going to fudge that. */
10116 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10118 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10122 lh
= xmalloc (sizeof (*lh
));
10123 memset (lh
, 0, sizeof (*lh
));
10124 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10127 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10129 /* Read in the header. */
10131 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10132 &bytes_read
, &offset_size
);
10133 line_ptr
+= bytes_read
;
10134 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10135 + dwarf2_per_objfile
->line
.size
))
10137 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10140 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10141 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10143 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10144 line_ptr
+= offset_size
;
10145 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10147 if (lh
->version
>= 4)
10149 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10153 lh
->maximum_ops_per_instruction
= 1;
10155 if (lh
->maximum_ops_per_instruction
== 0)
10157 lh
->maximum_ops_per_instruction
= 1;
10158 complaint (&symfile_complaints
,
10159 _("invalid maximum_ops_per_instruction "
10160 "in `.debug_line' section"));
10163 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10165 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10167 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10169 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10171 lh
->standard_opcode_lengths
10172 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10174 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10175 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10177 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10181 /* Read directory table. */
10182 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10184 line_ptr
+= bytes_read
;
10185 add_include_dir (lh
, cur_dir
);
10187 line_ptr
+= bytes_read
;
10189 /* Read file name table. */
10190 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10192 unsigned int dir_index
, mod_time
, length
;
10194 line_ptr
+= bytes_read
;
10195 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10196 line_ptr
+= bytes_read
;
10197 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10198 line_ptr
+= bytes_read
;
10199 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10200 line_ptr
+= bytes_read
;
10202 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10204 line_ptr
+= bytes_read
;
10205 lh
->statement_program_start
= line_ptr
;
10207 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
10208 + dwarf2_per_objfile
->line
.size
))
10209 complaint (&symfile_complaints
,
10210 _("line number info header doesn't "
10211 "fit in `.debug_line' section"));
10213 discard_cleanups (back_to
);
10217 /* This function exists to work around a bug in certain compilers
10218 (particularly GCC 2.95), in which the first line number marker of a
10219 function does not show up until after the prologue, right before
10220 the second line number marker. This function shifts ADDRESS down
10221 to the beginning of the function if necessary, and is called on
10222 addresses passed to record_line. */
10225 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
10227 struct function_range
*fn
;
10229 /* Find the function_range containing address. */
10233 if (!cu
->cached_fn
)
10234 cu
->cached_fn
= cu
->first_fn
;
10236 fn
= cu
->cached_fn
;
10238 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10244 while (fn
&& fn
!= cu
->cached_fn
)
10245 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10255 if (address
!= fn
->lowpc
)
10256 complaint (&symfile_complaints
,
10257 _("misplaced first line number at 0x%lx for '%s'"),
10258 (unsigned long) address
, fn
->name
);
10263 /* Subroutine of dwarf_decode_lines to simplify it.
10264 Return the file name of the psymtab for included file FILE_INDEX
10265 in line header LH of PST.
10266 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10267 If space for the result is malloc'd, it will be freed by a cleanup.
10268 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10271 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10272 const struct partial_symtab
*pst
,
10273 const char *comp_dir
)
10275 const struct file_entry fe
= lh
->file_names
[file_index
];
10276 char *include_name
= fe
.name
;
10277 char *include_name_to_compare
= include_name
;
10278 char *dir_name
= NULL
;
10279 const char *pst_filename
;
10280 char *copied_name
= NULL
;
10284 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10286 if (!IS_ABSOLUTE_PATH (include_name
)
10287 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10289 /* Avoid creating a duplicate psymtab for PST.
10290 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10291 Before we do the comparison, however, we need to account
10292 for DIR_NAME and COMP_DIR.
10293 First prepend dir_name (if non-NULL). If we still don't
10294 have an absolute path prepend comp_dir (if non-NULL).
10295 However, the directory we record in the include-file's
10296 psymtab does not contain COMP_DIR (to match the
10297 corresponding symtab(s)).
10302 bash$ gcc -g ./hello.c
10303 include_name = "hello.c"
10305 DW_AT_comp_dir = comp_dir = "/tmp"
10306 DW_AT_name = "./hello.c" */
10308 if (dir_name
!= NULL
)
10310 include_name
= concat (dir_name
, SLASH_STRING
,
10311 include_name
, (char *)NULL
);
10312 include_name_to_compare
= include_name
;
10313 make_cleanup (xfree
, include_name
);
10315 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10317 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10318 include_name
, (char *)NULL
);
10322 pst_filename
= pst
->filename
;
10323 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10325 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
10326 pst_filename
, (char *)NULL
);
10327 pst_filename
= copied_name
;
10330 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
10332 if (include_name_to_compare
!= include_name
)
10333 xfree (include_name_to_compare
);
10334 if (copied_name
!= NULL
)
10335 xfree (copied_name
);
10339 return include_name
;
10342 /* Decode the Line Number Program (LNP) for the given line_header
10343 structure and CU. The actual information extracted and the type
10344 of structures created from the LNP depends on the value of PST.
10346 1. If PST is NULL, then this procedure uses the data from the program
10347 to create all necessary symbol tables, and their linetables.
10349 2. If PST is not NULL, this procedure reads the program to determine
10350 the list of files included by the unit represented by PST, and
10351 builds all the associated partial symbol tables.
10353 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10354 It is used for relative paths in the line table.
10355 NOTE: When processing partial symtabs (pst != NULL),
10356 comp_dir == pst->dirname.
10358 NOTE: It is important that psymtabs have the same file name (via strcmp)
10359 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10360 symtab we don't use it in the name of the psymtabs we create.
10361 E.g. expand_line_sal requires this when finding psymtabs to expand.
10362 A good testcase for this is mb-inline.exp. */
10365 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
10366 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10368 gdb_byte
*line_ptr
, *extended_end
;
10369 gdb_byte
*line_end
;
10370 unsigned int bytes_read
, extended_len
;
10371 unsigned char op_code
, extended_op
, adj_opcode
;
10372 CORE_ADDR baseaddr
;
10373 struct objfile
*objfile
= cu
->objfile
;
10374 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10375 const int decode_for_pst_p
= (pst
!= NULL
);
10376 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10378 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10380 line_ptr
= lh
->statement_program_start
;
10381 line_end
= lh
->statement_program_end
;
10383 /* Read the statement sequences until there's nothing left. */
10384 while (line_ptr
< line_end
)
10386 /* state machine registers */
10387 CORE_ADDR address
= 0;
10388 unsigned int file
= 1;
10389 unsigned int line
= 1;
10390 unsigned int column
= 0;
10391 int is_stmt
= lh
->default_is_stmt
;
10392 int basic_block
= 0;
10393 int end_sequence
= 0;
10395 unsigned char op_index
= 0;
10397 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10399 /* Start a subfile for the current file of the state machine. */
10400 /* lh->include_dirs and lh->file_names are 0-based, but the
10401 directory and file name numbers in the statement program
10403 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10407 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10409 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10412 /* Decode the table. */
10413 while (!end_sequence
)
10415 op_code
= read_1_byte (abfd
, line_ptr
);
10417 if (line_ptr
> line_end
)
10419 dwarf2_debug_line_missing_end_sequence_complaint ();
10423 if (op_code
>= lh
->opcode_base
)
10425 /* Special operand. */
10426 adj_opcode
= op_code
- lh
->opcode_base
;
10427 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10428 / lh
->maximum_ops_per_instruction
)
10429 * lh
->minimum_instruction_length
);
10430 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10431 % lh
->maximum_ops_per_instruction
);
10432 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10433 if (lh
->num_file_names
< file
|| file
== 0)
10434 dwarf2_debug_line_missing_file_complaint ();
10435 /* For now we ignore lines not starting on an
10436 instruction boundary. */
10437 else if (op_index
== 0)
10439 lh
->file_names
[file
- 1].included_p
= 1;
10440 if (!decode_for_pst_p
&& is_stmt
)
10442 if (last_subfile
!= current_subfile
)
10444 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10446 record_line (last_subfile
, 0, addr
);
10447 last_subfile
= current_subfile
;
10449 /* Append row to matrix using current values. */
10450 addr
= check_cu_functions (address
, cu
);
10451 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10452 record_line (current_subfile
, line
, addr
);
10457 else switch (op_code
)
10459 case DW_LNS_extended_op
:
10460 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
10462 line_ptr
+= bytes_read
;
10463 extended_end
= line_ptr
+ extended_len
;
10464 extended_op
= read_1_byte (abfd
, line_ptr
);
10466 switch (extended_op
)
10468 case DW_LNE_end_sequence
:
10471 case DW_LNE_set_address
:
10472 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10474 line_ptr
+= bytes_read
;
10475 address
+= baseaddr
;
10477 case DW_LNE_define_file
:
10480 unsigned int dir_index
, mod_time
, length
;
10482 cur_file
= read_direct_string (abfd
, line_ptr
,
10484 line_ptr
+= bytes_read
;
10486 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10487 line_ptr
+= bytes_read
;
10489 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10490 line_ptr
+= bytes_read
;
10492 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10493 line_ptr
+= bytes_read
;
10494 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10497 case DW_LNE_set_discriminator
:
10498 /* The discriminator is not interesting to the debugger;
10500 line_ptr
= extended_end
;
10503 complaint (&symfile_complaints
,
10504 _("mangled .debug_line section"));
10507 /* Make sure that we parsed the extended op correctly. If e.g.
10508 we expected a different address size than the producer used,
10509 we may have read the wrong number of bytes. */
10510 if (line_ptr
!= extended_end
)
10512 complaint (&symfile_complaints
,
10513 _("mangled .debug_line section"));
10518 if (lh
->num_file_names
< file
|| file
== 0)
10519 dwarf2_debug_line_missing_file_complaint ();
10522 lh
->file_names
[file
- 1].included_p
= 1;
10523 if (!decode_for_pst_p
&& is_stmt
)
10525 if (last_subfile
!= current_subfile
)
10527 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10529 record_line (last_subfile
, 0, addr
);
10530 last_subfile
= current_subfile
;
10532 addr
= check_cu_functions (address
, cu
);
10533 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10534 record_line (current_subfile
, line
, addr
);
10539 case DW_LNS_advance_pc
:
10542 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10544 address
+= (((op_index
+ adjust
)
10545 / lh
->maximum_ops_per_instruction
)
10546 * lh
->minimum_instruction_length
);
10547 op_index
= ((op_index
+ adjust
)
10548 % lh
->maximum_ops_per_instruction
);
10549 line_ptr
+= bytes_read
;
10552 case DW_LNS_advance_line
:
10553 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
10554 line_ptr
+= bytes_read
;
10556 case DW_LNS_set_file
:
10558 /* The arrays lh->include_dirs and lh->file_names are
10559 0-based, but the directory and file name numbers in
10560 the statement program are 1-based. */
10561 struct file_entry
*fe
;
10564 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10565 line_ptr
+= bytes_read
;
10566 if (lh
->num_file_names
< file
|| file
== 0)
10567 dwarf2_debug_line_missing_file_complaint ();
10570 fe
= &lh
->file_names
[file
- 1];
10572 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10573 if (!decode_for_pst_p
)
10575 last_subfile
= current_subfile
;
10576 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10581 case DW_LNS_set_column
:
10582 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10583 line_ptr
+= bytes_read
;
10585 case DW_LNS_negate_stmt
:
10586 is_stmt
= (!is_stmt
);
10588 case DW_LNS_set_basic_block
:
10591 /* Add to the address register of the state machine the
10592 address increment value corresponding to special opcode
10593 255. I.e., this value is scaled by the minimum
10594 instruction length since special opcode 255 would have
10595 scaled the increment. */
10596 case DW_LNS_const_add_pc
:
10598 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
10600 address
+= (((op_index
+ adjust
)
10601 / lh
->maximum_ops_per_instruction
)
10602 * lh
->minimum_instruction_length
);
10603 op_index
= ((op_index
+ adjust
)
10604 % lh
->maximum_ops_per_instruction
);
10607 case DW_LNS_fixed_advance_pc
:
10608 address
+= read_2_bytes (abfd
, line_ptr
);
10614 /* Unknown standard opcode, ignore it. */
10617 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
10619 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10620 line_ptr
+= bytes_read
;
10625 if (lh
->num_file_names
< file
|| file
== 0)
10626 dwarf2_debug_line_missing_file_complaint ();
10629 lh
->file_names
[file
- 1].included_p
= 1;
10630 if (!decode_for_pst_p
)
10632 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10633 record_line (current_subfile
, 0, addr
);
10638 if (decode_for_pst_p
)
10642 /* Now that we're done scanning the Line Header Program, we can
10643 create the psymtab of each included file. */
10644 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
10645 if (lh
->file_names
[file_index
].included_p
== 1)
10647 char *include_name
=
10648 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
10649 if (include_name
!= NULL
)
10650 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
10655 /* Make sure a symtab is created for every file, even files
10656 which contain only variables (i.e. no code with associated
10660 struct file_entry
*fe
;
10662 for (i
= 0; i
< lh
->num_file_names
; i
++)
10666 fe
= &lh
->file_names
[i
];
10668 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10669 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10671 /* Skip the main file; we don't need it, and it must be
10672 allocated last, so that it will show up before the
10673 non-primary symtabs in the objfile's symtab list. */
10674 if (current_subfile
== first_subfile
)
10677 if (current_subfile
->symtab
== NULL
)
10678 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
10680 fe
->symtab
= current_subfile
->symtab
;
10685 /* Start a subfile for DWARF. FILENAME is the name of the file and
10686 DIRNAME the name of the source directory which contains FILENAME
10687 or NULL if not known. COMP_DIR is the compilation directory for the
10688 linetable's compilation unit or NULL if not known.
10689 This routine tries to keep line numbers from identical absolute and
10690 relative file names in a common subfile.
10692 Using the `list' example from the GDB testsuite, which resides in
10693 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10694 of /srcdir/list0.c yields the following debugging information for list0.c:
10696 DW_AT_name: /srcdir/list0.c
10697 DW_AT_comp_dir: /compdir
10698 files.files[0].name: list0.h
10699 files.files[0].dir: /srcdir
10700 files.files[1].name: list0.c
10701 files.files[1].dir: /srcdir
10703 The line number information for list0.c has to end up in a single
10704 subfile, so that `break /srcdir/list0.c:1' works as expected.
10705 start_subfile will ensure that this happens provided that we pass the
10706 concatenation of files.files[1].dir and files.files[1].name as the
10710 dwarf2_start_subfile (char *filename
, const char *dirname
,
10711 const char *comp_dir
)
10715 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10716 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10717 second argument to start_subfile. To be consistent, we do the
10718 same here. In order not to lose the line information directory,
10719 we concatenate it to the filename when it makes sense.
10720 Note that the Dwarf3 standard says (speaking of filenames in line
10721 information): ``The directory index is ignored for file names
10722 that represent full path names''. Thus ignoring dirname in the
10723 `else' branch below isn't an issue. */
10725 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
10726 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
10728 fullname
= filename
;
10730 start_subfile (fullname
, comp_dir
);
10732 if (fullname
!= filename
)
10737 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
10738 struct dwarf2_cu
*cu
)
10740 struct objfile
*objfile
= cu
->objfile
;
10741 struct comp_unit_head
*cu_header
= &cu
->header
;
10743 /* NOTE drow/2003-01-30: There used to be a comment and some special
10744 code here to turn a symbol with DW_AT_external and a
10745 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10746 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10747 with some versions of binutils) where shared libraries could have
10748 relocations against symbols in their debug information - the
10749 minimal symbol would have the right address, but the debug info
10750 would not. It's no longer necessary, because we will explicitly
10751 apply relocations when we read in the debug information now. */
10753 /* A DW_AT_location attribute with no contents indicates that a
10754 variable has been optimized away. */
10755 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
10757 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10761 /* Handle one degenerate form of location expression specially, to
10762 preserve GDB's previous behavior when section offsets are
10763 specified. If this is just a DW_OP_addr then mark this symbol
10766 if (attr_form_is_block (attr
)
10767 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
10768 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
10770 unsigned int dummy
;
10772 SYMBOL_VALUE_ADDRESS (sym
) =
10773 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
10774 SYMBOL_CLASS (sym
) = LOC_STATIC
;
10775 fixup_symbol_section (sym
, objfile
);
10776 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
10777 SYMBOL_SECTION (sym
));
10781 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
10782 expression evaluator, and use LOC_COMPUTED only when necessary
10783 (i.e. when the value of a register or memory location is
10784 referenced, or a thread-local block, etc.). Then again, it might
10785 not be worthwhile. I'm assuming that it isn't unless performance
10786 or memory numbers show me otherwise. */
10788 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
10789 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10792 /* Given a pointer to a DWARF information entry, figure out if we need
10793 to make a symbol table entry for it, and if so, create a new entry
10794 and return a pointer to it.
10795 If TYPE is NULL, determine symbol type from the die, otherwise
10796 used the passed type.
10797 If SPACE is not NULL, use it to hold the new symbol. If it is
10798 NULL, allocate a new symbol on the objfile's obstack. */
10800 static struct symbol
*
10801 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
10802 struct symbol
*space
)
10804 struct objfile
*objfile
= cu
->objfile
;
10805 struct symbol
*sym
= NULL
;
10807 struct attribute
*attr
= NULL
;
10808 struct attribute
*attr2
= NULL
;
10809 CORE_ADDR baseaddr
;
10810 struct pending
**list_to_add
= NULL
;
10812 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10814 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10816 name
= dwarf2_name (die
, cu
);
10819 const char *linkagename
;
10820 int suppress_add
= 0;
10825 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
10826 OBJSTAT (objfile
, n_syms
++);
10828 /* Cache this symbol's name and the name's demangled form (if any). */
10829 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
10830 linkagename
= dwarf2_physname (name
, die
, cu
);
10831 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
10833 /* Fortran does not have mangling standard and the mangling does differ
10834 between gfortran, iFort etc. */
10835 if (cu
->language
== language_fortran
10836 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
10837 symbol_set_demangled_name (&(sym
->ginfo
),
10838 (char *) dwarf2_full_name (name
, die
, cu
),
10841 /* Default assumptions.
10842 Use the passed type or decode it from the die. */
10843 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10844 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10846 SYMBOL_TYPE (sym
) = type
;
10848 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
10849 attr
= dwarf2_attr (die
,
10850 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
10854 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
10857 attr
= dwarf2_attr (die
,
10858 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
10862 int file_index
= DW_UNSND (attr
);
10864 if (cu
->line_header
== NULL
10865 || file_index
> cu
->line_header
->num_file_names
)
10866 complaint (&symfile_complaints
,
10867 _("file index out of range"));
10868 else if (file_index
> 0)
10870 struct file_entry
*fe
;
10872 fe
= &cu
->line_header
->file_names
[file_index
- 1];
10873 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
10880 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10883 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
10885 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
10886 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
10887 SYMBOL_CLASS (sym
) = LOC_LABEL
;
10888 add_symbol_to_list (sym
, cu
->list_in_scope
);
10890 case DW_TAG_subprogram
:
10891 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10893 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10894 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10895 if ((attr2
&& (DW_UNSND (attr2
) != 0))
10896 || cu
->language
== language_ada
)
10898 /* Subprograms marked external are stored as a global symbol.
10899 Ada subprograms, whether marked external or not, are always
10900 stored as a global symbol, because we want to be able to
10901 access them globally. For instance, we want to be able
10902 to break on a nested subprogram without having to
10903 specify the context. */
10904 list_to_add
= &global_symbols
;
10908 list_to_add
= cu
->list_in_scope
;
10911 case DW_TAG_inlined_subroutine
:
10912 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10914 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10915 SYMBOL_INLINED (sym
) = 1;
10916 /* Do not add the symbol to any lists. It will be found via
10917 BLOCK_FUNCTION from the blockvector. */
10919 case DW_TAG_template_value_param
:
10921 /* Fall through. */
10922 case DW_TAG_constant
:
10923 case DW_TAG_variable
:
10924 case DW_TAG_member
:
10925 /* Compilation with minimal debug info may result in
10926 variables with missing type entries. Change the
10927 misleading `void' type to something sensible. */
10928 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
10930 = objfile_type (objfile
)->nodebug_data_symbol
;
10932 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10933 /* In the case of DW_TAG_member, we should only be called for
10934 static const members. */
10935 if (die
->tag
== DW_TAG_member
)
10937 /* dwarf2_add_field uses die_is_declaration,
10938 so we do the same. */
10939 gdb_assert (die_is_declaration (die
, cu
));
10944 dwarf2_const_value (attr
, sym
, cu
);
10945 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10948 if (attr2
&& (DW_UNSND (attr2
) != 0))
10949 list_to_add
= &global_symbols
;
10951 list_to_add
= cu
->list_in_scope
;
10955 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10958 var_decode_location (attr
, sym
, cu
);
10959 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10960 if (SYMBOL_CLASS (sym
) == LOC_STATIC
10961 && SYMBOL_VALUE_ADDRESS (sym
) == 0
10962 && !dwarf2_per_objfile
->has_section_at_zero
)
10964 /* When a static variable is eliminated by the linker,
10965 the corresponding debug information is not stripped
10966 out, but the variable address is set to null;
10967 do not add such variables into symbol table. */
10969 else if (attr2
&& (DW_UNSND (attr2
) != 0))
10971 /* Workaround gfortran PR debug/40040 - it uses
10972 DW_AT_location for variables in -fPIC libraries which may
10973 get overriden by other libraries/executable and get
10974 a different address. Resolve it by the minimal symbol
10975 which may come from inferior's executable using copy
10976 relocation. Make this workaround only for gfortran as for
10977 other compilers GDB cannot guess the minimal symbol
10978 Fortran mangling kind. */
10979 if (cu
->language
== language_fortran
&& die
->parent
10980 && die
->parent
->tag
== DW_TAG_module
10982 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
10983 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10985 /* A variable with DW_AT_external is never static,
10986 but it may be block-scoped. */
10987 list_to_add
= (cu
->list_in_scope
== &file_symbols
10988 ? &global_symbols
: cu
->list_in_scope
);
10991 list_to_add
= cu
->list_in_scope
;
10995 /* We do not know the address of this symbol.
10996 If it is an external symbol and we have type information
10997 for it, enter the symbol as a LOC_UNRESOLVED symbol.
10998 The address of the variable will then be determined from
10999 the minimal symbol table whenever the variable is
11001 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11002 if (attr2
&& (DW_UNSND (attr2
) != 0)
11003 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11005 /* A variable with DW_AT_external is never static, but it
11006 may be block-scoped. */
11007 list_to_add
= (cu
->list_in_scope
== &file_symbols
11008 ? &global_symbols
: cu
->list_in_scope
);
11010 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11012 else if (!die_is_declaration (die
, cu
))
11014 /* Use the default LOC_OPTIMIZED_OUT class. */
11015 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11017 list_to_add
= cu
->list_in_scope
;
11021 case DW_TAG_formal_parameter
:
11022 /* If we are inside a function, mark this as an argument. If
11023 not, we might be looking at an argument to an inlined function
11024 when we do not have enough information to show inlined frames;
11025 pretend it's a local variable in that case so that the user can
11027 if (context_stack_depth
> 0
11028 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11029 SYMBOL_IS_ARGUMENT (sym
) = 1;
11030 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11033 var_decode_location (attr
, sym
, cu
);
11035 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11038 dwarf2_const_value (attr
, sym
, cu
);
11040 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
11041 if (attr
&& DW_UNSND (attr
))
11043 struct type
*ref_type
;
11045 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
11046 SYMBOL_TYPE (sym
) = ref_type
;
11049 list_to_add
= cu
->list_in_scope
;
11051 case DW_TAG_unspecified_parameters
:
11052 /* From varargs functions; gdb doesn't seem to have any
11053 interest in this information, so just ignore it for now.
11056 case DW_TAG_template_type_param
:
11058 /* Fall through. */
11059 case DW_TAG_class_type
:
11060 case DW_TAG_interface_type
:
11061 case DW_TAG_structure_type
:
11062 case DW_TAG_union_type
:
11063 case DW_TAG_set_type
:
11064 case DW_TAG_enumeration_type
:
11065 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11066 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11069 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11070 really ever be static objects: otherwise, if you try
11071 to, say, break of a class's method and you're in a file
11072 which doesn't mention that class, it won't work unless
11073 the check for all static symbols in lookup_symbol_aux
11074 saves you. See the OtherFileClass tests in
11075 gdb.c++/namespace.exp. */
11079 list_to_add
= (cu
->list_in_scope
== &file_symbols
11080 && (cu
->language
== language_cplus
11081 || cu
->language
== language_java
)
11082 ? &global_symbols
: cu
->list_in_scope
);
11084 /* The semantics of C++ state that "struct foo {
11085 ... }" also defines a typedef for "foo". A Java
11086 class declaration also defines a typedef for the
11088 if (cu
->language
== language_cplus
11089 || cu
->language
== language_java
11090 || cu
->language
== language_ada
)
11092 /* The symbol's name is already allocated along
11093 with this objfile, so we don't need to
11094 duplicate it for the type. */
11095 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11096 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11101 case DW_TAG_typedef
:
11102 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11103 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11104 list_to_add
= cu
->list_in_scope
;
11106 case DW_TAG_base_type
:
11107 case DW_TAG_subrange_type
:
11108 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11109 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11110 list_to_add
= cu
->list_in_scope
;
11112 case DW_TAG_enumerator
:
11113 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11116 dwarf2_const_value (attr
, sym
, cu
);
11119 /* NOTE: carlton/2003-11-10: See comment above in the
11120 DW_TAG_class_type, etc. block. */
11122 list_to_add
= (cu
->list_in_scope
== &file_symbols
11123 && (cu
->language
== language_cplus
11124 || cu
->language
== language_java
)
11125 ? &global_symbols
: cu
->list_in_scope
);
11128 case DW_TAG_namespace
:
11129 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11130 list_to_add
= &global_symbols
;
11133 /* Not a tag we recognize. Hopefully we aren't processing
11134 trash data, but since we must specifically ignore things
11135 we don't recognize, there is nothing else we should do at
11137 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11138 dwarf_tag_name (die
->tag
));
11144 sym
->hash_next
= objfile
->template_symbols
;
11145 objfile
->template_symbols
= sym
;
11146 list_to_add
= NULL
;
11149 if (list_to_add
!= NULL
)
11150 add_symbol_to_list (sym
, list_to_add
);
11152 /* For the benefit of old versions of GCC, check for anonymous
11153 namespaces based on the demangled name. */
11154 if (!processing_has_namespace_info
11155 && cu
->language
== language_cplus
)
11156 cp_scan_for_anonymous_namespaces (sym
);
11161 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11163 static struct symbol
*
11164 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11166 return new_symbol_full (die
, type
, cu
, NULL
);
11169 /* Given an attr with a DW_FORM_dataN value in host byte order,
11170 zero-extend it as appropriate for the symbol's type. The DWARF
11171 standard (v4) is not entirely clear about the meaning of using
11172 DW_FORM_dataN for a constant with a signed type, where the type is
11173 wider than the data. The conclusion of a discussion on the DWARF
11174 list was that this is unspecified. We choose to always zero-extend
11175 because that is the interpretation long in use by GCC. */
11178 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11179 const char *name
, struct obstack
*obstack
,
11180 struct dwarf2_cu
*cu
, long *value
, int bits
)
11182 struct objfile
*objfile
= cu
->objfile
;
11183 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11184 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11185 LONGEST l
= DW_UNSND (attr
);
11187 if (bits
< sizeof (*value
) * 8)
11189 l
&= ((LONGEST
) 1 << bits
) - 1;
11192 else if (bits
== sizeof (*value
) * 8)
11196 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11197 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11204 /* Read a constant value from an attribute. Either set *VALUE, or if
11205 the value does not fit in *VALUE, set *BYTES - either already
11206 allocated on the objfile obstack, or newly allocated on OBSTACK,
11207 or, set *BATON, if we translated the constant to a location
11211 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11212 const char *name
, struct obstack
*obstack
,
11213 struct dwarf2_cu
*cu
,
11214 long *value
, gdb_byte
**bytes
,
11215 struct dwarf2_locexpr_baton
**baton
)
11217 struct objfile
*objfile
= cu
->objfile
;
11218 struct comp_unit_head
*cu_header
= &cu
->header
;
11219 struct dwarf_block
*blk
;
11220 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
11221 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
11227 switch (attr
->form
)
11233 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
11234 dwarf2_const_value_length_mismatch_complaint (name
,
11235 cu_header
->addr_size
,
11236 TYPE_LENGTH (type
));
11237 /* Symbols of this form are reasonably rare, so we just
11238 piggyback on the existing location code rather than writing
11239 a new implementation of symbol_computed_ops. */
11240 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11241 sizeof (struct dwarf2_locexpr_baton
));
11242 (*baton
)->per_cu
= cu
->per_cu
;
11243 gdb_assert ((*baton
)->per_cu
);
11245 (*baton
)->size
= 2 + cu_header
->addr_size
;
11246 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11247 (*baton
)->data
= data
;
11249 data
[0] = DW_OP_addr
;
11250 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11251 byte_order
, DW_ADDR (attr
));
11252 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11255 case DW_FORM_string
:
11257 /* DW_STRING is already allocated on the objfile obstack, point
11259 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11261 case DW_FORM_block1
:
11262 case DW_FORM_block2
:
11263 case DW_FORM_block4
:
11264 case DW_FORM_block
:
11265 case DW_FORM_exprloc
:
11266 blk
= DW_BLOCK (attr
);
11267 if (TYPE_LENGTH (type
) != blk
->size
)
11268 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11269 TYPE_LENGTH (type
));
11270 *bytes
= blk
->data
;
11273 /* The DW_AT_const_value attributes are supposed to carry the
11274 symbol's value "represented as it would be on the target
11275 architecture." By the time we get here, it's already been
11276 converted to host endianness, so we just need to sign- or
11277 zero-extend it as appropriate. */
11278 case DW_FORM_data1
:
11279 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11280 obstack
, cu
, value
, 8);
11282 case DW_FORM_data2
:
11283 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11284 obstack
, cu
, value
, 16);
11286 case DW_FORM_data4
:
11287 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11288 obstack
, cu
, value
, 32);
11290 case DW_FORM_data8
:
11291 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11292 obstack
, cu
, value
, 64);
11295 case DW_FORM_sdata
:
11296 *value
= DW_SND (attr
);
11299 case DW_FORM_udata
:
11300 *value
= DW_UNSND (attr
);
11304 complaint (&symfile_complaints
,
11305 _("unsupported const value attribute form: '%s'"),
11306 dwarf_form_name (attr
->form
));
11313 /* Copy constant value from an attribute to a symbol. */
11316 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11317 struct dwarf2_cu
*cu
)
11319 struct objfile
*objfile
= cu
->objfile
;
11320 struct comp_unit_head
*cu_header
= &cu
->header
;
11323 struct dwarf2_locexpr_baton
*baton
;
11325 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11326 SYMBOL_PRINT_NAME (sym
),
11327 &objfile
->objfile_obstack
, cu
,
11328 &value
, &bytes
, &baton
);
11332 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11333 SYMBOL_LOCATION_BATON (sym
) = baton
;
11334 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11336 else if (bytes
!= NULL
)
11338 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11339 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11343 SYMBOL_VALUE (sym
) = value
;
11344 SYMBOL_CLASS (sym
) = LOC_CONST
;
11348 /* Return the type of the die in question using its DW_AT_type attribute. */
11350 static struct type
*
11351 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11353 struct attribute
*type_attr
;
11355 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11358 /* A missing DW_AT_type represents a void type. */
11359 return objfile_type (cu
->objfile
)->builtin_void
;
11362 return lookup_die_type (die
, type_attr
, cu
);
11365 /* True iff CU's producer generates GNAT Ada auxiliary information
11366 that allows to find parallel types through that information instead
11367 of having to do expensive parallel lookups by type name. */
11370 need_gnat_info (struct dwarf2_cu
*cu
)
11372 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11373 of GNAT produces this auxiliary information, without any indication
11374 that it is produced. Part of enhancing the FSF version of GNAT
11375 to produce that information will be to put in place an indicator
11376 that we can use in order to determine whether the descriptive type
11377 info is available or not. One suggestion that has been made is
11378 to use a new attribute, attached to the CU die. For now, assume
11379 that the descriptive type info is not available. */
11383 /* Return the auxiliary type of the die in question using its
11384 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11385 attribute is not present. */
11387 static struct type
*
11388 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11390 struct attribute
*type_attr
;
11392 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11396 return lookup_die_type (die
, type_attr
, cu
);
11399 /* If DIE has a descriptive_type attribute, then set the TYPE's
11400 descriptive type accordingly. */
11403 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11404 struct dwarf2_cu
*cu
)
11406 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11408 if (descriptive_type
)
11410 ALLOCATE_GNAT_AUX_TYPE (type
);
11411 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11415 /* Return the containing type of the die in question using its
11416 DW_AT_containing_type attribute. */
11418 static struct type
*
11419 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11421 struct attribute
*type_attr
;
11423 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11425 error (_("Dwarf Error: Problem turning containing type into gdb type "
11426 "[in module %s]"), cu
->objfile
->name
);
11428 return lookup_die_type (die
, type_attr
, cu
);
11431 /* Look up the type of DIE in CU using its type attribute ATTR.
11432 If there is no type substitute an error marker. */
11434 static struct type
*
11435 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11436 struct dwarf2_cu
*cu
)
11438 struct type
*this_type
;
11440 /* First see if we have it cached. */
11442 if (is_ref_attr (attr
))
11444 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11446 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11448 else if (attr
->form
== DW_FORM_sig8
)
11450 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11451 struct dwarf2_cu
*sig_cu
;
11452 unsigned int offset
;
11454 /* sig_type will be NULL if the signatured type is missing from
11456 if (sig_type
== NULL
)
11457 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11458 "at 0x%x [in module %s]"),
11459 die
->offset
, cu
->objfile
->name
);
11461 gdb_assert (sig_type
->per_cu
.from_debug_types
);
11462 offset
= sig_type
->offset
+ sig_type
->type_offset
;
11463 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11467 dump_die_for_error (die
);
11468 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11469 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11472 /* If not cached we need to read it in. */
11474 if (this_type
== NULL
)
11476 struct die_info
*type_die
;
11477 struct dwarf2_cu
*type_cu
= cu
;
11479 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11480 /* If the type is cached, we should have found it above. */
11481 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
11482 this_type
= read_type_die_1 (type_die
, type_cu
);
11485 /* If we still don't have a type use an error marker. */
11487 if (this_type
== NULL
)
11489 char *message
, *saved
;
11491 /* read_type_die already issued a complaint. */
11492 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11496 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
11497 message
, strlen (message
));
11500 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
11506 /* Return the type in DIE, CU.
11507 Returns NULL for invalid types.
11509 This first does a lookup in the appropriate type_hash table,
11510 and only reads the die in if necessary.
11512 NOTE: This can be called when reading in partial or full symbols. */
11514 static struct type
*
11515 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11517 struct type
*this_type
;
11519 this_type
= get_die_type (die
, cu
);
11523 return read_type_die_1 (die
, cu
);
11526 /* Read the type in DIE, CU.
11527 Returns NULL for invalid types. */
11529 static struct type
*
11530 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
11532 struct type
*this_type
= NULL
;
11536 case DW_TAG_class_type
:
11537 case DW_TAG_interface_type
:
11538 case DW_TAG_structure_type
:
11539 case DW_TAG_union_type
:
11540 this_type
= read_structure_type (die
, cu
);
11542 case DW_TAG_enumeration_type
:
11543 this_type
= read_enumeration_type (die
, cu
);
11545 case DW_TAG_subprogram
:
11546 case DW_TAG_subroutine_type
:
11547 case DW_TAG_inlined_subroutine
:
11548 this_type
= read_subroutine_type (die
, cu
);
11550 case DW_TAG_array_type
:
11551 this_type
= read_array_type (die
, cu
);
11553 case DW_TAG_set_type
:
11554 this_type
= read_set_type (die
, cu
);
11556 case DW_TAG_pointer_type
:
11557 this_type
= read_tag_pointer_type (die
, cu
);
11559 case DW_TAG_ptr_to_member_type
:
11560 this_type
= read_tag_ptr_to_member_type (die
, cu
);
11562 case DW_TAG_reference_type
:
11563 this_type
= read_tag_reference_type (die
, cu
);
11565 case DW_TAG_const_type
:
11566 this_type
= read_tag_const_type (die
, cu
);
11568 case DW_TAG_volatile_type
:
11569 this_type
= read_tag_volatile_type (die
, cu
);
11571 case DW_TAG_string_type
:
11572 this_type
= read_tag_string_type (die
, cu
);
11574 case DW_TAG_typedef
:
11575 this_type
= read_typedef (die
, cu
);
11577 case DW_TAG_subrange_type
:
11578 this_type
= read_subrange_type (die
, cu
);
11580 case DW_TAG_base_type
:
11581 this_type
= read_base_type (die
, cu
);
11583 case DW_TAG_unspecified_type
:
11584 this_type
= read_unspecified_type (die
, cu
);
11586 case DW_TAG_namespace
:
11587 this_type
= read_namespace_type (die
, cu
);
11589 case DW_TAG_module
:
11590 this_type
= read_module_type (die
, cu
);
11593 complaint (&symfile_complaints
,
11594 _("unexpected tag in read_type_die: '%s'"),
11595 dwarf_tag_name (die
->tag
));
11602 /* See if we can figure out if the class lives in a namespace. We do
11603 this by looking for a member function; its demangled name will
11604 contain namespace info, if there is any.
11605 Return the computed name or NULL.
11606 Space for the result is allocated on the objfile's obstack.
11607 This is the full-die version of guess_partial_die_structure_name.
11608 In this case we know DIE has no useful parent. */
11611 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11613 struct die_info
*spec_die
;
11614 struct dwarf2_cu
*spec_cu
;
11615 struct die_info
*child
;
11618 spec_die
= die_specification (die
, &spec_cu
);
11619 if (spec_die
!= NULL
)
11625 for (child
= die
->child
;
11627 child
= child
->sibling
)
11629 if (child
->tag
== DW_TAG_subprogram
)
11631 struct attribute
*attr
;
11633 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
11635 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
11639 = language_class_name_from_physname (cu
->language_defn
,
11643 if (actual_name
!= NULL
)
11645 char *die_name
= dwarf2_name (die
, cu
);
11647 if (die_name
!= NULL
11648 && strcmp (die_name
, actual_name
) != 0)
11650 /* Strip off the class name from the full name.
11651 We want the prefix. */
11652 int die_name_len
= strlen (die_name
);
11653 int actual_name_len
= strlen (actual_name
);
11655 /* Test for '::' as a sanity check. */
11656 if (actual_name_len
> die_name_len
+ 2
11657 && actual_name
[actual_name_len
11658 - die_name_len
- 1] == ':')
11660 obsavestring (actual_name
,
11661 actual_name_len
- die_name_len
- 2,
11662 &cu
->objfile
->objfile_obstack
);
11665 xfree (actual_name
);
11674 /* Return the name of the namespace/class that DIE is defined within,
11675 or "" if we can't tell. The caller should not xfree the result.
11677 For example, if we're within the method foo() in the following
11687 then determine_prefix on foo's die will return "N::C". */
11690 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
11692 struct die_info
*parent
, *spec_die
;
11693 struct dwarf2_cu
*spec_cu
;
11694 struct type
*parent_type
;
11696 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
11697 && cu
->language
!= language_fortran
)
11700 /* We have to be careful in the presence of DW_AT_specification.
11701 For example, with GCC 3.4, given the code
11705 // Definition of N::foo.
11709 then we'll have a tree of DIEs like this:
11711 1: DW_TAG_compile_unit
11712 2: DW_TAG_namespace // N
11713 3: DW_TAG_subprogram // declaration of N::foo
11714 4: DW_TAG_subprogram // definition of N::foo
11715 DW_AT_specification // refers to die #3
11717 Thus, when processing die #4, we have to pretend that we're in
11718 the context of its DW_AT_specification, namely the contex of die
11721 spec_die
= die_specification (die
, &spec_cu
);
11722 if (spec_die
== NULL
)
11723 parent
= die
->parent
;
11726 parent
= spec_die
->parent
;
11730 if (parent
== NULL
)
11732 else if (parent
->building_fullname
)
11735 const char *parent_name
;
11737 /* It has been seen on RealView 2.2 built binaries,
11738 DW_TAG_template_type_param types actually _defined_ as
11739 children of the parent class:
11742 template class <class Enum> Class{};
11743 Class<enum E> class_e;
11745 1: DW_TAG_class_type (Class)
11746 2: DW_TAG_enumeration_type (E)
11747 3: DW_TAG_enumerator (enum1:0)
11748 3: DW_TAG_enumerator (enum2:1)
11750 2: DW_TAG_template_type_param
11751 DW_AT_type DW_FORM_ref_udata (E)
11753 Besides being broken debug info, it can put GDB into an
11754 infinite loop. Consider:
11756 When we're building the full name for Class<E>, we'll start
11757 at Class, and go look over its template type parameters,
11758 finding E. We'll then try to build the full name of E, and
11759 reach here. We're now trying to build the full name of E,
11760 and look over the parent DIE for containing scope. In the
11761 broken case, if we followed the parent DIE of E, we'd again
11762 find Class, and once again go look at its template type
11763 arguments, etc., etc. Simply don't consider such parent die
11764 as source-level parent of this die (it can't be, the language
11765 doesn't allow it), and break the loop here. */
11766 name
= dwarf2_name (die
, cu
);
11767 parent_name
= dwarf2_name (parent
, cu
);
11768 complaint (&symfile_complaints
,
11769 _("template param type '%s' defined within parent '%s'"),
11770 name
? name
: "<unknown>",
11771 parent_name
? parent_name
: "<unknown>");
11775 switch (parent
->tag
)
11777 case DW_TAG_namespace
:
11778 parent_type
= read_type_die (parent
, cu
);
11779 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
11780 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
11781 Work around this problem here. */
11782 if (cu
->language
== language_cplus
11783 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
11785 /* We give a name to even anonymous namespaces. */
11786 return TYPE_TAG_NAME (parent_type
);
11787 case DW_TAG_class_type
:
11788 case DW_TAG_interface_type
:
11789 case DW_TAG_structure_type
:
11790 case DW_TAG_union_type
:
11791 case DW_TAG_module
:
11792 parent_type
= read_type_die (parent
, cu
);
11793 if (TYPE_TAG_NAME (parent_type
) != NULL
)
11794 return TYPE_TAG_NAME (parent_type
);
11796 /* An anonymous structure is only allowed non-static data
11797 members; no typedefs, no member functions, et cetera.
11798 So it does not need a prefix. */
11800 case DW_TAG_compile_unit
:
11801 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
11802 if (cu
->language
== language_cplus
11803 && dwarf2_per_objfile
->types
.asection
!= NULL
11804 && die
->child
!= NULL
11805 && (die
->tag
== DW_TAG_class_type
11806 || die
->tag
== DW_TAG_structure_type
11807 || die
->tag
== DW_TAG_union_type
))
11809 char *name
= guess_full_die_structure_name (die
, cu
);
11815 return determine_prefix (parent
, cu
);
11819 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
11820 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
11821 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
11822 an obconcat, otherwise allocate storage for the result. The CU argument is
11823 used to determine the language and hence, the appropriate separator. */
11825 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
11828 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
11829 int physname
, struct dwarf2_cu
*cu
)
11831 const char *lead
= "";
11834 if (suffix
== NULL
|| suffix
[0] == '\0'
11835 || prefix
== NULL
|| prefix
[0] == '\0')
11837 else if (cu
->language
== language_java
)
11839 else if (cu
->language
== language_fortran
&& physname
)
11841 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
11842 DW_AT_MIPS_linkage_name is preferred and used instead. */
11850 if (prefix
== NULL
)
11852 if (suffix
== NULL
)
11858 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
11860 strcpy (retval
, lead
);
11861 strcat (retval
, prefix
);
11862 strcat (retval
, sep
);
11863 strcat (retval
, suffix
);
11868 /* We have an obstack. */
11869 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
11873 /* Return sibling of die, NULL if no sibling. */
11875 static struct die_info
*
11876 sibling_die (struct die_info
*die
)
11878 return die
->sibling
;
11881 /* Get name of a die, return NULL if not found. */
11884 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
11885 struct obstack
*obstack
)
11887 if (name
&& cu
->language
== language_cplus
)
11889 char *canon_name
= cp_canonicalize_string (name
);
11891 if (canon_name
!= NULL
)
11893 if (strcmp (canon_name
, name
) != 0)
11894 name
= obsavestring (canon_name
, strlen (canon_name
),
11896 xfree (canon_name
);
11903 /* Get name of a die, return NULL if not found. */
11906 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11908 struct attribute
*attr
;
11910 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11911 if (!attr
|| !DW_STRING (attr
))
11916 case DW_TAG_compile_unit
:
11917 /* Compilation units have a DW_AT_name that is a filename, not
11918 a source language identifier. */
11919 case DW_TAG_enumeration_type
:
11920 case DW_TAG_enumerator
:
11921 /* These tags always have simple identifiers already; no need
11922 to canonicalize them. */
11923 return DW_STRING (attr
);
11925 case DW_TAG_subprogram
:
11926 /* Java constructors will all be named "<init>", so return
11927 the class name when we see this special case. */
11928 if (cu
->language
== language_java
11929 && DW_STRING (attr
) != NULL
11930 && strcmp (DW_STRING (attr
), "<init>") == 0)
11932 struct dwarf2_cu
*spec_cu
= cu
;
11933 struct die_info
*spec_die
;
11935 /* GCJ will output '<init>' for Java constructor names.
11936 For this special case, return the name of the parent class. */
11938 /* GCJ may output suprogram DIEs with AT_specification set.
11939 If so, use the name of the specified DIE. */
11940 spec_die
= die_specification (die
, &spec_cu
);
11941 if (spec_die
!= NULL
)
11942 return dwarf2_name (spec_die
, spec_cu
);
11947 if (die
->tag
== DW_TAG_class_type
)
11948 return dwarf2_name (die
, cu
);
11950 while (die
->tag
!= DW_TAG_compile_unit
);
11954 case DW_TAG_class_type
:
11955 case DW_TAG_interface_type
:
11956 case DW_TAG_structure_type
:
11957 case DW_TAG_union_type
:
11958 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
11959 structures or unions. These were of the form "._%d" in GCC 4.1,
11960 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
11961 and GCC 4.4. We work around this problem by ignoring these. */
11962 if (strncmp (DW_STRING (attr
), "._", 2) == 0
11963 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
11971 if (!DW_STRING_IS_CANONICAL (attr
))
11974 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
11975 &cu
->objfile
->objfile_obstack
);
11976 DW_STRING_IS_CANONICAL (attr
) = 1;
11978 return DW_STRING (attr
);
11981 /* Return the die that this die in an extension of, or NULL if there
11982 is none. *EXT_CU is the CU containing DIE on input, and the CU
11983 containing the return value on output. */
11985 static struct die_info
*
11986 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
11988 struct attribute
*attr
;
11990 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
11994 return follow_die_ref (die
, attr
, ext_cu
);
11997 /* Convert a DIE tag into its string name. */
12000 dwarf_tag_name (unsigned tag
)
12004 case DW_TAG_padding
:
12005 return "DW_TAG_padding";
12006 case DW_TAG_array_type
:
12007 return "DW_TAG_array_type";
12008 case DW_TAG_class_type
:
12009 return "DW_TAG_class_type";
12010 case DW_TAG_entry_point
:
12011 return "DW_TAG_entry_point";
12012 case DW_TAG_enumeration_type
:
12013 return "DW_TAG_enumeration_type";
12014 case DW_TAG_formal_parameter
:
12015 return "DW_TAG_formal_parameter";
12016 case DW_TAG_imported_declaration
:
12017 return "DW_TAG_imported_declaration";
12019 return "DW_TAG_label";
12020 case DW_TAG_lexical_block
:
12021 return "DW_TAG_lexical_block";
12022 case DW_TAG_member
:
12023 return "DW_TAG_member";
12024 case DW_TAG_pointer_type
:
12025 return "DW_TAG_pointer_type";
12026 case DW_TAG_reference_type
:
12027 return "DW_TAG_reference_type";
12028 case DW_TAG_compile_unit
:
12029 return "DW_TAG_compile_unit";
12030 case DW_TAG_string_type
:
12031 return "DW_TAG_string_type";
12032 case DW_TAG_structure_type
:
12033 return "DW_TAG_structure_type";
12034 case DW_TAG_subroutine_type
:
12035 return "DW_TAG_subroutine_type";
12036 case DW_TAG_typedef
:
12037 return "DW_TAG_typedef";
12038 case DW_TAG_union_type
:
12039 return "DW_TAG_union_type";
12040 case DW_TAG_unspecified_parameters
:
12041 return "DW_TAG_unspecified_parameters";
12042 case DW_TAG_variant
:
12043 return "DW_TAG_variant";
12044 case DW_TAG_common_block
:
12045 return "DW_TAG_common_block";
12046 case DW_TAG_common_inclusion
:
12047 return "DW_TAG_common_inclusion";
12048 case DW_TAG_inheritance
:
12049 return "DW_TAG_inheritance";
12050 case DW_TAG_inlined_subroutine
:
12051 return "DW_TAG_inlined_subroutine";
12052 case DW_TAG_module
:
12053 return "DW_TAG_module";
12054 case DW_TAG_ptr_to_member_type
:
12055 return "DW_TAG_ptr_to_member_type";
12056 case DW_TAG_set_type
:
12057 return "DW_TAG_set_type";
12058 case DW_TAG_subrange_type
:
12059 return "DW_TAG_subrange_type";
12060 case DW_TAG_with_stmt
:
12061 return "DW_TAG_with_stmt";
12062 case DW_TAG_access_declaration
:
12063 return "DW_TAG_access_declaration";
12064 case DW_TAG_base_type
:
12065 return "DW_TAG_base_type";
12066 case DW_TAG_catch_block
:
12067 return "DW_TAG_catch_block";
12068 case DW_TAG_const_type
:
12069 return "DW_TAG_const_type";
12070 case DW_TAG_constant
:
12071 return "DW_TAG_constant";
12072 case DW_TAG_enumerator
:
12073 return "DW_TAG_enumerator";
12074 case DW_TAG_file_type
:
12075 return "DW_TAG_file_type";
12076 case DW_TAG_friend
:
12077 return "DW_TAG_friend";
12078 case DW_TAG_namelist
:
12079 return "DW_TAG_namelist";
12080 case DW_TAG_namelist_item
:
12081 return "DW_TAG_namelist_item";
12082 case DW_TAG_packed_type
:
12083 return "DW_TAG_packed_type";
12084 case DW_TAG_subprogram
:
12085 return "DW_TAG_subprogram";
12086 case DW_TAG_template_type_param
:
12087 return "DW_TAG_template_type_param";
12088 case DW_TAG_template_value_param
:
12089 return "DW_TAG_template_value_param";
12090 case DW_TAG_thrown_type
:
12091 return "DW_TAG_thrown_type";
12092 case DW_TAG_try_block
:
12093 return "DW_TAG_try_block";
12094 case DW_TAG_variant_part
:
12095 return "DW_TAG_variant_part";
12096 case DW_TAG_variable
:
12097 return "DW_TAG_variable";
12098 case DW_TAG_volatile_type
:
12099 return "DW_TAG_volatile_type";
12100 case DW_TAG_dwarf_procedure
:
12101 return "DW_TAG_dwarf_procedure";
12102 case DW_TAG_restrict_type
:
12103 return "DW_TAG_restrict_type";
12104 case DW_TAG_interface_type
:
12105 return "DW_TAG_interface_type";
12106 case DW_TAG_namespace
:
12107 return "DW_TAG_namespace";
12108 case DW_TAG_imported_module
:
12109 return "DW_TAG_imported_module";
12110 case DW_TAG_unspecified_type
:
12111 return "DW_TAG_unspecified_type";
12112 case DW_TAG_partial_unit
:
12113 return "DW_TAG_partial_unit";
12114 case DW_TAG_imported_unit
:
12115 return "DW_TAG_imported_unit";
12116 case DW_TAG_condition
:
12117 return "DW_TAG_condition";
12118 case DW_TAG_shared_type
:
12119 return "DW_TAG_shared_type";
12120 case DW_TAG_type_unit
:
12121 return "DW_TAG_type_unit";
12122 case DW_TAG_MIPS_loop
:
12123 return "DW_TAG_MIPS_loop";
12124 case DW_TAG_HP_array_descriptor
:
12125 return "DW_TAG_HP_array_descriptor";
12126 case DW_TAG_format_label
:
12127 return "DW_TAG_format_label";
12128 case DW_TAG_function_template
:
12129 return "DW_TAG_function_template";
12130 case DW_TAG_class_template
:
12131 return "DW_TAG_class_template";
12132 case DW_TAG_GNU_BINCL
:
12133 return "DW_TAG_GNU_BINCL";
12134 case DW_TAG_GNU_EINCL
:
12135 return "DW_TAG_GNU_EINCL";
12136 case DW_TAG_upc_shared_type
:
12137 return "DW_TAG_upc_shared_type";
12138 case DW_TAG_upc_strict_type
:
12139 return "DW_TAG_upc_strict_type";
12140 case DW_TAG_upc_relaxed_type
:
12141 return "DW_TAG_upc_relaxed_type";
12142 case DW_TAG_PGI_kanji_type
:
12143 return "DW_TAG_PGI_kanji_type";
12144 case DW_TAG_PGI_interface_block
:
12145 return "DW_TAG_PGI_interface_block";
12147 return "DW_TAG_<unknown>";
12151 /* Convert a DWARF attribute code into its string name. */
12154 dwarf_attr_name (unsigned attr
)
12158 case DW_AT_sibling
:
12159 return "DW_AT_sibling";
12160 case DW_AT_location
:
12161 return "DW_AT_location";
12163 return "DW_AT_name";
12164 case DW_AT_ordering
:
12165 return "DW_AT_ordering";
12166 case DW_AT_subscr_data
:
12167 return "DW_AT_subscr_data";
12168 case DW_AT_byte_size
:
12169 return "DW_AT_byte_size";
12170 case DW_AT_bit_offset
:
12171 return "DW_AT_bit_offset";
12172 case DW_AT_bit_size
:
12173 return "DW_AT_bit_size";
12174 case DW_AT_element_list
:
12175 return "DW_AT_element_list";
12176 case DW_AT_stmt_list
:
12177 return "DW_AT_stmt_list";
12179 return "DW_AT_low_pc";
12180 case DW_AT_high_pc
:
12181 return "DW_AT_high_pc";
12182 case DW_AT_language
:
12183 return "DW_AT_language";
12185 return "DW_AT_member";
12187 return "DW_AT_discr";
12188 case DW_AT_discr_value
:
12189 return "DW_AT_discr_value";
12190 case DW_AT_visibility
:
12191 return "DW_AT_visibility";
12193 return "DW_AT_import";
12194 case DW_AT_string_length
:
12195 return "DW_AT_string_length";
12196 case DW_AT_common_reference
:
12197 return "DW_AT_common_reference";
12198 case DW_AT_comp_dir
:
12199 return "DW_AT_comp_dir";
12200 case DW_AT_const_value
:
12201 return "DW_AT_const_value";
12202 case DW_AT_containing_type
:
12203 return "DW_AT_containing_type";
12204 case DW_AT_default_value
:
12205 return "DW_AT_default_value";
12207 return "DW_AT_inline";
12208 case DW_AT_is_optional
:
12209 return "DW_AT_is_optional";
12210 case DW_AT_lower_bound
:
12211 return "DW_AT_lower_bound";
12212 case DW_AT_producer
:
12213 return "DW_AT_producer";
12214 case DW_AT_prototyped
:
12215 return "DW_AT_prototyped";
12216 case DW_AT_return_addr
:
12217 return "DW_AT_return_addr";
12218 case DW_AT_start_scope
:
12219 return "DW_AT_start_scope";
12220 case DW_AT_bit_stride
:
12221 return "DW_AT_bit_stride";
12222 case DW_AT_upper_bound
:
12223 return "DW_AT_upper_bound";
12224 case DW_AT_abstract_origin
:
12225 return "DW_AT_abstract_origin";
12226 case DW_AT_accessibility
:
12227 return "DW_AT_accessibility";
12228 case DW_AT_address_class
:
12229 return "DW_AT_address_class";
12230 case DW_AT_artificial
:
12231 return "DW_AT_artificial";
12232 case DW_AT_base_types
:
12233 return "DW_AT_base_types";
12234 case DW_AT_calling_convention
:
12235 return "DW_AT_calling_convention";
12237 return "DW_AT_count";
12238 case DW_AT_data_member_location
:
12239 return "DW_AT_data_member_location";
12240 case DW_AT_decl_column
:
12241 return "DW_AT_decl_column";
12242 case DW_AT_decl_file
:
12243 return "DW_AT_decl_file";
12244 case DW_AT_decl_line
:
12245 return "DW_AT_decl_line";
12246 case DW_AT_declaration
:
12247 return "DW_AT_declaration";
12248 case DW_AT_discr_list
:
12249 return "DW_AT_discr_list";
12250 case DW_AT_encoding
:
12251 return "DW_AT_encoding";
12252 case DW_AT_external
:
12253 return "DW_AT_external";
12254 case DW_AT_frame_base
:
12255 return "DW_AT_frame_base";
12257 return "DW_AT_friend";
12258 case DW_AT_identifier_case
:
12259 return "DW_AT_identifier_case";
12260 case DW_AT_macro_info
:
12261 return "DW_AT_macro_info";
12262 case DW_AT_namelist_items
:
12263 return "DW_AT_namelist_items";
12264 case DW_AT_priority
:
12265 return "DW_AT_priority";
12266 case DW_AT_segment
:
12267 return "DW_AT_segment";
12268 case DW_AT_specification
:
12269 return "DW_AT_specification";
12270 case DW_AT_static_link
:
12271 return "DW_AT_static_link";
12273 return "DW_AT_type";
12274 case DW_AT_use_location
:
12275 return "DW_AT_use_location";
12276 case DW_AT_variable_parameter
:
12277 return "DW_AT_variable_parameter";
12278 case DW_AT_virtuality
:
12279 return "DW_AT_virtuality";
12280 case DW_AT_vtable_elem_location
:
12281 return "DW_AT_vtable_elem_location";
12282 /* DWARF 3 values. */
12283 case DW_AT_allocated
:
12284 return "DW_AT_allocated";
12285 case DW_AT_associated
:
12286 return "DW_AT_associated";
12287 case DW_AT_data_location
:
12288 return "DW_AT_data_location";
12289 case DW_AT_byte_stride
:
12290 return "DW_AT_byte_stride";
12291 case DW_AT_entry_pc
:
12292 return "DW_AT_entry_pc";
12293 case DW_AT_use_UTF8
:
12294 return "DW_AT_use_UTF8";
12295 case DW_AT_extension
:
12296 return "DW_AT_extension";
12298 return "DW_AT_ranges";
12299 case DW_AT_trampoline
:
12300 return "DW_AT_trampoline";
12301 case DW_AT_call_column
:
12302 return "DW_AT_call_column";
12303 case DW_AT_call_file
:
12304 return "DW_AT_call_file";
12305 case DW_AT_call_line
:
12306 return "DW_AT_call_line";
12307 case DW_AT_description
:
12308 return "DW_AT_description";
12309 case DW_AT_binary_scale
:
12310 return "DW_AT_binary_scale";
12311 case DW_AT_decimal_scale
:
12312 return "DW_AT_decimal_scale";
12314 return "DW_AT_small";
12315 case DW_AT_decimal_sign
:
12316 return "DW_AT_decimal_sign";
12317 case DW_AT_digit_count
:
12318 return "DW_AT_digit_count";
12319 case DW_AT_picture_string
:
12320 return "DW_AT_picture_string";
12321 case DW_AT_mutable
:
12322 return "DW_AT_mutable";
12323 case DW_AT_threads_scaled
:
12324 return "DW_AT_threads_scaled";
12325 case DW_AT_explicit
:
12326 return "DW_AT_explicit";
12327 case DW_AT_object_pointer
:
12328 return "DW_AT_object_pointer";
12329 case DW_AT_endianity
:
12330 return "DW_AT_endianity";
12331 case DW_AT_elemental
:
12332 return "DW_AT_elemental";
12334 return "DW_AT_pure";
12335 case DW_AT_recursive
:
12336 return "DW_AT_recursive";
12337 /* DWARF 4 values. */
12338 case DW_AT_signature
:
12339 return "DW_AT_signature";
12340 case DW_AT_linkage_name
:
12341 return "DW_AT_linkage_name";
12342 /* SGI/MIPS extensions. */
12343 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12344 case DW_AT_MIPS_fde
:
12345 return "DW_AT_MIPS_fde";
12347 case DW_AT_MIPS_loop_begin
:
12348 return "DW_AT_MIPS_loop_begin";
12349 case DW_AT_MIPS_tail_loop_begin
:
12350 return "DW_AT_MIPS_tail_loop_begin";
12351 case DW_AT_MIPS_epilog_begin
:
12352 return "DW_AT_MIPS_epilog_begin";
12353 case DW_AT_MIPS_loop_unroll_factor
:
12354 return "DW_AT_MIPS_loop_unroll_factor";
12355 case DW_AT_MIPS_software_pipeline_depth
:
12356 return "DW_AT_MIPS_software_pipeline_depth";
12357 case DW_AT_MIPS_linkage_name
:
12358 return "DW_AT_MIPS_linkage_name";
12359 case DW_AT_MIPS_stride
:
12360 return "DW_AT_MIPS_stride";
12361 case DW_AT_MIPS_abstract_name
:
12362 return "DW_AT_MIPS_abstract_name";
12363 case DW_AT_MIPS_clone_origin
:
12364 return "DW_AT_MIPS_clone_origin";
12365 case DW_AT_MIPS_has_inlines
:
12366 return "DW_AT_MIPS_has_inlines";
12367 /* HP extensions. */
12368 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12369 case DW_AT_HP_block_index
:
12370 return "DW_AT_HP_block_index";
12372 case DW_AT_HP_unmodifiable
:
12373 return "DW_AT_HP_unmodifiable";
12374 case DW_AT_HP_actuals_stmt_list
:
12375 return "DW_AT_HP_actuals_stmt_list";
12376 case DW_AT_HP_proc_per_section
:
12377 return "DW_AT_HP_proc_per_section";
12378 case DW_AT_HP_raw_data_ptr
:
12379 return "DW_AT_HP_raw_data_ptr";
12380 case DW_AT_HP_pass_by_reference
:
12381 return "DW_AT_HP_pass_by_reference";
12382 case DW_AT_HP_opt_level
:
12383 return "DW_AT_HP_opt_level";
12384 case DW_AT_HP_prof_version_id
:
12385 return "DW_AT_HP_prof_version_id";
12386 case DW_AT_HP_opt_flags
:
12387 return "DW_AT_HP_opt_flags";
12388 case DW_AT_HP_cold_region_low_pc
:
12389 return "DW_AT_HP_cold_region_low_pc";
12390 case DW_AT_HP_cold_region_high_pc
:
12391 return "DW_AT_HP_cold_region_high_pc";
12392 case DW_AT_HP_all_variables_modifiable
:
12393 return "DW_AT_HP_all_variables_modifiable";
12394 case DW_AT_HP_linkage_name
:
12395 return "DW_AT_HP_linkage_name";
12396 case DW_AT_HP_prof_flags
:
12397 return "DW_AT_HP_prof_flags";
12398 /* GNU extensions. */
12399 case DW_AT_sf_names
:
12400 return "DW_AT_sf_names";
12401 case DW_AT_src_info
:
12402 return "DW_AT_src_info";
12403 case DW_AT_mac_info
:
12404 return "DW_AT_mac_info";
12405 case DW_AT_src_coords
:
12406 return "DW_AT_src_coords";
12407 case DW_AT_body_begin
:
12408 return "DW_AT_body_begin";
12409 case DW_AT_body_end
:
12410 return "DW_AT_body_end";
12411 case DW_AT_GNU_vector
:
12412 return "DW_AT_GNU_vector";
12413 case DW_AT_GNU_odr_signature
:
12414 return "DW_AT_GNU_odr_signature";
12415 /* VMS extensions. */
12416 case DW_AT_VMS_rtnbeg_pd_address
:
12417 return "DW_AT_VMS_rtnbeg_pd_address";
12418 /* UPC extension. */
12419 case DW_AT_upc_threads_scaled
:
12420 return "DW_AT_upc_threads_scaled";
12421 /* PGI (STMicroelectronics) extensions. */
12422 case DW_AT_PGI_lbase
:
12423 return "DW_AT_PGI_lbase";
12424 case DW_AT_PGI_soffset
:
12425 return "DW_AT_PGI_soffset";
12426 case DW_AT_PGI_lstride
:
12427 return "DW_AT_PGI_lstride";
12429 return "DW_AT_<unknown>";
12433 /* Convert a DWARF value form code into its string name. */
12436 dwarf_form_name (unsigned form
)
12441 return "DW_FORM_addr";
12442 case DW_FORM_block2
:
12443 return "DW_FORM_block2";
12444 case DW_FORM_block4
:
12445 return "DW_FORM_block4";
12446 case DW_FORM_data2
:
12447 return "DW_FORM_data2";
12448 case DW_FORM_data4
:
12449 return "DW_FORM_data4";
12450 case DW_FORM_data8
:
12451 return "DW_FORM_data8";
12452 case DW_FORM_string
:
12453 return "DW_FORM_string";
12454 case DW_FORM_block
:
12455 return "DW_FORM_block";
12456 case DW_FORM_block1
:
12457 return "DW_FORM_block1";
12458 case DW_FORM_data1
:
12459 return "DW_FORM_data1";
12461 return "DW_FORM_flag";
12462 case DW_FORM_sdata
:
12463 return "DW_FORM_sdata";
12465 return "DW_FORM_strp";
12466 case DW_FORM_udata
:
12467 return "DW_FORM_udata";
12468 case DW_FORM_ref_addr
:
12469 return "DW_FORM_ref_addr";
12471 return "DW_FORM_ref1";
12473 return "DW_FORM_ref2";
12475 return "DW_FORM_ref4";
12477 return "DW_FORM_ref8";
12478 case DW_FORM_ref_udata
:
12479 return "DW_FORM_ref_udata";
12480 case DW_FORM_indirect
:
12481 return "DW_FORM_indirect";
12482 case DW_FORM_sec_offset
:
12483 return "DW_FORM_sec_offset";
12484 case DW_FORM_exprloc
:
12485 return "DW_FORM_exprloc";
12486 case DW_FORM_flag_present
:
12487 return "DW_FORM_flag_present";
12489 return "DW_FORM_sig8";
12491 return "DW_FORM_<unknown>";
12495 /* Convert a DWARF stack opcode into its string name. */
12498 dwarf_stack_op_name (unsigned op
)
12503 return "DW_OP_addr";
12505 return "DW_OP_deref";
12506 case DW_OP_const1u
:
12507 return "DW_OP_const1u";
12508 case DW_OP_const1s
:
12509 return "DW_OP_const1s";
12510 case DW_OP_const2u
:
12511 return "DW_OP_const2u";
12512 case DW_OP_const2s
:
12513 return "DW_OP_const2s";
12514 case DW_OP_const4u
:
12515 return "DW_OP_const4u";
12516 case DW_OP_const4s
:
12517 return "DW_OP_const4s";
12518 case DW_OP_const8u
:
12519 return "DW_OP_const8u";
12520 case DW_OP_const8s
:
12521 return "DW_OP_const8s";
12523 return "DW_OP_constu";
12525 return "DW_OP_consts";
12527 return "DW_OP_dup";
12529 return "DW_OP_drop";
12531 return "DW_OP_over";
12533 return "DW_OP_pick";
12535 return "DW_OP_swap";
12537 return "DW_OP_rot";
12539 return "DW_OP_xderef";
12541 return "DW_OP_abs";
12543 return "DW_OP_and";
12545 return "DW_OP_div";
12547 return "DW_OP_minus";
12549 return "DW_OP_mod";
12551 return "DW_OP_mul";
12553 return "DW_OP_neg";
12555 return "DW_OP_not";
12559 return "DW_OP_plus";
12560 case DW_OP_plus_uconst
:
12561 return "DW_OP_plus_uconst";
12563 return "DW_OP_shl";
12565 return "DW_OP_shr";
12567 return "DW_OP_shra";
12569 return "DW_OP_xor";
12571 return "DW_OP_bra";
12585 return "DW_OP_skip";
12587 return "DW_OP_lit0";
12589 return "DW_OP_lit1";
12591 return "DW_OP_lit2";
12593 return "DW_OP_lit3";
12595 return "DW_OP_lit4";
12597 return "DW_OP_lit5";
12599 return "DW_OP_lit6";
12601 return "DW_OP_lit7";
12603 return "DW_OP_lit8";
12605 return "DW_OP_lit9";
12607 return "DW_OP_lit10";
12609 return "DW_OP_lit11";
12611 return "DW_OP_lit12";
12613 return "DW_OP_lit13";
12615 return "DW_OP_lit14";
12617 return "DW_OP_lit15";
12619 return "DW_OP_lit16";
12621 return "DW_OP_lit17";
12623 return "DW_OP_lit18";
12625 return "DW_OP_lit19";
12627 return "DW_OP_lit20";
12629 return "DW_OP_lit21";
12631 return "DW_OP_lit22";
12633 return "DW_OP_lit23";
12635 return "DW_OP_lit24";
12637 return "DW_OP_lit25";
12639 return "DW_OP_lit26";
12641 return "DW_OP_lit27";
12643 return "DW_OP_lit28";
12645 return "DW_OP_lit29";
12647 return "DW_OP_lit30";
12649 return "DW_OP_lit31";
12651 return "DW_OP_reg0";
12653 return "DW_OP_reg1";
12655 return "DW_OP_reg2";
12657 return "DW_OP_reg3";
12659 return "DW_OP_reg4";
12661 return "DW_OP_reg5";
12663 return "DW_OP_reg6";
12665 return "DW_OP_reg7";
12667 return "DW_OP_reg8";
12669 return "DW_OP_reg9";
12671 return "DW_OP_reg10";
12673 return "DW_OP_reg11";
12675 return "DW_OP_reg12";
12677 return "DW_OP_reg13";
12679 return "DW_OP_reg14";
12681 return "DW_OP_reg15";
12683 return "DW_OP_reg16";
12685 return "DW_OP_reg17";
12687 return "DW_OP_reg18";
12689 return "DW_OP_reg19";
12691 return "DW_OP_reg20";
12693 return "DW_OP_reg21";
12695 return "DW_OP_reg22";
12697 return "DW_OP_reg23";
12699 return "DW_OP_reg24";
12701 return "DW_OP_reg25";
12703 return "DW_OP_reg26";
12705 return "DW_OP_reg27";
12707 return "DW_OP_reg28";
12709 return "DW_OP_reg29";
12711 return "DW_OP_reg30";
12713 return "DW_OP_reg31";
12715 return "DW_OP_breg0";
12717 return "DW_OP_breg1";
12719 return "DW_OP_breg2";
12721 return "DW_OP_breg3";
12723 return "DW_OP_breg4";
12725 return "DW_OP_breg5";
12727 return "DW_OP_breg6";
12729 return "DW_OP_breg7";
12731 return "DW_OP_breg8";
12733 return "DW_OP_breg9";
12735 return "DW_OP_breg10";
12737 return "DW_OP_breg11";
12739 return "DW_OP_breg12";
12741 return "DW_OP_breg13";
12743 return "DW_OP_breg14";
12745 return "DW_OP_breg15";
12747 return "DW_OP_breg16";
12749 return "DW_OP_breg17";
12751 return "DW_OP_breg18";
12753 return "DW_OP_breg19";
12755 return "DW_OP_breg20";
12757 return "DW_OP_breg21";
12759 return "DW_OP_breg22";
12761 return "DW_OP_breg23";
12763 return "DW_OP_breg24";
12765 return "DW_OP_breg25";
12767 return "DW_OP_breg26";
12769 return "DW_OP_breg27";
12771 return "DW_OP_breg28";
12773 return "DW_OP_breg29";
12775 return "DW_OP_breg30";
12777 return "DW_OP_breg31";
12779 return "DW_OP_regx";
12781 return "DW_OP_fbreg";
12783 return "DW_OP_bregx";
12785 return "DW_OP_piece";
12786 case DW_OP_deref_size
:
12787 return "DW_OP_deref_size";
12788 case DW_OP_xderef_size
:
12789 return "DW_OP_xderef_size";
12791 return "DW_OP_nop";
12792 /* DWARF 3 extensions. */
12793 case DW_OP_push_object_address
:
12794 return "DW_OP_push_object_address";
12796 return "DW_OP_call2";
12798 return "DW_OP_call4";
12799 case DW_OP_call_ref
:
12800 return "DW_OP_call_ref";
12801 case DW_OP_form_tls_address
:
12802 return "DW_OP_form_tls_address";
12803 case DW_OP_call_frame_cfa
:
12804 return "DW_OP_call_frame_cfa";
12805 case DW_OP_bit_piece
:
12806 return "DW_OP_bit_piece";
12807 /* DWARF 4 extensions. */
12808 case DW_OP_implicit_value
:
12809 return "DW_OP_implicit_value";
12810 case DW_OP_stack_value
:
12811 return "DW_OP_stack_value";
12812 /* GNU extensions. */
12813 case DW_OP_GNU_push_tls_address
:
12814 return "DW_OP_GNU_push_tls_address";
12815 case DW_OP_GNU_uninit
:
12816 return "DW_OP_GNU_uninit";
12817 case DW_OP_GNU_implicit_pointer
:
12818 return "DW_OP_GNU_implicit_pointer";
12825 dwarf_bool_name (unsigned mybool
)
12833 /* Convert a DWARF type code into its string name. */
12836 dwarf_type_encoding_name (unsigned enc
)
12841 return "DW_ATE_void";
12842 case DW_ATE_address
:
12843 return "DW_ATE_address";
12844 case DW_ATE_boolean
:
12845 return "DW_ATE_boolean";
12846 case DW_ATE_complex_float
:
12847 return "DW_ATE_complex_float";
12849 return "DW_ATE_float";
12850 case DW_ATE_signed
:
12851 return "DW_ATE_signed";
12852 case DW_ATE_signed_char
:
12853 return "DW_ATE_signed_char";
12854 case DW_ATE_unsigned
:
12855 return "DW_ATE_unsigned";
12856 case DW_ATE_unsigned_char
:
12857 return "DW_ATE_unsigned_char";
12859 case DW_ATE_imaginary_float
:
12860 return "DW_ATE_imaginary_float";
12861 case DW_ATE_packed_decimal
:
12862 return "DW_ATE_packed_decimal";
12863 case DW_ATE_numeric_string
:
12864 return "DW_ATE_numeric_string";
12865 case DW_ATE_edited
:
12866 return "DW_ATE_edited";
12867 case DW_ATE_signed_fixed
:
12868 return "DW_ATE_signed_fixed";
12869 case DW_ATE_unsigned_fixed
:
12870 return "DW_ATE_unsigned_fixed";
12871 case DW_ATE_decimal_float
:
12872 return "DW_ATE_decimal_float";
12875 return "DW_ATE_UTF";
12876 /* HP extensions. */
12877 case DW_ATE_HP_float80
:
12878 return "DW_ATE_HP_float80";
12879 case DW_ATE_HP_complex_float80
:
12880 return "DW_ATE_HP_complex_float80";
12881 case DW_ATE_HP_float128
:
12882 return "DW_ATE_HP_float128";
12883 case DW_ATE_HP_complex_float128
:
12884 return "DW_ATE_HP_complex_float128";
12885 case DW_ATE_HP_floathpintel
:
12886 return "DW_ATE_HP_floathpintel";
12887 case DW_ATE_HP_imaginary_float80
:
12888 return "DW_ATE_HP_imaginary_float80";
12889 case DW_ATE_HP_imaginary_float128
:
12890 return "DW_ATE_HP_imaginary_float128";
12892 return "DW_ATE_<unknown>";
12896 /* Convert a DWARF call frame info operation to its string name. */
12900 dwarf_cfi_name (unsigned cfi_opc
)
12904 case DW_CFA_advance_loc
:
12905 return "DW_CFA_advance_loc";
12906 case DW_CFA_offset
:
12907 return "DW_CFA_offset";
12908 case DW_CFA_restore
:
12909 return "DW_CFA_restore";
12911 return "DW_CFA_nop";
12912 case DW_CFA_set_loc
:
12913 return "DW_CFA_set_loc";
12914 case DW_CFA_advance_loc1
:
12915 return "DW_CFA_advance_loc1";
12916 case DW_CFA_advance_loc2
:
12917 return "DW_CFA_advance_loc2";
12918 case DW_CFA_advance_loc4
:
12919 return "DW_CFA_advance_loc4";
12920 case DW_CFA_offset_extended
:
12921 return "DW_CFA_offset_extended";
12922 case DW_CFA_restore_extended
:
12923 return "DW_CFA_restore_extended";
12924 case DW_CFA_undefined
:
12925 return "DW_CFA_undefined";
12926 case DW_CFA_same_value
:
12927 return "DW_CFA_same_value";
12928 case DW_CFA_register
:
12929 return "DW_CFA_register";
12930 case DW_CFA_remember_state
:
12931 return "DW_CFA_remember_state";
12932 case DW_CFA_restore_state
:
12933 return "DW_CFA_restore_state";
12934 case DW_CFA_def_cfa
:
12935 return "DW_CFA_def_cfa";
12936 case DW_CFA_def_cfa_register
:
12937 return "DW_CFA_def_cfa_register";
12938 case DW_CFA_def_cfa_offset
:
12939 return "DW_CFA_def_cfa_offset";
12941 case DW_CFA_def_cfa_expression
:
12942 return "DW_CFA_def_cfa_expression";
12943 case DW_CFA_expression
:
12944 return "DW_CFA_expression";
12945 case DW_CFA_offset_extended_sf
:
12946 return "DW_CFA_offset_extended_sf";
12947 case DW_CFA_def_cfa_sf
:
12948 return "DW_CFA_def_cfa_sf";
12949 case DW_CFA_def_cfa_offset_sf
:
12950 return "DW_CFA_def_cfa_offset_sf";
12951 case DW_CFA_val_offset
:
12952 return "DW_CFA_val_offset";
12953 case DW_CFA_val_offset_sf
:
12954 return "DW_CFA_val_offset_sf";
12955 case DW_CFA_val_expression
:
12956 return "DW_CFA_val_expression";
12957 /* SGI/MIPS specific. */
12958 case DW_CFA_MIPS_advance_loc8
:
12959 return "DW_CFA_MIPS_advance_loc8";
12960 /* GNU extensions. */
12961 case DW_CFA_GNU_window_save
:
12962 return "DW_CFA_GNU_window_save";
12963 case DW_CFA_GNU_args_size
:
12964 return "DW_CFA_GNU_args_size";
12965 case DW_CFA_GNU_negative_offset_extended
:
12966 return "DW_CFA_GNU_negative_offset_extended";
12968 return "DW_CFA_<unknown>";
12974 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
12978 print_spaces (indent
, f
);
12979 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
12980 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
12982 if (die
->parent
!= NULL
)
12984 print_spaces (indent
, f
);
12985 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
12986 die
->parent
->offset
);
12989 print_spaces (indent
, f
);
12990 fprintf_unfiltered (f
, " has children: %s\n",
12991 dwarf_bool_name (die
->child
!= NULL
));
12993 print_spaces (indent
, f
);
12994 fprintf_unfiltered (f
, " attributes:\n");
12996 for (i
= 0; i
< die
->num_attrs
; ++i
)
12998 print_spaces (indent
, f
);
12999 fprintf_unfiltered (f
, " %s (%s) ",
13000 dwarf_attr_name (die
->attrs
[i
].name
),
13001 dwarf_form_name (die
->attrs
[i
].form
));
13003 switch (die
->attrs
[i
].form
)
13005 case DW_FORM_ref_addr
:
13007 fprintf_unfiltered (f
, "address: ");
13008 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13010 case DW_FORM_block2
:
13011 case DW_FORM_block4
:
13012 case DW_FORM_block
:
13013 case DW_FORM_block1
:
13014 fprintf_unfiltered (f
, "block: size %d",
13015 DW_BLOCK (&die
->attrs
[i
])->size
);
13017 case DW_FORM_exprloc
:
13018 fprintf_unfiltered (f
, "expression: size %u",
13019 DW_BLOCK (&die
->attrs
[i
])->size
);
13024 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13025 (long) (DW_ADDR (&die
->attrs
[i
])));
13027 case DW_FORM_data1
:
13028 case DW_FORM_data2
:
13029 case DW_FORM_data4
:
13030 case DW_FORM_data8
:
13031 case DW_FORM_udata
:
13032 case DW_FORM_sdata
:
13033 fprintf_unfiltered (f
, "constant: %s",
13034 pulongest (DW_UNSND (&die
->attrs
[i
])));
13036 case DW_FORM_sec_offset
:
13037 fprintf_unfiltered (f
, "section offset: %s",
13038 pulongest (DW_UNSND (&die
->attrs
[i
])));
13041 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13042 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13043 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
13045 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13047 case DW_FORM_string
:
13049 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13050 DW_STRING (&die
->attrs
[i
])
13051 ? DW_STRING (&die
->attrs
[i
]) : "",
13052 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13055 if (DW_UNSND (&die
->attrs
[i
]))
13056 fprintf_unfiltered (f
, "flag: TRUE");
13058 fprintf_unfiltered (f
, "flag: FALSE");
13060 case DW_FORM_flag_present
:
13061 fprintf_unfiltered (f
, "flag: TRUE");
13063 case DW_FORM_indirect
:
13064 /* The reader will have reduced the indirect form to
13065 the "base form" so this form should not occur. */
13066 fprintf_unfiltered (f
,
13067 "unexpected attribute form: DW_FORM_indirect");
13070 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13071 die
->attrs
[i
].form
);
13074 fprintf_unfiltered (f
, "\n");
13079 dump_die_for_error (struct die_info
*die
)
13081 dump_die_shallow (gdb_stderr
, 0, die
);
13085 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13087 int indent
= level
* 4;
13089 gdb_assert (die
!= NULL
);
13091 if (level
>= max_level
)
13094 dump_die_shallow (f
, indent
, die
);
13096 if (die
->child
!= NULL
)
13098 print_spaces (indent
, f
);
13099 fprintf_unfiltered (f
, " Children:");
13100 if (level
+ 1 < max_level
)
13102 fprintf_unfiltered (f
, "\n");
13103 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13107 fprintf_unfiltered (f
,
13108 " [not printed, max nesting level reached]\n");
13112 if (die
->sibling
!= NULL
&& level
> 0)
13114 dump_die_1 (f
, level
, max_level
, die
->sibling
);
13118 /* This is called from the pdie macro in gdbinit.in.
13119 It's not static so gcc will keep a copy callable from gdb. */
13122 dump_die (struct die_info
*die
, int max_level
)
13124 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
13128 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
13132 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
13138 is_ref_attr (struct attribute
*attr
)
13140 switch (attr
->form
)
13142 case DW_FORM_ref_addr
:
13147 case DW_FORM_ref_udata
:
13154 static unsigned int
13155 dwarf2_get_ref_die_offset (struct attribute
*attr
)
13157 if (is_ref_attr (attr
))
13158 return DW_ADDR (attr
);
13160 complaint (&symfile_complaints
,
13161 _("unsupported die ref attribute form: '%s'"),
13162 dwarf_form_name (attr
->form
));
13166 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13167 * the value held by the attribute is not constant. */
13170 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
13172 if (attr
->form
== DW_FORM_sdata
)
13173 return DW_SND (attr
);
13174 else if (attr
->form
== DW_FORM_udata
13175 || attr
->form
== DW_FORM_data1
13176 || attr
->form
== DW_FORM_data2
13177 || attr
->form
== DW_FORM_data4
13178 || attr
->form
== DW_FORM_data8
)
13179 return DW_UNSND (attr
);
13182 complaint (&symfile_complaints
,
13183 _("Attribute value is not a constant (%s)"),
13184 dwarf_form_name (attr
->form
));
13185 return default_value
;
13189 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13190 unit and add it to our queue.
13191 The result is non-zero if PER_CU was queued, otherwise the result is zero
13192 meaning either PER_CU is already queued or it is already loaded. */
13195 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
13196 struct dwarf2_per_cu_data
*per_cu
)
13198 /* We may arrive here during partial symbol reading, if we need full
13199 DIEs to process an unusual case (e.g. template arguments). Do
13200 not queue PER_CU, just tell our caller to load its DIEs. */
13201 if (dwarf2_per_objfile
->reading_partial_symbols
)
13203 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
13208 /* Mark the dependence relation so that we don't flush PER_CU
13210 dwarf2_add_dependence (this_cu
, per_cu
);
13212 /* If it's already on the queue, we have nothing to do. */
13213 if (per_cu
->queued
)
13216 /* If the compilation unit is already loaded, just mark it as
13218 if (per_cu
->cu
!= NULL
)
13220 per_cu
->cu
->last_used
= 0;
13224 /* Add it to the queue. */
13225 queue_comp_unit (per_cu
, this_cu
->objfile
);
13230 /* Follow reference or signature attribute ATTR of SRC_DIE.
13231 On entry *REF_CU is the CU of SRC_DIE.
13232 On exit *REF_CU is the CU of the result. */
13234 static struct die_info
*
13235 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
13236 struct dwarf2_cu
**ref_cu
)
13238 struct die_info
*die
;
13240 if (is_ref_attr (attr
))
13241 die
= follow_die_ref (src_die
, attr
, ref_cu
);
13242 else if (attr
->form
== DW_FORM_sig8
)
13243 die
= follow_die_sig (src_die
, attr
, ref_cu
);
13246 dump_die_for_error (src_die
);
13247 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13248 (*ref_cu
)->objfile
->name
);
13254 /* Follow reference OFFSET.
13255 On entry *REF_CU is the CU of the source die referencing OFFSET.
13256 On exit *REF_CU is the CU of the result.
13257 Returns NULL if OFFSET is invalid. */
13259 static struct die_info
*
13260 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
13262 struct die_info temp_die
;
13263 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
13265 gdb_assert (cu
->per_cu
!= NULL
);
13269 if (cu
->per_cu
->from_debug_types
)
13271 /* .debug_types CUs cannot reference anything outside their CU.
13272 If they need to, they have to reference a signatured type via
13274 if (! offset_in_cu_p (&cu
->header
, offset
))
13277 else if (! offset_in_cu_p (&cu
->header
, offset
))
13279 struct dwarf2_per_cu_data
*per_cu
;
13281 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
13283 /* If necessary, add it to the queue and load its DIEs. */
13284 if (maybe_queue_comp_unit (cu
, per_cu
))
13285 load_full_comp_unit (per_cu
, cu
->objfile
);
13287 target_cu
= per_cu
->cu
;
13289 else if (cu
->dies
== NULL
)
13291 /* We're loading full DIEs during partial symbol reading. */
13292 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
13293 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
13296 *ref_cu
= target_cu
;
13297 temp_die
.offset
= offset
;
13298 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13301 /* Follow reference attribute ATTR of SRC_DIE.
13302 On entry *REF_CU is the CU of SRC_DIE.
13303 On exit *REF_CU is the CU of the result. */
13305 static struct die_info
*
13306 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13307 struct dwarf2_cu
**ref_cu
)
13309 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13310 struct dwarf2_cu
*cu
= *ref_cu
;
13311 struct die_info
*die
;
13313 die
= follow_die_offset (offset
, ref_cu
);
13315 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13316 "at 0x%x [in module %s]"),
13317 offset
, src_die
->offset
, cu
->objfile
->name
);
13322 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13323 value is intended for DW_OP_call*. */
13325 struct dwarf2_locexpr_baton
13326 dwarf2_fetch_die_location_block (unsigned int offset
,
13327 struct dwarf2_per_cu_data
*per_cu
,
13328 CORE_ADDR (*get_frame_pc
) (void *baton
),
13331 struct dwarf2_cu
*cu
= per_cu
->cu
;
13332 struct die_info
*die
;
13333 struct attribute
*attr
;
13334 struct dwarf2_locexpr_baton retval
;
13336 dw2_setup (per_cu
->objfile
);
13338 die
= follow_die_offset (offset
, &cu
);
13340 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13341 offset
, per_cu
->cu
->objfile
->name
);
13343 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13346 /* DWARF: "If there is no such attribute, then there is no effect.". */
13348 retval
.data
= NULL
;
13351 else if (attr_form_is_section_offset (attr
))
13353 struct dwarf2_loclist_baton loclist_baton
;
13354 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
13357 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
13359 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
13361 retval
.size
= size
;
13365 if (!attr_form_is_block (attr
))
13366 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13367 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13368 offset
, per_cu
->cu
->objfile
->name
);
13370 retval
.data
= DW_BLOCK (attr
)->data
;
13371 retval
.size
= DW_BLOCK (attr
)->size
;
13373 retval
.per_cu
= cu
->per_cu
;
13377 /* Follow the signature attribute ATTR in SRC_DIE.
13378 On entry *REF_CU is the CU of SRC_DIE.
13379 On exit *REF_CU is the CU of the result. */
13381 static struct die_info
*
13382 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
13383 struct dwarf2_cu
**ref_cu
)
13385 struct objfile
*objfile
= (*ref_cu
)->objfile
;
13386 struct die_info temp_die
;
13387 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13388 struct dwarf2_cu
*sig_cu
;
13389 struct die_info
*die
;
13391 /* sig_type will be NULL if the signatured type is missing from
13393 if (sig_type
== NULL
)
13394 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13395 "at 0x%x [in module %s]"),
13396 src_die
->offset
, objfile
->name
);
13398 /* If necessary, add it to the queue and load its DIEs. */
13400 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
13401 read_signatured_type (objfile
, sig_type
);
13403 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
13405 sig_cu
= sig_type
->per_cu
.cu
;
13406 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
13407 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
13414 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
13415 "from DIE at 0x%x [in module %s]"),
13416 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
13419 /* Given an offset of a signatured type, return its signatured_type. */
13421 static struct signatured_type
*
13422 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
13424 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
13425 unsigned int length
, initial_length_size
;
13426 unsigned int sig_offset
;
13427 struct signatured_type find_entry
, *type_sig
;
13429 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
13430 sig_offset
= (initial_length_size
13432 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
13433 + 1 /*address_size*/);
13434 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
13435 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
13437 /* This is only used to lookup previously recorded types.
13438 If we didn't find it, it's our bug. */
13439 gdb_assert (type_sig
!= NULL
);
13440 gdb_assert (offset
== type_sig
->offset
);
13445 /* Read in signatured type at OFFSET and build its CU and die(s). */
13448 read_signatured_type_at_offset (struct objfile
*objfile
,
13449 unsigned int offset
)
13451 struct signatured_type
*type_sig
;
13453 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13455 /* We have the section offset, but we need the signature to do the
13456 hash table lookup. */
13457 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
13459 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13461 read_signatured_type (objfile
, type_sig
);
13463 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
13466 /* Read in a signatured type and build its CU and DIEs. */
13469 read_signatured_type (struct objfile
*objfile
,
13470 struct signatured_type
*type_sig
)
13472 gdb_byte
*types_ptr
;
13473 struct die_reader_specs reader_specs
;
13474 struct dwarf2_cu
*cu
;
13475 ULONGEST signature
;
13476 struct cleanup
*back_to
, *free_cu_cleanup
;
13478 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13479 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
13481 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13483 cu
= xmalloc (sizeof (*cu
));
13484 init_one_comp_unit (cu
, objfile
);
13486 type_sig
->per_cu
.cu
= cu
;
13487 cu
->per_cu
= &type_sig
->per_cu
;
13489 /* If an error occurs while loading, release our storage. */
13490 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
13492 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
13493 types_ptr
, objfile
->obfd
);
13494 gdb_assert (signature
== type_sig
->signature
);
13497 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13501 &cu
->comp_unit_obstack
,
13502 hashtab_obstack_allocate
,
13503 dummy_obstack_deallocate
);
13505 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
13506 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
13508 init_cu_die_reader (&reader_specs
, cu
);
13510 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
13513 /* We try not to read any attributes in this function, because not
13514 all objfiles needed for references have been loaded yet, and symbol
13515 table processing isn't initialized. But we have to set the CU language,
13516 or we won't be able to build types correctly. */
13517 prepare_one_comp_unit (cu
, cu
->dies
);
13519 do_cleanups (back_to
);
13521 /* We've successfully allocated this compilation unit. Let our caller
13522 clean it up when finished with it. */
13523 discard_cleanups (free_cu_cleanup
);
13525 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
13526 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
13529 /* Decode simple location descriptions.
13530 Given a pointer to a dwarf block that defines a location, compute
13531 the location and return the value.
13533 NOTE drow/2003-11-18: This function is called in two situations
13534 now: for the address of static or global variables (partial symbols
13535 only) and for offsets into structures which are expected to be
13536 (more or less) constant. The partial symbol case should go away,
13537 and only the constant case should remain. That will let this
13538 function complain more accurately. A few special modes are allowed
13539 without complaint for global variables (for instance, global
13540 register values and thread-local values).
13542 A location description containing no operations indicates that the
13543 object is optimized out. The return value is 0 for that case.
13544 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13545 callers will only want a very basic result and this can become a
13548 Note that stack[0] is unused except as a default error return. */
13551 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
13553 struct objfile
*objfile
= cu
->objfile
;
13555 int size
= blk
->size
;
13556 gdb_byte
*data
= blk
->data
;
13557 CORE_ADDR stack
[64];
13559 unsigned int bytes_read
, unsnd
;
13565 stack
[++stacki
] = 0;
13604 stack
[++stacki
] = op
- DW_OP_lit0
;
13639 stack
[++stacki
] = op
- DW_OP_reg0
;
13641 dwarf2_complex_location_expr_complaint ();
13645 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13647 stack
[++stacki
] = unsnd
;
13649 dwarf2_complex_location_expr_complaint ();
13653 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
13658 case DW_OP_const1u
:
13659 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
13663 case DW_OP_const1s
:
13664 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
13668 case DW_OP_const2u
:
13669 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
13673 case DW_OP_const2s
:
13674 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
13678 case DW_OP_const4u
:
13679 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
13683 case DW_OP_const4s
:
13684 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
13689 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
13695 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
13700 stack
[stacki
+ 1] = stack
[stacki
];
13705 stack
[stacki
- 1] += stack
[stacki
];
13709 case DW_OP_plus_uconst
:
13710 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
13716 stack
[stacki
- 1] -= stack
[stacki
];
13721 /* If we're not the last op, then we definitely can't encode
13722 this using GDB's address_class enum. This is valid for partial
13723 global symbols, although the variable's address will be bogus
13726 dwarf2_complex_location_expr_complaint ();
13729 case DW_OP_GNU_push_tls_address
:
13730 /* The top of the stack has the offset from the beginning
13731 of the thread control block at which the variable is located. */
13732 /* Nothing should follow this operator, so the top of stack would
13734 /* This is valid for partial global symbols, but the variable's
13735 address will be bogus in the psymtab. */
13737 dwarf2_complex_location_expr_complaint ();
13740 case DW_OP_GNU_uninit
:
13745 const char *name
= dwarf_stack_op_name (op
);
13748 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
13751 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
13755 return (stack
[stacki
]);
13758 /* Enforce maximum stack depth of SIZE-1 to avoid writing
13759 outside of the allocated space. Also enforce minimum>0. */
13760 if (stacki
>= ARRAY_SIZE (stack
) - 1)
13762 complaint (&symfile_complaints
,
13763 _("location description stack overflow"));
13769 complaint (&symfile_complaints
,
13770 _("location description stack underflow"));
13774 return (stack
[stacki
]);
13777 /* memory allocation interface */
13779 static struct dwarf_block
*
13780 dwarf_alloc_block (struct dwarf2_cu
*cu
)
13782 struct dwarf_block
*blk
;
13784 blk
= (struct dwarf_block
*)
13785 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
13789 static struct abbrev_info
*
13790 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
13792 struct abbrev_info
*abbrev
;
13794 abbrev
= (struct abbrev_info
*)
13795 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
13796 memset (abbrev
, 0, sizeof (struct abbrev_info
));
13800 static struct die_info
*
13801 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
13803 struct die_info
*die
;
13804 size_t size
= sizeof (struct die_info
);
13807 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
13809 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
13810 memset (die
, 0, sizeof (struct die_info
));
13815 /* Macro support. */
13817 /* Return the full name of file number I in *LH's file name table.
13818 Use COMP_DIR as the name of the current directory of the
13819 compilation. The result is allocated using xmalloc; the caller is
13820 responsible for freeing it. */
13822 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
13824 /* Is the file number a valid index into the line header's file name
13825 table? Remember that file numbers start with one, not zero. */
13826 if (1 <= file
&& file
<= lh
->num_file_names
)
13828 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13830 if (IS_ABSOLUTE_PATH (fe
->name
))
13831 return xstrdup (fe
->name
);
13839 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13845 dir_len
= strlen (dir
);
13846 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
13847 strcpy (full_name
, dir
);
13848 full_name
[dir_len
] = '/';
13849 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
13853 return xstrdup (fe
->name
);
13858 /* The compiler produced a bogus file number. We can at least
13859 record the macro definitions made in the file, even if we
13860 won't be able to find the file by name. */
13861 char fake_name
[80];
13863 sprintf (fake_name
, "<bad macro file number %d>", file
);
13865 complaint (&symfile_complaints
,
13866 _("bad file number in macro information (%d)"),
13869 return xstrdup (fake_name
);
13874 static struct macro_source_file
*
13875 macro_start_file (int file
, int line
,
13876 struct macro_source_file
*current_file
,
13877 const char *comp_dir
,
13878 struct line_header
*lh
, struct objfile
*objfile
)
13880 /* The full name of this source file. */
13881 char *full_name
= file_full_name (file
, lh
, comp_dir
);
13883 /* We don't create a macro table for this compilation unit
13884 at all until we actually get a filename. */
13885 if (! pending_macros
)
13886 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
13887 objfile
->macro_cache
);
13889 if (! current_file
)
13890 /* If we have no current file, then this must be the start_file
13891 directive for the compilation unit's main source file. */
13892 current_file
= macro_set_main (pending_macros
, full_name
);
13894 current_file
= macro_include (current_file
, line
, full_name
);
13898 return current_file
;
13902 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
13903 followed by a null byte. */
13905 copy_string (const char *buf
, int len
)
13907 char *s
= xmalloc (len
+ 1);
13909 memcpy (s
, buf
, len
);
13915 static const char *
13916 consume_improper_spaces (const char *p
, const char *body
)
13920 complaint (&symfile_complaints
,
13921 _("macro definition contains spaces "
13922 "in formal argument list:\n`%s'"),
13934 parse_macro_definition (struct macro_source_file
*file
, int line
,
13939 /* The body string takes one of two forms. For object-like macro
13940 definitions, it should be:
13942 <macro name> " " <definition>
13944 For function-like macro definitions, it should be:
13946 <macro name> "() " <definition>
13948 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
13950 Spaces may appear only where explicitly indicated, and in the
13953 The Dwarf 2 spec says that an object-like macro's name is always
13954 followed by a space, but versions of GCC around March 2002 omit
13955 the space when the macro's definition is the empty string.
13957 The Dwarf 2 spec says that there should be no spaces between the
13958 formal arguments in a function-like macro's formal argument list,
13959 but versions of GCC around March 2002 include spaces after the
13963 /* Find the extent of the macro name. The macro name is terminated
13964 by either a space or null character (for an object-like macro) or
13965 an opening paren (for a function-like macro). */
13966 for (p
= body
; *p
; p
++)
13967 if (*p
== ' ' || *p
== '(')
13970 if (*p
== ' ' || *p
== '\0')
13972 /* It's an object-like macro. */
13973 int name_len
= p
- body
;
13974 char *name
= copy_string (body
, name_len
);
13975 const char *replacement
;
13978 replacement
= body
+ name_len
+ 1;
13981 dwarf2_macro_malformed_definition_complaint (body
);
13982 replacement
= body
+ name_len
;
13985 macro_define_object (file
, line
, name
, replacement
);
13989 else if (*p
== '(')
13991 /* It's a function-like macro. */
13992 char *name
= copy_string (body
, p
- body
);
13995 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
13999 p
= consume_improper_spaces (p
, body
);
14001 /* Parse the formal argument list. */
14002 while (*p
&& *p
!= ')')
14004 /* Find the extent of the current argument name. */
14005 const char *arg_start
= p
;
14007 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14010 if (! *p
|| p
== arg_start
)
14011 dwarf2_macro_malformed_definition_complaint (body
);
14014 /* Make sure argv has room for the new argument. */
14015 if (argc
>= argv_size
)
14018 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14021 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14024 p
= consume_improper_spaces (p
, body
);
14026 /* Consume the comma, if present. */
14031 p
= consume_improper_spaces (p
, body
);
14040 /* Perfectly formed definition, no complaints. */
14041 macro_define_function (file
, line
, name
,
14042 argc
, (const char **) argv
,
14044 else if (*p
== '\0')
14046 /* Complain, but do define it. */
14047 dwarf2_macro_malformed_definition_complaint (body
);
14048 macro_define_function (file
, line
, name
,
14049 argc
, (const char **) argv
,
14053 /* Just complain. */
14054 dwarf2_macro_malformed_definition_complaint (body
);
14057 /* Just complain. */
14058 dwarf2_macro_malformed_definition_complaint (body
);
14064 for (i
= 0; i
< argc
; i
++)
14070 dwarf2_macro_malformed_definition_complaint (body
);
14075 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
14076 char *comp_dir
, bfd
*abfd
,
14077 struct dwarf2_cu
*cu
)
14079 gdb_byte
*mac_ptr
, *mac_end
;
14080 struct macro_source_file
*current_file
= 0;
14081 enum dwarf_macinfo_record_type macinfo_type
;
14082 int at_commandline
;
14084 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14085 &dwarf2_per_objfile
->macinfo
);
14086 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
14088 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
14092 /* First pass: Find the name of the base filename.
14093 This filename is needed in order to process all macros whose definition
14094 (or undefinition) comes from the command line. These macros are defined
14095 before the first DW_MACINFO_start_file entry, and yet still need to be
14096 associated to the base file.
14098 To determine the base file name, we scan the macro definitions until we
14099 reach the first DW_MACINFO_start_file entry. We then initialize
14100 CURRENT_FILE accordingly so that any macro definition found before the
14101 first DW_MACINFO_start_file can still be associated to the base file. */
14103 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14104 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
14105 + dwarf2_per_objfile
->macinfo
.size
;
14109 /* Do we at least have room for a macinfo type byte? */
14110 if (mac_ptr
>= mac_end
)
14112 /* Complaint is printed during the second pass as GDB will probably
14113 stop the first pass earlier upon finding
14114 DW_MACINFO_start_file. */
14118 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14121 switch (macinfo_type
)
14123 /* A zero macinfo type indicates the end of the macro
14128 case DW_MACINFO_define
:
14129 case DW_MACINFO_undef
:
14130 /* Only skip the data by MAC_PTR. */
14132 unsigned int bytes_read
;
14134 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14135 mac_ptr
+= bytes_read
;
14136 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14137 mac_ptr
+= bytes_read
;
14141 case DW_MACINFO_start_file
:
14143 unsigned int bytes_read
;
14146 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14147 mac_ptr
+= bytes_read
;
14148 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14149 mac_ptr
+= bytes_read
;
14151 current_file
= macro_start_file (file
, line
, current_file
,
14152 comp_dir
, lh
, cu
->objfile
);
14156 case DW_MACINFO_end_file
:
14157 /* No data to skip by MAC_PTR. */
14160 case DW_MACINFO_vendor_ext
:
14161 /* Only skip the data by MAC_PTR. */
14163 unsigned int bytes_read
;
14165 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14166 mac_ptr
+= bytes_read
;
14167 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14168 mac_ptr
+= bytes_read
;
14175 } while (macinfo_type
!= 0 && current_file
== NULL
);
14177 /* Second pass: Process all entries.
14179 Use the AT_COMMAND_LINE flag to determine whether we are still processing
14180 command-line macro definitions/undefinitions. This flag is unset when we
14181 reach the first DW_MACINFO_start_file entry. */
14183 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14185 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14186 GDB is still reading the definitions from command line. First
14187 DW_MACINFO_start_file will need to be ignored as it was already executed
14188 to create CURRENT_FILE for the main source holding also the command line
14189 definitions. On first met DW_MACINFO_start_file this flag is reset to
14190 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14192 at_commandline
= 1;
14196 /* Do we at least have room for a macinfo type byte? */
14197 if (mac_ptr
>= mac_end
)
14199 dwarf2_macros_too_long_complaint ();
14203 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14206 switch (macinfo_type
)
14208 /* A zero macinfo type indicates the end of the macro
14213 case DW_MACINFO_define
:
14214 case DW_MACINFO_undef
:
14216 unsigned int bytes_read
;
14220 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14221 mac_ptr
+= bytes_read
;
14222 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14223 mac_ptr
+= bytes_read
;
14225 if (! current_file
)
14227 /* DWARF violation as no main source is present. */
14228 complaint (&symfile_complaints
,
14229 _("debug info with no main source gives macro %s "
14231 macinfo_type
== DW_MACINFO_define
?
14233 macinfo_type
== DW_MACINFO_undef
?
14234 _("undefinition") :
14235 _("something-or-other"), line
, body
);
14238 if ((line
== 0 && !at_commandline
)
14239 || (line
!= 0 && at_commandline
))
14240 complaint (&symfile_complaints
,
14241 _("debug info gives %s macro %s with %s line %d: %s"),
14242 at_commandline
? _("command-line") : _("in-file"),
14243 macinfo_type
== DW_MACINFO_define
?
14245 macinfo_type
== DW_MACINFO_undef
?
14246 _("undefinition") :
14247 _("something-or-other"),
14248 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
14250 if (macinfo_type
== DW_MACINFO_define
)
14251 parse_macro_definition (current_file
, line
, body
);
14252 else if (macinfo_type
== DW_MACINFO_undef
)
14253 macro_undef (current_file
, line
, body
);
14257 case DW_MACINFO_start_file
:
14259 unsigned int bytes_read
;
14262 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14263 mac_ptr
+= bytes_read
;
14264 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14265 mac_ptr
+= bytes_read
;
14267 if ((line
== 0 && !at_commandline
)
14268 || (line
!= 0 && at_commandline
))
14269 complaint (&symfile_complaints
,
14270 _("debug info gives source %d included "
14271 "from %s at %s line %d"),
14272 file
, at_commandline
? _("command-line") : _("file"),
14273 line
== 0 ? _("zero") : _("non-zero"), line
);
14275 if (at_commandline
)
14277 /* This DW_MACINFO_start_file was executed in the pass one. */
14278 at_commandline
= 0;
14281 current_file
= macro_start_file (file
, line
,
14282 current_file
, comp_dir
,
14287 case DW_MACINFO_end_file
:
14288 if (! current_file
)
14289 complaint (&symfile_complaints
,
14290 _("macro debug info has an unmatched "
14291 "`close_file' directive"));
14294 current_file
= current_file
->included_by
;
14295 if (! current_file
)
14297 enum dwarf_macinfo_record_type next_type
;
14299 /* GCC circa March 2002 doesn't produce the zero
14300 type byte marking the end of the compilation
14301 unit. Complain if it's not there, but exit no
14304 /* Do we at least have room for a macinfo type byte? */
14305 if (mac_ptr
>= mac_end
)
14307 dwarf2_macros_too_long_complaint ();
14311 /* We don't increment mac_ptr here, so this is just
14313 next_type
= read_1_byte (abfd
, mac_ptr
);
14314 if (next_type
!= 0)
14315 complaint (&symfile_complaints
,
14316 _("no terminating 0-type entry for "
14317 "macros in `.debug_macinfo' section"));
14324 case DW_MACINFO_vendor_ext
:
14326 unsigned int bytes_read
;
14329 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14330 mac_ptr
+= bytes_read
;
14331 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14332 mac_ptr
+= bytes_read
;
14334 /* We don't recognize any vendor extensions. */
14338 } while (macinfo_type
!= 0);
14341 /* Check if the attribute's form is a DW_FORM_block*
14342 if so return true else false. */
14344 attr_form_is_block (struct attribute
*attr
)
14346 return (attr
== NULL
? 0 :
14347 attr
->form
== DW_FORM_block1
14348 || attr
->form
== DW_FORM_block2
14349 || attr
->form
== DW_FORM_block4
14350 || attr
->form
== DW_FORM_block
14351 || attr
->form
== DW_FORM_exprloc
);
14354 /* Return non-zero if ATTR's value is a section offset --- classes
14355 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14356 You may use DW_UNSND (attr) to retrieve such offsets.
14358 Section 7.5.4, "Attribute Encodings", explains that no attribute
14359 may have a value that belongs to more than one of these classes; it
14360 would be ambiguous if we did, because we use the same forms for all
14363 attr_form_is_section_offset (struct attribute
*attr
)
14365 return (attr
->form
== DW_FORM_data4
14366 || attr
->form
== DW_FORM_data8
14367 || attr
->form
== DW_FORM_sec_offset
);
14371 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14372 zero otherwise. When this function returns true, you can apply
14373 dwarf2_get_attr_constant_value to it.
14375 However, note that for some attributes you must check
14376 attr_form_is_section_offset before using this test. DW_FORM_data4
14377 and DW_FORM_data8 are members of both the constant class, and of
14378 the classes that contain offsets into other debug sections
14379 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14380 that, if an attribute's can be either a constant or one of the
14381 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14382 taken as section offsets, not constants. */
14384 attr_form_is_constant (struct attribute
*attr
)
14386 switch (attr
->form
)
14388 case DW_FORM_sdata
:
14389 case DW_FORM_udata
:
14390 case DW_FORM_data1
:
14391 case DW_FORM_data2
:
14392 case DW_FORM_data4
:
14393 case DW_FORM_data8
:
14400 /* A helper function that fills in a dwarf2_loclist_baton. */
14403 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
14404 struct dwarf2_loclist_baton
*baton
,
14405 struct attribute
*attr
)
14407 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14408 &dwarf2_per_objfile
->loc
);
14410 baton
->per_cu
= cu
->per_cu
;
14411 gdb_assert (baton
->per_cu
);
14412 /* We don't know how long the location list is, but make sure we
14413 don't run off the edge of the section. */
14414 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
14415 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
14416 baton
->base_address
= cu
->base_address
;
14420 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
14421 struct dwarf2_cu
*cu
)
14423 if (attr_form_is_section_offset (attr
)
14424 /* ".debug_loc" may not exist at all, or the offset may be outside
14425 the section. If so, fall through to the complaint in the
14427 && DW_UNSND (attr
) < dwarf2_section_size (dwarf2_per_objfile
->objfile
,
14428 &dwarf2_per_objfile
->loc
))
14430 struct dwarf2_loclist_baton
*baton
;
14432 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14433 sizeof (struct dwarf2_loclist_baton
));
14435 fill_in_loclist_baton (cu
, baton
, attr
);
14437 if (cu
->base_known
== 0)
14438 complaint (&symfile_complaints
,
14439 _("Location list used without "
14440 "specifying the CU base address."));
14442 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
14443 SYMBOL_LOCATION_BATON (sym
) = baton
;
14447 struct dwarf2_locexpr_baton
*baton
;
14449 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14450 sizeof (struct dwarf2_locexpr_baton
));
14451 baton
->per_cu
= cu
->per_cu
;
14452 gdb_assert (baton
->per_cu
);
14454 if (attr_form_is_block (attr
))
14456 /* Note that we're just copying the block's data pointer
14457 here, not the actual data. We're still pointing into the
14458 info_buffer for SYM's objfile; right now we never release
14459 that buffer, but when we do clean up properly this may
14461 baton
->size
= DW_BLOCK (attr
)->size
;
14462 baton
->data
= DW_BLOCK (attr
)->data
;
14466 dwarf2_invalid_attrib_class_complaint ("location description",
14467 SYMBOL_NATURAL_NAME (sym
));
14469 baton
->data
= NULL
;
14472 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14473 SYMBOL_LOCATION_BATON (sym
) = baton
;
14477 /* Return the OBJFILE associated with the compilation unit CU. If CU
14478 came from a separate debuginfo file, then the master objfile is
14482 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
14484 struct objfile
*objfile
= per_cu
->objfile
;
14486 /* Return the master objfile, so that we can report and look up the
14487 correct file containing this variable. */
14488 if (objfile
->separate_debug_objfile_backlink
)
14489 objfile
= objfile
->separate_debug_objfile_backlink
;
14494 /* Return the address size given in the compilation unit header for CU. */
14497 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
14500 return per_cu
->cu
->header
.addr_size
;
14503 /* If the CU is not currently read in, we re-read its header. */
14504 struct objfile
*objfile
= per_cu
->objfile
;
14505 struct dwarf2_per_objfile
*per_objfile
14506 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14507 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14508 struct comp_unit_head cu_header
;
14510 memset (&cu_header
, 0, sizeof cu_header
);
14511 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14512 return cu_header
.addr_size
;
14516 /* Return the offset size given in the compilation unit header for CU. */
14519 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
14522 return per_cu
->cu
->header
.offset_size
;
14525 /* If the CU is not currently read in, we re-read its header. */
14526 struct objfile
*objfile
= per_cu
->objfile
;
14527 struct dwarf2_per_objfile
*per_objfile
14528 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14529 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14530 struct comp_unit_head cu_header
;
14532 memset (&cu_header
, 0, sizeof cu_header
);
14533 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14534 return cu_header
.offset_size
;
14538 /* Return the text offset of the CU. The returned offset comes from
14539 this CU's objfile. If this objfile came from a separate debuginfo
14540 file, then the offset may be different from the corresponding
14541 offset in the parent objfile. */
14544 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
14546 struct objfile
*objfile
= per_cu
->objfile
;
14548 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14551 /* Locate the .debug_info compilation unit from CU's objfile which contains
14552 the DIE at OFFSET. Raises an error on failure. */
14554 static struct dwarf2_per_cu_data
*
14555 dwarf2_find_containing_comp_unit (unsigned int offset
,
14556 struct objfile
*objfile
)
14558 struct dwarf2_per_cu_data
*this_cu
;
14562 high
= dwarf2_per_objfile
->n_comp_units
- 1;
14565 int mid
= low
+ (high
- low
) / 2;
14567 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
14572 gdb_assert (low
== high
);
14573 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
14576 error (_("Dwarf Error: could not find partial DIE containing "
14577 "offset 0x%lx [in module %s]"),
14578 (long) offset
, bfd_get_filename (objfile
->obfd
));
14580 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
14581 return dwarf2_per_objfile
->all_comp_units
[low
-1];
14585 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
14586 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
14587 && offset
>= this_cu
->offset
+ this_cu
->length
)
14588 error (_("invalid dwarf2 offset %u"), offset
);
14589 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
14594 /* Locate the compilation unit from OBJFILE which is located at exactly
14595 OFFSET. Raises an error on failure. */
14597 static struct dwarf2_per_cu_data
*
14598 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
14600 struct dwarf2_per_cu_data
*this_cu
;
14602 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
14603 if (this_cu
->offset
!= offset
)
14604 error (_("no compilation unit with offset %u."), offset
);
14608 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
14611 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
14613 memset (cu
, 0, sizeof (*cu
));
14614 cu
->objfile
= objfile
;
14615 obstack_init (&cu
->comp_unit_obstack
);
14618 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
14621 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
14623 struct attribute
*attr
;
14625 /* Set the language we're debugging. */
14626 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
14628 set_cu_language (DW_UNSND (attr
), cu
);
14630 set_cu_language (language_minimal
, cu
);
14633 /* Release one cached compilation unit, CU. We unlink it from the tree
14634 of compilation units, but we don't remove it from the read_in_chain;
14635 the caller is responsible for that.
14636 NOTE: DATA is a void * because this function is also used as a
14637 cleanup routine. */
14640 free_one_comp_unit (void *data
)
14642 struct dwarf2_cu
*cu
= data
;
14644 if (cu
->per_cu
!= NULL
)
14645 cu
->per_cu
->cu
= NULL
;
14648 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14653 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14654 when we're finished with it. We can't free the pointer itself, but be
14655 sure to unlink it from the cache. Also release any associated storage
14656 and perform cache maintenance.
14658 Only used during partial symbol parsing. */
14661 free_stack_comp_unit (void *data
)
14663 struct dwarf2_cu
*cu
= data
;
14665 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14666 cu
->partial_dies
= NULL
;
14668 if (cu
->per_cu
!= NULL
)
14670 /* This compilation unit is on the stack in our caller, so we
14671 should not xfree it. Just unlink it. */
14672 cu
->per_cu
->cu
= NULL
;
14675 /* If we had a per-cu pointer, then we may have other compilation
14676 units loaded, so age them now. */
14677 age_cached_comp_units ();
14681 /* Free all cached compilation units. */
14684 free_cached_comp_units (void *data
)
14686 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14688 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14689 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14690 while (per_cu
!= NULL
)
14692 struct dwarf2_per_cu_data
*next_cu
;
14694 next_cu
= per_cu
->cu
->read_in_chain
;
14696 free_one_comp_unit (per_cu
->cu
);
14697 *last_chain
= next_cu
;
14703 /* Increase the age counter on each cached compilation unit, and free
14704 any that are too old. */
14707 age_cached_comp_units (void)
14709 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14711 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
14712 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14713 while (per_cu
!= NULL
)
14715 per_cu
->cu
->last_used
++;
14716 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
14717 dwarf2_mark (per_cu
->cu
);
14718 per_cu
= per_cu
->cu
->read_in_chain
;
14721 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14722 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14723 while (per_cu
!= NULL
)
14725 struct dwarf2_per_cu_data
*next_cu
;
14727 next_cu
= per_cu
->cu
->read_in_chain
;
14729 if (!per_cu
->cu
->mark
)
14731 free_one_comp_unit (per_cu
->cu
);
14732 *last_chain
= next_cu
;
14735 last_chain
= &per_cu
->cu
->read_in_chain
;
14741 /* Remove a single compilation unit from the cache. */
14744 free_one_cached_comp_unit (void *target_cu
)
14746 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14748 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14749 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14750 while (per_cu
!= NULL
)
14752 struct dwarf2_per_cu_data
*next_cu
;
14754 next_cu
= per_cu
->cu
->read_in_chain
;
14756 if (per_cu
->cu
== target_cu
)
14758 free_one_comp_unit (per_cu
->cu
);
14759 *last_chain
= next_cu
;
14763 last_chain
= &per_cu
->cu
->read_in_chain
;
14769 /* Release all extra memory associated with OBJFILE. */
14772 dwarf2_free_objfile (struct objfile
*objfile
)
14774 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14776 if (dwarf2_per_objfile
== NULL
)
14779 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
14780 free_cached_comp_units (NULL
);
14782 if (dwarf2_per_objfile
->quick_file_names_table
)
14783 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
14785 /* Everything else should be on the objfile obstack. */
14788 /* A pair of DIE offset and GDB type pointer. We store these
14789 in a hash table separate from the DIEs, and preserve them
14790 when the DIEs are flushed out of cache. */
14792 struct dwarf2_offset_and_type
14794 unsigned int offset
;
14798 /* Hash function for a dwarf2_offset_and_type. */
14801 offset_and_type_hash (const void *item
)
14803 const struct dwarf2_offset_and_type
*ofs
= item
;
14805 return ofs
->offset
;
14808 /* Equality function for a dwarf2_offset_and_type. */
14811 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
14813 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
14814 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
14816 return ofs_lhs
->offset
== ofs_rhs
->offset
;
14819 /* Set the type associated with DIE to TYPE. Save it in CU's hash
14820 table if necessary. For convenience, return TYPE.
14822 The DIEs reading must have careful ordering to:
14823 * Not cause infite loops trying to read in DIEs as a prerequisite for
14824 reading current DIE.
14825 * Not trying to dereference contents of still incompletely read in types
14826 while reading in other DIEs.
14827 * Enable referencing still incompletely read in types just by a pointer to
14828 the type without accessing its fields.
14830 Therefore caller should follow these rules:
14831 * Try to fetch any prerequisite types we may need to build this DIE type
14832 before building the type and calling set_die_type.
14833 * After building type call set_die_type for current DIE as soon as
14834 possible before fetching more types to complete the current type.
14835 * Make the type as complete as possible before fetching more types. */
14837 static struct type
*
14838 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14840 struct dwarf2_offset_and_type
**slot
, ofs
;
14841 struct objfile
*objfile
= cu
->objfile
;
14842 htab_t
*type_hash_ptr
;
14844 /* For Ada types, make sure that the gnat-specific data is always
14845 initialized (if not already set). There are a few types where
14846 we should not be doing so, because the type-specific area is
14847 already used to hold some other piece of info (eg: TYPE_CODE_FLT
14848 where the type-specific area is used to store the floatformat).
14849 But this is not a problem, because the gnat-specific information
14850 is actually not needed for these types. */
14851 if (need_gnat_info (cu
)
14852 && TYPE_CODE (type
) != TYPE_CODE_FUNC
14853 && TYPE_CODE (type
) != TYPE_CODE_FLT
14854 && !HAVE_GNAT_AUX_INFO (type
))
14855 INIT_GNAT_SPECIFIC (type
);
14857 if (cu
->per_cu
->from_debug_types
)
14858 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
14860 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
14862 if (*type_hash_ptr
== NULL
)
14865 = htab_create_alloc_ex (127,
14866 offset_and_type_hash
,
14867 offset_and_type_eq
,
14869 &objfile
->objfile_obstack
,
14870 hashtab_obstack_allocate
,
14871 dummy_obstack_deallocate
);
14874 ofs
.offset
= die
->offset
;
14876 slot
= (struct dwarf2_offset_and_type
**)
14877 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
14879 complaint (&symfile_complaints
,
14880 _("A problem internal to GDB: DIE 0x%x has type already set"),
14882 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
14887 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
14888 table, or return NULL if the die does not have a saved type. */
14890 static struct type
*
14891 get_die_type_at_offset (unsigned int offset
,
14892 struct dwarf2_per_cu_data
*per_cu
)
14894 struct dwarf2_offset_and_type
*slot
, ofs
;
14897 if (per_cu
->from_debug_types
)
14898 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
14900 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
14901 if (type_hash
== NULL
)
14904 ofs
.offset
= offset
;
14905 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
14912 /* Look up the type for DIE in the appropriate type_hash table,
14913 or return NULL if DIE does not have a saved type. */
14915 static struct type
*
14916 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14918 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
14921 /* Add a dependence relationship from CU to REF_PER_CU. */
14924 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
14925 struct dwarf2_per_cu_data
*ref_per_cu
)
14929 if (cu
->dependencies
== NULL
)
14931 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
14932 NULL
, &cu
->comp_unit_obstack
,
14933 hashtab_obstack_allocate
,
14934 dummy_obstack_deallocate
);
14936 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
14938 *slot
= ref_per_cu
;
14941 /* Subroutine of dwarf2_mark to pass to htab_traverse.
14942 Set the mark field in every compilation unit in the
14943 cache that we must keep because we are keeping CU. */
14946 dwarf2_mark_helper (void **slot
, void *data
)
14948 struct dwarf2_per_cu_data
*per_cu
;
14950 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
14951 if (per_cu
->cu
->mark
)
14953 per_cu
->cu
->mark
= 1;
14955 if (per_cu
->cu
->dependencies
!= NULL
)
14956 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14961 /* Set the mark field in CU and in every other compilation unit in the
14962 cache that we must keep because we are keeping CU. */
14965 dwarf2_mark (struct dwarf2_cu
*cu
)
14970 if (cu
->dependencies
!= NULL
)
14971 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14975 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
14979 per_cu
->cu
->mark
= 0;
14980 per_cu
= per_cu
->cu
->read_in_chain
;
14984 /* Trivial hash function for partial_die_info: the hash value of a DIE
14985 is its offset in .debug_info for this objfile. */
14988 partial_die_hash (const void *item
)
14990 const struct partial_die_info
*part_die
= item
;
14992 return part_die
->offset
;
14995 /* Trivial comparison function for partial_die_info structures: two DIEs
14996 are equal if they have the same offset. */
14999 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
15001 const struct partial_die_info
*part_die_lhs
= item_lhs
;
15002 const struct partial_die_info
*part_die_rhs
= item_rhs
;
15004 return part_die_lhs
->offset
== part_die_rhs
->offset
;
15007 static struct cmd_list_element
*set_dwarf2_cmdlist
;
15008 static struct cmd_list_element
*show_dwarf2_cmdlist
;
15011 set_dwarf2_cmd (char *args
, int from_tty
)
15013 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
15017 show_dwarf2_cmd (char *args
, int from_tty
)
15019 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
15022 /* If section described by INFO was mmapped, munmap it now. */
15025 munmap_section_buffer (struct dwarf2_section_info
*info
)
15027 if (info
->was_mmapped
)
15030 intptr_t begin
= (intptr_t) info
->buffer
;
15031 intptr_t map_begin
= begin
& ~(pagesize
- 1);
15032 size_t map_length
= info
->size
+ begin
- map_begin
;
15034 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
15036 /* Without HAVE_MMAP, we should never be here to begin with. */
15037 gdb_assert_not_reached ("no mmap support");
15042 /* munmap debug sections for OBJFILE, if necessary. */
15045 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
15047 struct dwarf2_per_objfile
*data
= d
;
15049 /* This is sorted according to the order they're defined in to make it easier
15050 to keep in sync. */
15051 munmap_section_buffer (&data
->info
);
15052 munmap_section_buffer (&data
->abbrev
);
15053 munmap_section_buffer (&data
->line
);
15054 munmap_section_buffer (&data
->loc
);
15055 munmap_section_buffer (&data
->macinfo
);
15056 munmap_section_buffer (&data
->str
);
15057 munmap_section_buffer (&data
->ranges
);
15058 munmap_section_buffer (&data
->types
);
15059 munmap_section_buffer (&data
->frame
);
15060 munmap_section_buffer (&data
->eh_frame
);
15061 munmap_section_buffer (&data
->gdb_index
);
15065 /* The "save gdb-index" command. */
15067 /* The contents of the hash table we create when building the string
15069 struct strtab_entry
15071 offset_type offset
;
15075 /* Hash function for a strtab_entry. */
15078 hash_strtab_entry (const void *e
)
15080 const struct strtab_entry
*entry
= e
;
15081 return mapped_index_string_hash (entry
->str
);
15084 /* Equality function for a strtab_entry. */
15087 eq_strtab_entry (const void *a
, const void *b
)
15089 const struct strtab_entry
*ea
= a
;
15090 const struct strtab_entry
*eb
= b
;
15091 return !strcmp (ea
->str
, eb
->str
);
15094 /* Create a strtab_entry hash table. */
15097 create_strtab (void)
15099 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
15100 xfree
, xcalloc
, xfree
);
15103 /* Add a string to the constant pool. Return the string's offset in
15107 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
15110 struct strtab_entry entry
;
15111 struct strtab_entry
*result
;
15114 slot
= htab_find_slot (table
, &entry
, INSERT
);
15119 result
= XNEW (struct strtab_entry
);
15120 result
->offset
= obstack_object_size (cpool
);
15122 obstack_grow_str0 (cpool
, str
);
15125 return result
->offset
;
15128 /* An entry in the symbol table. */
15129 struct symtab_index_entry
15131 /* The name of the symbol. */
15133 /* The offset of the name in the constant pool. */
15134 offset_type index_offset
;
15135 /* A sorted vector of the indices of all the CUs that hold an object
15137 VEC (offset_type
) *cu_indices
;
15140 /* The symbol table. This is a power-of-2-sized hash table. */
15141 struct mapped_symtab
15143 offset_type n_elements
;
15145 struct symtab_index_entry
**data
;
15148 /* Hash function for a symtab_index_entry. */
15151 hash_symtab_entry (const void *e
)
15153 const struct symtab_index_entry
*entry
= e
;
15154 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
15155 sizeof (offset_type
) * VEC_length (offset_type
,
15156 entry
->cu_indices
),
15160 /* Equality function for a symtab_index_entry. */
15163 eq_symtab_entry (const void *a
, const void *b
)
15165 const struct symtab_index_entry
*ea
= a
;
15166 const struct symtab_index_entry
*eb
= b
;
15167 int len
= VEC_length (offset_type
, ea
->cu_indices
);
15168 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
15170 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
15171 VEC_address (offset_type
, eb
->cu_indices
),
15172 sizeof (offset_type
) * len
);
15175 /* Destroy a symtab_index_entry. */
15178 delete_symtab_entry (void *p
)
15180 struct symtab_index_entry
*entry
= p
;
15181 VEC_free (offset_type
, entry
->cu_indices
);
15185 /* Create a hash table holding symtab_index_entry objects. */
15188 create_symbol_hash_table (void)
15190 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
15191 delete_symtab_entry
, xcalloc
, xfree
);
15194 /* Create a new mapped symtab object. */
15196 static struct mapped_symtab
*
15197 create_mapped_symtab (void)
15199 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
15200 symtab
->n_elements
= 0;
15201 symtab
->size
= 1024;
15202 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15206 /* Destroy a mapped_symtab. */
15209 cleanup_mapped_symtab (void *p
)
15211 struct mapped_symtab
*symtab
= p
;
15212 /* The contents of the array are freed when the other hash table is
15214 xfree (symtab
->data
);
15218 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
15221 static struct symtab_index_entry
**
15222 find_slot (struct mapped_symtab
*symtab
, const char *name
)
15224 offset_type index
, step
, hash
= mapped_index_string_hash (name
);
15226 index
= hash
& (symtab
->size
- 1);
15227 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
15231 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
15232 return &symtab
->data
[index
];
15233 index
= (index
+ step
) & (symtab
->size
- 1);
15237 /* Expand SYMTAB's hash table. */
15240 hash_expand (struct mapped_symtab
*symtab
)
15242 offset_type old_size
= symtab
->size
;
15244 struct symtab_index_entry
**old_entries
= symtab
->data
;
15247 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15249 for (i
= 0; i
< old_size
; ++i
)
15251 if (old_entries
[i
])
15253 struct symtab_index_entry
**slot
= find_slot (symtab
,
15254 old_entries
[i
]->name
);
15255 *slot
= old_entries
[i
];
15259 xfree (old_entries
);
15262 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
15263 is the index of the CU in which the symbol appears. */
15266 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
15267 offset_type cu_index
)
15269 struct symtab_index_entry
**slot
;
15271 ++symtab
->n_elements
;
15272 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
15273 hash_expand (symtab
);
15275 slot
= find_slot (symtab
, name
);
15278 *slot
= XNEW (struct symtab_index_entry
);
15279 (*slot
)->name
= name
;
15280 (*slot
)->cu_indices
= NULL
;
15282 /* Don't push an index twice. Due to how we add entries we only
15283 have to check the last one. */
15284 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
15285 || VEC_length (offset_type
, (*slot
)->cu_indices
) != cu_index
)
15286 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
15289 /* Add a vector of indices to the constant pool. */
15292 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
15293 struct symtab_index_entry
*entry
)
15297 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
15300 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
15301 offset_type val
= MAYBE_SWAP (len
);
15306 entry
->index_offset
= obstack_object_size (cpool
);
15308 obstack_grow (cpool
, &val
, sizeof (val
));
15310 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
15313 val
= MAYBE_SWAP (iter
);
15314 obstack_grow (cpool
, &val
, sizeof (val
));
15319 struct symtab_index_entry
*old_entry
= *slot
;
15320 entry
->index_offset
= old_entry
->index_offset
;
15323 return entry
->index_offset
;
15326 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15327 constant pool entries going into the obstack CPOOL. */
15330 write_hash_table (struct mapped_symtab
*symtab
,
15331 struct obstack
*output
, struct obstack
*cpool
)
15334 htab_t symbol_hash_table
;
15337 symbol_hash_table
= create_symbol_hash_table ();
15338 str_table
= create_strtab ();
15340 /* We add all the index vectors to the constant pool first, to
15341 ensure alignment is ok. */
15342 for (i
= 0; i
< symtab
->size
; ++i
)
15344 if (symtab
->data
[i
])
15345 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
15348 /* Now write out the hash table. */
15349 for (i
= 0; i
< symtab
->size
; ++i
)
15351 offset_type str_off
, vec_off
;
15353 if (symtab
->data
[i
])
15355 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
15356 vec_off
= symtab
->data
[i
]->index_offset
;
15360 /* While 0 is a valid constant pool index, it is not valid
15361 to have 0 for both offsets. */
15366 str_off
= MAYBE_SWAP (str_off
);
15367 vec_off
= MAYBE_SWAP (vec_off
);
15369 obstack_grow (output
, &str_off
, sizeof (str_off
));
15370 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
15373 htab_delete (str_table
);
15374 htab_delete (symbol_hash_table
);
15377 /* Struct to map psymtab to CU index in the index file. */
15378 struct psymtab_cu_index_map
15380 struct partial_symtab
*psymtab
;
15381 unsigned int cu_index
;
15385 hash_psymtab_cu_index (const void *item
)
15387 const struct psymtab_cu_index_map
*map
= item
;
15389 return htab_hash_pointer (map
->psymtab
);
15393 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
15395 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
15396 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
15398 return lhs
->psymtab
== rhs
->psymtab
;
15401 /* Helper struct for building the address table. */
15402 struct addrmap_index_data
15404 struct objfile
*objfile
;
15405 struct obstack
*addr_obstack
;
15406 htab_t cu_index_htab
;
15408 /* Non-zero if the previous_* fields are valid.
15409 We can't write an entry until we see the next entry (since it is only then
15410 that we know the end of the entry). */
15411 int previous_valid
;
15412 /* Index of the CU in the table of all CUs in the index file. */
15413 unsigned int previous_cu_index
;
15414 /* Start address of the CU. */
15415 CORE_ADDR previous_cu_start
;
15418 /* Write an address entry to OBSTACK. */
15421 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
15422 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
15424 offset_type cu_index_to_write
;
15426 CORE_ADDR baseaddr
;
15428 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15430 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
15431 obstack_grow (obstack
, addr
, 8);
15432 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
15433 obstack_grow (obstack
, addr
, 8);
15434 cu_index_to_write
= MAYBE_SWAP (cu_index
);
15435 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
15438 /* Worker function for traversing an addrmap to build the address table. */
15441 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
15443 struct addrmap_index_data
*data
= datap
;
15444 struct partial_symtab
*pst
= obj
;
15445 offset_type cu_index
;
15448 if (data
->previous_valid
)
15449 add_address_entry (data
->objfile
, data
->addr_obstack
,
15450 data
->previous_cu_start
, start_addr
,
15451 data
->previous_cu_index
);
15453 data
->previous_cu_start
= start_addr
;
15456 struct psymtab_cu_index_map find_map
, *map
;
15457 find_map
.psymtab
= pst
;
15458 map
= htab_find (data
->cu_index_htab
, &find_map
);
15459 gdb_assert (map
!= NULL
);
15460 data
->previous_cu_index
= map
->cu_index
;
15461 data
->previous_valid
= 1;
15464 data
->previous_valid
= 0;
15469 /* Write OBJFILE's address map to OBSTACK.
15470 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
15471 in the index file. */
15474 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
15475 htab_t cu_index_htab
)
15477 struct addrmap_index_data addrmap_index_data
;
15479 /* When writing the address table, we have to cope with the fact that
15480 the addrmap iterator only provides the start of a region; we have to
15481 wait until the next invocation to get the start of the next region. */
15483 addrmap_index_data
.objfile
= objfile
;
15484 addrmap_index_data
.addr_obstack
= obstack
;
15485 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
15486 addrmap_index_data
.previous_valid
= 0;
15488 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
15489 &addrmap_index_data
);
15491 /* It's highly unlikely the last entry (end address = 0xff...ff)
15492 is valid, but we should still handle it.
15493 The end address is recorded as the start of the next region, but that
15494 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
15496 if (addrmap_index_data
.previous_valid
)
15497 add_address_entry (objfile
, obstack
,
15498 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
15499 addrmap_index_data
.previous_cu_index
);
15502 /* Add a list of partial symbols to SYMTAB. */
15505 write_psymbols (struct mapped_symtab
*symtab
,
15507 struct partial_symbol
**psymp
,
15509 offset_type cu_index
,
15512 for (; count
-- > 0; ++psymp
)
15514 void **slot
, *lookup
;
15516 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
15517 error (_("Ada is not currently supported by the index"));
15519 /* We only want to add a given psymbol once. However, we also
15520 want to account for whether it is global or static. So, we
15521 may add it twice, using slightly different values. */
15524 uintptr_t val
= 1 | (uintptr_t) *psymp
;
15526 lookup
= (void *) val
;
15531 /* Only add a given psymbol once. */
15532 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
15536 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
15541 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
15542 exception if there is an error. */
15545 write_obstack (FILE *file
, struct obstack
*obstack
)
15547 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
15549 != obstack_object_size (obstack
))
15550 error (_("couldn't data write to file"));
15553 /* Unlink a file if the argument is not NULL. */
15556 unlink_if_set (void *p
)
15558 char **filename
= p
;
15560 unlink (*filename
);
15563 /* A helper struct used when iterating over debug_types. */
15564 struct signatured_type_index_data
15566 struct objfile
*objfile
;
15567 struct mapped_symtab
*symtab
;
15568 struct obstack
*types_list
;
15573 /* A helper function that writes a single signatured_type to an
15577 write_one_signatured_type (void **slot
, void *d
)
15579 struct signatured_type_index_data
*info
= d
;
15580 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
15581 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
15582 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15585 write_psymbols (info
->symtab
,
15587 info
->objfile
->global_psymbols
.list
15588 + psymtab
->globals_offset
,
15589 psymtab
->n_global_syms
, info
->cu_index
,
15591 write_psymbols (info
->symtab
,
15593 info
->objfile
->static_psymbols
.list
15594 + psymtab
->statics_offset
,
15595 psymtab
->n_static_syms
, info
->cu_index
,
15598 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->offset
);
15599 obstack_grow (info
->types_list
, val
, 8);
15600 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
15601 obstack_grow (info
->types_list
, val
, 8);
15602 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
15603 obstack_grow (info
->types_list
, val
, 8);
15610 /* A cleanup function for an htab_t. */
15613 cleanup_htab (void *arg
)
15618 /* Create an index file for OBJFILE in the directory DIR. */
15621 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
15623 struct cleanup
*cleanup
;
15624 char *filename
, *cleanup_filename
;
15625 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
15626 struct obstack cu_list
, types_cu_list
;
15629 struct mapped_symtab
*symtab
;
15630 offset_type val
, size_of_contents
, total_len
;
15634 htab_t cu_index_htab
;
15635 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
15637 if (!objfile
->psymtabs
)
15639 if (dwarf2_per_objfile
->using_index
)
15640 error (_("Cannot use an index to create the index"));
15642 if (stat (objfile
->name
, &st
) < 0)
15643 perror_with_name (objfile
->name
);
15645 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
15646 INDEX_SUFFIX
, (char *) NULL
);
15647 cleanup
= make_cleanup (xfree
, filename
);
15649 out_file
= fopen (filename
, "wb");
15651 error (_("Can't open `%s' for writing"), filename
);
15653 cleanup_filename
= filename
;
15654 make_cleanup (unlink_if_set
, &cleanup_filename
);
15656 symtab
= create_mapped_symtab ();
15657 make_cleanup (cleanup_mapped_symtab
, symtab
);
15659 obstack_init (&addr_obstack
);
15660 make_cleanup_obstack_free (&addr_obstack
);
15662 obstack_init (&cu_list
);
15663 make_cleanup_obstack_free (&cu_list
);
15665 obstack_init (&types_cu_list
);
15666 make_cleanup_obstack_free (&types_cu_list
);
15668 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
15669 NULL
, xcalloc
, xfree
);
15670 make_cleanup (cleanup_htab
, psyms_seen
);
15672 /* While we're scanning CU's create a table that maps a psymtab pointer
15673 (which is what addrmap records) to its index (which is what is recorded
15674 in the index file). This will later be needed to write the address
15676 cu_index_htab
= htab_create_alloc (100,
15677 hash_psymtab_cu_index
,
15678 eq_psymtab_cu_index
,
15679 NULL
, xcalloc
, xfree
);
15680 make_cleanup (cleanup_htab
, cu_index_htab
);
15681 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
15682 xmalloc (sizeof (struct psymtab_cu_index_map
)
15683 * dwarf2_per_objfile
->n_comp_units
);
15684 make_cleanup (xfree
, psymtab_cu_index_map
);
15686 /* The CU list is already sorted, so we don't need to do additional
15687 work here. Also, the debug_types entries do not appear in
15688 all_comp_units, but only in their own hash table. */
15689 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
15691 struct dwarf2_per_cu_data
*per_cu
15692 = dwarf2_per_objfile
->all_comp_units
[i
];
15693 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15695 struct psymtab_cu_index_map
*map
;
15698 write_psymbols (symtab
,
15700 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15701 psymtab
->n_global_syms
, i
,
15703 write_psymbols (symtab
,
15705 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15706 psymtab
->n_static_syms
, i
,
15709 map
= &psymtab_cu_index_map
[i
];
15710 map
->psymtab
= psymtab
;
15712 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
15713 gdb_assert (slot
!= NULL
);
15714 gdb_assert (*slot
== NULL
);
15717 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
15718 obstack_grow (&cu_list
, val
, 8);
15719 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
15720 obstack_grow (&cu_list
, val
, 8);
15723 /* Dump the address map. */
15724 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
15726 /* Write out the .debug_type entries, if any. */
15727 if (dwarf2_per_objfile
->signatured_types
)
15729 struct signatured_type_index_data sig_data
;
15731 sig_data
.objfile
= objfile
;
15732 sig_data
.symtab
= symtab
;
15733 sig_data
.types_list
= &types_cu_list
;
15734 sig_data
.psyms_seen
= psyms_seen
;
15735 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
15736 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
15737 write_one_signatured_type
, &sig_data
);
15740 obstack_init (&constant_pool
);
15741 make_cleanup_obstack_free (&constant_pool
);
15742 obstack_init (&symtab_obstack
);
15743 make_cleanup_obstack_free (&symtab_obstack
);
15744 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
15746 obstack_init (&contents
);
15747 make_cleanup_obstack_free (&contents
);
15748 size_of_contents
= 6 * sizeof (offset_type
);
15749 total_len
= size_of_contents
;
15751 /* The version number. */
15752 val
= MAYBE_SWAP (4);
15753 obstack_grow (&contents
, &val
, sizeof (val
));
15755 /* The offset of the CU list from the start of the file. */
15756 val
= MAYBE_SWAP (total_len
);
15757 obstack_grow (&contents
, &val
, sizeof (val
));
15758 total_len
+= obstack_object_size (&cu_list
);
15760 /* The offset of the types CU list from the start of the file. */
15761 val
= MAYBE_SWAP (total_len
);
15762 obstack_grow (&contents
, &val
, sizeof (val
));
15763 total_len
+= obstack_object_size (&types_cu_list
);
15765 /* The offset of the address table from the start of the file. */
15766 val
= MAYBE_SWAP (total_len
);
15767 obstack_grow (&contents
, &val
, sizeof (val
));
15768 total_len
+= obstack_object_size (&addr_obstack
);
15770 /* The offset of the symbol table from the start of the file. */
15771 val
= MAYBE_SWAP (total_len
);
15772 obstack_grow (&contents
, &val
, sizeof (val
));
15773 total_len
+= obstack_object_size (&symtab_obstack
);
15775 /* The offset of the constant pool from the start of the file. */
15776 val
= MAYBE_SWAP (total_len
);
15777 obstack_grow (&contents
, &val
, sizeof (val
));
15778 total_len
+= obstack_object_size (&constant_pool
);
15780 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
15782 write_obstack (out_file
, &contents
);
15783 write_obstack (out_file
, &cu_list
);
15784 write_obstack (out_file
, &types_cu_list
);
15785 write_obstack (out_file
, &addr_obstack
);
15786 write_obstack (out_file
, &symtab_obstack
);
15787 write_obstack (out_file
, &constant_pool
);
15791 /* We want to keep the file, so we set cleanup_filename to NULL
15792 here. See unlink_if_set. */
15793 cleanup_filename
= NULL
;
15795 do_cleanups (cleanup
);
15798 /* The mapped index file format is designed to be directly mmap()able
15799 on any architecture. In most cases, a datum is represented using a
15800 little-endian 32-bit integer value, called an offset_type. Big
15801 endian machines must byte-swap the values before using them.
15802 Exceptions to this rule are noted. The data is laid out such that
15803 alignment is always respected.
15805 A mapped index consists of several sections.
15807 1. The file header. This is a sequence of values, of offset_type
15808 unless otherwise noted:
15810 [0] The version number, currently 4. Versions 1, 2 and 3 are
15812 [1] The offset, from the start of the file, of the CU list.
15813 [2] The offset, from the start of the file, of the types CU list.
15814 Note that this section can be empty, in which case this offset will
15815 be equal to the next offset.
15816 [3] The offset, from the start of the file, of the address section.
15817 [4] The offset, from the start of the file, of the symbol table.
15818 [5] The offset, from the start of the file, of the constant pool.
15820 2. The CU list. This is a sequence of pairs of 64-bit
15821 little-endian values, sorted by the CU offset. The first element
15822 in each pair is the offset of a CU in the .debug_info section. The
15823 second element in each pair is the length of that CU. References
15824 to a CU elsewhere in the map are done using a CU index, which is
15825 just the 0-based index into this table. Note that if there are
15826 type CUs, then conceptually CUs and type CUs form a single list for
15827 the purposes of CU indices.
15829 3. The types CU list. This is a sequence of triplets of 64-bit
15830 little-endian values. In a triplet, the first value is the CU
15831 offset, the second value is the type offset in the CU, and the
15832 third value is the type signature. The types CU list is not
15835 4. The address section. The address section consists of a sequence
15836 of address entries. Each address entry has three elements.
15837 [0] The low address. This is a 64-bit little-endian value.
15838 [1] The high address. This is a 64-bit little-endian value.
15839 Like DW_AT_high_pc, the value is one byte beyond the end.
15840 [2] The CU index. This is an offset_type value.
15842 5. The symbol table. This is a hash table. The size of the hash
15843 table is always a power of 2. The initial hash and the step are
15844 currently defined by the `find_slot' function.
15846 Each slot in the hash table consists of a pair of offset_type
15847 values. The first value is the offset of the symbol's name in the
15848 constant pool. The second value is the offset of the CU vector in
15851 If both values are 0, then this slot in the hash table is empty.
15852 This is ok because while 0 is a valid constant pool index, it
15853 cannot be a valid index for both a string and a CU vector.
15855 A string in the constant pool is stored as a \0-terminated string,
15858 A CU vector in the constant pool is a sequence of offset_type
15859 values. The first value is the number of CU indices in the vector.
15860 Each subsequent value is the index of a CU in the CU list. This
15861 element in the hash table is used to indicate which CUs define the
15864 6. The constant pool. This is simply a bunch of bytes. It is
15865 organized so that alignment is correct: CU vectors are stored
15866 first, followed by strings. */
15869 save_gdb_index_command (char *arg
, int from_tty
)
15871 struct objfile
*objfile
;
15874 error (_("usage: save gdb-index DIRECTORY"));
15876 ALL_OBJFILES (objfile
)
15880 /* If the objfile does not correspond to an actual file, skip it. */
15881 if (stat (objfile
->name
, &st
) < 0)
15884 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15885 if (dwarf2_per_objfile
)
15887 volatile struct gdb_exception except
;
15889 TRY_CATCH (except
, RETURN_MASK_ERROR
)
15891 write_psymtabs_to_index (objfile
, arg
);
15893 if (except
.reason
< 0)
15894 exception_fprintf (gdb_stderr
, except
,
15895 _("Error while writing index for `%s': "),
15903 int dwarf2_always_disassemble
;
15906 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
15907 struct cmd_list_element
*c
, const char *value
)
15909 fprintf_filtered (file
,
15910 _("Whether to always disassemble "
15911 "DWARF expressions is %s.\n"),
15915 void _initialize_dwarf2_read (void);
15918 _initialize_dwarf2_read (void)
15920 struct cmd_list_element
*c
;
15922 dwarf2_objfile_data_key
15923 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
15925 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
15926 Set DWARF 2 specific variables.\n\
15927 Configure DWARF 2 variables such as the cache size"),
15928 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
15929 0/*allow-unknown*/, &maintenance_set_cmdlist
);
15931 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
15932 Show DWARF 2 specific variables\n\
15933 Show DWARF 2 variables such as the cache size"),
15934 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
15935 0/*allow-unknown*/, &maintenance_show_cmdlist
);
15937 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
15938 &dwarf2_max_cache_age
, _("\
15939 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
15940 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
15941 A higher limit means that cached compilation units will be stored\n\
15942 in memory longer, and more total memory will be used. Zero disables\n\
15943 caching, which can slow down startup."),
15945 show_dwarf2_max_cache_age
,
15946 &set_dwarf2_cmdlist
,
15947 &show_dwarf2_cmdlist
);
15949 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
15950 &dwarf2_always_disassemble
, _("\
15951 Set whether `info address' always disassembles DWARF expressions."), _("\
15952 Show whether `info address' always disassembles DWARF expressions."), _("\
15953 When enabled, DWARF expressions are always printed in an assembly-like\n\
15954 syntax. When disabled, expressions will be printed in a more\n\
15955 conversational style, when possible."),
15957 show_dwarf2_always_disassemble
,
15958 &set_dwarf2_cmdlist
,
15959 &show_dwarf2_cmdlist
);
15961 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
15962 Set debugging of the dwarf2 DIE reader."), _("\
15963 Show debugging of the dwarf2 DIE reader."), _("\
15964 When enabled (non-zero), DIEs are dumped after they are read in.\n\
15965 The value is the maximum depth to print."),
15968 &setdebuglist
, &showdebuglist
);
15970 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
15972 Save a gdb-index file.\n\
15973 Usage: save gdb-index DIRECTORY"),
15975 set_cmd_completer (c
, filename_completer
);