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
))
2775 /* Build a partial symbol table. */
2778 dwarf2_build_psymtabs (struct objfile
*objfile
)
2780 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2782 init_psymbol_list (objfile
, 1024);
2785 dwarf2_build_psymtabs_hard (objfile
);
2788 /* Return TRUE if OFFSET is within CU_HEADER. */
2791 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2793 unsigned int bottom
= cu_header
->offset
;
2794 unsigned int top
= (cu_header
->offset
2796 + cu_header
->initial_length_size
);
2798 return (offset
>= bottom
&& offset
< top
);
2801 /* Read in the comp unit header information from the debug_info at info_ptr.
2802 NOTE: This leaves members offset, first_die_offset to be filled in
2806 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2807 gdb_byte
*info_ptr
, bfd
*abfd
)
2810 unsigned int bytes_read
;
2812 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2813 cu_header
->initial_length_size
= bytes_read
;
2814 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2815 info_ptr
+= bytes_read
;
2816 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2818 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2820 info_ptr
+= bytes_read
;
2821 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2823 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2824 if (signed_addr
< 0)
2825 internal_error (__FILE__
, __LINE__
,
2826 _("read_comp_unit_head: dwarf from non elf file"));
2827 cu_header
->signed_addr_p
= signed_addr
;
2833 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2834 gdb_byte
*buffer
, unsigned int buffer_size
,
2837 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2839 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2841 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2842 error (_("Dwarf Error: wrong version in compilation unit header "
2843 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2844 bfd_get_filename (abfd
));
2846 if (header
->abbrev_offset
2847 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
2848 &dwarf2_per_objfile
->abbrev
))
2849 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2850 "(offset 0x%lx + 6) [in module %s]"),
2851 (long) header
->abbrev_offset
,
2852 (long) (beg_of_comp_unit
- buffer
),
2853 bfd_get_filename (abfd
));
2855 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2856 > buffer
+ buffer_size
)
2857 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2858 "(offset 0x%lx + 0) [in module %s]"),
2859 (long) header
->length
,
2860 (long) (beg_of_comp_unit
- buffer
),
2861 bfd_get_filename (abfd
));
2866 /* Read in the types comp unit header information from .debug_types entry at
2867 types_ptr. The result is a pointer to one past the end of the header. */
2870 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2871 ULONGEST
*signature
,
2872 gdb_byte
*types_ptr
, bfd
*abfd
)
2874 gdb_byte
*initial_types_ptr
= types_ptr
;
2876 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2877 &dwarf2_per_objfile
->types
);
2878 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2880 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2882 *signature
= read_8_bytes (abfd
, types_ptr
);
2884 types_ptr
+= cu_header
->offset_size
;
2885 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2890 /* Allocate a new partial symtab for file named NAME and mark this new
2891 partial symtab as being an include of PST. */
2894 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2895 struct objfile
*objfile
)
2897 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2899 subpst
->section_offsets
= pst
->section_offsets
;
2900 subpst
->textlow
= 0;
2901 subpst
->texthigh
= 0;
2903 subpst
->dependencies
= (struct partial_symtab
**)
2904 obstack_alloc (&objfile
->objfile_obstack
,
2905 sizeof (struct partial_symtab
*));
2906 subpst
->dependencies
[0] = pst
;
2907 subpst
->number_of_dependencies
= 1;
2909 subpst
->globals_offset
= 0;
2910 subpst
->n_global_syms
= 0;
2911 subpst
->statics_offset
= 0;
2912 subpst
->n_static_syms
= 0;
2913 subpst
->symtab
= NULL
;
2914 subpst
->read_symtab
= pst
->read_symtab
;
2917 /* No private part is necessary for include psymtabs. This property
2918 can be used to differentiate between such include psymtabs and
2919 the regular ones. */
2920 subpst
->read_symtab_private
= NULL
;
2923 /* Read the Line Number Program data and extract the list of files
2924 included by the source file represented by PST. Build an include
2925 partial symtab for each of these included files. */
2928 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2929 struct die_info
*die
,
2930 struct partial_symtab
*pst
)
2932 struct objfile
*objfile
= cu
->objfile
;
2933 bfd
*abfd
= objfile
->obfd
;
2934 struct line_header
*lh
= NULL
;
2935 struct attribute
*attr
;
2937 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2940 unsigned int line_offset
= DW_UNSND (attr
);
2942 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2945 return; /* No linetable, so no includes. */
2947 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2948 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
2950 free_line_header (lh
);
2954 hash_type_signature (const void *item
)
2956 const struct signatured_type
*type_sig
= item
;
2958 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2959 return type_sig
->signature
;
2963 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2965 const struct signatured_type
*lhs
= item_lhs
;
2966 const struct signatured_type
*rhs
= item_rhs
;
2968 return lhs
->signature
== rhs
->signature
;
2971 /* Allocate a hash table for signatured types. */
2974 allocate_signatured_type_table (struct objfile
*objfile
)
2976 return htab_create_alloc_ex (41,
2977 hash_type_signature
,
2980 &objfile
->objfile_obstack
,
2981 hashtab_obstack_allocate
,
2982 dummy_obstack_deallocate
);
2985 /* A helper function to add a signatured type CU to a list. */
2988 add_signatured_type_cu_to_list (void **slot
, void *datum
)
2990 struct signatured_type
*sigt
= *slot
;
2991 struct dwarf2_per_cu_data
***datap
= datum
;
2993 **datap
= &sigt
->per_cu
;
2999 /* Create the hash table of all entries in the .debug_types section.
3000 The result is zero if there is an error (e.g. missing .debug_types section),
3001 otherwise non-zero. */
3004 create_debug_types_hash_table (struct objfile
*objfile
)
3008 struct dwarf2_per_cu_data
**iter
;
3010 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
3011 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
3013 if (info_ptr
== NULL
)
3015 dwarf2_per_objfile
->signatured_types
= NULL
;
3019 types_htab
= allocate_signatured_type_table (objfile
);
3021 if (dwarf2_die_debug
)
3022 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3024 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
3025 + dwarf2_per_objfile
->types
.size
)
3027 unsigned int offset
;
3028 unsigned int offset_size
;
3029 unsigned int type_offset
;
3030 unsigned int length
, initial_length_size
;
3031 unsigned short version
;
3033 struct signatured_type
*type_sig
;
3035 gdb_byte
*ptr
= info_ptr
;
3037 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
3039 /* We need to read the type's signature in order to build the hash
3040 table, but we don't need to read anything else just yet. */
3042 /* Sanity check to ensure entire cu is present. */
3043 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
3044 if (ptr
+ length
+ initial_length_size
3045 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
3047 complaint (&symfile_complaints
,
3048 _("debug type entry runs off end "
3049 "of `.debug_types' section, ignored"));
3053 offset_size
= initial_length_size
== 4 ? 4 : 8;
3054 ptr
+= initial_length_size
;
3055 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3057 ptr
+= offset_size
; /* abbrev offset */
3058 ptr
+= 1; /* address size */
3059 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3061 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3063 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3064 memset (type_sig
, 0, sizeof (*type_sig
));
3065 type_sig
->signature
= signature
;
3066 type_sig
->offset
= offset
;
3067 type_sig
->type_offset
= type_offset
;
3068 type_sig
->per_cu
.objfile
= objfile
;
3069 type_sig
->per_cu
.from_debug_types
= 1;
3071 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3072 gdb_assert (slot
!= NULL
);
3075 if (dwarf2_die_debug
)
3076 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3077 offset
, phex (signature
, sizeof (signature
)));
3079 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3082 dwarf2_per_objfile
->signatured_types
= types_htab
;
3084 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3085 dwarf2_per_objfile
->type_comp_units
3086 = obstack_alloc (&objfile
->objfile_obstack
,
3087 dwarf2_per_objfile
->n_type_comp_units
3088 * sizeof (struct dwarf2_per_cu_data
*));
3089 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3090 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3091 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3092 == dwarf2_per_objfile
->n_type_comp_units
);
3097 /* Lookup a signature based type.
3098 Returns NULL if SIG is not present in the table. */
3100 static struct signatured_type
*
3101 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3103 struct signatured_type find_entry
, *entry
;
3105 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3107 complaint (&symfile_complaints
,
3108 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3112 find_entry
.signature
= sig
;
3113 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3117 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3120 init_cu_die_reader (struct die_reader_specs
*reader
,
3121 struct dwarf2_cu
*cu
)
3123 reader
->abfd
= cu
->objfile
->obfd
;
3125 if (cu
->per_cu
->from_debug_types
)
3127 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3128 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
3132 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3133 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3137 /* Find the base address of the compilation unit for range lists and
3138 location lists. It will normally be specified by DW_AT_low_pc.
3139 In DWARF-3 draft 4, the base address could be overridden by
3140 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3141 compilation units with discontinuous ranges. */
3144 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3146 struct attribute
*attr
;
3149 cu
->base_address
= 0;
3151 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3154 cu
->base_address
= DW_ADDR (attr
);
3159 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3162 cu
->base_address
= DW_ADDR (attr
);
3168 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3169 to combine the common parts.
3170 Process a compilation unit for a psymtab.
3171 BUFFER is a pointer to the beginning of the dwarf section buffer,
3172 either .debug_info or debug_types.
3173 INFO_PTR is a pointer to the start of the CU.
3174 Returns a pointer to the next CU. */
3177 process_psymtab_comp_unit (struct objfile
*objfile
,
3178 struct dwarf2_per_cu_data
*this_cu
,
3179 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3180 unsigned int buffer_size
)
3182 bfd
*abfd
= objfile
->obfd
;
3183 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3184 struct die_info
*comp_unit_die
;
3185 struct partial_symtab
*pst
;
3187 struct cleanup
*back_to_inner
;
3188 struct dwarf2_cu cu
;
3189 int has_children
, has_pc_info
;
3190 struct attribute
*attr
;
3191 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3192 struct die_reader_specs reader_specs
;
3193 const char *filename
;
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 if (attr
== NULL
|| !DW_STRING (attr
))
3256 filename
= DW_STRING (attr
);
3257 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3259 /* TEXTLOW and TEXTHIGH are set below. */
3261 objfile
->global_psymbols
.next
,
3262 objfile
->static_psymbols
.next
);
3264 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3266 pst
->dirname
= DW_STRING (attr
);
3268 pst
->read_symtab_private
= this_cu
;
3270 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3272 /* Store the function that reads in the rest of the symbol table. */
3273 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3275 this_cu
->v
.psymtab
= pst
;
3277 dwarf2_find_base_address (comp_unit_die
, &cu
);
3279 /* Possibly set the default values of LOWPC and HIGHPC from
3281 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3282 &best_highpc
, &cu
, pst
);
3283 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3284 /* Store the contiguous range if it is not empty; it can be empty for
3285 CUs with no code. */
3286 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3287 best_lowpc
+ baseaddr
,
3288 best_highpc
+ baseaddr
- 1, pst
);
3290 /* Check if comp unit has_children.
3291 If so, read the rest of the partial symbols from this comp unit.
3292 If not, there's no more debug_info for this comp unit. */
3295 struct partial_die_info
*first_die
;
3296 CORE_ADDR lowpc
, highpc
;
3298 lowpc
= ((CORE_ADDR
) -1);
3299 highpc
= ((CORE_ADDR
) 0);
3301 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3303 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3304 ! has_pc_info
, &cu
);
3306 /* If we didn't find a lowpc, set it to highpc to avoid
3307 complaints from `maint check'. */
3308 if (lowpc
== ((CORE_ADDR
) -1))
3311 /* If the compilation unit didn't have an explicit address range,
3312 then use the information extracted from its child dies. */
3316 best_highpc
= highpc
;
3319 pst
->textlow
= best_lowpc
+ baseaddr
;
3320 pst
->texthigh
= best_highpc
+ baseaddr
;
3322 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3323 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3324 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3325 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3326 sort_pst_symbols (pst
);
3328 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3329 + cu
.header
.initial_length_size
);
3331 if (this_cu
->from_debug_types
)
3333 /* It's not clear we want to do anything with stmt lists here.
3334 Waiting to see what gcc ultimately does. */
3338 /* Get the list of files included in the current compilation unit,
3339 and build a psymtab for each of them. */
3340 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3343 do_cleanups (back_to_inner
);
3348 /* Traversal function for htab_traverse_noresize.
3349 Process one .debug_types comp-unit. */
3352 process_type_comp_unit (void **slot
, void *info
)
3354 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3355 struct objfile
*objfile
= (struct objfile
*) info
;
3356 struct dwarf2_per_cu_data
*this_cu
;
3358 this_cu
= &entry
->per_cu
;
3360 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3361 process_psymtab_comp_unit (objfile
, this_cu
,
3362 dwarf2_per_objfile
->types
.buffer
,
3363 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
3364 dwarf2_per_objfile
->types
.size
);
3369 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3370 Build partial symbol tables for the .debug_types comp-units. */
3373 build_type_psymtabs (struct objfile
*objfile
)
3375 if (! create_debug_types_hash_table (objfile
))
3378 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3379 process_type_comp_unit
, objfile
);
3382 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3385 psymtabs_addrmap_cleanup (void *o
)
3387 struct objfile
*objfile
= o
;
3389 objfile
->psymtabs_addrmap
= NULL
;
3392 /* Build the partial symbol table by doing a quick pass through the
3393 .debug_info and .debug_abbrev sections. */
3396 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3399 struct cleanup
*back_to
, *addrmap_cleanup
;
3400 struct obstack temp_obstack
;
3402 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3404 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3405 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3407 /* Any cached compilation units will be linked by the per-objfile
3408 read_in_chain. Make sure to free them when we're done. */
3409 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3411 build_type_psymtabs (objfile
);
3413 create_all_comp_units (objfile
);
3415 /* Create a temporary address map on a temporary obstack. We later
3416 copy this to the final obstack. */
3417 obstack_init (&temp_obstack
);
3418 make_cleanup_obstack_free (&temp_obstack
);
3419 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3420 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3422 /* Since the objects we're extracting from .debug_info vary in
3423 length, only the individual functions to extract them (like
3424 read_comp_unit_head and load_partial_die) can really know whether
3425 the buffer is large enough to hold another complete object.
3427 At the moment, they don't actually check that. If .debug_info
3428 holds just one extra byte after the last compilation unit's dies,
3429 then read_comp_unit_head will happily read off the end of the
3430 buffer. read_partial_die is similarly casual. Those functions
3433 For this loop condition, simply checking whether there's any data
3434 left at all should be sufficient. */
3436 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3437 + dwarf2_per_objfile
->info
.size
))
3439 struct dwarf2_per_cu_data
*this_cu
;
3441 this_cu
= dwarf2_find_comp_unit (info_ptr
3442 - dwarf2_per_objfile
->info
.buffer
,
3445 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3446 dwarf2_per_objfile
->info
.buffer
,
3448 dwarf2_per_objfile
->info
.size
);
3451 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3452 &objfile
->objfile_obstack
);
3453 discard_cleanups (addrmap_cleanup
);
3455 do_cleanups (back_to
);
3458 /* Load the partial DIEs for a secondary CU into memory. */
3461 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3462 struct objfile
*objfile
)
3464 bfd
*abfd
= objfile
->obfd
;
3465 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3466 struct die_info
*comp_unit_die
;
3467 struct dwarf2_cu
*cu
;
3468 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3470 struct die_reader_specs reader_specs
;
3473 gdb_assert (! this_cu
->from_debug_types
);
3475 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3476 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3477 beg_of_comp_unit
= info_ptr
;
3479 if (this_cu
->cu
== NULL
)
3481 cu
= xmalloc (sizeof (*cu
));
3482 init_one_comp_unit (cu
, objfile
);
3486 /* If an error occurs while loading, release our storage. */
3487 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3489 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3490 dwarf2_per_objfile
->info
.buffer
,
3491 dwarf2_per_objfile
->info
.size
,
3494 /* Complete the cu_header. */
3495 cu
->header
.offset
= this_cu
->offset
;
3496 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3498 /* Link this compilation unit into the compilation unit tree. */
3500 cu
->per_cu
= this_cu
;
3502 /* Link this CU into read_in_chain. */
3503 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3504 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3509 info_ptr
+= cu
->header
.first_die_offset
;
3512 /* Read the abbrevs for this compilation unit into a table. */
3513 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3514 dwarf2_read_abbrevs (abfd
, cu
);
3515 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3517 /* Read the compilation unit die. */
3518 init_cu_die_reader (&reader_specs
, cu
);
3519 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3522 prepare_one_comp_unit (cu
, comp_unit_die
);
3524 /* Check if comp unit has_children.
3525 If so, read the rest of the partial symbols from this comp unit.
3526 If not, there's no more debug_info for this comp unit. */
3528 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3530 do_cleanups (free_abbrevs_cleanup
);
3534 /* We've successfully allocated this compilation unit. Let our
3535 caller clean it up when finished with it. */
3536 discard_cleanups (free_cu_cleanup
);
3540 /* Create a list of all compilation units in OBJFILE. We do this only
3541 if an inter-comp-unit reference is found; presumably if there is one,
3542 there will be many, and one will occur early in the .debug_info section.
3543 So there's no point in building this list incrementally. */
3546 create_all_comp_units (struct objfile
*objfile
)
3550 struct dwarf2_per_cu_data
**all_comp_units
;
3553 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3554 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3558 all_comp_units
= xmalloc (n_allocated
3559 * sizeof (struct dwarf2_per_cu_data
*));
3561 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3562 + dwarf2_per_objfile
->info
.size
)
3564 unsigned int length
, initial_length_size
;
3565 struct dwarf2_per_cu_data
*this_cu
;
3566 unsigned int offset
;
3568 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3570 /* Read just enough information to find out where the next
3571 compilation unit is. */
3572 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3573 &initial_length_size
);
3575 /* Save the compilation unit for later lookup. */
3576 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3577 sizeof (struct dwarf2_per_cu_data
));
3578 memset (this_cu
, 0, sizeof (*this_cu
));
3579 this_cu
->offset
= offset
;
3580 this_cu
->length
= length
+ initial_length_size
;
3581 this_cu
->objfile
= objfile
;
3583 if (n_comp_units
== n_allocated
)
3586 all_comp_units
= xrealloc (all_comp_units
,
3588 * sizeof (struct dwarf2_per_cu_data
*));
3590 all_comp_units
[n_comp_units
++] = this_cu
;
3592 info_ptr
= info_ptr
+ this_cu
->length
;
3595 dwarf2_per_objfile
->all_comp_units
3596 = obstack_alloc (&objfile
->objfile_obstack
,
3597 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3598 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3599 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3600 xfree (all_comp_units
);
3601 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3604 /* Process all loaded DIEs for compilation unit CU, starting at
3605 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3606 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3607 DW_AT_ranges). If NEED_PC is set, then this function will set
3608 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3609 and record the covered ranges in the addrmap. */
3612 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3613 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3615 struct partial_die_info
*pdi
;
3617 /* Now, march along the PDI's, descending into ones which have
3618 interesting children but skipping the children of the other ones,
3619 until we reach the end of the compilation unit. */
3625 fixup_partial_die (pdi
, cu
);
3627 /* Anonymous namespaces or modules have no name but have interesting
3628 children, so we need to look at them. Ditto for anonymous
3631 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3632 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3636 case DW_TAG_subprogram
:
3637 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3639 case DW_TAG_constant
:
3640 case DW_TAG_variable
:
3641 case DW_TAG_typedef
:
3642 case DW_TAG_union_type
:
3643 if (!pdi
->is_declaration
)
3645 add_partial_symbol (pdi
, cu
);
3648 case DW_TAG_class_type
:
3649 case DW_TAG_interface_type
:
3650 case DW_TAG_structure_type
:
3651 if (!pdi
->is_declaration
)
3653 add_partial_symbol (pdi
, cu
);
3656 case DW_TAG_enumeration_type
:
3657 if (!pdi
->is_declaration
)
3658 add_partial_enumeration (pdi
, cu
);
3660 case DW_TAG_base_type
:
3661 case DW_TAG_subrange_type
:
3662 /* File scope base type definitions are added to the partial
3664 add_partial_symbol (pdi
, cu
);
3666 case DW_TAG_namespace
:
3667 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3670 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3677 /* If the die has a sibling, skip to the sibling. */
3679 pdi
= pdi
->die_sibling
;
3683 /* Functions used to compute the fully scoped name of a partial DIE.
3685 Normally, this is simple. For C++, the parent DIE's fully scoped
3686 name is concatenated with "::" and the partial DIE's name. For
3687 Java, the same thing occurs except that "." is used instead of "::".
3688 Enumerators are an exception; they use the scope of their parent
3689 enumeration type, i.e. the name of the enumeration type is not
3690 prepended to the enumerator.
3692 There are two complexities. One is DW_AT_specification; in this
3693 case "parent" means the parent of the target of the specification,
3694 instead of the direct parent of the DIE. The other is compilers
3695 which do not emit DW_TAG_namespace; in this case we try to guess
3696 the fully qualified name of structure types from their members'
3697 linkage names. This must be done using the DIE's children rather
3698 than the children of any DW_AT_specification target. We only need
3699 to do this for structures at the top level, i.e. if the target of
3700 any DW_AT_specification (if any; otherwise the DIE itself) does not
3703 /* Compute the scope prefix associated with PDI's parent, in
3704 compilation unit CU. The result will be allocated on CU's
3705 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3706 field. NULL is returned if no prefix is necessary. */
3708 partial_die_parent_scope (struct partial_die_info
*pdi
,
3709 struct dwarf2_cu
*cu
)
3711 char *grandparent_scope
;
3712 struct partial_die_info
*parent
, *real_pdi
;
3714 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3715 then this means the parent of the specification DIE. */
3718 while (real_pdi
->has_specification
)
3719 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3721 parent
= real_pdi
->die_parent
;
3725 if (parent
->scope_set
)
3726 return parent
->scope
;
3728 fixup_partial_die (parent
, cu
);
3730 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3732 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3733 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3734 Work around this problem here. */
3735 if (cu
->language
== language_cplus
3736 && parent
->tag
== DW_TAG_namespace
3737 && strcmp (parent
->name
, "::") == 0
3738 && grandparent_scope
== NULL
)
3740 parent
->scope
= NULL
;
3741 parent
->scope_set
= 1;
3745 if (parent
->tag
== DW_TAG_namespace
3746 || parent
->tag
== DW_TAG_module
3747 || parent
->tag
== DW_TAG_structure_type
3748 || parent
->tag
== DW_TAG_class_type
3749 || parent
->tag
== DW_TAG_interface_type
3750 || parent
->tag
== DW_TAG_union_type
3751 || parent
->tag
== DW_TAG_enumeration_type
)
3753 if (grandparent_scope
== NULL
)
3754 parent
->scope
= parent
->name
;
3756 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3758 parent
->name
, 0, cu
);
3760 else if (parent
->tag
== DW_TAG_enumerator
)
3761 /* Enumerators should not get the name of the enumeration as a prefix. */
3762 parent
->scope
= grandparent_scope
;
3765 /* FIXME drow/2004-04-01: What should we be doing with
3766 function-local names? For partial symbols, we should probably be
3768 complaint (&symfile_complaints
,
3769 _("unhandled containing DIE tag %d for DIE at %d"),
3770 parent
->tag
, pdi
->offset
);
3771 parent
->scope
= grandparent_scope
;
3774 parent
->scope_set
= 1;
3775 return parent
->scope
;
3778 /* Return the fully scoped name associated with PDI, from compilation unit
3779 CU. The result will be allocated with malloc. */
3781 partial_die_full_name (struct partial_die_info
*pdi
,
3782 struct dwarf2_cu
*cu
)
3786 /* If this is a template instantiation, we can not work out the
3787 template arguments from partial DIEs. So, unfortunately, we have
3788 to go through the full DIEs. At least any work we do building
3789 types here will be reused if full symbols are loaded later. */
3790 if (pdi
->has_template_arguments
)
3792 fixup_partial_die (pdi
, cu
);
3794 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3796 struct die_info
*die
;
3797 struct attribute attr
;
3798 struct dwarf2_cu
*ref_cu
= cu
;
3801 attr
.form
= DW_FORM_ref_addr
;
3802 attr
.u
.addr
= pdi
->offset
;
3803 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3805 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3809 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3810 if (parent_scope
== NULL
)
3813 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3817 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3819 struct objfile
*objfile
= cu
->objfile
;
3821 char *actual_name
= NULL
;
3822 const struct partial_symbol
*psym
= NULL
;
3824 int built_actual_name
= 0;
3826 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3828 actual_name
= partial_die_full_name (pdi
, cu
);
3830 built_actual_name
= 1;
3832 if (actual_name
== NULL
)
3833 actual_name
= pdi
->name
;
3837 case DW_TAG_subprogram
:
3838 if (pdi
->is_external
|| cu
->language
== language_ada
)
3840 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3841 of the global scope. But in Ada, we want to be able to access
3842 nested procedures globally. So all Ada subprograms are stored
3843 in the global scope. */
3844 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3845 mst_text, objfile); */
3846 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3848 VAR_DOMAIN
, LOC_BLOCK
,
3849 &objfile
->global_psymbols
,
3850 0, pdi
->lowpc
+ baseaddr
,
3851 cu
->language
, objfile
);
3855 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3856 mst_file_text, objfile); */
3857 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3859 VAR_DOMAIN
, LOC_BLOCK
,
3860 &objfile
->static_psymbols
,
3861 0, pdi
->lowpc
+ baseaddr
,
3862 cu
->language
, objfile
);
3865 case DW_TAG_constant
:
3867 struct psymbol_allocation_list
*list
;
3869 if (pdi
->is_external
)
3870 list
= &objfile
->global_psymbols
;
3872 list
= &objfile
->static_psymbols
;
3873 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3874 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
3875 list
, 0, 0, cu
->language
, objfile
);
3878 case DW_TAG_variable
:
3880 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3884 && !dwarf2_per_objfile
->has_section_at_zero
)
3886 /* A global or static variable may also have been stripped
3887 out by the linker if unused, in which case its address
3888 will be nullified; do not add such variables into partial
3889 symbol table then. */
3891 else if (pdi
->is_external
)
3894 Don't enter into the minimal symbol tables as there is
3895 a minimal symbol table entry from the ELF symbols already.
3896 Enter into partial symbol table if it has a location
3897 descriptor or a type.
3898 If the location descriptor is missing, new_symbol will create
3899 a LOC_UNRESOLVED symbol, the address of the variable will then
3900 be determined from the minimal symbol table whenever the variable
3902 The address for the partial symbol table entry is not
3903 used by GDB, but it comes in handy for debugging partial symbol
3906 if (pdi
->locdesc
|| pdi
->has_type
)
3907 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3909 VAR_DOMAIN
, LOC_STATIC
,
3910 &objfile
->global_psymbols
,
3912 cu
->language
, objfile
);
3916 /* Static Variable. Skip symbols without location descriptors. */
3917 if (pdi
->locdesc
== NULL
)
3919 if (built_actual_name
)
3920 xfree (actual_name
);
3923 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
3924 mst_file_data, objfile); */
3925 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3927 VAR_DOMAIN
, LOC_STATIC
,
3928 &objfile
->static_psymbols
,
3930 cu
->language
, objfile
);
3933 case DW_TAG_typedef
:
3934 case DW_TAG_base_type
:
3935 case DW_TAG_subrange_type
:
3936 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3938 VAR_DOMAIN
, LOC_TYPEDEF
,
3939 &objfile
->static_psymbols
,
3940 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3942 case DW_TAG_namespace
:
3943 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3945 VAR_DOMAIN
, LOC_TYPEDEF
,
3946 &objfile
->global_psymbols
,
3947 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3949 case DW_TAG_class_type
:
3950 case DW_TAG_interface_type
:
3951 case DW_TAG_structure_type
:
3952 case DW_TAG_union_type
:
3953 case DW_TAG_enumeration_type
:
3954 /* Skip external references. The DWARF standard says in the section
3955 about "Structure, Union, and Class Type Entries": "An incomplete
3956 structure, union or class type is represented by a structure,
3957 union or class entry that does not have a byte size attribute
3958 and that has a DW_AT_declaration attribute." */
3959 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3961 if (built_actual_name
)
3962 xfree (actual_name
);
3966 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3967 static vs. global. */
3968 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3970 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3971 (cu
->language
== language_cplus
3972 || cu
->language
== language_java
)
3973 ? &objfile
->global_psymbols
3974 : &objfile
->static_psymbols
,
3975 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3978 case DW_TAG_enumerator
:
3979 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3981 VAR_DOMAIN
, LOC_CONST
,
3982 (cu
->language
== language_cplus
3983 || cu
->language
== language_java
)
3984 ? &objfile
->global_psymbols
3985 : &objfile
->static_psymbols
,
3986 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3992 if (built_actual_name
)
3993 xfree (actual_name
);
3996 /* Read a partial die corresponding to a namespace; also, add a symbol
3997 corresponding to that namespace to the symbol table. NAMESPACE is
3998 the name of the enclosing namespace. */
4001 add_partial_namespace (struct partial_die_info
*pdi
,
4002 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4003 int need_pc
, struct dwarf2_cu
*cu
)
4005 /* Add a symbol for the namespace. */
4007 add_partial_symbol (pdi
, cu
);
4009 /* Now scan partial symbols in that namespace. */
4011 if (pdi
->has_children
)
4012 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4015 /* Read a partial die corresponding to a Fortran module. */
4018 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4019 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4021 /* Now scan partial symbols in that module. */
4023 if (pdi
->has_children
)
4024 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4027 /* Read a partial die corresponding to a subprogram and create a partial
4028 symbol for that subprogram. When the CU language allows it, this
4029 routine also defines a partial symbol for each nested subprogram
4030 that this subprogram contains.
4032 DIE my also be a lexical block, in which case we simply search
4033 recursively for suprograms defined inside that lexical block.
4034 Again, this is only performed when the CU language allows this
4035 type of definitions. */
4038 add_partial_subprogram (struct partial_die_info
*pdi
,
4039 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4040 int need_pc
, struct dwarf2_cu
*cu
)
4042 if (pdi
->tag
== DW_TAG_subprogram
)
4044 if (pdi
->has_pc_info
)
4046 if (pdi
->lowpc
< *lowpc
)
4047 *lowpc
= pdi
->lowpc
;
4048 if (pdi
->highpc
> *highpc
)
4049 *highpc
= pdi
->highpc
;
4053 struct objfile
*objfile
= cu
->objfile
;
4055 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4056 SECT_OFF_TEXT (objfile
));
4057 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4058 pdi
->lowpc
+ baseaddr
,
4059 pdi
->highpc
- 1 + baseaddr
,
4060 cu
->per_cu
->v
.psymtab
);
4062 if (!pdi
->is_declaration
)
4063 /* Ignore subprogram DIEs that do not have a name, they are
4064 illegal. Do not emit a complaint at this point, we will
4065 do so when we convert this psymtab into a symtab. */
4067 add_partial_symbol (pdi
, cu
);
4071 if (! pdi
->has_children
)
4074 if (cu
->language
== language_ada
)
4076 pdi
= pdi
->die_child
;
4079 fixup_partial_die (pdi
, cu
);
4080 if (pdi
->tag
== DW_TAG_subprogram
4081 || pdi
->tag
== DW_TAG_lexical_block
)
4082 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4083 pdi
= pdi
->die_sibling
;
4088 /* Read a partial die corresponding to an enumeration type. */
4091 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4092 struct dwarf2_cu
*cu
)
4094 struct partial_die_info
*pdi
;
4096 if (enum_pdi
->name
!= NULL
)
4097 add_partial_symbol (enum_pdi
, cu
);
4099 pdi
= enum_pdi
->die_child
;
4102 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4103 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4105 add_partial_symbol (pdi
, cu
);
4106 pdi
= pdi
->die_sibling
;
4110 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4111 Return the corresponding abbrev, or NULL if the number is zero (indicating
4112 an empty DIE). In either case *BYTES_READ will be set to the length of
4113 the initial number. */
4115 static struct abbrev_info
*
4116 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4117 struct dwarf2_cu
*cu
)
4119 bfd
*abfd
= cu
->objfile
->obfd
;
4120 unsigned int abbrev_number
;
4121 struct abbrev_info
*abbrev
;
4123 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4125 if (abbrev_number
== 0)
4128 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4131 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4132 abbrev_number
, bfd_get_filename (abfd
));
4138 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4139 Returns a pointer to the end of a series of DIEs, terminated by an empty
4140 DIE. Any children of the skipped DIEs will also be skipped. */
4143 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4145 struct abbrev_info
*abbrev
;
4146 unsigned int bytes_read
;
4150 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4152 return info_ptr
+ bytes_read
;
4154 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4158 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4159 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4160 abbrev corresponding to that skipped uleb128 should be passed in
4161 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4165 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4166 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4168 unsigned int bytes_read
;
4169 struct attribute attr
;
4170 bfd
*abfd
= cu
->objfile
->obfd
;
4171 unsigned int form
, i
;
4173 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4175 /* The only abbrev we care about is DW_AT_sibling. */
4176 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4178 read_attribute (&attr
, &abbrev
->attrs
[i
],
4179 abfd
, info_ptr
, cu
);
4180 if (attr
.form
== DW_FORM_ref_addr
)
4181 complaint (&symfile_complaints
,
4182 _("ignoring absolute DW_AT_sibling"));
4184 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4187 /* If it isn't DW_AT_sibling, skip this attribute. */
4188 form
= abbrev
->attrs
[i
].form
;
4192 case DW_FORM_ref_addr
:
4193 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4194 and later it is offset sized. */
4195 if (cu
->header
.version
== 2)
4196 info_ptr
+= cu
->header
.addr_size
;
4198 info_ptr
+= cu
->header
.offset_size
;
4201 info_ptr
+= cu
->header
.addr_size
;
4208 case DW_FORM_flag_present
:
4220 case DW_FORM_ref_sig8
:
4223 case DW_FORM_string
:
4224 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4225 info_ptr
+= bytes_read
;
4227 case DW_FORM_sec_offset
:
4229 info_ptr
+= cu
->header
.offset_size
;
4231 case DW_FORM_exprloc
:
4233 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4234 info_ptr
+= bytes_read
;
4236 case DW_FORM_block1
:
4237 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4239 case DW_FORM_block2
:
4240 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4242 case DW_FORM_block4
:
4243 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4247 case DW_FORM_ref_udata
:
4248 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4250 case DW_FORM_indirect
:
4251 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4252 info_ptr
+= bytes_read
;
4253 /* We need to continue parsing from here, so just go back to
4255 goto skip_attribute
;
4258 error (_("Dwarf Error: Cannot handle %s "
4259 "in DWARF reader [in module %s]"),
4260 dwarf_form_name (form
),
4261 bfd_get_filename (abfd
));
4265 if (abbrev
->has_children
)
4266 return skip_children (buffer
, info_ptr
, cu
);
4271 /* Locate ORIG_PDI's sibling.
4272 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4276 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4277 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4278 bfd
*abfd
, struct dwarf2_cu
*cu
)
4280 /* Do we know the sibling already? */
4282 if (orig_pdi
->sibling
)
4283 return orig_pdi
->sibling
;
4285 /* Are there any children to deal with? */
4287 if (!orig_pdi
->has_children
)
4290 /* Skip the children the long way. */
4292 return skip_children (buffer
, info_ptr
, cu
);
4295 /* Expand this partial symbol table into a full symbol table. */
4298 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4304 warning (_("bug: psymtab for %s is already read in."),
4311 printf_filtered (_("Reading in symbols for %s..."),
4313 gdb_flush (gdb_stdout
);
4316 /* Restore our global data. */
4317 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4318 dwarf2_objfile_data_key
);
4320 /* If this psymtab is constructed from a debug-only objfile, the
4321 has_section_at_zero flag will not necessarily be correct. We
4322 can get the correct value for this flag by looking at the data
4323 associated with the (presumably stripped) associated objfile. */
4324 if (pst
->objfile
->separate_debug_objfile_backlink
)
4326 struct dwarf2_per_objfile
*dpo_backlink
4327 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4328 dwarf2_objfile_data_key
);
4330 dwarf2_per_objfile
->has_section_at_zero
4331 = dpo_backlink
->has_section_at_zero
;
4334 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4336 psymtab_to_symtab_1 (pst
);
4338 /* Finish up the debug error message. */
4340 printf_filtered (_("done.\n"));
4345 /* Add PER_CU to the queue. */
4348 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4350 struct dwarf2_queue_item
*item
;
4353 item
= xmalloc (sizeof (*item
));
4354 item
->per_cu
= per_cu
;
4357 if (dwarf2_queue
== NULL
)
4358 dwarf2_queue
= item
;
4360 dwarf2_queue_tail
->next
= item
;
4362 dwarf2_queue_tail
= item
;
4365 /* Process the queue. */
4368 process_queue (struct objfile
*objfile
)
4370 struct dwarf2_queue_item
*item
, *next_item
;
4372 /* The queue starts out with one item, but following a DIE reference
4373 may load a new CU, adding it to the end of the queue. */
4374 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4376 if (dwarf2_per_objfile
->using_index
4377 ? !item
->per_cu
->v
.quick
->symtab
4378 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4379 process_full_comp_unit (item
->per_cu
);
4381 item
->per_cu
->queued
= 0;
4382 next_item
= item
->next
;
4386 dwarf2_queue_tail
= NULL
;
4389 /* Free all allocated queue entries. This function only releases anything if
4390 an error was thrown; if the queue was processed then it would have been
4391 freed as we went along. */
4394 dwarf2_release_queue (void *dummy
)
4396 struct dwarf2_queue_item
*item
, *last
;
4398 item
= dwarf2_queue
;
4401 /* Anything still marked queued is likely to be in an
4402 inconsistent state, so discard it. */
4403 if (item
->per_cu
->queued
)
4405 if (item
->per_cu
->cu
!= NULL
)
4406 free_one_cached_comp_unit (item
->per_cu
->cu
);
4407 item
->per_cu
->queued
= 0;
4415 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4418 /* Read in full symbols for PST, and anything it depends on. */
4421 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4423 struct dwarf2_per_cu_data
*per_cu
;
4424 struct cleanup
*back_to
;
4427 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4428 if (!pst
->dependencies
[i
]->readin
)
4430 /* Inform about additional files that need to be read in. */
4433 /* FIXME: i18n: Need to make this a single string. */
4434 fputs_filtered (" ", gdb_stdout
);
4436 fputs_filtered ("and ", gdb_stdout
);
4438 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4439 wrap_here (""); /* Flush output. */
4440 gdb_flush (gdb_stdout
);
4442 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4445 per_cu
= pst
->read_symtab_private
;
4449 /* It's an include file, no symbols to read for it.
4450 Everything is in the parent symtab. */
4455 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4458 /* Load the DIEs associated with PER_CU into memory. */
4461 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
4462 struct objfile
*objfile
)
4464 bfd
*abfd
= objfile
->obfd
;
4465 struct dwarf2_cu
*cu
;
4466 unsigned int offset
;
4467 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4468 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4469 struct attribute
*attr
;
4472 gdb_assert (! per_cu
->from_debug_types
);
4474 /* Set local variables from the partial symbol table info. */
4475 offset
= per_cu
->offset
;
4477 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4478 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4479 beg_of_comp_unit
= info_ptr
;
4481 if (per_cu
->cu
== NULL
)
4483 cu
= xmalloc (sizeof (*cu
));
4484 init_one_comp_unit (cu
, objfile
);
4488 /* If an error occurs while loading, release our storage. */
4489 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4491 /* Read in the comp_unit header. */
4492 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4494 /* Complete the cu_header. */
4495 cu
->header
.offset
= offset
;
4496 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4498 /* Read the abbrevs for this compilation unit. */
4499 dwarf2_read_abbrevs (abfd
, cu
);
4500 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4502 /* Link this compilation unit into the compilation unit tree. */
4504 cu
->per_cu
= per_cu
;
4506 /* Link this CU into read_in_chain. */
4507 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4508 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4513 info_ptr
+= cu
->header
.first_die_offset
;
4516 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4518 /* We try not to read any attributes in this function, because not
4519 all objfiles needed for references have been loaded yet, and symbol
4520 table processing isn't initialized. But we have to set the CU language,
4521 or we won't be able to build types correctly. */
4522 prepare_one_comp_unit (cu
, cu
->dies
);
4524 /* Similarly, if we do not read the producer, we can not apply
4525 producer-specific interpretation. */
4526 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4528 cu
->producer
= DW_STRING (attr
);
4532 do_cleanups (free_abbrevs_cleanup
);
4534 /* We've successfully allocated this compilation unit. Let our
4535 caller clean it up when finished with it. */
4536 discard_cleanups (free_cu_cleanup
);
4540 /* Add a DIE to the delayed physname list. */
4543 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4544 const char *name
, struct die_info
*die
,
4545 struct dwarf2_cu
*cu
)
4547 struct delayed_method_info mi
;
4549 mi
.fnfield_index
= fnfield_index
;
4553 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4556 /* A cleanup for freeing the delayed method list. */
4559 free_delayed_list (void *ptr
)
4561 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4562 if (cu
->method_list
!= NULL
)
4564 VEC_free (delayed_method_info
, cu
->method_list
);
4565 cu
->method_list
= NULL
;
4569 /* Compute the physnames of any methods on the CU's method list.
4571 The computation of method physnames is delayed in order to avoid the
4572 (bad) condition that one of the method's formal parameters is of an as yet
4576 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4579 struct delayed_method_info
*mi
;
4580 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4583 struct fn_fieldlist
*fn_flp
4584 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4585 physname
= (char *) dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4586 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4590 /* Generate full symbol information for PST and CU, whose DIEs have
4591 already been loaded into memory. */
4594 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4596 struct dwarf2_cu
*cu
= per_cu
->cu
;
4597 struct objfile
*objfile
= per_cu
->objfile
;
4598 CORE_ADDR lowpc
, highpc
;
4599 struct symtab
*symtab
;
4600 struct cleanup
*back_to
, *delayed_list_cleanup
;
4603 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4606 back_to
= make_cleanup (really_free_pendings
, NULL
);
4607 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4609 cu
->list_in_scope
= &file_symbols
;
4611 dwarf2_find_base_address (cu
->dies
, cu
);
4613 /* Do line number decoding in read_file_scope () */
4614 process_die (cu
->dies
, cu
);
4616 /* Now that we have processed all the DIEs in the CU, all the types
4617 should be complete, and it should now be safe to compute all of the
4619 compute_delayed_physnames (cu
);
4620 do_cleanups (delayed_list_cleanup
);
4622 /* Some compilers don't define a DW_AT_high_pc attribute for the
4623 compilation unit. If the DW_AT_high_pc is missing, synthesize
4624 it, by scanning the DIE's below the compilation unit. */
4625 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4627 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4629 /* Set symtab language to language from DW_AT_language.
4630 If the compilation is from a C file generated by language preprocessors,
4631 do not set the language if it was already deduced by start_subfile. */
4633 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4635 symtab
->language
= cu
->language
;
4638 if (dwarf2_per_objfile
->using_index
)
4639 per_cu
->v
.quick
->symtab
= symtab
;
4642 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4643 pst
->symtab
= symtab
;
4647 do_cleanups (back_to
);
4650 /* Process a die and its children. */
4653 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4657 case DW_TAG_padding
:
4659 case DW_TAG_compile_unit
:
4660 read_file_scope (die
, cu
);
4662 case DW_TAG_type_unit
:
4663 read_type_unit_scope (die
, cu
);
4665 case DW_TAG_subprogram
:
4666 case DW_TAG_inlined_subroutine
:
4667 read_func_scope (die
, cu
);
4669 case DW_TAG_lexical_block
:
4670 case DW_TAG_try_block
:
4671 case DW_TAG_catch_block
:
4672 read_lexical_block_scope (die
, cu
);
4674 case DW_TAG_class_type
:
4675 case DW_TAG_interface_type
:
4676 case DW_TAG_structure_type
:
4677 case DW_TAG_union_type
:
4678 process_structure_scope (die
, cu
);
4680 case DW_TAG_enumeration_type
:
4681 process_enumeration_scope (die
, cu
);
4684 /* These dies have a type, but processing them does not create
4685 a symbol or recurse to process the children. Therefore we can
4686 read them on-demand through read_type_die. */
4687 case DW_TAG_subroutine_type
:
4688 case DW_TAG_set_type
:
4689 case DW_TAG_array_type
:
4690 case DW_TAG_pointer_type
:
4691 case DW_TAG_ptr_to_member_type
:
4692 case DW_TAG_reference_type
:
4693 case DW_TAG_string_type
:
4696 case DW_TAG_base_type
:
4697 case DW_TAG_subrange_type
:
4698 case DW_TAG_typedef
:
4699 /* Add a typedef symbol for the type definition, if it has a
4701 new_symbol (die
, read_type_die (die
, cu
), cu
);
4703 case DW_TAG_common_block
:
4704 read_common_block (die
, cu
);
4706 case DW_TAG_common_inclusion
:
4708 case DW_TAG_namespace
:
4709 processing_has_namespace_info
= 1;
4710 read_namespace (die
, cu
);
4713 processing_has_namespace_info
= 1;
4714 read_module (die
, cu
);
4716 case DW_TAG_imported_declaration
:
4717 case DW_TAG_imported_module
:
4718 processing_has_namespace_info
= 1;
4719 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4720 || cu
->language
!= language_fortran
))
4721 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4722 dwarf_tag_name (die
->tag
));
4723 read_import_statement (die
, cu
);
4726 new_symbol (die
, NULL
, cu
);
4731 /* A helper function for dwarf2_compute_name which determines whether DIE
4732 needs to have the name of the scope prepended to the name listed in the
4736 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4738 struct attribute
*attr
;
4742 case DW_TAG_namespace
:
4743 case DW_TAG_typedef
:
4744 case DW_TAG_class_type
:
4745 case DW_TAG_interface_type
:
4746 case DW_TAG_structure_type
:
4747 case DW_TAG_union_type
:
4748 case DW_TAG_enumeration_type
:
4749 case DW_TAG_enumerator
:
4750 case DW_TAG_subprogram
:
4754 case DW_TAG_variable
:
4755 case DW_TAG_constant
:
4756 /* We only need to prefix "globally" visible variables. These include
4757 any variable marked with DW_AT_external or any variable that
4758 lives in a namespace. [Variables in anonymous namespaces
4759 require prefixing, but they are not DW_AT_external.] */
4761 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4763 struct dwarf2_cu
*spec_cu
= cu
;
4765 return die_needs_namespace (die_specification (die
, &spec_cu
),
4769 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4770 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4771 && die
->parent
->tag
!= DW_TAG_module
)
4773 /* A variable in a lexical block of some kind does not need a
4774 namespace, even though in C++ such variables may be external
4775 and have a mangled name. */
4776 if (die
->parent
->tag
== DW_TAG_lexical_block
4777 || die
->parent
->tag
== DW_TAG_try_block
4778 || die
->parent
->tag
== DW_TAG_catch_block
4779 || die
->parent
->tag
== DW_TAG_subprogram
)
4788 /* Retrieve the last character from a mem_file. */
4791 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4793 char *last_char_p
= (char *) object
;
4796 *last_char_p
= buffer
[length
- 1];
4799 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4800 compute the physname for the object, which include a method's
4801 formal parameters (C++/Java) and return type (Java).
4803 For Ada, return the DIE's linkage name rather than the fully qualified
4804 name. PHYSNAME is ignored..
4806 The result is allocated on the objfile_obstack and canonicalized. */
4809 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4813 name
= dwarf2_name (die
, cu
);
4815 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4816 compute it by typename_concat inside GDB. */
4817 if (cu
->language
== language_ada
4818 || (cu
->language
== language_fortran
&& physname
))
4820 /* For Ada unit, we prefer the linkage name over the name, as
4821 the former contains the exported name, which the user expects
4822 to be able to reference. Ideally, we want the user to be able
4823 to reference this entity using either natural or linkage name,
4824 but we haven't started looking at this enhancement yet. */
4825 struct attribute
*attr
;
4827 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4829 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4830 if (attr
&& DW_STRING (attr
))
4831 return DW_STRING (attr
);
4834 /* These are the only languages we know how to qualify names in. */
4836 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4837 || cu
->language
== language_fortran
))
4839 if (die_needs_namespace (die
, cu
))
4843 struct ui_file
*buf
;
4845 prefix
= determine_prefix (die
, cu
);
4846 buf
= mem_fileopen ();
4847 if (*prefix
!= '\0')
4849 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4852 fputs_unfiltered (prefixed_name
, buf
);
4853 xfree (prefixed_name
);
4856 fputs_unfiltered (name
, buf
);
4858 /* Template parameters may be specified in the DIE's DW_AT_name, or
4859 as children with DW_TAG_template_type_param or
4860 DW_TAG_value_type_param. If the latter, add them to the name
4861 here. If the name already has template parameters, then
4862 skip this step; some versions of GCC emit both, and
4863 it is more efficient to use the pre-computed name.
4865 Something to keep in mind about this process: it is very
4866 unlikely, or in some cases downright impossible, to produce
4867 something that will match the mangled name of a function.
4868 If the definition of the function has the same debug info,
4869 we should be able to match up with it anyway. But fallbacks
4870 using the minimal symbol, for instance to find a method
4871 implemented in a stripped copy of libstdc++, will not work.
4872 If we do not have debug info for the definition, we will have to
4873 match them up some other way.
4875 When we do name matching there is a related problem with function
4876 templates; two instantiated function templates are allowed to
4877 differ only by their return types, which we do not add here. */
4879 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
4881 struct attribute
*attr
;
4882 struct die_info
*child
;
4885 die
->building_fullname
= 1;
4887 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
4892 struct dwarf2_locexpr_baton
*baton
;
4895 if (child
->tag
!= DW_TAG_template_type_param
4896 && child
->tag
!= DW_TAG_template_value_param
)
4901 fputs_unfiltered ("<", buf
);
4905 fputs_unfiltered (", ", buf
);
4907 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
4910 complaint (&symfile_complaints
,
4911 _("template parameter missing DW_AT_type"));
4912 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
4915 type
= die_type (child
, cu
);
4917 if (child
->tag
== DW_TAG_template_type_param
)
4919 c_print_type (type
, "", buf
, -1, 0);
4923 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
4926 complaint (&symfile_complaints
,
4927 _("template parameter missing "
4928 "DW_AT_const_value"));
4929 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
4933 dwarf2_const_value_attr (attr
, type
, name
,
4934 &cu
->comp_unit_obstack
, cu
,
4935 &value
, &bytes
, &baton
);
4937 if (TYPE_NOSIGN (type
))
4938 /* GDB prints characters as NUMBER 'CHAR'. If that's
4939 changed, this can use value_print instead. */
4940 c_printchar (value
, type
, buf
);
4943 struct value_print_options opts
;
4946 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
4950 else if (bytes
!= NULL
)
4952 v
= allocate_value (type
);
4953 memcpy (value_contents_writeable (v
), bytes
,
4954 TYPE_LENGTH (type
));
4957 v
= value_from_longest (type
, value
);
4959 /* Specify decimal so that we do not depend on
4961 get_formatted_print_options (&opts
, 'd');
4963 value_print (v
, buf
, &opts
);
4969 die
->building_fullname
= 0;
4973 /* Close the argument list, with a space if necessary
4974 (nested templates). */
4975 char last_char
= '\0';
4976 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
4977 if (last_char
== '>')
4978 fputs_unfiltered (" >", buf
);
4980 fputs_unfiltered (">", buf
);
4984 /* For Java and C++ methods, append formal parameter type
4985 information, if PHYSNAME. */
4987 if (physname
&& die
->tag
== DW_TAG_subprogram
4988 && (cu
->language
== language_cplus
4989 || cu
->language
== language_java
))
4991 struct type
*type
= read_type_die (die
, cu
);
4993 c_type_print_args (type
, buf
, 1, cu
->language
);
4995 if (cu
->language
== language_java
)
4997 /* For java, we must append the return type to method
4999 if (die
->tag
== DW_TAG_subprogram
)
5000 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5003 else if (cu
->language
== language_cplus
)
5005 /* Assume that an artificial first parameter is
5006 "this", but do not crash if it is not. RealView
5007 marks unnamed (and thus unused) parameters as
5008 artificial; there is no way to differentiate
5010 if (TYPE_NFIELDS (type
) > 0
5011 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5012 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5013 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5015 fputs_unfiltered (" const", buf
);
5019 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
5021 ui_file_delete (buf
);
5023 if (cu
->language
== language_cplus
)
5026 = dwarf2_canonicalize_name (name
, cu
,
5027 &cu
->objfile
->objfile_obstack
);
5038 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5039 If scope qualifiers are appropriate they will be added. The result
5040 will be allocated on the objfile_obstack, or NULL if the DIE does
5041 not have a name. NAME may either be from a previous call to
5042 dwarf2_name or NULL.
5044 The output string will be canonicalized (if C++/Java). */
5047 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5049 return dwarf2_compute_name (name
, die
, cu
, 0);
5052 /* Construct a physname for the given DIE in CU. NAME may either be
5053 from a previous call to dwarf2_name or NULL. The result will be
5054 allocated on the objfile_objstack or NULL if the DIE does not have a
5057 The output string will be canonicalized (if C++/Java). */
5060 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5062 return dwarf2_compute_name (name
, die
, cu
, 1);
5065 /* Read the import statement specified by the given die and record it. */
5068 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5070 struct attribute
*import_attr
;
5071 struct die_info
*imported_die
;
5072 struct dwarf2_cu
*imported_cu
;
5073 const char *imported_name
;
5074 const char *imported_name_prefix
;
5075 const char *canonical_name
;
5076 const char *import_alias
;
5077 const char *imported_declaration
= NULL
;
5078 const char *import_prefix
;
5082 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5083 if (import_attr
== NULL
)
5085 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5086 dwarf_tag_name (die
->tag
));
5091 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5092 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5093 if (imported_name
== NULL
)
5095 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5097 The import in the following code:
5111 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5112 <52> DW_AT_decl_file : 1
5113 <53> DW_AT_decl_line : 6
5114 <54> DW_AT_import : <0x75>
5115 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5117 <5b> DW_AT_decl_file : 1
5118 <5c> DW_AT_decl_line : 2
5119 <5d> DW_AT_type : <0x6e>
5121 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5122 <76> DW_AT_byte_size : 4
5123 <77> DW_AT_encoding : 5 (signed)
5125 imports the wrong die ( 0x75 instead of 0x58 ).
5126 This case will be ignored until the gcc bug is fixed. */
5130 /* Figure out the local name after import. */
5131 import_alias
= dwarf2_name (die
, cu
);
5133 /* Figure out where the statement is being imported to. */
5134 import_prefix
= determine_prefix (die
, cu
);
5136 /* Figure out what the scope of the imported die is and prepend it
5137 to the name of the imported die. */
5138 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5140 if (imported_die
->tag
!= DW_TAG_namespace
5141 && imported_die
->tag
!= DW_TAG_module
)
5143 imported_declaration
= imported_name
;
5144 canonical_name
= imported_name_prefix
;
5146 else if (strlen (imported_name_prefix
) > 0)
5148 temp
= alloca (strlen (imported_name_prefix
)
5149 + 2 + strlen (imported_name
) + 1);
5150 strcpy (temp
, imported_name_prefix
);
5151 strcat (temp
, "::");
5152 strcat (temp
, imported_name
);
5153 canonical_name
= temp
;
5156 canonical_name
= imported_name
;
5158 cp_add_using_directive (import_prefix
,
5161 imported_declaration
,
5162 &cu
->objfile
->objfile_obstack
);
5166 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5168 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5171 /* Cleanup function for read_file_scope. */
5174 free_cu_line_header (void *arg
)
5176 struct dwarf2_cu
*cu
= arg
;
5178 free_line_header (cu
->line_header
);
5179 cu
->line_header
= NULL
;
5183 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5184 char **name
, char **comp_dir
)
5186 struct attribute
*attr
;
5191 /* Find the filename. Do not use dwarf2_name here, since the filename
5192 is not a source language identifier. */
5193 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5196 *name
= DW_STRING (attr
);
5199 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5201 *comp_dir
= DW_STRING (attr
);
5202 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5204 *comp_dir
= ldirname (*name
);
5205 if (*comp_dir
!= NULL
)
5206 make_cleanup (xfree
, *comp_dir
);
5208 if (*comp_dir
!= NULL
)
5210 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5211 directory, get rid of it. */
5212 char *cp
= strchr (*comp_dir
, ':');
5214 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5219 *name
= "<unknown>";
5222 /* Process DW_TAG_compile_unit. */
5225 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5227 struct objfile
*objfile
= cu
->objfile
;
5228 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5229 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5230 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5231 struct attribute
*attr
;
5233 char *comp_dir
= NULL
;
5234 struct die_info
*child_die
;
5235 bfd
*abfd
= objfile
->obfd
;
5236 struct line_header
*line_header
= 0;
5239 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5241 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5243 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5244 from finish_block. */
5245 if (lowpc
== ((CORE_ADDR
) -1))
5250 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5252 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5255 set_cu_language (DW_UNSND (attr
), cu
);
5258 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5260 cu
->producer
= DW_STRING (attr
);
5262 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5263 standardised yet. As a workaround for the language detection we fall
5264 back to the DW_AT_producer string. */
5265 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5266 cu
->language
= language_opencl
;
5268 /* We assume that we're processing GCC output. */
5269 processing_gcc_compilation
= 2;
5271 processing_has_namespace_info
= 0;
5273 start_symtab (name
, comp_dir
, lowpc
);
5274 record_debugformat ("DWARF 2");
5275 record_producer (cu
->producer
);
5277 initialize_cu_func_list (cu
);
5279 /* Decode line number information if present. We do this before
5280 processing child DIEs, so that the line header table is available
5281 for DW_AT_decl_file. */
5282 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5285 unsigned int line_offset
= DW_UNSND (attr
);
5286 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5289 cu
->line_header
= line_header
;
5290 make_cleanup (free_cu_line_header
, cu
);
5291 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5295 /* Process all dies in compilation unit. */
5296 if (die
->child
!= NULL
)
5298 child_die
= die
->child
;
5299 while (child_die
&& child_die
->tag
)
5301 process_die (child_die
, cu
);
5302 child_die
= sibling_die (child_die
);
5306 /* Decode macro information, if present. Dwarf 2 macro information
5307 refers to information in the line number info statement program
5308 header, so we can only read it if we've read the header
5310 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5311 if (attr
&& line_header
)
5313 unsigned int macro_offset
= DW_UNSND (attr
);
5315 dwarf_decode_macros (line_header
, macro_offset
,
5316 comp_dir
, abfd
, cu
);
5318 do_cleanups (back_to
);
5321 /* Process DW_TAG_type_unit.
5322 For TUs we want to skip the first top level sibling if it's not the
5323 actual type being defined by this TU. In this case the first top
5324 level sibling is there to provide context only. */
5327 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5329 struct objfile
*objfile
= cu
->objfile
;
5330 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5332 struct attribute
*attr
;
5334 char *comp_dir
= NULL
;
5335 struct die_info
*child_die
;
5336 bfd
*abfd
= objfile
->obfd
;
5338 /* start_symtab needs a low pc, but we don't really have one.
5339 Do what read_file_scope would do in the absence of such info. */
5340 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5342 /* Find the filename. Do not use dwarf2_name here, since the filename
5343 is not a source language identifier. */
5344 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5346 name
= DW_STRING (attr
);
5348 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5350 comp_dir
= DW_STRING (attr
);
5351 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5353 comp_dir
= ldirname (name
);
5354 if (comp_dir
!= NULL
)
5355 make_cleanup (xfree
, comp_dir
);
5361 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5363 set_cu_language (DW_UNSND (attr
), cu
);
5365 /* This isn't technically needed today. It is done for symmetry
5366 with read_file_scope. */
5367 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5369 cu
->producer
= DW_STRING (attr
);
5371 /* We assume that we're processing GCC output. */
5372 processing_gcc_compilation
= 2;
5374 processing_has_namespace_info
= 0;
5376 start_symtab (name
, comp_dir
, lowpc
);
5377 record_debugformat ("DWARF 2");
5378 record_producer (cu
->producer
);
5380 /* Process the dies in the type unit. */
5381 if (die
->child
== NULL
)
5383 dump_die_for_error (die
);
5384 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5385 bfd_get_filename (abfd
));
5388 child_die
= die
->child
;
5390 while (child_die
&& child_die
->tag
)
5392 process_die (child_die
, cu
);
5394 child_die
= sibling_die (child_die
);
5397 do_cleanups (back_to
);
5401 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5402 struct dwarf2_cu
*cu
)
5404 struct function_range
*thisfn
;
5406 thisfn
= (struct function_range
*)
5407 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5408 thisfn
->name
= name
;
5409 thisfn
->lowpc
= lowpc
;
5410 thisfn
->highpc
= highpc
;
5411 thisfn
->seen_line
= 0;
5412 thisfn
->next
= NULL
;
5414 if (cu
->last_fn
== NULL
)
5415 cu
->first_fn
= thisfn
;
5417 cu
->last_fn
->next
= thisfn
;
5419 cu
->last_fn
= thisfn
;
5422 /* qsort helper for inherit_abstract_dies. */
5425 unsigned_int_compar (const void *ap
, const void *bp
)
5427 unsigned int a
= *(unsigned int *) ap
;
5428 unsigned int b
= *(unsigned int *) bp
;
5430 return (a
> b
) - (b
> a
);
5433 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5434 Inherit only the children of the DW_AT_abstract_origin DIE not being
5435 already referenced by DW_AT_abstract_origin from the children of the
5439 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5441 struct die_info
*child_die
;
5442 unsigned die_children_count
;
5443 /* CU offsets which were referenced by children of the current DIE. */
5445 unsigned *offsets_end
, *offsetp
;
5446 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5447 struct die_info
*origin_die
;
5448 /* Iterator of the ORIGIN_DIE children. */
5449 struct die_info
*origin_child_die
;
5450 struct cleanup
*cleanups
;
5451 struct attribute
*attr
;
5452 struct dwarf2_cu
*origin_cu
;
5453 struct pending
**origin_previous_list_in_scope
;
5455 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5459 /* Note that following die references may follow to a die in a
5463 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5465 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5467 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5468 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5470 if (die
->tag
!= origin_die
->tag
5471 && !(die
->tag
== DW_TAG_inlined_subroutine
5472 && origin_die
->tag
== DW_TAG_subprogram
))
5473 complaint (&symfile_complaints
,
5474 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5475 die
->offset
, origin_die
->offset
);
5477 child_die
= die
->child
;
5478 die_children_count
= 0;
5479 while (child_die
&& child_die
->tag
)
5481 child_die
= sibling_die (child_die
);
5482 die_children_count
++;
5484 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5485 cleanups
= make_cleanup (xfree
, offsets
);
5487 offsets_end
= offsets
;
5488 child_die
= die
->child
;
5489 while (child_die
&& child_die
->tag
)
5491 /* For each CHILD_DIE, find the corresponding child of
5492 ORIGIN_DIE. If there is more than one layer of
5493 DW_AT_abstract_origin, follow them all; there shouldn't be,
5494 but GCC versions at least through 4.4 generate this (GCC PR
5496 struct die_info
*child_origin_die
= child_die
;
5497 struct dwarf2_cu
*child_origin_cu
= cu
;
5501 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5505 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5509 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5510 counterpart may exist. */
5511 if (child_origin_die
!= child_die
)
5513 if (child_die
->tag
!= child_origin_die
->tag
5514 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5515 && child_origin_die
->tag
== DW_TAG_subprogram
))
5516 complaint (&symfile_complaints
,
5517 _("Child DIE 0x%x and its abstract origin 0x%x have "
5518 "different tags"), child_die
->offset
,
5519 child_origin_die
->offset
);
5520 if (child_origin_die
->parent
!= origin_die
)
5521 complaint (&symfile_complaints
,
5522 _("Child DIE 0x%x and its abstract origin 0x%x have "
5523 "different parents"), child_die
->offset
,
5524 child_origin_die
->offset
);
5526 *offsets_end
++ = child_origin_die
->offset
;
5528 child_die
= sibling_die (child_die
);
5530 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5531 unsigned_int_compar
);
5532 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5533 if (offsetp
[-1] == *offsetp
)
5534 complaint (&symfile_complaints
,
5535 _("Multiple children of DIE 0x%x refer "
5536 "to DIE 0x%x as their abstract origin"),
5537 die
->offset
, *offsetp
);
5540 origin_child_die
= origin_die
->child
;
5541 while (origin_child_die
&& origin_child_die
->tag
)
5543 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5544 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5546 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5548 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5549 process_die (origin_child_die
, origin_cu
);
5551 origin_child_die
= sibling_die (origin_child_die
);
5553 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5555 do_cleanups (cleanups
);
5559 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5561 struct objfile
*objfile
= cu
->objfile
;
5562 struct context_stack
*new;
5565 struct die_info
*child_die
;
5566 struct attribute
*attr
, *call_line
, *call_file
;
5569 struct block
*block
;
5570 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5571 VEC (symbolp
) *template_args
= NULL
;
5572 struct template_symbol
*templ_func
= NULL
;
5576 /* If we do not have call site information, we can't show the
5577 caller of this inlined function. That's too confusing, so
5578 only use the scope for local variables. */
5579 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5580 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5581 if (call_line
== NULL
|| call_file
== NULL
)
5583 read_lexical_block_scope (die
, cu
);
5588 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5590 name
= dwarf2_name (die
, cu
);
5592 /* Ignore functions with missing or empty names. These are actually
5593 illegal according to the DWARF standard. */
5596 complaint (&symfile_complaints
,
5597 _("missing name for subprogram DIE at %d"), die
->offset
);
5601 /* Ignore functions with missing or invalid low and high pc attributes. */
5602 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5604 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5605 if (!attr
|| !DW_UNSND (attr
))
5606 complaint (&symfile_complaints
,
5607 _("cannot get low and high bounds "
5608 "for subprogram DIE at %d"),
5616 /* Record the function range for dwarf_decode_lines. */
5617 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5619 /* If we have any template arguments, then we must allocate a
5620 different sort of symbol. */
5621 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5623 if (child_die
->tag
== DW_TAG_template_type_param
5624 || child_die
->tag
== DW_TAG_template_value_param
)
5626 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5627 struct template_symbol
);
5628 templ_func
->base
.is_cplus_template_function
= 1;
5633 new = push_context (0, lowpc
);
5634 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5635 (struct symbol
*) templ_func
);
5637 /* If there is a location expression for DW_AT_frame_base, record
5639 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5641 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5642 expression is being recorded directly in the function's symbol
5643 and not in a separate frame-base object. I guess this hack is
5644 to avoid adding some sort of frame-base adjunct/annex to the
5645 function's symbol :-(. The problem with doing this is that it
5646 results in a function symbol with a location expression that
5647 has nothing to do with the location of the function, ouch! The
5648 relationship should be: a function's symbol has-a frame base; a
5649 frame-base has-a location expression. */
5650 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5652 cu
->list_in_scope
= &local_symbols
;
5654 if (die
->child
!= NULL
)
5656 child_die
= die
->child
;
5657 while (child_die
&& child_die
->tag
)
5659 if (child_die
->tag
== DW_TAG_template_type_param
5660 || child_die
->tag
== DW_TAG_template_value_param
)
5662 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5665 VEC_safe_push (symbolp
, template_args
, arg
);
5668 process_die (child_die
, cu
);
5669 child_die
= sibling_die (child_die
);
5673 inherit_abstract_dies (die
, cu
);
5675 /* If we have a DW_AT_specification, we might need to import using
5676 directives from the context of the specification DIE. See the
5677 comment in determine_prefix. */
5678 if (cu
->language
== language_cplus
5679 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5681 struct dwarf2_cu
*spec_cu
= cu
;
5682 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5686 child_die
= spec_die
->child
;
5687 while (child_die
&& child_die
->tag
)
5689 if (child_die
->tag
== DW_TAG_imported_module
)
5690 process_die (child_die
, spec_cu
);
5691 child_die
= sibling_die (child_die
);
5694 /* In some cases, GCC generates specification DIEs that
5695 themselves contain DW_AT_specification attributes. */
5696 spec_die
= die_specification (spec_die
, &spec_cu
);
5700 new = pop_context ();
5701 /* Make a block for the local symbols within. */
5702 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5703 lowpc
, highpc
, objfile
);
5705 /* For C++, set the block's scope. */
5706 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5707 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5708 determine_prefix (die
, cu
),
5709 processing_has_namespace_info
);
5711 /* If we have address ranges, record them. */
5712 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5714 /* Attach template arguments to function. */
5715 if (! VEC_empty (symbolp
, template_args
))
5717 gdb_assert (templ_func
!= NULL
);
5719 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5720 templ_func
->template_arguments
5721 = obstack_alloc (&objfile
->objfile_obstack
,
5722 (templ_func
->n_template_arguments
5723 * sizeof (struct symbol
*)));
5724 memcpy (templ_func
->template_arguments
,
5725 VEC_address (symbolp
, template_args
),
5726 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5727 VEC_free (symbolp
, template_args
);
5730 /* In C++, we can have functions nested inside functions (e.g., when
5731 a function declares a class that has methods). This means that
5732 when we finish processing a function scope, we may need to go
5733 back to building a containing block's symbol lists. */
5734 local_symbols
= new->locals
;
5735 param_symbols
= new->params
;
5736 using_directives
= new->using_directives
;
5738 /* If we've finished processing a top-level function, subsequent
5739 symbols go in the file symbol list. */
5740 if (outermost_context_p ())
5741 cu
->list_in_scope
= &file_symbols
;
5744 /* Process all the DIES contained within a lexical block scope. Start
5745 a new scope, process the dies, and then close the scope. */
5748 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5750 struct objfile
*objfile
= cu
->objfile
;
5751 struct context_stack
*new;
5752 CORE_ADDR lowpc
, highpc
;
5753 struct die_info
*child_die
;
5756 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5758 /* Ignore blocks with missing or invalid low and high pc attributes. */
5759 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5760 as multiple lexical blocks? Handling children in a sane way would
5761 be nasty. Might be easier to properly extend generic blocks to
5763 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5768 push_context (0, lowpc
);
5769 if (die
->child
!= NULL
)
5771 child_die
= die
->child
;
5772 while (child_die
&& child_die
->tag
)
5774 process_die (child_die
, cu
);
5775 child_die
= sibling_die (child_die
);
5778 new = pop_context ();
5780 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5783 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5786 /* Note that recording ranges after traversing children, as we
5787 do here, means that recording a parent's ranges entails
5788 walking across all its children's ranges as they appear in
5789 the address map, which is quadratic behavior.
5791 It would be nicer to record the parent's ranges before
5792 traversing its children, simply overriding whatever you find
5793 there. But since we don't even decide whether to create a
5794 block until after we've traversed its children, that's hard
5796 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5798 local_symbols
= new->locals
;
5799 using_directives
= new->using_directives
;
5802 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5803 Return 1 if the attributes are present and valid, otherwise, return 0.
5804 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5807 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5808 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5809 struct partial_symtab
*ranges_pst
)
5811 struct objfile
*objfile
= cu
->objfile
;
5812 struct comp_unit_head
*cu_header
= &cu
->header
;
5813 bfd
*obfd
= objfile
->obfd
;
5814 unsigned int addr_size
= cu_header
->addr_size
;
5815 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5816 /* Base address selection entry. */
5827 found_base
= cu
->base_known
;
5828 base
= cu
->base_address
;
5830 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5831 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5833 complaint (&symfile_complaints
,
5834 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5838 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5840 /* Read in the largest possible address. */
5841 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5842 if ((marker
& mask
) == mask
)
5844 /* If we found the largest possible address, then
5845 read the base address. */
5846 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5847 buffer
+= 2 * addr_size
;
5848 offset
+= 2 * addr_size
;
5854 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5858 CORE_ADDR range_beginning
, range_end
;
5860 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5861 buffer
+= addr_size
;
5862 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5863 buffer
+= addr_size
;
5864 offset
+= 2 * addr_size
;
5866 /* An end of list marker is a pair of zero addresses. */
5867 if (range_beginning
== 0 && range_end
== 0)
5868 /* Found the end of list entry. */
5871 /* Each base address selection entry is a pair of 2 values.
5872 The first is the largest possible address, the second is
5873 the base address. Check for a base address here. */
5874 if ((range_beginning
& mask
) == mask
)
5876 /* If we found the largest possible address, then
5877 read the base address. */
5878 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5885 /* We have no valid base address for the ranges
5887 complaint (&symfile_complaints
,
5888 _("Invalid .debug_ranges data (no base address)"));
5892 if (range_beginning
> range_end
)
5894 /* Inverted range entries are invalid. */
5895 complaint (&symfile_complaints
,
5896 _("Invalid .debug_ranges data (inverted range)"));
5900 /* Empty range entries have no effect. */
5901 if (range_beginning
== range_end
)
5904 range_beginning
+= base
;
5907 if (ranges_pst
!= NULL
)
5908 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5909 range_beginning
+ baseaddr
,
5910 range_end
- 1 + baseaddr
,
5913 /* FIXME: This is recording everything as a low-high
5914 segment of consecutive addresses. We should have a
5915 data structure for discontiguous block ranges
5919 low
= range_beginning
;
5925 if (range_beginning
< low
)
5926 low
= range_beginning
;
5927 if (range_end
> high
)
5933 /* If the first entry is an end-of-list marker, the range
5934 describes an empty scope, i.e. no instructions. */
5940 *high_return
= high
;
5944 /* Get low and high pc attributes from a die. Return 1 if the attributes
5945 are present and valid, otherwise, return 0. Return -1 if the range is
5946 discontinuous, i.e. derived from DW_AT_ranges information. */
5948 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5949 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5950 struct partial_symtab
*pst
)
5952 struct attribute
*attr
;
5957 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5960 high
= DW_ADDR (attr
);
5961 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5963 low
= DW_ADDR (attr
);
5965 /* Found high w/o low attribute. */
5968 /* Found consecutive range of addresses. */
5973 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5976 /* Value of the DW_AT_ranges attribute is the offset in the
5977 .debug_ranges section. */
5978 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
5980 /* Found discontinuous range of addresses. */
5985 /* read_partial_die has also the strict LOW < HIGH requirement. */
5989 /* When using the GNU linker, .gnu.linkonce. sections are used to
5990 eliminate duplicate copies of functions and vtables and such.
5991 The linker will arbitrarily choose one and discard the others.
5992 The AT_*_pc values for such functions refer to local labels in
5993 these sections. If the section from that file was discarded, the
5994 labels are not in the output, so the relocs get a value of 0.
5995 If this is a discarded function, mark the pc bounds as invalid,
5996 so that GDB will ignore it. */
5997 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6005 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6006 its low and high PC addresses. Do nothing if these addresses could not
6007 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6008 and HIGHPC to the high address if greater than HIGHPC. */
6011 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6012 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6013 struct dwarf2_cu
*cu
)
6015 CORE_ADDR low
, high
;
6016 struct die_info
*child
= die
->child
;
6018 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6020 *lowpc
= min (*lowpc
, low
);
6021 *highpc
= max (*highpc
, high
);
6024 /* If the language does not allow nested subprograms (either inside
6025 subprograms or lexical blocks), we're done. */
6026 if (cu
->language
!= language_ada
)
6029 /* Check all the children of the given DIE. If it contains nested
6030 subprograms, then check their pc bounds. Likewise, we need to
6031 check lexical blocks as well, as they may also contain subprogram
6033 while (child
&& child
->tag
)
6035 if (child
->tag
== DW_TAG_subprogram
6036 || child
->tag
== DW_TAG_lexical_block
)
6037 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6038 child
= sibling_die (child
);
6042 /* Get the low and high pc's represented by the scope DIE, and store
6043 them in *LOWPC and *HIGHPC. If the correct values can't be
6044 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6047 get_scope_pc_bounds (struct die_info
*die
,
6048 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6049 struct dwarf2_cu
*cu
)
6051 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6052 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6053 CORE_ADDR current_low
, current_high
;
6055 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6057 best_low
= current_low
;
6058 best_high
= current_high
;
6062 struct die_info
*child
= die
->child
;
6064 while (child
&& child
->tag
)
6066 switch (child
->tag
) {
6067 case DW_TAG_subprogram
:
6068 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6070 case DW_TAG_namespace
:
6072 /* FIXME: carlton/2004-01-16: Should we do this for
6073 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6074 that current GCC's always emit the DIEs corresponding
6075 to definitions of methods of classes as children of a
6076 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6077 the DIEs giving the declarations, which could be
6078 anywhere). But I don't see any reason why the
6079 standards says that they have to be there. */
6080 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6082 if (current_low
!= ((CORE_ADDR
) -1))
6084 best_low
= min (best_low
, current_low
);
6085 best_high
= max (best_high
, current_high
);
6093 child
= sibling_die (child
);
6098 *highpc
= best_high
;
6101 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6104 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6105 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6107 struct attribute
*attr
;
6109 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6112 CORE_ADDR high
= DW_ADDR (attr
);
6114 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6117 CORE_ADDR low
= DW_ADDR (attr
);
6119 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6123 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6126 bfd
*obfd
= cu
->objfile
->obfd
;
6128 /* The value of the DW_AT_ranges attribute is the offset of the
6129 address range list in the .debug_ranges section. */
6130 unsigned long offset
= DW_UNSND (attr
);
6131 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6133 /* For some target architectures, but not others, the
6134 read_address function sign-extends the addresses it returns.
6135 To recognize base address selection entries, we need a
6137 unsigned int addr_size
= cu
->header
.addr_size
;
6138 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6140 /* The base address, to which the next pair is relative. Note
6141 that this 'base' is a DWARF concept: most entries in a range
6142 list are relative, to reduce the number of relocs against the
6143 debugging information. This is separate from this function's
6144 'baseaddr' argument, which GDB uses to relocate debugging
6145 information from a shared library based on the address at
6146 which the library was loaded. */
6147 CORE_ADDR base
= cu
->base_address
;
6148 int base_known
= cu
->base_known
;
6150 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6151 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6153 complaint (&symfile_complaints
,
6154 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6161 unsigned int bytes_read
;
6162 CORE_ADDR start
, end
;
6164 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6165 buffer
+= bytes_read
;
6166 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6167 buffer
+= bytes_read
;
6169 /* Did we find the end of the range list? */
6170 if (start
== 0 && end
== 0)
6173 /* Did we find a base address selection entry? */
6174 else if ((start
& base_select_mask
) == base_select_mask
)
6180 /* We found an ordinary address range. */
6185 complaint (&symfile_complaints
,
6186 _("Invalid .debug_ranges data "
6187 "(no base address)"));
6193 /* Inverted range entries are invalid. */
6194 complaint (&symfile_complaints
,
6195 _("Invalid .debug_ranges data "
6196 "(inverted range)"));
6200 /* Empty range entries have no effect. */
6204 record_block_range (block
,
6205 baseaddr
+ base
+ start
,
6206 baseaddr
+ base
+ end
- 1);
6212 /* Add an aggregate field to the field list. */
6215 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6216 struct dwarf2_cu
*cu
)
6218 struct objfile
*objfile
= cu
->objfile
;
6219 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6220 struct nextfield
*new_field
;
6221 struct attribute
*attr
;
6223 char *fieldname
= "";
6225 /* Allocate a new field list entry and link it in. */
6226 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6227 make_cleanup (xfree
, new_field
);
6228 memset (new_field
, 0, sizeof (struct nextfield
));
6230 if (die
->tag
== DW_TAG_inheritance
)
6232 new_field
->next
= fip
->baseclasses
;
6233 fip
->baseclasses
= new_field
;
6237 new_field
->next
= fip
->fields
;
6238 fip
->fields
= new_field
;
6242 /* Handle accessibility and virtuality of field.
6243 The default accessibility for members is public, the default
6244 accessibility for inheritance is private. */
6245 if (die
->tag
!= DW_TAG_inheritance
)
6246 new_field
->accessibility
= DW_ACCESS_public
;
6248 new_field
->accessibility
= DW_ACCESS_private
;
6249 new_field
->virtuality
= DW_VIRTUALITY_none
;
6251 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6253 new_field
->accessibility
= DW_UNSND (attr
);
6254 if (new_field
->accessibility
!= DW_ACCESS_public
)
6255 fip
->non_public_fields
= 1;
6256 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6258 new_field
->virtuality
= DW_UNSND (attr
);
6260 fp
= &new_field
->field
;
6262 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6264 /* Data member other than a C++ static data member. */
6266 /* Get type of field. */
6267 fp
->type
= die_type (die
, cu
);
6269 SET_FIELD_BITPOS (*fp
, 0);
6271 /* Get bit size of field (zero if none). */
6272 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6275 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6279 FIELD_BITSIZE (*fp
) = 0;
6282 /* Get bit offset of field. */
6283 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6286 int byte_offset
= 0;
6288 if (attr_form_is_section_offset (attr
))
6289 dwarf2_complex_location_expr_complaint ();
6290 else if (attr_form_is_constant (attr
))
6291 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6292 else if (attr_form_is_block (attr
))
6293 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6295 dwarf2_complex_location_expr_complaint ();
6297 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6299 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6302 if (gdbarch_bits_big_endian (gdbarch
))
6304 /* For big endian bits, the DW_AT_bit_offset gives the
6305 additional bit offset from the MSB of the containing
6306 anonymous object to the MSB of the field. We don't
6307 have to do anything special since we don't need to
6308 know the size of the anonymous object. */
6309 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6313 /* For little endian bits, compute the bit offset to the
6314 MSB of the anonymous object, subtract off the number of
6315 bits from the MSB of the field to the MSB of the
6316 object, and then subtract off the number of bits of
6317 the field itself. The result is the bit offset of
6318 the LSB of the field. */
6320 int bit_offset
= DW_UNSND (attr
);
6322 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6325 /* The size of the anonymous object containing
6326 the bit field is explicit, so use the
6327 indicated size (in bytes). */
6328 anonymous_size
= DW_UNSND (attr
);
6332 /* The size of the anonymous object containing
6333 the bit field must be inferred from the type
6334 attribute of the data member containing the
6336 anonymous_size
= TYPE_LENGTH (fp
->type
);
6338 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6339 - bit_offset
- FIELD_BITSIZE (*fp
);
6343 /* Get name of field. */
6344 fieldname
= dwarf2_name (die
, cu
);
6345 if (fieldname
== NULL
)
6348 /* The name is already allocated along with this objfile, so we don't
6349 need to duplicate it for the type. */
6350 fp
->name
= fieldname
;
6352 /* Change accessibility for artificial fields (e.g. virtual table
6353 pointer or virtual base class pointer) to private. */
6354 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6356 FIELD_ARTIFICIAL (*fp
) = 1;
6357 new_field
->accessibility
= DW_ACCESS_private
;
6358 fip
->non_public_fields
= 1;
6361 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6363 /* C++ static member. */
6365 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6366 is a declaration, but all versions of G++ as of this writing
6367 (so through at least 3.2.1) incorrectly generate
6368 DW_TAG_variable tags. */
6372 /* Get name of field. */
6373 fieldname
= dwarf2_name (die
, cu
);
6374 if (fieldname
== NULL
)
6377 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6379 /* Only create a symbol if this is an external value.
6380 new_symbol checks this and puts the value in the global symbol
6381 table, which we want. If it is not external, new_symbol
6382 will try to put the value in cu->list_in_scope which is wrong. */
6383 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6385 /* A static const member, not much different than an enum as far as
6386 we're concerned, except that we can support more types. */
6387 new_symbol (die
, NULL
, cu
);
6390 /* Get physical name. */
6391 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6393 /* The name is already allocated along with this objfile, so we don't
6394 need to duplicate it for the type. */
6395 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6396 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6397 FIELD_NAME (*fp
) = fieldname
;
6399 else if (die
->tag
== DW_TAG_inheritance
)
6401 /* C++ base class field. */
6402 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6405 int byte_offset
= 0;
6407 if (attr_form_is_section_offset (attr
))
6408 dwarf2_complex_location_expr_complaint ();
6409 else if (attr_form_is_constant (attr
))
6410 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6411 else if (attr_form_is_block (attr
))
6412 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6414 dwarf2_complex_location_expr_complaint ();
6416 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6418 FIELD_BITSIZE (*fp
) = 0;
6419 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6420 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6421 fip
->nbaseclasses
++;
6425 /* Add a typedef defined in the scope of the FIP's class. */
6428 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6429 struct dwarf2_cu
*cu
)
6431 struct objfile
*objfile
= cu
->objfile
;
6432 struct typedef_field_list
*new_field
;
6433 struct attribute
*attr
;
6434 struct typedef_field
*fp
;
6435 char *fieldname
= "";
6437 /* Allocate a new field list entry and link it in. */
6438 new_field
= xzalloc (sizeof (*new_field
));
6439 make_cleanup (xfree
, new_field
);
6441 gdb_assert (die
->tag
== DW_TAG_typedef
);
6443 fp
= &new_field
->field
;
6445 /* Get name of field. */
6446 fp
->name
= dwarf2_name (die
, cu
);
6447 if (fp
->name
== NULL
)
6450 fp
->type
= read_type_die (die
, cu
);
6452 new_field
->next
= fip
->typedef_field_list
;
6453 fip
->typedef_field_list
= new_field
;
6454 fip
->typedef_field_list_count
++;
6457 /* Create the vector of fields, and attach it to the type. */
6460 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6461 struct dwarf2_cu
*cu
)
6463 int nfields
= fip
->nfields
;
6465 /* Record the field count, allocate space for the array of fields,
6466 and create blank accessibility bitfields if necessary. */
6467 TYPE_NFIELDS (type
) = nfields
;
6468 TYPE_FIELDS (type
) = (struct field
*)
6469 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6470 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6472 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6474 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6476 TYPE_FIELD_PRIVATE_BITS (type
) =
6477 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6478 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6480 TYPE_FIELD_PROTECTED_BITS (type
) =
6481 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6482 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6484 TYPE_FIELD_IGNORE_BITS (type
) =
6485 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6486 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6489 /* If the type has baseclasses, allocate and clear a bit vector for
6490 TYPE_FIELD_VIRTUAL_BITS. */
6491 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6493 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6494 unsigned char *pointer
;
6496 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6497 pointer
= TYPE_ALLOC (type
, num_bytes
);
6498 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6499 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6500 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6503 /* Copy the saved-up fields into the field vector. Start from the head of
6504 the list, adding to the tail of the field array, so that they end up in
6505 the same order in the array in which they were added to the list. */
6506 while (nfields
-- > 0)
6508 struct nextfield
*fieldp
;
6512 fieldp
= fip
->fields
;
6513 fip
->fields
= fieldp
->next
;
6517 fieldp
= fip
->baseclasses
;
6518 fip
->baseclasses
= fieldp
->next
;
6521 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6522 switch (fieldp
->accessibility
)
6524 case DW_ACCESS_private
:
6525 if (cu
->language
!= language_ada
)
6526 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6529 case DW_ACCESS_protected
:
6530 if (cu
->language
!= language_ada
)
6531 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6534 case DW_ACCESS_public
:
6538 /* Unknown accessibility. Complain and treat it as public. */
6540 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6541 fieldp
->accessibility
);
6545 if (nfields
< fip
->nbaseclasses
)
6547 switch (fieldp
->virtuality
)
6549 case DW_VIRTUALITY_virtual
:
6550 case DW_VIRTUALITY_pure_virtual
:
6551 if (cu
->language
== language_ada
)
6552 error (_("unexpected virtuality in component of Ada type"));
6553 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6560 /* Add a member function to the proper fieldlist. */
6563 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6564 struct type
*type
, struct dwarf2_cu
*cu
)
6566 struct objfile
*objfile
= cu
->objfile
;
6567 struct attribute
*attr
;
6568 struct fnfieldlist
*flp
;
6570 struct fn_field
*fnp
;
6572 struct nextfnfield
*new_fnfield
;
6573 struct type
*this_type
;
6575 if (cu
->language
== language_ada
)
6576 error (_("unexpected member function in Ada type"));
6578 /* Get name of member function. */
6579 fieldname
= dwarf2_name (die
, cu
);
6580 if (fieldname
== NULL
)
6583 /* Look up member function name in fieldlist. */
6584 for (i
= 0; i
< fip
->nfnfields
; i
++)
6586 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6590 /* Create new list element if necessary. */
6591 if (i
< fip
->nfnfields
)
6592 flp
= &fip
->fnfieldlists
[i
];
6595 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6597 fip
->fnfieldlists
= (struct fnfieldlist
*)
6598 xrealloc (fip
->fnfieldlists
,
6599 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6600 * sizeof (struct fnfieldlist
));
6601 if (fip
->nfnfields
== 0)
6602 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6604 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6605 flp
->name
= fieldname
;
6608 i
= fip
->nfnfields
++;
6611 /* Create a new member function field and chain it to the field list
6613 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6614 make_cleanup (xfree
, new_fnfield
);
6615 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6616 new_fnfield
->next
= flp
->head
;
6617 flp
->head
= new_fnfield
;
6620 /* Fill in the member function field info. */
6621 fnp
= &new_fnfield
->fnfield
;
6623 /* Delay processing of the physname until later. */
6624 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
6626 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
6631 char *physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6632 fnp
->physname
= physname
? physname
: "";
6635 fnp
->type
= alloc_type (objfile
);
6636 this_type
= read_type_die (die
, cu
);
6637 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6639 int nparams
= TYPE_NFIELDS (this_type
);
6641 /* TYPE is the domain of this method, and THIS_TYPE is the type
6642 of the method itself (TYPE_CODE_METHOD). */
6643 smash_to_method_type (fnp
->type
, type
,
6644 TYPE_TARGET_TYPE (this_type
),
6645 TYPE_FIELDS (this_type
),
6646 TYPE_NFIELDS (this_type
),
6647 TYPE_VARARGS (this_type
));
6649 /* Handle static member functions.
6650 Dwarf2 has no clean way to discern C++ static and non-static
6651 member functions. G++ helps GDB by marking the first
6652 parameter for non-static member functions (which is the this
6653 pointer) as artificial. We obtain this information from
6654 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6655 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6656 fnp
->voffset
= VOFFSET_STATIC
;
6659 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
6660 dwarf2_full_name (fieldname
, die
, cu
));
6662 /* Get fcontext from DW_AT_containing_type if present. */
6663 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6664 fnp
->fcontext
= die_containing_type (die
, cu
);
6666 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
6667 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6669 /* Get accessibility. */
6670 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6673 switch (DW_UNSND (attr
))
6675 case DW_ACCESS_private
:
6676 fnp
->is_private
= 1;
6678 case DW_ACCESS_protected
:
6679 fnp
->is_protected
= 1;
6684 /* Check for artificial methods. */
6685 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
6686 if (attr
&& DW_UNSND (attr
) != 0)
6687 fnp
->is_artificial
= 1;
6689 /* Get index in virtual function table if it is a virtual member
6690 function. For older versions of GCC, this is an offset in the
6691 appropriate virtual table, as specified by DW_AT_containing_type.
6692 For everyone else, it is an expression to be evaluated relative
6693 to the object address. */
6695 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
6698 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
6700 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
6702 /* Old-style GCC. */
6703 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
6705 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6706 || (DW_BLOCK (attr
)->size
> 1
6707 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
6708 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
6710 struct dwarf_block blk
;
6713 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6715 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
6716 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
6717 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6718 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
6719 dwarf2_complex_location_expr_complaint ();
6721 fnp
->voffset
/= cu
->header
.addr_size
;
6725 dwarf2_complex_location_expr_complaint ();
6728 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
6730 else if (attr_form_is_section_offset (attr
))
6732 dwarf2_complex_location_expr_complaint ();
6736 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6742 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6743 if (attr
&& DW_UNSND (attr
))
6745 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6746 complaint (&symfile_complaints
,
6747 _("Member function \"%s\" (offset %d) is virtual "
6748 "but the vtable offset is not specified"),
6749 fieldname
, die
->offset
);
6750 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6751 TYPE_CPLUS_DYNAMIC (type
) = 1;
6756 /* Create the vector of member function fields, and attach it to the type. */
6759 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6760 struct dwarf2_cu
*cu
)
6762 struct fnfieldlist
*flp
;
6763 int total_length
= 0;
6766 if (cu
->language
== language_ada
)
6767 error (_("unexpected member functions in Ada type"));
6769 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6770 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6771 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6773 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6775 struct nextfnfield
*nfp
= flp
->head
;
6776 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6779 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6780 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6781 fn_flp
->fn_fields
= (struct fn_field
*)
6782 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6783 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6784 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6786 total_length
+= flp
->length
;
6789 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6790 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6793 /* Returns non-zero if NAME is the name of a vtable member in CU's
6794 language, zero otherwise. */
6796 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6798 static const char vptr
[] = "_vptr";
6799 static const char vtable
[] = "vtable";
6801 /* Look for the C++ and Java forms of the vtable. */
6802 if ((cu
->language
== language_java
6803 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6804 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6805 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6811 /* GCC outputs unnamed structures that are really pointers to member
6812 functions, with the ABI-specified layout. If TYPE describes
6813 such a structure, smash it into a member function type.
6815 GCC shouldn't do this; it should just output pointer to member DIEs.
6816 This is GCC PR debug/28767. */
6819 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6821 struct type
*pfn_type
, *domain_type
, *new_type
;
6823 /* Check for a structure with no name and two children. */
6824 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6827 /* Check for __pfn and __delta members. */
6828 if (TYPE_FIELD_NAME (type
, 0) == NULL
6829 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6830 || TYPE_FIELD_NAME (type
, 1) == NULL
6831 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6834 /* Find the type of the method. */
6835 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6836 if (pfn_type
== NULL
6837 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6838 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6841 /* Look for the "this" argument. */
6842 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6843 if (TYPE_NFIELDS (pfn_type
) == 0
6844 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6845 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6848 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6849 new_type
= alloc_type (objfile
);
6850 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6851 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6852 TYPE_VARARGS (pfn_type
));
6853 smash_to_methodptr_type (type
, new_type
);
6856 /* Called when we find the DIE that starts a structure or union scope
6857 (definition) to create a type for the structure or union. Fill in
6858 the type's name and general properties; the members will not be
6859 processed until process_structure_type.
6861 NOTE: we need to call these functions regardless of whether or not the
6862 DIE has a DW_AT_name attribute, since it might be an anonymous
6863 structure or union. This gets the type entered into our set of
6866 However, if the structure is incomplete (an opaque struct/union)
6867 then suppress creating a symbol table entry for it since gdb only
6868 wants to find the one with the complete definition. Note that if
6869 it is complete, we just call new_symbol, which does it's own
6870 checking about whether the struct/union is anonymous or not (and
6871 suppresses creating a symbol table entry itself). */
6873 static struct type
*
6874 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6876 struct objfile
*objfile
= cu
->objfile
;
6878 struct attribute
*attr
;
6881 /* If the definition of this type lives in .debug_types, read that type.
6882 Don't follow DW_AT_specification though, that will take us back up
6883 the chain and we want to go down. */
6884 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6887 struct dwarf2_cu
*type_cu
= cu
;
6888 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6890 /* We could just recurse on read_structure_type, but we need to call
6891 get_die_type to ensure only one type for this DIE is created.
6892 This is important, for example, because for c++ classes we need
6893 TYPE_NAME set which is only done by new_symbol. Blech. */
6894 type
= read_type_die (type_die
, type_cu
);
6896 /* TYPE_CU may not be the same as CU.
6897 Ensure TYPE is recorded in CU's type_hash table. */
6898 return set_die_type (die
, type
, cu
);
6901 type
= alloc_type (objfile
);
6902 INIT_CPLUS_SPECIFIC (type
);
6904 name
= dwarf2_name (die
, cu
);
6907 if (cu
->language
== language_cplus
6908 || cu
->language
== language_java
)
6910 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
6912 /* dwarf2_full_name might have already finished building the DIE's
6913 type. If so, there is no need to continue. */
6914 if (get_die_type (die
, cu
) != NULL
)
6915 return get_die_type (die
, cu
);
6917 TYPE_TAG_NAME (type
) = full_name
;
6918 if (die
->tag
== DW_TAG_structure_type
6919 || die
->tag
== DW_TAG_class_type
)
6920 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6924 /* The name is already allocated along with this objfile, so
6925 we don't need to duplicate it for the type. */
6926 TYPE_TAG_NAME (type
) = (char *) name
;
6927 if (die
->tag
== DW_TAG_class_type
)
6928 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6932 if (die
->tag
== DW_TAG_structure_type
)
6934 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
6936 else if (die
->tag
== DW_TAG_union_type
)
6938 TYPE_CODE (type
) = TYPE_CODE_UNION
;
6942 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
6945 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
6946 TYPE_DECLARED_CLASS (type
) = 1;
6948 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6951 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6955 TYPE_LENGTH (type
) = 0;
6958 TYPE_STUB_SUPPORTED (type
) = 1;
6959 if (die_is_declaration (die
, cu
))
6960 TYPE_STUB (type
) = 1;
6961 else if (attr
== NULL
&& die
->child
== NULL
6962 && producer_is_realview (cu
->producer
))
6963 /* RealView does not output the required DW_AT_declaration
6964 on incomplete types. */
6965 TYPE_STUB (type
) = 1;
6967 /* We need to add the type field to the die immediately so we don't
6968 infinitely recurse when dealing with pointers to the structure
6969 type within the structure itself. */
6970 set_die_type (die
, type
, cu
);
6972 /* set_die_type should be already done. */
6973 set_descriptive_type (type
, die
, cu
);
6978 /* Finish creating a structure or union type, including filling in
6979 its members and creating a symbol for it. */
6982 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6984 struct objfile
*objfile
= cu
->objfile
;
6985 struct die_info
*child_die
= die
->child
;
6988 type
= get_die_type (die
, cu
);
6990 type
= read_structure_type (die
, cu
);
6992 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
6994 struct field_info fi
;
6995 struct die_info
*child_die
;
6996 VEC (symbolp
) *template_args
= NULL
;
6997 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6999 memset (&fi
, 0, sizeof (struct field_info
));
7001 child_die
= die
->child
;
7003 while (child_die
&& child_die
->tag
)
7005 if (child_die
->tag
== DW_TAG_member
7006 || child_die
->tag
== DW_TAG_variable
)
7008 /* NOTE: carlton/2002-11-05: A C++ static data member
7009 should be a DW_TAG_member that is a declaration, but
7010 all versions of G++ as of this writing (so through at
7011 least 3.2.1) incorrectly generate DW_TAG_variable
7012 tags for them instead. */
7013 dwarf2_add_field (&fi
, child_die
, cu
);
7015 else if (child_die
->tag
== DW_TAG_subprogram
)
7017 /* C++ member function. */
7018 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7020 else if (child_die
->tag
== DW_TAG_inheritance
)
7022 /* C++ base class field. */
7023 dwarf2_add_field (&fi
, child_die
, cu
);
7025 else if (child_die
->tag
== DW_TAG_typedef
)
7026 dwarf2_add_typedef (&fi
, child_die
, cu
);
7027 else if (child_die
->tag
== DW_TAG_template_type_param
7028 || child_die
->tag
== DW_TAG_template_value_param
)
7030 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7033 VEC_safe_push (symbolp
, template_args
, arg
);
7036 child_die
= sibling_die (child_die
);
7039 /* Attach template arguments to type. */
7040 if (! VEC_empty (symbolp
, template_args
))
7042 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7043 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7044 = VEC_length (symbolp
, template_args
);
7045 TYPE_TEMPLATE_ARGUMENTS (type
)
7046 = obstack_alloc (&objfile
->objfile_obstack
,
7047 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7048 * sizeof (struct symbol
*)));
7049 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7050 VEC_address (symbolp
, template_args
),
7051 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7052 * sizeof (struct symbol
*)));
7053 VEC_free (symbolp
, template_args
);
7056 /* Attach fields and member functions to the type. */
7058 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7061 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7063 /* Get the type which refers to the base class (possibly this
7064 class itself) which contains the vtable pointer for the current
7065 class from the DW_AT_containing_type attribute. This use of
7066 DW_AT_containing_type is a GNU extension. */
7068 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7070 struct type
*t
= die_containing_type (die
, cu
);
7072 TYPE_VPTR_BASETYPE (type
) = t
;
7077 /* Our own class provides vtbl ptr. */
7078 for (i
= TYPE_NFIELDS (t
) - 1;
7079 i
>= TYPE_N_BASECLASSES (t
);
7082 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7084 if (is_vtable_name (fieldname
, cu
))
7086 TYPE_VPTR_FIELDNO (type
) = i
;
7091 /* Complain if virtual function table field not found. */
7092 if (i
< TYPE_N_BASECLASSES (t
))
7093 complaint (&symfile_complaints
,
7094 _("virtual function table pointer "
7095 "not found when defining class '%s'"),
7096 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7101 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7104 else if (cu
->producer
7105 && strncmp (cu
->producer
,
7106 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7108 /* The IBM XLC compiler does not provide direct indication
7109 of the containing type, but the vtable pointer is
7110 always named __vfp. */
7114 for (i
= TYPE_NFIELDS (type
) - 1;
7115 i
>= TYPE_N_BASECLASSES (type
);
7118 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7120 TYPE_VPTR_FIELDNO (type
) = i
;
7121 TYPE_VPTR_BASETYPE (type
) = type
;
7128 /* Copy fi.typedef_field_list linked list elements content into the
7129 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7130 if (fi
.typedef_field_list
)
7132 int i
= fi
.typedef_field_list_count
;
7134 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7135 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7136 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7137 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7139 /* Reverse the list order to keep the debug info elements order. */
7142 struct typedef_field
*dest
, *src
;
7144 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7145 src
= &fi
.typedef_field_list
->field
;
7146 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7151 do_cleanups (back_to
);
7154 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
7156 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7157 snapshots) has been known to create a die giving a declaration
7158 for a class that has, as a child, a die giving a definition for a
7159 nested class. So we have to process our children even if the
7160 current die is a declaration. Normally, of course, a declaration
7161 won't have any children at all. */
7163 while (child_die
!= NULL
&& child_die
->tag
)
7165 if (child_die
->tag
== DW_TAG_member
7166 || child_die
->tag
== DW_TAG_variable
7167 || child_die
->tag
== DW_TAG_inheritance
7168 || child_die
->tag
== DW_TAG_template_value_param
7169 || child_die
->tag
== DW_TAG_template_type_param
)
7174 process_die (child_die
, cu
);
7176 child_die
= sibling_die (child_die
);
7179 /* Do not consider external references. According to the DWARF standard,
7180 these DIEs are identified by the fact that they have no byte_size
7181 attribute, and a declaration attribute. */
7182 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7183 || !die_is_declaration (die
, cu
))
7184 new_symbol (die
, type
, cu
);
7187 /* Given a DW_AT_enumeration_type die, set its type. We do not
7188 complete the type's fields yet, or create any symbols. */
7190 static struct type
*
7191 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7193 struct objfile
*objfile
= cu
->objfile
;
7195 struct attribute
*attr
;
7198 /* If the definition of this type lives in .debug_types, read that type.
7199 Don't follow DW_AT_specification though, that will take us back up
7200 the chain and we want to go down. */
7201 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7204 struct dwarf2_cu
*type_cu
= cu
;
7205 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7207 type
= read_type_die (type_die
, type_cu
);
7209 /* TYPE_CU may not be the same as CU.
7210 Ensure TYPE is recorded in CU's type_hash table. */
7211 return set_die_type (die
, type
, cu
);
7214 type
= alloc_type (objfile
);
7216 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7217 name
= dwarf2_full_name (NULL
, die
, cu
);
7219 TYPE_TAG_NAME (type
) = (char *) name
;
7221 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7224 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7228 TYPE_LENGTH (type
) = 0;
7231 /* The enumeration DIE can be incomplete. In Ada, any type can be
7232 declared as private in the package spec, and then defined only
7233 inside the package body. Such types are known as Taft Amendment
7234 Types. When another package uses such a type, an incomplete DIE
7235 may be generated by the compiler. */
7236 if (die_is_declaration (die
, cu
))
7237 TYPE_STUB (type
) = 1;
7239 return set_die_type (die
, type
, cu
);
7242 /* Given a pointer to a die which begins an enumeration, process all
7243 the dies that define the members of the enumeration, and create the
7244 symbol for the enumeration type.
7246 NOTE: We reverse the order of the element list. */
7249 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7251 struct type
*this_type
;
7253 this_type
= get_die_type (die
, cu
);
7254 if (this_type
== NULL
)
7255 this_type
= read_enumeration_type (die
, cu
);
7257 if (die
->child
!= NULL
)
7259 struct die_info
*child_die
;
7261 struct field
*fields
= NULL
;
7263 int unsigned_enum
= 1;
7266 child_die
= die
->child
;
7267 while (child_die
&& child_die
->tag
)
7269 if (child_die
->tag
!= DW_TAG_enumerator
)
7271 process_die (child_die
, cu
);
7275 name
= dwarf2_name (child_die
, cu
);
7278 sym
= new_symbol (child_die
, this_type
, cu
);
7279 if (SYMBOL_VALUE (sym
) < 0)
7282 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7284 fields
= (struct field
*)
7286 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7287 * sizeof (struct field
));
7290 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7291 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7292 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7293 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7299 child_die
= sibling_die (child_die
);
7304 TYPE_NFIELDS (this_type
) = num_fields
;
7305 TYPE_FIELDS (this_type
) = (struct field
*)
7306 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7307 memcpy (TYPE_FIELDS (this_type
), fields
,
7308 sizeof (struct field
) * num_fields
);
7312 TYPE_UNSIGNED (this_type
) = 1;
7315 new_symbol (die
, this_type
, cu
);
7318 /* Extract all information from a DW_TAG_array_type DIE and put it in
7319 the DIE's type field. For now, this only handles one dimensional
7322 static struct type
*
7323 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7325 struct objfile
*objfile
= cu
->objfile
;
7326 struct die_info
*child_die
;
7328 struct type
*element_type
, *range_type
, *index_type
;
7329 struct type
**range_types
= NULL
;
7330 struct attribute
*attr
;
7332 struct cleanup
*back_to
;
7335 element_type
= die_type (die
, cu
);
7337 /* The die_type call above may have already set the type for this DIE. */
7338 type
= get_die_type (die
, cu
);
7342 /* Irix 6.2 native cc creates array types without children for
7343 arrays with unspecified length. */
7344 if (die
->child
== NULL
)
7346 index_type
= objfile_type (objfile
)->builtin_int
;
7347 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7348 type
= create_array_type (NULL
, element_type
, range_type
);
7349 return set_die_type (die
, type
, cu
);
7352 back_to
= make_cleanup (null_cleanup
, NULL
);
7353 child_die
= die
->child
;
7354 while (child_die
&& child_die
->tag
)
7356 if (child_die
->tag
== DW_TAG_subrange_type
)
7358 struct type
*child_type
= read_type_die (child_die
, cu
);
7360 if (child_type
!= NULL
)
7362 /* The range type was succesfully read. Save it for the
7363 array type creation. */
7364 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7366 range_types
= (struct type
**)
7367 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7368 * sizeof (struct type
*));
7370 make_cleanup (free_current_contents
, &range_types
);
7372 range_types
[ndim
++] = child_type
;
7375 child_die
= sibling_die (child_die
);
7378 /* Dwarf2 dimensions are output from left to right, create the
7379 necessary array types in backwards order. */
7381 type
= element_type
;
7383 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7388 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7393 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7396 /* Understand Dwarf2 support for vector types (like they occur on
7397 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7398 array type. This is not part of the Dwarf2/3 standard yet, but a
7399 custom vendor extension. The main difference between a regular
7400 array and the vector variant is that vectors are passed by value
7402 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7404 make_vector_type (type
);
7406 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7407 implementation may choose to implement triple vectors using this
7409 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7412 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
7413 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7415 complaint (&symfile_complaints
,
7416 _("DW_AT_byte_size for array type smaller "
7417 "than the total size of elements"));
7420 name
= dwarf2_name (die
, cu
);
7422 TYPE_NAME (type
) = name
;
7424 /* Install the type in the die. */
7425 set_die_type (die
, type
, cu
);
7427 /* set_die_type should be already done. */
7428 set_descriptive_type (type
, die
, cu
);
7430 do_cleanups (back_to
);
7435 static enum dwarf_array_dim_ordering
7436 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7438 struct attribute
*attr
;
7440 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7442 if (attr
) return DW_SND (attr
);
7444 /* GNU F77 is a special case, as at 08/2004 array type info is the
7445 opposite order to the dwarf2 specification, but data is still
7446 laid out as per normal fortran.
7448 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7449 version checking. */
7451 if (cu
->language
== language_fortran
7452 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7454 return DW_ORD_row_major
;
7457 switch (cu
->language_defn
->la_array_ordering
)
7459 case array_column_major
:
7460 return DW_ORD_col_major
;
7461 case array_row_major
:
7463 return DW_ORD_row_major
;
7467 /* Extract all information from a DW_TAG_set_type DIE and put it in
7468 the DIE's type field. */
7470 static struct type
*
7471 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7473 struct type
*domain_type
, *set_type
;
7474 struct attribute
*attr
;
7476 domain_type
= die_type (die
, cu
);
7478 /* The die_type call above may have already set the type for this DIE. */
7479 set_type
= get_die_type (die
, cu
);
7483 set_type
= create_set_type (NULL
, domain_type
);
7485 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7487 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7489 return set_die_type (die
, set_type
, cu
);
7492 /* First cut: install each common block member as a global variable. */
7495 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7497 struct die_info
*child_die
;
7498 struct attribute
*attr
;
7500 CORE_ADDR base
= (CORE_ADDR
) 0;
7502 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7505 /* Support the .debug_loc offsets. */
7506 if (attr_form_is_block (attr
))
7508 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7510 else if (attr_form_is_section_offset (attr
))
7512 dwarf2_complex_location_expr_complaint ();
7516 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7517 "common block member");
7520 if (die
->child
!= NULL
)
7522 child_die
= die
->child
;
7523 while (child_die
&& child_die
->tag
)
7525 sym
= new_symbol (child_die
, NULL
, cu
);
7526 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
7527 if (sym
!= NULL
&& attr
!= NULL
)
7529 CORE_ADDR byte_offset
= 0;
7531 if (attr_form_is_section_offset (attr
))
7532 dwarf2_complex_location_expr_complaint ();
7533 else if (attr_form_is_constant (attr
))
7534 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
7535 else if (attr_form_is_block (attr
))
7536 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7538 dwarf2_complex_location_expr_complaint ();
7540 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
7541 add_symbol_to_list (sym
, &global_symbols
);
7543 child_die
= sibling_die (child_die
);
7548 /* Create a type for a C++ namespace. */
7550 static struct type
*
7551 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7553 struct objfile
*objfile
= cu
->objfile
;
7554 const char *previous_prefix
, *name
;
7558 /* For extensions, reuse the type of the original namespace. */
7559 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7561 struct die_info
*ext_die
;
7562 struct dwarf2_cu
*ext_cu
= cu
;
7564 ext_die
= dwarf2_extension (die
, &ext_cu
);
7565 type
= read_type_die (ext_die
, ext_cu
);
7567 /* EXT_CU may not be the same as CU.
7568 Ensure TYPE is recorded in CU's type_hash table. */
7569 return set_die_type (die
, type
, cu
);
7572 name
= namespace_name (die
, &is_anonymous
, cu
);
7574 /* Now build the name of the current namespace. */
7576 previous_prefix
= determine_prefix (die
, cu
);
7577 if (previous_prefix
[0] != '\0')
7578 name
= typename_concat (&objfile
->objfile_obstack
,
7579 previous_prefix
, name
, 0, cu
);
7581 /* Create the type. */
7582 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7584 TYPE_NAME (type
) = (char *) name
;
7585 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7587 return set_die_type (die
, type
, cu
);
7590 /* Read a C++ namespace. */
7593 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7595 struct objfile
*objfile
= cu
->objfile
;
7598 /* Add a symbol associated to this if we haven't seen the namespace
7599 before. Also, add a using directive if it's an anonymous
7602 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7606 type
= read_type_die (die
, cu
);
7607 new_symbol (die
, type
, cu
);
7609 namespace_name (die
, &is_anonymous
, cu
);
7612 const char *previous_prefix
= determine_prefix (die
, cu
);
7614 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7615 NULL
, &objfile
->objfile_obstack
);
7619 if (die
->child
!= NULL
)
7621 struct die_info
*child_die
= die
->child
;
7623 while (child_die
&& child_die
->tag
)
7625 process_die (child_die
, cu
);
7626 child_die
= sibling_die (child_die
);
7631 /* Read a Fortran module as type. This DIE can be only a declaration used for
7632 imported module. Still we need that type as local Fortran "use ... only"
7633 declaration imports depend on the created type in determine_prefix. */
7635 static struct type
*
7636 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7638 struct objfile
*objfile
= cu
->objfile
;
7642 module_name
= dwarf2_name (die
, cu
);
7644 complaint (&symfile_complaints
,
7645 _("DW_TAG_module has no name, offset 0x%x"),
7647 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7649 /* determine_prefix uses TYPE_TAG_NAME. */
7650 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7652 return set_die_type (die
, type
, cu
);
7655 /* Read a Fortran module. */
7658 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7660 struct die_info
*child_die
= die
->child
;
7662 while (child_die
&& child_die
->tag
)
7664 process_die (child_die
, cu
);
7665 child_die
= sibling_die (child_die
);
7669 /* Return the name of the namespace represented by DIE. Set
7670 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7674 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
7676 struct die_info
*current_die
;
7677 const char *name
= NULL
;
7679 /* Loop through the extensions until we find a name. */
7681 for (current_die
= die
;
7682 current_die
!= NULL
;
7683 current_die
= dwarf2_extension (die
, &cu
))
7685 name
= dwarf2_name (current_die
, cu
);
7690 /* Is it an anonymous namespace? */
7692 *is_anonymous
= (name
== NULL
);
7694 name
= "(anonymous namespace)";
7699 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7700 the user defined type vector. */
7702 static struct type
*
7703 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7705 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7706 struct comp_unit_head
*cu_header
= &cu
->header
;
7708 struct attribute
*attr_byte_size
;
7709 struct attribute
*attr_address_class
;
7710 int byte_size
, addr_class
;
7711 struct type
*target_type
;
7713 target_type
= die_type (die
, cu
);
7715 /* The die_type call above may have already set the type for this DIE. */
7716 type
= get_die_type (die
, cu
);
7720 type
= lookup_pointer_type (target_type
);
7722 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7724 byte_size
= DW_UNSND (attr_byte_size
);
7726 byte_size
= cu_header
->addr_size
;
7728 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
7729 if (attr_address_class
)
7730 addr_class
= DW_UNSND (attr_address_class
);
7732 addr_class
= DW_ADDR_none
;
7734 /* If the pointer size or address class is different than the
7735 default, create a type variant marked as such and set the
7736 length accordingly. */
7737 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
7739 if (gdbarch_address_class_type_flags_p (gdbarch
))
7743 type_flags
= gdbarch_address_class_type_flags
7744 (gdbarch
, byte_size
, addr_class
);
7745 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
7747 type
= make_type_with_address_space (type
, type_flags
);
7749 else if (TYPE_LENGTH (type
) != byte_size
)
7751 complaint (&symfile_complaints
,
7752 _("invalid pointer size %d"), byte_size
);
7756 /* Should we also complain about unhandled address classes? */
7760 TYPE_LENGTH (type
) = byte_size
;
7761 return set_die_type (die
, type
, cu
);
7764 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7765 the user defined type vector. */
7767 static struct type
*
7768 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7771 struct type
*to_type
;
7772 struct type
*domain
;
7774 to_type
= die_type (die
, cu
);
7775 domain
= die_containing_type (die
, cu
);
7777 /* The calls above may have already set the type for this DIE. */
7778 type
= get_die_type (die
, cu
);
7782 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
7783 type
= lookup_methodptr_type (to_type
);
7785 type
= lookup_memberptr_type (to_type
, domain
);
7787 return set_die_type (die
, type
, cu
);
7790 /* Extract all information from a DW_TAG_reference_type DIE and add to
7791 the user defined type vector. */
7793 static struct type
*
7794 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7796 struct comp_unit_head
*cu_header
= &cu
->header
;
7797 struct type
*type
, *target_type
;
7798 struct attribute
*attr
;
7800 target_type
= die_type (die
, cu
);
7802 /* The die_type call above may have already set the type for this DIE. */
7803 type
= get_die_type (die
, cu
);
7807 type
= lookup_reference_type (target_type
);
7808 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7811 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7815 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7817 return set_die_type (die
, type
, cu
);
7820 static struct type
*
7821 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7823 struct type
*base_type
, *cv_type
;
7825 base_type
= die_type (die
, cu
);
7827 /* The die_type call above may have already set the type for this DIE. */
7828 cv_type
= get_die_type (die
, cu
);
7832 /* In case the const qualifier is applied to an array type, the element type
7833 is so qualified, not the array type (section 6.7.3 of C99). */
7834 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
7836 struct type
*el_type
, *inner_array
;
7838 base_type
= copy_type (base_type
);
7839 inner_array
= base_type
;
7841 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
7843 TYPE_TARGET_TYPE (inner_array
) =
7844 copy_type (TYPE_TARGET_TYPE (inner_array
));
7845 inner_array
= TYPE_TARGET_TYPE (inner_array
);
7848 el_type
= TYPE_TARGET_TYPE (inner_array
);
7849 TYPE_TARGET_TYPE (inner_array
) =
7850 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
7852 return set_die_type (die
, base_type
, cu
);
7855 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7856 return set_die_type (die
, cv_type
, cu
);
7859 static struct type
*
7860 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7862 struct type
*base_type
, *cv_type
;
7864 base_type
= die_type (die
, cu
);
7866 /* The die_type call above may have already set the type for this DIE. */
7867 cv_type
= get_die_type (die
, cu
);
7871 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7872 return set_die_type (die
, cv_type
, cu
);
7875 /* Extract all information from a DW_TAG_string_type DIE and add to
7876 the user defined type vector. It isn't really a user defined type,
7877 but it behaves like one, with other DIE's using an AT_user_def_type
7878 attribute to reference it. */
7880 static struct type
*
7881 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7883 struct objfile
*objfile
= cu
->objfile
;
7884 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7885 struct type
*type
, *range_type
, *index_type
, *char_type
;
7886 struct attribute
*attr
;
7887 unsigned int length
;
7889 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7892 length
= DW_UNSND (attr
);
7896 /* Check for the DW_AT_byte_size attribute. */
7897 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7900 length
= DW_UNSND (attr
);
7908 index_type
= objfile_type (objfile
)->builtin_int
;
7909 range_type
= create_range_type (NULL
, index_type
, 1, length
);
7910 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
7911 type
= create_string_type (NULL
, char_type
, range_type
);
7913 return set_die_type (die
, type
, cu
);
7916 /* Handle DIES due to C code like:
7920 int (*funcp)(int a, long l);
7924 ('funcp' generates a DW_TAG_subroutine_type DIE). */
7926 static struct type
*
7927 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7929 struct type
*type
; /* Type that this function returns. */
7930 struct type
*ftype
; /* Function that returns above type. */
7931 struct attribute
*attr
;
7933 type
= die_type (die
, cu
);
7935 /* The die_type call above may have already set the type for this DIE. */
7936 ftype
= get_die_type (die
, cu
);
7940 ftype
= lookup_function_type (type
);
7942 /* All functions in C++, Pascal and Java have prototypes. */
7943 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
7944 if ((attr
&& (DW_UNSND (attr
) != 0))
7945 || cu
->language
== language_cplus
7946 || cu
->language
== language_java
7947 || cu
->language
== language_pascal
)
7948 TYPE_PROTOTYPED (ftype
) = 1;
7949 else if (producer_is_realview (cu
->producer
))
7950 /* RealView does not emit DW_AT_prototyped. We can not
7951 distinguish prototyped and unprototyped functions; default to
7952 prototyped, since that is more common in modern code (and
7953 RealView warns about unprototyped functions). */
7954 TYPE_PROTOTYPED (ftype
) = 1;
7956 /* Store the calling convention in the type if it's available in
7957 the subroutine die. Otherwise set the calling convention to
7958 the default value DW_CC_normal. */
7959 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
7961 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
7962 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
7963 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
7965 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
7967 /* We need to add the subroutine type to the die immediately so
7968 we don't infinitely recurse when dealing with parameters
7969 declared as the same subroutine type. */
7970 set_die_type (die
, ftype
, cu
);
7972 if (die
->child
!= NULL
)
7974 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
7975 struct die_info
*child_die
;
7976 int nparams
, iparams
;
7978 /* Count the number of parameters.
7979 FIXME: GDB currently ignores vararg functions, but knows about
7980 vararg member functions. */
7982 child_die
= die
->child
;
7983 while (child_die
&& child_die
->tag
)
7985 if (child_die
->tag
== DW_TAG_formal_parameter
)
7987 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
7988 TYPE_VARARGS (ftype
) = 1;
7989 child_die
= sibling_die (child_die
);
7992 /* Allocate storage for parameters and fill them in. */
7993 TYPE_NFIELDS (ftype
) = nparams
;
7994 TYPE_FIELDS (ftype
) = (struct field
*)
7995 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
7997 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7998 even if we error out during the parameters reading below. */
7999 for (iparams
= 0; iparams
< nparams
; iparams
++)
8000 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8003 child_die
= die
->child
;
8004 while (child_die
&& child_die
->tag
)
8006 if (child_die
->tag
== DW_TAG_formal_parameter
)
8008 struct type
*arg_type
;
8010 /* DWARF version 2 has no clean way to discern C++
8011 static and non-static member functions. G++ helps
8012 GDB by marking the first parameter for non-static
8013 member functions (which is the this pointer) as
8014 artificial. We pass this information to
8015 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8017 DWARF version 3 added DW_AT_object_pointer, which GCC
8018 4.5 does not yet generate. */
8019 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8021 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8024 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8026 /* GCC/43521: In java, the formal parameter
8027 "this" is sometimes not marked with DW_AT_artificial. */
8028 if (cu
->language
== language_java
)
8030 const char *name
= dwarf2_name (child_die
, cu
);
8032 if (name
&& !strcmp (name
, "this"))
8033 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8036 arg_type
= die_type (child_die
, cu
);
8038 /* RealView does not mark THIS as const, which the testsuite
8039 expects. GCC marks THIS as const in method definitions,
8040 but not in the class specifications (GCC PR 43053). */
8041 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8042 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8045 struct dwarf2_cu
*arg_cu
= cu
;
8046 const char *name
= dwarf2_name (child_die
, cu
);
8048 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8051 /* If the compiler emits this, use it. */
8052 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8055 else if (name
&& strcmp (name
, "this") == 0)
8056 /* Function definitions will have the argument names. */
8058 else if (name
== NULL
&& iparams
== 0)
8059 /* Declarations may not have the names, so like
8060 elsewhere in GDB, assume an artificial first
8061 argument is "this". */
8065 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8069 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8072 child_die
= sibling_die (child_die
);
8079 static struct type
*
8080 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8082 struct objfile
*objfile
= cu
->objfile
;
8083 const char *name
= NULL
;
8084 struct type
*this_type
;
8086 name
= dwarf2_full_name (NULL
, die
, cu
);
8087 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8088 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8089 TYPE_NAME (this_type
) = (char *) name
;
8090 set_die_type (die
, this_type
, cu
);
8091 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
8095 /* Find a representation of a given base type and install
8096 it in the TYPE field of the die. */
8098 static struct type
*
8099 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8101 struct objfile
*objfile
= cu
->objfile
;
8103 struct attribute
*attr
;
8104 int encoding
= 0, size
= 0;
8106 enum type_code code
= TYPE_CODE_INT
;
8108 struct type
*target_type
= NULL
;
8110 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8113 encoding
= DW_UNSND (attr
);
8115 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8118 size
= DW_UNSND (attr
);
8120 name
= dwarf2_name (die
, cu
);
8123 complaint (&symfile_complaints
,
8124 _("DW_AT_name missing from DW_TAG_base_type"));
8129 case DW_ATE_address
:
8130 /* Turn DW_ATE_address into a void * pointer. */
8131 code
= TYPE_CODE_PTR
;
8132 type_flags
|= TYPE_FLAG_UNSIGNED
;
8133 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8135 case DW_ATE_boolean
:
8136 code
= TYPE_CODE_BOOL
;
8137 type_flags
|= TYPE_FLAG_UNSIGNED
;
8139 case DW_ATE_complex_float
:
8140 code
= TYPE_CODE_COMPLEX
;
8141 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8143 case DW_ATE_decimal_float
:
8144 code
= TYPE_CODE_DECFLOAT
;
8147 code
= TYPE_CODE_FLT
;
8151 case DW_ATE_unsigned
:
8152 type_flags
|= TYPE_FLAG_UNSIGNED
;
8154 case DW_ATE_signed_char
:
8155 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8156 || cu
->language
== language_pascal
)
8157 code
= TYPE_CODE_CHAR
;
8159 case DW_ATE_unsigned_char
:
8160 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8161 || cu
->language
== language_pascal
)
8162 code
= TYPE_CODE_CHAR
;
8163 type_flags
|= TYPE_FLAG_UNSIGNED
;
8166 /* We just treat this as an integer and then recognize the
8167 type by name elsewhere. */
8171 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8172 dwarf_type_encoding_name (encoding
));
8176 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8177 TYPE_NAME (type
) = name
;
8178 TYPE_TARGET_TYPE (type
) = target_type
;
8180 if (name
&& strcmp (name
, "char") == 0)
8181 TYPE_NOSIGN (type
) = 1;
8183 return set_die_type (die
, type
, cu
);
8186 /* Read the given DW_AT_subrange DIE. */
8188 static struct type
*
8189 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8191 struct type
*base_type
;
8192 struct type
*range_type
;
8193 struct attribute
*attr
;
8197 LONGEST negative_mask
;
8199 base_type
= die_type (die
, cu
);
8200 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8201 check_typedef (base_type
);
8203 /* The die_type call above may have already set the type for this DIE. */
8204 range_type
= get_die_type (die
, cu
);
8208 if (cu
->language
== language_fortran
)
8210 /* FORTRAN implies a lower bound of 1, if not given. */
8214 /* FIXME: For variable sized arrays either of these could be
8215 a variable rather than a constant value. We'll allow it,
8216 but we don't know how to handle it. */
8217 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8219 low
= dwarf2_get_attr_constant_value (attr
, 0);
8221 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8224 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
8226 /* GCC encodes arrays with unspecified or dynamic length
8227 with a DW_FORM_block1 attribute or a reference attribute.
8228 FIXME: GDB does not yet know how to handle dynamic
8229 arrays properly, treat them as arrays with unspecified
8232 FIXME: jimb/2003-09-22: GDB does not really know
8233 how to handle arrays of unspecified length
8234 either; we just represent them as zero-length
8235 arrays. Choose an appropriate upper bound given
8236 the lower bound we've computed above. */
8240 high
= dwarf2_get_attr_constant_value (attr
, 1);
8244 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8247 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8248 high
= low
+ count
- 1;
8252 /* Unspecified array length. */
8257 /* Dwarf-2 specifications explicitly allows to create subrange types
8258 without specifying a base type.
8259 In that case, the base type must be set to the type of
8260 the lower bound, upper bound or count, in that order, if any of these
8261 three attributes references an object that has a type.
8262 If no base type is found, the Dwarf-2 specifications say that
8263 a signed integer type of size equal to the size of an address should
8265 For the following C code: `extern char gdb_int [];'
8266 GCC produces an empty range DIE.
8267 FIXME: muller/2010-05-28: Possible references to object for low bound,
8268 high bound or count are not yet handled by this code. */
8269 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8271 struct objfile
*objfile
= cu
->objfile
;
8272 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8273 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8274 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8276 /* Test "int", "long int", and "long long int" objfile types,
8277 and select the first one having a size above or equal to the
8278 architecture address size. */
8279 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8280 base_type
= int_type
;
8283 int_type
= objfile_type (objfile
)->builtin_long
;
8284 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8285 base_type
= int_type
;
8288 int_type
= objfile_type (objfile
)->builtin_long_long
;
8289 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8290 base_type
= int_type
;
8296 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8297 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8298 low
|= negative_mask
;
8299 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8300 high
|= negative_mask
;
8302 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8304 /* Mark arrays with dynamic length at least as an array of unspecified
8305 length. GDB could check the boundary but before it gets implemented at
8306 least allow accessing the array elements. */
8307 if (attr
&& attr
->form
== DW_FORM_block1
)
8308 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8310 /* Ada expects an empty array on no boundary attributes. */
8311 if (attr
== NULL
&& cu
->language
!= language_ada
)
8312 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8314 name
= dwarf2_name (die
, cu
);
8316 TYPE_NAME (range_type
) = name
;
8318 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8320 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8322 set_die_type (die
, range_type
, cu
);
8324 /* set_die_type should be already done. */
8325 set_descriptive_type (range_type
, die
, cu
);
8330 static struct type
*
8331 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8335 /* For now, we only support the C meaning of an unspecified type: void. */
8337 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8338 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8340 return set_die_type (die
, type
, cu
);
8343 /* Trivial hash function for die_info: the hash value of a DIE
8344 is its offset in .debug_info for this objfile. */
8347 die_hash (const void *item
)
8349 const struct die_info
*die
= item
;
8354 /* Trivial comparison function for die_info structures: two DIEs
8355 are equal if they have the same offset. */
8358 die_eq (const void *item_lhs
, const void *item_rhs
)
8360 const struct die_info
*die_lhs
= item_lhs
;
8361 const struct die_info
*die_rhs
= item_rhs
;
8363 return die_lhs
->offset
== die_rhs
->offset
;
8366 /* Read a whole compilation unit into a linked list of dies. */
8368 static struct die_info
*
8369 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8371 struct die_reader_specs reader_specs
;
8372 int read_abbrevs
= 0;
8373 struct cleanup
*back_to
= NULL
;
8374 struct die_info
*die
;
8376 if (cu
->dwarf2_abbrevs
== NULL
)
8378 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8379 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8383 gdb_assert (cu
->die_hash
== NULL
);
8385 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8389 &cu
->comp_unit_obstack
,
8390 hashtab_obstack_allocate
,
8391 dummy_obstack_deallocate
);
8393 init_cu_die_reader (&reader_specs
, cu
);
8395 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8398 do_cleanups (back_to
);
8403 /* Main entry point for reading a DIE and all children.
8404 Read the DIE and dump it if requested. */
8406 static struct die_info
*
8407 read_die_and_children (const struct die_reader_specs
*reader
,
8409 gdb_byte
**new_info_ptr
,
8410 struct die_info
*parent
)
8412 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8413 new_info_ptr
, parent
);
8415 if (dwarf2_die_debug
)
8417 fprintf_unfiltered (gdb_stdlog
,
8418 "\nRead die from %s of %s:\n",
8419 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8421 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8423 : "unknown section",
8424 reader
->abfd
->filename
);
8425 dump_die (result
, dwarf2_die_debug
);
8431 /* Read a single die and all its descendents. Set the die's sibling
8432 field to NULL; set other fields in the die correctly, and set all
8433 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8434 location of the info_ptr after reading all of those dies. PARENT
8435 is the parent of the die in question. */
8437 static struct die_info
*
8438 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8440 gdb_byte
**new_info_ptr
,
8441 struct die_info
*parent
)
8443 struct die_info
*die
;
8447 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8450 *new_info_ptr
= cur_ptr
;
8453 store_in_ref_table (die
, reader
->cu
);
8456 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8460 *new_info_ptr
= cur_ptr
;
8463 die
->sibling
= NULL
;
8464 die
->parent
= parent
;
8468 /* Read a die, all of its descendents, and all of its siblings; set
8469 all of the fields of all of the dies correctly. Arguments are as
8470 in read_die_and_children. */
8472 static struct die_info
*
8473 read_die_and_siblings (const struct die_reader_specs
*reader
,
8475 gdb_byte
**new_info_ptr
,
8476 struct die_info
*parent
)
8478 struct die_info
*first_die
, *last_sibling
;
8482 first_die
= last_sibling
= NULL
;
8486 struct die_info
*die
8487 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8491 *new_info_ptr
= cur_ptr
;
8498 last_sibling
->sibling
= die
;
8504 /* Read the die from the .debug_info section buffer. Set DIEP to
8505 point to a newly allocated die with its information, except for its
8506 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8507 whether the die has children or not. */
8510 read_full_die (const struct die_reader_specs
*reader
,
8511 struct die_info
**diep
, gdb_byte
*info_ptr
,
8514 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8515 struct abbrev_info
*abbrev
;
8516 struct die_info
*die
;
8517 struct dwarf2_cu
*cu
= reader
->cu
;
8518 bfd
*abfd
= reader
->abfd
;
8520 offset
= info_ptr
- reader
->buffer
;
8521 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8522 info_ptr
+= bytes_read
;
8530 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8532 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8534 bfd_get_filename (abfd
));
8536 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8537 die
->offset
= offset
;
8538 die
->tag
= abbrev
->tag
;
8539 die
->abbrev
= abbrev_number
;
8541 die
->num_attrs
= abbrev
->num_attrs
;
8543 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8544 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8545 abfd
, info_ptr
, cu
);
8548 *has_children
= abbrev
->has_children
;
8552 /* In DWARF version 2, the description of the debugging information is
8553 stored in a separate .debug_abbrev section. Before we read any
8554 dies from a section we read in all abbreviations and install them
8555 in a hash table. This function also sets flags in CU describing
8556 the data found in the abbrev table. */
8559 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8561 struct comp_unit_head
*cu_header
= &cu
->header
;
8562 gdb_byte
*abbrev_ptr
;
8563 struct abbrev_info
*cur_abbrev
;
8564 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8565 unsigned int abbrev_form
, hash_number
;
8566 struct attr_abbrev
*cur_attrs
;
8567 unsigned int allocated_attrs
;
8569 /* Initialize dwarf2 abbrevs. */
8570 obstack_init (&cu
->abbrev_obstack
);
8571 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8573 * sizeof (struct abbrev_info
*)));
8574 memset (cu
->dwarf2_abbrevs
, 0,
8575 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8577 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8578 &dwarf2_per_objfile
->abbrev
);
8579 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8580 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8581 abbrev_ptr
+= bytes_read
;
8583 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8584 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8586 /* Loop until we reach an abbrev number of 0. */
8587 while (abbrev_number
)
8589 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8591 /* read in abbrev header */
8592 cur_abbrev
->number
= abbrev_number
;
8593 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8594 abbrev_ptr
+= bytes_read
;
8595 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8598 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8599 cu
->has_namespace_info
= 1;
8601 /* now read in declarations */
8602 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8603 abbrev_ptr
+= bytes_read
;
8604 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8605 abbrev_ptr
+= bytes_read
;
8608 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8610 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8612 = xrealloc (cur_attrs
, (allocated_attrs
8613 * sizeof (struct attr_abbrev
)));
8616 /* Record whether this compilation unit might have
8617 inter-compilation-unit references. If we don't know what form
8618 this attribute will have, then it might potentially be a
8619 DW_FORM_ref_addr, so we conservatively expect inter-CU
8622 if (abbrev_form
== DW_FORM_ref_addr
8623 || abbrev_form
== DW_FORM_indirect
)
8624 cu
->has_form_ref_addr
= 1;
8626 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8627 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8628 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8629 abbrev_ptr
+= bytes_read
;
8630 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8631 abbrev_ptr
+= bytes_read
;
8634 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8635 (cur_abbrev
->num_attrs
8636 * sizeof (struct attr_abbrev
)));
8637 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8638 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8640 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8641 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8642 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8644 /* Get next abbreviation.
8645 Under Irix6 the abbreviations for a compilation unit are not
8646 always properly terminated with an abbrev number of 0.
8647 Exit loop if we encounter an abbreviation which we have
8648 already read (which means we are about to read the abbreviations
8649 for the next compile unit) or if the end of the abbreviation
8650 table is reached. */
8651 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8652 >= dwarf2_per_objfile
->abbrev
.size
)
8654 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8655 abbrev_ptr
+= bytes_read
;
8656 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
8663 /* Release the memory used by the abbrev table for a compilation unit. */
8666 dwarf2_free_abbrev_table (void *ptr_to_cu
)
8668 struct dwarf2_cu
*cu
= ptr_to_cu
;
8670 obstack_free (&cu
->abbrev_obstack
, NULL
);
8671 cu
->dwarf2_abbrevs
= NULL
;
8674 /* Lookup an abbrev_info structure in the abbrev hash table. */
8676 static struct abbrev_info
*
8677 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
8679 unsigned int hash_number
;
8680 struct abbrev_info
*abbrev
;
8682 hash_number
= number
% ABBREV_HASH_SIZE
;
8683 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
8687 if (abbrev
->number
== number
)
8690 abbrev
= abbrev
->next
;
8695 /* Returns nonzero if TAG represents a type that we might generate a partial
8699 is_type_tag_for_partial (int tag
)
8704 /* Some types that would be reasonable to generate partial symbols for,
8705 that we don't at present. */
8706 case DW_TAG_array_type
:
8707 case DW_TAG_file_type
:
8708 case DW_TAG_ptr_to_member_type
:
8709 case DW_TAG_set_type
:
8710 case DW_TAG_string_type
:
8711 case DW_TAG_subroutine_type
:
8713 case DW_TAG_base_type
:
8714 case DW_TAG_class_type
:
8715 case DW_TAG_interface_type
:
8716 case DW_TAG_enumeration_type
:
8717 case DW_TAG_structure_type
:
8718 case DW_TAG_subrange_type
:
8719 case DW_TAG_typedef
:
8720 case DW_TAG_union_type
:
8727 /* Load all DIEs that are interesting for partial symbols into memory. */
8729 static struct partial_die_info
*
8730 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8731 int building_psymtab
, struct dwarf2_cu
*cu
)
8733 struct partial_die_info
*part_die
;
8734 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
8735 struct abbrev_info
*abbrev
;
8736 unsigned int bytes_read
;
8737 unsigned int load_all
= 0;
8739 int nesting_level
= 1;
8744 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
8748 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8752 &cu
->comp_unit_obstack
,
8753 hashtab_obstack_allocate
,
8754 dummy_obstack_deallocate
);
8756 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8757 sizeof (struct partial_die_info
));
8761 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
8763 /* A NULL abbrev means the end of a series of children. */
8766 if (--nesting_level
== 0)
8768 /* PART_DIE was probably the last thing allocated on the
8769 comp_unit_obstack, so we could call obstack_free
8770 here. We don't do that because the waste is small,
8771 and will be cleaned up when we're done with this
8772 compilation unit. This way, we're also more robust
8773 against other users of the comp_unit_obstack. */
8776 info_ptr
+= bytes_read
;
8777 last_die
= parent_die
;
8778 parent_die
= parent_die
->die_parent
;
8782 /* Check for template arguments. We never save these; if
8783 they're seen, we just mark the parent, and go on our way. */
8784 if (parent_die
!= NULL
8785 && cu
->language
== language_cplus
8786 && (abbrev
->tag
== DW_TAG_template_type_param
8787 || abbrev
->tag
== DW_TAG_template_value_param
))
8789 parent_die
->has_template_arguments
= 1;
8793 /* We don't need a partial DIE for the template argument. */
8794 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
8800 /* We only recurse into subprograms looking for template arguments.
8801 Skip their other children. */
8803 && cu
->language
== language_cplus
8804 && parent_die
!= NULL
8805 && parent_die
->tag
== DW_TAG_subprogram
)
8807 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8811 /* Check whether this DIE is interesting enough to save. Normally
8812 we would not be interested in members here, but there may be
8813 later variables referencing them via DW_AT_specification (for
8816 && !is_type_tag_for_partial (abbrev
->tag
)
8817 && abbrev
->tag
!= DW_TAG_constant
8818 && abbrev
->tag
!= DW_TAG_enumerator
8819 && abbrev
->tag
!= DW_TAG_subprogram
8820 && abbrev
->tag
!= DW_TAG_lexical_block
8821 && abbrev
->tag
!= DW_TAG_variable
8822 && abbrev
->tag
!= DW_TAG_namespace
8823 && abbrev
->tag
!= DW_TAG_module
8824 && abbrev
->tag
!= DW_TAG_member
)
8826 /* Otherwise we skip to the next sibling, if any. */
8827 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8831 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
8832 buffer
, info_ptr
, cu
);
8834 /* This two-pass algorithm for processing partial symbols has a
8835 high cost in cache pressure. Thus, handle some simple cases
8836 here which cover the majority of C partial symbols. DIEs
8837 which neither have specification tags in them, nor could have
8838 specification tags elsewhere pointing at them, can simply be
8839 processed and discarded.
8841 This segment is also optional; scan_partial_symbols and
8842 add_partial_symbol will handle these DIEs if we chain
8843 them in normally. When compilers which do not emit large
8844 quantities of duplicate debug information are more common,
8845 this code can probably be removed. */
8847 /* Any complete simple types at the top level (pretty much all
8848 of them, for a language without namespaces), can be processed
8850 if (parent_die
== NULL
8851 && part_die
->has_specification
== 0
8852 && part_die
->is_declaration
== 0
8853 && (part_die
->tag
== DW_TAG_typedef
8854 || part_die
->tag
== DW_TAG_base_type
8855 || part_die
->tag
== DW_TAG_subrange_type
))
8857 if (building_psymtab
&& part_die
->name
!= NULL
)
8858 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8859 VAR_DOMAIN
, LOC_TYPEDEF
,
8860 &cu
->objfile
->static_psymbols
,
8861 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8862 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8866 /* If we're at the second level, and we're an enumerator, and
8867 our parent has no specification (meaning possibly lives in a
8868 namespace elsewhere), then we can add the partial symbol now
8869 instead of queueing it. */
8870 if (part_die
->tag
== DW_TAG_enumerator
8871 && parent_die
!= NULL
8872 && parent_die
->die_parent
== NULL
8873 && parent_die
->tag
== DW_TAG_enumeration_type
8874 && parent_die
->has_specification
== 0)
8876 if (part_die
->name
== NULL
)
8877 complaint (&symfile_complaints
,
8878 _("malformed enumerator DIE ignored"));
8879 else if (building_psymtab
)
8880 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8881 VAR_DOMAIN
, LOC_CONST
,
8882 (cu
->language
== language_cplus
8883 || cu
->language
== language_java
)
8884 ? &cu
->objfile
->global_psymbols
8885 : &cu
->objfile
->static_psymbols
,
8886 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8888 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8892 /* We'll save this DIE so link it in. */
8893 part_die
->die_parent
= parent_die
;
8894 part_die
->die_sibling
= NULL
;
8895 part_die
->die_child
= NULL
;
8897 if (last_die
&& last_die
== parent_die
)
8898 last_die
->die_child
= part_die
;
8900 last_die
->die_sibling
= part_die
;
8902 last_die
= part_die
;
8904 if (first_die
== NULL
)
8905 first_die
= part_die
;
8907 /* Maybe add the DIE to the hash table. Not all DIEs that we
8908 find interesting need to be in the hash table, because we
8909 also have the parent/sibling/child chains; only those that we
8910 might refer to by offset later during partial symbol reading.
8912 For now this means things that might have be the target of a
8913 DW_AT_specification, DW_AT_abstract_origin, or
8914 DW_AT_extension. DW_AT_extension will refer only to
8915 namespaces; DW_AT_abstract_origin refers to functions (and
8916 many things under the function DIE, but we do not recurse
8917 into function DIEs during partial symbol reading) and
8918 possibly variables as well; DW_AT_specification refers to
8919 declarations. Declarations ought to have the DW_AT_declaration
8920 flag. It happens that GCC forgets to put it in sometimes, but
8921 only for functions, not for types.
8923 Adding more things than necessary to the hash table is harmless
8924 except for the performance cost. Adding too few will result in
8925 wasted time in find_partial_die, when we reread the compilation
8926 unit with load_all_dies set. */
8929 || abbrev
->tag
== DW_TAG_constant
8930 || abbrev
->tag
== DW_TAG_subprogram
8931 || abbrev
->tag
== DW_TAG_variable
8932 || abbrev
->tag
== DW_TAG_namespace
8933 || part_die
->is_declaration
)
8937 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
8938 part_die
->offset
, INSERT
);
8942 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8943 sizeof (struct partial_die_info
));
8945 /* For some DIEs we want to follow their children (if any). For C
8946 we have no reason to follow the children of structures; for other
8947 languages we have to, so that we can get at method physnames
8948 to infer fully qualified class names, for DW_AT_specification,
8949 and for C++ template arguments. For C++, we also look one level
8950 inside functions to find template arguments (if the name of the
8951 function does not already contain the template arguments).
8953 For Ada, we need to scan the children of subprograms and lexical
8954 blocks as well because Ada allows the definition of nested
8955 entities that could be interesting for the debugger, such as
8956 nested subprograms for instance. */
8957 if (last_die
->has_children
8959 || last_die
->tag
== DW_TAG_namespace
8960 || last_die
->tag
== DW_TAG_module
8961 || last_die
->tag
== DW_TAG_enumeration_type
8962 || (cu
->language
== language_cplus
8963 && last_die
->tag
== DW_TAG_subprogram
8964 && (last_die
->name
== NULL
8965 || strchr (last_die
->name
, '<') == NULL
))
8966 || (cu
->language
!= language_c
8967 && (last_die
->tag
== DW_TAG_class_type
8968 || last_die
->tag
== DW_TAG_interface_type
8969 || last_die
->tag
== DW_TAG_structure_type
8970 || last_die
->tag
== DW_TAG_union_type
))
8971 || (cu
->language
== language_ada
8972 && (last_die
->tag
== DW_TAG_subprogram
8973 || last_die
->tag
== DW_TAG_lexical_block
))))
8976 parent_die
= last_die
;
8980 /* Otherwise we skip to the next sibling, if any. */
8981 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
8983 /* Back to the top, do it again. */
8987 /* Read a minimal amount of information into the minimal die structure. */
8990 read_partial_die (struct partial_die_info
*part_die
,
8991 struct abbrev_info
*abbrev
,
8992 unsigned int abbrev_len
, bfd
*abfd
,
8993 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8994 struct dwarf2_cu
*cu
)
8997 struct attribute attr
;
8998 int has_low_pc_attr
= 0;
8999 int has_high_pc_attr
= 0;
9001 memset (part_die
, 0, sizeof (struct partial_die_info
));
9003 part_die
->offset
= info_ptr
- buffer
;
9005 info_ptr
+= abbrev_len
;
9010 part_die
->tag
= abbrev
->tag
;
9011 part_die
->has_children
= abbrev
->has_children
;
9013 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9015 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9017 /* Store the data if it is of an attribute we want to keep in a
9018 partial symbol table. */
9022 switch (part_die
->tag
)
9024 case DW_TAG_compile_unit
:
9025 case DW_TAG_type_unit
:
9026 /* Compilation units have a DW_AT_name that is a filename, not
9027 a source language identifier. */
9028 case DW_TAG_enumeration_type
:
9029 case DW_TAG_enumerator
:
9030 /* These tags always have simple identifiers already; no need
9031 to canonicalize them. */
9032 part_die
->name
= DW_STRING (&attr
);
9036 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9037 &cu
->objfile
->objfile_obstack
);
9041 case DW_AT_linkage_name
:
9042 case DW_AT_MIPS_linkage_name
:
9043 /* Note that both forms of linkage name might appear. We
9044 assume they will be the same, and we only store the last
9046 if (cu
->language
== language_ada
)
9047 part_die
->name
= DW_STRING (&attr
);
9048 part_die
->linkage_name
= DW_STRING (&attr
);
9051 has_low_pc_attr
= 1;
9052 part_die
->lowpc
= DW_ADDR (&attr
);
9055 has_high_pc_attr
= 1;
9056 part_die
->highpc
= DW_ADDR (&attr
);
9058 case DW_AT_location
:
9059 /* Support the .debug_loc offsets. */
9060 if (attr_form_is_block (&attr
))
9062 part_die
->locdesc
= DW_BLOCK (&attr
);
9064 else if (attr_form_is_section_offset (&attr
))
9066 dwarf2_complex_location_expr_complaint ();
9070 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9071 "partial symbol information");
9074 case DW_AT_external
:
9075 part_die
->is_external
= DW_UNSND (&attr
);
9077 case DW_AT_declaration
:
9078 part_die
->is_declaration
= DW_UNSND (&attr
);
9081 part_die
->has_type
= 1;
9083 case DW_AT_abstract_origin
:
9084 case DW_AT_specification
:
9085 case DW_AT_extension
:
9086 part_die
->has_specification
= 1;
9087 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9090 /* Ignore absolute siblings, they might point outside of
9091 the current compile unit. */
9092 if (attr
.form
== DW_FORM_ref_addr
)
9093 complaint (&symfile_complaints
,
9094 _("ignoring absolute DW_AT_sibling"));
9096 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9098 case DW_AT_byte_size
:
9099 part_die
->has_byte_size
= 1;
9101 case DW_AT_calling_convention
:
9102 /* DWARF doesn't provide a way to identify a program's source-level
9103 entry point. DW_AT_calling_convention attributes are only meant
9104 to describe functions' calling conventions.
9106 However, because it's a necessary piece of information in
9107 Fortran, and because DW_CC_program is the only piece of debugging
9108 information whose definition refers to a 'main program' at all,
9109 several compilers have begun marking Fortran main programs with
9110 DW_CC_program --- even when those functions use the standard
9111 calling conventions.
9113 So until DWARF specifies a way to provide this information and
9114 compilers pick up the new representation, we'll support this
9116 if (DW_UNSND (&attr
) == DW_CC_program
9117 && cu
->language
== language_fortran
)
9119 set_main_name (part_die
->name
);
9121 /* As this DIE has a static linkage the name would be difficult
9122 to look up later. */
9123 language_of_main
= language_fortran
;
9131 if (has_low_pc_attr
&& has_high_pc_attr
)
9133 /* When using the GNU linker, .gnu.linkonce. sections are used to
9134 eliminate duplicate copies of functions and vtables and such.
9135 The linker will arbitrarily choose one and discard the others.
9136 The AT_*_pc values for such functions refer to local labels in
9137 these sections. If the section from that file was discarded, the
9138 labels are not in the output, so the relocs get a value of 0.
9139 If this is a discarded function, mark the pc bounds as invalid,
9140 so that GDB will ignore it. */
9141 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9143 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9145 complaint (&symfile_complaints
,
9146 _("DW_AT_low_pc %s is zero "
9147 "for DIE at 0x%x [in module %s]"),
9148 paddress (gdbarch
, part_die
->lowpc
),
9149 part_die
->offset
, cu
->objfile
->name
);
9151 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9152 else if (part_die
->lowpc
>= part_die
->highpc
)
9154 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9156 complaint (&symfile_complaints
,
9157 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9158 "for DIE at 0x%x [in module %s]"),
9159 paddress (gdbarch
, part_die
->lowpc
),
9160 paddress (gdbarch
, part_die
->highpc
),
9161 part_die
->offset
, cu
->objfile
->name
);
9164 part_die
->has_pc_info
= 1;
9170 /* Find a cached partial DIE at OFFSET in CU. */
9172 static struct partial_die_info
*
9173 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9175 struct partial_die_info
*lookup_die
= NULL
;
9176 struct partial_die_info part_die
;
9178 part_die
.offset
= offset
;
9179 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9184 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9185 except in the case of .debug_types DIEs which do not reference
9186 outside their CU (they do however referencing other types via
9187 DW_FORM_ref_sig8). */
9189 static struct partial_die_info
*
9190 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9192 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9193 struct partial_die_info
*pd
= NULL
;
9195 if (cu
->per_cu
->from_debug_types
)
9197 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9203 if (offset_in_cu_p (&cu
->header
, offset
))
9205 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9210 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9212 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9213 load_partial_comp_unit (per_cu
, cu
->objfile
);
9215 per_cu
->cu
->last_used
= 0;
9216 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9218 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9220 struct cleanup
*back_to
;
9221 struct partial_die_info comp_unit_die
;
9222 struct abbrev_info
*abbrev
;
9223 unsigned int bytes_read
;
9226 per_cu
->load_all_dies
= 1;
9228 /* Re-read the DIEs. */
9229 back_to
= make_cleanup (null_cleanup
, 0);
9230 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9232 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
9233 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9235 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9236 + per_cu
->cu
->header
.offset
9237 + per_cu
->cu
->header
.first_die_offset
);
9238 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9239 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9240 per_cu
->cu
->objfile
->obfd
,
9241 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9243 if (comp_unit_die
.has_children
)
9244 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
9245 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9247 do_cleanups (back_to
);
9249 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9255 internal_error (__FILE__
, __LINE__
,
9256 _("could not find partial DIE 0x%x "
9257 "in cache [from module %s]\n"),
9258 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9262 /* See if we can figure out if the class lives in a namespace. We do
9263 this by looking for a member function; its demangled name will
9264 contain namespace info, if there is any. */
9267 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9268 struct dwarf2_cu
*cu
)
9270 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9271 what template types look like, because the demangler
9272 frequently doesn't give the same name as the debug info. We
9273 could fix this by only using the demangled name to get the
9274 prefix (but see comment in read_structure_type). */
9276 struct partial_die_info
*real_pdi
;
9277 struct partial_die_info
*child_pdi
;
9279 /* If this DIE (this DIE's specification, if any) has a parent, then
9280 we should not do this. We'll prepend the parent's fully qualified
9281 name when we create the partial symbol. */
9283 real_pdi
= struct_pdi
;
9284 while (real_pdi
->has_specification
)
9285 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9287 if (real_pdi
->die_parent
!= NULL
)
9290 for (child_pdi
= struct_pdi
->die_child
;
9292 child_pdi
= child_pdi
->die_sibling
)
9294 if (child_pdi
->tag
== DW_TAG_subprogram
9295 && child_pdi
->linkage_name
!= NULL
)
9297 char *actual_class_name
9298 = language_class_name_from_physname (cu
->language_defn
,
9299 child_pdi
->linkage_name
);
9300 if (actual_class_name
!= NULL
)
9303 = obsavestring (actual_class_name
,
9304 strlen (actual_class_name
),
9305 &cu
->objfile
->objfile_obstack
);
9306 xfree (actual_class_name
);
9313 /* Adjust PART_DIE before generating a symbol for it. This function
9314 may set the is_external flag or change the DIE's name. */
9317 fixup_partial_die (struct partial_die_info
*part_die
,
9318 struct dwarf2_cu
*cu
)
9320 /* Once we've fixed up a die, there's no point in doing so again.
9321 This also avoids a memory leak if we were to call
9322 guess_partial_die_structure_name multiple times. */
9323 if (part_die
->fixup_called
)
9326 /* If we found a reference attribute and the DIE has no name, try
9327 to find a name in the referred to DIE. */
9329 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9331 struct partial_die_info
*spec_die
;
9333 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9335 fixup_partial_die (spec_die
, cu
);
9339 part_die
->name
= spec_die
->name
;
9341 /* Copy DW_AT_external attribute if it is set. */
9342 if (spec_die
->is_external
)
9343 part_die
->is_external
= spec_die
->is_external
;
9347 /* Set default names for some unnamed DIEs. */
9349 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9350 part_die
->name
= "(anonymous namespace)";
9352 /* If there is no parent die to provide a namespace, and there are
9353 children, see if we can determine the namespace from their linkage
9355 NOTE: We need to do this even if cu->has_namespace_info != 0.
9356 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9357 if (cu
->language
== language_cplus
9358 && dwarf2_per_objfile
->types
.asection
!= NULL
9359 && part_die
->die_parent
== NULL
9360 && part_die
->has_children
9361 && (part_die
->tag
== DW_TAG_class_type
9362 || part_die
->tag
== DW_TAG_structure_type
9363 || part_die
->tag
== DW_TAG_union_type
))
9364 guess_partial_die_structure_name (part_die
, cu
);
9366 /* GCC might emit a nameless struct or union that has a linkage
9367 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
9368 if (part_die
->name
== NULL
9369 && (part_die
->tag
== DW_TAG_structure_type
9370 || part_die
->tag
== DW_TAG_union_type
9371 || part_die
->tag
== DW_TAG_class_type
)
9372 && part_die
->linkage_name
!= NULL
)
9376 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
9379 part_die
->name
= obsavestring (demangled
, strlen (demangled
),
9380 &cu
->objfile
->objfile_obstack
);
9385 part_die
->fixup_called
= 1;
9388 /* Read an attribute value described by an attribute form. */
9391 read_attribute_value (struct attribute
*attr
, unsigned form
,
9392 bfd
*abfd
, gdb_byte
*info_ptr
,
9393 struct dwarf2_cu
*cu
)
9395 struct comp_unit_head
*cu_header
= &cu
->header
;
9396 unsigned int bytes_read
;
9397 struct dwarf_block
*blk
;
9402 case DW_FORM_ref_addr
:
9403 if (cu
->header
.version
== 2)
9404 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9406 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
9407 &cu
->header
, &bytes_read
);
9408 info_ptr
+= bytes_read
;
9411 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9412 info_ptr
+= bytes_read
;
9414 case DW_FORM_block2
:
9415 blk
= dwarf_alloc_block (cu
);
9416 blk
->size
= read_2_bytes (abfd
, info_ptr
);
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_block4
:
9423 blk
= dwarf_alloc_block (cu
);
9424 blk
->size
= read_4_bytes (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_2_bytes (abfd
, info_ptr
);
9435 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9439 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9442 case DW_FORM_sec_offset
:
9443 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9444 info_ptr
+= bytes_read
;
9446 case DW_FORM_string
:
9447 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9448 DW_STRING_IS_CANONICAL (attr
) = 0;
9449 info_ptr
+= bytes_read
;
9452 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9454 DW_STRING_IS_CANONICAL (attr
) = 0;
9455 info_ptr
+= bytes_read
;
9457 case DW_FORM_exprloc
:
9459 blk
= dwarf_alloc_block (cu
);
9460 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9461 info_ptr
+= bytes_read
;
9462 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9463 info_ptr
+= blk
->size
;
9464 DW_BLOCK (attr
) = blk
;
9466 case DW_FORM_block1
:
9467 blk
= dwarf_alloc_block (cu
);
9468 blk
->size
= read_1_byte (abfd
, info_ptr
);
9470 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9471 info_ptr
+= blk
->size
;
9472 DW_BLOCK (attr
) = blk
;
9475 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9479 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9482 case DW_FORM_flag_present
:
9483 DW_UNSND (attr
) = 1;
9486 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9487 info_ptr
+= bytes_read
;
9490 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9491 info_ptr
+= bytes_read
;
9494 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9498 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9502 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9506 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9509 case DW_FORM_ref_sig8
:
9510 /* Convert the signature to something we can record in DW_UNSND
9512 NOTE: This is NULL if the type wasn't found. */
9513 DW_SIGNATURED_TYPE (attr
) =
9514 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9517 case DW_FORM_ref_udata
:
9518 DW_ADDR (attr
) = (cu
->header
.offset
9519 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9520 info_ptr
+= bytes_read
;
9522 case DW_FORM_indirect
:
9523 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9524 info_ptr
+= bytes_read
;
9525 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9528 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9529 dwarf_form_name (form
),
9530 bfd_get_filename (abfd
));
9533 /* We have seen instances where the compiler tried to emit a byte
9534 size attribute of -1 which ended up being encoded as an unsigned
9535 0xffffffff. Although 0xffffffff is technically a valid size value,
9536 an object of this size seems pretty unlikely so we can relatively
9537 safely treat these cases as if the size attribute was invalid and
9538 treat them as zero by default. */
9539 if (attr
->name
== DW_AT_byte_size
9540 && form
== DW_FORM_data4
9541 && DW_UNSND (attr
) >= 0xffffffff)
9544 (&symfile_complaints
,
9545 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9546 hex_string (DW_UNSND (attr
)));
9547 DW_UNSND (attr
) = 0;
9553 /* Read an attribute described by an abbreviated attribute. */
9556 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9557 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9559 attr
->name
= abbrev
->name
;
9560 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9563 /* Read dwarf information from a buffer. */
9566 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9568 return bfd_get_8 (abfd
, buf
);
9572 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9574 return bfd_get_signed_8 (abfd
, buf
);
9578 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9580 return bfd_get_16 (abfd
, buf
);
9584 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9586 return bfd_get_signed_16 (abfd
, buf
);
9590 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9592 return bfd_get_32 (abfd
, buf
);
9596 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9598 return bfd_get_signed_32 (abfd
, buf
);
9602 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9604 return bfd_get_64 (abfd
, buf
);
9608 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9609 unsigned int *bytes_read
)
9611 struct comp_unit_head
*cu_header
= &cu
->header
;
9612 CORE_ADDR retval
= 0;
9614 if (cu_header
->signed_addr_p
)
9616 switch (cu_header
->addr_size
)
9619 retval
= bfd_get_signed_16 (abfd
, buf
);
9622 retval
= bfd_get_signed_32 (abfd
, buf
);
9625 retval
= bfd_get_signed_64 (abfd
, buf
);
9628 internal_error (__FILE__
, __LINE__
,
9629 _("read_address: bad switch, signed [in module %s]"),
9630 bfd_get_filename (abfd
));
9635 switch (cu_header
->addr_size
)
9638 retval
= bfd_get_16 (abfd
, buf
);
9641 retval
= bfd_get_32 (abfd
, buf
);
9644 retval
= bfd_get_64 (abfd
, buf
);
9647 internal_error (__FILE__
, __LINE__
,
9648 _("read_address: bad switch, "
9649 "unsigned [in module %s]"),
9650 bfd_get_filename (abfd
));
9654 *bytes_read
= cu_header
->addr_size
;
9658 /* Read the initial length from a section. The (draft) DWARF 3
9659 specification allows the initial length to take up either 4 bytes
9660 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9661 bytes describe the length and all offsets will be 8 bytes in length
9664 An older, non-standard 64-bit format is also handled by this
9665 function. The older format in question stores the initial length
9666 as an 8-byte quantity without an escape value. Lengths greater
9667 than 2^32 aren't very common which means that the initial 4 bytes
9668 is almost always zero. Since a length value of zero doesn't make
9669 sense for the 32-bit format, this initial zero can be considered to
9670 be an escape value which indicates the presence of the older 64-bit
9671 format. As written, the code can't detect (old format) lengths
9672 greater than 4GB. If it becomes necessary to handle lengths
9673 somewhat larger than 4GB, we could allow other small values (such
9674 as the non-sensical values of 1, 2, and 3) to also be used as
9675 escape values indicating the presence of the old format.
9677 The value returned via bytes_read should be used to increment the
9678 relevant pointer after calling read_initial_length().
9680 [ Note: read_initial_length() and read_offset() are based on the
9681 document entitled "DWARF Debugging Information Format", revision
9682 3, draft 8, dated November 19, 2001. This document was obtained
9685 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9687 This document is only a draft and is subject to change. (So beware.)
9689 Details regarding the older, non-standard 64-bit format were
9690 determined empirically by examining 64-bit ELF files produced by
9691 the SGI toolchain on an IRIX 6.5 machine.
9693 - Kevin, July 16, 2002
9697 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
9699 LONGEST length
= bfd_get_32 (abfd
, buf
);
9701 if (length
== 0xffffffff)
9703 length
= bfd_get_64 (abfd
, buf
+ 4);
9706 else if (length
== 0)
9708 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9709 length
= bfd_get_64 (abfd
, buf
);
9720 /* Cover function for read_initial_length.
9721 Returns the length of the object at BUF, and stores the size of the
9722 initial length in *BYTES_READ and stores the size that offsets will be in
9724 If the initial length size is not equivalent to that specified in
9725 CU_HEADER then issue a complaint.
9726 This is useful when reading non-comp-unit headers. */
9729 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
9730 const struct comp_unit_head
*cu_header
,
9731 unsigned int *bytes_read
,
9732 unsigned int *offset_size
)
9734 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
9736 gdb_assert (cu_header
->initial_length_size
== 4
9737 || cu_header
->initial_length_size
== 8
9738 || cu_header
->initial_length_size
== 12);
9740 if (cu_header
->initial_length_size
!= *bytes_read
)
9741 complaint (&symfile_complaints
,
9742 _("intermixed 32-bit and 64-bit DWARF sections"));
9744 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
9748 /* Read an offset from the data stream. The size of the offset is
9749 given by cu_header->offset_size. */
9752 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
9753 unsigned int *bytes_read
)
9755 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
9757 *bytes_read
= cu_header
->offset_size
;
9761 /* Read an offset from the data stream. */
9764 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
9768 switch (offset_size
)
9771 retval
= bfd_get_32 (abfd
, buf
);
9774 retval
= bfd_get_64 (abfd
, buf
);
9777 internal_error (__FILE__
, __LINE__
,
9778 _("read_offset_1: bad switch [in module %s]"),
9779 bfd_get_filename (abfd
));
9786 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
9788 /* If the size of a host char is 8 bits, we can return a pointer
9789 to the buffer, otherwise we have to copy the data to a buffer
9790 allocated on the temporary obstack. */
9791 gdb_assert (HOST_CHAR_BIT
== 8);
9796 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9798 /* If the size of a host char is 8 bits, we can return a pointer
9799 to the string, otherwise we have to copy the string to a buffer
9800 allocated on the temporary obstack. */
9801 gdb_assert (HOST_CHAR_BIT
== 8);
9804 *bytes_read_ptr
= 1;
9807 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
9808 return (char *) buf
;
9812 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
9813 const struct comp_unit_head
*cu_header
,
9814 unsigned int *bytes_read_ptr
)
9816 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
9818 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
9819 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
9821 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9822 bfd_get_filename (abfd
));
9825 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
9827 error (_("DW_FORM_strp pointing outside of "
9828 ".debug_str section [in module %s]"),
9829 bfd_get_filename (abfd
));
9832 gdb_assert (HOST_CHAR_BIT
== 8);
9833 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
9835 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
9838 static unsigned long
9839 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9841 unsigned long result
;
9842 unsigned int num_read
;
9852 byte
= bfd_get_8 (abfd
, buf
);
9855 result
|= ((unsigned long)(byte
& 127) << shift
);
9856 if ((byte
& 128) == 0)
9862 *bytes_read_ptr
= num_read
;
9867 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9870 int i
, shift
, num_read
;
9879 byte
= bfd_get_8 (abfd
, buf
);
9882 result
|= ((long)(byte
& 127) << shift
);
9884 if ((byte
& 128) == 0)
9889 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
9890 result
|= -(((long)1) << shift
);
9891 *bytes_read_ptr
= num_read
;
9895 /* Return a pointer to just past the end of an LEB128 number in BUF. */
9898 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
9904 byte
= bfd_get_8 (abfd
, buf
);
9906 if ((byte
& 128) == 0)
9912 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
9919 cu
->language
= language_c
;
9921 case DW_LANG_C_plus_plus
:
9922 cu
->language
= language_cplus
;
9925 cu
->language
= language_d
;
9927 case DW_LANG_Fortran77
:
9928 case DW_LANG_Fortran90
:
9929 case DW_LANG_Fortran95
:
9930 cu
->language
= language_fortran
;
9932 case DW_LANG_Mips_Assembler
:
9933 cu
->language
= language_asm
;
9936 cu
->language
= language_java
;
9940 cu
->language
= language_ada
;
9942 case DW_LANG_Modula2
:
9943 cu
->language
= language_m2
;
9945 case DW_LANG_Pascal83
:
9946 cu
->language
= language_pascal
;
9949 cu
->language
= language_objc
;
9951 case DW_LANG_Cobol74
:
9952 case DW_LANG_Cobol85
:
9954 cu
->language
= language_minimal
;
9957 cu
->language_defn
= language_def (cu
->language
);
9960 /* Return the named attribute or NULL if not there. */
9962 static struct attribute
*
9963 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
9966 struct attribute
*spec
= NULL
;
9968 for (i
= 0; i
< die
->num_attrs
; ++i
)
9970 if (die
->attrs
[i
].name
== name
)
9971 return &die
->attrs
[i
];
9972 if (die
->attrs
[i
].name
== DW_AT_specification
9973 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
9974 spec
= &die
->attrs
[i
];
9979 die
= follow_die_ref (die
, spec
, &cu
);
9980 return dwarf2_attr (die
, name
, cu
);
9986 /* Return the named attribute or NULL if not there,
9987 but do not follow DW_AT_specification, etc.
9988 This is for use in contexts where we're reading .debug_types dies.
9989 Following DW_AT_specification, DW_AT_abstract_origin will take us
9990 back up the chain, and we want to go down. */
9992 static struct attribute
*
9993 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
9994 struct dwarf2_cu
*cu
)
9998 for (i
= 0; i
< die
->num_attrs
; ++i
)
9999 if (die
->attrs
[i
].name
== name
)
10000 return &die
->attrs
[i
];
10005 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10006 and holds a non-zero value. This function should only be used for
10007 DW_FORM_flag or DW_FORM_flag_present attributes. */
10010 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10012 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10014 return (attr
&& DW_UNSND (attr
));
10018 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10020 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10021 which value is non-zero. However, we have to be careful with
10022 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10023 (via dwarf2_flag_true_p) follows this attribute. So we may
10024 end up accidently finding a declaration attribute that belongs
10025 to a different DIE referenced by the specification attribute,
10026 even though the given DIE does not have a declaration attribute. */
10027 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10028 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10031 /* Return the die giving the specification for DIE, if there is
10032 one. *SPEC_CU is the CU containing DIE on input, and the CU
10033 containing the return value on output. If there is no
10034 specification, but there is an abstract origin, that is
10037 static struct die_info
*
10038 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10040 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10043 if (spec_attr
== NULL
)
10044 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10046 if (spec_attr
== NULL
)
10049 return follow_die_ref (die
, spec_attr
, spec_cu
);
10052 /* Free the line_header structure *LH, and any arrays and strings it
10054 NOTE: This is also used as a "cleanup" function. */
10057 free_line_header (struct line_header
*lh
)
10059 if (lh
->standard_opcode_lengths
)
10060 xfree (lh
->standard_opcode_lengths
);
10062 /* Remember that all the lh->file_names[i].name pointers are
10063 pointers into debug_line_buffer, and don't need to be freed. */
10064 if (lh
->file_names
)
10065 xfree (lh
->file_names
);
10067 /* Similarly for the include directory names. */
10068 if (lh
->include_dirs
)
10069 xfree (lh
->include_dirs
);
10074 /* Add an entry to LH's include directory table. */
10077 add_include_dir (struct line_header
*lh
, char *include_dir
)
10079 /* Grow the array if necessary. */
10080 if (lh
->include_dirs_size
== 0)
10082 lh
->include_dirs_size
= 1; /* for testing */
10083 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10084 * sizeof (*lh
->include_dirs
));
10086 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10088 lh
->include_dirs_size
*= 2;
10089 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10090 (lh
->include_dirs_size
10091 * sizeof (*lh
->include_dirs
)));
10094 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10097 /* Add an entry to LH's file name table. */
10100 add_file_name (struct line_header
*lh
,
10102 unsigned int dir_index
,
10103 unsigned int mod_time
,
10104 unsigned int length
)
10106 struct file_entry
*fe
;
10108 /* Grow the array if necessary. */
10109 if (lh
->file_names_size
== 0)
10111 lh
->file_names_size
= 1; /* for testing */
10112 lh
->file_names
= xmalloc (lh
->file_names_size
10113 * sizeof (*lh
->file_names
));
10115 else if (lh
->num_file_names
>= lh
->file_names_size
)
10117 lh
->file_names_size
*= 2;
10118 lh
->file_names
= xrealloc (lh
->file_names
,
10119 (lh
->file_names_size
10120 * sizeof (*lh
->file_names
)));
10123 fe
= &lh
->file_names
[lh
->num_file_names
++];
10125 fe
->dir_index
= dir_index
;
10126 fe
->mod_time
= mod_time
;
10127 fe
->length
= length
;
10128 fe
->included_p
= 0;
10132 /* Read the statement program header starting at OFFSET in
10133 .debug_line, according to the endianness of ABFD. Return a pointer
10134 to a struct line_header, allocated using xmalloc.
10136 NOTE: the strings in the include directory and file name tables of
10137 the returned object point into debug_line_buffer, and must not be
10140 static struct line_header
*
10141 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10142 struct dwarf2_cu
*cu
)
10144 struct cleanup
*back_to
;
10145 struct line_header
*lh
;
10146 gdb_byte
*line_ptr
;
10147 unsigned int bytes_read
, offset_size
;
10149 char *cur_dir
, *cur_file
;
10151 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10152 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10154 complaint (&symfile_complaints
, _("missing .debug_line section"));
10158 /* Make sure that at least there's room for the total_length field.
10159 That could be 12 bytes long, but we're just going to fudge that. */
10160 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10162 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10166 lh
= xmalloc (sizeof (*lh
));
10167 memset (lh
, 0, sizeof (*lh
));
10168 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10171 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10173 /* Read in the header. */
10175 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10176 &bytes_read
, &offset_size
);
10177 line_ptr
+= bytes_read
;
10178 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10179 + dwarf2_per_objfile
->line
.size
))
10181 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10184 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10185 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10187 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10188 line_ptr
+= offset_size
;
10189 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10191 if (lh
->version
>= 4)
10193 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10197 lh
->maximum_ops_per_instruction
= 1;
10199 if (lh
->maximum_ops_per_instruction
== 0)
10201 lh
->maximum_ops_per_instruction
= 1;
10202 complaint (&symfile_complaints
,
10203 _("invalid maximum_ops_per_instruction "
10204 "in `.debug_line' section"));
10207 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10209 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10211 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10213 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10215 lh
->standard_opcode_lengths
10216 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10218 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10219 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10221 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10225 /* Read directory table. */
10226 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10228 line_ptr
+= bytes_read
;
10229 add_include_dir (lh
, cur_dir
);
10231 line_ptr
+= bytes_read
;
10233 /* Read file name table. */
10234 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10236 unsigned int dir_index
, mod_time
, length
;
10238 line_ptr
+= bytes_read
;
10239 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10240 line_ptr
+= bytes_read
;
10241 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10242 line_ptr
+= bytes_read
;
10243 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10244 line_ptr
+= bytes_read
;
10246 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10248 line_ptr
+= bytes_read
;
10249 lh
->statement_program_start
= line_ptr
;
10251 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
10252 + dwarf2_per_objfile
->line
.size
))
10253 complaint (&symfile_complaints
,
10254 _("line number info header doesn't "
10255 "fit in `.debug_line' section"));
10257 discard_cleanups (back_to
);
10261 /* This function exists to work around a bug in certain compilers
10262 (particularly GCC 2.95), in which the first line number marker of a
10263 function does not show up until after the prologue, right before
10264 the second line number marker. This function shifts ADDRESS down
10265 to the beginning of the function if necessary, and is called on
10266 addresses passed to record_line. */
10269 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
10271 struct function_range
*fn
;
10273 /* Find the function_range containing address. */
10277 if (!cu
->cached_fn
)
10278 cu
->cached_fn
= cu
->first_fn
;
10280 fn
= cu
->cached_fn
;
10282 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10288 while (fn
&& fn
!= cu
->cached_fn
)
10289 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10299 if (address
!= fn
->lowpc
)
10300 complaint (&symfile_complaints
,
10301 _("misplaced first line number at 0x%lx for '%s'"),
10302 (unsigned long) address
, fn
->name
);
10307 /* Subroutine of dwarf_decode_lines to simplify it.
10308 Return the file name of the psymtab for included file FILE_INDEX
10309 in line header LH of PST.
10310 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10311 If space for the result is malloc'd, it will be freed by a cleanup.
10312 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10315 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10316 const struct partial_symtab
*pst
,
10317 const char *comp_dir
)
10319 const struct file_entry fe
= lh
->file_names
[file_index
];
10320 char *include_name
= fe
.name
;
10321 char *include_name_to_compare
= include_name
;
10322 char *dir_name
= NULL
;
10323 const char *pst_filename
;
10324 char *copied_name
= NULL
;
10328 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10330 if (!IS_ABSOLUTE_PATH (include_name
)
10331 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10333 /* Avoid creating a duplicate psymtab for PST.
10334 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10335 Before we do the comparison, however, we need to account
10336 for DIR_NAME and COMP_DIR.
10337 First prepend dir_name (if non-NULL). If we still don't
10338 have an absolute path prepend comp_dir (if non-NULL).
10339 However, the directory we record in the include-file's
10340 psymtab does not contain COMP_DIR (to match the
10341 corresponding symtab(s)).
10346 bash$ gcc -g ./hello.c
10347 include_name = "hello.c"
10349 DW_AT_comp_dir = comp_dir = "/tmp"
10350 DW_AT_name = "./hello.c" */
10352 if (dir_name
!= NULL
)
10354 include_name
= concat (dir_name
, SLASH_STRING
,
10355 include_name
, (char *)NULL
);
10356 include_name_to_compare
= include_name
;
10357 make_cleanup (xfree
, include_name
);
10359 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10361 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10362 include_name
, (char *)NULL
);
10366 pst_filename
= pst
->filename
;
10367 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10369 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
10370 pst_filename
, (char *)NULL
);
10371 pst_filename
= copied_name
;
10374 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
10376 if (include_name_to_compare
!= include_name
)
10377 xfree (include_name_to_compare
);
10378 if (copied_name
!= NULL
)
10379 xfree (copied_name
);
10383 return include_name
;
10386 /* Ignore this record_line request. */
10389 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10394 /* Decode the Line Number Program (LNP) for the given line_header
10395 structure and CU. The actual information extracted and the type
10396 of structures created from the LNP depends on the value of PST.
10398 1. If PST is NULL, then this procedure uses the data from the program
10399 to create all necessary symbol tables, and their linetables.
10401 2. If PST is not NULL, this procedure reads the program to determine
10402 the list of files included by the unit represented by PST, and
10403 builds all the associated partial symbol tables.
10405 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10406 It is used for relative paths in the line table.
10407 NOTE: When processing partial symtabs (pst != NULL),
10408 comp_dir == pst->dirname.
10410 NOTE: It is important that psymtabs have the same file name (via strcmp)
10411 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10412 symtab we don't use it in the name of the psymtabs we create.
10413 E.g. expand_line_sal requires this when finding psymtabs to expand.
10414 A good testcase for this is mb-inline.exp. */
10417 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
10418 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10420 gdb_byte
*line_ptr
, *extended_end
;
10421 gdb_byte
*line_end
;
10422 unsigned int bytes_read
, extended_len
;
10423 unsigned char op_code
, extended_op
, adj_opcode
;
10424 CORE_ADDR baseaddr
;
10425 struct objfile
*objfile
= cu
->objfile
;
10426 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10427 const int decode_for_pst_p
= (pst
!= NULL
);
10428 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10429 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10432 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10434 line_ptr
= lh
->statement_program_start
;
10435 line_end
= lh
->statement_program_end
;
10437 /* Read the statement sequences until there's nothing left. */
10438 while (line_ptr
< line_end
)
10440 /* state machine registers */
10441 CORE_ADDR address
= 0;
10442 unsigned int file
= 1;
10443 unsigned int line
= 1;
10444 unsigned int column
= 0;
10445 int is_stmt
= lh
->default_is_stmt
;
10446 int basic_block
= 0;
10447 int end_sequence
= 0;
10449 unsigned char op_index
= 0;
10451 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10453 /* Start a subfile for the current file of the state machine. */
10454 /* lh->include_dirs and lh->file_names are 0-based, but the
10455 directory and file name numbers in the statement program
10457 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10461 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10463 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10466 /* Decode the table. */
10467 while (!end_sequence
)
10469 op_code
= read_1_byte (abfd
, line_ptr
);
10471 if (line_ptr
> line_end
)
10473 dwarf2_debug_line_missing_end_sequence_complaint ();
10477 if (op_code
>= lh
->opcode_base
)
10479 /* Special operand. */
10480 adj_opcode
= op_code
- lh
->opcode_base
;
10481 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10482 / lh
->maximum_ops_per_instruction
)
10483 * lh
->minimum_instruction_length
);
10484 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10485 % lh
->maximum_ops_per_instruction
);
10486 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10487 if (lh
->num_file_names
< file
|| file
== 0)
10488 dwarf2_debug_line_missing_file_complaint ();
10489 /* For now we ignore lines not starting on an
10490 instruction boundary. */
10491 else if (op_index
== 0)
10493 lh
->file_names
[file
- 1].included_p
= 1;
10494 if (!decode_for_pst_p
&& is_stmt
)
10496 if (last_subfile
!= current_subfile
)
10498 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10500 (*p_record_line
) (last_subfile
, 0, addr
);
10501 last_subfile
= current_subfile
;
10503 /* Append row to matrix using current values. */
10504 addr
= check_cu_functions (address
, cu
);
10505 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10506 (*p_record_line
) (current_subfile
, line
, addr
);
10511 else switch (op_code
)
10513 case DW_LNS_extended_op
:
10514 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
10516 line_ptr
+= bytes_read
;
10517 extended_end
= line_ptr
+ extended_len
;
10518 extended_op
= read_1_byte (abfd
, line_ptr
);
10520 switch (extended_op
)
10522 case DW_LNE_end_sequence
:
10523 p_record_line
= record_line
;
10526 case DW_LNE_set_address
:
10527 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10529 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10531 /* This line table is for a function which has been
10532 GCd by the linker. Ignore it. PR gdb/12528 */
10535 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
10537 complaint (&symfile_complaints
,
10538 _(".debug_line address at offset 0x%lx is 0 "
10540 line_offset
, cu
->objfile
->name
);
10541 p_record_line
= noop_record_line
;
10545 line_ptr
+= bytes_read
;
10546 address
+= baseaddr
;
10548 case DW_LNE_define_file
:
10551 unsigned int dir_index
, mod_time
, length
;
10553 cur_file
= read_direct_string (abfd
, line_ptr
,
10555 line_ptr
+= bytes_read
;
10557 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10558 line_ptr
+= bytes_read
;
10560 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10561 line_ptr
+= bytes_read
;
10563 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10564 line_ptr
+= bytes_read
;
10565 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10568 case DW_LNE_set_discriminator
:
10569 /* The discriminator is not interesting to the debugger;
10571 line_ptr
= extended_end
;
10574 complaint (&symfile_complaints
,
10575 _("mangled .debug_line section"));
10578 /* Make sure that we parsed the extended op correctly. If e.g.
10579 we expected a different address size than the producer used,
10580 we may have read the wrong number of bytes. */
10581 if (line_ptr
!= extended_end
)
10583 complaint (&symfile_complaints
,
10584 _("mangled .debug_line section"));
10589 if (lh
->num_file_names
< file
|| file
== 0)
10590 dwarf2_debug_line_missing_file_complaint ();
10593 lh
->file_names
[file
- 1].included_p
= 1;
10594 if (!decode_for_pst_p
&& is_stmt
)
10596 if (last_subfile
!= current_subfile
)
10598 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10600 (*p_record_line
) (last_subfile
, 0, addr
);
10601 last_subfile
= current_subfile
;
10603 addr
= check_cu_functions (address
, cu
);
10604 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10605 (*p_record_line
) (current_subfile
, line
, addr
);
10610 case DW_LNS_advance_pc
:
10613 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10615 address
+= (((op_index
+ adjust
)
10616 / lh
->maximum_ops_per_instruction
)
10617 * lh
->minimum_instruction_length
);
10618 op_index
= ((op_index
+ adjust
)
10619 % lh
->maximum_ops_per_instruction
);
10620 line_ptr
+= bytes_read
;
10623 case DW_LNS_advance_line
:
10624 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
10625 line_ptr
+= bytes_read
;
10627 case DW_LNS_set_file
:
10629 /* The arrays lh->include_dirs and lh->file_names are
10630 0-based, but the directory and file name numbers in
10631 the statement program are 1-based. */
10632 struct file_entry
*fe
;
10635 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10636 line_ptr
+= bytes_read
;
10637 if (lh
->num_file_names
< file
|| file
== 0)
10638 dwarf2_debug_line_missing_file_complaint ();
10641 fe
= &lh
->file_names
[file
- 1];
10643 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10644 if (!decode_for_pst_p
)
10646 last_subfile
= current_subfile
;
10647 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10652 case DW_LNS_set_column
:
10653 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10654 line_ptr
+= bytes_read
;
10656 case DW_LNS_negate_stmt
:
10657 is_stmt
= (!is_stmt
);
10659 case DW_LNS_set_basic_block
:
10662 /* Add to the address register of the state machine the
10663 address increment value corresponding to special opcode
10664 255. I.e., this value is scaled by the minimum
10665 instruction length since special opcode 255 would have
10666 scaled the increment. */
10667 case DW_LNS_const_add_pc
:
10669 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
10671 address
+= (((op_index
+ adjust
)
10672 / lh
->maximum_ops_per_instruction
)
10673 * lh
->minimum_instruction_length
);
10674 op_index
= ((op_index
+ adjust
)
10675 % lh
->maximum_ops_per_instruction
);
10678 case DW_LNS_fixed_advance_pc
:
10679 address
+= read_2_bytes (abfd
, line_ptr
);
10685 /* Unknown standard opcode, ignore it. */
10688 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
10690 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10691 line_ptr
+= bytes_read
;
10696 if (lh
->num_file_names
< file
|| file
== 0)
10697 dwarf2_debug_line_missing_file_complaint ();
10700 lh
->file_names
[file
- 1].included_p
= 1;
10701 if (!decode_for_pst_p
)
10703 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10704 (*p_record_line
) (current_subfile
, 0, addr
);
10709 if (decode_for_pst_p
)
10713 /* Now that we're done scanning the Line Header Program, we can
10714 create the psymtab of each included file. */
10715 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
10716 if (lh
->file_names
[file_index
].included_p
== 1)
10718 char *include_name
=
10719 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
10720 if (include_name
!= NULL
)
10721 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
10726 /* Make sure a symtab is created for every file, even files
10727 which contain only variables (i.e. no code with associated
10731 struct file_entry
*fe
;
10733 for (i
= 0; i
< lh
->num_file_names
; i
++)
10737 fe
= &lh
->file_names
[i
];
10739 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10740 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10742 /* Skip the main file; we don't need it, and it must be
10743 allocated last, so that it will show up before the
10744 non-primary symtabs in the objfile's symtab list. */
10745 if (current_subfile
== first_subfile
)
10748 if (current_subfile
->symtab
== NULL
)
10749 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
10751 fe
->symtab
= current_subfile
->symtab
;
10756 /* Start a subfile for DWARF. FILENAME is the name of the file and
10757 DIRNAME the name of the source directory which contains FILENAME
10758 or NULL if not known. COMP_DIR is the compilation directory for the
10759 linetable's compilation unit or NULL if not known.
10760 This routine tries to keep line numbers from identical absolute and
10761 relative file names in a common subfile.
10763 Using the `list' example from the GDB testsuite, which resides in
10764 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10765 of /srcdir/list0.c yields the following debugging information for list0.c:
10767 DW_AT_name: /srcdir/list0.c
10768 DW_AT_comp_dir: /compdir
10769 files.files[0].name: list0.h
10770 files.files[0].dir: /srcdir
10771 files.files[1].name: list0.c
10772 files.files[1].dir: /srcdir
10774 The line number information for list0.c has to end up in a single
10775 subfile, so that `break /srcdir/list0.c:1' works as expected.
10776 start_subfile will ensure that this happens provided that we pass the
10777 concatenation of files.files[1].dir and files.files[1].name as the
10781 dwarf2_start_subfile (char *filename
, const char *dirname
,
10782 const char *comp_dir
)
10786 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10787 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10788 second argument to start_subfile. To be consistent, we do the
10789 same here. In order not to lose the line information directory,
10790 we concatenate it to the filename when it makes sense.
10791 Note that the Dwarf3 standard says (speaking of filenames in line
10792 information): ``The directory index is ignored for file names
10793 that represent full path names''. Thus ignoring dirname in the
10794 `else' branch below isn't an issue. */
10796 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
10797 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
10799 fullname
= filename
;
10801 start_subfile (fullname
, comp_dir
);
10803 if (fullname
!= filename
)
10808 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
10809 struct dwarf2_cu
*cu
)
10811 struct objfile
*objfile
= cu
->objfile
;
10812 struct comp_unit_head
*cu_header
= &cu
->header
;
10814 /* NOTE drow/2003-01-30: There used to be a comment and some special
10815 code here to turn a symbol with DW_AT_external and a
10816 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10817 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10818 with some versions of binutils) where shared libraries could have
10819 relocations against symbols in their debug information - the
10820 minimal symbol would have the right address, but the debug info
10821 would not. It's no longer necessary, because we will explicitly
10822 apply relocations when we read in the debug information now. */
10824 /* A DW_AT_location attribute with no contents indicates that a
10825 variable has been optimized away. */
10826 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
10828 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10832 /* Handle one degenerate form of location expression specially, to
10833 preserve GDB's previous behavior when section offsets are
10834 specified. If this is just a DW_OP_addr then mark this symbol
10837 if (attr_form_is_block (attr
)
10838 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
10839 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
10841 unsigned int dummy
;
10843 SYMBOL_VALUE_ADDRESS (sym
) =
10844 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
10845 SYMBOL_CLASS (sym
) = LOC_STATIC
;
10846 fixup_symbol_section (sym
, objfile
);
10847 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
10848 SYMBOL_SECTION (sym
));
10852 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
10853 expression evaluator, and use LOC_COMPUTED only when necessary
10854 (i.e. when the value of a register or memory location is
10855 referenced, or a thread-local block, etc.). Then again, it might
10856 not be worthwhile. I'm assuming that it isn't unless performance
10857 or memory numbers show me otherwise. */
10859 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
10860 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10863 /* Given a pointer to a DWARF information entry, figure out if we need
10864 to make a symbol table entry for it, and if so, create a new entry
10865 and return a pointer to it.
10866 If TYPE is NULL, determine symbol type from the die, otherwise
10867 used the passed type.
10868 If SPACE is not NULL, use it to hold the new symbol. If it is
10869 NULL, allocate a new symbol on the objfile's obstack. */
10871 static struct symbol
*
10872 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
10873 struct symbol
*space
)
10875 struct objfile
*objfile
= cu
->objfile
;
10876 struct symbol
*sym
= NULL
;
10878 struct attribute
*attr
= NULL
;
10879 struct attribute
*attr2
= NULL
;
10880 CORE_ADDR baseaddr
;
10881 struct pending
**list_to_add
= NULL
;
10883 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10885 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10887 name
= dwarf2_name (die
, cu
);
10890 const char *linkagename
;
10891 int suppress_add
= 0;
10896 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
10897 OBJSTAT (objfile
, n_syms
++);
10899 /* Cache this symbol's name and the name's demangled form (if any). */
10900 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
10901 linkagename
= dwarf2_physname (name
, die
, cu
);
10902 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
10904 /* Fortran does not have mangling standard and the mangling does differ
10905 between gfortran, iFort etc. */
10906 if (cu
->language
== language_fortran
10907 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
10908 symbol_set_demangled_name (&(sym
->ginfo
),
10909 (char *) dwarf2_full_name (name
, die
, cu
),
10912 /* Default assumptions.
10913 Use the passed type or decode it from the die. */
10914 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10915 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10917 SYMBOL_TYPE (sym
) = type
;
10919 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
10920 attr
= dwarf2_attr (die
,
10921 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
10925 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
10928 attr
= dwarf2_attr (die
,
10929 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
10933 int file_index
= DW_UNSND (attr
);
10935 if (cu
->line_header
== NULL
10936 || file_index
> cu
->line_header
->num_file_names
)
10937 complaint (&symfile_complaints
,
10938 _("file index out of range"));
10939 else if (file_index
> 0)
10941 struct file_entry
*fe
;
10943 fe
= &cu
->line_header
->file_names
[file_index
- 1];
10944 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
10951 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10954 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
10956 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
10957 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
10958 SYMBOL_CLASS (sym
) = LOC_LABEL
;
10959 add_symbol_to_list (sym
, cu
->list_in_scope
);
10961 case DW_TAG_subprogram
:
10962 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10964 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10965 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10966 if ((attr2
&& (DW_UNSND (attr2
) != 0))
10967 || cu
->language
== language_ada
)
10969 /* Subprograms marked external are stored as a global symbol.
10970 Ada subprograms, whether marked external or not, are always
10971 stored as a global symbol, because we want to be able to
10972 access them globally. For instance, we want to be able
10973 to break on a nested subprogram without having to
10974 specify the context. */
10975 list_to_add
= &global_symbols
;
10979 list_to_add
= cu
->list_in_scope
;
10982 case DW_TAG_inlined_subroutine
:
10983 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10985 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10986 SYMBOL_INLINED (sym
) = 1;
10987 /* Do not add the symbol to any lists. It will be found via
10988 BLOCK_FUNCTION from the blockvector. */
10990 case DW_TAG_template_value_param
:
10992 /* Fall through. */
10993 case DW_TAG_constant
:
10994 case DW_TAG_variable
:
10995 case DW_TAG_member
:
10996 /* Compilation with minimal debug info may result in
10997 variables with missing type entries. Change the
10998 misleading `void' type to something sensible. */
10999 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11001 = objfile_type (objfile
)->nodebug_data_symbol
;
11003 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11004 /* In the case of DW_TAG_member, we should only be called for
11005 static const members. */
11006 if (die
->tag
== DW_TAG_member
)
11008 /* dwarf2_add_field uses die_is_declaration,
11009 so we do the same. */
11010 gdb_assert (die_is_declaration (die
, cu
));
11015 dwarf2_const_value (attr
, sym
, cu
);
11016 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11019 if (attr2
&& (DW_UNSND (attr2
) != 0))
11020 list_to_add
= &global_symbols
;
11022 list_to_add
= cu
->list_in_scope
;
11026 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11029 var_decode_location (attr
, sym
, cu
);
11030 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11031 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11032 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11033 && !dwarf2_per_objfile
->has_section_at_zero
)
11035 /* When a static variable is eliminated by the linker,
11036 the corresponding debug information is not stripped
11037 out, but the variable address is set to null;
11038 do not add such variables into symbol table. */
11040 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11042 /* Workaround gfortran PR debug/40040 - it uses
11043 DW_AT_location for variables in -fPIC libraries which may
11044 get overriden by other libraries/executable and get
11045 a different address. Resolve it by the minimal symbol
11046 which may come from inferior's executable using copy
11047 relocation. Make this workaround only for gfortran as for
11048 other compilers GDB cannot guess the minimal symbol
11049 Fortran mangling kind. */
11050 if (cu
->language
== language_fortran
&& die
->parent
11051 && die
->parent
->tag
== DW_TAG_module
11053 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11054 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11056 /* A variable with DW_AT_external is never static,
11057 but it may be block-scoped. */
11058 list_to_add
= (cu
->list_in_scope
== &file_symbols
11059 ? &global_symbols
: cu
->list_in_scope
);
11062 list_to_add
= cu
->list_in_scope
;
11066 /* We do not know the address of this symbol.
11067 If it is an external symbol and we have type information
11068 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11069 The address of the variable will then be determined from
11070 the minimal symbol table whenever the variable is
11072 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11073 if (attr2
&& (DW_UNSND (attr2
) != 0)
11074 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11076 /* A variable with DW_AT_external is never static, but it
11077 may be block-scoped. */
11078 list_to_add
= (cu
->list_in_scope
== &file_symbols
11079 ? &global_symbols
: cu
->list_in_scope
);
11081 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11083 else if (!die_is_declaration (die
, cu
))
11085 /* Use the default LOC_OPTIMIZED_OUT class. */
11086 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11088 list_to_add
= cu
->list_in_scope
;
11092 case DW_TAG_formal_parameter
:
11093 /* If we are inside a function, mark this as an argument. If
11094 not, we might be looking at an argument to an inlined function
11095 when we do not have enough information to show inlined frames;
11096 pretend it's a local variable in that case so that the user can
11098 if (context_stack_depth
> 0
11099 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11100 SYMBOL_IS_ARGUMENT (sym
) = 1;
11101 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11104 var_decode_location (attr
, sym
, cu
);
11106 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11109 dwarf2_const_value (attr
, sym
, cu
);
11111 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
11112 if (attr
&& DW_UNSND (attr
))
11114 struct type
*ref_type
;
11116 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
11117 SYMBOL_TYPE (sym
) = ref_type
;
11120 list_to_add
= cu
->list_in_scope
;
11122 case DW_TAG_unspecified_parameters
:
11123 /* From varargs functions; gdb doesn't seem to have any
11124 interest in this information, so just ignore it for now.
11127 case DW_TAG_template_type_param
:
11129 /* Fall through. */
11130 case DW_TAG_class_type
:
11131 case DW_TAG_interface_type
:
11132 case DW_TAG_structure_type
:
11133 case DW_TAG_union_type
:
11134 case DW_TAG_set_type
:
11135 case DW_TAG_enumeration_type
:
11136 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11137 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11140 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11141 really ever be static objects: otherwise, if you try
11142 to, say, break of a class's method and you're in a file
11143 which doesn't mention that class, it won't work unless
11144 the check for all static symbols in lookup_symbol_aux
11145 saves you. See the OtherFileClass tests in
11146 gdb.c++/namespace.exp. */
11150 list_to_add
= (cu
->list_in_scope
== &file_symbols
11151 && (cu
->language
== language_cplus
11152 || cu
->language
== language_java
)
11153 ? &global_symbols
: cu
->list_in_scope
);
11155 /* The semantics of C++ state that "struct foo {
11156 ... }" also defines a typedef for "foo". A Java
11157 class declaration also defines a typedef for the
11159 if (cu
->language
== language_cplus
11160 || cu
->language
== language_java
11161 || cu
->language
== language_ada
)
11163 /* The symbol's name is already allocated along
11164 with this objfile, so we don't need to
11165 duplicate it for the type. */
11166 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11167 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11172 case DW_TAG_typedef
:
11173 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11174 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11175 list_to_add
= cu
->list_in_scope
;
11177 case DW_TAG_base_type
:
11178 case DW_TAG_subrange_type
:
11179 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11180 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11181 list_to_add
= cu
->list_in_scope
;
11183 case DW_TAG_enumerator
:
11184 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11187 dwarf2_const_value (attr
, sym
, cu
);
11190 /* NOTE: carlton/2003-11-10: See comment above in the
11191 DW_TAG_class_type, etc. block. */
11193 list_to_add
= (cu
->list_in_scope
== &file_symbols
11194 && (cu
->language
== language_cplus
11195 || cu
->language
== language_java
)
11196 ? &global_symbols
: cu
->list_in_scope
);
11199 case DW_TAG_namespace
:
11200 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11201 list_to_add
= &global_symbols
;
11204 /* Not a tag we recognize. Hopefully we aren't processing
11205 trash data, but since we must specifically ignore things
11206 we don't recognize, there is nothing else we should do at
11208 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11209 dwarf_tag_name (die
->tag
));
11215 sym
->hash_next
= objfile
->template_symbols
;
11216 objfile
->template_symbols
= sym
;
11217 list_to_add
= NULL
;
11220 if (list_to_add
!= NULL
)
11221 add_symbol_to_list (sym
, list_to_add
);
11223 /* For the benefit of old versions of GCC, check for anonymous
11224 namespaces based on the demangled name. */
11225 if (!processing_has_namespace_info
11226 && cu
->language
== language_cplus
)
11227 cp_scan_for_anonymous_namespaces (sym
);
11232 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11234 static struct symbol
*
11235 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11237 return new_symbol_full (die
, type
, cu
, NULL
);
11240 /* Given an attr with a DW_FORM_dataN value in host byte order,
11241 zero-extend it as appropriate for the symbol's type. The DWARF
11242 standard (v4) is not entirely clear about the meaning of using
11243 DW_FORM_dataN for a constant with a signed type, where the type is
11244 wider than the data. The conclusion of a discussion on the DWARF
11245 list was that this is unspecified. We choose to always zero-extend
11246 because that is the interpretation long in use by GCC. */
11249 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11250 const char *name
, struct obstack
*obstack
,
11251 struct dwarf2_cu
*cu
, long *value
, int bits
)
11253 struct objfile
*objfile
= cu
->objfile
;
11254 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11255 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11256 LONGEST l
= DW_UNSND (attr
);
11258 if (bits
< sizeof (*value
) * 8)
11260 l
&= ((LONGEST
) 1 << bits
) - 1;
11263 else if (bits
== sizeof (*value
) * 8)
11267 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11268 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11275 /* Read a constant value from an attribute. Either set *VALUE, or if
11276 the value does not fit in *VALUE, set *BYTES - either already
11277 allocated on the objfile obstack, or newly allocated on OBSTACK,
11278 or, set *BATON, if we translated the constant to a location
11282 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11283 const char *name
, struct obstack
*obstack
,
11284 struct dwarf2_cu
*cu
,
11285 long *value
, gdb_byte
**bytes
,
11286 struct dwarf2_locexpr_baton
**baton
)
11288 struct objfile
*objfile
= cu
->objfile
;
11289 struct comp_unit_head
*cu_header
= &cu
->header
;
11290 struct dwarf_block
*blk
;
11291 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
11292 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
11298 switch (attr
->form
)
11304 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
11305 dwarf2_const_value_length_mismatch_complaint (name
,
11306 cu_header
->addr_size
,
11307 TYPE_LENGTH (type
));
11308 /* Symbols of this form are reasonably rare, so we just
11309 piggyback on the existing location code rather than writing
11310 a new implementation of symbol_computed_ops. */
11311 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11312 sizeof (struct dwarf2_locexpr_baton
));
11313 (*baton
)->per_cu
= cu
->per_cu
;
11314 gdb_assert ((*baton
)->per_cu
);
11316 (*baton
)->size
= 2 + cu_header
->addr_size
;
11317 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11318 (*baton
)->data
= data
;
11320 data
[0] = DW_OP_addr
;
11321 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11322 byte_order
, DW_ADDR (attr
));
11323 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11326 case DW_FORM_string
:
11328 /* DW_STRING is already allocated on the objfile obstack, point
11330 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11332 case DW_FORM_block1
:
11333 case DW_FORM_block2
:
11334 case DW_FORM_block4
:
11335 case DW_FORM_block
:
11336 case DW_FORM_exprloc
:
11337 blk
= DW_BLOCK (attr
);
11338 if (TYPE_LENGTH (type
) != blk
->size
)
11339 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11340 TYPE_LENGTH (type
));
11341 *bytes
= blk
->data
;
11344 /* The DW_AT_const_value attributes are supposed to carry the
11345 symbol's value "represented as it would be on the target
11346 architecture." By the time we get here, it's already been
11347 converted to host endianness, so we just need to sign- or
11348 zero-extend it as appropriate. */
11349 case DW_FORM_data1
:
11350 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11351 obstack
, cu
, value
, 8);
11353 case DW_FORM_data2
:
11354 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11355 obstack
, cu
, value
, 16);
11357 case DW_FORM_data4
:
11358 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11359 obstack
, cu
, value
, 32);
11361 case DW_FORM_data8
:
11362 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11363 obstack
, cu
, value
, 64);
11366 case DW_FORM_sdata
:
11367 *value
= DW_SND (attr
);
11370 case DW_FORM_udata
:
11371 *value
= DW_UNSND (attr
);
11375 complaint (&symfile_complaints
,
11376 _("unsupported const value attribute form: '%s'"),
11377 dwarf_form_name (attr
->form
));
11384 /* Copy constant value from an attribute to a symbol. */
11387 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11388 struct dwarf2_cu
*cu
)
11390 struct objfile
*objfile
= cu
->objfile
;
11391 struct comp_unit_head
*cu_header
= &cu
->header
;
11394 struct dwarf2_locexpr_baton
*baton
;
11396 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11397 SYMBOL_PRINT_NAME (sym
),
11398 &objfile
->objfile_obstack
, cu
,
11399 &value
, &bytes
, &baton
);
11403 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11404 SYMBOL_LOCATION_BATON (sym
) = baton
;
11405 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11407 else if (bytes
!= NULL
)
11409 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11410 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11414 SYMBOL_VALUE (sym
) = value
;
11415 SYMBOL_CLASS (sym
) = LOC_CONST
;
11419 /* Return the type of the die in question using its DW_AT_type attribute. */
11421 static struct type
*
11422 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11424 struct attribute
*type_attr
;
11426 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11429 /* A missing DW_AT_type represents a void type. */
11430 return objfile_type (cu
->objfile
)->builtin_void
;
11433 return lookup_die_type (die
, type_attr
, cu
);
11436 /* True iff CU's producer generates GNAT Ada auxiliary information
11437 that allows to find parallel types through that information instead
11438 of having to do expensive parallel lookups by type name. */
11441 need_gnat_info (struct dwarf2_cu
*cu
)
11443 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11444 of GNAT produces this auxiliary information, without any indication
11445 that it is produced. Part of enhancing the FSF version of GNAT
11446 to produce that information will be to put in place an indicator
11447 that we can use in order to determine whether the descriptive type
11448 info is available or not. One suggestion that has been made is
11449 to use a new attribute, attached to the CU die. For now, assume
11450 that the descriptive type info is not available. */
11454 /* Return the auxiliary type of the die in question using its
11455 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11456 attribute is not present. */
11458 static struct type
*
11459 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11461 struct attribute
*type_attr
;
11463 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11467 return lookup_die_type (die
, type_attr
, cu
);
11470 /* If DIE has a descriptive_type attribute, then set the TYPE's
11471 descriptive type accordingly. */
11474 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11475 struct dwarf2_cu
*cu
)
11477 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11479 if (descriptive_type
)
11481 ALLOCATE_GNAT_AUX_TYPE (type
);
11482 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11486 /* Return the containing type of the die in question using its
11487 DW_AT_containing_type attribute. */
11489 static struct type
*
11490 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11492 struct attribute
*type_attr
;
11494 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11496 error (_("Dwarf Error: Problem turning containing type into gdb type "
11497 "[in module %s]"), cu
->objfile
->name
);
11499 return lookup_die_type (die
, type_attr
, cu
);
11502 /* Look up the type of DIE in CU using its type attribute ATTR.
11503 If there is no type substitute an error marker. */
11505 static struct type
*
11506 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11507 struct dwarf2_cu
*cu
)
11509 struct type
*this_type
;
11511 /* First see if we have it cached. */
11513 if (is_ref_attr (attr
))
11515 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11517 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11519 else if (attr
->form
== DW_FORM_ref_sig8
)
11521 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11522 struct dwarf2_cu
*sig_cu
;
11523 unsigned int offset
;
11525 /* sig_type will be NULL if the signatured type is missing from
11527 if (sig_type
== NULL
)
11528 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11529 "at 0x%x [in module %s]"),
11530 die
->offset
, cu
->objfile
->name
);
11532 gdb_assert (sig_type
->per_cu
.from_debug_types
);
11533 offset
= sig_type
->offset
+ sig_type
->type_offset
;
11534 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11538 dump_die_for_error (die
);
11539 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11540 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11543 /* If not cached we need to read it in. */
11545 if (this_type
== NULL
)
11547 struct die_info
*type_die
;
11548 struct dwarf2_cu
*type_cu
= cu
;
11550 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11551 /* If the type is cached, we should have found it above. */
11552 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
11553 this_type
= read_type_die_1 (type_die
, type_cu
);
11556 /* If we still don't have a type use an error marker. */
11558 if (this_type
== NULL
)
11560 char *message
, *saved
;
11562 /* read_type_die already issued a complaint. */
11563 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11567 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
11568 message
, strlen (message
));
11571 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
11577 /* Return the type in DIE, CU.
11578 Returns NULL for invalid types.
11580 This first does a lookup in the appropriate type_hash table,
11581 and only reads the die in if necessary.
11583 NOTE: This can be called when reading in partial or full symbols. */
11585 static struct type
*
11586 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11588 struct type
*this_type
;
11590 this_type
= get_die_type (die
, cu
);
11594 return read_type_die_1 (die
, cu
);
11597 /* Read the type in DIE, CU.
11598 Returns NULL for invalid types. */
11600 static struct type
*
11601 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
11603 struct type
*this_type
= NULL
;
11607 case DW_TAG_class_type
:
11608 case DW_TAG_interface_type
:
11609 case DW_TAG_structure_type
:
11610 case DW_TAG_union_type
:
11611 this_type
= read_structure_type (die
, cu
);
11613 case DW_TAG_enumeration_type
:
11614 this_type
= read_enumeration_type (die
, cu
);
11616 case DW_TAG_subprogram
:
11617 case DW_TAG_subroutine_type
:
11618 case DW_TAG_inlined_subroutine
:
11619 this_type
= read_subroutine_type (die
, cu
);
11621 case DW_TAG_array_type
:
11622 this_type
= read_array_type (die
, cu
);
11624 case DW_TAG_set_type
:
11625 this_type
= read_set_type (die
, cu
);
11627 case DW_TAG_pointer_type
:
11628 this_type
= read_tag_pointer_type (die
, cu
);
11630 case DW_TAG_ptr_to_member_type
:
11631 this_type
= read_tag_ptr_to_member_type (die
, cu
);
11633 case DW_TAG_reference_type
:
11634 this_type
= read_tag_reference_type (die
, cu
);
11636 case DW_TAG_const_type
:
11637 this_type
= read_tag_const_type (die
, cu
);
11639 case DW_TAG_volatile_type
:
11640 this_type
= read_tag_volatile_type (die
, cu
);
11642 case DW_TAG_string_type
:
11643 this_type
= read_tag_string_type (die
, cu
);
11645 case DW_TAG_typedef
:
11646 this_type
= read_typedef (die
, cu
);
11648 case DW_TAG_subrange_type
:
11649 this_type
= read_subrange_type (die
, cu
);
11651 case DW_TAG_base_type
:
11652 this_type
= read_base_type (die
, cu
);
11654 case DW_TAG_unspecified_type
:
11655 this_type
= read_unspecified_type (die
, cu
);
11657 case DW_TAG_namespace
:
11658 this_type
= read_namespace_type (die
, cu
);
11660 case DW_TAG_module
:
11661 this_type
= read_module_type (die
, cu
);
11664 complaint (&symfile_complaints
,
11665 _("unexpected tag in read_type_die: '%s'"),
11666 dwarf_tag_name (die
->tag
));
11673 /* See if we can figure out if the class lives in a namespace. We do
11674 this by looking for a member function; its demangled name will
11675 contain namespace info, if there is any.
11676 Return the computed name or NULL.
11677 Space for the result is allocated on the objfile's obstack.
11678 This is the full-die version of guess_partial_die_structure_name.
11679 In this case we know DIE has no useful parent. */
11682 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11684 struct die_info
*spec_die
;
11685 struct dwarf2_cu
*spec_cu
;
11686 struct die_info
*child
;
11689 spec_die
= die_specification (die
, &spec_cu
);
11690 if (spec_die
!= NULL
)
11696 for (child
= die
->child
;
11698 child
= child
->sibling
)
11700 if (child
->tag
== DW_TAG_subprogram
)
11702 struct attribute
*attr
;
11704 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
11706 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
11710 = language_class_name_from_physname (cu
->language_defn
,
11714 if (actual_name
!= NULL
)
11716 char *die_name
= dwarf2_name (die
, cu
);
11718 if (die_name
!= NULL
11719 && strcmp (die_name
, actual_name
) != 0)
11721 /* Strip off the class name from the full name.
11722 We want the prefix. */
11723 int die_name_len
= strlen (die_name
);
11724 int actual_name_len
= strlen (actual_name
);
11726 /* Test for '::' as a sanity check. */
11727 if (actual_name_len
> die_name_len
+ 2
11728 && actual_name
[actual_name_len
11729 - die_name_len
- 1] == ':')
11731 obsavestring (actual_name
,
11732 actual_name_len
- die_name_len
- 2,
11733 &cu
->objfile
->objfile_obstack
);
11736 xfree (actual_name
);
11745 /* Return the name of the namespace/class that DIE is defined within,
11746 or "" if we can't tell. The caller should not xfree the result.
11748 For example, if we're within the method foo() in the following
11758 then determine_prefix on foo's die will return "N::C". */
11761 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
11763 struct die_info
*parent
, *spec_die
;
11764 struct dwarf2_cu
*spec_cu
;
11765 struct type
*parent_type
;
11767 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
11768 && cu
->language
!= language_fortran
)
11771 /* We have to be careful in the presence of DW_AT_specification.
11772 For example, with GCC 3.4, given the code
11776 // Definition of N::foo.
11780 then we'll have a tree of DIEs like this:
11782 1: DW_TAG_compile_unit
11783 2: DW_TAG_namespace // N
11784 3: DW_TAG_subprogram // declaration of N::foo
11785 4: DW_TAG_subprogram // definition of N::foo
11786 DW_AT_specification // refers to die #3
11788 Thus, when processing die #4, we have to pretend that we're in
11789 the context of its DW_AT_specification, namely the contex of die
11792 spec_die
= die_specification (die
, &spec_cu
);
11793 if (spec_die
== NULL
)
11794 parent
= die
->parent
;
11797 parent
= spec_die
->parent
;
11801 if (parent
== NULL
)
11803 else if (parent
->building_fullname
)
11806 const char *parent_name
;
11808 /* It has been seen on RealView 2.2 built binaries,
11809 DW_TAG_template_type_param types actually _defined_ as
11810 children of the parent class:
11813 template class <class Enum> Class{};
11814 Class<enum E> class_e;
11816 1: DW_TAG_class_type (Class)
11817 2: DW_TAG_enumeration_type (E)
11818 3: DW_TAG_enumerator (enum1:0)
11819 3: DW_TAG_enumerator (enum2:1)
11821 2: DW_TAG_template_type_param
11822 DW_AT_type DW_FORM_ref_udata (E)
11824 Besides being broken debug info, it can put GDB into an
11825 infinite loop. Consider:
11827 When we're building the full name for Class<E>, we'll start
11828 at Class, and go look over its template type parameters,
11829 finding E. We'll then try to build the full name of E, and
11830 reach here. We're now trying to build the full name of E,
11831 and look over the parent DIE for containing scope. In the
11832 broken case, if we followed the parent DIE of E, we'd again
11833 find Class, and once again go look at its template type
11834 arguments, etc., etc. Simply don't consider such parent die
11835 as source-level parent of this die (it can't be, the language
11836 doesn't allow it), and break the loop here. */
11837 name
= dwarf2_name (die
, cu
);
11838 parent_name
= dwarf2_name (parent
, cu
);
11839 complaint (&symfile_complaints
,
11840 _("template param type '%s' defined within parent '%s'"),
11841 name
? name
: "<unknown>",
11842 parent_name
? parent_name
: "<unknown>");
11846 switch (parent
->tag
)
11848 case DW_TAG_namespace
:
11849 parent_type
= read_type_die (parent
, cu
);
11850 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
11851 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
11852 Work around this problem here. */
11853 if (cu
->language
== language_cplus
11854 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
11856 /* We give a name to even anonymous namespaces. */
11857 return TYPE_TAG_NAME (parent_type
);
11858 case DW_TAG_class_type
:
11859 case DW_TAG_interface_type
:
11860 case DW_TAG_structure_type
:
11861 case DW_TAG_union_type
:
11862 case DW_TAG_module
:
11863 parent_type
= read_type_die (parent
, cu
);
11864 if (TYPE_TAG_NAME (parent_type
) != NULL
)
11865 return TYPE_TAG_NAME (parent_type
);
11867 /* An anonymous structure is only allowed non-static data
11868 members; no typedefs, no member functions, et cetera.
11869 So it does not need a prefix. */
11871 case DW_TAG_compile_unit
:
11872 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
11873 if (cu
->language
== language_cplus
11874 && dwarf2_per_objfile
->types
.asection
!= NULL
11875 && die
->child
!= NULL
11876 && (die
->tag
== DW_TAG_class_type
11877 || die
->tag
== DW_TAG_structure_type
11878 || die
->tag
== DW_TAG_union_type
))
11880 char *name
= guess_full_die_structure_name (die
, cu
);
11886 return determine_prefix (parent
, cu
);
11890 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
11891 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
11892 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
11893 an obconcat, otherwise allocate storage for the result. The CU argument is
11894 used to determine the language and hence, the appropriate separator. */
11896 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
11899 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
11900 int physname
, struct dwarf2_cu
*cu
)
11902 const char *lead
= "";
11905 if (suffix
== NULL
|| suffix
[0] == '\0'
11906 || prefix
== NULL
|| prefix
[0] == '\0')
11908 else if (cu
->language
== language_java
)
11910 else if (cu
->language
== language_fortran
&& physname
)
11912 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
11913 DW_AT_MIPS_linkage_name is preferred and used instead. */
11921 if (prefix
== NULL
)
11923 if (suffix
== NULL
)
11929 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
11931 strcpy (retval
, lead
);
11932 strcat (retval
, prefix
);
11933 strcat (retval
, sep
);
11934 strcat (retval
, suffix
);
11939 /* We have an obstack. */
11940 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
11944 /* Return sibling of die, NULL if no sibling. */
11946 static struct die_info
*
11947 sibling_die (struct die_info
*die
)
11949 return die
->sibling
;
11952 /* Get name of a die, return NULL if not found. */
11955 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
11956 struct obstack
*obstack
)
11958 if (name
&& cu
->language
== language_cplus
)
11960 char *canon_name
= cp_canonicalize_string (name
);
11962 if (canon_name
!= NULL
)
11964 if (strcmp (canon_name
, name
) != 0)
11965 name
= obsavestring (canon_name
, strlen (canon_name
),
11967 xfree (canon_name
);
11974 /* Get name of a die, return NULL if not found. */
11977 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11979 struct attribute
*attr
;
11981 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11982 if ((!attr
|| !DW_STRING (attr
))
11983 && die
->tag
!= DW_TAG_class_type
11984 && die
->tag
!= DW_TAG_interface_type
11985 && die
->tag
!= DW_TAG_structure_type
11986 && die
->tag
!= DW_TAG_union_type
)
11991 case DW_TAG_compile_unit
:
11992 /* Compilation units have a DW_AT_name that is a filename, not
11993 a source language identifier. */
11994 case DW_TAG_enumeration_type
:
11995 case DW_TAG_enumerator
:
11996 /* These tags always have simple identifiers already; no need
11997 to canonicalize them. */
11998 return DW_STRING (attr
);
12000 case DW_TAG_subprogram
:
12001 /* Java constructors will all be named "<init>", so return
12002 the class name when we see this special case. */
12003 if (cu
->language
== language_java
12004 && DW_STRING (attr
) != NULL
12005 && strcmp (DW_STRING (attr
), "<init>") == 0)
12007 struct dwarf2_cu
*spec_cu
= cu
;
12008 struct die_info
*spec_die
;
12010 /* GCJ will output '<init>' for Java constructor names.
12011 For this special case, return the name of the parent class. */
12013 /* GCJ may output suprogram DIEs with AT_specification set.
12014 If so, use the name of the specified DIE. */
12015 spec_die
= die_specification (die
, &spec_cu
);
12016 if (spec_die
!= NULL
)
12017 return dwarf2_name (spec_die
, spec_cu
);
12022 if (die
->tag
== DW_TAG_class_type
)
12023 return dwarf2_name (die
, cu
);
12025 while (die
->tag
!= DW_TAG_compile_unit
);
12029 case DW_TAG_class_type
:
12030 case DW_TAG_interface_type
:
12031 case DW_TAG_structure_type
:
12032 case DW_TAG_union_type
:
12033 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12034 structures or unions. These were of the form "._%d" in GCC 4.1,
12035 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12036 and GCC 4.4. We work around this problem by ignoring these. */
12037 if (attr
&& DW_STRING (attr
)
12038 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12039 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12042 /* GCC might emit a nameless typedef that has a linkage name. See
12043 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12044 if (!attr
|| DW_STRING (attr
) == NULL
)
12048 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12050 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12052 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12055 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12059 /* FIXME: we already did this for the partial symbol... */
12061 = obsavestring (demangled
, strlen (demangled
),
12062 &cu
->objfile
->objfile_obstack
);
12063 DW_STRING_IS_CANONICAL (attr
) = 1;
12073 if (!DW_STRING_IS_CANONICAL (attr
))
12076 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12077 &cu
->objfile
->objfile_obstack
);
12078 DW_STRING_IS_CANONICAL (attr
) = 1;
12080 return DW_STRING (attr
);
12083 /* Return the die that this die in an extension of, or NULL if there
12084 is none. *EXT_CU is the CU containing DIE on input, and the CU
12085 containing the return value on output. */
12087 static struct die_info
*
12088 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12090 struct attribute
*attr
;
12092 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12096 return follow_die_ref (die
, attr
, ext_cu
);
12099 /* Convert a DIE tag into its string name. */
12102 dwarf_tag_name (unsigned tag
)
12106 case DW_TAG_padding
:
12107 return "DW_TAG_padding";
12108 case DW_TAG_array_type
:
12109 return "DW_TAG_array_type";
12110 case DW_TAG_class_type
:
12111 return "DW_TAG_class_type";
12112 case DW_TAG_entry_point
:
12113 return "DW_TAG_entry_point";
12114 case DW_TAG_enumeration_type
:
12115 return "DW_TAG_enumeration_type";
12116 case DW_TAG_formal_parameter
:
12117 return "DW_TAG_formal_parameter";
12118 case DW_TAG_imported_declaration
:
12119 return "DW_TAG_imported_declaration";
12121 return "DW_TAG_label";
12122 case DW_TAG_lexical_block
:
12123 return "DW_TAG_lexical_block";
12124 case DW_TAG_member
:
12125 return "DW_TAG_member";
12126 case DW_TAG_pointer_type
:
12127 return "DW_TAG_pointer_type";
12128 case DW_TAG_reference_type
:
12129 return "DW_TAG_reference_type";
12130 case DW_TAG_compile_unit
:
12131 return "DW_TAG_compile_unit";
12132 case DW_TAG_string_type
:
12133 return "DW_TAG_string_type";
12134 case DW_TAG_structure_type
:
12135 return "DW_TAG_structure_type";
12136 case DW_TAG_subroutine_type
:
12137 return "DW_TAG_subroutine_type";
12138 case DW_TAG_typedef
:
12139 return "DW_TAG_typedef";
12140 case DW_TAG_union_type
:
12141 return "DW_TAG_union_type";
12142 case DW_TAG_unspecified_parameters
:
12143 return "DW_TAG_unspecified_parameters";
12144 case DW_TAG_variant
:
12145 return "DW_TAG_variant";
12146 case DW_TAG_common_block
:
12147 return "DW_TAG_common_block";
12148 case DW_TAG_common_inclusion
:
12149 return "DW_TAG_common_inclusion";
12150 case DW_TAG_inheritance
:
12151 return "DW_TAG_inheritance";
12152 case DW_TAG_inlined_subroutine
:
12153 return "DW_TAG_inlined_subroutine";
12154 case DW_TAG_module
:
12155 return "DW_TAG_module";
12156 case DW_TAG_ptr_to_member_type
:
12157 return "DW_TAG_ptr_to_member_type";
12158 case DW_TAG_set_type
:
12159 return "DW_TAG_set_type";
12160 case DW_TAG_subrange_type
:
12161 return "DW_TAG_subrange_type";
12162 case DW_TAG_with_stmt
:
12163 return "DW_TAG_with_stmt";
12164 case DW_TAG_access_declaration
:
12165 return "DW_TAG_access_declaration";
12166 case DW_TAG_base_type
:
12167 return "DW_TAG_base_type";
12168 case DW_TAG_catch_block
:
12169 return "DW_TAG_catch_block";
12170 case DW_TAG_const_type
:
12171 return "DW_TAG_const_type";
12172 case DW_TAG_constant
:
12173 return "DW_TAG_constant";
12174 case DW_TAG_enumerator
:
12175 return "DW_TAG_enumerator";
12176 case DW_TAG_file_type
:
12177 return "DW_TAG_file_type";
12178 case DW_TAG_friend
:
12179 return "DW_TAG_friend";
12180 case DW_TAG_namelist
:
12181 return "DW_TAG_namelist";
12182 case DW_TAG_namelist_item
:
12183 return "DW_TAG_namelist_item";
12184 case DW_TAG_packed_type
:
12185 return "DW_TAG_packed_type";
12186 case DW_TAG_subprogram
:
12187 return "DW_TAG_subprogram";
12188 case DW_TAG_template_type_param
:
12189 return "DW_TAG_template_type_param";
12190 case DW_TAG_template_value_param
:
12191 return "DW_TAG_template_value_param";
12192 case DW_TAG_thrown_type
:
12193 return "DW_TAG_thrown_type";
12194 case DW_TAG_try_block
:
12195 return "DW_TAG_try_block";
12196 case DW_TAG_variant_part
:
12197 return "DW_TAG_variant_part";
12198 case DW_TAG_variable
:
12199 return "DW_TAG_variable";
12200 case DW_TAG_volatile_type
:
12201 return "DW_TAG_volatile_type";
12202 case DW_TAG_dwarf_procedure
:
12203 return "DW_TAG_dwarf_procedure";
12204 case DW_TAG_restrict_type
:
12205 return "DW_TAG_restrict_type";
12206 case DW_TAG_interface_type
:
12207 return "DW_TAG_interface_type";
12208 case DW_TAG_namespace
:
12209 return "DW_TAG_namespace";
12210 case DW_TAG_imported_module
:
12211 return "DW_TAG_imported_module";
12212 case DW_TAG_unspecified_type
:
12213 return "DW_TAG_unspecified_type";
12214 case DW_TAG_partial_unit
:
12215 return "DW_TAG_partial_unit";
12216 case DW_TAG_imported_unit
:
12217 return "DW_TAG_imported_unit";
12218 case DW_TAG_condition
:
12219 return "DW_TAG_condition";
12220 case DW_TAG_shared_type
:
12221 return "DW_TAG_shared_type";
12222 case DW_TAG_type_unit
:
12223 return "DW_TAG_type_unit";
12224 case DW_TAG_MIPS_loop
:
12225 return "DW_TAG_MIPS_loop";
12226 case DW_TAG_HP_array_descriptor
:
12227 return "DW_TAG_HP_array_descriptor";
12228 case DW_TAG_format_label
:
12229 return "DW_TAG_format_label";
12230 case DW_TAG_function_template
:
12231 return "DW_TAG_function_template";
12232 case DW_TAG_class_template
:
12233 return "DW_TAG_class_template";
12234 case DW_TAG_GNU_BINCL
:
12235 return "DW_TAG_GNU_BINCL";
12236 case DW_TAG_GNU_EINCL
:
12237 return "DW_TAG_GNU_EINCL";
12238 case DW_TAG_upc_shared_type
:
12239 return "DW_TAG_upc_shared_type";
12240 case DW_TAG_upc_strict_type
:
12241 return "DW_TAG_upc_strict_type";
12242 case DW_TAG_upc_relaxed_type
:
12243 return "DW_TAG_upc_relaxed_type";
12244 case DW_TAG_PGI_kanji_type
:
12245 return "DW_TAG_PGI_kanji_type";
12246 case DW_TAG_PGI_interface_block
:
12247 return "DW_TAG_PGI_interface_block";
12249 return "DW_TAG_<unknown>";
12253 /* Convert a DWARF attribute code into its string name. */
12256 dwarf_attr_name (unsigned attr
)
12260 case DW_AT_sibling
:
12261 return "DW_AT_sibling";
12262 case DW_AT_location
:
12263 return "DW_AT_location";
12265 return "DW_AT_name";
12266 case DW_AT_ordering
:
12267 return "DW_AT_ordering";
12268 case DW_AT_subscr_data
:
12269 return "DW_AT_subscr_data";
12270 case DW_AT_byte_size
:
12271 return "DW_AT_byte_size";
12272 case DW_AT_bit_offset
:
12273 return "DW_AT_bit_offset";
12274 case DW_AT_bit_size
:
12275 return "DW_AT_bit_size";
12276 case DW_AT_element_list
:
12277 return "DW_AT_element_list";
12278 case DW_AT_stmt_list
:
12279 return "DW_AT_stmt_list";
12281 return "DW_AT_low_pc";
12282 case DW_AT_high_pc
:
12283 return "DW_AT_high_pc";
12284 case DW_AT_language
:
12285 return "DW_AT_language";
12287 return "DW_AT_member";
12289 return "DW_AT_discr";
12290 case DW_AT_discr_value
:
12291 return "DW_AT_discr_value";
12292 case DW_AT_visibility
:
12293 return "DW_AT_visibility";
12295 return "DW_AT_import";
12296 case DW_AT_string_length
:
12297 return "DW_AT_string_length";
12298 case DW_AT_common_reference
:
12299 return "DW_AT_common_reference";
12300 case DW_AT_comp_dir
:
12301 return "DW_AT_comp_dir";
12302 case DW_AT_const_value
:
12303 return "DW_AT_const_value";
12304 case DW_AT_containing_type
:
12305 return "DW_AT_containing_type";
12306 case DW_AT_default_value
:
12307 return "DW_AT_default_value";
12309 return "DW_AT_inline";
12310 case DW_AT_is_optional
:
12311 return "DW_AT_is_optional";
12312 case DW_AT_lower_bound
:
12313 return "DW_AT_lower_bound";
12314 case DW_AT_producer
:
12315 return "DW_AT_producer";
12316 case DW_AT_prototyped
:
12317 return "DW_AT_prototyped";
12318 case DW_AT_return_addr
:
12319 return "DW_AT_return_addr";
12320 case DW_AT_start_scope
:
12321 return "DW_AT_start_scope";
12322 case DW_AT_bit_stride
:
12323 return "DW_AT_bit_stride";
12324 case DW_AT_upper_bound
:
12325 return "DW_AT_upper_bound";
12326 case DW_AT_abstract_origin
:
12327 return "DW_AT_abstract_origin";
12328 case DW_AT_accessibility
:
12329 return "DW_AT_accessibility";
12330 case DW_AT_address_class
:
12331 return "DW_AT_address_class";
12332 case DW_AT_artificial
:
12333 return "DW_AT_artificial";
12334 case DW_AT_base_types
:
12335 return "DW_AT_base_types";
12336 case DW_AT_calling_convention
:
12337 return "DW_AT_calling_convention";
12339 return "DW_AT_count";
12340 case DW_AT_data_member_location
:
12341 return "DW_AT_data_member_location";
12342 case DW_AT_decl_column
:
12343 return "DW_AT_decl_column";
12344 case DW_AT_decl_file
:
12345 return "DW_AT_decl_file";
12346 case DW_AT_decl_line
:
12347 return "DW_AT_decl_line";
12348 case DW_AT_declaration
:
12349 return "DW_AT_declaration";
12350 case DW_AT_discr_list
:
12351 return "DW_AT_discr_list";
12352 case DW_AT_encoding
:
12353 return "DW_AT_encoding";
12354 case DW_AT_external
:
12355 return "DW_AT_external";
12356 case DW_AT_frame_base
:
12357 return "DW_AT_frame_base";
12359 return "DW_AT_friend";
12360 case DW_AT_identifier_case
:
12361 return "DW_AT_identifier_case";
12362 case DW_AT_macro_info
:
12363 return "DW_AT_macro_info";
12364 case DW_AT_namelist_items
:
12365 return "DW_AT_namelist_items";
12366 case DW_AT_priority
:
12367 return "DW_AT_priority";
12368 case DW_AT_segment
:
12369 return "DW_AT_segment";
12370 case DW_AT_specification
:
12371 return "DW_AT_specification";
12372 case DW_AT_static_link
:
12373 return "DW_AT_static_link";
12375 return "DW_AT_type";
12376 case DW_AT_use_location
:
12377 return "DW_AT_use_location";
12378 case DW_AT_variable_parameter
:
12379 return "DW_AT_variable_parameter";
12380 case DW_AT_virtuality
:
12381 return "DW_AT_virtuality";
12382 case DW_AT_vtable_elem_location
:
12383 return "DW_AT_vtable_elem_location";
12384 /* DWARF 3 values. */
12385 case DW_AT_allocated
:
12386 return "DW_AT_allocated";
12387 case DW_AT_associated
:
12388 return "DW_AT_associated";
12389 case DW_AT_data_location
:
12390 return "DW_AT_data_location";
12391 case DW_AT_byte_stride
:
12392 return "DW_AT_byte_stride";
12393 case DW_AT_entry_pc
:
12394 return "DW_AT_entry_pc";
12395 case DW_AT_use_UTF8
:
12396 return "DW_AT_use_UTF8";
12397 case DW_AT_extension
:
12398 return "DW_AT_extension";
12400 return "DW_AT_ranges";
12401 case DW_AT_trampoline
:
12402 return "DW_AT_trampoline";
12403 case DW_AT_call_column
:
12404 return "DW_AT_call_column";
12405 case DW_AT_call_file
:
12406 return "DW_AT_call_file";
12407 case DW_AT_call_line
:
12408 return "DW_AT_call_line";
12409 case DW_AT_description
:
12410 return "DW_AT_description";
12411 case DW_AT_binary_scale
:
12412 return "DW_AT_binary_scale";
12413 case DW_AT_decimal_scale
:
12414 return "DW_AT_decimal_scale";
12416 return "DW_AT_small";
12417 case DW_AT_decimal_sign
:
12418 return "DW_AT_decimal_sign";
12419 case DW_AT_digit_count
:
12420 return "DW_AT_digit_count";
12421 case DW_AT_picture_string
:
12422 return "DW_AT_picture_string";
12423 case DW_AT_mutable
:
12424 return "DW_AT_mutable";
12425 case DW_AT_threads_scaled
:
12426 return "DW_AT_threads_scaled";
12427 case DW_AT_explicit
:
12428 return "DW_AT_explicit";
12429 case DW_AT_object_pointer
:
12430 return "DW_AT_object_pointer";
12431 case DW_AT_endianity
:
12432 return "DW_AT_endianity";
12433 case DW_AT_elemental
:
12434 return "DW_AT_elemental";
12436 return "DW_AT_pure";
12437 case DW_AT_recursive
:
12438 return "DW_AT_recursive";
12439 /* DWARF 4 values. */
12440 case DW_AT_signature
:
12441 return "DW_AT_signature";
12442 case DW_AT_linkage_name
:
12443 return "DW_AT_linkage_name";
12444 /* SGI/MIPS extensions. */
12445 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12446 case DW_AT_MIPS_fde
:
12447 return "DW_AT_MIPS_fde";
12449 case DW_AT_MIPS_loop_begin
:
12450 return "DW_AT_MIPS_loop_begin";
12451 case DW_AT_MIPS_tail_loop_begin
:
12452 return "DW_AT_MIPS_tail_loop_begin";
12453 case DW_AT_MIPS_epilog_begin
:
12454 return "DW_AT_MIPS_epilog_begin";
12455 case DW_AT_MIPS_loop_unroll_factor
:
12456 return "DW_AT_MIPS_loop_unroll_factor";
12457 case DW_AT_MIPS_software_pipeline_depth
:
12458 return "DW_AT_MIPS_software_pipeline_depth";
12459 case DW_AT_MIPS_linkage_name
:
12460 return "DW_AT_MIPS_linkage_name";
12461 case DW_AT_MIPS_stride
:
12462 return "DW_AT_MIPS_stride";
12463 case DW_AT_MIPS_abstract_name
:
12464 return "DW_AT_MIPS_abstract_name";
12465 case DW_AT_MIPS_clone_origin
:
12466 return "DW_AT_MIPS_clone_origin";
12467 case DW_AT_MIPS_has_inlines
:
12468 return "DW_AT_MIPS_has_inlines";
12469 /* HP extensions. */
12470 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12471 case DW_AT_HP_block_index
:
12472 return "DW_AT_HP_block_index";
12474 case DW_AT_HP_unmodifiable
:
12475 return "DW_AT_HP_unmodifiable";
12476 case DW_AT_HP_actuals_stmt_list
:
12477 return "DW_AT_HP_actuals_stmt_list";
12478 case DW_AT_HP_proc_per_section
:
12479 return "DW_AT_HP_proc_per_section";
12480 case DW_AT_HP_raw_data_ptr
:
12481 return "DW_AT_HP_raw_data_ptr";
12482 case DW_AT_HP_pass_by_reference
:
12483 return "DW_AT_HP_pass_by_reference";
12484 case DW_AT_HP_opt_level
:
12485 return "DW_AT_HP_opt_level";
12486 case DW_AT_HP_prof_version_id
:
12487 return "DW_AT_HP_prof_version_id";
12488 case DW_AT_HP_opt_flags
:
12489 return "DW_AT_HP_opt_flags";
12490 case DW_AT_HP_cold_region_low_pc
:
12491 return "DW_AT_HP_cold_region_low_pc";
12492 case DW_AT_HP_cold_region_high_pc
:
12493 return "DW_AT_HP_cold_region_high_pc";
12494 case DW_AT_HP_all_variables_modifiable
:
12495 return "DW_AT_HP_all_variables_modifiable";
12496 case DW_AT_HP_linkage_name
:
12497 return "DW_AT_HP_linkage_name";
12498 case DW_AT_HP_prof_flags
:
12499 return "DW_AT_HP_prof_flags";
12500 /* GNU extensions. */
12501 case DW_AT_sf_names
:
12502 return "DW_AT_sf_names";
12503 case DW_AT_src_info
:
12504 return "DW_AT_src_info";
12505 case DW_AT_mac_info
:
12506 return "DW_AT_mac_info";
12507 case DW_AT_src_coords
:
12508 return "DW_AT_src_coords";
12509 case DW_AT_body_begin
:
12510 return "DW_AT_body_begin";
12511 case DW_AT_body_end
:
12512 return "DW_AT_body_end";
12513 case DW_AT_GNU_vector
:
12514 return "DW_AT_GNU_vector";
12515 case DW_AT_GNU_odr_signature
:
12516 return "DW_AT_GNU_odr_signature";
12517 /* VMS extensions. */
12518 case DW_AT_VMS_rtnbeg_pd_address
:
12519 return "DW_AT_VMS_rtnbeg_pd_address";
12520 /* UPC extension. */
12521 case DW_AT_upc_threads_scaled
:
12522 return "DW_AT_upc_threads_scaled";
12523 /* PGI (STMicroelectronics) extensions. */
12524 case DW_AT_PGI_lbase
:
12525 return "DW_AT_PGI_lbase";
12526 case DW_AT_PGI_soffset
:
12527 return "DW_AT_PGI_soffset";
12528 case DW_AT_PGI_lstride
:
12529 return "DW_AT_PGI_lstride";
12531 return "DW_AT_<unknown>";
12535 /* Convert a DWARF value form code into its string name. */
12538 dwarf_form_name (unsigned form
)
12543 return "DW_FORM_addr";
12544 case DW_FORM_block2
:
12545 return "DW_FORM_block2";
12546 case DW_FORM_block4
:
12547 return "DW_FORM_block4";
12548 case DW_FORM_data2
:
12549 return "DW_FORM_data2";
12550 case DW_FORM_data4
:
12551 return "DW_FORM_data4";
12552 case DW_FORM_data8
:
12553 return "DW_FORM_data8";
12554 case DW_FORM_string
:
12555 return "DW_FORM_string";
12556 case DW_FORM_block
:
12557 return "DW_FORM_block";
12558 case DW_FORM_block1
:
12559 return "DW_FORM_block1";
12560 case DW_FORM_data1
:
12561 return "DW_FORM_data1";
12563 return "DW_FORM_flag";
12564 case DW_FORM_sdata
:
12565 return "DW_FORM_sdata";
12567 return "DW_FORM_strp";
12568 case DW_FORM_udata
:
12569 return "DW_FORM_udata";
12570 case DW_FORM_ref_addr
:
12571 return "DW_FORM_ref_addr";
12573 return "DW_FORM_ref1";
12575 return "DW_FORM_ref2";
12577 return "DW_FORM_ref4";
12579 return "DW_FORM_ref8";
12580 case DW_FORM_ref_udata
:
12581 return "DW_FORM_ref_udata";
12582 case DW_FORM_indirect
:
12583 return "DW_FORM_indirect";
12584 case DW_FORM_sec_offset
:
12585 return "DW_FORM_sec_offset";
12586 case DW_FORM_exprloc
:
12587 return "DW_FORM_exprloc";
12588 case DW_FORM_flag_present
:
12589 return "DW_FORM_flag_present";
12590 case DW_FORM_ref_sig8
:
12591 return "DW_FORM_ref_sig8";
12593 return "DW_FORM_<unknown>";
12597 /* Convert a DWARF stack opcode into its string name. */
12600 dwarf_stack_op_name (unsigned op
)
12605 return "DW_OP_addr";
12607 return "DW_OP_deref";
12608 case DW_OP_const1u
:
12609 return "DW_OP_const1u";
12610 case DW_OP_const1s
:
12611 return "DW_OP_const1s";
12612 case DW_OP_const2u
:
12613 return "DW_OP_const2u";
12614 case DW_OP_const2s
:
12615 return "DW_OP_const2s";
12616 case DW_OP_const4u
:
12617 return "DW_OP_const4u";
12618 case DW_OP_const4s
:
12619 return "DW_OP_const4s";
12620 case DW_OP_const8u
:
12621 return "DW_OP_const8u";
12622 case DW_OP_const8s
:
12623 return "DW_OP_const8s";
12625 return "DW_OP_constu";
12627 return "DW_OP_consts";
12629 return "DW_OP_dup";
12631 return "DW_OP_drop";
12633 return "DW_OP_over";
12635 return "DW_OP_pick";
12637 return "DW_OP_swap";
12639 return "DW_OP_rot";
12641 return "DW_OP_xderef";
12643 return "DW_OP_abs";
12645 return "DW_OP_and";
12647 return "DW_OP_div";
12649 return "DW_OP_minus";
12651 return "DW_OP_mod";
12653 return "DW_OP_mul";
12655 return "DW_OP_neg";
12657 return "DW_OP_not";
12661 return "DW_OP_plus";
12662 case DW_OP_plus_uconst
:
12663 return "DW_OP_plus_uconst";
12665 return "DW_OP_shl";
12667 return "DW_OP_shr";
12669 return "DW_OP_shra";
12671 return "DW_OP_xor";
12673 return "DW_OP_bra";
12687 return "DW_OP_skip";
12689 return "DW_OP_lit0";
12691 return "DW_OP_lit1";
12693 return "DW_OP_lit2";
12695 return "DW_OP_lit3";
12697 return "DW_OP_lit4";
12699 return "DW_OP_lit5";
12701 return "DW_OP_lit6";
12703 return "DW_OP_lit7";
12705 return "DW_OP_lit8";
12707 return "DW_OP_lit9";
12709 return "DW_OP_lit10";
12711 return "DW_OP_lit11";
12713 return "DW_OP_lit12";
12715 return "DW_OP_lit13";
12717 return "DW_OP_lit14";
12719 return "DW_OP_lit15";
12721 return "DW_OP_lit16";
12723 return "DW_OP_lit17";
12725 return "DW_OP_lit18";
12727 return "DW_OP_lit19";
12729 return "DW_OP_lit20";
12731 return "DW_OP_lit21";
12733 return "DW_OP_lit22";
12735 return "DW_OP_lit23";
12737 return "DW_OP_lit24";
12739 return "DW_OP_lit25";
12741 return "DW_OP_lit26";
12743 return "DW_OP_lit27";
12745 return "DW_OP_lit28";
12747 return "DW_OP_lit29";
12749 return "DW_OP_lit30";
12751 return "DW_OP_lit31";
12753 return "DW_OP_reg0";
12755 return "DW_OP_reg1";
12757 return "DW_OP_reg2";
12759 return "DW_OP_reg3";
12761 return "DW_OP_reg4";
12763 return "DW_OP_reg5";
12765 return "DW_OP_reg6";
12767 return "DW_OP_reg7";
12769 return "DW_OP_reg8";
12771 return "DW_OP_reg9";
12773 return "DW_OP_reg10";
12775 return "DW_OP_reg11";
12777 return "DW_OP_reg12";
12779 return "DW_OP_reg13";
12781 return "DW_OP_reg14";
12783 return "DW_OP_reg15";
12785 return "DW_OP_reg16";
12787 return "DW_OP_reg17";
12789 return "DW_OP_reg18";
12791 return "DW_OP_reg19";
12793 return "DW_OP_reg20";
12795 return "DW_OP_reg21";
12797 return "DW_OP_reg22";
12799 return "DW_OP_reg23";
12801 return "DW_OP_reg24";
12803 return "DW_OP_reg25";
12805 return "DW_OP_reg26";
12807 return "DW_OP_reg27";
12809 return "DW_OP_reg28";
12811 return "DW_OP_reg29";
12813 return "DW_OP_reg30";
12815 return "DW_OP_reg31";
12817 return "DW_OP_breg0";
12819 return "DW_OP_breg1";
12821 return "DW_OP_breg2";
12823 return "DW_OP_breg3";
12825 return "DW_OP_breg4";
12827 return "DW_OP_breg5";
12829 return "DW_OP_breg6";
12831 return "DW_OP_breg7";
12833 return "DW_OP_breg8";
12835 return "DW_OP_breg9";
12837 return "DW_OP_breg10";
12839 return "DW_OP_breg11";
12841 return "DW_OP_breg12";
12843 return "DW_OP_breg13";
12845 return "DW_OP_breg14";
12847 return "DW_OP_breg15";
12849 return "DW_OP_breg16";
12851 return "DW_OP_breg17";
12853 return "DW_OP_breg18";
12855 return "DW_OP_breg19";
12857 return "DW_OP_breg20";
12859 return "DW_OP_breg21";
12861 return "DW_OP_breg22";
12863 return "DW_OP_breg23";
12865 return "DW_OP_breg24";
12867 return "DW_OP_breg25";
12869 return "DW_OP_breg26";
12871 return "DW_OP_breg27";
12873 return "DW_OP_breg28";
12875 return "DW_OP_breg29";
12877 return "DW_OP_breg30";
12879 return "DW_OP_breg31";
12881 return "DW_OP_regx";
12883 return "DW_OP_fbreg";
12885 return "DW_OP_bregx";
12887 return "DW_OP_piece";
12888 case DW_OP_deref_size
:
12889 return "DW_OP_deref_size";
12890 case DW_OP_xderef_size
:
12891 return "DW_OP_xderef_size";
12893 return "DW_OP_nop";
12894 /* DWARF 3 extensions. */
12895 case DW_OP_push_object_address
:
12896 return "DW_OP_push_object_address";
12898 return "DW_OP_call2";
12900 return "DW_OP_call4";
12901 case DW_OP_call_ref
:
12902 return "DW_OP_call_ref";
12903 case DW_OP_form_tls_address
:
12904 return "DW_OP_form_tls_address";
12905 case DW_OP_call_frame_cfa
:
12906 return "DW_OP_call_frame_cfa";
12907 case DW_OP_bit_piece
:
12908 return "DW_OP_bit_piece";
12909 /* DWARF 4 extensions. */
12910 case DW_OP_implicit_value
:
12911 return "DW_OP_implicit_value";
12912 case DW_OP_stack_value
:
12913 return "DW_OP_stack_value";
12914 /* GNU extensions. */
12915 case DW_OP_GNU_push_tls_address
:
12916 return "DW_OP_GNU_push_tls_address";
12917 case DW_OP_GNU_uninit
:
12918 return "DW_OP_GNU_uninit";
12919 case DW_OP_GNU_implicit_pointer
:
12920 return "DW_OP_GNU_implicit_pointer";
12927 dwarf_bool_name (unsigned mybool
)
12935 /* Convert a DWARF type code into its string name. */
12938 dwarf_type_encoding_name (unsigned enc
)
12943 return "DW_ATE_void";
12944 case DW_ATE_address
:
12945 return "DW_ATE_address";
12946 case DW_ATE_boolean
:
12947 return "DW_ATE_boolean";
12948 case DW_ATE_complex_float
:
12949 return "DW_ATE_complex_float";
12951 return "DW_ATE_float";
12952 case DW_ATE_signed
:
12953 return "DW_ATE_signed";
12954 case DW_ATE_signed_char
:
12955 return "DW_ATE_signed_char";
12956 case DW_ATE_unsigned
:
12957 return "DW_ATE_unsigned";
12958 case DW_ATE_unsigned_char
:
12959 return "DW_ATE_unsigned_char";
12961 case DW_ATE_imaginary_float
:
12962 return "DW_ATE_imaginary_float";
12963 case DW_ATE_packed_decimal
:
12964 return "DW_ATE_packed_decimal";
12965 case DW_ATE_numeric_string
:
12966 return "DW_ATE_numeric_string";
12967 case DW_ATE_edited
:
12968 return "DW_ATE_edited";
12969 case DW_ATE_signed_fixed
:
12970 return "DW_ATE_signed_fixed";
12971 case DW_ATE_unsigned_fixed
:
12972 return "DW_ATE_unsigned_fixed";
12973 case DW_ATE_decimal_float
:
12974 return "DW_ATE_decimal_float";
12977 return "DW_ATE_UTF";
12978 /* HP extensions. */
12979 case DW_ATE_HP_float80
:
12980 return "DW_ATE_HP_float80";
12981 case DW_ATE_HP_complex_float80
:
12982 return "DW_ATE_HP_complex_float80";
12983 case DW_ATE_HP_float128
:
12984 return "DW_ATE_HP_float128";
12985 case DW_ATE_HP_complex_float128
:
12986 return "DW_ATE_HP_complex_float128";
12987 case DW_ATE_HP_floathpintel
:
12988 return "DW_ATE_HP_floathpintel";
12989 case DW_ATE_HP_imaginary_float80
:
12990 return "DW_ATE_HP_imaginary_float80";
12991 case DW_ATE_HP_imaginary_float128
:
12992 return "DW_ATE_HP_imaginary_float128";
12994 return "DW_ATE_<unknown>";
12998 /* Convert a DWARF call frame info operation to its string name. */
13002 dwarf_cfi_name (unsigned cfi_opc
)
13006 case DW_CFA_advance_loc
:
13007 return "DW_CFA_advance_loc";
13008 case DW_CFA_offset
:
13009 return "DW_CFA_offset";
13010 case DW_CFA_restore
:
13011 return "DW_CFA_restore";
13013 return "DW_CFA_nop";
13014 case DW_CFA_set_loc
:
13015 return "DW_CFA_set_loc";
13016 case DW_CFA_advance_loc1
:
13017 return "DW_CFA_advance_loc1";
13018 case DW_CFA_advance_loc2
:
13019 return "DW_CFA_advance_loc2";
13020 case DW_CFA_advance_loc4
:
13021 return "DW_CFA_advance_loc4";
13022 case DW_CFA_offset_extended
:
13023 return "DW_CFA_offset_extended";
13024 case DW_CFA_restore_extended
:
13025 return "DW_CFA_restore_extended";
13026 case DW_CFA_undefined
:
13027 return "DW_CFA_undefined";
13028 case DW_CFA_same_value
:
13029 return "DW_CFA_same_value";
13030 case DW_CFA_register
:
13031 return "DW_CFA_register";
13032 case DW_CFA_remember_state
:
13033 return "DW_CFA_remember_state";
13034 case DW_CFA_restore_state
:
13035 return "DW_CFA_restore_state";
13036 case DW_CFA_def_cfa
:
13037 return "DW_CFA_def_cfa";
13038 case DW_CFA_def_cfa_register
:
13039 return "DW_CFA_def_cfa_register";
13040 case DW_CFA_def_cfa_offset
:
13041 return "DW_CFA_def_cfa_offset";
13043 case DW_CFA_def_cfa_expression
:
13044 return "DW_CFA_def_cfa_expression";
13045 case DW_CFA_expression
:
13046 return "DW_CFA_expression";
13047 case DW_CFA_offset_extended_sf
:
13048 return "DW_CFA_offset_extended_sf";
13049 case DW_CFA_def_cfa_sf
:
13050 return "DW_CFA_def_cfa_sf";
13051 case DW_CFA_def_cfa_offset_sf
:
13052 return "DW_CFA_def_cfa_offset_sf";
13053 case DW_CFA_val_offset
:
13054 return "DW_CFA_val_offset";
13055 case DW_CFA_val_offset_sf
:
13056 return "DW_CFA_val_offset_sf";
13057 case DW_CFA_val_expression
:
13058 return "DW_CFA_val_expression";
13059 /* SGI/MIPS specific. */
13060 case DW_CFA_MIPS_advance_loc8
:
13061 return "DW_CFA_MIPS_advance_loc8";
13062 /* GNU extensions. */
13063 case DW_CFA_GNU_window_save
:
13064 return "DW_CFA_GNU_window_save";
13065 case DW_CFA_GNU_args_size
:
13066 return "DW_CFA_GNU_args_size";
13067 case DW_CFA_GNU_negative_offset_extended
:
13068 return "DW_CFA_GNU_negative_offset_extended";
13070 return "DW_CFA_<unknown>";
13076 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13080 print_spaces (indent
, f
);
13081 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13082 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13084 if (die
->parent
!= NULL
)
13086 print_spaces (indent
, f
);
13087 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13088 die
->parent
->offset
);
13091 print_spaces (indent
, f
);
13092 fprintf_unfiltered (f
, " has children: %s\n",
13093 dwarf_bool_name (die
->child
!= NULL
));
13095 print_spaces (indent
, f
);
13096 fprintf_unfiltered (f
, " attributes:\n");
13098 for (i
= 0; i
< die
->num_attrs
; ++i
)
13100 print_spaces (indent
, f
);
13101 fprintf_unfiltered (f
, " %s (%s) ",
13102 dwarf_attr_name (die
->attrs
[i
].name
),
13103 dwarf_form_name (die
->attrs
[i
].form
));
13105 switch (die
->attrs
[i
].form
)
13107 case DW_FORM_ref_addr
:
13109 fprintf_unfiltered (f
, "address: ");
13110 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13112 case DW_FORM_block2
:
13113 case DW_FORM_block4
:
13114 case DW_FORM_block
:
13115 case DW_FORM_block1
:
13116 fprintf_unfiltered (f
, "block: size %d",
13117 DW_BLOCK (&die
->attrs
[i
])->size
);
13119 case DW_FORM_exprloc
:
13120 fprintf_unfiltered (f
, "expression: size %u",
13121 DW_BLOCK (&die
->attrs
[i
])->size
);
13126 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13127 (long) (DW_ADDR (&die
->attrs
[i
])));
13129 case DW_FORM_data1
:
13130 case DW_FORM_data2
:
13131 case DW_FORM_data4
:
13132 case DW_FORM_data8
:
13133 case DW_FORM_udata
:
13134 case DW_FORM_sdata
:
13135 fprintf_unfiltered (f
, "constant: %s",
13136 pulongest (DW_UNSND (&die
->attrs
[i
])));
13138 case DW_FORM_sec_offset
:
13139 fprintf_unfiltered (f
, "section offset: %s",
13140 pulongest (DW_UNSND (&die
->attrs
[i
])));
13142 case DW_FORM_ref_sig8
:
13143 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13144 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13145 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
13147 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13149 case DW_FORM_string
:
13151 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13152 DW_STRING (&die
->attrs
[i
])
13153 ? DW_STRING (&die
->attrs
[i
]) : "",
13154 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13157 if (DW_UNSND (&die
->attrs
[i
]))
13158 fprintf_unfiltered (f
, "flag: TRUE");
13160 fprintf_unfiltered (f
, "flag: FALSE");
13162 case DW_FORM_flag_present
:
13163 fprintf_unfiltered (f
, "flag: TRUE");
13165 case DW_FORM_indirect
:
13166 /* The reader will have reduced the indirect form to
13167 the "base form" so this form should not occur. */
13168 fprintf_unfiltered (f
,
13169 "unexpected attribute form: DW_FORM_indirect");
13172 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13173 die
->attrs
[i
].form
);
13176 fprintf_unfiltered (f
, "\n");
13181 dump_die_for_error (struct die_info
*die
)
13183 dump_die_shallow (gdb_stderr
, 0, die
);
13187 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13189 int indent
= level
* 4;
13191 gdb_assert (die
!= NULL
);
13193 if (level
>= max_level
)
13196 dump_die_shallow (f
, indent
, die
);
13198 if (die
->child
!= NULL
)
13200 print_spaces (indent
, f
);
13201 fprintf_unfiltered (f
, " Children:");
13202 if (level
+ 1 < max_level
)
13204 fprintf_unfiltered (f
, "\n");
13205 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13209 fprintf_unfiltered (f
,
13210 " [not printed, max nesting level reached]\n");
13214 if (die
->sibling
!= NULL
&& level
> 0)
13216 dump_die_1 (f
, level
, max_level
, die
->sibling
);
13220 /* This is called from the pdie macro in gdbinit.in.
13221 It's not static so gcc will keep a copy callable from gdb. */
13224 dump_die (struct die_info
*die
, int max_level
)
13226 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
13230 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
13234 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
13240 is_ref_attr (struct attribute
*attr
)
13242 switch (attr
->form
)
13244 case DW_FORM_ref_addr
:
13249 case DW_FORM_ref_udata
:
13256 static unsigned int
13257 dwarf2_get_ref_die_offset (struct attribute
*attr
)
13259 if (is_ref_attr (attr
))
13260 return DW_ADDR (attr
);
13262 complaint (&symfile_complaints
,
13263 _("unsupported die ref attribute form: '%s'"),
13264 dwarf_form_name (attr
->form
));
13268 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13269 * the value held by the attribute is not constant. */
13272 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
13274 if (attr
->form
== DW_FORM_sdata
)
13275 return DW_SND (attr
);
13276 else if (attr
->form
== DW_FORM_udata
13277 || attr
->form
== DW_FORM_data1
13278 || attr
->form
== DW_FORM_data2
13279 || attr
->form
== DW_FORM_data4
13280 || attr
->form
== DW_FORM_data8
)
13281 return DW_UNSND (attr
);
13284 complaint (&symfile_complaints
,
13285 _("Attribute value is not a constant (%s)"),
13286 dwarf_form_name (attr
->form
));
13287 return default_value
;
13291 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13292 unit and add it to our queue.
13293 The result is non-zero if PER_CU was queued, otherwise the result is zero
13294 meaning either PER_CU is already queued or it is already loaded. */
13297 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
13298 struct dwarf2_per_cu_data
*per_cu
)
13300 /* We may arrive here during partial symbol reading, if we need full
13301 DIEs to process an unusual case (e.g. template arguments). Do
13302 not queue PER_CU, just tell our caller to load its DIEs. */
13303 if (dwarf2_per_objfile
->reading_partial_symbols
)
13305 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
13310 /* Mark the dependence relation so that we don't flush PER_CU
13312 dwarf2_add_dependence (this_cu
, per_cu
);
13314 /* If it's already on the queue, we have nothing to do. */
13315 if (per_cu
->queued
)
13318 /* If the compilation unit is already loaded, just mark it as
13320 if (per_cu
->cu
!= NULL
)
13322 per_cu
->cu
->last_used
= 0;
13326 /* Add it to the queue. */
13327 queue_comp_unit (per_cu
, this_cu
->objfile
);
13332 /* Follow reference or signature attribute ATTR of SRC_DIE.
13333 On entry *REF_CU is the CU of SRC_DIE.
13334 On exit *REF_CU is the CU of the result. */
13336 static struct die_info
*
13337 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
13338 struct dwarf2_cu
**ref_cu
)
13340 struct die_info
*die
;
13342 if (is_ref_attr (attr
))
13343 die
= follow_die_ref (src_die
, attr
, ref_cu
);
13344 else if (attr
->form
== DW_FORM_ref_sig8
)
13345 die
= follow_die_sig (src_die
, attr
, ref_cu
);
13348 dump_die_for_error (src_die
);
13349 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13350 (*ref_cu
)->objfile
->name
);
13356 /* Follow reference OFFSET.
13357 On entry *REF_CU is the CU of the source die referencing OFFSET.
13358 On exit *REF_CU is the CU of the result.
13359 Returns NULL if OFFSET is invalid. */
13361 static struct die_info
*
13362 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
13364 struct die_info temp_die
;
13365 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
13367 gdb_assert (cu
->per_cu
!= NULL
);
13371 if (cu
->per_cu
->from_debug_types
)
13373 /* .debug_types CUs cannot reference anything outside their CU.
13374 If they need to, they have to reference a signatured type via
13375 DW_FORM_ref_sig8. */
13376 if (! offset_in_cu_p (&cu
->header
, offset
))
13379 else if (! offset_in_cu_p (&cu
->header
, offset
))
13381 struct dwarf2_per_cu_data
*per_cu
;
13383 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
13385 /* If necessary, add it to the queue and load its DIEs. */
13386 if (maybe_queue_comp_unit (cu
, per_cu
))
13387 load_full_comp_unit (per_cu
, cu
->objfile
);
13389 target_cu
= per_cu
->cu
;
13391 else if (cu
->dies
== NULL
)
13393 /* We're loading full DIEs during partial symbol reading. */
13394 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
13395 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
13398 *ref_cu
= target_cu
;
13399 temp_die
.offset
= offset
;
13400 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13403 /* Follow reference attribute ATTR of SRC_DIE.
13404 On entry *REF_CU is the CU of SRC_DIE.
13405 On exit *REF_CU is the CU of the result. */
13407 static struct die_info
*
13408 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13409 struct dwarf2_cu
**ref_cu
)
13411 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13412 struct dwarf2_cu
*cu
= *ref_cu
;
13413 struct die_info
*die
;
13415 die
= follow_die_offset (offset
, ref_cu
);
13417 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13418 "at 0x%x [in module %s]"),
13419 offset
, src_die
->offset
, cu
->objfile
->name
);
13424 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13425 value is intended for DW_OP_call*. */
13427 struct dwarf2_locexpr_baton
13428 dwarf2_fetch_die_location_block (unsigned int offset
,
13429 struct dwarf2_per_cu_data
*per_cu
,
13430 CORE_ADDR (*get_frame_pc
) (void *baton
),
13433 struct dwarf2_cu
*cu
= per_cu
->cu
;
13434 struct die_info
*die
;
13435 struct attribute
*attr
;
13436 struct dwarf2_locexpr_baton retval
;
13438 dw2_setup (per_cu
->objfile
);
13440 die
= follow_die_offset (offset
, &cu
);
13442 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13443 offset
, per_cu
->cu
->objfile
->name
);
13445 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13448 /* DWARF: "If there is no such attribute, then there is no effect.". */
13450 retval
.data
= NULL
;
13453 else if (attr_form_is_section_offset (attr
))
13455 struct dwarf2_loclist_baton loclist_baton
;
13456 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
13459 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
13461 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
13463 retval
.size
= size
;
13467 if (!attr_form_is_block (attr
))
13468 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13469 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13470 offset
, per_cu
->cu
->objfile
->name
);
13472 retval
.data
= DW_BLOCK (attr
)->data
;
13473 retval
.size
= DW_BLOCK (attr
)->size
;
13475 retval
.per_cu
= cu
->per_cu
;
13479 /* Follow the signature attribute ATTR in SRC_DIE.
13480 On entry *REF_CU is the CU of SRC_DIE.
13481 On exit *REF_CU is the CU of the result. */
13483 static struct die_info
*
13484 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
13485 struct dwarf2_cu
**ref_cu
)
13487 struct objfile
*objfile
= (*ref_cu
)->objfile
;
13488 struct die_info temp_die
;
13489 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13490 struct dwarf2_cu
*sig_cu
;
13491 struct die_info
*die
;
13493 /* sig_type will be NULL if the signatured type is missing from
13495 if (sig_type
== NULL
)
13496 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13497 "at 0x%x [in module %s]"),
13498 src_die
->offset
, objfile
->name
);
13500 /* If necessary, add it to the queue and load its DIEs. */
13502 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
13503 read_signatured_type (objfile
, sig_type
);
13505 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
13507 sig_cu
= sig_type
->per_cu
.cu
;
13508 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
13509 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
13516 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
13517 "from DIE at 0x%x [in module %s]"),
13518 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
13521 /* Given an offset of a signatured type, return its signatured_type. */
13523 static struct signatured_type
*
13524 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
13526 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
13527 unsigned int length
, initial_length_size
;
13528 unsigned int sig_offset
;
13529 struct signatured_type find_entry
, *type_sig
;
13531 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
13532 sig_offset
= (initial_length_size
13534 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
13535 + 1 /*address_size*/);
13536 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
13537 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
13539 /* This is only used to lookup previously recorded types.
13540 If we didn't find it, it's our bug. */
13541 gdb_assert (type_sig
!= NULL
);
13542 gdb_assert (offset
== type_sig
->offset
);
13547 /* Read in signatured type at OFFSET and build its CU and die(s). */
13550 read_signatured_type_at_offset (struct objfile
*objfile
,
13551 unsigned int offset
)
13553 struct signatured_type
*type_sig
;
13555 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13557 /* We have the section offset, but we need the signature to do the
13558 hash table lookup. */
13559 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
13561 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13563 read_signatured_type (objfile
, type_sig
);
13565 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
13568 /* Read in a signatured type and build its CU and DIEs. */
13571 read_signatured_type (struct objfile
*objfile
,
13572 struct signatured_type
*type_sig
)
13574 gdb_byte
*types_ptr
;
13575 struct die_reader_specs reader_specs
;
13576 struct dwarf2_cu
*cu
;
13577 ULONGEST signature
;
13578 struct cleanup
*back_to
, *free_cu_cleanup
;
13580 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13581 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
13583 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13585 cu
= xmalloc (sizeof (*cu
));
13586 init_one_comp_unit (cu
, objfile
);
13588 type_sig
->per_cu
.cu
= cu
;
13589 cu
->per_cu
= &type_sig
->per_cu
;
13591 /* If an error occurs while loading, release our storage. */
13592 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
13594 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
13595 types_ptr
, objfile
->obfd
);
13596 gdb_assert (signature
== type_sig
->signature
);
13599 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13603 &cu
->comp_unit_obstack
,
13604 hashtab_obstack_allocate
,
13605 dummy_obstack_deallocate
);
13607 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
13608 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
13610 init_cu_die_reader (&reader_specs
, cu
);
13612 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
13615 /* We try not to read any attributes in this function, because not
13616 all objfiles needed for references have been loaded yet, and symbol
13617 table processing isn't initialized. But we have to set the CU language,
13618 or we won't be able to build types correctly. */
13619 prepare_one_comp_unit (cu
, cu
->dies
);
13621 do_cleanups (back_to
);
13623 /* We've successfully allocated this compilation unit. Let our caller
13624 clean it up when finished with it. */
13625 discard_cleanups (free_cu_cleanup
);
13627 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
13628 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
13631 /* Decode simple location descriptions.
13632 Given a pointer to a dwarf block that defines a location, compute
13633 the location and return the value.
13635 NOTE drow/2003-11-18: This function is called in two situations
13636 now: for the address of static or global variables (partial symbols
13637 only) and for offsets into structures which are expected to be
13638 (more or less) constant. The partial symbol case should go away,
13639 and only the constant case should remain. That will let this
13640 function complain more accurately. A few special modes are allowed
13641 without complaint for global variables (for instance, global
13642 register values and thread-local values).
13644 A location description containing no operations indicates that the
13645 object is optimized out. The return value is 0 for that case.
13646 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13647 callers will only want a very basic result and this can become a
13650 Note that stack[0] is unused except as a default error return. */
13653 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
13655 struct objfile
*objfile
= cu
->objfile
;
13657 int size
= blk
->size
;
13658 gdb_byte
*data
= blk
->data
;
13659 CORE_ADDR stack
[64];
13661 unsigned int bytes_read
, unsnd
;
13667 stack
[++stacki
] = 0;
13706 stack
[++stacki
] = op
- DW_OP_lit0
;
13741 stack
[++stacki
] = op
- DW_OP_reg0
;
13743 dwarf2_complex_location_expr_complaint ();
13747 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13749 stack
[++stacki
] = unsnd
;
13751 dwarf2_complex_location_expr_complaint ();
13755 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
13760 case DW_OP_const1u
:
13761 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
13765 case DW_OP_const1s
:
13766 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
13770 case DW_OP_const2u
:
13771 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
13775 case DW_OP_const2s
:
13776 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
13780 case DW_OP_const4u
:
13781 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
13785 case DW_OP_const4s
:
13786 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
13791 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
13797 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
13802 stack
[stacki
+ 1] = stack
[stacki
];
13807 stack
[stacki
- 1] += stack
[stacki
];
13811 case DW_OP_plus_uconst
:
13812 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
13818 stack
[stacki
- 1] -= stack
[stacki
];
13823 /* If we're not the last op, then we definitely can't encode
13824 this using GDB's address_class enum. This is valid for partial
13825 global symbols, although the variable's address will be bogus
13828 dwarf2_complex_location_expr_complaint ();
13831 case DW_OP_GNU_push_tls_address
:
13832 /* The top of the stack has the offset from the beginning
13833 of the thread control block at which the variable is located. */
13834 /* Nothing should follow this operator, so the top of stack would
13836 /* This is valid for partial global symbols, but the variable's
13837 address will be bogus in the psymtab. */
13839 dwarf2_complex_location_expr_complaint ();
13842 case DW_OP_GNU_uninit
:
13847 const char *name
= dwarf_stack_op_name (op
);
13850 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
13853 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
13857 return (stack
[stacki
]);
13860 /* Enforce maximum stack depth of SIZE-1 to avoid writing
13861 outside of the allocated space. Also enforce minimum>0. */
13862 if (stacki
>= ARRAY_SIZE (stack
) - 1)
13864 complaint (&symfile_complaints
,
13865 _("location description stack overflow"));
13871 complaint (&symfile_complaints
,
13872 _("location description stack underflow"));
13876 return (stack
[stacki
]);
13879 /* memory allocation interface */
13881 static struct dwarf_block
*
13882 dwarf_alloc_block (struct dwarf2_cu
*cu
)
13884 struct dwarf_block
*blk
;
13886 blk
= (struct dwarf_block
*)
13887 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
13891 static struct abbrev_info
*
13892 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
13894 struct abbrev_info
*abbrev
;
13896 abbrev
= (struct abbrev_info
*)
13897 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
13898 memset (abbrev
, 0, sizeof (struct abbrev_info
));
13902 static struct die_info
*
13903 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
13905 struct die_info
*die
;
13906 size_t size
= sizeof (struct die_info
);
13909 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
13911 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
13912 memset (die
, 0, sizeof (struct die_info
));
13917 /* Macro support. */
13919 /* Return the full name of file number I in *LH's file name table.
13920 Use COMP_DIR as the name of the current directory of the
13921 compilation. The result is allocated using xmalloc; the caller is
13922 responsible for freeing it. */
13924 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
13926 /* Is the file number a valid index into the line header's file name
13927 table? Remember that file numbers start with one, not zero. */
13928 if (1 <= file
&& file
<= lh
->num_file_names
)
13930 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13932 if (IS_ABSOLUTE_PATH (fe
->name
))
13933 return xstrdup (fe
->name
);
13941 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13947 dir_len
= strlen (dir
);
13948 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
13949 strcpy (full_name
, dir
);
13950 full_name
[dir_len
] = '/';
13951 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
13955 return xstrdup (fe
->name
);
13960 /* The compiler produced a bogus file number. We can at least
13961 record the macro definitions made in the file, even if we
13962 won't be able to find the file by name. */
13963 char fake_name
[80];
13965 sprintf (fake_name
, "<bad macro file number %d>", file
);
13967 complaint (&symfile_complaints
,
13968 _("bad file number in macro information (%d)"),
13971 return xstrdup (fake_name
);
13976 static struct macro_source_file
*
13977 macro_start_file (int file
, int line
,
13978 struct macro_source_file
*current_file
,
13979 const char *comp_dir
,
13980 struct line_header
*lh
, struct objfile
*objfile
)
13982 /* The full name of this source file. */
13983 char *full_name
= file_full_name (file
, lh
, comp_dir
);
13985 /* We don't create a macro table for this compilation unit
13986 at all until we actually get a filename. */
13987 if (! pending_macros
)
13988 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
13989 objfile
->macro_cache
);
13991 if (! current_file
)
13992 /* If we have no current file, then this must be the start_file
13993 directive for the compilation unit's main source file. */
13994 current_file
= macro_set_main (pending_macros
, full_name
);
13996 current_file
= macro_include (current_file
, line
, full_name
);
14000 return current_file
;
14004 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14005 followed by a null byte. */
14007 copy_string (const char *buf
, int len
)
14009 char *s
= xmalloc (len
+ 1);
14011 memcpy (s
, buf
, len
);
14017 static const char *
14018 consume_improper_spaces (const char *p
, const char *body
)
14022 complaint (&symfile_complaints
,
14023 _("macro definition contains spaces "
14024 "in formal argument list:\n`%s'"),
14036 parse_macro_definition (struct macro_source_file
*file
, int line
,
14041 /* The body string takes one of two forms. For object-like macro
14042 definitions, it should be:
14044 <macro name> " " <definition>
14046 For function-like macro definitions, it should be:
14048 <macro name> "() " <definition>
14050 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14052 Spaces may appear only where explicitly indicated, and in the
14055 The Dwarf 2 spec says that an object-like macro's name is always
14056 followed by a space, but versions of GCC around March 2002 omit
14057 the space when the macro's definition is the empty string.
14059 The Dwarf 2 spec says that there should be no spaces between the
14060 formal arguments in a function-like macro's formal argument list,
14061 but versions of GCC around March 2002 include spaces after the
14065 /* Find the extent of the macro name. The macro name is terminated
14066 by either a space or null character (for an object-like macro) or
14067 an opening paren (for a function-like macro). */
14068 for (p
= body
; *p
; p
++)
14069 if (*p
== ' ' || *p
== '(')
14072 if (*p
== ' ' || *p
== '\0')
14074 /* It's an object-like macro. */
14075 int name_len
= p
- body
;
14076 char *name
= copy_string (body
, name_len
);
14077 const char *replacement
;
14080 replacement
= body
+ name_len
+ 1;
14083 dwarf2_macro_malformed_definition_complaint (body
);
14084 replacement
= body
+ name_len
;
14087 macro_define_object (file
, line
, name
, replacement
);
14091 else if (*p
== '(')
14093 /* It's a function-like macro. */
14094 char *name
= copy_string (body
, p
- body
);
14097 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14101 p
= consume_improper_spaces (p
, body
);
14103 /* Parse the formal argument list. */
14104 while (*p
&& *p
!= ')')
14106 /* Find the extent of the current argument name. */
14107 const char *arg_start
= p
;
14109 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14112 if (! *p
|| p
== arg_start
)
14113 dwarf2_macro_malformed_definition_complaint (body
);
14116 /* Make sure argv has room for the new argument. */
14117 if (argc
>= argv_size
)
14120 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14123 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14126 p
= consume_improper_spaces (p
, body
);
14128 /* Consume the comma, if present. */
14133 p
= consume_improper_spaces (p
, body
);
14142 /* Perfectly formed definition, no complaints. */
14143 macro_define_function (file
, line
, name
,
14144 argc
, (const char **) argv
,
14146 else if (*p
== '\0')
14148 /* Complain, but do define it. */
14149 dwarf2_macro_malformed_definition_complaint (body
);
14150 macro_define_function (file
, line
, name
,
14151 argc
, (const char **) argv
,
14155 /* Just complain. */
14156 dwarf2_macro_malformed_definition_complaint (body
);
14159 /* Just complain. */
14160 dwarf2_macro_malformed_definition_complaint (body
);
14166 for (i
= 0; i
< argc
; i
++)
14172 dwarf2_macro_malformed_definition_complaint (body
);
14177 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
14178 char *comp_dir
, bfd
*abfd
,
14179 struct dwarf2_cu
*cu
)
14181 gdb_byte
*mac_ptr
, *mac_end
;
14182 struct macro_source_file
*current_file
= 0;
14183 enum dwarf_macinfo_record_type macinfo_type
;
14184 int at_commandline
;
14186 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14187 &dwarf2_per_objfile
->macinfo
);
14188 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
14190 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
14194 /* First pass: Find the name of the base filename.
14195 This filename is needed in order to process all macros whose definition
14196 (or undefinition) comes from the command line. These macros are defined
14197 before the first DW_MACINFO_start_file entry, and yet still need to be
14198 associated to the base file.
14200 To determine the base file name, we scan the macro definitions until we
14201 reach the first DW_MACINFO_start_file entry. We then initialize
14202 CURRENT_FILE accordingly so that any macro definition found before the
14203 first DW_MACINFO_start_file can still be associated to the base file. */
14205 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14206 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
14207 + dwarf2_per_objfile
->macinfo
.size
;
14211 /* Do we at least have room for a macinfo type byte? */
14212 if (mac_ptr
>= mac_end
)
14214 /* Complaint is printed during the second pass as GDB will probably
14215 stop the first pass earlier upon finding
14216 DW_MACINFO_start_file. */
14220 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14223 switch (macinfo_type
)
14225 /* A zero macinfo type indicates the end of the macro
14230 case DW_MACINFO_define
:
14231 case DW_MACINFO_undef
:
14232 /* Only skip the data by MAC_PTR. */
14234 unsigned int bytes_read
;
14236 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14237 mac_ptr
+= bytes_read
;
14238 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14239 mac_ptr
+= bytes_read
;
14243 case DW_MACINFO_start_file
:
14245 unsigned int bytes_read
;
14248 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14249 mac_ptr
+= bytes_read
;
14250 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14251 mac_ptr
+= bytes_read
;
14253 current_file
= macro_start_file (file
, line
, current_file
,
14254 comp_dir
, lh
, cu
->objfile
);
14258 case DW_MACINFO_end_file
:
14259 /* No data to skip by MAC_PTR. */
14262 case DW_MACINFO_vendor_ext
:
14263 /* Only skip the data by MAC_PTR. */
14265 unsigned int bytes_read
;
14267 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14268 mac_ptr
+= bytes_read
;
14269 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14270 mac_ptr
+= bytes_read
;
14277 } while (macinfo_type
!= 0 && current_file
== NULL
);
14279 /* Second pass: Process all entries.
14281 Use the AT_COMMAND_LINE flag to determine whether we are still processing
14282 command-line macro definitions/undefinitions. This flag is unset when we
14283 reach the first DW_MACINFO_start_file entry. */
14285 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14287 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14288 GDB is still reading the definitions from command line. First
14289 DW_MACINFO_start_file will need to be ignored as it was already executed
14290 to create CURRENT_FILE for the main source holding also the command line
14291 definitions. On first met DW_MACINFO_start_file this flag is reset to
14292 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14294 at_commandline
= 1;
14298 /* Do we at least have room for a macinfo type byte? */
14299 if (mac_ptr
>= mac_end
)
14301 dwarf2_macros_too_long_complaint ();
14305 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14308 switch (macinfo_type
)
14310 /* A zero macinfo type indicates the end of the macro
14315 case DW_MACINFO_define
:
14316 case DW_MACINFO_undef
:
14318 unsigned int bytes_read
;
14322 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14323 mac_ptr
+= bytes_read
;
14324 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14325 mac_ptr
+= bytes_read
;
14327 if (! current_file
)
14329 /* DWARF violation as no main source is present. */
14330 complaint (&symfile_complaints
,
14331 _("debug info with no main source gives macro %s "
14333 macinfo_type
== DW_MACINFO_define
?
14335 macinfo_type
== DW_MACINFO_undef
?
14336 _("undefinition") :
14337 _("something-or-other"), line
, body
);
14340 if ((line
== 0 && !at_commandline
)
14341 || (line
!= 0 && at_commandline
))
14342 complaint (&symfile_complaints
,
14343 _("debug info gives %s macro %s with %s line %d: %s"),
14344 at_commandline
? _("command-line") : _("in-file"),
14345 macinfo_type
== DW_MACINFO_define
?
14347 macinfo_type
== DW_MACINFO_undef
?
14348 _("undefinition") :
14349 _("something-or-other"),
14350 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
14352 if (macinfo_type
== DW_MACINFO_define
)
14353 parse_macro_definition (current_file
, line
, body
);
14354 else if (macinfo_type
== DW_MACINFO_undef
)
14355 macro_undef (current_file
, line
, body
);
14359 case DW_MACINFO_start_file
:
14361 unsigned int bytes_read
;
14364 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14365 mac_ptr
+= bytes_read
;
14366 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14367 mac_ptr
+= bytes_read
;
14369 if ((line
== 0 && !at_commandline
)
14370 || (line
!= 0 && at_commandline
))
14371 complaint (&symfile_complaints
,
14372 _("debug info gives source %d included "
14373 "from %s at %s line %d"),
14374 file
, at_commandline
? _("command-line") : _("file"),
14375 line
== 0 ? _("zero") : _("non-zero"), line
);
14377 if (at_commandline
)
14379 /* This DW_MACINFO_start_file was executed in the pass one. */
14380 at_commandline
= 0;
14383 current_file
= macro_start_file (file
, line
,
14384 current_file
, comp_dir
,
14389 case DW_MACINFO_end_file
:
14390 if (! current_file
)
14391 complaint (&symfile_complaints
,
14392 _("macro debug info has an unmatched "
14393 "`close_file' directive"));
14396 current_file
= current_file
->included_by
;
14397 if (! current_file
)
14399 enum dwarf_macinfo_record_type next_type
;
14401 /* GCC circa March 2002 doesn't produce the zero
14402 type byte marking the end of the compilation
14403 unit. Complain if it's not there, but exit no
14406 /* Do we at least have room for a macinfo type byte? */
14407 if (mac_ptr
>= mac_end
)
14409 dwarf2_macros_too_long_complaint ();
14413 /* We don't increment mac_ptr here, so this is just
14415 next_type
= read_1_byte (abfd
, mac_ptr
);
14416 if (next_type
!= 0)
14417 complaint (&symfile_complaints
,
14418 _("no terminating 0-type entry for "
14419 "macros in `.debug_macinfo' section"));
14426 case DW_MACINFO_vendor_ext
:
14428 unsigned int bytes_read
;
14431 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14432 mac_ptr
+= bytes_read
;
14433 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14434 mac_ptr
+= bytes_read
;
14436 /* We don't recognize any vendor extensions. */
14440 } while (macinfo_type
!= 0);
14443 /* Check if the attribute's form is a DW_FORM_block*
14444 if so return true else false. */
14446 attr_form_is_block (struct attribute
*attr
)
14448 return (attr
== NULL
? 0 :
14449 attr
->form
== DW_FORM_block1
14450 || attr
->form
== DW_FORM_block2
14451 || attr
->form
== DW_FORM_block4
14452 || attr
->form
== DW_FORM_block
14453 || attr
->form
== DW_FORM_exprloc
);
14456 /* Return non-zero if ATTR's value is a section offset --- classes
14457 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14458 You may use DW_UNSND (attr) to retrieve such offsets.
14460 Section 7.5.4, "Attribute Encodings", explains that no attribute
14461 may have a value that belongs to more than one of these classes; it
14462 would be ambiguous if we did, because we use the same forms for all
14465 attr_form_is_section_offset (struct attribute
*attr
)
14467 return (attr
->form
== DW_FORM_data4
14468 || attr
->form
== DW_FORM_data8
14469 || attr
->form
== DW_FORM_sec_offset
);
14473 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14474 zero otherwise. When this function returns true, you can apply
14475 dwarf2_get_attr_constant_value to it.
14477 However, note that for some attributes you must check
14478 attr_form_is_section_offset before using this test. DW_FORM_data4
14479 and DW_FORM_data8 are members of both the constant class, and of
14480 the classes that contain offsets into other debug sections
14481 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14482 that, if an attribute's can be either a constant or one of the
14483 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14484 taken as section offsets, not constants. */
14486 attr_form_is_constant (struct attribute
*attr
)
14488 switch (attr
->form
)
14490 case DW_FORM_sdata
:
14491 case DW_FORM_udata
:
14492 case DW_FORM_data1
:
14493 case DW_FORM_data2
:
14494 case DW_FORM_data4
:
14495 case DW_FORM_data8
:
14502 /* A helper function that fills in a dwarf2_loclist_baton. */
14505 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
14506 struct dwarf2_loclist_baton
*baton
,
14507 struct attribute
*attr
)
14509 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14510 &dwarf2_per_objfile
->loc
);
14512 baton
->per_cu
= cu
->per_cu
;
14513 gdb_assert (baton
->per_cu
);
14514 /* We don't know how long the location list is, but make sure we
14515 don't run off the edge of the section. */
14516 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
14517 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
14518 baton
->base_address
= cu
->base_address
;
14522 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
14523 struct dwarf2_cu
*cu
)
14525 if (attr_form_is_section_offset (attr
)
14526 /* ".debug_loc" may not exist at all, or the offset may be outside
14527 the section. If so, fall through to the complaint in the
14529 && DW_UNSND (attr
) < dwarf2_section_size (dwarf2_per_objfile
->objfile
,
14530 &dwarf2_per_objfile
->loc
))
14532 struct dwarf2_loclist_baton
*baton
;
14534 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14535 sizeof (struct dwarf2_loclist_baton
));
14537 fill_in_loclist_baton (cu
, baton
, attr
);
14539 if (cu
->base_known
== 0)
14540 complaint (&symfile_complaints
,
14541 _("Location list used without "
14542 "specifying the CU base address."));
14544 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
14545 SYMBOL_LOCATION_BATON (sym
) = baton
;
14549 struct dwarf2_locexpr_baton
*baton
;
14551 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14552 sizeof (struct dwarf2_locexpr_baton
));
14553 baton
->per_cu
= cu
->per_cu
;
14554 gdb_assert (baton
->per_cu
);
14556 if (attr_form_is_block (attr
))
14558 /* Note that we're just copying the block's data pointer
14559 here, not the actual data. We're still pointing into the
14560 info_buffer for SYM's objfile; right now we never release
14561 that buffer, but when we do clean up properly this may
14563 baton
->size
= DW_BLOCK (attr
)->size
;
14564 baton
->data
= DW_BLOCK (attr
)->data
;
14568 dwarf2_invalid_attrib_class_complaint ("location description",
14569 SYMBOL_NATURAL_NAME (sym
));
14571 baton
->data
= NULL
;
14574 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14575 SYMBOL_LOCATION_BATON (sym
) = baton
;
14579 /* Return the OBJFILE associated with the compilation unit CU. If CU
14580 came from a separate debuginfo file, then the master objfile is
14584 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
14586 struct objfile
*objfile
= per_cu
->objfile
;
14588 /* Return the master objfile, so that we can report and look up the
14589 correct file containing this variable. */
14590 if (objfile
->separate_debug_objfile_backlink
)
14591 objfile
= objfile
->separate_debug_objfile_backlink
;
14596 /* Return the address size given in the compilation unit header for CU. */
14599 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
14602 return per_cu
->cu
->header
.addr_size
;
14605 /* If the CU is not currently read in, we re-read its header. */
14606 struct objfile
*objfile
= per_cu
->objfile
;
14607 struct dwarf2_per_objfile
*per_objfile
14608 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14609 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14610 struct comp_unit_head cu_header
;
14612 memset (&cu_header
, 0, sizeof cu_header
);
14613 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14614 return cu_header
.addr_size
;
14618 /* Return the offset size given in the compilation unit header for CU. */
14621 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
14624 return per_cu
->cu
->header
.offset_size
;
14627 /* If the CU is not currently read in, we re-read its header. */
14628 struct objfile
*objfile
= per_cu
->objfile
;
14629 struct dwarf2_per_objfile
*per_objfile
14630 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14631 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14632 struct comp_unit_head cu_header
;
14634 memset (&cu_header
, 0, sizeof cu_header
);
14635 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14636 return cu_header
.offset_size
;
14640 /* Return the text offset of the CU. The returned offset comes from
14641 this CU's objfile. If this objfile came from a separate debuginfo
14642 file, then the offset may be different from the corresponding
14643 offset in the parent objfile. */
14646 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
14648 struct objfile
*objfile
= per_cu
->objfile
;
14650 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14653 /* Locate the .debug_info compilation unit from CU's objfile which contains
14654 the DIE at OFFSET. Raises an error on failure. */
14656 static struct dwarf2_per_cu_data
*
14657 dwarf2_find_containing_comp_unit (unsigned int offset
,
14658 struct objfile
*objfile
)
14660 struct dwarf2_per_cu_data
*this_cu
;
14664 high
= dwarf2_per_objfile
->n_comp_units
- 1;
14667 int mid
= low
+ (high
- low
) / 2;
14669 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
14674 gdb_assert (low
== high
);
14675 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
14678 error (_("Dwarf Error: could not find partial DIE containing "
14679 "offset 0x%lx [in module %s]"),
14680 (long) offset
, bfd_get_filename (objfile
->obfd
));
14682 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
14683 return dwarf2_per_objfile
->all_comp_units
[low
-1];
14687 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
14688 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
14689 && offset
>= this_cu
->offset
+ this_cu
->length
)
14690 error (_("invalid dwarf2 offset %u"), offset
);
14691 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
14696 /* Locate the compilation unit from OBJFILE which is located at exactly
14697 OFFSET. Raises an error on failure. */
14699 static struct dwarf2_per_cu_data
*
14700 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
14702 struct dwarf2_per_cu_data
*this_cu
;
14704 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
14705 if (this_cu
->offset
!= offset
)
14706 error (_("no compilation unit with offset %u."), offset
);
14710 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
14713 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
14715 memset (cu
, 0, sizeof (*cu
));
14716 cu
->objfile
= objfile
;
14717 obstack_init (&cu
->comp_unit_obstack
);
14720 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
14723 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
14725 struct attribute
*attr
;
14727 /* Set the language we're debugging. */
14728 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
14730 set_cu_language (DW_UNSND (attr
), cu
);
14733 cu
->language
= language_minimal
;
14734 cu
->language_defn
= language_def (cu
->language
);
14738 /* Release one cached compilation unit, CU. We unlink it from the tree
14739 of compilation units, but we don't remove it from the read_in_chain;
14740 the caller is responsible for that.
14741 NOTE: DATA is a void * because this function is also used as a
14742 cleanup routine. */
14745 free_one_comp_unit (void *data
)
14747 struct dwarf2_cu
*cu
= data
;
14749 if (cu
->per_cu
!= NULL
)
14750 cu
->per_cu
->cu
= NULL
;
14753 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14758 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14759 when we're finished with it. We can't free the pointer itself, but be
14760 sure to unlink it from the cache. Also release any associated storage
14761 and perform cache maintenance.
14763 Only used during partial symbol parsing. */
14766 free_stack_comp_unit (void *data
)
14768 struct dwarf2_cu
*cu
= data
;
14770 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14771 cu
->partial_dies
= NULL
;
14773 if (cu
->per_cu
!= NULL
)
14775 /* This compilation unit is on the stack in our caller, so we
14776 should not xfree it. Just unlink it. */
14777 cu
->per_cu
->cu
= NULL
;
14780 /* If we had a per-cu pointer, then we may have other compilation
14781 units loaded, so age them now. */
14782 age_cached_comp_units ();
14786 /* Free all cached compilation units. */
14789 free_cached_comp_units (void *data
)
14791 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14793 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14794 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14795 while (per_cu
!= NULL
)
14797 struct dwarf2_per_cu_data
*next_cu
;
14799 next_cu
= per_cu
->cu
->read_in_chain
;
14801 free_one_comp_unit (per_cu
->cu
);
14802 *last_chain
= next_cu
;
14808 /* Increase the age counter on each cached compilation unit, and free
14809 any that are too old. */
14812 age_cached_comp_units (void)
14814 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14816 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
14817 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14818 while (per_cu
!= NULL
)
14820 per_cu
->cu
->last_used
++;
14821 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
14822 dwarf2_mark (per_cu
->cu
);
14823 per_cu
= per_cu
->cu
->read_in_chain
;
14826 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14827 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14828 while (per_cu
!= NULL
)
14830 struct dwarf2_per_cu_data
*next_cu
;
14832 next_cu
= per_cu
->cu
->read_in_chain
;
14834 if (!per_cu
->cu
->mark
)
14836 free_one_comp_unit (per_cu
->cu
);
14837 *last_chain
= next_cu
;
14840 last_chain
= &per_cu
->cu
->read_in_chain
;
14846 /* Remove a single compilation unit from the cache. */
14849 free_one_cached_comp_unit (void *target_cu
)
14851 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14853 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14854 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14855 while (per_cu
!= NULL
)
14857 struct dwarf2_per_cu_data
*next_cu
;
14859 next_cu
= per_cu
->cu
->read_in_chain
;
14861 if (per_cu
->cu
== target_cu
)
14863 free_one_comp_unit (per_cu
->cu
);
14864 *last_chain
= next_cu
;
14868 last_chain
= &per_cu
->cu
->read_in_chain
;
14874 /* Release all extra memory associated with OBJFILE. */
14877 dwarf2_free_objfile (struct objfile
*objfile
)
14879 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14881 if (dwarf2_per_objfile
== NULL
)
14884 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
14885 free_cached_comp_units (NULL
);
14887 if (dwarf2_per_objfile
->quick_file_names_table
)
14888 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
14890 /* Everything else should be on the objfile obstack. */
14893 /* A pair of DIE offset and GDB type pointer. We store these
14894 in a hash table separate from the DIEs, and preserve them
14895 when the DIEs are flushed out of cache. */
14897 struct dwarf2_offset_and_type
14899 unsigned int offset
;
14903 /* Hash function for a dwarf2_offset_and_type. */
14906 offset_and_type_hash (const void *item
)
14908 const struct dwarf2_offset_and_type
*ofs
= item
;
14910 return ofs
->offset
;
14913 /* Equality function for a dwarf2_offset_and_type. */
14916 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
14918 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
14919 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
14921 return ofs_lhs
->offset
== ofs_rhs
->offset
;
14924 /* Set the type associated with DIE to TYPE. Save it in CU's hash
14925 table if necessary. For convenience, return TYPE.
14927 The DIEs reading must have careful ordering to:
14928 * Not cause infite loops trying to read in DIEs as a prerequisite for
14929 reading current DIE.
14930 * Not trying to dereference contents of still incompletely read in types
14931 while reading in other DIEs.
14932 * Enable referencing still incompletely read in types just by a pointer to
14933 the type without accessing its fields.
14935 Therefore caller should follow these rules:
14936 * Try to fetch any prerequisite types we may need to build this DIE type
14937 before building the type and calling set_die_type.
14938 * After building type call set_die_type for current DIE as soon as
14939 possible before fetching more types to complete the current type.
14940 * Make the type as complete as possible before fetching more types. */
14942 static struct type
*
14943 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14945 struct dwarf2_offset_and_type
**slot
, ofs
;
14946 struct objfile
*objfile
= cu
->objfile
;
14947 htab_t
*type_hash_ptr
;
14949 /* For Ada types, make sure that the gnat-specific data is always
14950 initialized (if not already set). There are a few types where
14951 we should not be doing so, because the type-specific area is
14952 already used to hold some other piece of info (eg: TYPE_CODE_FLT
14953 where the type-specific area is used to store the floatformat).
14954 But this is not a problem, because the gnat-specific information
14955 is actually not needed for these types. */
14956 if (need_gnat_info (cu
)
14957 && TYPE_CODE (type
) != TYPE_CODE_FUNC
14958 && TYPE_CODE (type
) != TYPE_CODE_FLT
14959 && !HAVE_GNAT_AUX_INFO (type
))
14960 INIT_GNAT_SPECIFIC (type
);
14962 if (cu
->per_cu
->from_debug_types
)
14963 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
14965 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
14967 if (*type_hash_ptr
== NULL
)
14970 = htab_create_alloc_ex (127,
14971 offset_and_type_hash
,
14972 offset_and_type_eq
,
14974 &objfile
->objfile_obstack
,
14975 hashtab_obstack_allocate
,
14976 dummy_obstack_deallocate
);
14979 ofs
.offset
= die
->offset
;
14981 slot
= (struct dwarf2_offset_and_type
**)
14982 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
14984 complaint (&symfile_complaints
,
14985 _("A problem internal to GDB: DIE 0x%x has type already set"),
14987 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
14992 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
14993 table, or return NULL if the die does not have a saved type. */
14995 static struct type
*
14996 get_die_type_at_offset (unsigned int offset
,
14997 struct dwarf2_per_cu_data
*per_cu
)
14999 struct dwarf2_offset_and_type
*slot
, ofs
;
15002 if (per_cu
->from_debug_types
)
15003 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
15005 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
15006 if (type_hash
== NULL
)
15009 ofs
.offset
= offset
;
15010 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
15017 /* Look up the type for DIE in the appropriate type_hash table,
15018 or return NULL if DIE does not have a saved type. */
15020 static struct type
*
15021 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15023 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
15026 /* Add a dependence relationship from CU to REF_PER_CU. */
15029 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
15030 struct dwarf2_per_cu_data
*ref_per_cu
)
15034 if (cu
->dependencies
== NULL
)
15036 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
15037 NULL
, &cu
->comp_unit_obstack
,
15038 hashtab_obstack_allocate
,
15039 dummy_obstack_deallocate
);
15041 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
15043 *slot
= ref_per_cu
;
15046 /* Subroutine of dwarf2_mark to pass to htab_traverse.
15047 Set the mark field in every compilation unit in the
15048 cache that we must keep because we are keeping CU. */
15051 dwarf2_mark_helper (void **slot
, void *data
)
15053 struct dwarf2_per_cu_data
*per_cu
;
15055 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
15056 if (per_cu
->cu
->mark
)
15058 per_cu
->cu
->mark
= 1;
15060 if (per_cu
->cu
->dependencies
!= NULL
)
15061 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15066 /* Set the mark field in CU and in every other compilation unit in the
15067 cache that we must keep because we are keeping CU. */
15070 dwarf2_mark (struct dwarf2_cu
*cu
)
15075 if (cu
->dependencies
!= NULL
)
15076 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15080 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
15084 per_cu
->cu
->mark
= 0;
15085 per_cu
= per_cu
->cu
->read_in_chain
;
15089 /* Trivial hash function for partial_die_info: the hash value of a DIE
15090 is its offset in .debug_info for this objfile. */
15093 partial_die_hash (const void *item
)
15095 const struct partial_die_info
*part_die
= item
;
15097 return part_die
->offset
;
15100 /* Trivial comparison function for partial_die_info structures: two DIEs
15101 are equal if they have the same offset. */
15104 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
15106 const struct partial_die_info
*part_die_lhs
= item_lhs
;
15107 const struct partial_die_info
*part_die_rhs
= item_rhs
;
15109 return part_die_lhs
->offset
== part_die_rhs
->offset
;
15112 static struct cmd_list_element
*set_dwarf2_cmdlist
;
15113 static struct cmd_list_element
*show_dwarf2_cmdlist
;
15116 set_dwarf2_cmd (char *args
, int from_tty
)
15118 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
15122 show_dwarf2_cmd (char *args
, int from_tty
)
15124 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
15127 /* If section described by INFO was mmapped, munmap it now. */
15130 munmap_section_buffer (struct dwarf2_section_info
*info
)
15132 if (info
->was_mmapped
)
15135 intptr_t begin
= (intptr_t) info
->buffer
;
15136 intptr_t map_begin
= begin
& ~(pagesize
- 1);
15137 size_t map_length
= info
->size
+ begin
- map_begin
;
15139 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
15141 /* Without HAVE_MMAP, we should never be here to begin with. */
15142 gdb_assert_not_reached ("no mmap support");
15147 /* munmap debug sections for OBJFILE, if necessary. */
15150 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
15152 struct dwarf2_per_objfile
*data
= d
;
15154 /* This is sorted according to the order they're defined in to make it easier
15155 to keep in sync. */
15156 munmap_section_buffer (&data
->info
);
15157 munmap_section_buffer (&data
->abbrev
);
15158 munmap_section_buffer (&data
->line
);
15159 munmap_section_buffer (&data
->loc
);
15160 munmap_section_buffer (&data
->macinfo
);
15161 munmap_section_buffer (&data
->str
);
15162 munmap_section_buffer (&data
->ranges
);
15163 munmap_section_buffer (&data
->types
);
15164 munmap_section_buffer (&data
->frame
);
15165 munmap_section_buffer (&data
->eh_frame
);
15166 munmap_section_buffer (&data
->gdb_index
);
15170 /* The "save gdb-index" command. */
15172 /* The contents of the hash table we create when building the string
15174 struct strtab_entry
15176 offset_type offset
;
15180 /* Hash function for a strtab_entry. */
15183 hash_strtab_entry (const void *e
)
15185 const struct strtab_entry
*entry
= e
;
15186 return mapped_index_string_hash (entry
->str
);
15189 /* Equality function for a strtab_entry. */
15192 eq_strtab_entry (const void *a
, const void *b
)
15194 const struct strtab_entry
*ea
= a
;
15195 const struct strtab_entry
*eb
= b
;
15196 return !strcmp (ea
->str
, eb
->str
);
15199 /* Create a strtab_entry hash table. */
15202 create_strtab (void)
15204 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
15205 xfree
, xcalloc
, xfree
);
15208 /* Add a string to the constant pool. Return the string's offset in
15212 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
15215 struct strtab_entry entry
;
15216 struct strtab_entry
*result
;
15219 slot
= htab_find_slot (table
, &entry
, INSERT
);
15224 result
= XNEW (struct strtab_entry
);
15225 result
->offset
= obstack_object_size (cpool
);
15227 obstack_grow_str0 (cpool
, str
);
15230 return result
->offset
;
15233 /* An entry in the symbol table. */
15234 struct symtab_index_entry
15236 /* The name of the symbol. */
15238 /* The offset of the name in the constant pool. */
15239 offset_type index_offset
;
15240 /* A sorted vector of the indices of all the CUs that hold an object
15242 VEC (offset_type
) *cu_indices
;
15245 /* The symbol table. This is a power-of-2-sized hash table. */
15246 struct mapped_symtab
15248 offset_type n_elements
;
15250 struct symtab_index_entry
**data
;
15253 /* Hash function for a symtab_index_entry. */
15256 hash_symtab_entry (const void *e
)
15258 const struct symtab_index_entry
*entry
= e
;
15259 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
15260 sizeof (offset_type
) * VEC_length (offset_type
,
15261 entry
->cu_indices
),
15265 /* Equality function for a symtab_index_entry. */
15268 eq_symtab_entry (const void *a
, const void *b
)
15270 const struct symtab_index_entry
*ea
= a
;
15271 const struct symtab_index_entry
*eb
= b
;
15272 int len
= VEC_length (offset_type
, ea
->cu_indices
);
15273 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
15275 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
15276 VEC_address (offset_type
, eb
->cu_indices
),
15277 sizeof (offset_type
) * len
);
15280 /* Destroy a symtab_index_entry. */
15283 delete_symtab_entry (void *p
)
15285 struct symtab_index_entry
*entry
= p
;
15286 VEC_free (offset_type
, entry
->cu_indices
);
15290 /* Create a hash table holding symtab_index_entry objects. */
15293 create_symbol_hash_table (void)
15295 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
15296 delete_symtab_entry
, xcalloc
, xfree
);
15299 /* Create a new mapped symtab object. */
15301 static struct mapped_symtab
*
15302 create_mapped_symtab (void)
15304 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
15305 symtab
->n_elements
= 0;
15306 symtab
->size
= 1024;
15307 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15311 /* Destroy a mapped_symtab. */
15314 cleanup_mapped_symtab (void *p
)
15316 struct mapped_symtab
*symtab
= p
;
15317 /* The contents of the array are freed when the other hash table is
15319 xfree (symtab
->data
);
15323 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
15326 static struct symtab_index_entry
**
15327 find_slot (struct mapped_symtab
*symtab
, const char *name
)
15329 offset_type index
, step
, hash
= mapped_index_string_hash (name
);
15331 index
= hash
& (symtab
->size
- 1);
15332 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
15336 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
15337 return &symtab
->data
[index
];
15338 index
= (index
+ step
) & (symtab
->size
- 1);
15342 /* Expand SYMTAB's hash table. */
15345 hash_expand (struct mapped_symtab
*symtab
)
15347 offset_type old_size
= symtab
->size
;
15349 struct symtab_index_entry
**old_entries
= symtab
->data
;
15352 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15354 for (i
= 0; i
< old_size
; ++i
)
15356 if (old_entries
[i
])
15358 struct symtab_index_entry
**slot
= find_slot (symtab
,
15359 old_entries
[i
]->name
);
15360 *slot
= old_entries
[i
];
15364 xfree (old_entries
);
15367 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
15368 is the index of the CU in which the symbol appears. */
15371 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
15372 offset_type cu_index
)
15374 struct symtab_index_entry
**slot
;
15376 ++symtab
->n_elements
;
15377 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
15378 hash_expand (symtab
);
15380 slot
= find_slot (symtab
, name
);
15383 *slot
= XNEW (struct symtab_index_entry
);
15384 (*slot
)->name
= name
;
15385 (*slot
)->cu_indices
= NULL
;
15387 /* Don't push an index twice. Due to how we add entries we only
15388 have to check the last one. */
15389 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
15390 || VEC_length (offset_type
, (*slot
)->cu_indices
) != cu_index
)
15391 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
15394 /* Add a vector of indices to the constant pool. */
15397 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
15398 struct symtab_index_entry
*entry
)
15402 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
15405 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
15406 offset_type val
= MAYBE_SWAP (len
);
15411 entry
->index_offset
= obstack_object_size (cpool
);
15413 obstack_grow (cpool
, &val
, sizeof (val
));
15415 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
15418 val
= MAYBE_SWAP (iter
);
15419 obstack_grow (cpool
, &val
, sizeof (val
));
15424 struct symtab_index_entry
*old_entry
= *slot
;
15425 entry
->index_offset
= old_entry
->index_offset
;
15428 return entry
->index_offset
;
15431 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15432 constant pool entries going into the obstack CPOOL. */
15435 write_hash_table (struct mapped_symtab
*symtab
,
15436 struct obstack
*output
, struct obstack
*cpool
)
15439 htab_t symbol_hash_table
;
15442 symbol_hash_table
= create_symbol_hash_table ();
15443 str_table
= create_strtab ();
15445 /* We add all the index vectors to the constant pool first, to
15446 ensure alignment is ok. */
15447 for (i
= 0; i
< symtab
->size
; ++i
)
15449 if (symtab
->data
[i
])
15450 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
15453 /* Now write out the hash table. */
15454 for (i
= 0; i
< symtab
->size
; ++i
)
15456 offset_type str_off
, vec_off
;
15458 if (symtab
->data
[i
])
15460 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
15461 vec_off
= symtab
->data
[i
]->index_offset
;
15465 /* While 0 is a valid constant pool index, it is not valid
15466 to have 0 for both offsets. */
15471 str_off
= MAYBE_SWAP (str_off
);
15472 vec_off
= MAYBE_SWAP (vec_off
);
15474 obstack_grow (output
, &str_off
, sizeof (str_off
));
15475 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
15478 htab_delete (str_table
);
15479 htab_delete (symbol_hash_table
);
15482 /* Struct to map psymtab to CU index in the index file. */
15483 struct psymtab_cu_index_map
15485 struct partial_symtab
*psymtab
;
15486 unsigned int cu_index
;
15490 hash_psymtab_cu_index (const void *item
)
15492 const struct psymtab_cu_index_map
*map
= item
;
15494 return htab_hash_pointer (map
->psymtab
);
15498 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
15500 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
15501 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
15503 return lhs
->psymtab
== rhs
->psymtab
;
15506 /* Helper struct for building the address table. */
15507 struct addrmap_index_data
15509 struct objfile
*objfile
;
15510 struct obstack
*addr_obstack
;
15511 htab_t cu_index_htab
;
15513 /* Non-zero if the previous_* fields are valid.
15514 We can't write an entry until we see the next entry (since it is only then
15515 that we know the end of the entry). */
15516 int previous_valid
;
15517 /* Index of the CU in the table of all CUs in the index file. */
15518 unsigned int previous_cu_index
;
15519 /* Start address of the CU. */
15520 CORE_ADDR previous_cu_start
;
15523 /* Write an address entry to OBSTACK. */
15526 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
15527 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
15529 offset_type cu_index_to_write
;
15531 CORE_ADDR baseaddr
;
15533 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15535 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
15536 obstack_grow (obstack
, addr
, 8);
15537 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
15538 obstack_grow (obstack
, addr
, 8);
15539 cu_index_to_write
= MAYBE_SWAP (cu_index
);
15540 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
15543 /* Worker function for traversing an addrmap to build the address table. */
15546 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
15548 struct addrmap_index_data
*data
= datap
;
15549 struct partial_symtab
*pst
= obj
;
15550 offset_type cu_index
;
15553 if (data
->previous_valid
)
15554 add_address_entry (data
->objfile
, data
->addr_obstack
,
15555 data
->previous_cu_start
, start_addr
,
15556 data
->previous_cu_index
);
15558 data
->previous_cu_start
= start_addr
;
15561 struct psymtab_cu_index_map find_map
, *map
;
15562 find_map
.psymtab
= pst
;
15563 map
= htab_find (data
->cu_index_htab
, &find_map
);
15564 gdb_assert (map
!= NULL
);
15565 data
->previous_cu_index
= map
->cu_index
;
15566 data
->previous_valid
= 1;
15569 data
->previous_valid
= 0;
15574 /* Write OBJFILE's address map to OBSTACK.
15575 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
15576 in the index file. */
15579 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
15580 htab_t cu_index_htab
)
15582 struct addrmap_index_data addrmap_index_data
;
15584 /* When writing the address table, we have to cope with the fact that
15585 the addrmap iterator only provides the start of a region; we have to
15586 wait until the next invocation to get the start of the next region. */
15588 addrmap_index_data
.objfile
= objfile
;
15589 addrmap_index_data
.addr_obstack
= obstack
;
15590 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
15591 addrmap_index_data
.previous_valid
= 0;
15593 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
15594 &addrmap_index_data
);
15596 /* It's highly unlikely the last entry (end address = 0xff...ff)
15597 is valid, but we should still handle it.
15598 The end address is recorded as the start of the next region, but that
15599 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
15601 if (addrmap_index_data
.previous_valid
)
15602 add_address_entry (objfile
, obstack
,
15603 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
15604 addrmap_index_data
.previous_cu_index
);
15607 /* Add a list of partial symbols to SYMTAB. */
15610 write_psymbols (struct mapped_symtab
*symtab
,
15612 struct partial_symbol
**psymp
,
15614 offset_type cu_index
,
15617 for (; count
-- > 0; ++psymp
)
15619 void **slot
, *lookup
;
15621 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
15622 error (_("Ada is not currently supported by the index"));
15624 /* We only want to add a given psymbol once. However, we also
15625 want to account for whether it is global or static. So, we
15626 may add it twice, using slightly different values. */
15629 uintptr_t val
= 1 | (uintptr_t) *psymp
;
15631 lookup
= (void *) val
;
15636 /* Only add a given psymbol once. */
15637 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
15641 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
15646 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
15647 exception if there is an error. */
15650 write_obstack (FILE *file
, struct obstack
*obstack
)
15652 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
15654 != obstack_object_size (obstack
))
15655 error (_("couldn't data write to file"));
15658 /* Unlink a file if the argument is not NULL. */
15661 unlink_if_set (void *p
)
15663 char **filename
= p
;
15665 unlink (*filename
);
15668 /* A helper struct used when iterating over debug_types. */
15669 struct signatured_type_index_data
15671 struct objfile
*objfile
;
15672 struct mapped_symtab
*symtab
;
15673 struct obstack
*types_list
;
15678 /* A helper function that writes a single signatured_type to an
15682 write_one_signatured_type (void **slot
, void *d
)
15684 struct signatured_type_index_data
*info
= d
;
15685 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
15686 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
15687 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15690 write_psymbols (info
->symtab
,
15692 info
->objfile
->global_psymbols
.list
15693 + psymtab
->globals_offset
,
15694 psymtab
->n_global_syms
, info
->cu_index
,
15696 write_psymbols (info
->symtab
,
15698 info
->objfile
->static_psymbols
.list
15699 + psymtab
->statics_offset
,
15700 psymtab
->n_static_syms
, info
->cu_index
,
15703 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->offset
);
15704 obstack_grow (info
->types_list
, val
, 8);
15705 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
15706 obstack_grow (info
->types_list
, val
, 8);
15707 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
15708 obstack_grow (info
->types_list
, val
, 8);
15715 /* A cleanup function for an htab_t. */
15718 cleanup_htab (void *arg
)
15723 /* Create an index file for OBJFILE in the directory DIR. */
15726 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
15728 struct cleanup
*cleanup
;
15729 char *filename
, *cleanup_filename
;
15730 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
15731 struct obstack cu_list
, types_cu_list
;
15734 struct mapped_symtab
*symtab
;
15735 offset_type val
, size_of_contents
, total_len
;
15739 htab_t cu_index_htab
;
15740 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
15742 if (!objfile
->psymtabs
)
15744 if (dwarf2_per_objfile
->using_index
)
15745 error (_("Cannot use an index to create the index"));
15747 if (stat (objfile
->name
, &st
) < 0)
15748 perror_with_name (objfile
->name
);
15750 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
15751 INDEX_SUFFIX
, (char *) NULL
);
15752 cleanup
= make_cleanup (xfree
, filename
);
15754 out_file
= fopen (filename
, "wb");
15756 error (_("Can't open `%s' for writing"), filename
);
15758 cleanup_filename
= filename
;
15759 make_cleanup (unlink_if_set
, &cleanup_filename
);
15761 symtab
= create_mapped_symtab ();
15762 make_cleanup (cleanup_mapped_symtab
, symtab
);
15764 obstack_init (&addr_obstack
);
15765 make_cleanup_obstack_free (&addr_obstack
);
15767 obstack_init (&cu_list
);
15768 make_cleanup_obstack_free (&cu_list
);
15770 obstack_init (&types_cu_list
);
15771 make_cleanup_obstack_free (&types_cu_list
);
15773 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
15774 NULL
, xcalloc
, xfree
);
15775 make_cleanup (cleanup_htab
, psyms_seen
);
15777 /* While we're scanning CU's create a table that maps a psymtab pointer
15778 (which is what addrmap records) to its index (which is what is recorded
15779 in the index file). This will later be needed to write the address
15781 cu_index_htab
= htab_create_alloc (100,
15782 hash_psymtab_cu_index
,
15783 eq_psymtab_cu_index
,
15784 NULL
, xcalloc
, xfree
);
15785 make_cleanup (cleanup_htab
, cu_index_htab
);
15786 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
15787 xmalloc (sizeof (struct psymtab_cu_index_map
)
15788 * dwarf2_per_objfile
->n_comp_units
);
15789 make_cleanup (xfree
, psymtab_cu_index_map
);
15791 /* The CU list is already sorted, so we don't need to do additional
15792 work here. Also, the debug_types entries do not appear in
15793 all_comp_units, but only in their own hash table. */
15794 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
15796 struct dwarf2_per_cu_data
*per_cu
15797 = dwarf2_per_objfile
->all_comp_units
[i
];
15798 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15800 struct psymtab_cu_index_map
*map
;
15803 write_psymbols (symtab
,
15805 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15806 psymtab
->n_global_syms
, i
,
15808 write_psymbols (symtab
,
15810 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15811 psymtab
->n_static_syms
, i
,
15814 map
= &psymtab_cu_index_map
[i
];
15815 map
->psymtab
= psymtab
;
15817 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
15818 gdb_assert (slot
!= NULL
);
15819 gdb_assert (*slot
== NULL
);
15822 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
15823 obstack_grow (&cu_list
, val
, 8);
15824 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
15825 obstack_grow (&cu_list
, val
, 8);
15828 /* Dump the address map. */
15829 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
15831 /* Write out the .debug_type entries, if any. */
15832 if (dwarf2_per_objfile
->signatured_types
)
15834 struct signatured_type_index_data sig_data
;
15836 sig_data
.objfile
= objfile
;
15837 sig_data
.symtab
= symtab
;
15838 sig_data
.types_list
= &types_cu_list
;
15839 sig_data
.psyms_seen
= psyms_seen
;
15840 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
15841 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
15842 write_one_signatured_type
, &sig_data
);
15845 obstack_init (&constant_pool
);
15846 make_cleanup_obstack_free (&constant_pool
);
15847 obstack_init (&symtab_obstack
);
15848 make_cleanup_obstack_free (&symtab_obstack
);
15849 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
15851 obstack_init (&contents
);
15852 make_cleanup_obstack_free (&contents
);
15853 size_of_contents
= 6 * sizeof (offset_type
);
15854 total_len
= size_of_contents
;
15856 /* The version number. */
15857 val
= MAYBE_SWAP (4);
15858 obstack_grow (&contents
, &val
, sizeof (val
));
15860 /* The offset of the CU list from the start of the file. */
15861 val
= MAYBE_SWAP (total_len
);
15862 obstack_grow (&contents
, &val
, sizeof (val
));
15863 total_len
+= obstack_object_size (&cu_list
);
15865 /* The offset of the types CU list from the start of the file. */
15866 val
= MAYBE_SWAP (total_len
);
15867 obstack_grow (&contents
, &val
, sizeof (val
));
15868 total_len
+= obstack_object_size (&types_cu_list
);
15870 /* The offset of the address table from the start of the file. */
15871 val
= MAYBE_SWAP (total_len
);
15872 obstack_grow (&contents
, &val
, sizeof (val
));
15873 total_len
+= obstack_object_size (&addr_obstack
);
15875 /* The offset of the symbol table from the start of the file. */
15876 val
= MAYBE_SWAP (total_len
);
15877 obstack_grow (&contents
, &val
, sizeof (val
));
15878 total_len
+= obstack_object_size (&symtab_obstack
);
15880 /* The offset of the constant pool from the start of the file. */
15881 val
= MAYBE_SWAP (total_len
);
15882 obstack_grow (&contents
, &val
, sizeof (val
));
15883 total_len
+= obstack_object_size (&constant_pool
);
15885 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
15887 write_obstack (out_file
, &contents
);
15888 write_obstack (out_file
, &cu_list
);
15889 write_obstack (out_file
, &types_cu_list
);
15890 write_obstack (out_file
, &addr_obstack
);
15891 write_obstack (out_file
, &symtab_obstack
);
15892 write_obstack (out_file
, &constant_pool
);
15896 /* We want to keep the file, so we set cleanup_filename to NULL
15897 here. See unlink_if_set. */
15898 cleanup_filename
= NULL
;
15900 do_cleanups (cleanup
);
15903 /* The mapped index file format is designed to be directly mmap()able
15904 on any architecture. In most cases, a datum is represented using a
15905 little-endian 32-bit integer value, called an offset_type. Big
15906 endian machines must byte-swap the values before using them.
15907 Exceptions to this rule are noted. The data is laid out such that
15908 alignment is always respected.
15910 A mapped index consists of several sections.
15912 1. The file header. This is a sequence of values, of offset_type
15913 unless otherwise noted:
15915 [0] The version number, currently 4. Versions 1, 2 and 3 are
15917 [1] The offset, from the start of the file, of the CU list.
15918 [2] The offset, from the start of the file, of the types CU list.
15919 Note that this section can be empty, in which case this offset will
15920 be equal to the next offset.
15921 [3] The offset, from the start of the file, of the address section.
15922 [4] The offset, from the start of the file, of the symbol table.
15923 [5] The offset, from the start of the file, of the constant pool.
15925 2. The CU list. This is a sequence of pairs of 64-bit
15926 little-endian values, sorted by the CU offset. The first element
15927 in each pair is the offset of a CU in the .debug_info section. The
15928 second element in each pair is the length of that CU. References
15929 to a CU elsewhere in the map are done using a CU index, which is
15930 just the 0-based index into this table. Note that if there are
15931 type CUs, then conceptually CUs and type CUs form a single list for
15932 the purposes of CU indices.
15934 3. The types CU list. This is a sequence of triplets of 64-bit
15935 little-endian values. In a triplet, the first value is the CU
15936 offset, the second value is the type offset in the CU, and the
15937 third value is the type signature. The types CU list is not
15940 4. The address section. The address section consists of a sequence
15941 of address entries. Each address entry has three elements.
15942 [0] The low address. This is a 64-bit little-endian value.
15943 [1] The high address. This is a 64-bit little-endian value.
15944 Like DW_AT_high_pc, the value is one byte beyond the end.
15945 [2] The CU index. This is an offset_type value.
15947 5. The symbol table. This is a hash table. The size of the hash
15948 table is always a power of 2. The initial hash and the step are
15949 currently defined by the `find_slot' function.
15951 Each slot in the hash table consists of a pair of offset_type
15952 values. The first value is the offset of the symbol's name in the
15953 constant pool. The second value is the offset of the CU vector in
15956 If both values are 0, then this slot in the hash table is empty.
15957 This is ok because while 0 is a valid constant pool index, it
15958 cannot be a valid index for both a string and a CU vector.
15960 A string in the constant pool is stored as a \0-terminated string,
15963 A CU vector in the constant pool is a sequence of offset_type
15964 values. The first value is the number of CU indices in the vector.
15965 Each subsequent value is the index of a CU in the CU list. This
15966 element in the hash table is used to indicate which CUs define the
15969 6. The constant pool. This is simply a bunch of bytes. It is
15970 organized so that alignment is correct: CU vectors are stored
15971 first, followed by strings. */
15974 save_gdb_index_command (char *arg
, int from_tty
)
15976 struct objfile
*objfile
;
15979 error (_("usage: save gdb-index DIRECTORY"));
15981 ALL_OBJFILES (objfile
)
15985 /* If the objfile does not correspond to an actual file, skip it. */
15986 if (stat (objfile
->name
, &st
) < 0)
15989 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15990 if (dwarf2_per_objfile
)
15992 volatile struct gdb_exception except
;
15994 TRY_CATCH (except
, RETURN_MASK_ERROR
)
15996 write_psymtabs_to_index (objfile
, arg
);
15998 if (except
.reason
< 0)
15999 exception_fprintf (gdb_stderr
, except
,
16000 _("Error while writing index for `%s': "),
16008 int dwarf2_always_disassemble
;
16011 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
16012 struct cmd_list_element
*c
, const char *value
)
16014 fprintf_filtered (file
,
16015 _("Whether to always disassemble "
16016 "DWARF expressions is %s.\n"),
16020 void _initialize_dwarf2_read (void);
16023 _initialize_dwarf2_read (void)
16025 struct cmd_list_element
*c
;
16027 dwarf2_objfile_data_key
16028 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
16030 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
16031 Set DWARF 2 specific variables.\n\
16032 Configure DWARF 2 variables such as the cache size"),
16033 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
16034 0/*allow-unknown*/, &maintenance_set_cmdlist
);
16036 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
16037 Show DWARF 2 specific variables\n\
16038 Show DWARF 2 variables such as the cache size"),
16039 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
16040 0/*allow-unknown*/, &maintenance_show_cmdlist
);
16042 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
16043 &dwarf2_max_cache_age
, _("\
16044 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
16045 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
16046 A higher limit means that cached compilation units will be stored\n\
16047 in memory longer, and more total memory will be used. Zero disables\n\
16048 caching, which can slow down startup."),
16050 show_dwarf2_max_cache_age
,
16051 &set_dwarf2_cmdlist
,
16052 &show_dwarf2_cmdlist
);
16054 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
16055 &dwarf2_always_disassemble
, _("\
16056 Set whether `info address' always disassembles DWARF expressions."), _("\
16057 Show whether `info address' always disassembles DWARF expressions."), _("\
16058 When enabled, DWARF expressions are always printed in an assembly-like\n\
16059 syntax. When disabled, expressions will be printed in a more\n\
16060 conversational style, when possible."),
16062 show_dwarf2_always_disassemble
,
16063 &set_dwarf2_cmdlist
,
16064 &show_dwarf2_cmdlist
);
16066 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
16067 Set debugging of the dwarf2 DIE reader."), _("\
16068 Show debugging of the dwarf2 DIE reader."), _("\
16069 When enabled (non-zero), DIEs are dumped after they are read in.\n\
16070 The value is the maximum depth to print."),
16073 &setdebuglist
, &showdebuglist
);
16075 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
16077 Save a gdb-index file.\n\
16078 Usage: save gdb-index DIRECTORY"),
16080 set_cmd_completer (c
, filename_completer
);