1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
51 #include "typeprint.h"
54 #include "exceptions.h"
56 #include "completer.h"
63 #include "gdb_string.h"
64 #include "gdb_assert.h"
65 #include <sys/types.h>
72 #define MAP_FAILED ((void *) -1)
76 typedef struct symbol
*symbolp
;
80 /* .debug_info header for a compilation unit
81 Because of alignment constraints, this structure has padding and cannot
82 be mapped directly onto the beginning of the .debug_info section. */
83 typedef struct comp_unit_header
85 unsigned int length
; /* length of the .debug_info
87 unsigned short version
; /* version number -- 2 for DWARF
89 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
90 unsigned char addr_size
; /* byte size of an address -- 4 */
93 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
96 /* .debug_line statement program prologue
97 Because of alignment constraints, this structure has padding and cannot
98 be mapped directly onto the beginning of the .debug_info section. */
99 typedef struct statement_prologue
101 unsigned int total_length
; /* byte length of the statement
103 unsigned short version
; /* version number -- 2 for DWARF
105 unsigned int prologue_length
; /* # bytes between prologue &
107 unsigned char minimum_instruction_length
; /* byte size of
109 unsigned char default_is_stmt
; /* initial value of is_stmt
112 unsigned char line_range
;
113 unsigned char opcode_base
; /* number assigned to first special
115 unsigned char *standard_opcode_lengths
;
119 /* When non-zero, dump DIEs after they are read in. */
120 static int dwarf2_die_debug
= 0;
124 /* When set, the file that we're processing is known to have debugging
125 info for C++ namespaces. GCC 3.3.x did not produce this information,
126 but later versions do. */
128 static int processing_has_namespace_info
;
130 static const struct objfile_data
*dwarf2_objfile_data_key
;
132 struct dwarf2_section_info
138 /* True if we have tried to read this section. */
142 /* All offsets in the index are of this type. It must be
143 architecture-independent. */
144 typedef uint32_t offset_type
;
146 DEF_VEC_I (offset_type
);
148 /* A description of the mapped index. The file format is described in
149 a comment by the code that writes the index. */
152 /* Index data format version. */
155 /* The total length of the buffer. */
158 /* A pointer to the address table data. */
159 const gdb_byte
*address_table
;
161 /* Size of the address table data in bytes. */
162 offset_type address_table_size
;
164 /* The symbol table, implemented as a hash table. */
165 const offset_type
*symbol_table
;
167 /* Size in slots, each slot is 2 offset_types. */
168 offset_type symbol_table_slots
;
170 /* A pointer to the constant pool. */
171 const char *constant_pool
;
174 struct dwarf2_per_objfile
176 struct dwarf2_section_info info
;
177 struct dwarf2_section_info abbrev
;
178 struct dwarf2_section_info line
;
179 struct dwarf2_section_info loc
;
180 struct dwarf2_section_info macinfo
;
181 struct dwarf2_section_info str
;
182 struct dwarf2_section_info ranges
;
183 struct dwarf2_section_info types
;
184 struct dwarf2_section_info frame
;
185 struct dwarf2_section_info eh_frame
;
186 struct dwarf2_section_info gdb_index
;
189 struct objfile
*objfile
;
191 /* A list of all the compilation units. This is used to locate
192 the target compilation unit of a particular reference. */
193 struct dwarf2_per_cu_data
**all_comp_units
;
195 /* The number of compilation units in ALL_COMP_UNITS. */
198 /* The number of .debug_types-related CUs. */
199 int n_type_comp_units
;
201 /* The .debug_types-related CUs. */
202 struct dwarf2_per_cu_data
**type_comp_units
;
204 /* A chain of compilation units that are currently read in, so that
205 they can be freed later. */
206 struct dwarf2_per_cu_data
*read_in_chain
;
208 /* A table mapping .debug_types signatures to its signatured_type entry.
209 This is NULL if the .debug_types section hasn't been read in yet. */
210 htab_t signatured_types
;
212 /* A flag indicating wether this objfile has a section loaded at a
214 int has_section_at_zero
;
216 /* True if we are using the mapped index,
217 or we are faking it for OBJF_READNOW's sake. */
218 unsigned char using_index
;
220 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
221 struct mapped_index
*index_table
;
223 /* When using index_table, this keeps track of all quick_file_names entries.
224 TUs can share line table entries with CUs or other TUs, and there can be
225 a lot more TUs than unique line tables, so we maintain a separate table
226 of all line table entries to support the sharing. */
227 htab_t quick_file_names_table
;
229 /* Set during partial symbol reading, to prevent queueing of full
231 int reading_partial_symbols
;
233 /* Table mapping type .debug_info DIE offsets to types.
234 This is NULL if not allocated yet.
235 It (currently) makes sense to allocate debug_types_type_hash lazily.
236 To keep things simple we allocate both lazily. */
237 htab_t debug_info_type_hash
;
239 /* Table mapping type .debug_types DIE offsets to types.
240 This is NULL if not allocated yet. */
241 htab_t debug_types_type_hash
;
244 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
246 /* names of the debugging sections */
248 /* Note that if the debugging section has been compressed, it might
249 have a name like .zdebug_info. */
251 #define INFO_SECTION "debug_info"
252 #define ABBREV_SECTION "debug_abbrev"
253 #define LINE_SECTION "debug_line"
254 #define LOC_SECTION "debug_loc"
255 #define MACINFO_SECTION "debug_macinfo"
256 #define STR_SECTION "debug_str"
257 #define RANGES_SECTION "debug_ranges"
258 #define TYPES_SECTION "debug_types"
259 #define FRAME_SECTION "debug_frame"
260 #define EH_FRAME_SECTION "eh_frame"
261 #define GDB_INDEX_SECTION "gdb_index"
263 /* local data types */
265 /* We hold several abbreviation tables in memory at the same time. */
266 #ifndef ABBREV_HASH_SIZE
267 #define ABBREV_HASH_SIZE 121
270 /* The data in a compilation unit header, after target2host
271 translation, looks like this. */
272 struct comp_unit_head
276 unsigned char addr_size
;
277 unsigned char signed_addr_p
;
278 unsigned int abbrev_offset
;
280 /* Size of file offsets; either 4 or 8. */
281 unsigned int offset_size
;
283 /* Size of the length field; either 4 or 12. */
284 unsigned int initial_length_size
;
286 /* Offset to the first byte of this compilation unit header in the
287 .debug_info section, for resolving relative reference dies. */
290 /* Offset to first die in this cu from the start of the cu.
291 This will be the first byte following the compilation unit header. */
292 unsigned int first_die_offset
;
295 /* Type used for delaying computation of method physnames.
296 See comments for compute_delayed_physnames. */
297 struct delayed_method_info
299 /* The type to which the method is attached, i.e., its parent class. */
302 /* The index of the method in the type's function fieldlists. */
305 /* The index of the method in the fieldlist. */
308 /* The name of the DIE. */
311 /* The DIE associated with this method. */
312 struct die_info
*die
;
315 typedef struct delayed_method_info delayed_method_info
;
316 DEF_VEC_O (delayed_method_info
);
318 /* Internal state when decoding a particular compilation unit. */
321 /* The objfile containing this compilation unit. */
322 struct objfile
*objfile
;
324 /* The header of the compilation unit. */
325 struct comp_unit_head header
;
327 /* Base address of this compilation unit. */
328 CORE_ADDR base_address
;
330 /* Non-zero if base_address has been set. */
333 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
335 /* The language we are debugging. */
336 enum language language
;
337 const struct language_defn
*language_defn
;
339 const char *producer
;
341 /* The generic symbol table building routines have separate lists for
342 file scope symbols and all all other scopes (local scopes). So
343 we need to select the right one to pass to add_symbol_to_list().
344 We do it by keeping a pointer to the correct list in list_in_scope.
346 FIXME: The original dwarf code just treated the file scope as the
347 first local scope, and all other local scopes as nested local
348 scopes, and worked fine. Check to see if we really need to
349 distinguish these in buildsym.c. */
350 struct pending
**list_in_scope
;
352 /* DWARF abbreviation table associated with this compilation unit. */
353 struct abbrev_info
**dwarf2_abbrevs
;
355 /* Storage for the abbrev table. */
356 struct obstack abbrev_obstack
;
358 /* Hash table holding all the loaded partial DIEs. */
361 /* Storage for things with the same lifetime as this read-in compilation
362 unit, including partial DIEs. */
363 struct obstack comp_unit_obstack
;
365 /* When multiple dwarf2_cu structures are living in memory, this field
366 chains them all together, so that they can be released efficiently.
367 We will probably also want a generation counter so that most-recently-used
368 compilation units are cached... */
369 struct dwarf2_per_cu_data
*read_in_chain
;
371 /* Backchain to our per_cu entry if the tree has been built. */
372 struct dwarf2_per_cu_data
*per_cu
;
374 /* How many compilation units ago was this CU last referenced? */
377 /* A hash table of die offsets for following references. */
380 /* Full DIEs if read in. */
381 struct die_info
*dies
;
383 /* A set of pointers to dwarf2_per_cu_data objects for compilation
384 units referenced by this one. Only set during full symbol processing;
385 partial symbol tables do not have dependencies. */
388 /* Header data from the line table, during full symbol processing. */
389 struct line_header
*line_header
;
391 /* A list of methods which need to have physnames computed
392 after all type information has been read. */
393 VEC (delayed_method_info
) *method_list
;
395 /* Mark used when releasing cached dies. */
396 unsigned int mark
: 1;
398 /* This flag will be set if this compilation unit might include
399 inter-compilation-unit references. */
400 unsigned int has_form_ref_addr
: 1;
402 /* This flag will be set if this compilation unit includes any
403 DW_TAG_namespace DIEs. If we know that there are explicit
404 DIEs for namespaces, we don't need to try to infer them
405 from mangled names. */
406 unsigned int has_namespace_info
: 1;
408 /* This CU references .debug_loc. See the symtab->locations_valid field.
409 This test is imperfect as there may exist optimized debug code not using
410 any location list and still facing inlining issues if handled as
411 unoptimized code. For a future better test see GCC PR other/32998. */
413 unsigned int has_loclist
: 1;
416 /* Persistent data held for a compilation unit, even when not
417 processing it. We put a pointer to this structure in the
418 read_symtab_private field of the psymtab. If we encounter
419 inter-compilation-unit references, we also maintain a sorted
420 list of all compilation units. */
422 struct dwarf2_per_cu_data
424 /* The start offset and length of this compilation unit. 2**29-1
425 bytes should suffice to store the length of any compilation unit
426 - if it doesn't, GDB will fall over anyway.
427 NOTE: Unlike comp_unit_head.length, this length includes
428 initial_length_size. */
430 unsigned int length
: 29;
432 /* Flag indicating this compilation unit will be read in before
433 any of the current compilation units are processed. */
434 unsigned int queued
: 1;
436 /* This flag will be set if we need to load absolutely all DIEs
437 for this compilation unit, instead of just the ones we think
438 are interesting. It gets set if we look for a DIE in the
439 hash table and don't find it. */
440 unsigned int load_all_dies
: 1;
442 /* Non-zero if this CU is from .debug_types.
443 Otherwise it's from .debug_info. */
444 unsigned int from_debug_types
: 1;
446 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
447 of the CU cache it gets reset to NULL again. */
448 struct dwarf2_cu
*cu
;
450 /* The corresponding objfile. */
451 struct objfile
*objfile
;
453 /* When using partial symbol tables, the 'psymtab' field is active.
454 Otherwise the 'quick' field is active. */
457 /* The partial symbol table associated with this compilation unit,
458 or NULL for partial units (which do not have an associated
460 struct partial_symtab
*psymtab
;
462 /* Data needed by the "quick" functions. */
463 struct dwarf2_per_cu_quick_data
*quick
;
467 /* Entry in the signatured_types hash table. */
469 struct signatured_type
473 /* Offset in .debug_types of the TU (type_unit) for this type. */
476 /* Offset in .debug_types of the type defined by this TU. */
477 unsigned int type_offset
;
479 /* The CU(/TU) of this type. */
480 struct dwarf2_per_cu_data per_cu
;
483 /* Struct used to pass misc. parameters to read_die_and_children, et
484 al. which are used for both .debug_info and .debug_types dies.
485 All parameters here are unchanging for the life of the call. This
486 struct exists to abstract away the constant parameters of die
489 struct die_reader_specs
491 /* The bfd of this objfile. */
494 /* The CU of the DIE we are parsing. */
495 struct dwarf2_cu
*cu
;
497 /* Pointer to start of section buffer.
498 This is either the start of .debug_info or .debug_types. */
499 const gdb_byte
*buffer
;
502 /* The line number information for a compilation unit (found in the
503 .debug_line section) begins with a "statement program header",
504 which contains the following information. */
507 unsigned int total_length
;
508 unsigned short version
;
509 unsigned int header_length
;
510 unsigned char minimum_instruction_length
;
511 unsigned char maximum_ops_per_instruction
;
512 unsigned char default_is_stmt
;
514 unsigned char line_range
;
515 unsigned char opcode_base
;
517 /* standard_opcode_lengths[i] is the number of operands for the
518 standard opcode whose value is i. This means that
519 standard_opcode_lengths[0] is unused, and the last meaningful
520 element is standard_opcode_lengths[opcode_base - 1]. */
521 unsigned char *standard_opcode_lengths
;
523 /* The include_directories table. NOTE! These strings are not
524 allocated with xmalloc; instead, they are pointers into
525 debug_line_buffer. If you try to free them, `free' will get
527 unsigned int num_include_dirs
, include_dirs_size
;
530 /* The file_names table. NOTE! These strings are not allocated
531 with xmalloc; instead, they are pointers into debug_line_buffer.
532 Don't try to free them directly. */
533 unsigned int num_file_names
, file_names_size
;
537 unsigned int dir_index
;
538 unsigned int mod_time
;
540 int included_p
; /* Non-zero if referenced by the Line Number Program. */
541 struct symtab
*symtab
; /* The associated symbol table, if any. */
544 /* The start and end of the statement program following this
545 header. These point into dwarf2_per_objfile->line_buffer. */
546 gdb_byte
*statement_program_start
, *statement_program_end
;
549 /* When we construct a partial symbol table entry we only
550 need this much information. */
551 struct partial_die_info
553 /* Offset of this DIE. */
556 /* DWARF-2 tag for this DIE. */
557 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
559 /* Assorted flags describing the data found in this DIE. */
560 unsigned int has_children
: 1;
561 unsigned int is_external
: 1;
562 unsigned int is_declaration
: 1;
563 unsigned int has_type
: 1;
564 unsigned int has_specification
: 1;
565 unsigned int has_pc_info
: 1;
567 /* Flag set if the SCOPE field of this structure has been
569 unsigned int scope_set
: 1;
571 /* Flag set if the DIE has a byte_size attribute. */
572 unsigned int has_byte_size
: 1;
574 /* Flag set if any of the DIE's children are template arguments. */
575 unsigned int has_template_arguments
: 1;
577 /* Flag set if fixup_partial_die has been called on this die. */
578 unsigned int fixup_called
: 1;
580 /* The name of this DIE. Normally the value of DW_AT_name, but
581 sometimes a default name for unnamed DIEs. */
584 /* The linkage name, if present. */
585 const char *linkage_name
;
587 /* The scope to prepend to our children. This is generally
588 allocated on the comp_unit_obstack, so will disappear
589 when this compilation unit leaves the cache. */
592 /* The location description associated with this DIE, if any. */
593 struct dwarf_block
*locdesc
;
595 /* If HAS_PC_INFO, the PC range associated with this DIE. */
599 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
600 DW_AT_sibling, if any. */
601 /* NOTE: This member isn't strictly necessary, read_partial_die could
602 return DW_AT_sibling values to its caller load_partial_dies. */
605 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
606 DW_AT_specification (or DW_AT_abstract_origin or
608 unsigned int spec_offset
;
610 /* Pointers to this DIE's parent, first child, and next sibling,
612 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
615 /* This data structure holds the information of an abbrev. */
618 unsigned int number
; /* number identifying abbrev */
619 enum dwarf_tag tag
; /* dwarf tag */
620 unsigned short has_children
; /* boolean */
621 unsigned short num_attrs
; /* number of attributes */
622 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
623 struct abbrev_info
*next
; /* next in chain */
628 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
629 ENUM_BITFIELD(dwarf_form
) form
: 16;
632 /* Attributes have a name and a value. */
635 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
636 ENUM_BITFIELD(dwarf_form
) form
: 15;
638 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
639 field should be in u.str (existing only for DW_STRING) but it is kept
640 here for better struct attribute alignment. */
641 unsigned int string_is_canonical
: 1;
646 struct dwarf_block
*blk
;
650 struct signatured_type
*signatured_type
;
655 /* This data structure holds a complete die structure. */
658 /* DWARF-2 tag for this DIE. */
659 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
661 /* Number of attributes */
662 unsigned char num_attrs
;
664 /* True if we're presently building the full type name for the
665 type derived from this DIE. */
666 unsigned char building_fullname
: 1;
671 /* Offset in .debug_info or .debug_types section. */
674 /* The dies in a compilation unit form an n-ary tree. PARENT
675 points to this die's parent; CHILD points to the first child of
676 this node; and all the children of a given node are chained
677 together via their SIBLING fields. */
678 struct die_info
*child
; /* Its first child, if any. */
679 struct die_info
*sibling
; /* Its next sibling, if any. */
680 struct die_info
*parent
; /* Its parent, if any. */
682 /* An array of attributes, with NUM_ATTRS elements. There may be
683 zero, but it's not common and zero-sized arrays are not
684 sufficiently portable C. */
685 struct attribute attrs
[1];
688 struct function_range
691 CORE_ADDR lowpc
, highpc
;
693 struct function_range
*next
;
696 /* Get at parts of an attribute structure. */
698 #define DW_STRING(attr) ((attr)->u.str)
699 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
700 #define DW_UNSND(attr) ((attr)->u.unsnd)
701 #define DW_BLOCK(attr) ((attr)->u.blk)
702 #define DW_SND(attr) ((attr)->u.snd)
703 #define DW_ADDR(attr) ((attr)->u.addr)
704 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
706 /* Blocks are a bunch of untyped bytes. */
713 #ifndef ATTR_ALLOC_CHUNK
714 #define ATTR_ALLOC_CHUNK 4
717 /* Allocate fields for structs, unions and enums in this size. */
718 #ifndef DW_FIELD_ALLOC_CHUNK
719 #define DW_FIELD_ALLOC_CHUNK 4
722 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
723 but this would require a corresponding change in unpack_field_as_long
725 static int bits_per_byte
= 8;
727 /* The routines that read and process dies for a C struct or C++ class
728 pass lists of data member fields and lists of member function fields
729 in an instance of a field_info structure, as defined below. */
732 /* List of data member and baseclasses fields. */
735 struct nextfield
*next
;
740 *fields
, *baseclasses
;
742 /* Number of fields (including baseclasses). */
745 /* Number of baseclasses. */
748 /* Set if the accesibility of one of the fields is not public. */
749 int non_public_fields
;
751 /* Member function fields array, entries are allocated in the order they
752 are encountered in the object file. */
755 struct nextfnfield
*next
;
756 struct fn_field fnfield
;
760 /* Member function fieldlist array, contains name of possibly overloaded
761 member function, number of overloaded member functions and a pointer
762 to the head of the member function field chain. */
767 struct nextfnfield
*head
;
771 /* Number of entries in the fnfieldlists array. */
774 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
775 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
776 struct typedef_field_list
778 struct typedef_field field
;
779 struct typedef_field_list
*next
;
782 unsigned typedef_field_list_count
;
785 /* One item on the queue of compilation units to read in full symbols
787 struct dwarf2_queue_item
789 struct dwarf2_per_cu_data
*per_cu
;
790 struct dwarf2_queue_item
*next
;
793 /* The current queue. */
794 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
796 /* Loaded secondary compilation units are kept in memory until they
797 have not been referenced for the processing of this many
798 compilation units. Set this to zero to disable caching. Cache
799 sizes of up to at least twenty will improve startup time for
800 typical inter-CU-reference binaries, at an obvious memory cost. */
801 static int dwarf2_max_cache_age
= 5;
803 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
804 struct cmd_list_element
*c
, const char *value
)
806 fprintf_filtered (file
, _("The upper bound on the age of cached "
807 "dwarf2 compilation units is %s.\n"),
812 /* Various complaints about symbol reading that don't abort the process. */
815 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
817 complaint (&symfile_complaints
,
818 _("statement list doesn't fit in .debug_line section"));
822 dwarf2_debug_line_missing_file_complaint (void)
824 complaint (&symfile_complaints
,
825 _(".debug_line section has line data without a file"));
829 dwarf2_debug_line_missing_end_sequence_complaint (void)
831 complaint (&symfile_complaints
,
832 _(".debug_line section has line "
833 "program sequence without an end"));
837 dwarf2_complex_location_expr_complaint (void)
839 complaint (&symfile_complaints
, _("location expression too complex"));
843 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
846 complaint (&symfile_complaints
,
847 _("const value length mismatch for '%s', got %d, expected %d"),
852 dwarf2_macros_too_long_complaint (void)
854 complaint (&symfile_complaints
,
855 _("macro info runs off end of `.debug_macinfo' section"));
859 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
861 complaint (&symfile_complaints
,
862 _("macro debug info contains a "
863 "malformed macro definition:\n`%s'"),
868 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
870 complaint (&symfile_complaints
,
871 _("invalid attribute class or form for '%s' in '%s'"),
875 /* local function prototypes */
877 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
879 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
882 static void dwarf2_build_psymtabs_hard (struct objfile
*);
884 static void scan_partial_symbols (struct partial_die_info
*,
885 CORE_ADDR
*, CORE_ADDR
*,
886 int, struct dwarf2_cu
*);
888 static void add_partial_symbol (struct partial_die_info
*,
891 static void add_partial_namespace (struct partial_die_info
*pdi
,
892 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
893 int need_pc
, struct dwarf2_cu
*cu
);
895 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
896 CORE_ADDR
*highpc
, int need_pc
,
897 struct dwarf2_cu
*cu
);
899 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
900 struct dwarf2_cu
*cu
);
902 static void add_partial_subprogram (struct partial_die_info
*pdi
,
903 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
904 int need_pc
, struct dwarf2_cu
*cu
);
906 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
907 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
908 bfd
*abfd
, struct dwarf2_cu
*cu
);
910 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
912 static void psymtab_to_symtab_1 (struct partial_symtab
*);
914 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
916 static void dwarf2_free_abbrev_table (void *);
918 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
921 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
924 static struct partial_die_info
*load_partial_dies (bfd
*,
925 gdb_byte
*, gdb_byte
*,
926 int, struct dwarf2_cu
*);
928 static gdb_byte
*read_partial_die (struct partial_die_info
*,
929 struct abbrev_info
*abbrev
,
931 gdb_byte
*, gdb_byte
*,
934 static struct partial_die_info
*find_partial_die (unsigned int,
937 static void fixup_partial_die (struct partial_die_info
*,
940 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
941 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
943 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
944 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
946 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
948 static int read_1_signed_byte (bfd
*, gdb_byte
*);
950 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
952 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
954 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
956 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
959 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
961 static LONGEST read_checked_initial_length_and_offset
962 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
963 unsigned int *, unsigned int *);
965 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
968 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
970 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
972 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
974 static char *read_indirect_string (bfd
*, gdb_byte
*,
975 const struct comp_unit_head
*,
978 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
980 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
982 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
984 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
986 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
989 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
993 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
994 struct dwarf2_cu
*cu
);
996 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
998 static struct die_info
*die_specification (struct die_info
*die
,
999 struct dwarf2_cu
**);
1001 static void free_line_header (struct line_header
*lh
);
1003 static void add_file_name (struct line_header
*, char *, unsigned int,
1004 unsigned int, unsigned int);
1006 static struct line_header
*(dwarf_decode_line_header
1007 (unsigned int offset
,
1008 bfd
*abfd
, struct dwarf2_cu
*cu
));
1010 static void dwarf_decode_lines (struct line_header
*, const char *, bfd
*,
1011 struct dwarf2_cu
*, struct partial_symtab
*);
1013 static void dwarf2_start_subfile (char *, const char *, const char *);
1015 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1016 struct dwarf2_cu
*);
1018 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1019 struct dwarf2_cu
*, struct symbol
*);
1021 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1022 struct dwarf2_cu
*);
1024 static void dwarf2_const_value_attr (struct attribute
*attr
,
1027 struct obstack
*obstack
,
1028 struct dwarf2_cu
*cu
, long *value
,
1030 struct dwarf2_locexpr_baton
**baton
);
1032 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1034 static int need_gnat_info (struct dwarf2_cu
*);
1036 static struct type
*die_descriptive_type (struct die_info
*,
1037 struct dwarf2_cu
*);
1039 static void set_descriptive_type (struct type
*, struct die_info
*,
1040 struct dwarf2_cu
*);
1042 static struct type
*die_containing_type (struct die_info
*,
1043 struct dwarf2_cu
*);
1045 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1046 struct dwarf2_cu
*);
1048 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1050 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1052 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1054 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1055 const char *suffix
, int physname
,
1056 struct dwarf2_cu
*cu
);
1058 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1060 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1062 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1064 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1066 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1067 struct dwarf2_cu
*, struct partial_symtab
*);
1069 static int dwarf2_get_pc_bounds (struct die_info
*,
1070 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1071 struct partial_symtab
*);
1073 static void get_scope_pc_bounds (struct die_info
*,
1074 CORE_ADDR
*, CORE_ADDR
*,
1075 struct dwarf2_cu
*);
1077 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1078 CORE_ADDR
, struct dwarf2_cu
*);
1080 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1081 struct dwarf2_cu
*);
1083 static void dwarf2_attach_fields_to_type (struct field_info
*,
1084 struct type
*, struct dwarf2_cu
*);
1086 static void dwarf2_add_member_fn (struct field_info
*,
1087 struct die_info
*, struct type
*,
1088 struct dwarf2_cu
*);
1090 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1092 struct dwarf2_cu
*);
1094 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1096 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1098 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1100 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1102 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1104 static struct type
*read_module_type (struct die_info
*die
,
1105 struct dwarf2_cu
*cu
);
1107 static const char *namespace_name (struct die_info
*die
,
1108 int *is_anonymous
, struct dwarf2_cu
*);
1110 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1112 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1114 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1115 struct dwarf2_cu
*);
1117 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1119 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1121 gdb_byte
**new_info_ptr
,
1122 struct die_info
*parent
);
1124 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1126 gdb_byte
**new_info_ptr
,
1127 struct die_info
*parent
);
1129 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1131 gdb_byte
**new_info_ptr
,
1132 struct die_info
*parent
);
1134 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1135 struct die_info
**, gdb_byte
*,
1138 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1140 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1143 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1145 static const char *dwarf2_full_name (char *name
,
1146 struct die_info
*die
,
1147 struct dwarf2_cu
*cu
);
1149 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1150 struct dwarf2_cu
**);
1152 static char *dwarf_tag_name (unsigned int);
1154 static char *dwarf_attr_name (unsigned int);
1156 static char *dwarf_form_name (unsigned int);
1158 static char *dwarf_bool_name (unsigned int);
1160 static char *dwarf_type_encoding_name (unsigned int);
1163 static char *dwarf_cfi_name (unsigned int);
1166 static struct die_info
*sibling_die (struct die_info
*);
1168 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1170 static void dump_die_for_error (struct die_info
*);
1172 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1175 /*static*/ void dump_die (struct die_info
*, int max_level
);
1177 static void store_in_ref_table (struct die_info
*,
1178 struct dwarf2_cu
*);
1180 static int is_ref_attr (struct attribute
*);
1182 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1184 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1186 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1188 struct dwarf2_cu
**);
1190 static struct die_info
*follow_die_ref (struct die_info
*,
1192 struct dwarf2_cu
**);
1194 static struct die_info
*follow_die_sig (struct die_info
*,
1196 struct dwarf2_cu
**);
1198 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1199 unsigned int offset
);
1201 static void read_signatured_type (struct objfile
*,
1202 struct signatured_type
*type_sig
);
1204 /* memory allocation interface */
1206 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1208 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1210 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1212 static void initialize_cu_func_list (struct dwarf2_cu
*);
1214 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1215 struct dwarf2_cu
*);
1217 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1218 char *, bfd
*, struct dwarf2_cu
*);
1220 static int attr_form_is_block (struct attribute
*);
1222 static int attr_form_is_section_offset (struct attribute
*);
1224 static int attr_form_is_constant (struct attribute
*);
1226 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1227 struct dwarf2_loclist_baton
*baton
,
1228 struct attribute
*attr
);
1230 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1232 struct dwarf2_cu
*cu
);
1234 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1235 struct abbrev_info
*abbrev
,
1236 struct dwarf2_cu
*cu
);
1238 static void free_stack_comp_unit (void *);
1240 static hashval_t
partial_die_hash (const void *item
);
1242 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1244 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1245 (unsigned int offset
, struct objfile
*objfile
);
1247 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1248 (unsigned int offset
, struct objfile
*objfile
);
1250 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1251 struct objfile
*objfile
);
1253 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1254 struct die_info
*comp_unit_die
);
1256 static void free_one_comp_unit (void *);
1258 static void free_cached_comp_units (void *);
1260 static void age_cached_comp_units (void);
1262 static void free_one_cached_comp_unit (void *);
1264 static struct type
*set_die_type (struct die_info
*, struct type
*,
1265 struct dwarf2_cu
*);
1267 static void create_all_comp_units (struct objfile
*);
1269 static int create_debug_types_hash_table (struct objfile
*objfile
);
1271 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1274 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1276 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1277 struct dwarf2_per_cu_data
*);
1279 static void dwarf2_mark (struct dwarf2_cu
*);
1281 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1283 static struct type
*get_die_type_at_offset (unsigned int,
1284 struct dwarf2_per_cu_data
*per_cu
);
1286 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1288 static void dwarf2_release_queue (void *dummy
);
1290 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1291 struct objfile
*objfile
);
1293 static void process_queue (struct objfile
*objfile
);
1295 static void find_file_and_directory (struct die_info
*die
,
1296 struct dwarf2_cu
*cu
,
1297 char **name
, char **comp_dir
);
1299 static char *file_full_name (int file
, struct line_header
*lh
,
1300 const char *comp_dir
);
1302 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1305 unsigned int buffer_size
,
1308 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1309 struct dwarf2_cu
*cu
);
1311 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1315 /* Convert VALUE between big- and little-endian. */
1317 byte_swap (offset_type value
)
1321 result
= (value
& 0xff) << 24;
1322 result
|= (value
& 0xff00) << 8;
1323 result
|= (value
& 0xff0000) >> 8;
1324 result
|= (value
& 0xff000000) >> 24;
1328 #define MAYBE_SWAP(V) byte_swap (V)
1331 #define MAYBE_SWAP(V) (V)
1332 #endif /* WORDS_BIGENDIAN */
1334 /* The suffix for an index file. */
1335 #define INDEX_SUFFIX ".gdb-index"
1337 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1338 struct dwarf2_cu
*cu
);
1340 /* Try to locate the sections we need for DWARF 2 debugging
1341 information and return true if we have enough to do something. */
1344 dwarf2_has_info (struct objfile
*objfile
)
1346 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1347 if (!dwarf2_per_objfile
)
1349 /* Initialize per-objfile state. */
1350 struct dwarf2_per_objfile
*data
1351 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1353 memset (data
, 0, sizeof (*data
));
1354 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1355 dwarf2_per_objfile
= data
;
1357 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1358 dwarf2_per_objfile
->objfile
= objfile
;
1360 return (dwarf2_per_objfile
->info
.asection
!= NULL
1361 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1364 /* When loading sections, we can either look for ".<name>", or for
1365 * ".z<name>", which indicates a compressed section. */
1368 section_is_p (const char *section_name
, const char *name
)
1370 return (section_name
[0] == '.'
1371 && (strcmp (section_name
+ 1, name
) == 0
1372 || (section_name
[1] == 'z'
1373 && strcmp (section_name
+ 2, name
) == 0)));
1376 /* This function is mapped across the sections and remembers the
1377 offset and size of each of the debugging sections we are interested
1381 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1383 if (section_is_p (sectp
->name
, INFO_SECTION
))
1385 dwarf2_per_objfile
->info
.asection
= sectp
;
1386 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1388 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1390 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1391 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1393 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1395 dwarf2_per_objfile
->line
.asection
= sectp
;
1396 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1398 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1400 dwarf2_per_objfile
->loc
.asection
= sectp
;
1401 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1403 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1405 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1406 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1408 else if (section_is_p (sectp
->name
, STR_SECTION
))
1410 dwarf2_per_objfile
->str
.asection
= sectp
;
1411 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1413 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1415 dwarf2_per_objfile
->frame
.asection
= sectp
;
1416 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1418 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1420 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1422 if (aflag
& SEC_HAS_CONTENTS
)
1424 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1425 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1428 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1430 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1431 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1433 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1435 dwarf2_per_objfile
->types
.asection
= sectp
;
1436 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1438 else if (section_is_p (sectp
->name
, GDB_INDEX_SECTION
))
1440 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1441 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1444 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1445 && bfd_section_vma (abfd
, sectp
) == 0)
1446 dwarf2_per_objfile
->has_section_at_zero
= 1;
1449 /* Decompress a section that was compressed using zlib. Store the
1450 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1453 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1454 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1456 bfd
*abfd
= objfile
->obfd
;
1458 error (_("Support for zlib-compressed DWARF data (from '%s') "
1459 "is disabled in this copy of GDB"),
1460 bfd_get_filename (abfd
));
1462 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1463 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1464 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1465 bfd_size_type uncompressed_size
;
1466 gdb_byte
*uncompressed_buffer
;
1469 int header_size
= 12;
1471 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1472 || bfd_bread (compressed_buffer
,
1473 compressed_size
, abfd
) != compressed_size
)
1474 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1475 bfd_get_filename (abfd
));
1477 /* Read the zlib header. In this case, it should be "ZLIB" followed
1478 by the uncompressed section size, 8 bytes in big-endian order. */
1479 if (compressed_size
< header_size
1480 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1481 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1482 bfd_get_filename (abfd
));
1483 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1484 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1485 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1486 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1487 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1488 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1489 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1490 uncompressed_size
+= compressed_buffer
[11];
1492 /* It is possible the section consists of several compressed
1493 buffers concatenated together, so we uncompress in a loop. */
1497 strm
.avail_in
= compressed_size
- header_size
;
1498 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1499 strm
.avail_out
= uncompressed_size
;
1500 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1502 rc
= inflateInit (&strm
);
1503 while (strm
.avail_in
> 0)
1506 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1507 bfd_get_filename (abfd
), rc
);
1508 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1509 + (uncompressed_size
- strm
.avail_out
));
1510 rc
= inflate (&strm
, Z_FINISH
);
1511 if (rc
!= Z_STREAM_END
)
1512 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1513 bfd_get_filename (abfd
), rc
);
1514 rc
= inflateReset (&strm
);
1516 rc
= inflateEnd (&strm
);
1518 || strm
.avail_out
!= 0)
1519 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1520 bfd_get_filename (abfd
), rc
);
1522 do_cleanups (cleanup
);
1523 *outbuf
= uncompressed_buffer
;
1524 *outsize
= uncompressed_size
;
1528 /* A helper function that decides whether a section is empty. */
1531 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1533 return info
->asection
== NULL
|| info
->size
== 0;
1536 /* Read the contents of the section SECTP from object file specified by
1537 OBJFILE, store info about the section into INFO.
1538 If the section is compressed, uncompress it before returning. */
1541 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1543 bfd
*abfd
= objfile
->obfd
;
1544 asection
*sectp
= info
->asection
;
1545 gdb_byte
*buf
, *retbuf
;
1546 unsigned char header
[4];
1550 info
->buffer
= NULL
;
1551 info
->was_mmapped
= 0;
1554 if (dwarf2_section_empty_p (info
))
1557 /* Check if the file has a 4-byte header indicating compression. */
1558 if (info
->size
> sizeof (header
)
1559 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1560 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1562 /* Upon decompression, update the buffer and its size. */
1563 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1565 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1573 pagesize
= getpagesize ();
1575 /* Only try to mmap sections which are large enough: we don't want to
1576 waste space due to fragmentation. Also, only try mmap for sections
1577 without relocations. */
1579 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1581 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1582 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1583 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1584 MAP_PRIVATE
, pg_offset
);
1586 if (retbuf
!= MAP_FAILED
)
1588 info
->was_mmapped
= 1;
1589 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1590 #if HAVE_POSIX_MADVISE
1591 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1598 /* If we get here, we are a normal, not-compressed section. */
1600 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1602 /* When debugging .o files, we may need to apply relocations; see
1603 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1604 We never compress sections in .o files, so we only need to
1605 try this when the section is not compressed. */
1606 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1609 info
->buffer
= retbuf
;
1613 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1614 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1615 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1616 bfd_get_filename (abfd
));
1619 /* A helper function that returns the size of a section in a safe way.
1620 If you are positive that the section has been read before using the
1621 size, then it is safe to refer to the dwarf2_section_info object's
1622 "size" field directly. In other cases, you must call this
1623 function, because for compressed sections the size field is not set
1624 correctly until the section has been read. */
1626 static bfd_size_type
1627 dwarf2_section_size (struct objfile
*objfile
,
1628 struct dwarf2_section_info
*info
)
1631 dwarf2_read_section (objfile
, info
);
1635 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1639 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1640 asection
**sectp
, gdb_byte
**bufp
,
1641 bfd_size_type
*sizep
)
1643 struct dwarf2_per_objfile
*data
1644 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1645 struct dwarf2_section_info
*info
;
1647 /* We may see an objfile without any DWARF, in which case we just
1656 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1657 info
= &data
->eh_frame
;
1658 else if (section_is_p (section_name
, FRAME_SECTION
))
1659 info
= &data
->frame
;
1661 gdb_assert_not_reached ("unexpected section");
1663 dwarf2_read_section (objfile
, info
);
1665 *sectp
= info
->asection
;
1666 *bufp
= info
->buffer
;
1667 *sizep
= info
->size
;
1671 /* DWARF quick_symbols_functions support. */
1673 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1674 unique line tables, so we maintain a separate table of all .debug_line
1675 derived entries to support the sharing.
1676 All the quick functions need is the list of file names. We discard the
1677 line_header when we're done and don't need to record it here. */
1678 struct quick_file_names
1680 /* The offset in .debug_line of the line table. We hash on this. */
1681 unsigned int offset
;
1683 /* The number of entries in file_names, real_names. */
1684 unsigned int num_file_names
;
1686 /* The file names from the line table, after being run through
1688 const char **file_names
;
1690 /* The file names from the line table after being run through
1691 gdb_realpath. These are computed lazily. */
1692 const char **real_names
;
1695 /* When using the index (and thus not using psymtabs), each CU has an
1696 object of this type. This is used to hold information needed by
1697 the various "quick" methods. */
1698 struct dwarf2_per_cu_quick_data
1700 /* The file table. This can be NULL if there was no file table
1701 or it's currently not read in.
1702 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1703 struct quick_file_names
*file_names
;
1705 /* The corresponding symbol table. This is NULL if symbols for this
1706 CU have not yet been read. */
1707 struct symtab
*symtab
;
1709 /* A temporary mark bit used when iterating over all CUs in
1710 expand_symtabs_matching. */
1711 unsigned int mark
: 1;
1713 /* True if we've tried to read the file table and found there isn't one.
1714 There will be no point in trying to read it again next time. */
1715 unsigned int no_file_data
: 1;
1718 /* Hash function for a quick_file_names. */
1721 hash_file_name_entry (const void *e
)
1723 const struct quick_file_names
*file_data
= e
;
1725 return file_data
->offset
;
1728 /* Equality function for a quick_file_names. */
1731 eq_file_name_entry (const void *a
, const void *b
)
1733 const struct quick_file_names
*ea
= a
;
1734 const struct quick_file_names
*eb
= b
;
1736 return ea
->offset
== eb
->offset
;
1739 /* Delete function for a quick_file_names. */
1742 delete_file_name_entry (void *e
)
1744 struct quick_file_names
*file_data
= e
;
1747 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1749 xfree ((void*) file_data
->file_names
[i
]);
1750 if (file_data
->real_names
)
1751 xfree ((void*) file_data
->real_names
[i
]);
1754 /* The space for the struct itself lives on objfile_obstack,
1755 so we don't free it here. */
1758 /* Create a quick_file_names hash table. */
1761 create_quick_file_names_table (unsigned int nr_initial_entries
)
1763 return htab_create_alloc (nr_initial_entries
,
1764 hash_file_name_entry
, eq_file_name_entry
,
1765 delete_file_name_entry
, xcalloc
, xfree
);
1768 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1772 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1773 struct dwarf2_per_cu_data
*per_cu
)
1775 struct cleanup
*back_to
;
1777 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1779 queue_comp_unit (per_cu
, objfile
);
1781 if (per_cu
->from_debug_types
)
1782 read_signatured_type_at_offset (objfile
, per_cu
->offset
);
1784 load_full_comp_unit (per_cu
, objfile
);
1786 process_queue (objfile
);
1788 /* Age the cache, releasing compilation units that have not
1789 been used recently. */
1790 age_cached_comp_units ();
1792 do_cleanups (back_to
);
1795 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1796 the objfile from which this CU came. Returns the resulting symbol
1799 static struct symtab
*
1800 dw2_instantiate_symtab (struct objfile
*objfile
,
1801 struct dwarf2_per_cu_data
*per_cu
)
1803 if (!per_cu
->v
.quick
->symtab
)
1805 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1806 increment_reading_symtab ();
1807 dw2_do_instantiate_symtab (objfile
, per_cu
);
1808 do_cleanups (back_to
);
1810 return per_cu
->v
.quick
->symtab
;
1813 /* Return the CU given its index. */
1815 static struct dwarf2_per_cu_data
*
1816 dw2_get_cu (int index
)
1818 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1820 index
-= dwarf2_per_objfile
->n_comp_units
;
1821 return dwarf2_per_objfile
->type_comp_units
[index
];
1823 return dwarf2_per_objfile
->all_comp_units
[index
];
1826 /* A helper function that knows how to read a 64-bit value in a way
1827 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1831 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1833 if (sizeof (ULONGEST
) < 8)
1837 /* Ignore the upper 4 bytes if they are all zero. */
1838 for (i
= 0; i
< 4; ++i
)
1839 if (bytes
[i
+ 4] != 0)
1842 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1845 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1849 /* Read the CU list from the mapped index, and use it to create all
1850 the CU objects for this objfile. Return 0 if something went wrong,
1851 1 if everything went ok. */
1854 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1855 offset_type cu_list_elements
)
1859 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1860 dwarf2_per_objfile
->all_comp_units
1861 = obstack_alloc (&objfile
->objfile_obstack
,
1862 dwarf2_per_objfile
->n_comp_units
1863 * sizeof (struct dwarf2_per_cu_data
*));
1865 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1867 struct dwarf2_per_cu_data
*the_cu
;
1868 ULONGEST offset
, length
;
1870 if (!extract_cu_value (cu_list
, &offset
)
1871 || !extract_cu_value (cu_list
+ 8, &length
))
1875 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1876 struct dwarf2_per_cu_data
);
1877 the_cu
->offset
= offset
;
1878 the_cu
->length
= length
;
1879 the_cu
->objfile
= objfile
;
1880 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1881 struct dwarf2_per_cu_quick_data
);
1882 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1888 /* Create the signatured type hash table from the index. */
1891 create_signatured_type_table_from_index (struct objfile
*objfile
,
1892 const gdb_byte
*bytes
,
1893 offset_type elements
)
1896 htab_t sig_types_hash
;
1898 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1899 dwarf2_per_objfile
->type_comp_units
1900 = obstack_alloc (&objfile
->objfile_obstack
,
1901 dwarf2_per_objfile
->n_type_comp_units
1902 * sizeof (struct dwarf2_per_cu_data
*));
1904 sig_types_hash
= allocate_signatured_type_table (objfile
);
1906 for (i
= 0; i
< elements
; i
+= 3)
1908 struct signatured_type
*type_sig
;
1909 ULONGEST offset
, type_offset
, signature
;
1912 if (!extract_cu_value (bytes
, &offset
)
1913 || !extract_cu_value (bytes
+ 8, &type_offset
))
1915 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1918 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1919 struct signatured_type
);
1920 type_sig
->signature
= signature
;
1921 type_sig
->offset
= offset
;
1922 type_sig
->type_offset
= type_offset
;
1923 type_sig
->per_cu
.from_debug_types
= 1;
1924 type_sig
->per_cu
.offset
= offset
;
1925 type_sig
->per_cu
.objfile
= objfile
;
1926 type_sig
->per_cu
.v
.quick
1927 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1928 struct dwarf2_per_cu_quick_data
);
1930 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1933 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1936 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1941 /* Read the address map data from the mapped index, and use it to
1942 populate the objfile's psymtabs_addrmap. */
1945 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1947 const gdb_byte
*iter
, *end
;
1948 struct obstack temp_obstack
;
1949 struct addrmap
*mutable_map
;
1950 struct cleanup
*cleanup
;
1953 obstack_init (&temp_obstack
);
1954 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1955 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1957 iter
= index
->address_table
;
1958 end
= iter
+ index
->address_table_size
;
1960 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1964 ULONGEST hi
, lo
, cu_index
;
1965 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1967 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1969 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1972 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1973 dw2_get_cu (cu_index
));
1976 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1977 &objfile
->objfile_obstack
);
1978 do_cleanups (cleanup
);
1981 /* The hash function for strings in the mapped index. This is the same as
1982 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
1983 implementation. This is necessary because the hash function is tied to the
1984 format of the mapped index file. The hash values do not have to match with
1987 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
1990 mapped_index_string_hash (int index_version
, const void *p
)
1992 const unsigned char *str
= (const unsigned char *) p
;
1996 while ((c
= *str
++) != 0)
1998 if (index_version
>= 5)
2000 r
= r
* 67 + c
- 113;
2006 /* Find a slot in the mapped index INDEX for the object named NAME.
2007 If NAME is found, set *VEC_OUT to point to the CU vector in the
2008 constant pool and return 1. If NAME cannot be found, return 0. */
2011 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2012 offset_type
**vec_out
)
2014 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2016 offset_type slot
, step
;
2017 int (*cmp
) (const char *, const char *);
2019 if (current_language
->la_language
== language_cplus
2020 || current_language
->la_language
== language_java
2021 || current_language
->la_language
== language_fortran
)
2023 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2025 const char *paren
= strchr (name
, '(');
2031 dup
= xmalloc (paren
- name
+ 1);
2032 memcpy (dup
, name
, paren
- name
);
2033 dup
[paren
- name
] = 0;
2035 make_cleanup (xfree
, dup
);
2040 /* Index version 4 did not support case insensitive searches. But the
2041 indexes for case insensitive languages are built in lowercase, therefore
2042 simulate our NAME being searched is also lowercased. */
2043 hash
= mapped_index_string_hash ((index
->version
== 4
2044 && case_sensitivity
== case_sensitive_off
2045 ? 5 : index
->version
),
2048 slot
= hash
& (index
->symbol_table_slots
- 1);
2049 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2050 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2054 /* Convert a slot number to an offset into the table. */
2055 offset_type i
= 2 * slot
;
2057 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2059 do_cleanups (back_to
);
2063 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2064 if (!cmp (name
, str
))
2066 *vec_out
= (offset_type
*) (index
->constant_pool
2067 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2068 do_cleanups (back_to
);
2072 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2076 /* Read the index file. If everything went ok, initialize the "quick"
2077 elements of all the CUs and return 1. Otherwise, return 0. */
2080 dwarf2_read_index (struct objfile
*objfile
)
2083 struct mapped_index
*map
;
2084 offset_type
*metadata
;
2085 const gdb_byte
*cu_list
;
2086 const gdb_byte
*types_list
= NULL
;
2087 offset_type version
, cu_list_elements
;
2088 offset_type types_list_elements
= 0;
2091 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2094 /* Older elfutils strip versions could keep the section in the main
2095 executable while splitting it for the separate debug info file. */
2096 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2097 & SEC_HAS_CONTENTS
) == 0)
2100 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2102 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2103 /* Version check. */
2104 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2105 /* Versions earlier than 3 emitted every copy of a psymbol. This
2106 causes the index to behave very poorly for certain requests. Version 3
2107 contained incomplete addrmap. So, it seems better to just ignore such
2108 indices. Index version 4 uses a different hash function than index
2109 version 5 and later. */
2112 /* Indexes with higher version than the one supported by GDB may be no
2113 longer backward compatible. */
2117 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2118 map
->version
= version
;
2119 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2121 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2124 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2125 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2129 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2130 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2131 - MAYBE_SWAP (metadata
[i
]))
2135 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2136 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2137 - MAYBE_SWAP (metadata
[i
]));
2140 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2141 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2142 - MAYBE_SWAP (metadata
[i
]))
2143 / (2 * sizeof (offset_type
)));
2146 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2148 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2151 if (types_list_elements
2152 && !create_signatured_type_table_from_index (objfile
, types_list
,
2153 types_list_elements
))
2156 create_addrmap_from_index (objfile
, map
);
2158 dwarf2_per_objfile
->index_table
= map
;
2159 dwarf2_per_objfile
->using_index
= 1;
2160 dwarf2_per_objfile
->quick_file_names_table
=
2161 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2166 /* A helper for the "quick" functions which sets the global
2167 dwarf2_per_objfile according to OBJFILE. */
2170 dw2_setup (struct objfile
*objfile
)
2172 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2173 gdb_assert (dwarf2_per_objfile
);
2176 /* A helper for the "quick" functions which attempts to read the line
2177 table for THIS_CU. */
2179 static struct quick_file_names
*
2180 dw2_get_file_names (struct objfile
*objfile
,
2181 struct dwarf2_per_cu_data
*this_cu
)
2183 bfd
*abfd
= objfile
->obfd
;
2184 struct line_header
*lh
;
2185 struct attribute
*attr
;
2186 struct cleanup
*cleanups
;
2187 struct die_info
*comp_unit_die
;
2188 struct dwarf2_section_info
* sec
;
2189 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2190 int has_children
, i
;
2191 struct dwarf2_cu cu
;
2192 unsigned int bytes_read
, buffer_size
;
2193 struct die_reader_specs reader_specs
;
2194 char *name
, *comp_dir
;
2196 struct quick_file_names
*qfn
;
2197 unsigned int line_offset
;
2199 if (this_cu
->v
.quick
->file_names
!= NULL
)
2200 return this_cu
->v
.quick
->file_names
;
2201 /* If we know there is no line data, no point in looking again. */
2202 if (this_cu
->v
.quick
->no_file_data
)
2205 init_one_comp_unit (&cu
, objfile
);
2206 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2208 if (this_cu
->from_debug_types
)
2209 sec
= &dwarf2_per_objfile
->types
;
2211 sec
= &dwarf2_per_objfile
->info
;
2212 dwarf2_read_section (objfile
, sec
);
2213 buffer_size
= sec
->size
;
2214 buffer
= sec
->buffer
;
2215 info_ptr
= buffer
+ this_cu
->offset
;
2216 beg_of_comp_unit
= info_ptr
;
2218 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2219 buffer
, buffer_size
,
2222 /* Complete the cu_header. */
2223 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2224 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2227 cu
.per_cu
= this_cu
;
2229 dwarf2_read_abbrevs (abfd
, &cu
);
2230 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2232 if (this_cu
->from_debug_types
)
2233 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2234 init_cu_die_reader (&reader_specs
, &cu
);
2235 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2241 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2244 struct quick_file_names find_entry
;
2246 line_offset
= DW_UNSND (attr
);
2248 /* We may have already read in this line header (TU line header sharing).
2249 If we have we're done. */
2250 find_entry
.offset
= line_offset
;
2251 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2252 &find_entry
, INSERT
);
2255 do_cleanups (cleanups
);
2256 this_cu
->v
.quick
->file_names
= *slot
;
2260 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2264 do_cleanups (cleanups
);
2265 this_cu
->v
.quick
->no_file_data
= 1;
2269 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2270 qfn
->offset
= line_offset
;
2271 gdb_assert (slot
!= NULL
);
2274 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2276 qfn
->num_file_names
= lh
->num_file_names
;
2277 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2278 lh
->num_file_names
* sizeof (char *));
2279 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2280 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2281 qfn
->real_names
= NULL
;
2283 free_line_header (lh
);
2284 do_cleanups (cleanups
);
2286 this_cu
->v
.quick
->file_names
= qfn
;
2290 /* A helper for the "quick" functions which computes and caches the
2291 real path for a given file name from the line table. */
2294 dw2_get_real_path (struct objfile
*objfile
,
2295 struct quick_file_names
*qfn
, int index
)
2297 if (qfn
->real_names
== NULL
)
2298 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2299 qfn
->num_file_names
, sizeof (char *));
2301 if (qfn
->real_names
[index
] == NULL
)
2302 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2304 return qfn
->real_names
[index
];
2307 static struct symtab
*
2308 dw2_find_last_source_symtab (struct objfile
*objfile
)
2312 dw2_setup (objfile
);
2313 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2314 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2317 /* Traversal function for dw2_forget_cached_source_info. */
2320 dw2_free_cached_file_names (void **slot
, void *info
)
2322 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2324 if (file_data
->real_names
)
2328 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2330 xfree ((void*) file_data
->real_names
[i
]);
2331 file_data
->real_names
[i
] = NULL
;
2339 dw2_forget_cached_source_info (struct objfile
*objfile
)
2341 dw2_setup (objfile
);
2343 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2344 dw2_free_cached_file_names
, NULL
);
2348 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2349 const char *full_path
, const char *real_path
,
2350 struct symtab
**result
)
2353 int check_basename
= lbasename (name
) == name
;
2354 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2356 dw2_setup (objfile
);
2358 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2359 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2362 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2363 struct quick_file_names
*file_data
;
2365 if (per_cu
->v
.quick
->symtab
)
2368 file_data
= dw2_get_file_names (objfile
, per_cu
);
2369 if (file_data
== NULL
)
2372 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2374 const char *this_name
= file_data
->file_names
[j
];
2376 if (FILENAME_CMP (name
, this_name
) == 0)
2378 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2382 if (check_basename
&& ! base_cu
2383 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2386 if (full_path
!= NULL
)
2388 const char *this_real_name
= dw2_get_real_path (objfile
,
2391 if (this_real_name
!= NULL
2392 && FILENAME_CMP (full_path
, this_real_name
) == 0)
2394 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2399 if (real_path
!= NULL
)
2401 const char *this_real_name
= dw2_get_real_path (objfile
,
2404 if (this_real_name
!= NULL
2405 && FILENAME_CMP (real_path
, this_real_name
) == 0)
2407 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2416 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2423 static struct symtab
*
2424 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2425 const char *name
, domain_enum domain
)
2427 /* We do all the work in the pre_expand_symtabs_matching hook
2432 /* A helper function that expands all symtabs that hold an object
2436 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2438 dw2_setup (objfile
);
2440 /* index_table is NULL if OBJF_READNOW. */
2441 if (dwarf2_per_objfile
->index_table
)
2445 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2448 offset_type i
, len
= MAYBE_SWAP (*vec
);
2449 for (i
= 0; i
< len
; ++i
)
2451 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2452 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2454 dw2_instantiate_symtab (objfile
, per_cu
);
2461 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2462 enum block_enum block_kind
, const char *name
,
2465 dw2_do_expand_symtabs_matching (objfile
, name
);
2469 dw2_print_stats (struct objfile
*objfile
)
2473 dw2_setup (objfile
);
2475 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2476 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2478 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2480 if (!per_cu
->v
.quick
->symtab
)
2483 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2487 dw2_dump (struct objfile
*objfile
)
2489 /* Nothing worth printing. */
2493 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2494 struct section_offsets
*delta
)
2496 /* There's nothing to relocate here. */
2500 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2501 const char *func_name
)
2503 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2507 dw2_expand_all_symtabs (struct objfile
*objfile
)
2511 dw2_setup (objfile
);
2513 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2514 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2516 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2518 dw2_instantiate_symtab (objfile
, per_cu
);
2523 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2524 const char *filename
)
2528 dw2_setup (objfile
);
2530 /* We don't need to consider type units here.
2531 This is only called for examining code, e.g. expand_line_sal.
2532 There can be an order of magnitude (or more) more type units
2533 than comp units, and we avoid them if we can. */
2535 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2538 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2539 struct quick_file_names
*file_data
;
2541 if (per_cu
->v
.quick
->symtab
)
2544 file_data
= dw2_get_file_names (objfile
, per_cu
);
2545 if (file_data
== NULL
)
2548 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2550 const char *this_name
= file_data
->file_names
[j
];
2551 if (FILENAME_CMP (this_name
, filename
) == 0)
2553 dw2_instantiate_symtab (objfile
, per_cu
);
2561 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2563 struct dwarf2_per_cu_data
*per_cu
;
2565 struct quick_file_names
*file_data
;
2567 dw2_setup (objfile
);
2569 /* index_table is NULL if OBJF_READNOW. */
2570 if (!dwarf2_per_objfile
->index_table
)
2573 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2577 /* Note that this just looks at the very first one named NAME -- but
2578 actually we are looking for a function. find_main_filename
2579 should be rewritten so that it doesn't require a custom hook. It
2580 could just use the ordinary symbol tables. */
2581 /* vec[0] is the length, which must always be >0. */
2582 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2584 file_data
= dw2_get_file_names (objfile
, per_cu
);
2585 if (file_data
== NULL
)
2588 return file_data
->file_names
[file_data
->num_file_names
- 1];
2592 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2593 struct objfile
*objfile
, int global
,
2594 int (*callback
) (struct block
*,
2595 struct symbol
*, void *),
2596 void *data
, symbol_compare_ftype
*match
,
2597 symbol_compare_ftype
*ordered_compare
)
2599 /* Currently unimplemented; used for Ada. The function can be called if the
2600 current language is Ada for a non-Ada objfile using GNU index. As Ada
2601 does not look for non-Ada symbols this function should just return. */
2605 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2606 int (*file_matcher
) (const char *, void *),
2607 int (*name_matcher
) (const char *, void *),
2608 enum search_domain kind
,
2613 struct mapped_index
*index
;
2615 dw2_setup (objfile
);
2617 /* index_table is NULL if OBJF_READNOW. */
2618 if (!dwarf2_per_objfile
->index_table
)
2620 index
= dwarf2_per_objfile
->index_table
;
2622 if (file_matcher
!= NULL
)
2623 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2624 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2627 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2628 struct quick_file_names
*file_data
;
2630 per_cu
->v
.quick
->mark
= 0;
2631 if (per_cu
->v
.quick
->symtab
)
2634 file_data
= dw2_get_file_names (objfile
, per_cu
);
2635 if (file_data
== NULL
)
2638 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2640 if (file_matcher (file_data
->file_names
[j
], data
))
2642 per_cu
->v
.quick
->mark
= 1;
2648 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2650 offset_type idx
= 2 * iter
;
2652 offset_type
*vec
, vec_len
, vec_idx
;
2654 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2657 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2659 if (! (*name_matcher
) (name
, data
))
2662 /* The name was matched, now expand corresponding CUs that were
2664 vec
= (offset_type
*) (index
->constant_pool
2665 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2666 vec_len
= MAYBE_SWAP (vec
[0]);
2667 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2669 struct dwarf2_per_cu_data
*per_cu
;
2671 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2672 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2673 dw2_instantiate_symtab (objfile
, per_cu
);
2678 static struct symtab
*
2679 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2680 struct minimal_symbol
*msymbol
,
2682 struct obj_section
*section
,
2685 struct dwarf2_per_cu_data
*data
;
2687 dw2_setup (objfile
);
2689 if (!objfile
->psymtabs_addrmap
)
2692 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2696 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2697 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2698 paddress (get_objfile_arch (objfile
), pc
));
2700 return dw2_instantiate_symtab (objfile
, data
);
2704 dw2_map_symbol_filenames (struct objfile
*objfile
,
2705 void (*fun
) (const char *, const char *, void *),
2710 dw2_setup (objfile
);
2712 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2713 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2716 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2717 struct quick_file_names
*file_data
;
2719 if (per_cu
->v
.quick
->symtab
)
2722 file_data
= dw2_get_file_names (objfile
, per_cu
);
2723 if (file_data
== NULL
)
2726 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2728 const char *this_real_name
= dw2_get_real_path (objfile
, file_data
,
2730 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2736 dw2_has_symbols (struct objfile
*objfile
)
2741 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2744 dw2_find_last_source_symtab
,
2745 dw2_forget_cached_source_info
,
2748 dw2_pre_expand_symtabs_matching
,
2752 dw2_expand_symtabs_for_function
,
2753 dw2_expand_all_symtabs
,
2754 dw2_expand_symtabs_with_filename
,
2755 dw2_find_symbol_file
,
2756 dw2_map_matching_symbols
,
2757 dw2_expand_symtabs_matching
,
2758 dw2_find_pc_sect_symtab
,
2759 dw2_map_symbol_filenames
2762 /* Initialize for reading DWARF for this objfile. Return 0 if this
2763 file will use psymtabs, or 1 if using the GNU index. */
2766 dwarf2_initialize_objfile (struct objfile
*objfile
)
2768 /* If we're about to read full symbols, don't bother with the
2769 indices. In this case we also don't care if some other debug
2770 format is making psymtabs, because they are all about to be
2772 if ((objfile
->flags
& OBJF_READNOW
))
2776 dwarf2_per_objfile
->using_index
= 1;
2777 create_all_comp_units (objfile
);
2778 create_debug_types_hash_table (objfile
);
2779 dwarf2_per_objfile
->quick_file_names_table
=
2780 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2782 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2783 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2785 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2787 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2788 struct dwarf2_per_cu_quick_data
);
2791 /* Return 1 so that gdb sees the "quick" functions. However,
2792 these functions will be no-ops because we will have expanded
2797 if (dwarf2_read_index (objfile
))
2805 /* Build a partial symbol table. */
2808 dwarf2_build_psymtabs (struct objfile
*objfile
)
2810 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2812 init_psymbol_list (objfile
, 1024);
2815 dwarf2_build_psymtabs_hard (objfile
);
2818 /* Return TRUE if OFFSET is within CU_HEADER. */
2821 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2823 unsigned int bottom
= cu_header
->offset
;
2824 unsigned int top
= (cu_header
->offset
2826 + cu_header
->initial_length_size
);
2828 return (offset
>= bottom
&& offset
< top
);
2831 /* Read in the comp unit header information from the debug_info at info_ptr.
2832 NOTE: This leaves members offset, first_die_offset to be filled in
2836 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2837 gdb_byte
*info_ptr
, bfd
*abfd
)
2840 unsigned int bytes_read
;
2842 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2843 cu_header
->initial_length_size
= bytes_read
;
2844 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2845 info_ptr
+= bytes_read
;
2846 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2848 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2850 info_ptr
+= bytes_read
;
2851 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2853 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2854 if (signed_addr
< 0)
2855 internal_error (__FILE__
, __LINE__
,
2856 _("read_comp_unit_head: dwarf from non elf file"));
2857 cu_header
->signed_addr_p
= signed_addr
;
2863 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2864 gdb_byte
*buffer
, unsigned int buffer_size
,
2867 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2869 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2871 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2872 error (_("Dwarf Error: wrong version in compilation unit header "
2873 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2874 bfd_get_filename (abfd
));
2876 if (header
->abbrev_offset
2877 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
2878 &dwarf2_per_objfile
->abbrev
))
2879 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2880 "(offset 0x%lx + 6) [in module %s]"),
2881 (long) header
->abbrev_offset
,
2882 (long) (beg_of_comp_unit
- buffer
),
2883 bfd_get_filename (abfd
));
2885 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2886 > buffer
+ buffer_size
)
2887 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2888 "(offset 0x%lx + 0) [in module %s]"),
2889 (long) header
->length
,
2890 (long) (beg_of_comp_unit
- buffer
),
2891 bfd_get_filename (abfd
));
2896 /* Read in the types comp unit header information from .debug_types entry at
2897 types_ptr. The result is a pointer to one past the end of the header. */
2900 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2901 ULONGEST
*signature
,
2902 gdb_byte
*types_ptr
, bfd
*abfd
)
2904 gdb_byte
*initial_types_ptr
= types_ptr
;
2906 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2907 &dwarf2_per_objfile
->types
);
2908 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2910 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2912 *signature
= read_8_bytes (abfd
, types_ptr
);
2914 types_ptr
+= cu_header
->offset_size
;
2915 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2920 /* Allocate a new partial symtab for file named NAME and mark this new
2921 partial symtab as being an include of PST. */
2924 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2925 struct objfile
*objfile
)
2927 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2929 subpst
->section_offsets
= pst
->section_offsets
;
2930 subpst
->textlow
= 0;
2931 subpst
->texthigh
= 0;
2933 subpst
->dependencies
= (struct partial_symtab
**)
2934 obstack_alloc (&objfile
->objfile_obstack
,
2935 sizeof (struct partial_symtab
*));
2936 subpst
->dependencies
[0] = pst
;
2937 subpst
->number_of_dependencies
= 1;
2939 subpst
->globals_offset
= 0;
2940 subpst
->n_global_syms
= 0;
2941 subpst
->statics_offset
= 0;
2942 subpst
->n_static_syms
= 0;
2943 subpst
->symtab
= NULL
;
2944 subpst
->read_symtab
= pst
->read_symtab
;
2947 /* No private part is necessary for include psymtabs. This property
2948 can be used to differentiate between such include psymtabs and
2949 the regular ones. */
2950 subpst
->read_symtab_private
= NULL
;
2953 /* Read the Line Number Program data and extract the list of files
2954 included by the source file represented by PST. Build an include
2955 partial symtab for each of these included files. */
2958 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2959 struct die_info
*die
,
2960 struct partial_symtab
*pst
)
2962 struct objfile
*objfile
= cu
->objfile
;
2963 bfd
*abfd
= objfile
->obfd
;
2964 struct line_header
*lh
= NULL
;
2965 struct attribute
*attr
;
2967 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2970 unsigned int line_offset
= DW_UNSND (attr
);
2972 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2975 return; /* No linetable, so no includes. */
2977 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2978 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
2980 free_line_header (lh
);
2984 hash_type_signature (const void *item
)
2986 const struct signatured_type
*type_sig
= item
;
2988 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2989 return type_sig
->signature
;
2993 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2995 const struct signatured_type
*lhs
= item_lhs
;
2996 const struct signatured_type
*rhs
= item_rhs
;
2998 return lhs
->signature
== rhs
->signature
;
3001 /* Allocate a hash table for signatured types. */
3004 allocate_signatured_type_table (struct objfile
*objfile
)
3006 return htab_create_alloc_ex (41,
3007 hash_type_signature
,
3010 &objfile
->objfile_obstack
,
3011 hashtab_obstack_allocate
,
3012 dummy_obstack_deallocate
);
3015 /* A helper function to add a signatured type CU to a list. */
3018 add_signatured_type_cu_to_list (void **slot
, void *datum
)
3020 struct signatured_type
*sigt
= *slot
;
3021 struct dwarf2_per_cu_data
***datap
= datum
;
3023 **datap
= &sigt
->per_cu
;
3029 /* Create the hash table of all entries in the .debug_types section.
3030 The result is zero if there is an error (e.g. missing .debug_types section),
3031 otherwise non-zero. */
3034 create_debug_types_hash_table (struct objfile
*objfile
)
3038 struct dwarf2_per_cu_data
**iter
;
3040 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
3041 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
3043 if (info_ptr
== NULL
)
3045 dwarf2_per_objfile
->signatured_types
= NULL
;
3049 types_htab
= allocate_signatured_type_table (objfile
);
3051 if (dwarf2_die_debug
)
3052 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3054 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
3055 + dwarf2_per_objfile
->types
.size
)
3057 unsigned int offset
;
3058 unsigned int offset_size
;
3059 unsigned int type_offset
;
3060 unsigned int length
, initial_length_size
;
3061 unsigned short version
;
3063 struct signatured_type
*type_sig
;
3065 gdb_byte
*ptr
= info_ptr
;
3067 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
3069 /* We need to read the type's signature in order to build the hash
3070 table, but we don't need to read anything else just yet. */
3072 /* Sanity check to ensure entire cu is present. */
3073 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
3074 if (ptr
+ length
+ initial_length_size
3075 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
3077 complaint (&symfile_complaints
,
3078 _("debug type entry runs off end "
3079 "of `.debug_types' section, ignored"));
3083 offset_size
= initial_length_size
== 4 ? 4 : 8;
3084 ptr
+= initial_length_size
;
3085 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3087 ptr
+= offset_size
; /* abbrev offset */
3088 ptr
+= 1; /* address size */
3089 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3091 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3093 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3094 memset (type_sig
, 0, sizeof (*type_sig
));
3095 type_sig
->signature
= signature
;
3096 type_sig
->offset
= offset
;
3097 type_sig
->type_offset
= type_offset
;
3098 type_sig
->per_cu
.objfile
= objfile
;
3099 type_sig
->per_cu
.from_debug_types
= 1;
3101 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3102 gdb_assert (slot
!= NULL
);
3105 if (dwarf2_die_debug
)
3106 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3107 offset
, phex (signature
, sizeof (signature
)));
3109 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3112 dwarf2_per_objfile
->signatured_types
= types_htab
;
3114 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3115 dwarf2_per_objfile
->type_comp_units
3116 = obstack_alloc (&objfile
->objfile_obstack
,
3117 dwarf2_per_objfile
->n_type_comp_units
3118 * sizeof (struct dwarf2_per_cu_data
*));
3119 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3120 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3121 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3122 == dwarf2_per_objfile
->n_type_comp_units
);
3127 /* Lookup a signature based type.
3128 Returns NULL if SIG is not present in the table. */
3130 static struct signatured_type
*
3131 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3133 struct signatured_type find_entry
, *entry
;
3135 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3137 complaint (&symfile_complaints
,
3138 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3142 find_entry
.signature
= sig
;
3143 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3147 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3150 init_cu_die_reader (struct die_reader_specs
*reader
,
3151 struct dwarf2_cu
*cu
)
3153 reader
->abfd
= cu
->objfile
->obfd
;
3155 if (cu
->per_cu
->from_debug_types
)
3157 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3158 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
3162 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3163 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3167 /* Find the base address of the compilation unit for range lists and
3168 location lists. It will normally be specified by DW_AT_low_pc.
3169 In DWARF-3 draft 4, the base address could be overridden by
3170 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3171 compilation units with discontinuous ranges. */
3174 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3176 struct attribute
*attr
;
3179 cu
->base_address
= 0;
3181 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3184 cu
->base_address
= DW_ADDR (attr
);
3189 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3192 cu
->base_address
= DW_ADDR (attr
);
3198 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3199 to combine the common parts.
3200 Process a compilation unit for a psymtab.
3201 BUFFER is a pointer to the beginning of the dwarf section buffer,
3202 either .debug_info or debug_types.
3203 INFO_PTR is a pointer to the start of the CU.
3204 Returns a pointer to the next CU. */
3207 process_psymtab_comp_unit (struct objfile
*objfile
,
3208 struct dwarf2_per_cu_data
*this_cu
,
3209 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3210 unsigned int buffer_size
)
3212 bfd
*abfd
= objfile
->obfd
;
3213 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3214 struct die_info
*comp_unit_die
;
3215 struct partial_symtab
*pst
;
3217 struct cleanup
*back_to_inner
;
3218 struct dwarf2_cu cu
;
3219 int has_children
, has_pc_info
;
3220 struct attribute
*attr
;
3221 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3222 struct die_reader_specs reader_specs
;
3223 const char *filename
;
3225 init_one_comp_unit (&cu
, objfile
);
3226 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3228 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3229 buffer
, buffer_size
,
3232 /* Complete the cu_header. */
3233 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3234 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3236 cu
.list_in_scope
= &file_symbols
;
3238 /* If this compilation unit was already read in, free the
3239 cached copy in order to read it in again. This is
3240 necessary because we skipped some symbols when we first
3241 read in the compilation unit (see load_partial_dies).
3242 This problem could be avoided, but the benefit is
3244 if (this_cu
->cu
!= NULL
)
3245 free_one_cached_comp_unit (this_cu
->cu
);
3247 /* Note that this is a pointer to our stack frame, being
3248 added to a global data structure. It will be cleaned up
3249 in free_stack_comp_unit when we finish with this
3250 compilation unit. */
3252 cu
.per_cu
= this_cu
;
3254 /* Read the abbrevs for this compilation unit into a table. */
3255 dwarf2_read_abbrevs (abfd
, &cu
);
3256 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3258 /* Read the compilation unit die. */
3259 if (this_cu
->from_debug_types
)
3260 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3261 init_cu_die_reader (&reader_specs
, &cu
);
3262 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3265 if (this_cu
->from_debug_types
)
3267 /* offset,length haven't been set yet for type units. */
3268 this_cu
->offset
= cu
.header
.offset
;
3269 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3271 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3273 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3274 + cu
.header
.initial_length_size
);
3275 do_cleanups (back_to_inner
);
3279 prepare_one_comp_unit (&cu
, comp_unit_die
);
3281 /* Allocate a new partial symbol table structure. */
3282 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3283 if (attr
== NULL
|| !DW_STRING (attr
))
3286 filename
= DW_STRING (attr
);
3287 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3289 /* TEXTLOW and TEXTHIGH are set below. */
3291 objfile
->global_psymbols
.next
,
3292 objfile
->static_psymbols
.next
);
3294 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3296 pst
->dirname
= DW_STRING (attr
);
3298 pst
->read_symtab_private
= this_cu
;
3300 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3302 /* Store the function that reads in the rest of the symbol table. */
3303 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3305 this_cu
->v
.psymtab
= pst
;
3307 dwarf2_find_base_address (comp_unit_die
, &cu
);
3309 /* Possibly set the default values of LOWPC and HIGHPC from
3311 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3312 &best_highpc
, &cu
, pst
);
3313 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3314 /* Store the contiguous range if it is not empty; it can be empty for
3315 CUs with no code. */
3316 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3317 best_lowpc
+ baseaddr
,
3318 best_highpc
+ baseaddr
- 1, pst
);
3320 /* Check if comp unit has_children.
3321 If so, read the rest of the partial symbols from this comp unit.
3322 If not, there's no more debug_info for this comp unit. */
3325 struct partial_die_info
*first_die
;
3326 CORE_ADDR lowpc
, highpc
;
3328 lowpc
= ((CORE_ADDR
) -1);
3329 highpc
= ((CORE_ADDR
) 0);
3331 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3333 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3334 ! has_pc_info
, &cu
);
3336 /* If we didn't find a lowpc, set it to highpc to avoid
3337 complaints from `maint check'. */
3338 if (lowpc
== ((CORE_ADDR
) -1))
3341 /* If the compilation unit didn't have an explicit address range,
3342 then use the information extracted from its child dies. */
3346 best_highpc
= highpc
;
3349 pst
->textlow
= best_lowpc
+ baseaddr
;
3350 pst
->texthigh
= best_highpc
+ baseaddr
;
3352 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3353 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3354 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3355 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3356 sort_pst_symbols (pst
);
3358 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3359 + cu
.header
.initial_length_size
);
3361 if (this_cu
->from_debug_types
)
3363 /* It's not clear we want to do anything with stmt lists here.
3364 Waiting to see what gcc ultimately does. */
3368 /* Get the list of files included in the current compilation unit,
3369 and build a psymtab for each of them. */
3370 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3373 do_cleanups (back_to_inner
);
3378 /* Traversal function for htab_traverse_noresize.
3379 Process one .debug_types comp-unit. */
3382 process_type_comp_unit (void **slot
, void *info
)
3384 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3385 struct objfile
*objfile
= (struct objfile
*) info
;
3386 struct dwarf2_per_cu_data
*this_cu
;
3388 this_cu
= &entry
->per_cu
;
3390 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3391 process_psymtab_comp_unit (objfile
, this_cu
,
3392 dwarf2_per_objfile
->types
.buffer
,
3393 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
3394 dwarf2_per_objfile
->types
.size
);
3399 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3400 Build partial symbol tables for the .debug_types comp-units. */
3403 build_type_psymtabs (struct objfile
*objfile
)
3405 if (! create_debug_types_hash_table (objfile
))
3408 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3409 process_type_comp_unit
, objfile
);
3412 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3415 psymtabs_addrmap_cleanup (void *o
)
3417 struct objfile
*objfile
= o
;
3419 objfile
->psymtabs_addrmap
= NULL
;
3422 /* Build the partial symbol table by doing a quick pass through the
3423 .debug_info and .debug_abbrev sections. */
3426 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3429 struct cleanup
*back_to
, *addrmap_cleanup
;
3430 struct obstack temp_obstack
;
3432 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3434 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3435 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3437 /* Any cached compilation units will be linked by the per-objfile
3438 read_in_chain. Make sure to free them when we're done. */
3439 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3441 build_type_psymtabs (objfile
);
3443 create_all_comp_units (objfile
);
3445 /* Create a temporary address map on a temporary obstack. We later
3446 copy this to the final obstack. */
3447 obstack_init (&temp_obstack
);
3448 make_cleanup_obstack_free (&temp_obstack
);
3449 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3450 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3452 /* Since the objects we're extracting from .debug_info vary in
3453 length, only the individual functions to extract them (like
3454 read_comp_unit_head and load_partial_die) can really know whether
3455 the buffer is large enough to hold another complete object.
3457 At the moment, they don't actually check that. If .debug_info
3458 holds just one extra byte after the last compilation unit's dies,
3459 then read_comp_unit_head will happily read off the end of the
3460 buffer. read_partial_die is similarly casual. Those functions
3463 For this loop condition, simply checking whether there's any data
3464 left at all should be sufficient. */
3466 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3467 + dwarf2_per_objfile
->info
.size
))
3469 struct dwarf2_per_cu_data
*this_cu
;
3471 this_cu
= dwarf2_find_comp_unit (info_ptr
3472 - dwarf2_per_objfile
->info
.buffer
,
3475 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3476 dwarf2_per_objfile
->info
.buffer
,
3478 dwarf2_per_objfile
->info
.size
);
3481 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3482 &objfile
->objfile_obstack
);
3483 discard_cleanups (addrmap_cleanup
);
3485 do_cleanups (back_to
);
3488 /* Load the partial DIEs for a secondary CU into memory. */
3491 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3492 struct objfile
*objfile
)
3494 bfd
*abfd
= objfile
->obfd
;
3495 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3496 struct die_info
*comp_unit_die
;
3497 struct dwarf2_cu
*cu
;
3498 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3500 struct die_reader_specs reader_specs
;
3503 gdb_assert (! this_cu
->from_debug_types
);
3505 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3506 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3507 beg_of_comp_unit
= info_ptr
;
3509 if (this_cu
->cu
== NULL
)
3511 cu
= xmalloc (sizeof (*cu
));
3512 init_one_comp_unit (cu
, objfile
);
3516 /* If an error occurs while loading, release our storage. */
3517 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3519 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3520 dwarf2_per_objfile
->info
.buffer
,
3521 dwarf2_per_objfile
->info
.size
,
3524 /* Complete the cu_header. */
3525 cu
->header
.offset
= this_cu
->offset
;
3526 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3528 /* Link this compilation unit into the compilation unit tree. */
3530 cu
->per_cu
= this_cu
;
3532 /* Link this CU into read_in_chain. */
3533 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3534 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3539 info_ptr
+= cu
->header
.first_die_offset
;
3542 /* Read the abbrevs for this compilation unit into a table. */
3543 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3544 dwarf2_read_abbrevs (abfd
, cu
);
3545 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3547 /* Read the compilation unit die. */
3548 init_cu_die_reader (&reader_specs
, cu
);
3549 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3552 prepare_one_comp_unit (cu
, comp_unit_die
);
3554 /* Check if comp unit has_children.
3555 If so, read the rest of the partial symbols from this comp unit.
3556 If not, there's no more debug_info for this comp unit. */
3558 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3560 do_cleanups (free_abbrevs_cleanup
);
3564 /* We've successfully allocated this compilation unit. Let our
3565 caller clean it up when finished with it. */
3566 discard_cleanups (free_cu_cleanup
);
3570 /* Create a list of all compilation units in OBJFILE. We do this only
3571 if an inter-comp-unit reference is found; presumably if there is one,
3572 there will be many, and one will occur early in the .debug_info section.
3573 So there's no point in building this list incrementally. */
3576 create_all_comp_units (struct objfile
*objfile
)
3580 struct dwarf2_per_cu_data
**all_comp_units
;
3583 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3584 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3588 all_comp_units
= xmalloc (n_allocated
3589 * sizeof (struct dwarf2_per_cu_data
*));
3591 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3592 + dwarf2_per_objfile
->info
.size
)
3594 unsigned int length
, initial_length_size
;
3595 struct dwarf2_per_cu_data
*this_cu
;
3596 unsigned int offset
;
3598 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3600 /* Read just enough information to find out where the next
3601 compilation unit is. */
3602 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3603 &initial_length_size
);
3605 /* Save the compilation unit for later lookup. */
3606 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3607 sizeof (struct dwarf2_per_cu_data
));
3608 memset (this_cu
, 0, sizeof (*this_cu
));
3609 this_cu
->offset
= offset
;
3610 this_cu
->length
= length
+ initial_length_size
;
3611 this_cu
->objfile
= objfile
;
3613 if (n_comp_units
== n_allocated
)
3616 all_comp_units
= xrealloc (all_comp_units
,
3618 * sizeof (struct dwarf2_per_cu_data
*));
3620 all_comp_units
[n_comp_units
++] = this_cu
;
3622 info_ptr
= info_ptr
+ this_cu
->length
;
3625 dwarf2_per_objfile
->all_comp_units
3626 = obstack_alloc (&objfile
->objfile_obstack
,
3627 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3628 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3629 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3630 xfree (all_comp_units
);
3631 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3634 /* Process all loaded DIEs for compilation unit CU, starting at
3635 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3636 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3637 DW_AT_ranges). If NEED_PC is set, then this function will set
3638 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3639 and record the covered ranges in the addrmap. */
3642 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3643 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3645 struct partial_die_info
*pdi
;
3647 /* Now, march along the PDI's, descending into ones which have
3648 interesting children but skipping the children of the other ones,
3649 until we reach the end of the compilation unit. */
3655 fixup_partial_die (pdi
, cu
);
3657 /* Anonymous namespaces or modules have no name but have interesting
3658 children, so we need to look at them. Ditto for anonymous
3661 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3662 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3666 case DW_TAG_subprogram
:
3667 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3669 case DW_TAG_constant
:
3670 case DW_TAG_variable
:
3671 case DW_TAG_typedef
:
3672 case DW_TAG_union_type
:
3673 if (!pdi
->is_declaration
)
3675 add_partial_symbol (pdi
, cu
);
3678 case DW_TAG_class_type
:
3679 case DW_TAG_interface_type
:
3680 case DW_TAG_structure_type
:
3681 if (!pdi
->is_declaration
)
3683 add_partial_symbol (pdi
, cu
);
3686 case DW_TAG_enumeration_type
:
3687 if (!pdi
->is_declaration
)
3688 add_partial_enumeration (pdi
, cu
);
3690 case DW_TAG_base_type
:
3691 case DW_TAG_subrange_type
:
3692 /* File scope base type definitions are added to the partial
3694 add_partial_symbol (pdi
, cu
);
3696 case DW_TAG_namespace
:
3697 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3700 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3707 /* If the die has a sibling, skip to the sibling. */
3709 pdi
= pdi
->die_sibling
;
3713 /* Functions used to compute the fully scoped name of a partial DIE.
3715 Normally, this is simple. For C++, the parent DIE's fully scoped
3716 name is concatenated with "::" and the partial DIE's name. For
3717 Java, the same thing occurs except that "." is used instead of "::".
3718 Enumerators are an exception; they use the scope of their parent
3719 enumeration type, i.e. the name of the enumeration type is not
3720 prepended to the enumerator.
3722 There are two complexities. One is DW_AT_specification; in this
3723 case "parent" means the parent of the target of the specification,
3724 instead of the direct parent of the DIE. The other is compilers
3725 which do not emit DW_TAG_namespace; in this case we try to guess
3726 the fully qualified name of structure types from their members'
3727 linkage names. This must be done using the DIE's children rather
3728 than the children of any DW_AT_specification target. We only need
3729 to do this for structures at the top level, i.e. if the target of
3730 any DW_AT_specification (if any; otherwise the DIE itself) does not
3733 /* Compute the scope prefix associated with PDI's parent, in
3734 compilation unit CU. The result will be allocated on CU's
3735 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3736 field. NULL is returned if no prefix is necessary. */
3738 partial_die_parent_scope (struct partial_die_info
*pdi
,
3739 struct dwarf2_cu
*cu
)
3741 char *grandparent_scope
;
3742 struct partial_die_info
*parent
, *real_pdi
;
3744 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3745 then this means the parent of the specification DIE. */
3748 while (real_pdi
->has_specification
)
3749 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3751 parent
= real_pdi
->die_parent
;
3755 if (parent
->scope_set
)
3756 return parent
->scope
;
3758 fixup_partial_die (parent
, cu
);
3760 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3762 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3763 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3764 Work around this problem here. */
3765 if (cu
->language
== language_cplus
3766 && parent
->tag
== DW_TAG_namespace
3767 && strcmp (parent
->name
, "::") == 0
3768 && grandparent_scope
== NULL
)
3770 parent
->scope
= NULL
;
3771 parent
->scope_set
= 1;
3775 if (parent
->tag
== DW_TAG_namespace
3776 || parent
->tag
== DW_TAG_module
3777 || parent
->tag
== DW_TAG_structure_type
3778 || parent
->tag
== DW_TAG_class_type
3779 || parent
->tag
== DW_TAG_interface_type
3780 || parent
->tag
== DW_TAG_union_type
3781 || parent
->tag
== DW_TAG_enumeration_type
)
3783 if (grandparent_scope
== NULL
)
3784 parent
->scope
= parent
->name
;
3786 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3788 parent
->name
, 0, cu
);
3790 else if (parent
->tag
== DW_TAG_enumerator
)
3791 /* Enumerators should not get the name of the enumeration as a prefix. */
3792 parent
->scope
= grandparent_scope
;
3795 /* FIXME drow/2004-04-01: What should we be doing with
3796 function-local names? For partial symbols, we should probably be
3798 complaint (&symfile_complaints
,
3799 _("unhandled containing DIE tag %d for DIE at %d"),
3800 parent
->tag
, pdi
->offset
);
3801 parent
->scope
= grandparent_scope
;
3804 parent
->scope_set
= 1;
3805 return parent
->scope
;
3808 /* Return the fully scoped name associated with PDI, from compilation unit
3809 CU. The result will be allocated with malloc. */
3811 partial_die_full_name (struct partial_die_info
*pdi
,
3812 struct dwarf2_cu
*cu
)
3816 /* If this is a template instantiation, we can not work out the
3817 template arguments from partial DIEs. So, unfortunately, we have
3818 to go through the full DIEs. At least any work we do building
3819 types here will be reused if full symbols are loaded later. */
3820 if (pdi
->has_template_arguments
)
3822 fixup_partial_die (pdi
, cu
);
3824 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3826 struct die_info
*die
;
3827 struct attribute attr
;
3828 struct dwarf2_cu
*ref_cu
= cu
;
3831 attr
.form
= DW_FORM_ref_addr
;
3832 attr
.u
.addr
= pdi
->offset
;
3833 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3835 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3839 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3840 if (parent_scope
== NULL
)
3843 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3847 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3849 struct objfile
*objfile
= cu
->objfile
;
3851 char *actual_name
= NULL
;
3852 const struct partial_symbol
*psym
= NULL
;
3854 int built_actual_name
= 0;
3856 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3858 actual_name
= partial_die_full_name (pdi
, cu
);
3860 built_actual_name
= 1;
3862 if (actual_name
== NULL
)
3863 actual_name
= pdi
->name
;
3867 case DW_TAG_subprogram
:
3868 if (pdi
->is_external
|| cu
->language
== language_ada
)
3870 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3871 of the global scope. But in Ada, we want to be able to access
3872 nested procedures globally. So all Ada subprograms are stored
3873 in the global scope. */
3874 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3875 mst_text, objfile); */
3876 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3878 VAR_DOMAIN
, LOC_BLOCK
,
3879 &objfile
->global_psymbols
,
3880 0, pdi
->lowpc
+ baseaddr
,
3881 cu
->language
, objfile
);
3885 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3886 mst_file_text, objfile); */
3887 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3889 VAR_DOMAIN
, LOC_BLOCK
,
3890 &objfile
->static_psymbols
,
3891 0, pdi
->lowpc
+ baseaddr
,
3892 cu
->language
, objfile
);
3895 case DW_TAG_constant
:
3897 struct psymbol_allocation_list
*list
;
3899 if (pdi
->is_external
)
3900 list
= &objfile
->global_psymbols
;
3902 list
= &objfile
->static_psymbols
;
3903 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3904 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
3905 list
, 0, 0, cu
->language
, objfile
);
3908 case DW_TAG_variable
:
3910 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3914 && !dwarf2_per_objfile
->has_section_at_zero
)
3916 /* A global or static variable may also have been stripped
3917 out by the linker if unused, in which case its address
3918 will be nullified; do not add such variables into partial
3919 symbol table then. */
3921 else if (pdi
->is_external
)
3924 Don't enter into the minimal symbol tables as there is
3925 a minimal symbol table entry from the ELF symbols already.
3926 Enter into partial symbol table if it has a location
3927 descriptor or a type.
3928 If the location descriptor is missing, new_symbol will create
3929 a LOC_UNRESOLVED symbol, the address of the variable will then
3930 be determined from the minimal symbol table whenever the variable
3932 The address for the partial symbol table entry is not
3933 used by GDB, but it comes in handy for debugging partial symbol
3936 if (pdi
->locdesc
|| pdi
->has_type
)
3937 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3939 VAR_DOMAIN
, LOC_STATIC
,
3940 &objfile
->global_psymbols
,
3942 cu
->language
, objfile
);
3946 /* Static Variable. Skip symbols without location descriptors. */
3947 if (pdi
->locdesc
== NULL
)
3949 if (built_actual_name
)
3950 xfree (actual_name
);
3953 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
3954 mst_file_data, objfile); */
3955 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3957 VAR_DOMAIN
, LOC_STATIC
,
3958 &objfile
->static_psymbols
,
3960 cu
->language
, objfile
);
3963 case DW_TAG_typedef
:
3964 case DW_TAG_base_type
:
3965 case DW_TAG_subrange_type
:
3966 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3968 VAR_DOMAIN
, LOC_TYPEDEF
,
3969 &objfile
->static_psymbols
,
3970 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3972 case DW_TAG_namespace
:
3973 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3975 VAR_DOMAIN
, LOC_TYPEDEF
,
3976 &objfile
->global_psymbols
,
3977 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3979 case DW_TAG_class_type
:
3980 case DW_TAG_interface_type
:
3981 case DW_TAG_structure_type
:
3982 case DW_TAG_union_type
:
3983 case DW_TAG_enumeration_type
:
3984 /* Skip external references. The DWARF standard says in the section
3985 about "Structure, Union, and Class Type Entries": "An incomplete
3986 structure, union or class type is represented by a structure,
3987 union or class entry that does not have a byte size attribute
3988 and that has a DW_AT_declaration attribute." */
3989 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3991 if (built_actual_name
)
3992 xfree (actual_name
);
3996 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3997 static vs. global. */
3998 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4000 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4001 (cu
->language
== language_cplus
4002 || cu
->language
== language_java
)
4003 ? &objfile
->global_psymbols
4004 : &objfile
->static_psymbols
,
4005 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4008 case DW_TAG_enumerator
:
4009 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4011 VAR_DOMAIN
, LOC_CONST
,
4012 (cu
->language
== language_cplus
4013 || cu
->language
== language_java
)
4014 ? &objfile
->global_psymbols
4015 : &objfile
->static_psymbols
,
4016 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4022 if (built_actual_name
)
4023 xfree (actual_name
);
4026 /* Read a partial die corresponding to a namespace; also, add a symbol
4027 corresponding to that namespace to the symbol table. NAMESPACE is
4028 the name of the enclosing namespace. */
4031 add_partial_namespace (struct partial_die_info
*pdi
,
4032 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4033 int need_pc
, struct dwarf2_cu
*cu
)
4035 /* Add a symbol for the namespace. */
4037 add_partial_symbol (pdi
, cu
);
4039 /* Now scan partial symbols in that namespace. */
4041 if (pdi
->has_children
)
4042 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4045 /* Read a partial die corresponding to a Fortran module. */
4048 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4049 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4051 /* Now scan partial symbols in that module. */
4053 if (pdi
->has_children
)
4054 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4057 /* Read a partial die corresponding to a subprogram and create a partial
4058 symbol for that subprogram. When the CU language allows it, this
4059 routine also defines a partial symbol for each nested subprogram
4060 that this subprogram contains.
4062 DIE my also be a lexical block, in which case we simply search
4063 recursively for suprograms defined inside that lexical block.
4064 Again, this is only performed when the CU language allows this
4065 type of definitions. */
4068 add_partial_subprogram (struct partial_die_info
*pdi
,
4069 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4070 int need_pc
, struct dwarf2_cu
*cu
)
4072 if (pdi
->tag
== DW_TAG_subprogram
)
4074 if (pdi
->has_pc_info
)
4076 if (pdi
->lowpc
< *lowpc
)
4077 *lowpc
= pdi
->lowpc
;
4078 if (pdi
->highpc
> *highpc
)
4079 *highpc
= pdi
->highpc
;
4083 struct objfile
*objfile
= cu
->objfile
;
4085 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4086 SECT_OFF_TEXT (objfile
));
4087 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4088 pdi
->lowpc
+ baseaddr
,
4089 pdi
->highpc
- 1 + baseaddr
,
4090 cu
->per_cu
->v
.psymtab
);
4092 if (!pdi
->is_declaration
)
4093 /* Ignore subprogram DIEs that do not have a name, they are
4094 illegal. Do not emit a complaint at this point, we will
4095 do so when we convert this psymtab into a symtab. */
4097 add_partial_symbol (pdi
, cu
);
4101 if (! pdi
->has_children
)
4104 if (cu
->language
== language_ada
)
4106 pdi
= pdi
->die_child
;
4109 fixup_partial_die (pdi
, cu
);
4110 if (pdi
->tag
== DW_TAG_subprogram
4111 || pdi
->tag
== DW_TAG_lexical_block
)
4112 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4113 pdi
= pdi
->die_sibling
;
4118 /* Read a partial die corresponding to an enumeration type. */
4121 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4122 struct dwarf2_cu
*cu
)
4124 struct partial_die_info
*pdi
;
4126 if (enum_pdi
->name
!= NULL
)
4127 add_partial_symbol (enum_pdi
, cu
);
4129 pdi
= enum_pdi
->die_child
;
4132 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4133 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4135 add_partial_symbol (pdi
, cu
);
4136 pdi
= pdi
->die_sibling
;
4140 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4141 Return the corresponding abbrev, or NULL if the number is zero (indicating
4142 an empty DIE). In either case *BYTES_READ will be set to the length of
4143 the initial number. */
4145 static struct abbrev_info
*
4146 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4147 struct dwarf2_cu
*cu
)
4149 bfd
*abfd
= cu
->objfile
->obfd
;
4150 unsigned int abbrev_number
;
4151 struct abbrev_info
*abbrev
;
4153 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4155 if (abbrev_number
== 0)
4158 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4161 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4162 abbrev_number
, bfd_get_filename (abfd
));
4168 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4169 Returns a pointer to the end of a series of DIEs, terminated by an empty
4170 DIE. Any children of the skipped DIEs will also be skipped. */
4173 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4175 struct abbrev_info
*abbrev
;
4176 unsigned int bytes_read
;
4180 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4182 return info_ptr
+ bytes_read
;
4184 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4188 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4189 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4190 abbrev corresponding to that skipped uleb128 should be passed in
4191 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4195 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4196 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4198 unsigned int bytes_read
;
4199 struct attribute attr
;
4200 bfd
*abfd
= cu
->objfile
->obfd
;
4201 unsigned int form
, i
;
4203 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4205 /* The only abbrev we care about is DW_AT_sibling. */
4206 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4208 read_attribute (&attr
, &abbrev
->attrs
[i
],
4209 abfd
, info_ptr
, cu
);
4210 if (attr
.form
== DW_FORM_ref_addr
)
4211 complaint (&symfile_complaints
,
4212 _("ignoring absolute DW_AT_sibling"));
4214 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4217 /* If it isn't DW_AT_sibling, skip this attribute. */
4218 form
= abbrev
->attrs
[i
].form
;
4222 case DW_FORM_ref_addr
:
4223 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4224 and later it is offset sized. */
4225 if (cu
->header
.version
== 2)
4226 info_ptr
+= cu
->header
.addr_size
;
4228 info_ptr
+= cu
->header
.offset_size
;
4231 info_ptr
+= cu
->header
.addr_size
;
4238 case DW_FORM_flag_present
:
4250 case DW_FORM_ref_sig8
:
4253 case DW_FORM_string
:
4254 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4255 info_ptr
+= bytes_read
;
4257 case DW_FORM_sec_offset
:
4259 info_ptr
+= cu
->header
.offset_size
;
4261 case DW_FORM_exprloc
:
4263 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4264 info_ptr
+= bytes_read
;
4266 case DW_FORM_block1
:
4267 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4269 case DW_FORM_block2
:
4270 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4272 case DW_FORM_block4
:
4273 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4277 case DW_FORM_ref_udata
:
4278 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4280 case DW_FORM_indirect
:
4281 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4282 info_ptr
+= bytes_read
;
4283 /* We need to continue parsing from here, so just go back to
4285 goto skip_attribute
;
4288 error (_("Dwarf Error: Cannot handle %s "
4289 "in DWARF reader [in module %s]"),
4290 dwarf_form_name (form
),
4291 bfd_get_filename (abfd
));
4295 if (abbrev
->has_children
)
4296 return skip_children (buffer
, info_ptr
, cu
);
4301 /* Locate ORIG_PDI's sibling.
4302 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4306 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4307 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4308 bfd
*abfd
, struct dwarf2_cu
*cu
)
4310 /* Do we know the sibling already? */
4312 if (orig_pdi
->sibling
)
4313 return orig_pdi
->sibling
;
4315 /* Are there any children to deal with? */
4317 if (!orig_pdi
->has_children
)
4320 /* Skip the children the long way. */
4322 return skip_children (buffer
, info_ptr
, cu
);
4325 /* Expand this partial symbol table into a full symbol table. */
4328 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4334 warning (_("bug: psymtab for %s is already read in."),
4341 printf_filtered (_("Reading in symbols for %s..."),
4343 gdb_flush (gdb_stdout
);
4346 /* Restore our global data. */
4347 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4348 dwarf2_objfile_data_key
);
4350 /* If this psymtab is constructed from a debug-only objfile, the
4351 has_section_at_zero flag will not necessarily be correct. We
4352 can get the correct value for this flag by looking at the data
4353 associated with the (presumably stripped) associated objfile. */
4354 if (pst
->objfile
->separate_debug_objfile_backlink
)
4356 struct dwarf2_per_objfile
*dpo_backlink
4357 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4358 dwarf2_objfile_data_key
);
4360 dwarf2_per_objfile
->has_section_at_zero
4361 = dpo_backlink
->has_section_at_zero
;
4364 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4366 psymtab_to_symtab_1 (pst
);
4368 /* Finish up the debug error message. */
4370 printf_filtered (_("done.\n"));
4375 /* Add PER_CU to the queue. */
4378 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4380 struct dwarf2_queue_item
*item
;
4383 item
= xmalloc (sizeof (*item
));
4384 item
->per_cu
= per_cu
;
4387 if (dwarf2_queue
== NULL
)
4388 dwarf2_queue
= item
;
4390 dwarf2_queue_tail
->next
= item
;
4392 dwarf2_queue_tail
= item
;
4395 /* Process the queue. */
4398 process_queue (struct objfile
*objfile
)
4400 struct dwarf2_queue_item
*item
, *next_item
;
4402 /* The queue starts out with one item, but following a DIE reference
4403 may load a new CU, adding it to the end of the queue. */
4404 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4406 if (dwarf2_per_objfile
->using_index
4407 ? !item
->per_cu
->v
.quick
->symtab
4408 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4409 process_full_comp_unit (item
->per_cu
);
4411 item
->per_cu
->queued
= 0;
4412 next_item
= item
->next
;
4416 dwarf2_queue_tail
= NULL
;
4419 /* Free all allocated queue entries. This function only releases anything if
4420 an error was thrown; if the queue was processed then it would have been
4421 freed as we went along. */
4424 dwarf2_release_queue (void *dummy
)
4426 struct dwarf2_queue_item
*item
, *last
;
4428 item
= dwarf2_queue
;
4431 /* Anything still marked queued is likely to be in an
4432 inconsistent state, so discard it. */
4433 if (item
->per_cu
->queued
)
4435 if (item
->per_cu
->cu
!= NULL
)
4436 free_one_cached_comp_unit (item
->per_cu
->cu
);
4437 item
->per_cu
->queued
= 0;
4445 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4448 /* Read in full symbols for PST, and anything it depends on. */
4451 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4453 struct dwarf2_per_cu_data
*per_cu
;
4454 struct cleanup
*back_to
;
4457 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4458 if (!pst
->dependencies
[i
]->readin
)
4460 /* Inform about additional files that need to be read in. */
4463 /* FIXME: i18n: Need to make this a single string. */
4464 fputs_filtered (" ", gdb_stdout
);
4466 fputs_filtered ("and ", gdb_stdout
);
4468 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4469 wrap_here (""); /* Flush output. */
4470 gdb_flush (gdb_stdout
);
4472 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4475 per_cu
= pst
->read_symtab_private
;
4479 /* It's an include file, no symbols to read for it.
4480 Everything is in the parent symtab. */
4485 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4488 /* Load the DIEs associated with PER_CU into memory. */
4491 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
4492 struct objfile
*objfile
)
4494 bfd
*abfd
= objfile
->obfd
;
4495 struct dwarf2_cu
*cu
;
4496 unsigned int offset
;
4497 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4498 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4499 struct attribute
*attr
;
4502 gdb_assert (! per_cu
->from_debug_types
);
4504 /* Set local variables from the partial symbol table info. */
4505 offset
= per_cu
->offset
;
4507 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4508 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4509 beg_of_comp_unit
= info_ptr
;
4511 if (per_cu
->cu
== NULL
)
4513 cu
= xmalloc (sizeof (*cu
));
4514 init_one_comp_unit (cu
, objfile
);
4518 /* If an error occurs while loading, release our storage. */
4519 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4521 /* Read in the comp_unit header. */
4522 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4524 /* Complete the cu_header. */
4525 cu
->header
.offset
= offset
;
4526 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4528 /* Read the abbrevs for this compilation unit. */
4529 dwarf2_read_abbrevs (abfd
, cu
);
4530 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4532 /* Link this compilation unit into the compilation unit tree. */
4534 cu
->per_cu
= per_cu
;
4536 /* Link this CU into read_in_chain. */
4537 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4538 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4543 info_ptr
+= cu
->header
.first_die_offset
;
4546 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4548 /* We try not to read any attributes in this function, because not
4549 all objfiles needed for references have been loaded yet, and symbol
4550 table processing isn't initialized. But we have to set the CU language,
4551 or we won't be able to build types correctly. */
4552 prepare_one_comp_unit (cu
, cu
->dies
);
4554 /* Similarly, if we do not read the producer, we can not apply
4555 producer-specific interpretation. */
4556 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4558 cu
->producer
= DW_STRING (attr
);
4562 do_cleanups (free_abbrevs_cleanup
);
4564 /* We've successfully allocated this compilation unit. Let our
4565 caller clean it up when finished with it. */
4566 discard_cleanups (free_cu_cleanup
);
4570 /* Add a DIE to the delayed physname list. */
4573 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4574 const char *name
, struct die_info
*die
,
4575 struct dwarf2_cu
*cu
)
4577 struct delayed_method_info mi
;
4579 mi
.fnfield_index
= fnfield_index
;
4583 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4586 /* A cleanup for freeing the delayed method list. */
4589 free_delayed_list (void *ptr
)
4591 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4592 if (cu
->method_list
!= NULL
)
4594 VEC_free (delayed_method_info
, cu
->method_list
);
4595 cu
->method_list
= NULL
;
4599 /* Compute the physnames of any methods on the CU's method list.
4601 The computation of method physnames is delayed in order to avoid the
4602 (bad) condition that one of the method's formal parameters is of an as yet
4606 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4609 struct delayed_method_info
*mi
;
4610 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4613 struct fn_fieldlist
*fn_flp
4614 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4615 physname
= (char *) dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4616 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4620 /* Check for GCC >= 4.0. */
4623 producer_is_gcc_ge_4_0 (struct dwarf2_cu
*cu
)
4628 if (cu
->producer
== NULL
)
4630 /* For unknown compilers expect their behavior is not compliant. For GCC
4631 this case can also happen for -gdwarf-4 type units supported since
4637 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
4639 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
4641 /* For non-GCC compilers expect their behavior is not compliant. */
4645 cs
= &cu
->producer
[strlen ("GNU ")];
4646 while (*cs
&& !isdigit (*cs
))
4648 if (sscanf (cs
, "%d.%d", &major
, &minor
) != 2)
4650 /* Not recognized as GCC. */
4658 /* Generate full symbol information for PST and CU, whose DIEs have
4659 already been loaded into memory. */
4662 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4664 struct dwarf2_cu
*cu
= per_cu
->cu
;
4665 struct objfile
*objfile
= per_cu
->objfile
;
4666 CORE_ADDR lowpc
, highpc
;
4667 struct symtab
*symtab
;
4668 struct cleanup
*back_to
, *delayed_list_cleanup
;
4671 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4674 back_to
= make_cleanup (really_free_pendings
, NULL
);
4675 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4677 cu
->list_in_scope
= &file_symbols
;
4679 dwarf2_find_base_address (cu
->dies
, cu
);
4681 /* Do line number decoding in read_file_scope () */
4682 process_die (cu
->dies
, cu
);
4684 /* Now that we have processed all the DIEs in the CU, all the types
4685 should be complete, and it should now be safe to compute all of the
4687 compute_delayed_physnames (cu
);
4688 do_cleanups (delayed_list_cleanup
);
4690 /* Some compilers don't define a DW_AT_high_pc attribute for the
4691 compilation unit. If the DW_AT_high_pc is missing, synthesize
4692 it, by scanning the DIE's below the compilation unit. */
4693 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4695 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4699 /* Set symtab language to language from DW_AT_language. If the
4700 compilation is from a C file generated by language preprocessors, do
4701 not set the language if it was already deduced by start_subfile. */
4702 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4703 symtab
->language
= cu
->language
;
4705 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4706 produce DW_AT_location with location lists but it can be possibly
4707 invalid without -fvar-tracking.
4709 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4710 needed, it would be wrong due to missing DW_AT_producer there.
4712 Still one can confuse GDB by using non-standard GCC compilation
4713 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4715 if (cu
->has_loclist
&& producer_is_gcc_ge_4_0 (cu
))
4716 symtab
->locations_valid
= 1;
4719 if (dwarf2_per_objfile
->using_index
)
4720 per_cu
->v
.quick
->symtab
= symtab
;
4723 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4724 pst
->symtab
= symtab
;
4728 do_cleanups (back_to
);
4731 /* Process a die and its children. */
4734 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4738 case DW_TAG_padding
:
4740 case DW_TAG_compile_unit
:
4741 read_file_scope (die
, cu
);
4743 case DW_TAG_type_unit
:
4744 read_type_unit_scope (die
, cu
);
4746 case DW_TAG_subprogram
:
4747 case DW_TAG_inlined_subroutine
:
4748 read_func_scope (die
, cu
);
4750 case DW_TAG_lexical_block
:
4751 case DW_TAG_try_block
:
4752 case DW_TAG_catch_block
:
4753 read_lexical_block_scope (die
, cu
);
4755 case DW_TAG_class_type
:
4756 case DW_TAG_interface_type
:
4757 case DW_TAG_structure_type
:
4758 case DW_TAG_union_type
:
4759 process_structure_scope (die
, cu
);
4761 case DW_TAG_enumeration_type
:
4762 process_enumeration_scope (die
, cu
);
4765 /* These dies have a type, but processing them does not create
4766 a symbol or recurse to process the children. Therefore we can
4767 read them on-demand through read_type_die. */
4768 case DW_TAG_subroutine_type
:
4769 case DW_TAG_set_type
:
4770 case DW_TAG_array_type
:
4771 case DW_TAG_pointer_type
:
4772 case DW_TAG_ptr_to_member_type
:
4773 case DW_TAG_reference_type
:
4774 case DW_TAG_string_type
:
4777 case DW_TAG_base_type
:
4778 case DW_TAG_subrange_type
:
4779 case DW_TAG_typedef
:
4780 /* Add a typedef symbol for the type definition, if it has a
4782 new_symbol (die
, read_type_die (die
, cu
), cu
);
4784 case DW_TAG_common_block
:
4785 read_common_block (die
, cu
);
4787 case DW_TAG_common_inclusion
:
4789 case DW_TAG_namespace
:
4790 processing_has_namespace_info
= 1;
4791 read_namespace (die
, cu
);
4794 processing_has_namespace_info
= 1;
4795 read_module (die
, cu
);
4797 case DW_TAG_imported_declaration
:
4798 case DW_TAG_imported_module
:
4799 processing_has_namespace_info
= 1;
4800 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4801 || cu
->language
!= language_fortran
))
4802 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4803 dwarf_tag_name (die
->tag
));
4804 read_import_statement (die
, cu
);
4807 new_symbol (die
, NULL
, cu
);
4812 /* A helper function for dwarf2_compute_name which determines whether DIE
4813 needs to have the name of the scope prepended to the name listed in the
4817 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4819 struct attribute
*attr
;
4823 case DW_TAG_namespace
:
4824 case DW_TAG_typedef
:
4825 case DW_TAG_class_type
:
4826 case DW_TAG_interface_type
:
4827 case DW_TAG_structure_type
:
4828 case DW_TAG_union_type
:
4829 case DW_TAG_enumeration_type
:
4830 case DW_TAG_enumerator
:
4831 case DW_TAG_subprogram
:
4835 case DW_TAG_variable
:
4836 case DW_TAG_constant
:
4837 /* We only need to prefix "globally" visible variables. These include
4838 any variable marked with DW_AT_external or any variable that
4839 lives in a namespace. [Variables in anonymous namespaces
4840 require prefixing, but they are not DW_AT_external.] */
4842 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4844 struct dwarf2_cu
*spec_cu
= cu
;
4846 return die_needs_namespace (die_specification (die
, &spec_cu
),
4850 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4851 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4852 && die
->parent
->tag
!= DW_TAG_module
)
4854 /* A variable in a lexical block of some kind does not need a
4855 namespace, even though in C++ such variables may be external
4856 and have a mangled name. */
4857 if (die
->parent
->tag
== DW_TAG_lexical_block
4858 || die
->parent
->tag
== DW_TAG_try_block
4859 || die
->parent
->tag
== DW_TAG_catch_block
4860 || die
->parent
->tag
== DW_TAG_subprogram
)
4869 /* Retrieve the last character from a mem_file. */
4872 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4874 char *last_char_p
= (char *) object
;
4877 *last_char_p
= buffer
[length
- 1];
4880 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4881 compute the physname for the object, which include a method's
4882 formal parameters (C++/Java) and return type (Java).
4884 For Ada, return the DIE's linkage name rather than the fully qualified
4885 name. PHYSNAME is ignored..
4887 The result is allocated on the objfile_obstack and canonicalized. */
4890 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4894 name
= dwarf2_name (die
, cu
);
4896 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4897 compute it by typename_concat inside GDB. */
4898 if (cu
->language
== language_ada
4899 || (cu
->language
== language_fortran
&& physname
))
4901 /* For Ada unit, we prefer the linkage name over the name, as
4902 the former contains the exported name, which the user expects
4903 to be able to reference. Ideally, we want the user to be able
4904 to reference this entity using either natural or linkage name,
4905 but we haven't started looking at this enhancement yet. */
4906 struct attribute
*attr
;
4908 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4910 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4911 if (attr
&& DW_STRING (attr
))
4912 return DW_STRING (attr
);
4915 /* These are the only languages we know how to qualify names in. */
4917 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4918 || cu
->language
== language_fortran
))
4920 if (die_needs_namespace (die
, cu
))
4924 struct ui_file
*buf
;
4926 prefix
= determine_prefix (die
, cu
);
4927 buf
= mem_fileopen ();
4928 if (*prefix
!= '\0')
4930 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4933 fputs_unfiltered (prefixed_name
, buf
);
4934 xfree (prefixed_name
);
4937 fputs_unfiltered (name
, buf
);
4939 /* Template parameters may be specified in the DIE's DW_AT_name, or
4940 as children with DW_TAG_template_type_param or
4941 DW_TAG_value_type_param. If the latter, add them to the name
4942 here. If the name already has template parameters, then
4943 skip this step; some versions of GCC emit both, and
4944 it is more efficient to use the pre-computed name.
4946 Something to keep in mind about this process: it is very
4947 unlikely, or in some cases downright impossible, to produce
4948 something that will match the mangled name of a function.
4949 If the definition of the function has the same debug info,
4950 we should be able to match up with it anyway. But fallbacks
4951 using the minimal symbol, for instance to find a method
4952 implemented in a stripped copy of libstdc++, will not work.
4953 If we do not have debug info for the definition, we will have to
4954 match them up some other way.
4956 When we do name matching there is a related problem with function
4957 templates; two instantiated function templates are allowed to
4958 differ only by their return types, which we do not add here. */
4960 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
4962 struct attribute
*attr
;
4963 struct die_info
*child
;
4966 die
->building_fullname
= 1;
4968 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
4973 struct dwarf2_locexpr_baton
*baton
;
4976 if (child
->tag
!= DW_TAG_template_type_param
4977 && child
->tag
!= DW_TAG_template_value_param
)
4982 fputs_unfiltered ("<", buf
);
4986 fputs_unfiltered (", ", buf
);
4988 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
4991 complaint (&symfile_complaints
,
4992 _("template parameter missing DW_AT_type"));
4993 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
4996 type
= die_type (child
, cu
);
4998 if (child
->tag
== DW_TAG_template_type_param
)
5000 c_print_type (type
, "", buf
, -1, 0);
5004 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5007 complaint (&symfile_complaints
,
5008 _("template parameter missing "
5009 "DW_AT_const_value"));
5010 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5014 dwarf2_const_value_attr (attr
, type
, name
,
5015 &cu
->comp_unit_obstack
, cu
,
5016 &value
, &bytes
, &baton
);
5018 if (TYPE_NOSIGN (type
))
5019 /* GDB prints characters as NUMBER 'CHAR'. If that's
5020 changed, this can use value_print instead. */
5021 c_printchar (value
, type
, buf
);
5024 struct value_print_options opts
;
5027 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5031 else if (bytes
!= NULL
)
5033 v
= allocate_value (type
);
5034 memcpy (value_contents_writeable (v
), bytes
,
5035 TYPE_LENGTH (type
));
5038 v
= value_from_longest (type
, value
);
5040 /* Specify decimal so that we do not depend on
5042 get_formatted_print_options (&opts
, 'd');
5044 value_print (v
, buf
, &opts
);
5050 die
->building_fullname
= 0;
5054 /* Close the argument list, with a space if necessary
5055 (nested templates). */
5056 char last_char
= '\0';
5057 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5058 if (last_char
== '>')
5059 fputs_unfiltered (" >", buf
);
5061 fputs_unfiltered (">", buf
);
5065 /* For Java and C++ methods, append formal parameter type
5066 information, if PHYSNAME. */
5068 if (physname
&& die
->tag
== DW_TAG_subprogram
5069 && (cu
->language
== language_cplus
5070 || cu
->language
== language_java
))
5072 struct type
*type
= read_type_die (die
, cu
);
5074 c_type_print_args (type
, buf
, 1, cu
->language
);
5076 if (cu
->language
== language_java
)
5078 /* For java, we must append the return type to method
5080 if (die
->tag
== DW_TAG_subprogram
)
5081 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5084 else if (cu
->language
== language_cplus
)
5086 /* Assume that an artificial first parameter is
5087 "this", but do not crash if it is not. RealView
5088 marks unnamed (and thus unused) parameters as
5089 artificial; there is no way to differentiate
5091 if (TYPE_NFIELDS (type
) > 0
5092 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5093 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5094 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5096 fputs_unfiltered (" const", buf
);
5100 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
5102 ui_file_delete (buf
);
5104 if (cu
->language
== language_cplus
)
5107 = dwarf2_canonicalize_name (name
, cu
,
5108 &cu
->objfile
->objfile_obstack
);
5119 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5120 If scope qualifiers are appropriate they will be added. The result
5121 will be allocated on the objfile_obstack, or NULL if the DIE does
5122 not have a name. NAME may either be from a previous call to
5123 dwarf2_name or NULL.
5125 The output string will be canonicalized (if C++/Java). */
5128 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5130 return dwarf2_compute_name (name
, die
, cu
, 0);
5133 /* Construct a physname for the given DIE in CU. NAME may either be
5134 from a previous call to dwarf2_name or NULL. The result will be
5135 allocated on the objfile_objstack or NULL if the DIE does not have a
5138 The output string will be canonicalized (if C++/Java). */
5141 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5143 return dwarf2_compute_name (name
, die
, cu
, 1);
5146 /* Read the import statement specified by the given die and record it. */
5149 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5151 struct attribute
*import_attr
;
5152 struct die_info
*imported_die
;
5153 struct dwarf2_cu
*imported_cu
;
5154 const char *imported_name
;
5155 const char *imported_name_prefix
;
5156 const char *canonical_name
;
5157 const char *import_alias
;
5158 const char *imported_declaration
= NULL
;
5159 const char *import_prefix
;
5163 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5164 if (import_attr
== NULL
)
5166 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5167 dwarf_tag_name (die
->tag
));
5172 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5173 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5174 if (imported_name
== NULL
)
5176 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5178 The import in the following code:
5192 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5193 <52> DW_AT_decl_file : 1
5194 <53> DW_AT_decl_line : 6
5195 <54> DW_AT_import : <0x75>
5196 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5198 <5b> DW_AT_decl_file : 1
5199 <5c> DW_AT_decl_line : 2
5200 <5d> DW_AT_type : <0x6e>
5202 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5203 <76> DW_AT_byte_size : 4
5204 <77> DW_AT_encoding : 5 (signed)
5206 imports the wrong die ( 0x75 instead of 0x58 ).
5207 This case will be ignored until the gcc bug is fixed. */
5211 /* Figure out the local name after import. */
5212 import_alias
= dwarf2_name (die
, cu
);
5214 /* Figure out where the statement is being imported to. */
5215 import_prefix
= determine_prefix (die
, cu
);
5217 /* Figure out what the scope of the imported die is and prepend it
5218 to the name of the imported die. */
5219 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5221 if (imported_die
->tag
!= DW_TAG_namespace
5222 && imported_die
->tag
!= DW_TAG_module
)
5224 imported_declaration
= imported_name
;
5225 canonical_name
= imported_name_prefix
;
5227 else if (strlen (imported_name_prefix
) > 0)
5229 temp
= alloca (strlen (imported_name_prefix
)
5230 + 2 + strlen (imported_name
) + 1);
5231 strcpy (temp
, imported_name_prefix
);
5232 strcat (temp
, "::");
5233 strcat (temp
, imported_name
);
5234 canonical_name
= temp
;
5237 canonical_name
= imported_name
;
5239 cp_add_using_directive (import_prefix
,
5242 imported_declaration
,
5243 &cu
->objfile
->objfile_obstack
);
5247 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5249 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5252 /* Cleanup function for read_file_scope. */
5255 free_cu_line_header (void *arg
)
5257 struct dwarf2_cu
*cu
= arg
;
5259 free_line_header (cu
->line_header
);
5260 cu
->line_header
= NULL
;
5264 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5265 char **name
, char **comp_dir
)
5267 struct attribute
*attr
;
5272 /* Find the filename. Do not use dwarf2_name here, since the filename
5273 is not a source language identifier. */
5274 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5277 *name
= DW_STRING (attr
);
5280 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5282 *comp_dir
= DW_STRING (attr
);
5283 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5285 *comp_dir
= ldirname (*name
);
5286 if (*comp_dir
!= NULL
)
5287 make_cleanup (xfree
, *comp_dir
);
5289 if (*comp_dir
!= NULL
)
5291 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5292 directory, get rid of it. */
5293 char *cp
= strchr (*comp_dir
, ':');
5295 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5300 *name
= "<unknown>";
5303 /* Process DW_TAG_compile_unit. */
5306 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5308 struct objfile
*objfile
= cu
->objfile
;
5309 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5310 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5311 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5312 struct attribute
*attr
;
5314 char *comp_dir
= NULL
;
5315 struct die_info
*child_die
;
5316 bfd
*abfd
= objfile
->obfd
;
5317 struct line_header
*line_header
= 0;
5320 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5322 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5324 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5325 from finish_block. */
5326 if (lowpc
== ((CORE_ADDR
) -1))
5331 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5333 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5336 set_cu_language (DW_UNSND (attr
), cu
);
5339 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5341 cu
->producer
= DW_STRING (attr
);
5343 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5344 standardised yet. As a workaround for the language detection we fall
5345 back to the DW_AT_producer string. */
5346 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5347 cu
->language
= language_opencl
;
5349 /* We assume that we're processing GCC output. */
5350 processing_gcc_compilation
= 2;
5352 processing_has_namespace_info
= 0;
5354 start_symtab (name
, comp_dir
, lowpc
);
5355 record_debugformat ("DWARF 2");
5356 record_producer (cu
->producer
);
5358 initialize_cu_func_list (cu
);
5360 /* Decode line number information if present. We do this before
5361 processing child DIEs, so that the line header table is available
5362 for DW_AT_decl_file. */
5363 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5366 unsigned int line_offset
= DW_UNSND (attr
);
5367 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5370 cu
->line_header
= line_header
;
5371 make_cleanup (free_cu_line_header
, cu
);
5372 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5376 /* Process all dies in compilation unit. */
5377 if (die
->child
!= NULL
)
5379 child_die
= die
->child
;
5380 while (child_die
&& child_die
->tag
)
5382 process_die (child_die
, cu
);
5383 child_die
= sibling_die (child_die
);
5387 /* Decode macro information, if present. Dwarf 2 macro information
5388 refers to information in the line number info statement program
5389 header, so we can only read it if we've read the header
5391 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5392 if (attr
&& line_header
)
5394 unsigned int macro_offset
= DW_UNSND (attr
);
5396 dwarf_decode_macros (line_header
, macro_offset
,
5397 comp_dir
, abfd
, cu
);
5399 do_cleanups (back_to
);
5402 /* Process DW_TAG_type_unit.
5403 For TUs we want to skip the first top level sibling if it's not the
5404 actual type being defined by this TU. In this case the first top
5405 level sibling is there to provide context only. */
5408 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5410 struct objfile
*objfile
= cu
->objfile
;
5411 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5413 struct attribute
*attr
;
5415 char *comp_dir
= NULL
;
5416 struct die_info
*child_die
;
5417 bfd
*abfd
= objfile
->obfd
;
5419 /* start_symtab needs a low pc, but we don't really have one.
5420 Do what read_file_scope would do in the absence of such info. */
5421 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5423 /* Find the filename. Do not use dwarf2_name here, since the filename
5424 is not a source language identifier. */
5425 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5427 name
= DW_STRING (attr
);
5429 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5431 comp_dir
= DW_STRING (attr
);
5432 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5434 comp_dir
= ldirname (name
);
5435 if (comp_dir
!= NULL
)
5436 make_cleanup (xfree
, comp_dir
);
5442 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5444 set_cu_language (DW_UNSND (attr
), cu
);
5446 /* This isn't technically needed today. It is done for symmetry
5447 with read_file_scope. */
5448 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5450 cu
->producer
= DW_STRING (attr
);
5452 /* We assume that we're processing GCC output. */
5453 processing_gcc_compilation
= 2;
5455 processing_has_namespace_info
= 0;
5457 start_symtab (name
, comp_dir
, lowpc
);
5458 record_debugformat ("DWARF 2");
5459 record_producer (cu
->producer
);
5461 /* Process the dies in the type unit. */
5462 if (die
->child
== NULL
)
5464 dump_die_for_error (die
);
5465 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5466 bfd_get_filename (abfd
));
5469 child_die
= die
->child
;
5471 while (child_die
&& child_die
->tag
)
5473 process_die (child_die
, cu
);
5475 child_die
= sibling_die (child_die
);
5478 do_cleanups (back_to
);
5482 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5483 struct dwarf2_cu
*cu
)
5485 struct function_range
*thisfn
;
5487 thisfn
= (struct function_range
*)
5488 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5489 thisfn
->name
= name
;
5490 thisfn
->lowpc
= lowpc
;
5491 thisfn
->highpc
= highpc
;
5492 thisfn
->seen_line
= 0;
5493 thisfn
->next
= NULL
;
5495 if (cu
->last_fn
== NULL
)
5496 cu
->first_fn
= thisfn
;
5498 cu
->last_fn
->next
= thisfn
;
5500 cu
->last_fn
= thisfn
;
5503 /* qsort helper for inherit_abstract_dies. */
5506 unsigned_int_compar (const void *ap
, const void *bp
)
5508 unsigned int a
= *(unsigned int *) ap
;
5509 unsigned int b
= *(unsigned int *) bp
;
5511 return (a
> b
) - (b
> a
);
5514 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5515 Inherit only the children of the DW_AT_abstract_origin DIE not being
5516 already referenced by DW_AT_abstract_origin from the children of the
5520 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5522 struct die_info
*child_die
;
5523 unsigned die_children_count
;
5524 /* CU offsets which were referenced by children of the current DIE. */
5526 unsigned *offsets_end
, *offsetp
;
5527 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5528 struct die_info
*origin_die
;
5529 /* Iterator of the ORIGIN_DIE children. */
5530 struct die_info
*origin_child_die
;
5531 struct cleanup
*cleanups
;
5532 struct attribute
*attr
;
5533 struct dwarf2_cu
*origin_cu
;
5534 struct pending
**origin_previous_list_in_scope
;
5536 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5540 /* Note that following die references may follow to a die in a
5544 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5546 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5548 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5549 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5551 if (die
->tag
!= origin_die
->tag
5552 && !(die
->tag
== DW_TAG_inlined_subroutine
5553 && origin_die
->tag
== DW_TAG_subprogram
))
5554 complaint (&symfile_complaints
,
5555 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5556 die
->offset
, origin_die
->offset
);
5558 child_die
= die
->child
;
5559 die_children_count
= 0;
5560 while (child_die
&& child_die
->tag
)
5562 child_die
= sibling_die (child_die
);
5563 die_children_count
++;
5565 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5566 cleanups
= make_cleanup (xfree
, offsets
);
5568 offsets_end
= offsets
;
5569 child_die
= die
->child
;
5570 while (child_die
&& child_die
->tag
)
5572 /* For each CHILD_DIE, find the corresponding child of
5573 ORIGIN_DIE. If there is more than one layer of
5574 DW_AT_abstract_origin, follow them all; there shouldn't be,
5575 but GCC versions at least through 4.4 generate this (GCC PR
5577 struct die_info
*child_origin_die
= child_die
;
5578 struct dwarf2_cu
*child_origin_cu
= cu
;
5582 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5586 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5590 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5591 counterpart may exist. */
5592 if (child_origin_die
!= child_die
)
5594 if (child_die
->tag
!= child_origin_die
->tag
5595 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5596 && child_origin_die
->tag
== DW_TAG_subprogram
))
5597 complaint (&symfile_complaints
,
5598 _("Child DIE 0x%x and its abstract origin 0x%x have "
5599 "different tags"), child_die
->offset
,
5600 child_origin_die
->offset
);
5601 if (child_origin_die
->parent
!= origin_die
)
5602 complaint (&symfile_complaints
,
5603 _("Child DIE 0x%x and its abstract origin 0x%x have "
5604 "different parents"), child_die
->offset
,
5605 child_origin_die
->offset
);
5607 *offsets_end
++ = child_origin_die
->offset
;
5609 child_die
= sibling_die (child_die
);
5611 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5612 unsigned_int_compar
);
5613 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5614 if (offsetp
[-1] == *offsetp
)
5615 complaint (&symfile_complaints
,
5616 _("Multiple children of DIE 0x%x refer "
5617 "to DIE 0x%x as their abstract origin"),
5618 die
->offset
, *offsetp
);
5621 origin_child_die
= origin_die
->child
;
5622 while (origin_child_die
&& origin_child_die
->tag
)
5624 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5625 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5627 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5629 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5630 process_die (origin_child_die
, origin_cu
);
5632 origin_child_die
= sibling_die (origin_child_die
);
5634 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5636 do_cleanups (cleanups
);
5640 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5642 struct objfile
*objfile
= cu
->objfile
;
5643 struct context_stack
*new;
5646 struct die_info
*child_die
;
5647 struct attribute
*attr
, *call_line
, *call_file
;
5650 struct block
*block
;
5651 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5652 VEC (symbolp
) *template_args
= NULL
;
5653 struct template_symbol
*templ_func
= NULL
;
5657 /* If we do not have call site information, we can't show the
5658 caller of this inlined function. That's too confusing, so
5659 only use the scope for local variables. */
5660 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5661 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5662 if (call_line
== NULL
|| call_file
== NULL
)
5664 read_lexical_block_scope (die
, cu
);
5669 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5671 name
= dwarf2_name (die
, cu
);
5673 /* Ignore functions with missing or empty names. These are actually
5674 illegal according to the DWARF standard. */
5677 complaint (&symfile_complaints
,
5678 _("missing name for subprogram DIE at %d"), die
->offset
);
5682 /* Ignore functions with missing or invalid low and high pc attributes. */
5683 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5685 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5686 if (!attr
|| !DW_UNSND (attr
))
5687 complaint (&symfile_complaints
,
5688 _("cannot get low and high bounds "
5689 "for subprogram DIE at %d"),
5697 /* Record the function range for dwarf_decode_lines. */
5698 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5700 /* If we have any template arguments, then we must allocate a
5701 different sort of symbol. */
5702 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5704 if (child_die
->tag
== DW_TAG_template_type_param
5705 || child_die
->tag
== DW_TAG_template_value_param
)
5707 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5708 struct template_symbol
);
5709 templ_func
->base
.is_cplus_template_function
= 1;
5714 new = push_context (0, lowpc
);
5715 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5716 (struct symbol
*) templ_func
);
5718 /* If there is a location expression for DW_AT_frame_base, record
5720 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5722 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5723 expression is being recorded directly in the function's symbol
5724 and not in a separate frame-base object. I guess this hack is
5725 to avoid adding some sort of frame-base adjunct/annex to the
5726 function's symbol :-(. The problem with doing this is that it
5727 results in a function symbol with a location expression that
5728 has nothing to do with the location of the function, ouch! The
5729 relationship should be: a function's symbol has-a frame base; a
5730 frame-base has-a location expression. */
5731 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5733 cu
->list_in_scope
= &local_symbols
;
5735 if (die
->child
!= NULL
)
5737 child_die
= die
->child
;
5738 while (child_die
&& child_die
->tag
)
5740 if (child_die
->tag
== DW_TAG_template_type_param
5741 || child_die
->tag
== DW_TAG_template_value_param
)
5743 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5746 VEC_safe_push (symbolp
, template_args
, arg
);
5749 process_die (child_die
, cu
);
5750 child_die
= sibling_die (child_die
);
5754 inherit_abstract_dies (die
, cu
);
5756 /* If we have a DW_AT_specification, we might need to import using
5757 directives from the context of the specification DIE. See the
5758 comment in determine_prefix. */
5759 if (cu
->language
== language_cplus
5760 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5762 struct dwarf2_cu
*spec_cu
= cu
;
5763 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5767 child_die
= spec_die
->child
;
5768 while (child_die
&& child_die
->tag
)
5770 if (child_die
->tag
== DW_TAG_imported_module
)
5771 process_die (child_die
, spec_cu
);
5772 child_die
= sibling_die (child_die
);
5775 /* In some cases, GCC generates specification DIEs that
5776 themselves contain DW_AT_specification attributes. */
5777 spec_die
= die_specification (spec_die
, &spec_cu
);
5781 new = pop_context ();
5782 /* Make a block for the local symbols within. */
5783 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5784 lowpc
, highpc
, objfile
);
5786 /* For C++, set the block's scope. */
5787 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5788 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5789 determine_prefix (die
, cu
),
5790 processing_has_namespace_info
);
5792 /* If we have address ranges, record them. */
5793 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5795 /* Attach template arguments to function. */
5796 if (! VEC_empty (symbolp
, template_args
))
5798 gdb_assert (templ_func
!= NULL
);
5800 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5801 templ_func
->template_arguments
5802 = obstack_alloc (&objfile
->objfile_obstack
,
5803 (templ_func
->n_template_arguments
5804 * sizeof (struct symbol
*)));
5805 memcpy (templ_func
->template_arguments
,
5806 VEC_address (symbolp
, template_args
),
5807 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5808 VEC_free (symbolp
, template_args
);
5811 /* In C++, we can have functions nested inside functions (e.g., when
5812 a function declares a class that has methods). This means that
5813 when we finish processing a function scope, we may need to go
5814 back to building a containing block's symbol lists. */
5815 local_symbols
= new->locals
;
5816 param_symbols
= new->params
;
5817 using_directives
= new->using_directives
;
5819 /* If we've finished processing a top-level function, subsequent
5820 symbols go in the file symbol list. */
5821 if (outermost_context_p ())
5822 cu
->list_in_scope
= &file_symbols
;
5825 /* Process all the DIES contained within a lexical block scope. Start
5826 a new scope, process the dies, and then close the scope. */
5829 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5831 struct objfile
*objfile
= cu
->objfile
;
5832 struct context_stack
*new;
5833 CORE_ADDR lowpc
, highpc
;
5834 struct die_info
*child_die
;
5837 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5839 /* Ignore blocks with missing or invalid low and high pc attributes. */
5840 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5841 as multiple lexical blocks? Handling children in a sane way would
5842 be nasty. Might be easier to properly extend generic blocks to
5844 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5849 push_context (0, lowpc
);
5850 if (die
->child
!= NULL
)
5852 child_die
= die
->child
;
5853 while (child_die
&& child_die
->tag
)
5855 process_die (child_die
, cu
);
5856 child_die
= sibling_die (child_die
);
5859 new = pop_context ();
5861 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5864 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5867 /* Note that recording ranges after traversing children, as we
5868 do here, means that recording a parent's ranges entails
5869 walking across all its children's ranges as they appear in
5870 the address map, which is quadratic behavior.
5872 It would be nicer to record the parent's ranges before
5873 traversing its children, simply overriding whatever you find
5874 there. But since we don't even decide whether to create a
5875 block until after we've traversed its children, that's hard
5877 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5879 local_symbols
= new->locals
;
5880 using_directives
= new->using_directives
;
5883 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5884 Return 1 if the attributes are present and valid, otherwise, return 0.
5885 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5888 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5889 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5890 struct partial_symtab
*ranges_pst
)
5892 struct objfile
*objfile
= cu
->objfile
;
5893 struct comp_unit_head
*cu_header
= &cu
->header
;
5894 bfd
*obfd
= objfile
->obfd
;
5895 unsigned int addr_size
= cu_header
->addr_size
;
5896 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5897 /* Base address selection entry. */
5908 found_base
= cu
->base_known
;
5909 base
= cu
->base_address
;
5911 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5912 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5914 complaint (&symfile_complaints
,
5915 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5919 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5921 /* Read in the largest possible address. */
5922 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5923 if ((marker
& mask
) == mask
)
5925 /* If we found the largest possible address, then
5926 read the base address. */
5927 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5928 buffer
+= 2 * addr_size
;
5929 offset
+= 2 * addr_size
;
5935 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5939 CORE_ADDR range_beginning
, range_end
;
5941 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5942 buffer
+= addr_size
;
5943 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5944 buffer
+= addr_size
;
5945 offset
+= 2 * addr_size
;
5947 /* An end of list marker is a pair of zero addresses. */
5948 if (range_beginning
== 0 && range_end
== 0)
5949 /* Found the end of list entry. */
5952 /* Each base address selection entry is a pair of 2 values.
5953 The first is the largest possible address, the second is
5954 the base address. Check for a base address here. */
5955 if ((range_beginning
& mask
) == mask
)
5957 /* If we found the largest possible address, then
5958 read the base address. */
5959 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5966 /* We have no valid base address for the ranges
5968 complaint (&symfile_complaints
,
5969 _("Invalid .debug_ranges data (no base address)"));
5973 if (range_beginning
> range_end
)
5975 /* Inverted range entries are invalid. */
5976 complaint (&symfile_complaints
,
5977 _("Invalid .debug_ranges data (inverted range)"));
5981 /* Empty range entries have no effect. */
5982 if (range_beginning
== range_end
)
5985 range_beginning
+= base
;
5988 if (ranges_pst
!= NULL
)
5989 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5990 range_beginning
+ baseaddr
,
5991 range_end
- 1 + baseaddr
,
5994 /* FIXME: This is recording everything as a low-high
5995 segment of consecutive addresses. We should have a
5996 data structure for discontiguous block ranges
6000 low
= range_beginning
;
6006 if (range_beginning
< low
)
6007 low
= range_beginning
;
6008 if (range_end
> high
)
6014 /* If the first entry is an end-of-list marker, the range
6015 describes an empty scope, i.e. no instructions. */
6021 *high_return
= high
;
6025 /* Get low and high pc attributes from a die. Return 1 if the attributes
6026 are present and valid, otherwise, return 0. Return -1 if the range is
6027 discontinuous, i.e. derived from DW_AT_ranges information. */
6029 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6030 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6031 struct partial_symtab
*pst
)
6033 struct attribute
*attr
;
6038 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6041 high
= DW_ADDR (attr
);
6042 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6044 low
= DW_ADDR (attr
);
6046 /* Found high w/o low attribute. */
6049 /* Found consecutive range of addresses. */
6054 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6057 /* Value of the DW_AT_ranges attribute is the offset in the
6058 .debug_ranges section. */
6059 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6061 /* Found discontinuous range of addresses. */
6066 /* read_partial_die has also the strict LOW < HIGH requirement. */
6070 /* When using the GNU linker, .gnu.linkonce. sections are used to
6071 eliminate duplicate copies of functions and vtables and such.
6072 The linker will arbitrarily choose one and discard the others.
6073 The AT_*_pc values for such functions refer to local labels in
6074 these sections. If the section from that file was discarded, the
6075 labels are not in the output, so the relocs get a value of 0.
6076 If this is a discarded function, mark the pc bounds as invalid,
6077 so that GDB will ignore it. */
6078 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6086 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6087 its low and high PC addresses. Do nothing if these addresses could not
6088 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6089 and HIGHPC to the high address if greater than HIGHPC. */
6092 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6093 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6094 struct dwarf2_cu
*cu
)
6096 CORE_ADDR low
, high
;
6097 struct die_info
*child
= die
->child
;
6099 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6101 *lowpc
= min (*lowpc
, low
);
6102 *highpc
= max (*highpc
, high
);
6105 /* If the language does not allow nested subprograms (either inside
6106 subprograms or lexical blocks), we're done. */
6107 if (cu
->language
!= language_ada
)
6110 /* Check all the children of the given DIE. If it contains nested
6111 subprograms, then check their pc bounds. Likewise, we need to
6112 check lexical blocks as well, as they may also contain subprogram
6114 while (child
&& child
->tag
)
6116 if (child
->tag
== DW_TAG_subprogram
6117 || child
->tag
== DW_TAG_lexical_block
)
6118 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6119 child
= sibling_die (child
);
6123 /* Get the low and high pc's represented by the scope DIE, and store
6124 them in *LOWPC and *HIGHPC. If the correct values can't be
6125 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6128 get_scope_pc_bounds (struct die_info
*die
,
6129 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6130 struct dwarf2_cu
*cu
)
6132 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6133 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6134 CORE_ADDR current_low
, current_high
;
6136 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6138 best_low
= current_low
;
6139 best_high
= current_high
;
6143 struct die_info
*child
= die
->child
;
6145 while (child
&& child
->tag
)
6147 switch (child
->tag
) {
6148 case DW_TAG_subprogram
:
6149 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6151 case DW_TAG_namespace
:
6153 /* FIXME: carlton/2004-01-16: Should we do this for
6154 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6155 that current GCC's always emit the DIEs corresponding
6156 to definitions of methods of classes as children of a
6157 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6158 the DIEs giving the declarations, which could be
6159 anywhere). But I don't see any reason why the
6160 standards says that they have to be there. */
6161 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6163 if (current_low
!= ((CORE_ADDR
) -1))
6165 best_low
= min (best_low
, current_low
);
6166 best_high
= max (best_high
, current_high
);
6174 child
= sibling_die (child
);
6179 *highpc
= best_high
;
6182 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6185 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6186 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6188 struct attribute
*attr
;
6190 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6193 CORE_ADDR high
= DW_ADDR (attr
);
6195 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6198 CORE_ADDR low
= DW_ADDR (attr
);
6200 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6204 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6207 bfd
*obfd
= cu
->objfile
->obfd
;
6209 /* The value of the DW_AT_ranges attribute is the offset of the
6210 address range list in the .debug_ranges section. */
6211 unsigned long offset
= DW_UNSND (attr
);
6212 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6214 /* For some target architectures, but not others, the
6215 read_address function sign-extends the addresses it returns.
6216 To recognize base address selection entries, we need a
6218 unsigned int addr_size
= cu
->header
.addr_size
;
6219 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6221 /* The base address, to which the next pair is relative. Note
6222 that this 'base' is a DWARF concept: most entries in a range
6223 list are relative, to reduce the number of relocs against the
6224 debugging information. This is separate from this function's
6225 'baseaddr' argument, which GDB uses to relocate debugging
6226 information from a shared library based on the address at
6227 which the library was loaded. */
6228 CORE_ADDR base
= cu
->base_address
;
6229 int base_known
= cu
->base_known
;
6231 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6232 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6234 complaint (&symfile_complaints
,
6235 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6242 unsigned int bytes_read
;
6243 CORE_ADDR start
, end
;
6245 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6246 buffer
+= bytes_read
;
6247 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6248 buffer
+= bytes_read
;
6250 /* Did we find the end of the range list? */
6251 if (start
== 0 && end
== 0)
6254 /* Did we find a base address selection entry? */
6255 else if ((start
& base_select_mask
) == base_select_mask
)
6261 /* We found an ordinary address range. */
6266 complaint (&symfile_complaints
,
6267 _("Invalid .debug_ranges data "
6268 "(no base address)"));
6274 /* Inverted range entries are invalid. */
6275 complaint (&symfile_complaints
,
6276 _("Invalid .debug_ranges data "
6277 "(inverted range)"));
6281 /* Empty range entries have no effect. */
6285 record_block_range (block
,
6286 baseaddr
+ base
+ start
,
6287 baseaddr
+ base
+ end
- 1);
6293 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6294 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6295 during 4.6.0 experimental. */
6298 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6301 int major
, minor
, release
;
6303 if (cu
->producer
== NULL
)
6305 /* For unknown compilers expect their behavior is DWARF version
6308 GCC started to support .debug_types sections by -gdwarf-4 since
6309 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6310 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6311 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6312 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6317 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6319 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6321 /* For non-GCC compilers expect their behavior is DWARF version
6326 cs
= &cu
->producer
[strlen ("GNU ")];
6327 while (*cs
&& !isdigit (*cs
))
6329 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6331 /* Not recognized as GCC. */
6336 return major
< 4 || (major
== 4 && minor
< 6);
6339 /* Return the default accessibility type if it is not overriden by
6340 DW_AT_accessibility. */
6342 static enum dwarf_access_attribute
6343 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6345 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6347 /* The default DWARF 2 accessibility for members is public, the default
6348 accessibility for inheritance is private. */
6350 if (die
->tag
!= DW_TAG_inheritance
)
6351 return DW_ACCESS_public
;
6353 return DW_ACCESS_private
;
6357 /* DWARF 3+ defines the default accessibility a different way. The same
6358 rules apply now for DW_TAG_inheritance as for the members and it only
6359 depends on the container kind. */
6361 if (die
->parent
->tag
== DW_TAG_class_type
)
6362 return DW_ACCESS_private
;
6364 return DW_ACCESS_public
;
6368 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6369 offset. If the attribute was not found return 0, otherwise return
6370 1. If it was found but could not properly be handled, set *OFFSET
6374 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
6377 struct attribute
*attr
;
6379 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6384 /* Note that we do not check for a section offset first here.
6385 This is because DW_AT_data_member_location is new in DWARF 4,
6386 so if we see it, we can assume that a constant form is really
6387 a constant and not a section offset. */
6388 if (attr_form_is_constant (attr
))
6389 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
6390 else if (attr_form_is_section_offset (attr
))
6391 dwarf2_complex_location_expr_complaint ();
6392 else if (attr_form_is_block (attr
))
6393 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6395 dwarf2_complex_location_expr_complaint ();
6403 /* Add an aggregate field to the field list. */
6406 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6407 struct dwarf2_cu
*cu
)
6409 struct objfile
*objfile
= cu
->objfile
;
6410 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6411 struct nextfield
*new_field
;
6412 struct attribute
*attr
;
6414 char *fieldname
= "";
6416 /* Allocate a new field list entry and link it in. */
6417 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6418 make_cleanup (xfree
, new_field
);
6419 memset (new_field
, 0, sizeof (struct nextfield
));
6421 if (die
->tag
== DW_TAG_inheritance
)
6423 new_field
->next
= fip
->baseclasses
;
6424 fip
->baseclasses
= new_field
;
6428 new_field
->next
= fip
->fields
;
6429 fip
->fields
= new_field
;
6433 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6435 new_field
->accessibility
= DW_UNSND (attr
);
6437 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
6438 if (new_field
->accessibility
!= DW_ACCESS_public
)
6439 fip
->non_public_fields
= 1;
6441 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6443 new_field
->virtuality
= DW_UNSND (attr
);
6445 new_field
->virtuality
= DW_VIRTUALITY_none
;
6447 fp
= &new_field
->field
;
6449 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6453 /* Data member other than a C++ static data member. */
6455 /* Get type of field. */
6456 fp
->type
= die_type (die
, cu
);
6458 SET_FIELD_BITPOS (*fp
, 0);
6460 /* Get bit size of field (zero if none). */
6461 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6464 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6468 FIELD_BITSIZE (*fp
) = 0;
6471 /* Get bit offset of field. */
6472 if (handle_data_member_location (die
, cu
, &offset
))
6473 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
6474 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6477 if (gdbarch_bits_big_endian (gdbarch
))
6479 /* For big endian bits, the DW_AT_bit_offset gives the
6480 additional bit offset from the MSB of the containing
6481 anonymous object to the MSB of the field. We don't
6482 have to do anything special since we don't need to
6483 know the size of the anonymous object. */
6484 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6488 /* For little endian bits, compute the bit offset to the
6489 MSB of the anonymous object, subtract off the number of
6490 bits from the MSB of the field to the MSB of the
6491 object, and then subtract off the number of bits of
6492 the field itself. The result is the bit offset of
6493 the LSB of the field. */
6495 int bit_offset
= DW_UNSND (attr
);
6497 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6500 /* The size of the anonymous object containing
6501 the bit field is explicit, so use the
6502 indicated size (in bytes). */
6503 anonymous_size
= DW_UNSND (attr
);
6507 /* The size of the anonymous object containing
6508 the bit field must be inferred from the type
6509 attribute of the data member containing the
6511 anonymous_size
= TYPE_LENGTH (fp
->type
);
6513 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6514 - bit_offset
- FIELD_BITSIZE (*fp
);
6518 /* Get name of field. */
6519 fieldname
= dwarf2_name (die
, cu
);
6520 if (fieldname
== NULL
)
6523 /* The name is already allocated along with this objfile, so we don't
6524 need to duplicate it for the type. */
6525 fp
->name
= fieldname
;
6527 /* Change accessibility for artificial fields (e.g. virtual table
6528 pointer or virtual base class pointer) to private. */
6529 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6531 FIELD_ARTIFICIAL (*fp
) = 1;
6532 new_field
->accessibility
= DW_ACCESS_private
;
6533 fip
->non_public_fields
= 1;
6536 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6538 /* C++ static member. */
6540 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6541 is a declaration, but all versions of G++ as of this writing
6542 (so through at least 3.2.1) incorrectly generate
6543 DW_TAG_variable tags. */
6547 /* Get name of field. */
6548 fieldname
= dwarf2_name (die
, cu
);
6549 if (fieldname
== NULL
)
6552 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6554 /* Only create a symbol if this is an external value.
6555 new_symbol checks this and puts the value in the global symbol
6556 table, which we want. If it is not external, new_symbol
6557 will try to put the value in cu->list_in_scope which is wrong. */
6558 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6560 /* A static const member, not much different than an enum as far as
6561 we're concerned, except that we can support more types. */
6562 new_symbol (die
, NULL
, cu
);
6565 /* Get physical name. */
6566 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6568 /* The name is already allocated along with this objfile, so we don't
6569 need to duplicate it for the type. */
6570 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6571 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6572 FIELD_NAME (*fp
) = fieldname
;
6574 else if (die
->tag
== DW_TAG_inheritance
)
6578 /* C++ base class field. */
6579 if (handle_data_member_location (die
, cu
, &offset
))
6580 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
6581 FIELD_BITSIZE (*fp
) = 0;
6582 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6583 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6584 fip
->nbaseclasses
++;
6588 /* Add a typedef defined in the scope of the FIP's class. */
6591 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6592 struct dwarf2_cu
*cu
)
6594 struct objfile
*objfile
= cu
->objfile
;
6595 struct typedef_field_list
*new_field
;
6596 struct attribute
*attr
;
6597 struct typedef_field
*fp
;
6598 char *fieldname
= "";
6600 /* Allocate a new field list entry and link it in. */
6601 new_field
= xzalloc (sizeof (*new_field
));
6602 make_cleanup (xfree
, new_field
);
6604 gdb_assert (die
->tag
== DW_TAG_typedef
);
6606 fp
= &new_field
->field
;
6608 /* Get name of field. */
6609 fp
->name
= dwarf2_name (die
, cu
);
6610 if (fp
->name
== NULL
)
6613 fp
->type
= read_type_die (die
, cu
);
6615 new_field
->next
= fip
->typedef_field_list
;
6616 fip
->typedef_field_list
= new_field
;
6617 fip
->typedef_field_list_count
++;
6620 /* Create the vector of fields, and attach it to the type. */
6623 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6624 struct dwarf2_cu
*cu
)
6626 int nfields
= fip
->nfields
;
6628 /* Record the field count, allocate space for the array of fields,
6629 and create blank accessibility bitfields if necessary. */
6630 TYPE_NFIELDS (type
) = nfields
;
6631 TYPE_FIELDS (type
) = (struct field
*)
6632 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6633 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6635 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6637 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6639 TYPE_FIELD_PRIVATE_BITS (type
) =
6640 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6641 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6643 TYPE_FIELD_PROTECTED_BITS (type
) =
6644 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6645 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6647 TYPE_FIELD_IGNORE_BITS (type
) =
6648 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6649 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6652 /* If the type has baseclasses, allocate and clear a bit vector for
6653 TYPE_FIELD_VIRTUAL_BITS. */
6654 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6656 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6657 unsigned char *pointer
;
6659 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6660 pointer
= TYPE_ALLOC (type
, num_bytes
);
6661 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6662 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6663 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6666 /* Copy the saved-up fields into the field vector. Start from the head of
6667 the list, adding to the tail of the field array, so that they end up in
6668 the same order in the array in which they were added to the list. */
6669 while (nfields
-- > 0)
6671 struct nextfield
*fieldp
;
6675 fieldp
= fip
->fields
;
6676 fip
->fields
= fieldp
->next
;
6680 fieldp
= fip
->baseclasses
;
6681 fip
->baseclasses
= fieldp
->next
;
6684 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6685 switch (fieldp
->accessibility
)
6687 case DW_ACCESS_private
:
6688 if (cu
->language
!= language_ada
)
6689 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6692 case DW_ACCESS_protected
:
6693 if (cu
->language
!= language_ada
)
6694 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6697 case DW_ACCESS_public
:
6701 /* Unknown accessibility. Complain and treat it as public. */
6703 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6704 fieldp
->accessibility
);
6708 if (nfields
< fip
->nbaseclasses
)
6710 switch (fieldp
->virtuality
)
6712 case DW_VIRTUALITY_virtual
:
6713 case DW_VIRTUALITY_pure_virtual
:
6714 if (cu
->language
== language_ada
)
6715 error (_("unexpected virtuality in component of Ada type"));
6716 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6723 /* Add a member function to the proper fieldlist. */
6726 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6727 struct type
*type
, struct dwarf2_cu
*cu
)
6729 struct objfile
*objfile
= cu
->objfile
;
6730 struct attribute
*attr
;
6731 struct fnfieldlist
*flp
;
6733 struct fn_field
*fnp
;
6735 struct nextfnfield
*new_fnfield
;
6736 struct type
*this_type
;
6737 enum dwarf_access_attribute accessibility
;
6739 if (cu
->language
== language_ada
)
6740 error (_("unexpected member function in Ada type"));
6742 /* Get name of member function. */
6743 fieldname
= dwarf2_name (die
, cu
);
6744 if (fieldname
== NULL
)
6747 /* Look up member function name in fieldlist. */
6748 for (i
= 0; i
< fip
->nfnfields
; i
++)
6750 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6754 /* Create new list element if necessary. */
6755 if (i
< fip
->nfnfields
)
6756 flp
= &fip
->fnfieldlists
[i
];
6759 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6761 fip
->fnfieldlists
= (struct fnfieldlist
*)
6762 xrealloc (fip
->fnfieldlists
,
6763 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6764 * sizeof (struct fnfieldlist
));
6765 if (fip
->nfnfields
== 0)
6766 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6768 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6769 flp
->name
= fieldname
;
6772 i
= fip
->nfnfields
++;
6775 /* Create a new member function field and chain it to the field list
6777 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6778 make_cleanup (xfree
, new_fnfield
);
6779 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6780 new_fnfield
->next
= flp
->head
;
6781 flp
->head
= new_fnfield
;
6784 /* Fill in the member function field info. */
6785 fnp
= &new_fnfield
->fnfield
;
6787 /* Delay processing of the physname until later. */
6788 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
6790 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
6795 char *physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6796 fnp
->physname
= physname
? physname
: "";
6799 fnp
->type
= alloc_type (objfile
);
6800 this_type
= read_type_die (die
, cu
);
6801 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6803 int nparams
= TYPE_NFIELDS (this_type
);
6805 /* TYPE is the domain of this method, and THIS_TYPE is the type
6806 of the method itself (TYPE_CODE_METHOD). */
6807 smash_to_method_type (fnp
->type
, type
,
6808 TYPE_TARGET_TYPE (this_type
),
6809 TYPE_FIELDS (this_type
),
6810 TYPE_NFIELDS (this_type
),
6811 TYPE_VARARGS (this_type
));
6813 /* Handle static member functions.
6814 Dwarf2 has no clean way to discern C++ static and non-static
6815 member functions. G++ helps GDB by marking the first
6816 parameter for non-static member functions (which is the this
6817 pointer) as artificial. We obtain this information from
6818 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6819 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6820 fnp
->voffset
= VOFFSET_STATIC
;
6823 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
6824 dwarf2_full_name (fieldname
, die
, cu
));
6826 /* Get fcontext from DW_AT_containing_type if present. */
6827 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6828 fnp
->fcontext
= die_containing_type (die
, cu
);
6830 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
6831 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6833 /* Get accessibility. */
6834 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6836 accessibility
= DW_UNSND (attr
);
6838 accessibility
= dwarf2_default_access_attribute (die
, cu
);
6839 switch (accessibility
)
6841 case DW_ACCESS_private
:
6842 fnp
->is_private
= 1;
6844 case DW_ACCESS_protected
:
6845 fnp
->is_protected
= 1;
6849 /* Check for artificial methods. */
6850 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
6851 if (attr
&& DW_UNSND (attr
) != 0)
6852 fnp
->is_artificial
= 1;
6854 /* Get index in virtual function table if it is a virtual member
6855 function. For older versions of GCC, this is an offset in the
6856 appropriate virtual table, as specified by DW_AT_containing_type.
6857 For everyone else, it is an expression to be evaluated relative
6858 to the object address. */
6860 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
6863 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
6865 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
6867 /* Old-style GCC. */
6868 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
6870 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6871 || (DW_BLOCK (attr
)->size
> 1
6872 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
6873 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
6875 struct dwarf_block blk
;
6878 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6880 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
6881 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
6882 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6883 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
6884 dwarf2_complex_location_expr_complaint ();
6886 fnp
->voffset
/= cu
->header
.addr_size
;
6890 dwarf2_complex_location_expr_complaint ();
6893 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
6895 else if (attr_form_is_section_offset (attr
))
6897 dwarf2_complex_location_expr_complaint ();
6901 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6907 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6908 if (attr
&& DW_UNSND (attr
))
6910 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6911 complaint (&symfile_complaints
,
6912 _("Member function \"%s\" (offset %d) is virtual "
6913 "but the vtable offset is not specified"),
6914 fieldname
, die
->offset
);
6915 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6916 TYPE_CPLUS_DYNAMIC (type
) = 1;
6921 /* Create the vector of member function fields, and attach it to the type. */
6924 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6925 struct dwarf2_cu
*cu
)
6927 struct fnfieldlist
*flp
;
6928 int total_length
= 0;
6931 if (cu
->language
== language_ada
)
6932 error (_("unexpected member functions in Ada type"));
6934 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6935 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6936 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6938 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6940 struct nextfnfield
*nfp
= flp
->head
;
6941 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6944 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6945 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6946 fn_flp
->fn_fields
= (struct fn_field
*)
6947 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6948 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6949 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6951 total_length
+= flp
->length
;
6954 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6955 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6958 /* Returns non-zero if NAME is the name of a vtable member in CU's
6959 language, zero otherwise. */
6961 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6963 static const char vptr
[] = "_vptr";
6964 static const char vtable
[] = "vtable";
6966 /* Look for the C++ and Java forms of the vtable. */
6967 if ((cu
->language
== language_java
6968 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6969 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6970 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6976 /* GCC outputs unnamed structures that are really pointers to member
6977 functions, with the ABI-specified layout. If TYPE describes
6978 such a structure, smash it into a member function type.
6980 GCC shouldn't do this; it should just output pointer to member DIEs.
6981 This is GCC PR debug/28767. */
6984 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6986 struct type
*pfn_type
, *domain_type
, *new_type
;
6988 /* Check for a structure with no name and two children. */
6989 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6992 /* Check for __pfn and __delta members. */
6993 if (TYPE_FIELD_NAME (type
, 0) == NULL
6994 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6995 || TYPE_FIELD_NAME (type
, 1) == NULL
6996 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6999 /* Find the type of the method. */
7000 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7001 if (pfn_type
== NULL
7002 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7003 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7006 /* Look for the "this" argument. */
7007 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7008 if (TYPE_NFIELDS (pfn_type
) == 0
7009 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7010 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7013 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7014 new_type
= alloc_type (objfile
);
7015 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7016 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7017 TYPE_VARARGS (pfn_type
));
7018 smash_to_methodptr_type (type
, new_type
);
7021 /* Called when we find the DIE that starts a structure or union scope
7022 (definition) to create a type for the structure or union. Fill in
7023 the type's name and general properties; the members will not be
7024 processed until process_structure_type.
7026 NOTE: we need to call these functions regardless of whether or not the
7027 DIE has a DW_AT_name attribute, since it might be an anonymous
7028 structure or union. This gets the type entered into our set of
7031 However, if the structure is incomplete (an opaque struct/union)
7032 then suppress creating a symbol table entry for it since gdb only
7033 wants to find the one with the complete definition. Note that if
7034 it is complete, we just call new_symbol, which does it's own
7035 checking about whether the struct/union is anonymous or not (and
7036 suppresses creating a symbol table entry itself). */
7038 static struct type
*
7039 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7041 struct objfile
*objfile
= cu
->objfile
;
7043 struct attribute
*attr
;
7046 /* If the definition of this type lives in .debug_types, read that type.
7047 Don't follow DW_AT_specification though, that will take us back up
7048 the chain and we want to go down. */
7049 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7052 struct dwarf2_cu
*type_cu
= cu
;
7053 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7055 /* We could just recurse on read_structure_type, but we need to call
7056 get_die_type to ensure only one type for this DIE is created.
7057 This is important, for example, because for c++ classes we need
7058 TYPE_NAME set which is only done by new_symbol. Blech. */
7059 type
= read_type_die (type_die
, type_cu
);
7061 /* TYPE_CU may not be the same as CU.
7062 Ensure TYPE is recorded in CU's type_hash table. */
7063 return set_die_type (die
, type
, cu
);
7066 type
= alloc_type (objfile
);
7067 INIT_CPLUS_SPECIFIC (type
);
7069 name
= dwarf2_name (die
, cu
);
7072 if (cu
->language
== language_cplus
7073 || cu
->language
== language_java
)
7075 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7077 /* dwarf2_full_name might have already finished building the DIE's
7078 type. If so, there is no need to continue. */
7079 if (get_die_type (die
, cu
) != NULL
)
7080 return get_die_type (die
, cu
);
7082 TYPE_TAG_NAME (type
) = full_name
;
7083 if (die
->tag
== DW_TAG_structure_type
7084 || die
->tag
== DW_TAG_class_type
)
7085 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7089 /* The name is already allocated along with this objfile, so
7090 we don't need to duplicate it for the type. */
7091 TYPE_TAG_NAME (type
) = (char *) name
;
7092 if (die
->tag
== DW_TAG_class_type
)
7093 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7097 if (die
->tag
== DW_TAG_structure_type
)
7099 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7101 else if (die
->tag
== DW_TAG_union_type
)
7103 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7107 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7110 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7111 TYPE_DECLARED_CLASS (type
) = 1;
7113 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7116 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7120 TYPE_LENGTH (type
) = 0;
7123 TYPE_STUB_SUPPORTED (type
) = 1;
7124 if (die_is_declaration (die
, cu
))
7125 TYPE_STUB (type
) = 1;
7126 else if (attr
== NULL
&& die
->child
== NULL
7127 && producer_is_realview (cu
->producer
))
7128 /* RealView does not output the required DW_AT_declaration
7129 on incomplete types. */
7130 TYPE_STUB (type
) = 1;
7132 /* We need to add the type field to the die immediately so we don't
7133 infinitely recurse when dealing with pointers to the structure
7134 type within the structure itself. */
7135 set_die_type (die
, type
, cu
);
7137 /* set_die_type should be already done. */
7138 set_descriptive_type (type
, die
, cu
);
7143 /* Finish creating a structure or union type, including filling in
7144 its members and creating a symbol for it. */
7147 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7149 struct objfile
*objfile
= cu
->objfile
;
7150 struct die_info
*child_die
= die
->child
;
7153 type
= get_die_type (die
, cu
);
7155 type
= read_structure_type (die
, cu
);
7157 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7159 struct field_info fi
;
7160 struct die_info
*child_die
;
7161 VEC (symbolp
) *template_args
= NULL
;
7162 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7164 memset (&fi
, 0, sizeof (struct field_info
));
7166 child_die
= die
->child
;
7168 while (child_die
&& child_die
->tag
)
7170 if (child_die
->tag
== DW_TAG_member
7171 || child_die
->tag
== DW_TAG_variable
)
7173 /* NOTE: carlton/2002-11-05: A C++ static data member
7174 should be a DW_TAG_member that is a declaration, but
7175 all versions of G++ as of this writing (so through at
7176 least 3.2.1) incorrectly generate DW_TAG_variable
7177 tags for them instead. */
7178 dwarf2_add_field (&fi
, child_die
, cu
);
7180 else if (child_die
->tag
== DW_TAG_subprogram
)
7182 /* C++ member function. */
7183 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7185 else if (child_die
->tag
== DW_TAG_inheritance
)
7187 /* C++ base class field. */
7188 dwarf2_add_field (&fi
, child_die
, cu
);
7190 else if (child_die
->tag
== DW_TAG_typedef
)
7191 dwarf2_add_typedef (&fi
, child_die
, cu
);
7192 else if (child_die
->tag
== DW_TAG_template_type_param
7193 || child_die
->tag
== DW_TAG_template_value_param
)
7195 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7198 VEC_safe_push (symbolp
, template_args
, arg
);
7201 child_die
= sibling_die (child_die
);
7204 /* Attach template arguments to type. */
7205 if (! VEC_empty (symbolp
, template_args
))
7207 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7208 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7209 = VEC_length (symbolp
, template_args
);
7210 TYPE_TEMPLATE_ARGUMENTS (type
)
7211 = obstack_alloc (&objfile
->objfile_obstack
,
7212 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7213 * sizeof (struct symbol
*)));
7214 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7215 VEC_address (symbolp
, template_args
),
7216 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7217 * sizeof (struct symbol
*)));
7218 VEC_free (symbolp
, template_args
);
7221 /* Attach fields and member functions to the type. */
7223 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7226 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7228 /* Get the type which refers to the base class (possibly this
7229 class itself) which contains the vtable pointer for the current
7230 class from the DW_AT_containing_type attribute. This use of
7231 DW_AT_containing_type is a GNU extension. */
7233 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7235 struct type
*t
= die_containing_type (die
, cu
);
7237 TYPE_VPTR_BASETYPE (type
) = t
;
7242 /* Our own class provides vtbl ptr. */
7243 for (i
= TYPE_NFIELDS (t
) - 1;
7244 i
>= TYPE_N_BASECLASSES (t
);
7247 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7249 if (is_vtable_name (fieldname
, cu
))
7251 TYPE_VPTR_FIELDNO (type
) = i
;
7256 /* Complain if virtual function table field not found. */
7257 if (i
< TYPE_N_BASECLASSES (t
))
7258 complaint (&symfile_complaints
,
7259 _("virtual function table pointer "
7260 "not found when defining class '%s'"),
7261 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7266 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7269 else if (cu
->producer
7270 && strncmp (cu
->producer
,
7271 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7273 /* The IBM XLC compiler does not provide direct indication
7274 of the containing type, but the vtable pointer is
7275 always named __vfp. */
7279 for (i
= TYPE_NFIELDS (type
) - 1;
7280 i
>= TYPE_N_BASECLASSES (type
);
7283 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7285 TYPE_VPTR_FIELDNO (type
) = i
;
7286 TYPE_VPTR_BASETYPE (type
) = type
;
7293 /* Copy fi.typedef_field_list linked list elements content into the
7294 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7295 if (fi
.typedef_field_list
)
7297 int i
= fi
.typedef_field_list_count
;
7299 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7300 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7301 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7302 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7304 /* Reverse the list order to keep the debug info elements order. */
7307 struct typedef_field
*dest
, *src
;
7309 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7310 src
= &fi
.typedef_field_list
->field
;
7311 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7316 do_cleanups (back_to
);
7319 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
7321 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7322 snapshots) has been known to create a die giving a declaration
7323 for a class that has, as a child, a die giving a definition for a
7324 nested class. So we have to process our children even if the
7325 current die is a declaration. Normally, of course, a declaration
7326 won't have any children at all. */
7328 while (child_die
!= NULL
&& child_die
->tag
)
7330 if (child_die
->tag
== DW_TAG_member
7331 || child_die
->tag
== DW_TAG_variable
7332 || child_die
->tag
== DW_TAG_inheritance
7333 || child_die
->tag
== DW_TAG_template_value_param
7334 || child_die
->tag
== DW_TAG_template_type_param
)
7339 process_die (child_die
, cu
);
7341 child_die
= sibling_die (child_die
);
7344 /* Do not consider external references. According to the DWARF standard,
7345 these DIEs are identified by the fact that they have no byte_size
7346 attribute, and a declaration attribute. */
7347 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7348 || !die_is_declaration (die
, cu
))
7349 new_symbol (die
, type
, cu
);
7352 /* Given a DW_AT_enumeration_type die, set its type. We do not
7353 complete the type's fields yet, or create any symbols. */
7355 static struct type
*
7356 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7358 struct objfile
*objfile
= cu
->objfile
;
7360 struct attribute
*attr
;
7363 /* If the definition of this type lives in .debug_types, read that type.
7364 Don't follow DW_AT_specification though, that will take us back up
7365 the chain and we want to go down. */
7366 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7369 struct dwarf2_cu
*type_cu
= cu
;
7370 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7372 type
= read_type_die (type_die
, type_cu
);
7374 /* TYPE_CU may not be the same as CU.
7375 Ensure TYPE is recorded in CU's type_hash table. */
7376 return set_die_type (die
, type
, cu
);
7379 type
= alloc_type (objfile
);
7381 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7382 name
= dwarf2_full_name (NULL
, die
, cu
);
7384 TYPE_TAG_NAME (type
) = (char *) name
;
7386 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7389 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7393 TYPE_LENGTH (type
) = 0;
7396 /* The enumeration DIE can be incomplete. In Ada, any type can be
7397 declared as private in the package spec, and then defined only
7398 inside the package body. Such types are known as Taft Amendment
7399 Types. When another package uses such a type, an incomplete DIE
7400 may be generated by the compiler. */
7401 if (die_is_declaration (die
, cu
))
7402 TYPE_STUB (type
) = 1;
7404 return set_die_type (die
, type
, cu
);
7407 /* Given a pointer to a die which begins an enumeration, process all
7408 the dies that define the members of the enumeration, and create the
7409 symbol for the enumeration type.
7411 NOTE: We reverse the order of the element list. */
7414 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7416 struct type
*this_type
;
7418 this_type
= get_die_type (die
, cu
);
7419 if (this_type
== NULL
)
7420 this_type
= read_enumeration_type (die
, cu
);
7422 if (die
->child
!= NULL
)
7424 struct die_info
*child_die
;
7426 struct field
*fields
= NULL
;
7428 int unsigned_enum
= 1;
7431 child_die
= die
->child
;
7432 while (child_die
&& child_die
->tag
)
7434 if (child_die
->tag
!= DW_TAG_enumerator
)
7436 process_die (child_die
, cu
);
7440 name
= dwarf2_name (child_die
, cu
);
7443 sym
= new_symbol (child_die
, this_type
, cu
);
7444 if (SYMBOL_VALUE (sym
) < 0)
7447 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7449 fields
= (struct field
*)
7451 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7452 * sizeof (struct field
));
7455 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7456 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7457 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7458 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7464 child_die
= sibling_die (child_die
);
7469 TYPE_NFIELDS (this_type
) = num_fields
;
7470 TYPE_FIELDS (this_type
) = (struct field
*)
7471 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7472 memcpy (TYPE_FIELDS (this_type
), fields
,
7473 sizeof (struct field
) * num_fields
);
7477 TYPE_UNSIGNED (this_type
) = 1;
7480 new_symbol (die
, this_type
, cu
);
7483 /* Extract all information from a DW_TAG_array_type DIE and put it in
7484 the DIE's type field. For now, this only handles one dimensional
7487 static struct type
*
7488 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7490 struct objfile
*objfile
= cu
->objfile
;
7491 struct die_info
*child_die
;
7493 struct type
*element_type
, *range_type
, *index_type
;
7494 struct type
**range_types
= NULL
;
7495 struct attribute
*attr
;
7497 struct cleanup
*back_to
;
7500 element_type
= die_type (die
, cu
);
7502 /* The die_type call above may have already set the type for this DIE. */
7503 type
= get_die_type (die
, cu
);
7507 /* Irix 6.2 native cc creates array types without children for
7508 arrays with unspecified length. */
7509 if (die
->child
== NULL
)
7511 index_type
= objfile_type (objfile
)->builtin_int
;
7512 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7513 type
= create_array_type (NULL
, element_type
, range_type
);
7514 return set_die_type (die
, type
, cu
);
7517 back_to
= make_cleanup (null_cleanup
, NULL
);
7518 child_die
= die
->child
;
7519 while (child_die
&& child_die
->tag
)
7521 if (child_die
->tag
== DW_TAG_subrange_type
)
7523 struct type
*child_type
= read_type_die (child_die
, cu
);
7525 if (child_type
!= NULL
)
7527 /* The range type was succesfully read. Save it for the
7528 array type creation. */
7529 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7531 range_types
= (struct type
**)
7532 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7533 * sizeof (struct type
*));
7535 make_cleanup (free_current_contents
, &range_types
);
7537 range_types
[ndim
++] = child_type
;
7540 child_die
= sibling_die (child_die
);
7543 /* Dwarf2 dimensions are output from left to right, create the
7544 necessary array types in backwards order. */
7546 type
= element_type
;
7548 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7553 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7558 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7561 /* Understand Dwarf2 support for vector types (like they occur on
7562 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7563 array type. This is not part of the Dwarf2/3 standard yet, but a
7564 custom vendor extension. The main difference between a regular
7565 array and the vector variant is that vectors are passed by value
7567 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7569 make_vector_type (type
);
7571 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7572 implementation may choose to implement triple vectors using this
7574 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7577 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
7578 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7580 complaint (&symfile_complaints
,
7581 _("DW_AT_byte_size for array type smaller "
7582 "than the total size of elements"));
7585 name
= dwarf2_name (die
, cu
);
7587 TYPE_NAME (type
) = name
;
7589 /* Install the type in the die. */
7590 set_die_type (die
, type
, cu
);
7592 /* set_die_type should be already done. */
7593 set_descriptive_type (type
, die
, cu
);
7595 do_cleanups (back_to
);
7600 static enum dwarf_array_dim_ordering
7601 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7603 struct attribute
*attr
;
7605 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7607 if (attr
) return DW_SND (attr
);
7609 /* GNU F77 is a special case, as at 08/2004 array type info is the
7610 opposite order to the dwarf2 specification, but data is still
7611 laid out as per normal fortran.
7613 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7614 version checking. */
7616 if (cu
->language
== language_fortran
7617 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7619 return DW_ORD_row_major
;
7622 switch (cu
->language_defn
->la_array_ordering
)
7624 case array_column_major
:
7625 return DW_ORD_col_major
;
7626 case array_row_major
:
7628 return DW_ORD_row_major
;
7632 /* Extract all information from a DW_TAG_set_type DIE and put it in
7633 the DIE's type field. */
7635 static struct type
*
7636 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7638 struct type
*domain_type
, *set_type
;
7639 struct attribute
*attr
;
7641 domain_type
= die_type (die
, cu
);
7643 /* The die_type call above may have already set the type for this DIE. */
7644 set_type
= get_die_type (die
, cu
);
7648 set_type
= create_set_type (NULL
, domain_type
);
7650 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7652 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7654 return set_die_type (die
, set_type
, cu
);
7657 /* First cut: install each common block member as a global variable. */
7660 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7662 struct die_info
*child_die
;
7663 struct attribute
*attr
;
7665 CORE_ADDR base
= (CORE_ADDR
) 0;
7667 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7670 /* Support the .debug_loc offsets. */
7671 if (attr_form_is_block (attr
))
7673 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7675 else if (attr_form_is_section_offset (attr
))
7677 dwarf2_complex_location_expr_complaint ();
7681 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7682 "common block member");
7685 if (die
->child
!= NULL
)
7687 child_die
= die
->child
;
7688 while (child_die
&& child_die
->tag
)
7692 sym
= new_symbol (child_die
, NULL
, cu
);
7694 && handle_data_member_location (child_die
, cu
, &offset
))
7696 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
7697 add_symbol_to_list (sym
, &global_symbols
);
7699 child_die
= sibling_die (child_die
);
7704 /* Create a type for a C++ namespace. */
7706 static struct type
*
7707 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7709 struct objfile
*objfile
= cu
->objfile
;
7710 const char *previous_prefix
, *name
;
7714 /* For extensions, reuse the type of the original namespace. */
7715 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7717 struct die_info
*ext_die
;
7718 struct dwarf2_cu
*ext_cu
= cu
;
7720 ext_die
= dwarf2_extension (die
, &ext_cu
);
7721 type
= read_type_die (ext_die
, ext_cu
);
7723 /* EXT_CU may not be the same as CU.
7724 Ensure TYPE is recorded in CU's type_hash table. */
7725 return set_die_type (die
, type
, cu
);
7728 name
= namespace_name (die
, &is_anonymous
, cu
);
7730 /* Now build the name of the current namespace. */
7732 previous_prefix
= determine_prefix (die
, cu
);
7733 if (previous_prefix
[0] != '\0')
7734 name
= typename_concat (&objfile
->objfile_obstack
,
7735 previous_prefix
, name
, 0, cu
);
7737 /* Create the type. */
7738 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7740 TYPE_NAME (type
) = (char *) name
;
7741 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7743 return set_die_type (die
, type
, cu
);
7746 /* Read a C++ namespace. */
7749 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7751 struct objfile
*objfile
= cu
->objfile
;
7754 /* Add a symbol associated to this if we haven't seen the namespace
7755 before. Also, add a using directive if it's an anonymous
7758 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7762 type
= read_type_die (die
, cu
);
7763 new_symbol (die
, type
, cu
);
7765 namespace_name (die
, &is_anonymous
, cu
);
7768 const char *previous_prefix
= determine_prefix (die
, cu
);
7770 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7771 NULL
, &objfile
->objfile_obstack
);
7775 if (die
->child
!= NULL
)
7777 struct die_info
*child_die
= die
->child
;
7779 while (child_die
&& child_die
->tag
)
7781 process_die (child_die
, cu
);
7782 child_die
= sibling_die (child_die
);
7787 /* Read a Fortran module as type. This DIE can be only a declaration used for
7788 imported module. Still we need that type as local Fortran "use ... only"
7789 declaration imports depend on the created type in determine_prefix. */
7791 static struct type
*
7792 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7794 struct objfile
*objfile
= cu
->objfile
;
7798 module_name
= dwarf2_name (die
, cu
);
7800 complaint (&symfile_complaints
,
7801 _("DW_TAG_module has no name, offset 0x%x"),
7803 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7805 /* determine_prefix uses TYPE_TAG_NAME. */
7806 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7808 return set_die_type (die
, type
, cu
);
7811 /* Read a Fortran module. */
7814 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7816 struct die_info
*child_die
= die
->child
;
7818 while (child_die
&& child_die
->tag
)
7820 process_die (child_die
, cu
);
7821 child_die
= sibling_die (child_die
);
7825 /* Return the name of the namespace represented by DIE. Set
7826 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7830 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
7832 struct die_info
*current_die
;
7833 const char *name
= NULL
;
7835 /* Loop through the extensions until we find a name. */
7837 for (current_die
= die
;
7838 current_die
!= NULL
;
7839 current_die
= dwarf2_extension (die
, &cu
))
7841 name
= dwarf2_name (current_die
, cu
);
7846 /* Is it an anonymous namespace? */
7848 *is_anonymous
= (name
== NULL
);
7850 name
= "(anonymous namespace)";
7855 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7856 the user defined type vector. */
7858 static struct type
*
7859 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7861 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7862 struct comp_unit_head
*cu_header
= &cu
->header
;
7864 struct attribute
*attr_byte_size
;
7865 struct attribute
*attr_address_class
;
7866 int byte_size
, addr_class
;
7867 struct type
*target_type
;
7869 target_type
= die_type (die
, cu
);
7871 /* The die_type call above may have already set the type for this DIE. */
7872 type
= get_die_type (die
, cu
);
7876 type
= lookup_pointer_type (target_type
);
7878 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7880 byte_size
= DW_UNSND (attr_byte_size
);
7882 byte_size
= cu_header
->addr_size
;
7884 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
7885 if (attr_address_class
)
7886 addr_class
= DW_UNSND (attr_address_class
);
7888 addr_class
= DW_ADDR_none
;
7890 /* If the pointer size or address class is different than the
7891 default, create a type variant marked as such and set the
7892 length accordingly. */
7893 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
7895 if (gdbarch_address_class_type_flags_p (gdbarch
))
7899 type_flags
= gdbarch_address_class_type_flags
7900 (gdbarch
, byte_size
, addr_class
);
7901 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
7903 type
= make_type_with_address_space (type
, type_flags
);
7905 else if (TYPE_LENGTH (type
) != byte_size
)
7907 complaint (&symfile_complaints
,
7908 _("invalid pointer size %d"), byte_size
);
7912 /* Should we also complain about unhandled address classes? */
7916 TYPE_LENGTH (type
) = byte_size
;
7917 return set_die_type (die
, type
, cu
);
7920 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7921 the user defined type vector. */
7923 static struct type
*
7924 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7927 struct type
*to_type
;
7928 struct type
*domain
;
7930 to_type
= die_type (die
, cu
);
7931 domain
= die_containing_type (die
, cu
);
7933 /* The calls above may have already set the type for this DIE. */
7934 type
= get_die_type (die
, cu
);
7938 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
7939 type
= lookup_methodptr_type (to_type
);
7941 type
= lookup_memberptr_type (to_type
, domain
);
7943 return set_die_type (die
, type
, cu
);
7946 /* Extract all information from a DW_TAG_reference_type DIE and add to
7947 the user defined type vector. */
7949 static struct type
*
7950 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7952 struct comp_unit_head
*cu_header
= &cu
->header
;
7953 struct type
*type
, *target_type
;
7954 struct attribute
*attr
;
7956 target_type
= die_type (die
, cu
);
7958 /* The die_type call above may have already set the type for this DIE. */
7959 type
= get_die_type (die
, cu
);
7963 type
= lookup_reference_type (target_type
);
7964 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7967 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7971 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7973 return set_die_type (die
, type
, cu
);
7976 static struct type
*
7977 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7979 struct type
*base_type
, *cv_type
;
7981 base_type
= die_type (die
, cu
);
7983 /* The die_type call above may have already set the type for this DIE. */
7984 cv_type
= get_die_type (die
, cu
);
7988 /* In case the const qualifier is applied to an array type, the element type
7989 is so qualified, not the array type (section 6.7.3 of C99). */
7990 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
7992 struct type
*el_type
, *inner_array
;
7994 base_type
= copy_type (base_type
);
7995 inner_array
= base_type
;
7997 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
7999 TYPE_TARGET_TYPE (inner_array
) =
8000 copy_type (TYPE_TARGET_TYPE (inner_array
));
8001 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8004 el_type
= TYPE_TARGET_TYPE (inner_array
);
8005 TYPE_TARGET_TYPE (inner_array
) =
8006 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8008 return set_die_type (die
, base_type
, cu
);
8011 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8012 return set_die_type (die
, cv_type
, cu
);
8015 static struct type
*
8016 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8018 struct type
*base_type
, *cv_type
;
8020 base_type
= die_type (die
, cu
);
8022 /* The die_type call above may have already set the type for this DIE. */
8023 cv_type
= get_die_type (die
, cu
);
8027 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8028 return set_die_type (die
, cv_type
, cu
);
8031 /* Extract all information from a DW_TAG_string_type DIE and add to
8032 the user defined type vector. It isn't really a user defined type,
8033 but it behaves like one, with other DIE's using an AT_user_def_type
8034 attribute to reference it. */
8036 static struct type
*
8037 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8039 struct objfile
*objfile
= cu
->objfile
;
8040 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8041 struct type
*type
, *range_type
, *index_type
, *char_type
;
8042 struct attribute
*attr
;
8043 unsigned int length
;
8045 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8048 length
= DW_UNSND (attr
);
8052 /* Check for the DW_AT_byte_size attribute. */
8053 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8056 length
= DW_UNSND (attr
);
8064 index_type
= objfile_type (objfile
)->builtin_int
;
8065 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8066 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8067 type
= create_string_type (NULL
, char_type
, range_type
);
8069 return set_die_type (die
, type
, cu
);
8072 /* Handle DIES due to C code like:
8076 int (*funcp)(int a, long l);
8080 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8082 static struct type
*
8083 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8085 struct type
*type
; /* Type that this function returns. */
8086 struct type
*ftype
; /* Function that returns above type. */
8087 struct attribute
*attr
;
8089 type
= die_type (die
, cu
);
8091 /* The die_type call above may have already set the type for this DIE. */
8092 ftype
= get_die_type (die
, cu
);
8096 ftype
= lookup_function_type (type
);
8098 /* All functions in C++, Pascal and Java have prototypes. */
8099 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8100 if ((attr
&& (DW_UNSND (attr
) != 0))
8101 || cu
->language
== language_cplus
8102 || cu
->language
== language_java
8103 || cu
->language
== language_pascal
)
8104 TYPE_PROTOTYPED (ftype
) = 1;
8105 else if (producer_is_realview (cu
->producer
))
8106 /* RealView does not emit DW_AT_prototyped. We can not
8107 distinguish prototyped and unprototyped functions; default to
8108 prototyped, since that is more common in modern code (and
8109 RealView warns about unprototyped functions). */
8110 TYPE_PROTOTYPED (ftype
) = 1;
8112 /* Store the calling convention in the type if it's available in
8113 the subroutine die. Otherwise set the calling convention to
8114 the default value DW_CC_normal. */
8115 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8117 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8118 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8119 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8121 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8123 /* We need to add the subroutine type to the die immediately so
8124 we don't infinitely recurse when dealing with parameters
8125 declared as the same subroutine type. */
8126 set_die_type (die
, ftype
, cu
);
8128 if (die
->child
!= NULL
)
8130 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
8131 struct die_info
*child_die
;
8132 int nparams
, iparams
;
8134 /* Count the number of parameters.
8135 FIXME: GDB currently ignores vararg functions, but knows about
8136 vararg member functions. */
8138 child_die
= die
->child
;
8139 while (child_die
&& child_die
->tag
)
8141 if (child_die
->tag
== DW_TAG_formal_parameter
)
8143 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8144 TYPE_VARARGS (ftype
) = 1;
8145 child_die
= sibling_die (child_die
);
8148 /* Allocate storage for parameters and fill them in. */
8149 TYPE_NFIELDS (ftype
) = nparams
;
8150 TYPE_FIELDS (ftype
) = (struct field
*)
8151 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8153 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8154 even if we error out during the parameters reading below. */
8155 for (iparams
= 0; iparams
< nparams
; iparams
++)
8156 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8159 child_die
= die
->child
;
8160 while (child_die
&& child_die
->tag
)
8162 if (child_die
->tag
== DW_TAG_formal_parameter
)
8164 struct type
*arg_type
;
8166 /* DWARF version 2 has no clean way to discern C++
8167 static and non-static member functions. G++ helps
8168 GDB by marking the first parameter for non-static
8169 member functions (which is the this pointer) as
8170 artificial. We pass this information to
8171 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8173 DWARF version 3 added DW_AT_object_pointer, which GCC
8174 4.5 does not yet generate. */
8175 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8177 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8180 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8182 /* GCC/43521: In java, the formal parameter
8183 "this" is sometimes not marked with DW_AT_artificial. */
8184 if (cu
->language
== language_java
)
8186 const char *name
= dwarf2_name (child_die
, cu
);
8188 if (name
&& !strcmp (name
, "this"))
8189 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8192 arg_type
= die_type (child_die
, cu
);
8194 /* RealView does not mark THIS as const, which the testsuite
8195 expects. GCC marks THIS as const in method definitions,
8196 but not in the class specifications (GCC PR 43053). */
8197 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8198 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8201 struct dwarf2_cu
*arg_cu
= cu
;
8202 const char *name
= dwarf2_name (child_die
, cu
);
8204 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8207 /* If the compiler emits this, use it. */
8208 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8211 else if (name
&& strcmp (name
, "this") == 0)
8212 /* Function definitions will have the argument names. */
8214 else if (name
== NULL
&& iparams
== 0)
8215 /* Declarations may not have the names, so like
8216 elsewhere in GDB, assume an artificial first
8217 argument is "this". */
8221 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8225 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8228 child_die
= sibling_die (child_die
);
8235 static struct type
*
8236 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8238 struct objfile
*objfile
= cu
->objfile
;
8239 const char *name
= NULL
;
8240 struct type
*this_type
;
8242 name
= dwarf2_full_name (NULL
, die
, cu
);
8243 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8244 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8245 TYPE_NAME (this_type
) = (char *) name
;
8246 set_die_type (die
, this_type
, cu
);
8247 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
8251 /* Find a representation of a given base type and install
8252 it in the TYPE field of the die. */
8254 static struct type
*
8255 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8257 struct objfile
*objfile
= cu
->objfile
;
8259 struct attribute
*attr
;
8260 int encoding
= 0, size
= 0;
8262 enum type_code code
= TYPE_CODE_INT
;
8264 struct type
*target_type
= NULL
;
8266 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8269 encoding
= DW_UNSND (attr
);
8271 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8274 size
= DW_UNSND (attr
);
8276 name
= dwarf2_name (die
, cu
);
8279 complaint (&symfile_complaints
,
8280 _("DW_AT_name missing from DW_TAG_base_type"));
8285 case DW_ATE_address
:
8286 /* Turn DW_ATE_address into a void * pointer. */
8287 code
= TYPE_CODE_PTR
;
8288 type_flags
|= TYPE_FLAG_UNSIGNED
;
8289 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8291 case DW_ATE_boolean
:
8292 code
= TYPE_CODE_BOOL
;
8293 type_flags
|= TYPE_FLAG_UNSIGNED
;
8295 case DW_ATE_complex_float
:
8296 code
= TYPE_CODE_COMPLEX
;
8297 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8299 case DW_ATE_decimal_float
:
8300 code
= TYPE_CODE_DECFLOAT
;
8303 code
= TYPE_CODE_FLT
;
8307 case DW_ATE_unsigned
:
8308 type_flags
|= TYPE_FLAG_UNSIGNED
;
8310 case DW_ATE_signed_char
:
8311 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8312 || cu
->language
== language_pascal
)
8313 code
= TYPE_CODE_CHAR
;
8315 case DW_ATE_unsigned_char
:
8316 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8317 || cu
->language
== language_pascal
)
8318 code
= TYPE_CODE_CHAR
;
8319 type_flags
|= TYPE_FLAG_UNSIGNED
;
8322 /* We just treat this as an integer and then recognize the
8323 type by name elsewhere. */
8327 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8328 dwarf_type_encoding_name (encoding
));
8332 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8333 TYPE_NAME (type
) = name
;
8334 TYPE_TARGET_TYPE (type
) = target_type
;
8336 if (name
&& strcmp (name
, "char") == 0)
8337 TYPE_NOSIGN (type
) = 1;
8339 return set_die_type (die
, type
, cu
);
8342 /* Read the given DW_AT_subrange DIE. */
8344 static struct type
*
8345 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8347 struct type
*base_type
;
8348 struct type
*range_type
;
8349 struct attribute
*attr
;
8353 LONGEST negative_mask
;
8355 base_type
= die_type (die
, cu
);
8356 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8357 check_typedef (base_type
);
8359 /* The die_type call above may have already set the type for this DIE. */
8360 range_type
= get_die_type (die
, cu
);
8364 if (cu
->language
== language_fortran
)
8366 /* FORTRAN implies a lower bound of 1, if not given. */
8370 /* FIXME: For variable sized arrays either of these could be
8371 a variable rather than a constant value. We'll allow it,
8372 but we don't know how to handle it. */
8373 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8375 low
= dwarf2_get_attr_constant_value (attr
, 0);
8377 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8380 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
8382 /* GCC encodes arrays with unspecified or dynamic length
8383 with a DW_FORM_block1 attribute or a reference attribute.
8384 FIXME: GDB does not yet know how to handle dynamic
8385 arrays properly, treat them as arrays with unspecified
8388 FIXME: jimb/2003-09-22: GDB does not really know
8389 how to handle arrays of unspecified length
8390 either; we just represent them as zero-length
8391 arrays. Choose an appropriate upper bound given
8392 the lower bound we've computed above. */
8396 high
= dwarf2_get_attr_constant_value (attr
, 1);
8400 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8403 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8404 high
= low
+ count
- 1;
8408 /* Unspecified array length. */
8413 /* Dwarf-2 specifications explicitly allows to create subrange types
8414 without specifying a base type.
8415 In that case, the base type must be set to the type of
8416 the lower bound, upper bound or count, in that order, if any of these
8417 three attributes references an object that has a type.
8418 If no base type is found, the Dwarf-2 specifications say that
8419 a signed integer type of size equal to the size of an address should
8421 For the following C code: `extern char gdb_int [];'
8422 GCC produces an empty range DIE.
8423 FIXME: muller/2010-05-28: Possible references to object for low bound,
8424 high bound or count are not yet handled by this code. */
8425 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8427 struct objfile
*objfile
= cu
->objfile
;
8428 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8429 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8430 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8432 /* Test "int", "long int", and "long long int" objfile types,
8433 and select the first one having a size above or equal to the
8434 architecture address size. */
8435 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8436 base_type
= int_type
;
8439 int_type
= objfile_type (objfile
)->builtin_long
;
8440 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8441 base_type
= int_type
;
8444 int_type
= objfile_type (objfile
)->builtin_long_long
;
8445 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8446 base_type
= int_type
;
8452 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8453 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8454 low
|= negative_mask
;
8455 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8456 high
|= negative_mask
;
8458 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8460 /* Mark arrays with dynamic length at least as an array of unspecified
8461 length. GDB could check the boundary but before it gets implemented at
8462 least allow accessing the array elements. */
8463 if (attr
&& attr
->form
== DW_FORM_block1
)
8464 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8466 /* Ada expects an empty array on no boundary attributes. */
8467 if (attr
== NULL
&& cu
->language
!= language_ada
)
8468 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8470 name
= dwarf2_name (die
, cu
);
8472 TYPE_NAME (range_type
) = name
;
8474 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8476 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8478 set_die_type (die
, range_type
, cu
);
8480 /* set_die_type should be already done. */
8481 set_descriptive_type (range_type
, die
, cu
);
8486 static struct type
*
8487 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8491 /* For now, we only support the C meaning of an unspecified type: void. */
8493 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8494 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8496 return set_die_type (die
, type
, cu
);
8499 /* Trivial hash function for die_info: the hash value of a DIE
8500 is its offset in .debug_info for this objfile. */
8503 die_hash (const void *item
)
8505 const struct die_info
*die
= item
;
8510 /* Trivial comparison function for die_info structures: two DIEs
8511 are equal if they have the same offset. */
8514 die_eq (const void *item_lhs
, const void *item_rhs
)
8516 const struct die_info
*die_lhs
= item_lhs
;
8517 const struct die_info
*die_rhs
= item_rhs
;
8519 return die_lhs
->offset
== die_rhs
->offset
;
8522 /* Read a whole compilation unit into a linked list of dies. */
8524 static struct die_info
*
8525 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8527 struct die_reader_specs reader_specs
;
8528 int read_abbrevs
= 0;
8529 struct cleanup
*back_to
= NULL
;
8530 struct die_info
*die
;
8532 if (cu
->dwarf2_abbrevs
== NULL
)
8534 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8535 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8539 gdb_assert (cu
->die_hash
== NULL
);
8541 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8545 &cu
->comp_unit_obstack
,
8546 hashtab_obstack_allocate
,
8547 dummy_obstack_deallocate
);
8549 init_cu_die_reader (&reader_specs
, cu
);
8551 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8554 do_cleanups (back_to
);
8559 /* Main entry point for reading a DIE and all children.
8560 Read the DIE and dump it if requested. */
8562 static struct die_info
*
8563 read_die_and_children (const struct die_reader_specs
*reader
,
8565 gdb_byte
**new_info_ptr
,
8566 struct die_info
*parent
)
8568 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8569 new_info_ptr
, parent
);
8571 if (dwarf2_die_debug
)
8573 fprintf_unfiltered (gdb_stdlog
,
8574 "\nRead die from %s of %s:\n",
8575 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8577 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8579 : "unknown section",
8580 reader
->abfd
->filename
);
8581 dump_die (result
, dwarf2_die_debug
);
8587 /* Read a single die and all its descendents. Set the die's sibling
8588 field to NULL; set other fields in the die correctly, and set all
8589 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8590 location of the info_ptr after reading all of those dies. PARENT
8591 is the parent of the die in question. */
8593 static struct die_info
*
8594 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8596 gdb_byte
**new_info_ptr
,
8597 struct die_info
*parent
)
8599 struct die_info
*die
;
8603 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8606 *new_info_ptr
= cur_ptr
;
8609 store_in_ref_table (die
, reader
->cu
);
8612 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8616 *new_info_ptr
= cur_ptr
;
8619 die
->sibling
= NULL
;
8620 die
->parent
= parent
;
8624 /* Read a die, all of its descendents, and all of its siblings; set
8625 all of the fields of all of the dies correctly. Arguments are as
8626 in read_die_and_children. */
8628 static struct die_info
*
8629 read_die_and_siblings (const struct die_reader_specs
*reader
,
8631 gdb_byte
**new_info_ptr
,
8632 struct die_info
*parent
)
8634 struct die_info
*first_die
, *last_sibling
;
8638 first_die
= last_sibling
= NULL
;
8642 struct die_info
*die
8643 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8647 *new_info_ptr
= cur_ptr
;
8654 last_sibling
->sibling
= die
;
8660 /* Read the die from the .debug_info section buffer. Set DIEP to
8661 point to a newly allocated die with its information, except for its
8662 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8663 whether the die has children or not. */
8666 read_full_die (const struct die_reader_specs
*reader
,
8667 struct die_info
**diep
, gdb_byte
*info_ptr
,
8670 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8671 struct abbrev_info
*abbrev
;
8672 struct die_info
*die
;
8673 struct dwarf2_cu
*cu
= reader
->cu
;
8674 bfd
*abfd
= reader
->abfd
;
8676 offset
= info_ptr
- reader
->buffer
;
8677 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8678 info_ptr
+= bytes_read
;
8686 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8688 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8690 bfd_get_filename (abfd
));
8692 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8693 die
->offset
= offset
;
8694 die
->tag
= abbrev
->tag
;
8695 die
->abbrev
= abbrev_number
;
8697 die
->num_attrs
= abbrev
->num_attrs
;
8699 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8700 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8701 abfd
, info_ptr
, cu
);
8704 *has_children
= abbrev
->has_children
;
8708 /* In DWARF version 2, the description of the debugging information is
8709 stored in a separate .debug_abbrev section. Before we read any
8710 dies from a section we read in all abbreviations and install them
8711 in a hash table. This function also sets flags in CU describing
8712 the data found in the abbrev table. */
8715 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8717 struct comp_unit_head
*cu_header
= &cu
->header
;
8718 gdb_byte
*abbrev_ptr
;
8719 struct abbrev_info
*cur_abbrev
;
8720 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8721 unsigned int abbrev_form
, hash_number
;
8722 struct attr_abbrev
*cur_attrs
;
8723 unsigned int allocated_attrs
;
8725 /* Initialize dwarf2 abbrevs. */
8726 obstack_init (&cu
->abbrev_obstack
);
8727 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8729 * sizeof (struct abbrev_info
*)));
8730 memset (cu
->dwarf2_abbrevs
, 0,
8731 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8733 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8734 &dwarf2_per_objfile
->abbrev
);
8735 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8736 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8737 abbrev_ptr
+= bytes_read
;
8739 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8740 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8742 /* Loop until we reach an abbrev number of 0. */
8743 while (abbrev_number
)
8745 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8747 /* read in abbrev header */
8748 cur_abbrev
->number
= abbrev_number
;
8749 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8750 abbrev_ptr
+= bytes_read
;
8751 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8754 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8755 cu
->has_namespace_info
= 1;
8757 /* now read in declarations */
8758 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8759 abbrev_ptr
+= bytes_read
;
8760 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8761 abbrev_ptr
+= bytes_read
;
8764 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8766 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8768 = xrealloc (cur_attrs
, (allocated_attrs
8769 * sizeof (struct attr_abbrev
)));
8772 /* Record whether this compilation unit might have
8773 inter-compilation-unit references. If we don't know what form
8774 this attribute will have, then it might potentially be a
8775 DW_FORM_ref_addr, so we conservatively expect inter-CU
8778 if (abbrev_form
== DW_FORM_ref_addr
8779 || abbrev_form
== DW_FORM_indirect
)
8780 cu
->has_form_ref_addr
= 1;
8782 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8783 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8784 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8785 abbrev_ptr
+= bytes_read
;
8786 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8787 abbrev_ptr
+= bytes_read
;
8790 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8791 (cur_abbrev
->num_attrs
8792 * sizeof (struct attr_abbrev
)));
8793 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8794 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8796 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8797 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8798 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8800 /* Get next abbreviation.
8801 Under Irix6 the abbreviations for a compilation unit are not
8802 always properly terminated with an abbrev number of 0.
8803 Exit loop if we encounter an abbreviation which we have
8804 already read (which means we are about to read the abbreviations
8805 for the next compile unit) or if the end of the abbreviation
8806 table is reached. */
8807 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8808 >= dwarf2_per_objfile
->abbrev
.size
)
8810 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8811 abbrev_ptr
+= bytes_read
;
8812 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
8819 /* Release the memory used by the abbrev table for a compilation unit. */
8822 dwarf2_free_abbrev_table (void *ptr_to_cu
)
8824 struct dwarf2_cu
*cu
= ptr_to_cu
;
8826 obstack_free (&cu
->abbrev_obstack
, NULL
);
8827 cu
->dwarf2_abbrevs
= NULL
;
8830 /* Lookup an abbrev_info structure in the abbrev hash table. */
8832 static struct abbrev_info
*
8833 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
8835 unsigned int hash_number
;
8836 struct abbrev_info
*abbrev
;
8838 hash_number
= number
% ABBREV_HASH_SIZE
;
8839 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
8843 if (abbrev
->number
== number
)
8846 abbrev
= abbrev
->next
;
8851 /* Returns nonzero if TAG represents a type that we might generate a partial
8855 is_type_tag_for_partial (int tag
)
8860 /* Some types that would be reasonable to generate partial symbols for,
8861 that we don't at present. */
8862 case DW_TAG_array_type
:
8863 case DW_TAG_file_type
:
8864 case DW_TAG_ptr_to_member_type
:
8865 case DW_TAG_set_type
:
8866 case DW_TAG_string_type
:
8867 case DW_TAG_subroutine_type
:
8869 case DW_TAG_base_type
:
8870 case DW_TAG_class_type
:
8871 case DW_TAG_interface_type
:
8872 case DW_TAG_enumeration_type
:
8873 case DW_TAG_structure_type
:
8874 case DW_TAG_subrange_type
:
8875 case DW_TAG_typedef
:
8876 case DW_TAG_union_type
:
8883 /* Load all DIEs that are interesting for partial symbols into memory. */
8885 static struct partial_die_info
*
8886 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8887 int building_psymtab
, struct dwarf2_cu
*cu
)
8889 struct partial_die_info
*part_die
;
8890 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
8891 struct abbrev_info
*abbrev
;
8892 unsigned int bytes_read
;
8893 unsigned int load_all
= 0;
8895 int nesting_level
= 1;
8900 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
8904 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8908 &cu
->comp_unit_obstack
,
8909 hashtab_obstack_allocate
,
8910 dummy_obstack_deallocate
);
8912 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8913 sizeof (struct partial_die_info
));
8917 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
8919 /* A NULL abbrev means the end of a series of children. */
8922 if (--nesting_level
== 0)
8924 /* PART_DIE was probably the last thing allocated on the
8925 comp_unit_obstack, so we could call obstack_free
8926 here. We don't do that because the waste is small,
8927 and will be cleaned up when we're done with this
8928 compilation unit. This way, we're also more robust
8929 against other users of the comp_unit_obstack. */
8932 info_ptr
+= bytes_read
;
8933 last_die
= parent_die
;
8934 parent_die
= parent_die
->die_parent
;
8938 /* Check for template arguments. We never save these; if
8939 they're seen, we just mark the parent, and go on our way. */
8940 if (parent_die
!= NULL
8941 && cu
->language
== language_cplus
8942 && (abbrev
->tag
== DW_TAG_template_type_param
8943 || abbrev
->tag
== DW_TAG_template_value_param
))
8945 parent_die
->has_template_arguments
= 1;
8949 /* We don't need a partial DIE for the template argument. */
8950 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
8956 /* We only recurse into subprograms looking for template arguments.
8957 Skip their other children. */
8959 && cu
->language
== language_cplus
8960 && parent_die
!= NULL
8961 && parent_die
->tag
== DW_TAG_subprogram
)
8963 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8967 /* Check whether this DIE is interesting enough to save. Normally
8968 we would not be interested in members here, but there may be
8969 later variables referencing them via DW_AT_specification (for
8972 && !is_type_tag_for_partial (abbrev
->tag
)
8973 && abbrev
->tag
!= DW_TAG_constant
8974 && abbrev
->tag
!= DW_TAG_enumerator
8975 && abbrev
->tag
!= DW_TAG_subprogram
8976 && abbrev
->tag
!= DW_TAG_lexical_block
8977 && abbrev
->tag
!= DW_TAG_variable
8978 && abbrev
->tag
!= DW_TAG_namespace
8979 && abbrev
->tag
!= DW_TAG_module
8980 && abbrev
->tag
!= DW_TAG_member
)
8982 /* Otherwise we skip to the next sibling, if any. */
8983 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8987 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
8988 buffer
, info_ptr
, cu
);
8990 /* This two-pass algorithm for processing partial symbols has a
8991 high cost in cache pressure. Thus, handle some simple cases
8992 here which cover the majority of C partial symbols. DIEs
8993 which neither have specification tags in them, nor could have
8994 specification tags elsewhere pointing at them, can simply be
8995 processed and discarded.
8997 This segment is also optional; scan_partial_symbols and
8998 add_partial_symbol will handle these DIEs if we chain
8999 them in normally. When compilers which do not emit large
9000 quantities of duplicate debug information are more common,
9001 this code can probably be removed. */
9003 /* Any complete simple types at the top level (pretty much all
9004 of them, for a language without namespaces), can be processed
9006 if (parent_die
== NULL
9007 && part_die
->has_specification
== 0
9008 && part_die
->is_declaration
== 0
9009 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9010 || part_die
->tag
== DW_TAG_base_type
9011 || part_die
->tag
== DW_TAG_subrange_type
))
9013 if (building_psymtab
&& part_die
->name
!= NULL
)
9014 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9015 VAR_DOMAIN
, LOC_TYPEDEF
,
9016 &cu
->objfile
->static_psymbols
,
9017 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9018 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9022 /* The exception for DW_TAG_typedef with has_children above is
9023 a workaround of GCC PR debug/47510. In the case of this complaint
9024 type_name_no_tag_or_error will error on such types later.
9026 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9027 it could not find the child DIEs referenced later, this is checked
9028 above. In correct DWARF DW_TAG_typedef should have no children. */
9030 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9031 complaint (&symfile_complaints
,
9032 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9033 "- DIE at 0x%x [in module %s]"),
9034 part_die
->offset
, cu
->objfile
->name
);
9036 /* If we're at the second level, and we're an enumerator, and
9037 our parent has no specification (meaning possibly lives in a
9038 namespace elsewhere), then we can add the partial symbol now
9039 instead of queueing it. */
9040 if (part_die
->tag
== DW_TAG_enumerator
9041 && parent_die
!= NULL
9042 && parent_die
->die_parent
== NULL
9043 && parent_die
->tag
== DW_TAG_enumeration_type
9044 && parent_die
->has_specification
== 0)
9046 if (part_die
->name
== NULL
)
9047 complaint (&symfile_complaints
,
9048 _("malformed enumerator DIE ignored"));
9049 else if (building_psymtab
)
9050 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9051 VAR_DOMAIN
, LOC_CONST
,
9052 (cu
->language
== language_cplus
9053 || cu
->language
== language_java
)
9054 ? &cu
->objfile
->global_psymbols
9055 : &cu
->objfile
->static_psymbols
,
9056 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9058 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9062 /* We'll save this DIE so link it in. */
9063 part_die
->die_parent
= parent_die
;
9064 part_die
->die_sibling
= NULL
;
9065 part_die
->die_child
= NULL
;
9067 if (last_die
&& last_die
== parent_die
)
9068 last_die
->die_child
= part_die
;
9070 last_die
->die_sibling
= part_die
;
9072 last_die
= part_die
;
9074 if (first_die
== NULL
)
9075 first_die
= part_die
;
9077 /* Maybe add the DIE to the hash table. Not all DIEs that we
9078 find interesting need to be in the hash table, because we
9079 also have the parent/sibling/child chains; only those that we
9080 might refer to by offset later during partial symbol reading.
9082 For now this means things that might have be the target of a
9083 DW_AT_specification, DW_AT_abstract_origin, or
9084 DW_AT_extension. DW_AT_extension will refer only to
9085 namespaces; DW_AT_abstract_origin refers to functions (and
9086 many things under the function DIE, but we do not recurse
9087 into function DIEs during partial symbol reading) and
9088 possibly variables as well; DW_AT_specification refers to
9089 declarations. Declarations ought to have the DW_AT_declaration
9090 flag. It happens that GCC forgets to put it in sometimes, but
9091 only for functions, not for types.
9093 Adding more things than necessary to the hash table is harmless
9094 except for the performance cost. Adding too few will result in
9095 wasted time in find_partial_die, when we reread the compilation
9096 unit with load_all_dies set. */
9099 || abbrev
->tag
== DW_TAG_constant
9100 || abbrev
->tag
== DW_TAG_subprogram
9101 || abbrev
->tag
== DW_TAG_variable
9102 || abbrev
->tag
== DW_TAG_namespace
9103 || part_die
->is_declaration
)
9107 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9108 part_die
->offset
, INSERT
);
9112 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9113 sizeof (struct partial_die_info
));
9115 /* For some DIEs we want to follow their children (if any). For C
9116 we have no reason to follow the children of structures; for other
9117 languages we have to, so that we can get at method physnames
9118 to infer fully qualified class names, for DW_AT_specification,
9119 and for C++ template arguments. For C++, we also look one level
9120 inside functions to find template arguments (if the name of the
9121 function does not already contain the template arguments).
9123 For Ada, we need to scan the children of subprograms and lexical
9124 blocks as well because Ada allows the definition of nested
9125 entities that could be interesting for the debugger, such as
9126 nested subprograms for instance. */
9127 if (last_die
->has_children
9129 || last_die
->tag
== DW_TAG_namespace
9130 || last_die
->tag
== DW_TAG_module
9131 || last_die
->tag
== DW_TAG_enumeration_type
9132 || (cu
->language
== language_cplus
9133 && last_die
->tag
== DW_TAG_subprogram
9134 && (last_die
->name
== NULL
9135 || strchr (last_die
->name
, '<') == NULL
))
9136 || (cu
->language
!= language_c
9137 && (last_die
->tag
== DW_TAG_class_type
9138 || last_die
->tag
== DW_TAG_interface_type
9139 || last_die
->tag
== DW_TAG_structure_type
9140 || last_die
->tag
== DW_TAG_union_type
))
9141 || (cu
->language
== language_ada
9142 && (last_die
->tag
== DW_TAG_subprogram
9143 || last_die
->tag
== DW_TAG_lexical_block
))))
9146 parent_die
= last_die
;
9150 /* Otherwise we skip to the next sibling, if any. */
9151 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9153 /* Back to the top, do it again. */
9157 /* Read a minimal amount of information into the minimal die structure. */
9160 read_partial_die (struct partial_die_info
*part_die
,
9161 struct abbrev_info
*abbrev
,
9162 unsigned int abbrev_len
, bfd
*abfd
,
9163 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9164 struct dwarf2_cu
*cu
)
9167 struct attribute attr
;
9168 int has_low_pc_attr
= 0;
9169 int has_high_pc_attr
= 0;
9171 memset (part_die
, 0, sizeof (struct partial_die_info
));
9173 part_die
->offset
= info_ptr
- buffer
;
9175 info_ptr
+= abbrev_len
;
9180 part_die
->tag
= abbrev
->tag
;
9181 part_die
->has_children
= abbrev
->has_children
;
9183 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9185 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9187 /* Store the data if it is of an attribute we want to keep in a
9188 partial symbol table. */
9192 switch (part_die
->tag
)
9194 case DW_TAG_compile_unit
:
9195 case DW_TAG_type_unit
:
9196 /* Compilation units have a DW_AT_name that is a filename, not
9197 a source language identifier. */
9198 case DW_TAG_enumeration_type
:
9199 case DW_TAG_enumerator
:
9200 /* These tags always have simple identifiers already; no need
9201 to canonicalize them. */
9202 part_die
->name
= DW_STRING (&attr
);
9206 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9207 &cu
->objfile
->objfile_obstack
);
9211 case DW_AT_linkage_name
:
9212 case DW_AT_MIPS_linkage_name
:
9213 /* Note that both forms of linkage name might appear. We
9214 assume they will be the same, and we only store the last
9216 if (cu
->language
== language_ada
)
9217 part_die
->name
= DW_STRING (&attr
);
9218 part_die
->linkage_name
= DW_STRING (&attr
);
9221 has_low_pc_attr
= 1;
9222 part_die
->lowpc
= DW_ADDR (&attr
);
9225 has_high_pc_attr
= 1;
9226 part_die
->highpc
= DW_ADDR (&attr
);
9228 case DW_AT_location
:
9229 /* Support the .debug_loc offsets. */
9230 if (attr_form_is_block (&attr
))
9232 part_die
->locdesc
= DW_BLOCK (&attr
);
9234 else if (attr_form_is_section_offset (&attr
))
9236 dwarf2_complex_location_expr_complaint ();
9240 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9241 "partial symbol information");
9244 case DW_AT_external
:
9245 part_die
->is_external
= DW_UNSND (&attr
);
9247 case DW_AT_declaration
:
9248 part_die
->is_declaration
= DW_UNSND (&attr
);
9251 part_die
->has_type
= 1;
9253 case DW_AT_abstract_origin
:
9254 case DW_AT_specification
:
9255 case DW_AT_extension
:
9256 part_die
->has_specification
= 1;
9257 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9260 /* Ignore absolute siblings, they might point outside of
9261 the current compile unit. */
9262 if (attr
.form
== DW_FORM_ref_addr
)
9263 complaint (&symfile_complaints
,
9264 _("ignoring absolute DW_AT_sibling"));
9266 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9268 case DW_AT_byte_size
:
9269 part_die
->has_byte_size
= 1;
9271 case DW_AT_calling_convention
:
9272 /* DWARF doesn't provide a way to identify a program's source-level
9273 entry point. DW_AT_calling_convention attributes are only meant
9274 to describe functions' calling conventions.
9276 However, because it's a necessary piece of information in
9277 Fortran, and because DW_CC_program is the only piece of debugging
9278 information whose definition refers to a 'main program' at all,
9279 several compilers have begun marking Fortran main programs with
9280 DW_CC_program --- even when those functions use the standard
9281 calling conventions.
9283 So until DWARF specifies a way to provide this information and
9284 compilers pick up the new representation, we'll support this
9286 if (DW_UNSND (&attr
) == DW_CC_program
9287 && cu
->language
== language_fortran
)
9289 set_main_name (part_die
->name
);
9291 /* As this DIE has a static linkage the name would be difficult
9292 to look up later. */
9293 language_of_main
= language_fortran
;
9301 if (has_low_pc_attr
&& has_high_pc_attr
)
9303 /* When using the GNU linker, .gnu.linkonce. sections are used to
9304 eliminate duplicate copies of functions and vtables and such.
9305 The linker will arbitrarily choose one and discard the others.
9306 The AT_*_pc values for such functions refer to local labels in
9307 these sections. If the section from that file was discarded, the
9308 labels are not in the output, so the relocs get a value of 0.
9309 If this is a discarded function, mark the pc bounds as invalid,
9310 so that GDB will ignore it. */
9311 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9313 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9315 complaint (&symfile_complaints
,
9316 _("DW_AT_low_pc %s is zero "
9317 "for DIE at 0x%x [in module %s]"),
9318 paddress (gdbarch
, part_die
->lowpc
),
9319 part_die
->offset
, cu
->objfile
->name
);
9321 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9322 else if (part_die
->lowpc
>= part_die
->highpc
)
9324 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9326 complaint (&symfile_complaints
,
9327 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9328 "for DIE at 0x%x [in module %s]"),
9329 paddress (gdbarch
, part_die
->lowpc
),
9330 paddress (gdbarch
, part_die
->highpc
),
9331 part_die
->offset
, cu
->objfile
->name
);
9334 part_die
->has_pc_info
= 1;
9340 /* Find a cached partial DIE at OFFSET in CU. */
9342 static struct partial_die_info
*
9343 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9345 struct partial_die_info
*lookup_die
= NULL
;
9346 struct partial_die_info part_die
;
9348 part_die
.offset
= offset
;
9349 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9354 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9355 except in the case of .debug_types DIEs which do not reference
9356 outside their CU (they do however referencing other types via
9357 DW_FORM_ref_sig8). */
9359 static struct partial_die_info
*
9360 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9362 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9363 struct partial_die_info
*pd
= NULL
;
9365 if (cu
->per_cu
->from_debug_types
)
9367 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9373 if (offset_in_cu_p (&cu
->header
, offset
))
9375 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9380 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9382 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9383 load_partial_comp_unit (per_cu
, cu
->objfile
);
9385 per_cu
->cu
->last_used
= 0;
9386 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9388 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9390 struct cleanup
*back_to
;
9391 struct partial_die_info comp_unit_die
;
9392 struct abbrev_info
*abbrev
;
9393 unsigned int bytes_read
;
9396 per_cu
->load_all_dies
= 1;
9398 /* Re-read the DIEs. */
9399 back_to
= make_cleanup (null_cleanup
, 0);
9400 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9402 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
9403 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9405 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9406 + per_cu
->cu
->header
.offset
9407 + per_cu
->cu
->header
.first_die_offset
);
9408 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9409 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9410 per_cu
->cu
->objfile
->obfd
,
9411 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9413 if (comp_unit_die
.has_children
)
9414 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
9415 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9417 do_cleanups (back_to
);
9419 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9425 internal_error (__FILE__
, __LINE__
,
9426 _("could not find partial DIE 0x%x "
9427 "in cache [from module %s]\n"),
9428 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9432 /* See if we can figure out if the class lives in a namespace. We do
9433 this by looking for a member function; its demangled name will
9434 contain namespace info, if there is any. */
9437 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9438 struct dwarf2_cu
*cu
)
9440 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9441 what template types look like, because the demangler
9442 frequently doesn't give the same name as the debug info. We
9443 could fix this by only using the demangled name to get the
9444 prefix (but see comment in read_structure_type). */
9446 struct partial_die_info
*real_pdi
;
9447 struct partial_die_info
*child_pdi
;
9449 /* If this DIE (this DIE's specification, if any) has a parent, then
9450 we should not do this. We'll prepend the parent's fully qualified
9451 name when we create the partial symbol. */
9453 real_pdi
= struct_pdi
;
9454 while (real_pdi
->has_specification
)
9455 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9457 if (real_pdi
->die_parent
!= NULL
)
9460 for (child_pdi
= struct_pdi
->die_child
;
9462 child_pdi
= child_pdi
->die_sibling
)
9464 if (child_pdi
->tag
== DW_TAG_subprogram
9465 && child_pdi
->linkage_name
!= NULL
)
9467 char *actual_class_name
9468 = language_class_name_from_physname (cu
->language_defn
,
9469 child_pdi
->linkage_name
);
9470 if (actual_class_name
!= NULL
)
9473 = obsavestring (actual_class_name
,
9474 strlen (actual_class_name
),
9475 &cu
->objfile
->objfile_obstack
);
9476 xfree (actual_class_name
);
9483 /* Adjust PART_DIE before generating a symbol for it. This function
9484 may set the is_external flag or change the DIE's name. */
9487 fixup_partial_die (struct partial_die_info
*part_die
,
9488 struct dwarf2_cu
*cu
)
9490 /* Once we've fixed up a die, there's no point in doing so again.
9491 This also avoids a memory leak if we were to call
9492 guess_partial_die_structure_name multiple times. */
9493 if (part_die
->fixup_called
)
9496 /* If we found a reference attribute and the DIE has no name, try
9497 to find a name in the referred to DIE. */
9499 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9501 struct partial_die_info
*spec_die
;
9503 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9505 fixup_partial_die (spec_die
, cu
);
9509 part_die
->name
= spec_die
->name
;
9511 /* Copy DW_AT_external attribute if it is set. */
9512 if (spec_die
->is_external
)
9513 part_die
->is_external
= spec_die
->is_external
;
9517 /* Set default names for some unnamed DIEs. */
9519 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9520 part_die
->name
= "(anonymous namespace)";
9522 /* If there is no parent die to provide a namespace, and there are
9523 children, see if we can determine the namespace from their linkage
9525 NOTE: We need to do this even if cu->has_namespace_info != 0.
9526 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9527 if (cu
->language
== language_cplus
9528 && dwarf2_per_objfile
->types
.asection
!= NULL
9529 && part_die
->die_parent
== NULL
9530 && part_die
->has_children
9531 && (part_die
->tag
== DW_TAG_class_type
9532 || part_die
->tag
== DW_TAG_structure_type
9533 || part_die
->tag
== DW_TAG_union_type
))
9534 guess_partial_die_structure_name (part_die
, cu
);
9536 /* GCC might emit a nameless struct or union that has a linkage
9537 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
9538 if (part_die
->name
== NULL
9539 && (part_die
->tag
== DW_TAG_structure_type
9540 || part_die
->tag
== DW_TAG_union_type
9541 || part_die
->tag
== DW_TAG_class_type
)
9542 && part_die
->linkage_name
!= NULL
)
9546 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
9549 part_die
->name
= obsavestring (demangled
, strlen (demangled
),
9550 &cu
->objfile
->objfile_obstack
);
9555 part_die
->fixup_called
= 1;
9558 /* Read an attribute value described by an attribute form. */
9561 read_attribute_value (struct attribute
*attr
, unsigned form
,
9562 bfd
*abfd
, gdb_byte
*info_ptr
,
9563 struct dwarf2_cu
*cu
)
9565 struct comp_unit_head
*cu_header
= &cu
->header
;
9566 unsigned int bytes_read
;
9567 struct dwarf_block
*blk
;
9572 case DW_FORM_ref_addr
:
9573 if (cu
->header
.version
== 2)
9574 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9576 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
9577 &cu
->header
, &bytes_read
);
9578 info_ptr
+= bytes_read
;
9581 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9582 info_ptr
+= bytes_read
;
9584 case DW_FORM_block2
:
9585 blk
= dwarf_alloc_block (cu
);
9586 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9588 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9589 info_ptr
+= blk
->size
;
9590 DW_BLOCK (attr
) = blk
;
9592 case DW_FORM_block4
:
9593 blk
= dwarf_alloc_block (cu
);
9594 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9596 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9597 info_ptr
+= blk
->size
;
9598 DW_BLOCK (attr
) = blk
;
9601 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9605 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9609 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9612 case DW_FORM_sec_offset
:
9613 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9614 info_ptr
+= bytes_read
;
9616 case DW_FORM_string
:
9617 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9618 DW_STRING_IS_CANONICAL (attr
) = 0;
9619 info_ptr
+= bytes_read
;
9622 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9624 DW_STRING_IS_CANONICAL (attr
) = 0;
9625 info_ptr
+= bytes_read
;
9627 case DW_FORM_exprloc
:
9629 blk
= dwarf_alloc_block (cu
);
9630 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9631 info_ptr
+= bytes_read
;
9632 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9633 info_ptr
+= blk
->size
;
9634 DW_BLOCK (attr
) = blk
;
9636 case DW_FORM_block1
:
9637 blk
= dwarf_alloc_block (cu
);
9638 blk
->size
= read_1_byte (abfd
, info_ptr
);
9640 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9641 info_ptr
+= blk
->size
;
9642 DW_BLOCK (attr
) = blk
;
9645 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9649 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9652 case DW_FORM_flag_present
:
9653 DW_UNSND (attr
) = 1;
9656 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9657 info_ptr
+= bytes_read
;
9660 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9661 info_ptr
+= bytes_read
;
9664 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9668 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9672 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9676 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9679 case DW_FORM_ref_sig8
:
9680 /* Convert the signature to something we can record in DW_UNSND
9682 NOTE: This is NULL if the type wasn't found. */
9683 DW_SIGNATURED_TYPE (attr
) =
9684 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9687 case DW_FORM_ref_udata
:
9688 DW_ADDR (attr
) = (cu
->header
.offset
9689 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9690 info_ptr
+= bytes_read
;
9692 case DW_FORM_indirect
:
9693 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9694 info_ptr
+= bytes_read
;
9695 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9698 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9699 dwarf_form_name (form
),
9700 bfd_get_filename (abfd
));
9703 /* We have seen instances where the compiler tried to emit a byte
9704 size attribute of -1 which ended up being encoded as an unsigned
9705 0xffffffff. Although 0xffffffff is technically a valid size value,
9706 an object of this size seems pretty unlikely so we can relatively
9707 safely treat these cases as if the size attribute was invalid and
9708 treat them as zero by default. */
9709 if (attr
->name
== DW_AT_byte_size
9710 && form
== DW_FORM_data4
9711 && DW_UNSND (attr
) >= 0xffffffff)
9714 (&symfile_complaints
,
9715 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9716 hex_string (DW_UNSND (attr
)));
9717 DW_UNSND (attr
) = 0;
9723 /* Read an attribute described by an abbreviated attribute. */
9726 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9727 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9729 attr
->name
= abbrev
->name
;
9730 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9733 /* Read dwarf information from a buffer. */
9736 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9738 return bfd_get_8 (abfd
, buf
);
9742 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9744 return bfd_get_signed_8 (abfd
, buf
);
9748 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9750 return bfd_get_16 (abfd
, buf
);
9754 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9756 return bfd_get_signed_16 (abfd
, buf
);
9760 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9762 return bfd_get_32 (abfd
, buf
);
9766 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9768 return bfd_get_signed_32 (abfd
, buf
);
9772 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9774 return bfd_get_64 (abfd
, buf
);
9778 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9779 unsigned int *bytes_read
)
9781 struct comp_unit_head
*cu_header
= &cu
->header
;
9782 CORE_ADDR retval
= 0;
9784 if (cu_header
->signed_addr_p
)
9786 switch (cu_header
->addr_size
)
9789 retval
= bfd_get_signed_16 (abfd
, buf
);
9792 retval
= bfd_get_signed_32 (abfd
, buf
);
9795 retval
= bfd_get_signed_64 (abfd
, buf
);
9798 internal_error (__FILE__
, __LINE__
,
9799 _("read_address: bad switch, signed [in module %s]"),
9800 bfd_get_filename (abfd
));
9805 switch (cu_header
->addr_size
)
9808 retval
= bfd_get_16 (abfd
, buf
);
9811 retval
= bfd_get_32 (abfd
, buf
);
9814 retval
= bfd_get_64 (abfd
, buf
);
9817 internal_error (__FILE__
, __LINE__
,
9818 _("read_address: bad switch, "
9819 "unsigned [in module %s]"),
9820 bfd_get_filename (abfd
));
9824 *bytes_read
= cu_header
->addr_size
;
9828 /* Read the initial length from a section. The (draft) DWARF 3
9829 specification allows the initial length to take up either 4 bytes
9830 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9831 bytes describe the length and all offsets will be 8 bytes in length
9834 An older, non-standard 64-bit format is also handled by this
9835 function. The older format in question stores the initial length
9836 as an 8-byte quantity without an escape value. Lengths greater
9837 than 2^32 aren't very common which means that the initial 4 bytes
9838 is almost always zero. Since a length value of zero doesn't make
9839 sense for the 32-bit format, this initial zero can be considered to
9840 be an escape value which indicates the presence of the older 64-bit
9841 format. As written, the code can't detect (old format) lengths
9842 greater than 4GB. If it becomes necessary to handle lengths
9843 somewhat larger than 4GB, we could allow other small values (such
9844 as the non-sensical values of 1, 2, and 3) to also be used as
9845 escape values indicating the presence of the old format.
9847 The value returned via bytes_read should be used to increment the
9848 relevant pointer after calling read_initial_length().
9850 [ Note: read_initial_length() and read_offset() are based on the
9851 document entitled "DWARF Debugging Information Format", revision
9852 3, draft 8, dated November 19, 2001. This document was obtained
9855 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9857 This document is only a draft and is subject to change. (So beware.)
9859 Details regarding the older, non-standard 64-bit format were
9860 determined empirically by examining 64-bit ELF files produced by
9861 the SGI toolchain on an IRIX 6.5 machine.
9863 - Kevin, July 16, 2002
9867 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
9869 LONGEST length
= bfd_get_32 (abfd
, buf
);
9871 if (length
== 0xffffffff)
9873 length
= bfd_get_64 (abfd
, buf
+ 4);
9876 else if (length
== 0)
9878 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9879 length
= bfd_get_64 (abfd
, buf
);
9890 /* Cover function for read_initial_length.
9891 Returns the length of the object at BUF, and stores the size of the
9892 initial length in *BYTES_READ and stores the size that offsets will be in
9894 If the initial length size is not equivalent to that specified in
9895 CU_HEADER then issue a complaint.
9896 This is useful when reading non-comp-unit headers. */
9899 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
9900 const struct comp_unit_head
*cu_header
,
9901 unsigned int *bytes_read
,
9902 unsigned int *offset_size
)
9904 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
9906 gdb_assert (cu_header
->initial_length_size
== 4
9907 || cu_header
->initial_length_size
== 8
9908 || cu_header
->initial_length_size
== 12);
9910 if (cu_header
->initial_length_size
!= *bytes_read
)
9911 complaint (&symfile_complaints
,
9912 _("intermixed 32-bit and 64-bit DWARF sections"));
9914 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
9918 /* Read an offset from the data stream. The size of the offset is
9919 given by cu_header->offset_size. */
9922 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
9923 unsigned int *bytes_read
)
9925 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
9927 *bytes_read
= cu_header
->offset_size
;
9931 /* Read an offset from the data stream. */
9934 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
9938 switch (offset_size
)
9941 retval
= bfd_get_32 (abfd
, buf
);
9944 retval
= bfd_get_64 (abfd
, buf
);
9947 internal_error (__FILE__
, __LINE__
,
9948 _("read_offset_1: bad switch [in module %s]"),
9949 bfd_get_filename (abfd
));
9956 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
9958 /* If the size of a host char is 8 bits, we can return a pointer
9959 to the buffer, otherwise we have to copy the data to a buffer
9960 allocated on the temporary obstack. */
9961 gdb_assert (HOST_CHAR_BIT
== 8);
9966 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9968 /* If the size of a host char is 8 bits, we can return a pointer
9969 to the string, otherwise we have to copy the string to a buffer
9970 allocated on the temporary obstack. */
9971 gdb_assert (HOST_CHAR_BIT
== 8);
9974 *bytes_read_ptr
= 1;
9977 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
9978 return (char *) buf
;
9982 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
9983 const struct comp_unit_head
*cu_header
,
9984 unsigned int *bytes_read_ptr
)
9986 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
9988 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
9989 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
9991 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9992 bfd_get_filename (abfd
));
9995 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
9997 error (_("DW_FORM_strp pointing outside of "
9998 ".debug_str section [in module %s]"),
9999 bfd_get_filename (abfd
));
10002 gdb_assert (HOST_CHAR_BIT
== 8);
10003 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10005 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10008 static unsigned long
10009 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10011 unsigned long result
;
10012 unsigned int num_read
;
10014 unsigned char byte
;
10022 byte
= bfd_get_8 (abfd
, buf
);
10025 result
|= ((unsigned long)(byte
& 127) << shift
);
10026 if ((byte
& 128) == 0)
10032 *bytes_read_ptr
= num_read
;
10037 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10040 int i
, shift
, num_read
;
10041 unsigned char byte
;
10049 byte
= bfd_get_8 (abfd
, buf
);
10052 result
|= ((long)(byte
& 127) << shift
);
10054 if ((byte
& 128) == 0)
10059 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10060 result
|= -(((long)1) << shift
);
10061 *bytes_read_ptr
= num_read
;
10065 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10068 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10074 byte
= bfd_get_8 (abfd
, buf
);
10076 if ((byte
& 128) == 0)
10082 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10089 cu
->language
= language_c
;
10091 case DW_LANG_C_plus_plus
:
10092 cu
->language
= language_cplus
;
10095 cu
->language
= language_d
;
10097 case DW_LANG_Fortran77
:
10098 case DW_LANG_Fortran90
:
10099 case DW_LANG_Fortran95
:
10100 cu
->language
= language_fortran
;
10102 case DW_LANG_Mips_Assembler
:
10103 cu
->language
= language_asm
;
10106 cu
->language
= language_java
;
10108 case DW_LANG_Ada83
:
10109 case DW_LANG_Ada95
:
10110 cu
->language
= language_ada
;
10112 case DW_LANG_Modula2
:
10113 cu
->language
= language_m2
;
10115 case DW_LANG_Pascal83
:
10116 cu
->language
= language_pascal
;
10119 cu
->language
= language_objc
;
10121 case DW_LANG_Cobol74
:
10122 case DW_LANG_Cobol85
:
10124 cu
->language
= language_minimal
;
10127 cu
->language_defn
= language_def (cu
->language
);
10130 /* Return the named attribute or NULL if not there. */
10132 static struct attribute
*
10133 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10136 struct attribute
*spec
= NULL
;
10138 for (i
= 0; i
< die
->num_attrs
; ++i
)
10140 if (die
->attrs
[i
].name
== name
)
10141 return &die
->attrs
[i
];
10142 if (die
->attrs
[i
].name
== DW_AT_specification
10143 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10144 spec
= &die
->attrs
[i
];
10149 die
= follow_die_ref (die
, spec
, &cu
);
10150 return dwarf2_attr (die
, name
, cu
);
10156 /* Return the named attribute or NULL if not there,
10157 but do not follow DW_AT_specification, etc.
10158 This is for use in contexts where we're reading .debug_types dies.
10159 Following DW_AT_specification, DW_AT_abstract_origin will take us
10160 back up the chain, and we want to go down. */
10162 static struct attribute
*
10163 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10164 struct dwarf2_cu
*cu
)
10168 for (i
= 0; i
< die
->num_attrs
; ++i
)
10169 if (die
->attrs
[i
].name
== name
)
10170 return &die
->attrs
[i
];
10175 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10176 and holds a non-zero value. This function should only be used for
10177 DW_FORM_flag or DW_FORM_flag_present attributes. */
10180 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10182 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10184 return (attr
&& DW_UNSND (attr
));
10188 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10190 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10191 which value is non-zero. However, we have to be careful with
10192 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10193 (via dwarf2_flag_true_p) follows this attribute. So we may
10194 end up accidently finding a declaration attribute that belongs
10195 to a different DIE referenced by the specification attribute,
10196 even though the given DIE does not have a declaration attribute. */
10197 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10198 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10201 /* Return the die giving the specification for DIE, if there is
10202 one. *SPEC_CU is the CU containing DIE on input, and the CU
10203 containing the return value on output. If there is no
10204 specification, but there is an abstract origin, that is
10207 static struct die_info
*
10208 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10210 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10213 if (spec_attr
== NULL
)
10214 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10216 if (spec_attr
== NULL
)
10219 return follow_die_ref (die
, spec_attr
, spec_cu
);
10222 /* Free the line_header structure *LH, and any arrays and strings it
10224 NOTE: This is also used as a "cleanup" function. */
10227 free_line_header (struct line_header
*lh
)
10229 if (lh
->standard_opcode_lengths
)
10230 xfree (lh
->standard_opcode_lengths
);
10232 /* Remember that all the lh->file_names[i].name pointers are
10233 pointers into debug_line_buffer, and don't need to be freed. */
10234 if (lh
->file_names
)
10235 xfree (lh
->file_names
);
10237 /* Similarly for the include directory names. */
10238 if (lh
->include_dirs
)
10239 xfree (lh
->include_dirs
);
10244 /* Add an entry to LH's include directory table. */
10247 add_include_dir (struct line_header
*lh
, char *include_dir
)
10249 /* Grow the array if necessary. */
10250 if (lh
->include_dirs_size
== 0)
10252 lh
->include_dirs_size
= 1; /* for testing */
10253 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10254 * sizeof (*lh
->include_dirs
));
10256 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10258 lh
->include_dirs_size
*= 2;
10259 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10260 (lh
->include_dirs_size
10261 * sizeof (*lh
->include_dirs
)));
10264 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10267 /* Add an entry to LH's file name table. */
10270 add_file_name (struct line_header
*lh
,
10272 unsigned int dir_index
,
10273 unsigned int mod_time
,
10274 unsigned int length
)
10276 struct file_entry
*fe
;
10278 /* Grow the array if necessary. */
10279 if (lh
->file_names_size
== 0)
10281 lh
->file_names_size
= 1; /* for testing */
10282 lh
->file_names
= xmalloc (lh
->file_names_size
10283 * sizeof (*lh
->file_names
));
10285 else if (lh
->num_file_names
>= lh
->file_names_size
)
10287 lh
->file_names_size
*= 2;
10288 lh
->file_names
= xrealloc (lh
->file_names
,
10289 (lh
->file_names_size
10290 * sizeof (*lh
->file_names
)));
10293 fe
= &lh
->file_names
[lh
->num_file_names
++];
10295 fe
->dir_index
= dir_index
;
10296 fe
->mod_time
= mod_time
;
10297 fe
->length
= length
;
10298 fe
->included_p
= 0;
10302 /* Read the statement program header starting at OFFSET in
10303 .debug_line, according to the endianness of ABFD. Return a pointer
10304 to a struct line_header, allocated using xmalloc.
10306 NOTE: the strings in the include directory and file name tables of
10307 the returned object point into debug_line_buffer, and must not be
10310 static struct line_header
*
10311 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10312 struct dwarf2_cu
*cu
)
10314 struct cleanup
*back_to
;
10315 struct line_header
*lh
;
10316 gdb_byte
*line_ptr
;
10317 unsigned int bytes_read
, offset_size
;
10319 char *cur_dir
, *cur_file
;
10321 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10322 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10324 complaint (&symfile_complaints
, _("missing .debug_line section"));
10328 /* Make sure that at least there's room for the total_length field.
10329 That could be 12 bytes long, but we're just going to fudge that. */
10330 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10332 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10336 lh
= xmalloc (sizeof (*lh
));
10337 memset (lh
, 0, sizeof (*lh
));
10338 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10341 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10343 /* Read in the header. */
10345 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10346 &bytes_read
, &offset_size
);
10347 line_ptr
+= bytes_read
;
10348 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10349 + dwarf2_per_objfile
->line
.size
))
10351 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10354 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10355 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10357 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10358 line_ptr
+= offset_size
;
10359 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10361 if (lh
->version
>= 4)
10363 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10367 lh
->maximum_ops_per_instruction
= 1;
10369 if (lh
->maximum_ops_per_instruction
== 0)
10371 lh
->maximum_ops_per_instruction
= 1;
10372 complaint (&symfile_complaints
,
10373 _("invalid maximum_ops_per_instruction "
10374 "in `.debug_line' section"));
10377 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10379 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10381 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10383 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10385 lh
->standard_opcode_lengths
10386 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10388 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10389 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10391 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10395 /* Read directory table. */
10396 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10398 line_ptr
+= bytes_read
;
10399 add_include_dir (lh
, cur_dir
);
10401 line_ptr
+= bytes_read
;
10403 /* Read file name table. */
10404 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10406 unsigned int dir_index
, mod_time
, length
;
10408 line_ptr
+= bytes_read
;
10409 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10410 line_ptr
+= bytes_read
;
10411 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10412 line_ptr
+= bytes_read
;
10413 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10414 line_ptr
+= bytes_read
;
10416 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10418 line_ptr
+= bytes_read
;
10419 lh
->statement_program_start
= line_ptr
;
10421 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
10422 + dwarf2_per_objfile
->line
.size
))
10423 complaint (&symfile_complaints
,
10424 _("line number info header doesn't "
10425 "fit in `.debug_line' section"));
10427 discard_cleanups (back_to
);
10431 /* This function exists to work around a bug in certain compilers
10432 (particularly GCC 2.95), in which the first line number marker of a
10433 function does not show up until after the prologue, right before
10434 the second line number marker. This function shifts ADDRESS down
10435 to the beginning of the function if necessary, and is called on
10436 addresses passed to record_line. */
10439 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
10441 struct function_range
*fn
;
10443 /* Find the function_range containing address. */
10447 if (!cu
->cached_fn
)
10448 cu
->cached_fn
= cu
->first_fn
;
10450 fn
= cu
->cached_fn
;
10452 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10458 while (fn
&& fn
!= cu
->cached_fn
)
10459 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10469 if (address
!= fn
->lowpc
)
10470 complaint (&symfile_complaints
,
10471 _("misplaced first line number at 0x%lx for '%s'"),
10472 (unsigned long) address
, fn
->name
);
10477 /* Subroutine of dwarf_decode_lines to simplify it.
10478 Return the file name of the psymtab for included file FILE_INDEX
10479 in line header LH of PST.
10480 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10481 If space for the result is malloc'd, it will be freed by a cleanup.
10482 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10485 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10486 const struct partial_symtab
*pst
,
10487 const char *comp_dir
)
10489 const struct file_entry fe
= lh
->file_names
[file_index
];
10490 char *include_name
= fe
.name
;
10491 char *include_name_to_compare
= include_name
;
10492 char *dir_name
= NULL
;
10493 const char *pst_filename
;
10494 char *copied_name
= NULL
;
10498 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10500 if (!IS_ABSOLUTE_PATH (include_name
)
10501 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10503 /* Avoid creating a duplicate psymtab for PST.
10504 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10505 Before we do the comparison, however, we need to account
10506 for DIR_NAME and COMP_DIR.
10507 First prepend dir_name (if non-NULL). If we still don't
10508 have an absolute path prepend comp_dir (if non-NULL).
10509 However, the directory we record in the include-file's
10510 psymtab does not contain COMP_DIR (to match the
10511 corresponding symtab(s)).
10516 bash$ gcc -g ./hello.c
10517 include_name = "hello.c"
10519 DW_AT_comp_dir = comp_dir = "/tmp"
10520 DW_AT_name = "./hello.c" */
10522 if (dir_name
!= NULL
)
10524 include_name
= concat (dir_name
, SLASH_STRING
,
10525 include_name
, (char *)NULL
);
10526 include_name_to_compare
= include_name
;
10527 make_cleanup (xfree
, include_name
);
10529 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10531 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10532 include_name
, (char *)NULL
);
10536 pst_filename
= pst
->filename
;
10537 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10539 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
10540 pst_filename
, (char *)NULL
);
10541 pst_filename
= copied_name
;
10544 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
10546 if (include_name_to_compare
!= include_name
)
10547 xfree (include_name_to_compare
);
10548 if (copied_name
!= NULL
)
10549 xfree (copied_name
);
10553 return include_name
;
10556 /* Ignore this record_line request. */
10559 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10564 /* Decode the Line Number Program (LNP) for the given line_header
10565 structure and CU. The actual information extracted and the type
10566 of structures created from the LNP depends on the value of PST.
10568 1. If PST is NULL, then this procedure uses the data from the program
10569 to create all necessary symbol tables, and their linetables.
10571 2. If PST is not NULL, this procedure reads the program to determine
10572 the list of files included by the unit represented by PST, and
10573 builds all the associated partial symbol tables.
10575 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10576 It is used for relative paths in the line table.
10577 NOTE: When processing partial symtabs (pst != NULL),
10578 comp_dir == pst->dirname.
10580 NOTE: It is important that psymtabs have the same file name (via strcmp)
10581 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10582 symtab we don't use it in the name of the psymtabs we create.
10583 E.g. expand_line_sal requires this when finding psymtabs to expand.
10584 A good testcase for this is mb-inline.exp. */
10587 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
10588 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10590 gdb_byte
*line_ptr
, *extended_end
;
10591 gdb_byte
*line_end
;
10592 unsigned int bytes_read
, extended_len
;
10593 unsigned char op_code
, extended_op
, adj_opcode
;
10594 CORE_ADDR baseaddr
;
10595 struct objfile
*objfile
= cu
->objfile
;
10596 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10597 const int decode_for_pst_p
= (pst
!= NULL
);
10598 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10599 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10602 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10604 line_ptr
= lh
->statement_program_start
;
10605 line_end
= lh
->statement_program_end
;
10607 /* Read the statement sequences until there's nothing left. */
10608 while (line_ptr
< line_end
)
10610 /* state machine registers */
10611 CORE_ADDR address
= 0;
10612 unsigned int file
= 1;
10613 unsigned int line
= 1;
10614 unsigned int column
= 0;
10615 int is_stmt
= lh
->default_is_stmt
;
10616 int basic_block
= 0;
10617 int end_sequence
= 0;
10619 unsigned char op_index
= 0;
10621 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10623 /* Start a subfile for the current file of the state machine. */
10624 /* lh->include_dirs and lh->file_names are 0-based, but the
10625 directory and file name numbers in the statement program
10627 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10631 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10633 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10636 /* Decode the table. */
10637 while (!end_sequence
)
10639 op_code
= read_1_byte (abfd
, line_ptr
);
10641 if (line_ptr
> line_end
)
10643 dwarf2_debug_line_missing_end_sequence_complaint ();
10647 if (op_code
>= lh
->opcode_base
)
10649 /* Special operand. */
10650 adj_opcode
= op_code
- lh
->opcode_base
;
10651 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10652 / lh
->maximum_ops_per_instruction
)
10653 * lh
->minimum_instruction_length
);
10654 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10655 % lh
->maximum_ops_per_instruction
);
10656 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10657 if (lh
->num_file_names
< file
|| file
== 0)
10658 dwarf2_debug_line_missing_file_complaint ();
10659 /* For now we ignore lines not starting on an
10660 instruction boundary. */
10661 else if (op_index
== 0)
10663 lh
->file_names
[file
- 1].included_p
= 1;
10664 if (!decode_for_pst_p
&& is_stmt
)
10666 if (last_subfile
!= current_subfile
)
10668 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10670 (*p_record_line
) (last_subfile
, 0, addr
);
10671 last_subfile
= current_subfile
;
10673 /* Append row to matrix using current values. */
10674 addr
= check_cu_functions (address
, cu
);
10675 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10676 (*p_record_line
) (current_subfile
, line
, addr
);
10681 else switch (op_code
)
10683 case DW_LNS_extended_op
:
10684 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
10686 line_ptr
+= bytes_read
;
10687 extended_end
= line_ptr
+ extended_len
;
10688 extended_op
= read_1_byte (abfd
, line_ptr
);
10690 switch (extended_op
)
10692 case DW_LNE_end_sequence
:
10693 p_record_line
= record_line
;
10696 case DW_LNE_set_address
:
10697 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10699 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10701 /* This line table is for a function which has been
10702 GCd by the linker. Ignore it. PR gdb/12528 */
10705 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
10707 complaint (&symfile_complaints
,
10708 _(".debug_line address at offset 0x%lx is 0 "
10710 line_offset
, cu
->objfile
->name
);
10711 p_record_line
= noop_record_line
;
10715 line_ptr
+= bytes_read
;
10716 address
+= baseaddr
;
10718 case DW_LNE_define_file
:
10721 unsigned int dir_index
, mod_time
, length
;
10723 cur_file
= read_direct_string (abfd
, line_ptr
,
10725 line_ptr
+= bytes_read
;
10727 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10728 line_ptr
+= bytes_read
;
10730 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10731 line_ptr
+= bytes_read
;
10733 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10734 line_ptr
+= bytes_read
;
10735 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10738 case DW_LNE_set_discriminator
:
10739 /* The discriminator is not interesting to the debugger;
10741 line_ptr
= extended_end
;
10744 complaint (&symfile_complaints
,
10745 _("mangled .debug_line section"));
10748 /* Make sure that we parsed the extended op correctly. If e.g.
10749 we expected a different address size than the producer used,
10750 we may have read the wrong number of bytes. */
10751 if (line_ptr
!= extended_end
)
10753 complaint (&symfile_complaints
,
10754 _("mangled .debug_line section"));
10759 if (lh
->num_file_names
< file
|| file
== 0)
10760 dwarf2_debug_line_missing_file_complaint ();
10763 lh
->file_names
[file
- 1].included_p
= 1;
10764 if (!decode_for_pst_p
&& is_stmt
)
10766 if (last_subfile
!= current_subfile
)
10768 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10770 (*p_record_line
) (last_subfile
, 0, addr
);
10771 last_subfile
= current_subfile
;
10773 addr
= check_cu_functions (address
, cu
);
10774 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10775 (*p_record_line
) (current_subfile
, line
, addr
);
10780 case DW_LNS_advance_pc
:
10783 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10785 address
+= (((op_index
+ adjust
)
10786 / lh
->maximum_ops_per_instruction
)
10787 * lh
->minimum_instruction_length
);
10788 op_index
= ((op_index
+ adjust
)
10789 % lh
->maximum_ops_per_instruction
);
10790 line_ptr
+= bytes_read
;
10793 case DW_LNS_advance_line
:
10794 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
10795 line_ptr
+= bytes_read
;
10797 case DW_LNS_set_file
:
10799 /* The arrays lh->include_dirs and lh->file_names are
10800 0-based, but the directory and file name numbers in
10801 the statement program are 1-based. */
10802 struct file_entry
*fe
;
10805 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10806 line_ptr
+= bytes_read
;
10807 if (lh
->num_file_names
< file
|| file
== 0)
10808 dwarf2_debug_line_missing_file_complaint ();
10811 fe
= &lh
->file_names
[file
- 1];
10813 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10814 if (!decode_for_pst_p
)
10816 last_subfile
= current_subfile
;
10817 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10822 case DW_LNS_set_column
:
10823 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10824 line_ptr
+= bytes_read
;
10826 case DW_LNS_negate_stmt
:
10827 is_stmt
= (!is_stmt
);
10829 case DW_LNS_set_basic_block
:
10832 /* Add to the address register of the state machine the
10833 address increment value corresponding to special opcode
10834 255. I.e., this value is scaled by the minimum
10835 instruction length since special opcode 255 would have
10836 scaled the increment. */
10837 case DW_LNS_const_add_pc
:
10839 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
10841 address
+= (((op_index
+ adjust
)
10842 / lh
->maximum_ops_per_instruction
)
10843 * lh
->minimum_instruction_length
);
10844 op_index
= ((op_index
+ adjust
)
10845 % lh
->maximum_ops_per_instruction
);
10848 case DW_LNS_fixed_advance_pc
:
10849 address
+= read_2_bytes (abfd
, line_ptr
);
10855 /* Unknown standard opcode, ignore it. */
10858 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
10860 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10861 line_ptr
+= bytes_read
;
10866 if (lh
->num_file_names
< file
|| file
== 0)
10867 dwarf2_debug_line_missing_file_complaint ();
10870 lh
->file_names
[file
- 1].included_p
= 1;
10871 if (!decode_for_pst_p
)
10873 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10874 (*p_record_line
) (current_subfile
, 0, addr
);
10879 if (decode_for_pst_p
)
10883 /* Now that we're done scanning the Line Header Program, we can
10884 create the psymtab of each included file. */
10885 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
10886 if (lh
->file_names
[file_index
].included_p
== 1)
10888 char *include_name
=
10889 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
10890 if (include_name
!= NULL
)
10891 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
10896 /* Make sure a symtab is created for every file, even files
10897 which contain only variables (i.e. no code with associated
10901 struct file_entry
*fe
;
10903 for (i
= 0; i
< lh
->num_file_names
; i
++)
10907 fe
= &lh
->file_names
[i
];
10909 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10910 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10912 /* Skip the main file; we don't need it, and it must be
10913 allocated last, so that it will show up before the
10914 non-primary symtabs in the objfile's symtab list. */
10915 if (current_subfile
== first_subfile
)
10918 if (current_subfile
->symtab
== NULL
)
10919 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
10921 fe
->symtab
= current_subfile
->symtab
;
10926 /* Start a subfile for DWARF. FILENAME is the name of the file and
10927 DIRNAME the name of the source directory which contains FILENAME
10928 or NULL if not known. COMP_DIR is the compilation directory for the
10929 linetable's compilation unit or NULL if not known.
10930 This routine tries to keep line numbers from identical absolute and
10931 relative file names in a common subfile.
10933 Using the `list' example from the GDB testsuite, which resides in
10934 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10935 of /srcdir/list0.c yields the following debugging information for list0.c:
10937 DW_AT_name: /srcdir/list0.c
10938 DW_AT_comp_dir: /compdir
10939 files.files[0].name: list0.h
10940 files.files[0].dir: /srcdir
10941 files.files[1].name: list0.c
10942 files.files[1].dir: /srcdir
10944 The line number information for list0.c has to end up in a single
10945 subfile, so that `break /srcdir/list0.c:1' works as expected.
10946 start_subfile will ensure that this happens provided that we pass the
10947 concatenation of files.files[1].dir and files.files[1].name as the
10951 dwarf2_start_subfile (char *filename
, const char *dirname
,
10952 const char *comp_dir
)
10956 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10957 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10958 second argument to start_subfile. To be consistent, we do the
10959 same here. In order not to lose the line information directory,
10960 we concatenate it to the filename when it makes sense.
10961 Note that the Dwarf3 standard says (speaking of filenames in line
10962 information): ``The directory index is ignored for file names
10963 that represent full path names''. Thus ignoring dirname in the
10964 `else' branch below isn't an issue. */
10966 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
10967 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
10969 fullname
= filename
;
10971 start_subfile (fullname
, comp_dir
);
10973 if (fullname
!= filename
)
10978 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
10979 struct dwarf2_cu
*cu
)
10981 struct objfile
*objfile
= cu
->objfile
;
10982 struct comp_unit_head
*cu_header
= &cu
->header
;
10984 /* NOTE drow/2003-01-30: There used to be a comment and some special
10985 code here to turn a symbol with DW_AT_external and a
10986 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10987 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10988 with some versions of binutils) where shared libraries could have
10989 relocations against symbols in their debug information - the
10990 minimal symbol would have the right address, but the debug info
10991 would not. It's no longer necessary, because we will explicitly
10992 apply relocations when we read in the debug information now. */
10994 /* A DW_AT_location attribute with no contents indicates that a
10995 variable has been optimized away. */
10996 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
10998 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11002 /* Handle one degenerate form of location expression specially, to
11003 preserve GDB's previous behavior when section offsets are
11004 specified. If this is just a DW_OP_addr then mark this symbol
11007 if (attr_form_is_block (attr
)
11008 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11009 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11011 unsigned int dummy
;
11013 SYMBOL_VALUE_ADDRESS (sym
) =
11014 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11015 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11016 fixup_symbol_section (sym
, objfile
);
11017 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11018 SYMBOL_SECTION (sym
));
11022 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11023 expression evaluator, and use LOC_COMPUTED only when necessary
11024 (i.e. when the value of a register or memory location is
11025 referenced, or a thread-local block, etc.). Then again, it might
11026 not be worthwhile. I'm assuming that it isn't unless performance
11027 or memory numbers show me otherwise. */
11029 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11030 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11032 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11033 cu
->has_loclist
= 1;
11036 /* Given a pointer to a DWARF information entry, figure out if we need
11037 to make a symbol table entry for it, and if so, create a new entry
11038 and return a pointer to it.
11039 If TYPE is NULL, determine symbol type from the die, otherwise
11040 used the passed type.
11041 If SPACE is not NULL, use it to hold the new symbol. If it is
11042 NULL, allocate a new symbol on the objfile's obstack. */
11044 static struct symbol
*
11045 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11046 struct symbol
*space
)
11048 struct objfile
*objfile
= cu
->objfile
;
11049 struct symbol
*sym
= NULL
;
11051 struct attribute
*attr
= NULL
;
11052 struct attribute
*attr2
= NULL
;
11053 CORE_ADDR baseaddr
;
11054 struct pending
**list_to_add
= NULL
;
11056 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11058 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11060 name
= dwarf2_name (die
, cu
);
11063 const char *linkagename
;
11064 int suppress_add
= 0;
11069 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11070 OBJSTAT (objfile
, n_syms
++);
11072 /* Cache this symbol's name and the name's demangled form (if any). */
11073 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11074 linkagename
= dwarf2_physname (name
, die
, cu
);
11075 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11077 /* Fortran does not have mangling standard and the mangling does differ
11078 between gfortran, iFort etc. */
11079 if (cu
->language
== language_fortran
11080 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11081 symbol_set_demangled_name (&(sym
->ginfo
),
11082 (char *) dwarf2_full_name (name
, die
, cu
),
11085 /* Default assumptions.
11086 Use the passed type or decode it from the die. */
11087 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11088 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11090 SYMBOL_TYPE (sym
) = type
;
11092 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11093 attr
= dwarf2_attr (die
,
11094 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11098 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11101 attr
= dwarf2_attr (die
,
11102 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11106 int file_index
= DW_UNSND (attr
);
11108 if (cu
->line_header
== NULL
11109 || file_index
> cu
->line_header
->num_file_names
)
11110 complaint (&symfile_complaints
,
11111 _("file index out of range"));
11112 else if (file_index
> 0)
11114 struct file_entry
*fe
;
11116 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11117 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11124 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11127 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11129 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11130 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11131 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11132 add_symbol_to_list (sym
, cu
->list_in_scope
);
11134 case DW_TAG_subprogram
:
11135 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11137 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11138 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11139 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11140 || cu
->language
== language_ada
)
11142 /* Subprograms marked external are stored as a global symbol.
11143 Ada subprograms, whether marked external or not, are always
11144 stored as a global symbol, because we want to be able to
11145 access them globally. For instance, we want to be able
11146 to break on a nested subprogram without having to
11147 specify the context. */
11148 list_to_add
= &global_symbols
;
11152 list_to_add
= cu
->list_in_scope
;
11155 case DW_TAG_inlined_subroutine
:
11156 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11158 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11159 SYMBOL_INLINED (sym
) = 1;
11160 /* Do not add the symbol to any lists. It will be found via
11161 BLOCK_FUNCTION from the blockvector. */
11163 case DW_TAG_template_value_param
:
11165 /* Fall through. */
11166 case DW_TAG_constant
:
11167 case DW_TAG_variable
:
11168 case DW_TAG_member
:
11169 /* Compilation with minimal debug info may result in
11170 variables with missing type entries. Change the
11171 misleading `void' type to something sensible. */
11172 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11174 = objfile_type (objfile
)->nodebug_data_symbol
;
11176 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11177 /* In the case of DW_TAG_member, we should only be called for
11178 static const members. */
11179 if (die
->tag
== DW_TAG_member
)
11181 /* dwarf2_add_field uses die_is_declaration,
11182 so we do the same. */
11183 gdb_assert (die_is_declaration (die
, cu
));
11188 dwarf2_const_value (attr
, sym
, cu
);
11189 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11192 if (attr2
&& (DW_UNSND (attr2
) != 0))
11193 list_to_add
= &global_symbols
;
11195 list_to_add
= cu
->list_in_scope
;
11199 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11202 var_decode_location (attr
, sym
, cu
);
11203 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11204 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11205 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11206 && !dwarf2_per_objfile
->has_section_at_zero
)
11208 /* When a static variable is eliminated by the linker,
11209 the corresponding debug information is not stripped
11210 out, but the variable address is set to null;
11211 do not add such variables into symbol table. */
11213 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11215 /* Workaround gfortran PR debug/40040 - it uses
11216 DW_AT_location for variables in -fPIC libraries which may
11217 get overriden by other libraries/executable and get
11218 a different address. Resolve it by the minimal symbol
11219 which may come from inferior's executable using copy
11220 relocation. Make this workaround only for gfortran as for
11221 other compilers GDB cannot guess the minimal symbol
11222 Fortran mangling kind. */
11223 if (cu
->language
== language_fortran
&& die
->parent
11224 && die
->parent
->tag
== DW_TAG_module
11226 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11227 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11229 /* A variable with DW_AT_external is never static,
11230 but it may be block-scoped. */
11231 list_to_add
= (cu
->list_in_scope
== &file_symbols
11232 ? &global_symbols
: cu
->list_in_scope
);
11235 list_to_add
= cu
->list_in_scope
;
11239 /* We do not know the address of this symbol.
11240 If it is an external symbol and we have type information
11241 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11242 The address of the variable will then be determined from
11243 the minimal symbol table whenever the variable is
11245 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11246 if (attr2
&& (DW_UNSND (attr2
) != 0)
11247 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11249 /* A variable with DW_AT_external is never static, but it
11250 may be block-scoped. */
11251 list_to_add
= (cu
->list_in_scope
== &file_symbols
11252 ? &global_symbols
: cu
->list_in_scope
);
11254 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11256 else if (!die_is_declaration (die
, cu
))
11258 /* Use the default LOC_OPTIMIZED_OUT class. */
11259 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11261 list_to_add
= cu
->list_in_scope
;
11265 case DW_TAG_formal_parameter
:
11266 /* If we are inside a function, mark this as an argument. If
11267 not, we might be looking at an argument to an inlined function
11268 when we do not have enough information to show inlined frames;
11269 pretend it's a local variable in that case so that the user can
11271 if (context_stack_depth
> 0
11272 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11273 SYMBOL_IS_ARGUMENT (sym
) = 1;
11274 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11277 var_decode_location (attr
, sym
, cu
);
11279 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11282 dwarf2_const_value (attr
, sym
, cu
);
11284 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
11285 if (attr
&& DW_UNSND (attr
))
11287 struct type
*ref_type
;
11289 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
11290 SYMBOL_TYPE (sym
) = ref_type
;
11293 list_to_add
= cu
->list_in_scope
;
11295 case DW_TAG_unspecified_parameters
:
11296 /* From varargs functions; gdb doesn't seem to have any
11297 interest in this information, so just ignore it for now.
11300 case DW_TAG_template_type_param
:
11302 /* Fall through. */
11303 case DW_TAG_class_type
:
11304 case DW_TAG_interface_type
:
11305 case DW_TAG_structure_type
:
11306 case DW_TAG_union_type
:
11307 case DW_TAG_set_type
:
11308 case DW_TAG_enumeration_type
:
11309 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11310 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11313 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11314 really ever be static objects: otherwise, if you try
11315 to, say, break of a class's method and you're in a file
11316 which doesn't mention that class, it won't work unless
11317 the check for all static symbols in lookup_symbol_aux
11318 saves you. See the OtherFileClass tests in
11319 gdb.c++/namespace.exp. */
11323 list_to_add
= (cu
->list_in_scope
== &file_symbols
11324 && (cu
->language
== language_cplus
11325 || cu
->language
== language_java
)
11326 ? &global_symbols
: cu
->list_in_scope
);
11328 /* The semantics of C++ state that "struct foo {
11329 ... }" also defines a typedef for "foo". A Java
11330 class declaration also defines a typedef for the
11332 if (cu
->language
== language_cplus
11333 || cu
->language
== language_java
11334 || cu
->language
== language_ada
)
11336 /* The symbol's name is already allocated along
11337 with this objfile, so we don't need to
11338 duplicate it for the type. */
11339 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11340 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11345 case DW_TAG_typedef
:
11346 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11347 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11348 list_to_add
= cu
->list_in_scope
;
11350 case DW_TAG_base_type
:
11351 case DW_TAG_subrange_type
:
11352 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11353 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11354 list_to_add
= cu
->list_in_scope
;
11356 case DW_TAG_enumerator
:
11357 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11360 dwarf2_const_value (attr
, sym
, cu
);
11363 /* NOTE: carlton/2003-11-10: See comment above in the
11364 DW_TAG_class_type, etc. block. */
11366 list_to_add
= (cu
->list_in_scope
== &file_symbols
11367 && (cu
->language
== language_cplus
11368 || cu
->language
== language_java
)
11369 ? &global_symbols
: cu
->list_in_scope
);
11372 case DW_TAG_namespace
:
11373 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11374 list_to_add
= &global_symbols
;
11377 /* Not a tag we recognize. Hopefully we aren't processing
11378 trash data, but since we must specifically ignore things
11379 we don't recognize, there is nothing else we should do at
11381 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11382 dwarf_tag_name (die
->tag
));
11388 sym
->hash_next
= objfile
->template_symbols
;
11389 objfile
->template_symbols
= sym
;
11390 list_to_add
= NULL
;
11393 if (list_to_add
!= NULL
)
11394 add_symbol_to_list (sym
, list_to_add
);
11396 /* For the benefit of old versions of GCC, check for anonymous
11397 namespaces based on the demangled name. */
11398 if (!processing_has_namespace_info
11399 && cu
->language
== language_cplus
)
11400 cp_scan_for_anonymous_namespaces (sym
);
11405 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11407 static struct symbol
*
11408 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11410 return new_symbol_full (die
, type
, cu
, NULL
);
11413 /* Given an attr with a DW_FORM_dataN value in host byte order,
11414 zero-extend it as appropriate for the symbol's type. The DWARF
11415 standard (v4) is not entirely clear about the meaning of using
11416 DW_FORM_dataN for a constant with a signed type, where the type is
11417 wider than the data. The conclusion of a discussion on the DWARF
11418 list was that this is unspecified. We choose to always zero-extend
11419 because that is the interpretation long in use by GCC. */
11422 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11423 const char *name
, struct obstack
*obstack
,
11424 struct dwarf2_cu
*cu
, long *value
, int bits
)
11426 struct objfile
*objfile
= cu
->objfile
;
11427 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11428 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11429 LONGEST l
= DW_UNSND (attr
);
11431 if (bits
< sizeof (*value
) * 8)
11433 l
&= ((LONGEST
) 1 << bits
) - 1;
11436 else if (bits
== sizeof (*value
) * 8)
11440 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11441 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11448 /* Read a constant value from an attribute. Either set *VALUE, or if
11449 the value does not fit in *VALUE, set *BYTES - either already
11450 allocated on the objfile obstack, or newly allocated on OBSTACK,
11451 or, set *BATON, if we translated the constant to a location
11455 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11456 const char *name
, struct obstack
*obstack
,
11457 struct dwarf2_cu
*cu
,
11458 long *value
, gdb_byte
**bytes
,
11459 struct dwarf2_locexpr_baton
**baton
)
11461 struct objfile
*objfile
= cu
->objfile
;
11462 struct comp_unit_head
*cu_header
= &cu
->header
;
11463 struct dwarf_block
*blk
;
11464 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
11465 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
11471 switch (attr
->form
)
11477 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
11478 dwarf2_const_value_length_mismatch_complaint (name
,
11479 cu_header
->addr_size
,
11480 TYPE_LENGTH (type
));
11481 /* Symbols of this form are reasonably rare, so we just
11482 piggyback on the existing location code rather than writing
11483 a new implementation of symbol_computed_ops. */
11484 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11485 sizeof (struct dwarf2_locexpr_baton
));
11486 (*baton
)->per_cu
= cu
->per_cu
;
11487 gdb_assert ((*baton
)->per_cu
);
11489 (*baton
)->size
= 2 + cu_header
->addr_size
;
11490 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11491 (*baton
)->data
= data
;
11493 data
[0] = DW_OP_addr
;
11494 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11495 byte_order
, DW_ADDR (attr
));
11496 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11499 case DW_FORM_string
:
11501 /* DW_STRING is already allocated on the objfile obstack, point
11503 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11505 case DW_FORM_block1
:
11506 case DW_FORM_block2
:
11507 case DW_FORM_block4
:
11508 case DW_FORM_block
:
11509 case DW_FORM_exprloc
:
11510 blk
= DW_BLOCK (attr
);
11511 if (TYPE_LENGTH (type
) != blk
->size
)
11512 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11513 TYPE_LENGTH (type
));
11514 *bytes
= blk
->data
;
11517 /* The DW_AT_const_value attributes are supposed to carry the
11518 symbol's value "represented as it would be on the target
11519 architecture." By the time we get here, it's already been
11520 converted to host endianness, so we just need to sign- or
11521 zero-extend it as appropriate. */
11522 case DW_FORM_data1
:
11523 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11524 obstack
, cu
, value
, 8);
11526 case DW_FORM_data2
:
11527 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11528 obstack
, cu
, value
, 16);
11530 case DW_FORM_data4
:
11531 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11532 obstack
, cu
, value
, 32);
11534 case DW_FORM_data8
:
11535 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11536 obstack
, cu
, value
, 64);
11539 case DW_FORM_sdata
:
11540 *value
= DW_SND (attr
);
11543 case DW_FORM_udata
:
11544 *value
= DW_UNSND (attr
);
11548 complaint (&symfile_complaints
,
11549 _("unsupported const value attribute form: '%s'"),
11550 dwarf_form_name (attr
->form
));
11557 /* Copy constant value from an attribute to a symbol. */
11560 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11561 struct dwarf2_cu
*cu
)
11563 struct objfile
*objfile
= cu
->objfile
;
11564 struct comp_unit_head
*cu_header
= &cu
->header
;
11567 struct dwarf2_locexpr_baton
*baton
;
11569 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11570 SYMBOL_PRINT_NAME (sym
),
11571 &objfile
->objfile_obstack
, cu
,
11572 &value
, &bytes
, &baton
);
11576 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11577 SYMBOL_LOCATION_BATON (sym
) = baton
;
11578 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11580 else if (bytes
!= NULL
)
11582 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11583 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11587 SYMBOL_VALUE (sym
) = value
;
11588 SYMBOL_CLASS (sym
) = LOC_CONST
;
11592 /* Return the type of the die in question using its DW_AT_type attribute. */
11594 static struct type
*
11595 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11597 struct attribute
*type_attr
;
11599 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11602 /* A missing DW_AT_type represents a void type. */
11603 return objfile_type (cu
->objfile
)->builtin_void
;
11606 return lookup_die_type (die
, type_attr
, cu
);
11609 /* True iff CU's producer generates GNAT Ada auxiliary information
11610 that allows to find parallel types through that information instead
11611 of having to do expensive parallel lookups by type name. */
11614 need_gnat_info (struct dwarf2_cu
*cu
)
11616 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11617 of GNAT produces this auxiliary information, without any indication
11618 that it is produced. Part of enhancing the FSF version of GNAT
11619 to produce that information will be to put in place an indicator
11620 that we can use in order to determine whether the descriptive type
11621 info is available or not. One suggestion that has been made is
11622 to use a new attribute, attached to the CU die. For now, assume
11623 that the descriptive type info is not available. */
11627 /* Return the auxiliary type of the die in question using its
11628 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11629 attribute is not present. */
11631 static struct type
*
11632 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11634 struct attribute
*type_attr
;
11636 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11640 return lookup_die_type (die
, type_attr
, cu
);
11643 /* If DIE has a descriptive_type attribute, then set the TYPE's
11644 descriptive type accordingly. */
11647 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11648 struct dwarf2_cu
*cu
)
11650 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11652 if (descriptive_type
)
11654 ALLOCATE_GNAT_AUX_TYPE (type
);
11655 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11659 /* Return the containing type of the die in question using its
11660 DW_AT_containing_type attribute. */
11662 static struct type
*
11663 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11665 struct attribute
*type_attr
;
11667 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11669 error (_("Dwarf Error: Problem turning containing type into gdb type "
11670 "[in module %s]"), cu
->objfile
->name
);
11672 return lookup_die_type (die
, type_attr
, cu
);
11675 /* Look up the type of DIE in CU using its type attribute ATTR.
11676 If there is no type substitute an error marker. */
11678 static struct type
*
11679 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11680 struct dwarf2_cu
*cu
)
11682 struct type
*this_type
;
11684 /* First see if we have it cached. */
11686 if (is_ref_attr (attr
))
11688 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11690 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11692 else if (attr
->form
== DW_FORM_ref_sig8
)
11694 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11695 struct dwarf2_cu
*sig_cu
;
11696 unsigned int offset
;
11698 /* sig_type will be NULL if the signatured type is missing from
11700 if (sig_type
== NULL
)
11701 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11702 "at 0x%x [in module %s]"),
11703 die
->offset
, cu
->objfile
->name
);
11705 gdb_assert (sig_type
->per_cu
.from_debug_types
);
11706 offset
= sig_type
->offset
+ sig_type
->type_offset
;
11707 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11711 dump_die_for_error (die
);
11712 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11713 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11716 /* If not cached we need to read it in. */
11718 if (this_type
== NULL
)
11720 struct die_info
*type_die
;
11721 struct dwarf2_cu
*type_cu
= cu
;
11723 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11724 /* If the type is cached, we should have found it above. */
11725 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
11726 this_type
= read_type_die_1 (type_die
, type_cu
);
11729 /* If we still don't have a type use an error marker. */
11731 if (this_type
== NULL
)
11733 char *message
, *saved
;
11735 /* read_type_die already issued a complaint. */
11736 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11740 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
11741 message
, strlen (message
));
11744 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
11750 /* Return the type in DIE, CU.
11751 Returns NULL for invalid types.
11753 This first does a lookup in the appropriate type_hash table,
11754 and only reads the die in if necessary.
11756 NOTE: This can be called when reading in partial or full symbols. */
11758 static struct type
*
11759 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11761 struct type
*this_type
;
11763 this_type
= get_die_type (die
, cu
);
11767 return read_type_die_1 (die
, cu
);
11770 /* Read the type in DIE, CU.
11771 Returns NULL for invalid types. */
11773 static struct type
*
11774 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
11776 struct type
*this_type
= NULL
;
11780 case DW_TAG_class_type
:
11781 case DW_TAG_interface_type
:
11782 case DW_TAG_structure_type
:
11783 case DW_TAG_union_type
:
11784 this_type
= read_structure_type (die
, cu
);
11786 case DW_TAG_enumeration_type
:
11787 this_type
= read_enumeration_type (die
, cu
);
11789 case DW_TAG_subprogram
:
11790 case DW_TAG_subroutine_type
:
11791 case DW_TAG_inlined_subroutine
:
11792 this_type
= read_subroutine_type (die
, cu
);
11794 case DW_TAG_array_type
:
11795 this_type
= read_array_type (die
, cu
);
11797 case DW_TAG_set_type
:
11798 this_type
= read_set_type (die
, cu
);
11800 case DW_TAG_pointer_type
:
11801 this_type
= read_tag_pointer_type (die
, cu
);
11803 case DW_TAG_ptr_to_member_type
:
11804 this_type
= read_tag_ptr_to_member_type (die
, cu
);
11806 case DW_TAG_reference_type
:
11807 this_type
= read_tag_reference_type (die
, cu
);
11809 case DW_TAG_const_type
:
11810 this_type
= read_tag_const_type (die
, cu
);
11812 case DW_TAG_volatile_type
:
11813 this_type
= read_tag_volatile_type (die
, cu
);
11815 case DW_TAG_string_type
:
11816 this_type
= read_tag_string_type (die
, cu
);
11818 case DW_TAG_typedef
:
11819 this_type
= read_typedef (die
, cu
);
11821 case DW_TAG_subrange_type
:
11822 this_type
= read_subrange_type (die
, cu
);
11824 case DW_TAG_base_type
:
11825 this_type
= read_base_type (die
, cu
);
11827 case DW_TAG_unspecified_type
:
11828 this_type
= read_unspecified_type (die
, cu
);
11830 case DW_TAG_namespace
:
11831 this_type
= read_namespace_type (die
, cu
);
11833 case DW_TAG_module
:
11834 this_type
= read_module_type (die
, cu
);
11837 complaint (&symfile_complaints
,
11838 _("unexpected tag in read_type_die: '%s'"),
11839 dwarf_tag_name (die
->tag
));
11846 /* See if we can figure out if the class lives in a namespace. We do
11847 this by looking for a member function; its demangled name will
11848 contain namespace info, if there is any.
11849 Return the computed name or NULL.
11850 Space for the result is allocated on the objfile's obstack.
11851 This is the full-die version of guess_partial_die_structure_name.
11852 In this case we know DIE has no useful parent. */
11855 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11857 struct die_info
*spec_die
;
11858 struct dwarf2_cu
*spec_cu
;
11859 struct die_info
*child
;
11862 spec_die
= die_specification (die
, &spec_cu
);
11863 if (spec_die
!= NULL
)
11869 for (child
= die
->child
;
11871 child
= child
->sibling
)
11873 if (child
->tag
== DW_TAG_subprogram
)
11875 struct attribute
*attr
;
11877 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
11879 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
11883 = language_class_name_from_physname (cu
->language_defn
,
11887 if (actual_name
!= NULL
)
11889 char *die_name
= dwarf2_name (die
, cu
);
11891 if (die_name
!= NULL
11892 && strcmp (die_name
, actual_name
) != 0)
11894 /* Strip off the class name from the full name.
11895 We want the prefix. */
11896 int die_name_len
= strlen (die_name
);
11897 int actual_name_len
= strlen (actual_name
);
11899 /* Test for '::' as a sanity check. */
11900 if (actual_name_len
> die_name_len
+ 2
11901 && actual_name
[actual_name_len
11902 - die_name_len
- 1] == ':')
11904 obsavestring (actual_name
,
11905 actual_name_len
- die_name_len
- 2,
11906 &cu
->objfile
->objfile_obstack
);
11909 xfree (actual_name
);
11918 /* Return the name of the namespace/class that DIE is defined within,
11919 or "" if we can't tell. The caller should not xfree the result.
11921 For example, if we're within the method foo() in the following
11931 then determine_prefix on foo's die will return "N::C". */
11934 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
11936 struct die_info
*parent
, *spec_die
;
11937 struct dwarf2_cu
*spec_cu
;
11938 struct type
*parent_type
;
11940 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
11941 && cu
->language
!= language_fortran
)
11944 /* We have to be careful in the presence of DW_AT_specification.
11945 For example, with GCC 3.4, given the code
11949 // Definition of N::foo.
11953 then we'll have a tree of DIEs like this:
11955 1: DW_TAG_compile_unit
11956 2: DW_TAG_namespace // N
11957 3: DW_TAG_subprogram // declaration of N::foo
11958 4: DW_TAG_subprogram // definition of N::foo
11959 DW_AT_specification // refers to die #3
11961 Thus, when processing die #4, we have to pretend that we're in
11962 the context of its DW_AT_specification, namely the contex of die
11965 spec_die
= die_specification (die
, &spec_cu
);
11966 if (spec_die
== NULL
)
11967 parent
= die
->parent
;
11970 parent
= spec_die
->parent
;
11974 if (parent
== NULL
)
11976 else if (parent
->building_fullname
)
11979 const char *parent_name
;
11981 /* It has been seen on RealView 2.2 built binaries,
11982 DW_TAG_template_type_param types actually _defined_ as
11983 children of the parent class:
11986 template class <class Enum> Class{};
11987 Class<enum E> class_e;
11989 1: DW_TAG_class_type (Class)
11990 2: DW_TAG_enumeration_type (E)
11991 3: DW_TAG_enumerator (enum1:0)
11992 3: DW_TAG_enumerator (enum2:1)
11994 2: DW_TAG_template_type_param
11995 DW_AT_type DW_FORM_ref_udata (E)
11997 Besides being broken debug info, it can put GDB into an
11998 infinite loop. Consider:
12000 When we're building the full name for Class<E>, we'll start
12001 at Class, and go look over its template type parameters,
12002 finding E. We'll then try to build the full name of E, and
12003 reach here. We're now trying to build the full name of E,
12004 and look over the parent DIE for containing scope. In the
12005 broken case, if we followed the parent DIE of E, we'd again
12006 find Class, and once again go look at its template type
12007 arguments, etc., etc. Simply don't consider such parent die
12008 as source-level parent of this die (it can't be, the language
12009 doesn't allow it), and break the loop here. */
12010 name
= dwarf2_name (die
, cu
);
12011 parent_name
= dwarf2_name (parent
, cu
);
12012 complaint (&symfile_complaints
,
12013 _("template param type '%s' defined within parent '%s'"),
12014 name
? name
: "<unknown>",
12015 parent_name
? parent_name
: "<unknown>");
12019 switch (parent
->tag
)
12021 case DW_TAG_namespace
:
12022 parent_type
= read_type_die (parent
, cu
);
12023 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12024 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12025 Work around this problem here. */
12026 if (cu
->language
== language_cplus
12027 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12029 /* We give a name to even anonymous namespaces. */
12030 return TYPE_TAG_NAME (parent_type
);
12031 case DW_TAG_class_type
:
12032 case DW_TAG_interface_type
:
12033 case DW_TAG_structure_type
:
12034 case DW_TAG_union_type
:
12035 case DW_TAG_module
:
12036 parent_type
= read_type_die (parent
, cu
);
12037 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12038 return TYPE_TAG_NAME (parent_type
);
12040 /* An anonymous structure is only allowed non-static data
12041 members; no typedefs, no member functions, et cetera.
12042 So it does not need a prefix. */
12044 case DW_TAG_compile_unit
:
12045 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12046 if (cu
->language
== language_cplus
12047 && dwarf2_per_objfile
->types
.asection
!= NULL
12048 && die
->child
!= NULL
12049 && (die
->tag
== DW_TAG_class_type
12050 || die
->tag
== DW_TAG_structure_type
12051 || die
->tag
== DW_TAG_union_type
))
12053 char *name
= guess_full_die_structure_name (die
, cu
);
12059 return determine_prefix (parent
, cu
);
12063 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12064 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12065 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12066 an obconcat, otherwise allocate storage for the result. The CU argument is
12067 used to determine the language and hence, the appropriate separator. */
12069 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12072 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12073 int physname
, struct dwarf2_cu
*cu
)
12075 const char *lead
= "";
12078 if (suffix
== NULL
|| suffix
[0] == '\0'
12079 || prefix
== NULL
|| prefix
[0] == '\0')
12081 else if (cu
->language
== language_java
)
12083 else if (cu
->language
== language_fortran
&& physname
)
12085 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12086 DW_AT_MIPS_linkage_name is preferred and used instead. */
12094 if (prefix
== NULL
)
12096 if (suffix
== NULL
)
12102 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12104 strcpy (retval
, lead
);
12105 strcat (retval
, prefix
);
12106 strcat (retval
, sep
);
12107 strcat (retval
, suffix
);
12112 /* We have an obstack. */
12113 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12117 /* Return sibling of die, NULL if no sibling. */
12119 static struct die_info
*
12120 sibling_die (struct die_info
*die
)
12122 return die
->sibling
;
12125 /* Get name of a die, return NULL if not found. */
12128 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12129 struct obstack
*obstack
)
12131 if (name
&& cu
->language
== language_cplus
)
12133 char *canon_name
= cp_canonicalize_string (name
);
12135 if (canon_name
!= NULL
)
12137 if (strcmp (canon_name
, name
) != 0)
12138 name
= obsavestring (canon_name
, strlen (canon_name
),
12140 xfree (canon_name
);
12147 /* Get name of a die, return NULL if not found. */
12150 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12152 struct attribute
*attr
;
12154 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12155 if ((!attr
|| !DW_STRING (attr
))
12156 && die
->tag
!= DW_TAG_class_type
12157 && die
->tag
!= DW_TAG_interface_type
12158 && die
->tag
!= DW_TAG_structure_type
12159 && die
->tag
!= DW_TAG_union_type
)
12164 case DW_TAG_compile_unit
:
12165 /* Compilation units have a DW_AT_name that is a filename, not
12166 a source language identifier. */
12167 case DW_TAG_enumeration_type
:
12168 case DW_TAG_enumerator
:
12169 /* These tags always have simple identifiers already; no need
12170 to canonicalize them. */
12171 return DW_STRING (attr
);
12173 case DW_TAG_subprogram
:
12174 /* Java constructors will all be named "<init>", so return
12175 the class name when we see this special case. */
12176 if (cu
->language
== language_java
12177 && DW_STRING (attr
) != NULL
12178 && strcmp (DW_STRING (attr
), "<init>") == 0)
12180 struct dwarf2_cu
*spec_cu
= cu
;
12181 struct die_info
*spec_die
;
12183 /* GCJ will output '<init>' for Java constructor names.
12184 For this special case, return the name of the parent class. */
12186 /* GCJ may output suprogram DIEs with AT_specification set.
12187 If so, use the name of the specified DIE. */
12188 spec_die
= die_specification (die
, &spec_cu
);
12189 if (spec_die
!= NULL
)
12190 return dwarf2_name (spec_die
, spec_cu
);
12195 if (die
->tag
== DW_TAG_class_type
)
12196 return dwarf2_name (die
, cu
);
12198 while (die
->tag
!= DW_TAG_compile_unit
);
12202 case DW_TAG_class_type
:
12203 case DW_TAG_interface_type
:
12204 case DW_TAG_structure_type
:
12205 case DW_TAG_union_type
:
12206 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12207 structures or unions. These were of the form "._%d" in GCC 4.1,
12208 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12209 and GCC 4.4. We work around this problem by ignoring these. */
12210 if (attr
&& DW_STRING (attr
)
12211 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12212 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12215 /* GCC might emit a nameless typedef that has a linkage name. See
12216 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12217 if (!attr
|| DW_STRING (attr
) == NULL
)
12219 char *demangled
= NULL
;
12221 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12223 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12225 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12228 /* Avoid demangling DW_STRING (attr) the second time on a second
12229 call for the same DIE. */
12230 if (!DW_STRING_IS_CANONICAL (attr
))
12231 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12235 /* FIXME: we already did this for the partial symbol... */
12237 = obsavestring (demangled
, strlen (demangled
),
12238 &cu
->objfile
->objfile_obstack
);
12239 DW_STRING_IS_CANONICAL (attr
) = 1;
12249 if (!DW_STRING_IS_CANONICAL (attr
))
12252 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12253 &cu
->objfile
->objfile_obstack
);
12254 DW_STRING_IS_CANONICAL (attr
) = 1;
12256 return DW_STRING (attr
);
12259 /* Return the die that this die in an extension of, or NULL if there
12260 is none. *EXT_CU is the CU containing DIE on input, and the CU
12261 containing the return value on output. */
12263 static struct die_info
*
12264 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12266 struct attribute
*attr
;
12268 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12272 return follow_die_ref (die
, attr
, ext_cu
);
12275 /* Convert a DIE tag into its string name. */
12278 dwarf_tag_name (unsigned tag
)
12282 case DW_TAG_padding
:
12283 return "DW_TAG_padding";
12284 case DW_TAG_array_type
:
12285 return "DW_TAG_array_type";
12286 case DW_TAG_class_type
:
12287 return "DW_TAG_class_type";
12288 case DW_TAG_entry_point
:
12289 return "DW_TAG_entry_point";
12290 case DW_TAG_enumeration_type
:
12291 return "DW_TAG_enumeration_type";
12292 case DW_TAG_formal_parameter
:
12293 return "DW_TAG_formal_parameter";
12294 case DW_TAG_imported_declaration
:
12295 return "DW_TAG_imported_declaration";
12297 return "DW_TAG_label";
12298 case DW_TAG_lexical_block
:
12299 return "DW_TAG_lexical_block";
12300 case DW_TAG_member
:
12301 return "DW_TAG_member";
12302 case DW_TAG_pointer_type
:
12303 return "DW_TAG_pointer_type";
12304 case DW_TAG_reference_type
:
12305 return "DW_TAG_reference_type";
12306 case DW_TAG_compile_unit
:
12307 return "DW_TAG_compile_unit";
12308 case DW_TAG_string_type
:
12309 return "DW_TAG_string_type";
12310 case DW_TAG_structure_type
:
12311 return "DW_TAG_structure_type";
12312 case DW_TAG_subroutine_type
:
12313 return "DW_TAG_subroutine_type";
12314 case DW_TAG_typedef
:
12315 return "DW_TAG_typedef";
12316 case DW_TAG_union_type
:
12317 return "DW_TAG_union_type";
12318 case DW_TAG_unspecified_parameters
:
12319 return "DW_TAG_unspecified_parameters";
12320 case DW_TAG_variant
:
12321 return "DW_TAG_variant";
12322 case DW_TAG_common_block
:
12323 return "DW_TAG_common_block";
12324 case DW_TAG_common_inclusion
:
12325 return "DW_TAG_common_inclusion";
12326 case DW_TAG_inheritance
:
12327 return "DW_TAG_inheritance";
12328 case DW_TAG_inlined_subroutine
:
12329 return "DW_TAG_inlined_subroutine";
12330 case DW_TAG_module
:
12331 return "DW_TAG_module";
12332 case DW_TAG_ptr_to_member_type
:
12333 return "DW_TAG_ptr_to_member_type";
12334 case DW_TAG_set_type
:
12335 return "DW_TAG_set_type";
12336 case DW_TAG_subrange_type
:
12337 return "DW_TAG_subrange_type";
12338 case DW_TAG_with_stmt
:
12339 return "DW_TAG_with_stmt";
12340 case DW_TAG_access_declaration
:
12341 return "DW_TAG_access_declaration";
12342 case DW_TAG_base_type
:
12343 return "DW_TAG_base_type";
12344 case DW_TAG_catch_block
:
12345 return "DW_TAG_catch_block";
12346 case DW_TAG_const_type
:
12347 return "DW_TAG_const_type";
12348 case DW_TAG_constant
:
12349 return "DW_TAG_constant";
12350 case DW_TAG_enumerator
:
12351 return "DW_TAG_enumerator";
12352 case DW_TAG_file_type
:
12353 return "DW_TAG_file_type";
12354 case DW_TAG_friend
:
12355 return "DW_TAG_friend";
12356 case DW_TAG_namelist
:
12357 return "DW_TAG_namelist";
12358 case DW_TAG_namelist_item
:
12359 return "DW_TAG_namelist_item";
12360 case DW_TAG_packed_type
:
12361 return "DW_TAG_packed_type";
12362 case DW_TAG_subprogram
:
12363 return "DW_TAG_subprogram";
12364 case DW_TAG_template_type_param
:
12365 return "DW_TAG_template_type_param";
12366 case DW_TAG_template_value_param
:
12367 return "DW_TAG_template_value_param";
12368 case DW_TAG_thrown_type
:
12369 return "DW_TAG_thrown_type";
12370 case DW_TAG_try_block
:
12371 return "DW_TAG_try_block";
12372 case DW_TAG_variant_part
:
12373 return "DW_TAG_variant_part";
12374 case DW_TAG_variable
:
12375 return "DW_TAG_variable";
12376 case DW_TAG_volatile_type
:
12377 return "DW_TAG_volatile_type";
12378 case DW_TAG_dwarf_procedure
:
12379 return "DW_TAG_dwarf_procedure";
12380 case DW_TAG_restrict_type
:
12381 return "DW_TAG_restrict_type";
12382 case DW_TAG_interface_type
:
12383 return "DW_TAG_interface_type";
12384 case DW_TAG_namespace
:
12385 return "DW_TAG_namespace";
12386 case DW_TAG_imported_module
:
12387 return "DW_TAG_imported_module";
12388 case DW_TAG_unspecified_type
:
12389 return "DW_TAG_unspecified_type";
12390 case DW_TAG_partial_unit
:
12391 return "DW_TAG_partial_unit";
12392 case DW_TAG_imported_unit
:
12393 return "DW_TAG_imported_unit";
12394 case DW_TAG_condition
:
12395 return "DW_TAG_condition";
12396 case DW_TAG_shared_type
:
12397 return "DW_TAG_shared_type";
12398 case DW_TAG_type_unit
:
12399 return "DW_TAG_type_unit";
12400 case DW_TAG_MIPS_loop
:
12401 return "DW_TAG_MIPS_loop";
12402 case DW_TAG_HP_array_descriptor
:
12403 return "DW_TAG_HP_array_descriptor";
12404 case DW_TAG_format_label
:
12405 return "DW_TAG_format_label";
12406 case DW_TAG_function_template
:
12407 return "DW_TAG_function_template";
12408 case DW_TAG_class_template
:
12409 return "DW_TAG_class_template";
12410 case DW_TAG_GNU_BINCL
:
12411 return "DW_TAG_GNU_BINCL";
12412 case DW_TAG_GNU_EINCL
:
12413 return "DW_TAG_GNU_EINCL";
12414 case DW_TAG_upc_shared_type
:
12415 return "DW_TAG_upc_shared_type";
12416 case DW_TAG_upc_strict_type
:
12417 return "DW_TAG_upc_strict_type";
12418 case DW_TAG_upc_relaxed_type
:
12419 return "DW_TAG_upc_relaxed_type";
12420 case DW_TAG_PGI_kanji_type
:
12421 return "DW_TAG_PGI_kanji_type";
12422 case DW_TAG_PGI_interface_block
:
12423 return "DW_TAG_PGI_interface_block";
12425 return "DW_TAG_<unknown>";
12429 /* Convert a DWARF attribute code into its string name. */
12432 dwarf_attr_name (unsigned attr
)
12436 case DW_AT_sibling
:
12437 return "DW_AT_sibling";
12438 case DW_AT_location
:
12439 return "DW_AT_location";
12441 return "DW_AT_name";
12442 case DW_AT_ordering
:
12443 return "DW_AT_ordering";
12444 case DW_AT_subscr_data
:
12445 return "DW_AT_subscr_data";
12446 case DW_AT_byte_size
:
12447 return "DW_AT_byte_size";
12448 case DW_AT_bit_offset
:
12449 return "DW_AT_bit_offset";
12450 case DW_AT_bit_size
:
12451 return "DW_AT_bit_size";
12452 case DW_AT_element_list
:
12453 return "DW_AT_element_list";
12454 case DW_AT_stmt_list
:
12455 return "DW_AT_stmt_list";
12457 return "DW_AT_low_pc";
12458 case DW_AT_high_pc
:
12459 return "DW_AT_high_pc";
12460 case DW_AT_language
:
12461 return "DW_AT_language";
12463 return "DW_AT_member";
12465 return "DW_AT_discr";
12466 case DW_AT_discr_value
:
12467 return "DW_AT_discr_value";
12468 case DW_AT_visibility
:
12469 return "DW_AT_visibility";
12471 return "DW_AT_import";
12472 case DW_AT_string_length
:
12473 return "DW_AT_string_length";
12474 case DW_AT_common_reference
:
12475 return "DW_AT_common_reference";
12476 case DW_AT_comp_dir
:
12477 return "DW_AT_comp_dir";
12478 case DW_AT_const_value
:
12479 return "DW_AT_const_value";
12480 case DW_AT_containing_type
:
12481 return "DW_AT_containing_type";
12482 case DW_AT_default_value
:
12483 return "DW_AT_default_value";
12485 return "DW_AT_inline";
12486 case DW_AT_is_optional
:
12487 return "DW_AT_is_optional";
12488 case DW_AT_lower_bound
:
12489 return "DW_AT_lower_bound";
12490 case DW_AT_producer
:
12491 return "DW_AT_producer";
12492 case DW_AT_prototyped
:
12493 return "DW_AT_prototyped";
12494 case DW_AT_return_addr
:
12495 return "DW_AT_return_addr";
12496 case DW_AT_start_scope
:
12497 return "DW_AT_start_scope";
12498 case DW_AT_bit_stride
:
12499 return "DW_AT_bit_stride";
12500 case DW_AT_upper_bound
:
12501 return "DW_AT_upper_bound";
12502 case DW_AT_abstract_origin
:
12503 return "DW_AT_abstract_origin";
12504 case DW_AT_accessibility
:
12505 return "DW_AT_accessibility";
12506 case DW_AT_address_class
:
12507 return "DW_AT_address_class";
12508 case DW_AT_artificial
:
12509 return "DW_AT_artificial";
12510 case DW_AT_base_types
:
12511 return "DW_AT_base_types";
12512 case DW_AT_calling_convention
:
12513 return "DW_AT_calling_convention";
12515 return "DW_AT_count";
12516 case DW_AT_data_member_location
:
12517 return "DW_AT_data_member_location";
12518 case DW_AT_decl_column
:
12519 return "DW_AT_decl_column";
12520 case DW_AT_decl_file
:
12521 return "DW_AT_decl_file";
12522 case DW_AT_decl_line
:
12523 return "DW_AT_decl_line";
12524 case DW_AT_declaration
:
12525 return "DW_AT_declaration";
12526 case DW_AT_discr_list
:
12527 return "DW_AT_discr_list";
12528 case DW_AT_encoding
:
12529 return "DW_AT_encoding";
12530 case DW_AT_external
:
12531 return "DW_AT_external";
12532 case DW_AT_frame_base
:
12533 return "DW_AT_frame_base";
12535 return "DW_AT_friend";
12536 case DW_AT_identifier_case
:
12537 return "DW_AT_identifier_case";
12538 case DW_AT_macro_info
:
12539 return "DW_AT_macro_info";
12540 case DW_AT_namelist_items
:
12541 return "DW_AT_namelist_items";
12542 case DW_AT_priority
:
12543 return "DW_AT_priority";
12544 case DW_AT_segment
:
12545 return "DW_AT_segment";
12546 case DW_AT_specification
:
12547 return "DW_AT_specification";
12548 case DW_AT_static_link
:
12549 return "DW_AT_static_link";
12551 return "DW_AT_type";
12552 case DW_AT_use_location
:
12553 return "DW_AT_use_location";
12554 case DW_AT_variable_parameter
:
12555 return "DW_AT_variable_parameter";
12556 case DW_AT_virtuality
:
12557 return "DW_AT_virtuality";
12558 case DW_AT_vtable_elem_location
:
12559 return "DW_AT_vtable_elem_location";
12560 /* DWARF 3 values. */
12561 case DW_AT_allocated
:
12562 return "DW_AT_allocated";
12563 case DW_AT_associated
:
12564 return "DW_AT_associated";
12565 case DW_AT_data_location
:
12566 return "DW_AT_data_location";
12567 case DW_AT_byte_stride
:
12568 return "DW_AT_byte_stride";
12569 case DW_AT_entry_pc
:
12570 return "DW_AT_entry_pc";
12571 case DW_AT_use_UTF8
:
12572 return "DW_AT_use_UTF8";
12573 case DW_AT_extension
:
12574 return "DW_AT_extension";
12576 return "DW_AT_ranges";
12577 case DW_AT_trampoline
:
12578 return "DW_AT_trampoline";
12579 case DW_AT_call_column
:
12580 return "DW_AT_call_column";
12581 case DW_AT_call_file
:
12582 return "DW_AT_call_file";
12583 case DW_AT_call_line
:
12584 return "DW_AT_call_line";
12585 case DW_AT_description
:
12586 return "DW_AT_description";
12587 case DW_AT_binary_scale
:
12588 return "DW_AT_binary_scale";
12589 case DW_AT_decimal_scale
:
12590 return "DW_AT_decimal_scale";
12592 return "DW_AT_small";
12593 case DW_AT_decimal_sign
:
12594 return "DW_AT_decimal_sign";
12595 case DW_AT_digit_count
:
12596 return "DW_AT_digit_count";
12597 case DW_AT_picture_string
:
12598 return "DW_AT_picture_string";
12599 case DW_AT_mutable
:
12600 return "DW_AT_mutable";
12601 case DW_AT_threads_scaled
:
12602 return "DW_AT_threads_scaled";
12603 case DW_AT_explicit
:
12604 return "DW_AT_explicit";
12605 case DW_AT_object_pointer
:
12606 return "DW_AT_object_pointer";
12607 case DW_AT_endianity
:
12608 return "DW_AT_endianity";
12609 case DW_AT_elemental
:
12610 return "DW_AT_elemental";
12612 return "DW_AT_pure";
12613 case DW_AT_recursive
:
12614 return "DW_AT_recursive";
12615 /* DWARF 4 values. */
12616 case DW_AT_signature
:
12617 return "DW_AT_signature";
12618 case DW_AT_linkage_name
:
12619 return "DW_AT_linkage_name";
12620 /* SGI/MIPS extensions. */
12621 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12622 case DW_AT_MIPS_fde
:
12623 return "DW_AT_MIPS_fde";
12625 case DW_AT_MIPS_loop_begin
:
12626 return "DW_AT_MIPS_loop_begin";
12627 case DW_AT_MIPS_tail_loop_begin
:
12628 return "DW_AT_MIPS_tail_loop_begin";
12629 case DW_AT_MIPS_epilog_begin
:
12630 return "DW_AT_MIPS_epilog_begin";
12631 case DW_AT_MIPS_loop_unroll_factor
:
12632 return "DW_AT_MIPS_loop_unroll_factor";
12633 case DW_AT_MIPS_software_pipeline_depth
:
12634 return "DW_AT_MIPS_software_pipeline_depth";
12635 case DW_AT_MIPS_linkage_name
:
12636 return "DW_AT_MIPS_linkage_name";
12637 case DW_AT_MIPS_stride
:
12638 return "DW_AT_MIPS_stride";
12639 case DW_AT_MIPS_abstract_name
:
12640 return "DW_AT_MIPS_abstract_name";
12641 case DW_AT_MIPS_clone_origin
:
12642 return "DW_AT_MIPS_clone_origin";
12643 case DW_AT_MIPS_has_inlines
:
12644 return "DW_AT_MIPS_has_inlines";
12645 /* HP extensions. */
12646 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12647 case DW_AT_HP_block_index
:
12648 return "DW_AT_HP_block_index";
12650 case DW_AT_HP_unmodifiable
:
12651 return "DW_AT_HP_unmodifiable";
12652 case DW_AT_HP_actuals_stmt_list
:
12653 return "DW_AT_HP_actuals_stmt_list";
12654 case DW_AT_HP_proc_per_section
:
12655 return "DW_AT_HP_proc_per_section";
12656 case DW_AT_HP_raw_data_ptr
:
12657 return "DW_AT_HP_raw_data_ptr";
12658 case DW_AT_HP_pass_by_reference
:
12659 return "DW_AT_HP_pass_by_reference";
12660 case DW_AT_HP_opt_level
:
12661 return "DW_AT_HP_opt_level";
12662 case DW_AT_HP_prof_version_id
:
12663 return "DW_AT_HP_prof_version_id";
12664 case DW_AT_HP_opt_flags
:
12665 return "DW_AT_HP_opt_flags";
12666 case DW_AT_HP_cold_region_low_pc
:
12667 return "DW_AT_HP_cold_region_low_pc";
12668 case DW_AT_HP_cold_region_high_pc
:
12669 return "DW_AT_HP_cold_region_high_pc";
12670 case DW_AT_HP_all_variables_modifiable
:
12671 return "DW_AT_HP_all_variables_modifiable";
12672 case DW_AT_HP_linkage_name
:
12673 return "DW_AT_HP_linkage_name";
12674 case DW_AT_HP_prof_flags
:
12675 return "DW_AT_HP_prof_flags";
12676 /* GNU extensions. */
12677 case DW_AT_sf_names
:
12678 return "DW_AT_sf_names";
12679 case DW_AT_src_info
:
12680 return "DW_AT_src_info";
12681 case DW_AT_mac_info
:
12682 return "DW_AT_mac_info";
12683 case DW_AT_src_coords
:
12684 return "DW_AT_src_coords";
12685 case DW_AT_body_begin
:
12686 return "DW_AT_body_begin";
12687 case DW_AT_body_end
:
12688 return "DW_AT_body_end";
12689 case DW_AT_GNU_vector
:
12690 return "DW_AT_GNU_vector";
12691 case DW_AT_GNU_odr_signature
:
12692 return "DW_AT_GNU_odr_signature";
12693 /* VMS extensions. */
12694 case DW_AT_VMS_rtnbeg_pd_address
:
12695 return "DW_AT_VMS_rtnbeg_pd_address";
12696 /* UPC extension. */
12697 case DW_AT_upc_threads_scaled
:
12698 return "DW_AT_upc_threads_scaled";
12699 /* PGI (STMicroelectronics) extensions. */
12700 case DW_AT_PGI_lbase
:
12701 return "DW_AT_PGI_lbase";
12702 case DW_AT_PGI_soffset
:
12703 return "DW_AT_PGI_soffset";
12704 case DW_AT_PGI_lstride
:
12705 return "DW_AT_PGI_lstride";
12707 return "DW_AT_<unknown>";
12711 /* Convert a DWARF value form code into its string name. */
12714 dwarf_form_name (unsigned form
)
12719 return "DW_FORM_addr";
12720 case DW_FORM_block2
:
12721 return "DW_FORM_block2";
12722 case DW_FORM_block4
:
12723 return "DW_FORM_block4";
12724 case DW_FORM_data2
:
12725 return "DW_FORM_data2";
12726 case DW_FORM_data4
:
12727 return "DW_FORM_data4";
12728 case DW_FORM_data8
:
12729 return "DW_FORM_data8";
12730 case DW_FORM_string
:
12731 return "DW_FORM_string";
12732 case DW_FORM_block
:
12733 return "DW_FORM_block";
12734 case DW_FORM_block1
:
12735 return "DW_FORM_block1";
12736 case DW_FORM_data1
:
12737 return "DW_FORM_data1";
12739 return "DW_FORM_flag";
12740 case DW_FORM_sdata
:
12741 return "DW_FORM_sdata";
12743 return "DW_FORM_strp";
12744 case DW_FORM_udata
:
12745 return "DW_FORM_udata";
12746 case DW_FORM_ref_addr
:
12747 return "DW_FORM_ref_addr";
12749 return "DW_FORM_ref1";
12751 return "DW_FORM_ref2";
12753 return "DW_FORM_ref4";
12755 return "DW_FORM_ref8";
12756 case DW_FORM_ref_udata
:
12757 return "DW_FORM_ref_udata";
12758 case DW_FORM_indirect
:
12759 return "DW_FORM_indirect";
12760 case DW_FORM_sec_offset
:
12761 return "DW_FORM_sec_offset";
12762 case DW_FORM_exprloc
:
12763 return "DW_FORM_exprloc";
12764 case DW_FORM_flag_present
:
12765 return "DW_FORM_flag_present";
12766 case DW_FORM_ref_sig8
:
12767 return "DW_FORM_ref_sig8";
12769 return "DW_FORM_<unknown>";
12773 /* Convert a DWARF stack opcode into its string name. */
12776 dwarf_stack_op_name (unsigned op
)
12781 return "DW_OP_addr";
12783 return "DW_OP_deref";
12784 case DW_OP_const1u
:
12785 return "DW_OP_const1u";
12786 case DW_OP_const1s
:
12787 return "DW_OP_const1s";
12788 case DW_OP_const2u
:
12789 return "DW_OP_const2u";
12790 case DW_OP_const2s
:
12791 return "DW_OP_const2s";
12792 case DW_OP_const4u
:
12793 return "DW_OP_const4u";
12794 case DW_OP_const4s
:
12795 return "DW_OP_const4s";
12796 case DW_OP_const8u
:
12797 return "DW_OP_const8u";
12798 case DW_OP_const8s
:
12799 return "DW_OP_const8s";
12801 return "DW_OP_constu";
12803 return "DW_OP_consts";
12805 return "DW_OP_dup";
12807 return "DW_OP_drop";
12809 return "DW_OP_over";
12811 return "DW_OP_pick";
12813 return "DW_OP_swap";
12815 return "DW_OP_rot";
12817 return "DW_OP_xderef";
12819 return "DW_OP_abs";
12821 return "DW_OP_and";
12823 return "DW_OP_div";
12825 return "DW_OP_minus";
12827 return "DW_OP_mod";
12829 return "DW_OP_mul";
12831 return "DW_OP_neg";
12833 return "DW_OP_not";
12837 return "DW_OP_plus";
12838 case DW_OP_plus_uconst
:
12839 return "DW_OP_plus_uconst";
12841 return "DW_OP_shl";
12843 return "DW_OP_shr";
12845 return "DW_OP_shra";
12847 return "DW_OP_xor";
12849 return "DW_OP_bra";
12863 return "DW_OP_skip";
12865 return "DW_OP_lit0";
12867 return "DW_OP_lit1";
12869 return "DW_OP_lit2";
12871 return "DW_OP_lit3";
12873 return "DW_OP_lit4";
12875 return "DW_OP_lit5";
12877 return "DW_OP_lit6";
12879 return "DW_OP_lit7";
12881 return "DW_OP_lit8";
12883 return "DW_OP_lit9";
12885 return "DW_OP_lit10";
12887 return "DW_OP_lit11";
12889 return "DW_OP_lit12";
12891 return "DW_OP_lit13";
12893 return "DW_OP_lit14";
12895 return "DW_OP_lit15";
12897 return "DW_OP_lit16";
12899 return "DW_OP_lit17";
12901 return "DW_OP_lit18";
12903 return "DW_OP_lit19";
12905 return "DW_OP_lit20";
12907 return "DW_OP_lit21";
12909 return "DW_OP_lit22";
12911 return "DW_OP_lit23";
12913 return "DW_OP_lit24";
12915 return "DW_OP_lit25";
12917 return "DW_OP_lit26";
12919 return "DW_OP_lit27";
12921 return "DW_OP_lit28";
12923 return "DW_OP_lit29";
12925 return "DW_OP_lit30";
12927 return "DW_OP_lit31";
12929 return "DW_OP_reg0";
12931 return "DW_OP_reg1";
12933 return "DW_OP_reg2";
12935 return "DW_OP_reg3";
12937 return "DW_OP_reg4";
12939 return "DW_OP_reg5";
12941 return "DW_OP_reg6";
12943 return "DW_OP_reg7";
12945 return "DW_OP_reg8";
12947 return "DW_OP_reg9";
12949 return "DW_OP_reg10";
12951 return "DW_OP_reg11";
12953 return "DW_OP_reg12";
12955 return "DW_OP_reg13";
12957 return "DW_OP_reg14";
12959 return "DW_OP_reg15";
12961 return "DW_OP_reg16";
12963 return "DW_OP_reg17";
12965 return "DW_OP_reg18";
12967 return "DW_OP_reg19";
12969 return "DW_OP_reg20";
12971 return "DW_OP_reg21";
12973 return "DW_OP_reg22";
12975 return "DW_OP_reg23";
12977 return "DW_OP_reg24";
12979 return "DW_OP_reg25";
12981 return "DW_OP_reg26";
12983 return "DW_OP_reg27";
12985 return "DW_OP_reg28";
12987 return "DW_OP_reg29";
12989 return "DW_OP_reg30";
12991 return "DW_OP_reg31";
12993 return "DW_OP_breg0";
12995 return "DW_OP_breg1";
12997 return "DW_OP_breg2";
12999 return "DW_OP_breg3";
13001 return "DW_OP_breg4";
13003 return "DW_OP_breg5";
13005 return "DW_OP_breg6";
13007 return "DW_OP_breg7";
13009 return "DW_OP_breg8";
13011 return "DW_OP_breg9";
13013 return "DW_OP_breg10";
13015 return "DW_OP_breg11";
13017 return "DW_OP_breg12";
13019 return "DW_OP_breg13";
13021 return "DW_OP_breg14";
13023 return "DW_OP_breg15";
13025 return "DW_OP_breg16";
13027 return "DW_OP_breg17";
13029 return "DW_OP_breg18";
13031 return "DW_OP_breg19";
13033 return "DW_OP_breg20";
13035 return "DW_OP_breg21";
13037 return "DW_OP_breg22";
13039 return "DW_OP_breg23";
13041 return "DW_OP_breg24";
13043 return "DW_OP_breg25";
13045 return "DW_OP_breg26";
13047 return "DW_OP_breg27";
13049 return "DW_OP_breg28";
13051 return "DW_OP_breg29";
13053 return "DW_OP_breg30";
13055 return "DW_OP_breg31";
13057 return "DW_OP_regx";
13059 return "DW_OP_fbreg";
13061 return "DW_OP_bregx";
13063 return "DW_OP_piece";
13064 case DW_OP_deref_size
:
13065 return "DW_OP_deref_size";
13066 case DW_OP_xderef_size
:
13067 return "DW_OP_xderef_size";
13069 return "DW_OP_nop";
13070 /* DWARF 3 extensions. */
13071 case DW_OP_push_object_address
:
13072 return "DW_OP_push_object_address";
13074 return "DW_OP_call2";
13076 return "DW_OP_call4";
13077 case DW_OP_call_ref
:
13078 return "DW_OP_call_ref";
13079 case DW_OP_form_tls_address
:
13080 return "DW_OP_form_tls_address";
13081 case DW_OP_call_frame_cfa
:
13082 return "DW_OP_call_frame_cfa";
13083 case DW_OP_bit_piece
:
13084 return "DW_OP_bit_piece";
13085 /* DWARF 4 extensions. */
13086 case DW_OP_implicit_value
:
13087 return "DW_OP_implicit_value";
13088 case DW_OP_stack_value
:
13089 return "DW_OP_stack_value";
13090 /* GNU extensions. */
13091 case DW_OP_GNU_push_tls_address
:
13092 return "DW_OP_GNU_push_tls_address";
13093 case DW_OP_GNU_uninit
:
13094 return "DW_OP_GNU_uninit";
13095 case DW_OP_GNU_implicit_pointer
:
13096 return "DW_OP_GNU_implicit_pointer";
13097 case DW_OP_GNU_entry_value
:
13098 return "DW_OP_GNU_entry_value";
13099 case DW_OP_GNU_const_type
:
13100 return "DW_OP_GNU_const_type";
13101 case DW_OP_GNU_regval_type
:
13102 return "DW_OP_GNU_regval_type";
13103 case DW_OP_GNU_deref_type
:
13104 return "DW_OP_GNU_deref_type";
13105 case DW_OP_GNU_convert
:
13106 return "DW_OP_GNU_convert";
13107 case DW_OP_GNU_reinterpret
:
13108 return "DW_OP_GNU_reinterpret";
13115 dwarf_bool_name (unsigned mybool
)
13123 /* Convert a DWARF type code into its string name. */
13126 dwarf_type_encoding_name (unsigned enc
)
13131 return "DW_ATE_void";
13132 case DW_ATE_address
:
13133 return "DW_ATE_address";
13134 case DW_ATE_boolean
:
13135 return "DW_ATE_boolean";
13136 case DW_ATE_complex_float
:
13137 return "DW_ATE_complex_float";
13139 return "DW_ATE_float";
13140 case DW_ATE_signed
:
13141 return "DW_ATE_signed";
13142 case DW_ATE_signed_char
:
13143 return "DW_ATE_signed_char";
13144 case DW_ATE_unsigned
:
13145 return "DW_ATE_unsigned";
13146 case DW_ATE_unsigned_char
:
13147 return "DW_ATE_unsigned_char";
13149 case DW_ATE_imaginary_float
:
13150 return "DW_ATE_imaginary_float";
13151 case DW_ATE_packed_decimal
:
13152 return "DW_ATE_packed_decimal";
13153 case DW_ATE_numeric_string
:
13154 return "DW_ATE_numeric_string";
13155 case DW_ATE_edited
:
13156 return "DW_ATE_edited";
13157 case DW_ATE_signed_fixed
:
13158 return "DW_ATE_signed_fixed";
13159 case DW_ATE_unsigned_fixed
:
13160 return "DW_ATE_unsigned_fixed";
13161 case DW_ATE_decimal_float
:
13162 return "DW_ATE_decimal_float";
13165 return "DW_ATE_UTF";
13166 /* HP extensions. */
13167 case DW_ATE_HP_float80
:
13168 return "DW_ATE_HP_float80";
13169 case DW_ATE_HP_complex_float80
:
13170 return "DW_ATE_HP_complex_float80";
13171 case DW_ATE_HP_float128
:
13172 return "DW_ATE_HP_float128";
13173 case DW_ATE_HP_complex_float128
:
13174 return "DW_ATE_HP_complex_float128";
13175 case DW_ATE_HP_floathpintel
:
13176 return "DW_ATE_HP_floathpintel";
13177 case DW_ATE_HP_imaginary_float80
:
13178 return "DW_ATE_HP_imaginary_float80";
13179 case DW_ATE_HP_imaginary_float128
:
13180 return "DW_ATE_HP_imaginary_float128";
13182 return "DW_ATE_<unknown>";
13186 /* Convert a DWARF call frame info operation to its string name. */
13190 dwarf_cfi_name (unsigned cfi_opc
)
13194 case DW_CFA_advance_loc
:
13195 return "DW_CFA_advance_loc";
13196 case DW_CFA_offset
:
13197 return "DW_CFA_offset";
13198 case DW_CFA_restore
:
13199 return "DW_CFA_restore";
13201 return "DW_CFA_nop";
13202 case DW_CFA_set_loc
:
13203 return "DW_CFA_set_loc";
13204 case DW_CFA_advance_loc1
:
13205 return "DW_CFA_advance_loc1";
13206 case DW_CFA_advance_loc2
:
13207 return "DW_CFA_advance_loc2";
13208 case DW_CFA_advance_loc4
:
13209 return "DW_CFA_advance_loc4";
13210 case DW_CFA_offset_extended
:
13211 return "DW_CFA_offset_extended";
13212 case DW_CFA_restore_extended
:
13213 return "DW_CFA_restore_extended";
13214 case DW_CFA_undefined
:
13215 return "DW_CFA_undefined";
13216 case DW_CFA_same_value
:
13217 return "DW_CFA_same_value";
13218 case DW_CFA_register
:
13219 return "DW_CFA_register";
13220 case DW_CFA_remember_state
:
13221 return "DW_CFA_remember_state";
13222 case DW_CFA_restore_state
:
13223 return "DW_CFA_restore_state";
13224 case DW_CFA_def_cfa
:
13225 return "DW_CFA_def_cfa";
13226 case DW_CFA_def_cfa_register
:
13227 return "DW_CFA_def_cfa_register";
13228 case DW_CFA_def_cfa_offset
:
13229 return "DW_CFA_def_cfa_offset";
13231 case DW_CFA_def_cfa_expression
:
13232 return "DW_CFA_def_cfa_expression";
13233 case DW_CFA_expression
:
13234 return "DW_CFA_expression";
13235 case DW_CFA_offset_extended_sf
:
13236 return "DW_CFA_offset_extended_sf";
13237 case DW_CFA_def_cfa_sf
:
13238 return "DW_CFA_def_cfa_sf";
13239 case DW_CFA_def_cfa_offset_sf
:
13240 return "DW_CFA_def_cfa_offset_sf";
13241 case DW_CFA_val_offset
:
13242 return "DW_CFA_val_offset";
13243 case DW_CFA_val_offset_sf
:
13244 return "DW_CFA_val_offset_sf";
13245 case DW_CFA_val_expression
:
13246 return "DW_CFA_val_expression";
13247 /* SGI/MIPS specific. */
13248 case DW_CFA_MIPS_advance_loc8
:
13249 return "DW_CFA_MIPS_advance_loc8";
13250 /* GNU extensions. */
13251 case DW_CFA_GNU_window_save
:
13252 return "DW_CFA_GNU_window_save";
13253 case DW_CFA_GNU_args_size
:
13254 return "DW_CFA_GNU_args_size";
13255 case DW_CFA_GNU_negative_offset_extended
:
13256 return "DW_CFA_GNU_negative_offset_extended";
13258 return "DW_CFA_<unknown>";
13264 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13268 print_spaces (indent
, f
);
13269 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13270 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13272 if (die
->parent
!= NULL
)
13274 print_spaces (indent
, f
);
13275 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13276 die
->parent
->offset
);
13279 print_spaces (indent
, f
);
13280 fprintf_unfiltered (f
, " has children: %s\n",
13281 dwarf_bool_name (die
->child
!= NULL
));
13283 print_spaces (indent
, f
);
13284 fprintf_unfiltered (f
, " attributes:\n");
13286 for (i
= 0; i
< die
->num_attrs
; ++i
)
13288 print_spaces (indent
, f
);
13289 fprintf_unfiltered (f
, " %s (%s) ",
13290 dwarf_attr_name (die
->attrs
[i
].name
),
13291 dwarf_form_name (die
->attrs
[i
].form
));
13293 switch (die
->attrs
[i
].form
)
13295 case DW_FORM_ref_addr
:
13297 fprintf_unfiltered (f
, "address: ");
13298 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13300 case DW_FORM_block2
:
13301 case DW_FORM_block4
:
13302 case DW_FORM_block
:
13303 case DW_FORM_block1
:
13304 fprintf_unfiltered (f
, "block: size %d",
13305 DW_BLOCK (&die
->attrs
[i
])->size
);
13307 case DW_FORM_exprloc
:
13308 fprintf_unfiltered (f
, "expression: size %u",
13309 DW_BLOCK (&die
->attrs
[i
])->size
);
13314 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13315 (long) (DW_ADDR (&die
->attrs
[i
])));
13317 case DW_FORM_data1
:
13318 case DW_FORM_data2
:
13319 case DW_FORM_data4
:
13320 case DW_FORM_data8
:
13321 case DW_FORM_udata
:
13322 case DW_FORM_sdata
:
13323 fprintf_unfiltered (f
, "constant: %s",
13324 pulongest (DW_UNSND (&die
->attrs
[i
])));
13326 case DW_FORM_sec_offset
:
13327 fprintf_unfiltered (f
, "section offset: %s",
13328 pulongest (DW_UNSND (&die
->attrs
[i
])));
13330 case DW_FORM_ref_sig8
:
13331 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13332 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13333 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
13335 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13337 case DW_FORM_string
:
13339 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13340 DW_STRING (&die
->attrs
[i
])
13341 ? DW_STRING (&die
->attrs
[i
]) : "",
13342 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13345 if (DW_UNSND (&die
->attrs
[i
]))
13346 fprintf_unfiltered (f
, "flag: TRUE");
13348 fprintf_unfiltered (f
, "flag: FALSE");
13350 case DW_FORM_flag_present
:
13351 fprintf_unfiltered (f
, "flag: TRUE");
13353 case DW_FORM_indirect
:
13354 /* The reader will have reduced the indirect form to
13355 the "base form" so this form should not occur. */
13356 fprintf_unfiltered (f
,
13357 "unexpected attribute form: DW_FORM_indirect");
13360 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13361 die
->attrs
[i
].form
);
13364 fprintf_unfiltered (f
, "\n");
13369 dump_die_for_error (struct die_info
*die
)
13371 dump_die_shallow (gdb_stderr
, 0, die
);
13375 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13377 int indent
= level
* 4;
13379 gdb_assert (die
!= NULL
);
13381 if (level
>= max_level
)
13384 dump_die_shallow (f
, indent
, die
);
13386 if (die
->child
!= NULL
)
13388 print_spaces (indent
, f
);
13389 fprintf_unfiltered (f
, " Children:");
13390 if (level
+ 1 < max_level
)
13392 fprintf_unfiltered (f
, "\n");
13393 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13397 fprintf_unfiltered (f
,
13398 " [not printed, max nesting level reached]\n");
13402 if (die
->sibling
!= NULL
&& level
> 0)
13404 dump_die_1 (f
, level
, max_level
, die
->sibling
);
13408 /* This is called from the pdie macro in gdbinit.in.
13409 It's not static so gcc will keep a copy callable from gdb. */
13412 dump_die (struct die_info
*die
, int max_level
)
13414 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
13418 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
13422 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
13428 is_ref_attr (struct attribute
*attr
)
13430 switch (attr
->form
)
13432 case DW_FORM_ref_addr
:
13437 case DW_FORM_ref_udata
:
13444 static unsigned int
13445 dwarf2_get_ref_die_offset (struct attribute
*attr
)
13447 if (is_ref_attr (attr
))
13448 return DW_ADDR (attr
);
13450 complaint (&symfile_complaints
,
13451 _("unsupported die ref attribute form: '%s'"),
13452 dwarf_form_name (attr
->form
));
13456 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13457 * the value held by the attribute is not constant. */
13460 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
13462 if (attr
->form
== DW_FORM_sdata
)
13463 return DW_SND (attr
);
13464 else if (attr
->form
== DW_FORM_udata
13465 || attr
->form
== DW_FORM_data1
13466 || attr
->form
== DW_FORM_data2
13467 || attr
->form
== DW_FORM_data4
13468 || attr
->form
== DW_FORM_data8
)
13469 return DW_UNSND (attr
);
13472 complaint (&symfile_complaints
,
13473 _("Attribute value is not a constant (%s)"),
13474 dwarf_form_name (attr
->form
));
13475 return default_value
;
13479 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13480 unit and add it to our queue.
13481 The result is non-zero if PER_CU was queued, otherwise the result is zero
13482 meaning either PER_CU is already queued or it is already loaded. */
13485 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
13486 struct dwarf2_per_cu_data
*per_cu
)
13488 /* We may arrive here during partial symbol reading, if we need full
13489 DIEs to process an unusual case (e.g. template arguments). Do
13490 not queue PER_CU, just tell our caller to load its DIEs. */
13491 if (dwarf2_per_objfile
->reading_partial_symbols
)
13493 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
13498 /* Mark the dependence relation so that we don't flush PER_CU
13500 dwarf2_add_dependence (this_cu
, per_cu
);
13502 /* If it's already on the queue, we have nothing to do. */
13503 if (per_cu
->queued
)
13506 /* If the compilation unit is already loaded, just mark it as
13508 if (per_cu
->cu
!= NULL
)
13510 per_cu
->cu
->last_used
= 0;
13514 /* Add it to the queue. */
13515 queue_comp_unit (per_cu
, this_cu
->objfile
);
13520 /* Follow reference or signature attribute ATTR of SRC_DIE.
13521 On entry *REF_CU is the CU of SRC_DIE.
13522 On exit *REF_CU is the CU of the result. */
13524 static struct die_info
*
13525 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
13526 struct dwarf2_cu
**ref_cu
)
13528 struct die_info
*die
;
13530 if (is_ref_attr (attr
))
13531 die
= follow_die_ref (src_die
, attr
, ref_cu
);
13532 else if (attr
->form
== DW_FORM_ref_sig8
)
13533 die
= follow_die_sig (src_die
, attr
, ref_cu
);
13536 dump_die_for_error (src_die
);
13537 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13538 (*ref_cu
)->objfile
->name
);
13544 /* Follow reference OFFSET.
13545 On entry *REF_CU is the CU of the source die referencing OFFSET.
13546 On exit *REF_CU is the CU of the result.
13547 Returns NULL if OFFSET is invalid. */
13549 static struct die_info
*
13550 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
13552 struct die_info temp_die
;
13553 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
13555 gdb_assert (cu
->per_cu
!= NULL
);
13559 if (cu
->per_cu
->from_debug_types
)
13561 /* .debug_types CUs cannot reference anything outside their CU.
13562 If they need to, they have to reference a signatured type via
13563 DW_FORM_ref_sig8. */
13564 if (! offset_in_cu_p (&cu
->header
, offset
))
13567 else if (! offset_in_cu_p (&cu
->header
, offset
))
13569 struct dwarf2_per_cu_data
*per_cu
;
13571 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
13573 /* If necessary, add it to the queue and load its DIEs. */
13574 if (maybe_queue_comp_unit (cu
, per_cu
))
13575 load_full_comp_unit (per_cu
, cu
->objfile
);
13577 target_cu
= per_cu
->cu
;
13579 else if (cu
->dies
== NULL
)
13581 /* We're loading full DIEs during partial symbol reading. */
13582 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
13583 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
13586 *ref_cu
= target_cu
;
13587 temp_die
.offset
= offset
;
13588 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13591 /* Follow reference attribute ATTR of SRC_DIE.
13592 On entry *REF_CU is the CU of SRC_DIE.
13593 On exit *REF_CU is the CU of the result. */
13595 static struct die_info
*
13596 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13597 struct dwarf2_cu
**ref_cu
)
13599 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13600 struct dwarf2_cu
*cu
= *ref_cu
;
13601 struct die_info
*die
;
13603 die
= follow_die_offset (offset
, ref_cu
);
13605 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13606 "at 0x%x [in module %s]"),
13607 offset
, src_die
->offset
, cu
->objfile
->name
);
13612 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13613 value is intended for DW_OP_call*. */
13615 struct dwarf2_locexpr_baton
13616 dwarf2_fetch_die_location_block (unsigned int offset
,
13617 struct dwarf2_per_cu_data
*per_cu
,
13618 CORE_ADDR (*get_frame_pc
) (void *baton
),
13621 struct dwarf2_cu
*cu
= per_cu
->cu
;
13622 struct die_info
*die
;
13623 struct attribute
*attr
;
13624 struct dwarf2_locexpr_baton retval
;
13626 dw2_setup (per_cu
->objfile
);
13628 die
= follow_die_offset (offset
, &cu
);
13630 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13631 offset
, per_cu
->cu
->objfile
->name
);
13633 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13636 /* DWARF: "If there is no such attribute, then there is no effect.". */
13638 retval
.data
= NULL
;
13641 else if (attr_form_is_section_offset (attr
))
13643 struct dwarf2_loclist_baton loclist_baton
;
13644 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
13647 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
13649 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
13651 retval
.size
= size
;
13655 if (!attr_form_is_block (attr
))
13656 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13657 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13658 offset
, per_cu
->cu
->objfile
->name
);
13660 retval
.data
= DW_BLOCK (attr
)->data
;
13661 retval
.size
= DW_BLOCK (attr
)->size
;
13663 retval
.per_cu
= cu
->per_cu
;
13667 /* Return the type of the DIE at DIE_OFFSET in the CU named by
13671 dwarf2_get_die_type (unsigned int die_offset
,
13672 struct dwarf2_per_cu_data
*per_cu
)
13674 struct dwarf2_cu
*cu
= per_cu
->cu
;
13675 struct die_info
*die
;
13676 struct type
*result
;
13678 dw2_setup (per_cu
->objfile
);
13680 die
= follow_die_offset (die_offset
, &cu
);
13682 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13683 die_offset
, per_cu
->cu
->objfile
->name
);
13685 result
= get_die_type (die
, cu
);
13686 if (result
== NULL
)
13687 result
= read_type_die_1 (die
, cu
);
13692 /* Follow the signature attribute ATTR in SRC_DIE.
13693 On entry *REF_CU is the CU of SRC_DIE.
13694 On exit *REF_CU is the CU of the result. */
13696 static struct die_info
*
13697 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
13698 struct dwarf2_cu
**ref_cu
)
13700 struct objfile
*objfile
= (*ref_cu
)->objfile
;
13701 struct die_info temp_die
;
13702 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13703 struct dwarf2_cu
*sig_cu
;
13704 struct die_info
*die
;
13706 /* sig_type will be NULL if the signatured type is missing from
13708 if (sig_type
== NULL
)
13709 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13710 "at 0x%x [in module %s]"),
13711 src_die
->offset
, objfile
->name
);
13713 /* If necessary, add it to the queue and load its DIEs. */
13715 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
13716 read_signatured_type (objfile
, sig_type
);
13718 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
13720 sig_cu
= sig_type
->per_cu
.cu
;
13721 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
13722 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
13729 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
13730 "from DIE at 0x%x [in module %s]"),
13731 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
13734 /* Given an offset of a signatured type, return its signatured_type. */
13736 static struct signatured_type
*
13737 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
13739 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
13740 unsigned int length
, initial_length_size
;
13741 unsigned int sig_offset
;
13742 struct signatured_type find_entry
, *type_sig
;
13744 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
13745 sig_offset
= (initial_length_size
13747 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
13748 + 1 /*address_size*/);
13749 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
13750 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
13752 /* This is only used to lookup previously recorded types.
13753 If we didn't find it, it's our bug. */
13754 gdb_assert (type_sig
!= NULL
);
13755 gdb_assert (offset
== type_sig
->offset
);
13760 /* Read in signatured type at OFFSET and build its CU and die(s). */
13763 read_signatured_type_at_offset (struct objfile
*objfile
,
13764 unsigned int offset
)
13766 struct signatured_type
*type_sig
;
13768 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13770 /* We have the section offset, but we need the signature to do the
13771 hash table lookup. */
13772 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
13774 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13776 read_signatured_type (objfile
, type_sig
);
13778 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
13781 /* Read in a signatured type and build its CU and DIEs. */
13784 read_signatured_type (struct objfile
*objfile
,
13785 struct signatured_type
*type_sig
)
13787 gdb_byte
*types_ptr
;
13788 struct die_reader_specs reader_specs
;
13789 struct dwarf2_cu
*cu
;
13790 ULONGEST signature
;
13791 struct cleanup
*back_to
, *free_cu_cleanup
;
13793 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13794 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
13796 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13798 cu
= xmalloc (sizeof (*cu
));
13799 init_one_comp_unit (cu
, objfile
);
13801 type_sig
->per_cu
.cu
= cu
;
13802 cu
->per_cu
= &type_sig
->per_cu
;
13804 /* If an error occurs while loading, release our storage. */
13805 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
13807 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
13808 types_ptr
, objfile
->obfd
);
13809 gdb_assert (signature
== type_sig
->signature
);
13812 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13816 &cu
->comp_unit_obstack
,
13817 hashtab_obstack_allocate
,
13818 dummy_obstack_deallocate
);
13820 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
13821 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
13823 init_cu_die_reader (&reader_specs
, cu
);
13825 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
13828 /* We try not to read any attributes in this function, because not
13829 all objfiles needed for references have been loaded yet, and symbol
13830 table processing isn't initialized. But we have to set the CU language,
13831 or we won't be able to build types correctly. */
13832 prepare_one_comp_unit (cu
, cu
->dies
);
13834 do_cleanups (back_to
);
13836 /* We've successfully allocated this compilation unit. Let our caller
13837 clean it up when finished with it. */
13838 discard_cleanups (free_cu_cleanup
);
13840 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
13841 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
13844 /* Decode simple location descriptions.
13845 Given a pointer to a dwarf block that defines a location, compute
13846 the location and return the value.
13848 NOTE drow/2003-11-18: This function is called in two situations
13849 now: for the address of static or global variables (partial symbols
13850 only) and for offsets into structures which are expected to be
13851 (more or less) constant. The partial symbol case should go away,
13852 and only the constant case should remain. That will let this
13853 function complain more accurately. A few special modes are allowed
13854 without complaint for global variables (for instance, global
13855 register values and thread-local values).
13857 A location description containing no operations indicates that the
13858 object is optimized out. The return value is 0 for that case.
13859 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13860 callers will only want a very basic result and this can become a
13863 Note that stack[0] is unused except as a default error return. */
13866 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
13868 struct objfile
*objfile
= cu
->objfile
;
13870 int size
= blk
->size
;
13871 gdb_byte
*data
= blk
->data
;
13872 CORE_ADDR stack
[64];
13874 unsigned int bytes_read
, unsnd
;
13880 stack
[++stacki
] = 0;
13919 stack
[++stacki
] = op
- DW_OP_lit0
;
13954 stack
[++stacki
] = op
- DW_OP_reg0
;
13956 dwarf2_complex_location_expr_complaint ();
13960 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13962 stack
[++stacki
] = unsnd
;
13964 dwarf2_complex_location_expr_complaint ();
13968 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
13973 case DW_OP_const1u
:
13974 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
13978 case DW_OP_const1s
:
13979 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
13983 case DW_OP_const2u
:
13984 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
13988 case DW_OP_const2s
:
13989 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
13993 case DW_OP_const4u
:
13994 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
13998 case DW_OP_const4s
:
13999 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14004 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14010 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14015 stack
[stacki
+ 1] = stack
[stacki
];
14020 stack
[stacki
- 1] += stack
[stacki
];
14024 case DW_OP_plus_uconst
:
14025 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14031 stack
[stacki
- 1] -= stack
[stacki
];
14036 /* If we're not the last op, then we definitely can't encode
14037 this using GDB's address_class enum. This is valid for partial
14038 global symbols, although the variable's address will be bogus
14041 dwarf2_complex_location_expr_complaint ();
14044 case DW_OP_GNU_push_tls_address
:
14045 /* The top of the stack has the offset from the beginning
14046 of the thread control block at which the variable is located. */
14047 /* Nothing should follow this operator, so the top of stack would
14049 /* This is valid for partial global symbols, but the variable's
14050 address will be bogus in the psymtab. */
14052 dwarf2_complex_location_expr_complaint ();
14055 case DW_OP_GNU_uninit
:
14060 const char *name
= dwarf_stack_op_name (op
);
14063 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14066 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14070 return (stack
[stacki
]);
14073 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14074 outside of the allocated space. Also enforce minimum>0. */
14075 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14077 complaint (&symfile_complaints
,
14078 _("location description stack overflow"));
14084 complaint (&symfile_complaints
,
14085 _("location description stack underflow"));
14089 return (stack
[stacki
]);
14092 /* memory allocation interface */
14094 static struct dwarf_block
*
14095 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14097 struct dwarf_block
*blk
;
14099 blk
= (struct dwarf_block
*)
14100 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14104 static struct abbrev_info
*
14105 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14107 struct abbrev_info
*abbrev
;
14109 abbrev
= (struct abbrev_info
*)
14110 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14111 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14115 static struct die_info
*
14116 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14118 struct die_info
*die
;
14119 size_t size
= sizeof (struct die_info
);
14122 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14124 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14125 memset (die
, 0, sizeof (struct die_info
));
14130 /* Macro support. */
14132 /* Return the full name of file number I in *LH's file name table.
14133 Use COMP_DIR as the name of the current directory of the
14134 compilation. The result is allocated using xmalloc; the caller is
14135 responsible for freeing it. */
14137 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14139 /* Is the file number a valid index into the line header's file name
14140 table? Remember that file numbers start with one, not zero. */
14141 if (1 <= file
&& file
<= lh
->num_file_names
)
14143 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14145 if (IS_ABSOLUTE_PATH (fe
->name
))
14146 return xstrdup (fe
->name
);
14154 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14160 dir_len
= strlen (dir
);
14161 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14162 strcpy (full_name
, dir
);
14163 full_name
[dir_len
] = '/';
14164 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14168 return xstrdup (fe
->name
);
14173 /* The compiler produced a bogus file number. We can at least
14174 record the macro definitions made in the file, even if we
14175 won't be able to find the file by name. */
14176 char fake_name
[80];
14178 sprintf (fake_name
, "<bad macro file number %d>", file
);
14180 complaint (&symfile_complaints
,
14181 _("bad file number in macro information (%d)"),
14184 return xstrdup (fake_name
);
14189 static struct macro_source_file
*
14190 macro_start_file (int file
, int line
,
14191 struct macro_source_file
*current_file
,
14192 const char *comp_dir
,
14193 struct line_header
*lh
, struct objfile
*objfile
)
14195 /* The full name of this source file. */
14196 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14198 /* We don't create a macro table for this compilation unit
14199 at all until we actually get a filename. */
14200 if (! pending_macros
)
14201 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14202 objfile
->macro_cache
);
14204 if (! current_file
)
14205 /* If we have no current file, then this must be the start_file
14206 directive for the compilation unit's main source file. */
14207 current_file
= macro_set_main (pending_macros
, full_name
);
14209 current_file
= macro_include (current_file
, line
, full_name
);
14213 return current_file
;
14217 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14218 followed by a null byte. */
14220 copy_string (const char *buf
, int len
)
14222 char *s
= xmalloc (len
+ 1);
14224 memcpy (s
, buf
, len
);
14230 static const char *
14231 consume_improper_spaces (const char *p
, const char *body
)
14235 complaint (&symfile_complaints
,
14236 _("macro definition contains spaces "
14237 "in formal argument list:\n`%s'"),
14249 parse_macro_definition (struct macro_source_file
*file
, int line
,
14254 /* The body string takes one of two forms. For object-like macro
14255 definitions, it should be:
14257 <macro name> " " <definition>
14259 For function-like macro definitions, it should be:
14261 <macro name> "() " <definition>
14263 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14265 Spaces may appear only where explicitly indicated, and in the
14268 The Dwarf 2 spec says that an object-like macro's name is always
14269 followed by a space, but versions of GCC around March 2002 omit
14270 the space when the macro's definition is the empty string.
14272 The Dwarf 2 spec says that there should be no spaces between the
14273 formal arguments in a function-like macro's formal argument list,
14274 but versions of GCC around March 2002 include spaces after the
14278 /* Find the extent of the macro name. The macro name is terminated
14279 by either a space or null character (for an object-like macro) or
14280 an opening paren (for a function-like macro). */
14281 for (p
= body
; *p
; p
++)
14282 if (*p
== ' ' || *p
== '(')
14285 if (*p
== ' ' || *p
== '\0')
14287 /* It's an object-like macro. */
14288 int name_len
= p
- body
;
14289 char *name
= copy_string (body
, name_len
);
14290 const char *replacement
;
14293 replacement
= body
+ name_len
+ 1;
14296 dwarf2_macro_malformed_definition_complaint (body
);
14297 replacement
= body
+ name_len
;
14300 macro_define_object (file
, line
, name
, replacement
);
14304 else if (*p
== '(')
14306 /* It's a function-like macro. */
14307 char *name
= copy_string (body
, p
- body
);
14310 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14314 p
= consume_improper_spaces (p
, body
);
14316 /* Parse the formal argument list. */
14317 while (*p
&& *p
!= ')')
14319 /* Find the extent of the current argument name. */
14320 const char *arg_start
= p
;
14322 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14325 if (! *p
|| p
== arg_start
)
14326 dwarf2_macro_malformed_definition_complaint (body
);
14329 /* Make sure argv has room for the new argument. */
14330 if (argc
>= argv_size
)
14333 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14336 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14339 p
= consume_improper_spaces (p
, body
);
14341 /* Consume the comma, if present. */
14346 p
= consume_improper_spaces (p
, body
);
14355 /* Perfectly formed definition, no complaints. */
14356 macro_define_function (file
, line
, name
,
14357 argc
, (const char **) argv
,
14359 else if (*p
== '\0')
14361 /* Complain, but do define it. */
14362 dwarf2_macro_malformed_definition_complaint (body
);
14363 macro_define_function (file
, line
, name
,
14364 argc
, (const char **) argv
,
14368 /* Just complain. */
14369 dwarf2_macro_malformed_definition_complaint (body
);
14372 /* Just complain. */
14373 dwarf2_macro_malformed_definition_complaint (body
);
14379 for (i
= 0; i
< argc
; i
++)
14385 dwarf2_macro_malformed_definition_complaint (body
);
14390 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
14391 char *comp_dir
, bfd
*abfd
,
14392 struct dwarf2_cu
*cu
)
14394 gdb_byte
*mac_ptr
, *mac_end
;
14395 struct macro_source_file
*current_file
= 0;
14396 enum dwarf_macinfo_record_type macinfo_type
;
14397 int at_commandline
;
14399 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14400 &dwarf2_per_objfile
->macinfo
);
14401 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
14403 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
14407 /* First pass: Find the name of the base filename.
14408 This filename is needed in order to process all macros whose definition
14409 (or undefinition) comes from the command line. These macros are defined
14410 before the first DW_MACINFO_start_file entry, and yet still need to be
14411 associated to the base file.
14413 To determine the base file name, we scan the macro definitions until we
14414 reach the first DW_MACINFO_start_file entry. We then initialize
14415 CURRENT_FILE accordingly so that any macro definition found before the
14416 first DW_MACINFO_start_file can still be associated to the base file. */
14418 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14419 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
14420 + dwarf2_per_objfile
->macinfo
.size
;
14424 /* Do we at least have room for a macinfo type byte? */
14425 if (mac_ptr
>= mac_end
)
14427 /* Complaint is printed during the second pass as GDB will probably
14428 stop the first pass earlier upon finding
14429 DW_MACINFO_start_file. */
14433 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14436 switch (macinfo_type
)
14438 /* A zero macinfo type indicates the end of the macro
14443 case DW_MACINFO_define
:
14444 case DW_MACINFO_undef
:
14445 /* Only skip the data by MAC_PTR. */
14447 unsigned int bytes_read
;
14449 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14450 mac_ptr
+= bytes_read
;
14451 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14452 mac_ptr
+= bytes_read
;
14456 case DW_MACINFO_start_file
:
14458 unsigned int bytes_read
;
14461 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14462 mac_ptr
+= bytes_read
;
14463 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14464 mac_ptr
+= bytes_read
;
14466 current_file
= macro_start_file (file
, line
, current_file
,
14467 comp_dir
, lh
, cu
->objfile
);
14471 case DW_MACINFO_end_file
:
14472 /* No data to skip by MAC_PTR. */
14475 case DW_MACINFO_vendor_ext
:
14476 /* Only skip the data by MAC_PTR. */
14478 unsigned int bytes_read
;
14480 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14481 mac_ptr
+= bytes_read
;
14482 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14483 mac_ptr
+= bytes_read
;
14490 } while (macinfo_type
!= 0 && current_file
== NULL
);
14492 /* Second pass: Process all entries.
14494 Use the AT_COMMAND_LINE flag to determine whether we are still processing
14495 command-line macro definitions/undefinitions. This flag is unset when we
14496 reach the first DW_MACINFO_start_file entry. */
14498 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14500 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14501 GDB is still reading the definitions from command line. First
14502 DW_MACINFO_start_file will need to be ignored as it was already executed
14503 to create CURRENT_FILE for the main source holding also the command line
14504 definitions. On first met DW_MACINFO_start_file this flag is reset to
14505 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14507 at_commandline
= 1;
14511 /* Do we at least have room for a macinfo type byte? */
14512 if (mac_ptr
>= mac_end
)
14514 dwarf2_macros_too_long_complaint ();
14518 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14521 switch (macinfo_type
)
14523 /* A zero macinfo type indicates the end of the macro
14528 case DW_MACINFO_define
:
14529 case DW_MACINFO_undef
:
14531 unsigned int bytes_read
;
14535 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14536 mac_ptr
+= bytes_read
;
14537 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14538 mac_ptr
+= bytes_read
;
14540 if (! current_file
)
14542 /* DWARF violation as no main source is present. */
14543 complaint (&symfile_complaints
,
14544 _("debug info with no main source gives macro %s "
14546 macinfo_type
== DW_MACINFO_define
?
14548 macinfo_type
== DW_MACINFO_undef
?
14549 _("undefinition") :
14550 _("something-or-other"), line
, body
);
14553 if ((line
== 0 && !at_commandline
)
14554 || (line
!= 0 && at_commandline
))
14555 complaint (&symfile_complaints
,
14556 _("debug info gives %s macro %s with %s line %d: %s"),
14557 at_commandline
? _("command-line") : _("in-file"),
14558 macinfo_type
== DW_MACINFO_define
?
14560 macinfo_type
== DW_MACINFO_undef
?
14561 _("undefinition") :
14562 _("something-or-other"),
14563 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
14565 if (macinfo_type
== DW_MACINFO_define
)
14566 parse_macro_definition (current_file
, line
, body
);
14567 else if (macinfo_type
== DW_MACINFO_undef
)
14568 macro_undef (current_file
, line
, body
);
14572 case DW_MACINFO_start_file
:
14574 unsigned int bytes_read
;
14577 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14578 mac_ptr
+= bytes_read
;
14579 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14580 mac_ptr
+= bytes_read
;
14582 if ((line
== 0 && !at_commandline
)
14583 || (line
!= 0 && at_commandline
))
14584 complaint (&symfile_complaints
,
14585 _("debug info gives source %d included "
14586 "from %s at %s line %d"),
14587 file
, at_commandline
? _("command-line") : _("file"),
14588 line
== 0 ? _("zero") : _("non-zero"), line
);
14590 if (at_commandline
)
14592 /* This DW_MACINFO_start_file was executed in the pass one. */
14593 at_commandline
= 0;
14596 current_file
= macro_start_file (file
, line
,
14597 current_file
, comp_dir
,
14602 case DW_MACINFO_end_file
:
14603 if (! current_file
)
14604 complaint (&symfile_complaints
,
14605 _("macro debug info has an unmatched "
14606 "`close_file' directive"));
14609 current_file
= current_file
->included_by
;
14610 if (! current_file
)
14612 enum dwarf_macinfo_record_type next_type
;
14614 /* GCC circa March 2002 doesn't produce the zero
14615 type byte marking the end of the compilation
14616 unit. Complain if it's not there, but exit no
14619 /* Do we at least have room for a macinfo type byte? */
14620 if (mac_ptr
>= mac_end
)
14622 dwarf2_macros_too_long_complaint ();
14626 /* We don't increment mac_ptr here, so this is just
14628 next_type
= read_1_byte (abfd
, mac_ptr
);
14629 if (next_type
!= 0)
14630 complaint (&symfile_complaints
,
14631 _("no terminating 0-type entry for "
14632 "macros in `.debug_macinfo' section"));
14639 case DW_MACINFO_vendor_ext
:
14641 unsigned int bytes_read
;
14644 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14645 mac_ptr
+= bytes_read
;
14646 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14647 mac_ptr
+= bytes_read
;
14649 /* We don't recognize any vendor extensions. */
14653 } while (macinfo_type
!= 0);
14656 /* Check if the attribute's form is a DW_FORM_block*
14657 if so return true else false. */
14659 attr_form_is_block (struct attribute
*attr
)
14661 return (attr
== NULL
? 0 :
14662 attr
->form
== DW_FORM_block1
14663 || attr
->form
== DW_FORM_block2
14664 || attr
->form
== DW_FORM_block4
14665 || attr
->form
== DW_FORM_block
14666 || attr
->form
== DW_FORM_exprloc
);
14669 /* Return non-zero if ATTR's value is a section offset --- classes
14670 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14671 You may use DW_UNSND (attr) to retrieve such offsets.
14673 Section 7.5.4, "Attribute Encodings", explains that no attribute
14674 may have a value that belongs to more than one of these classes; it
14675 would be ambiguous if we did, because we use the same forms for all
14678 attr_form_is_section_offset (struct attribute
*attr
)
14680 return (attr
->form
== DW_FORM_data4
14681 || attr
->form
== DW_FORM_data8
14682 || attr
->form
== DW_FORM_sec_offset
);
14686 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14687 zero otherwise. When this function returns true, you can apply
14688 dwarf2_get_attr_constant_value to it.
14690 However, note that for some attributes you must check
14691 attr_form_is_section_offset before using this test. DW_FORM_data4
14692 and DW_FORM_data8 are members of both the constant class, and of
14693 the classes that contain offsets into other debug sections
14694 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14695 that, if an attribute's can be either a constant or one of the
14696 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14697 taken as section offsets, not constants. */
14699 attr_form_is_constant (struct attribute
*attr
)
14701 switch (attr
->form
)
14703 case DW_FORM_sdata
:
14704 case DW_FORM_udata
:
14705 case DW_FORM_data1
:
14706 case DW_FORM_data2
:
14707 case DW_FORM_data4
:
14708 case DW_FORM_data8
:
14715 /* A helper function that fills in a dwarf2_loclist_baton. */
14718 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
14719 struct dwarf2_loclist_baton
*baton
,
14720 struct attribute
*attr
)
14722 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14723 &dwarf2_per_objfile
->loc
);
14725 baton
->per_cu
= cu
->per_cu
;
14726 gdb_assert (baton
->per_cu
);
14727 /* We don't know how long the location list is, but make sure we
14728 don't run off the edge of the section. */
14729 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
14730 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
14731 baton
->base_address
= cu
->base_address
;
14735 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
14736 struct dwarf2_cu
*cu
)
14738 if (attr_form_is_section_offset (attr
)
14739 /* ".debug_loc" may not exist at all, or the offset may be outside
14740 the section. If so, fall through to the complaint in the
14742 && DW_UNSND (attr
) < dwarf2_section_size (dwarf2_per_objfile
->objfile
,
14743 &dwarf2_per_objfile
->loc
))
14745 struct dwarf2_loclist_baton
*baton
;
14747 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14748 sizeof (struct dwarf2_loclist_baton
));
14750 fill_in_loclist_baton (cu
, baton
, attr
);
14752 if (cu
->base_known
== 0)
14753 complaint (&symfile_complaints
,
14754 _("Location list used without "
14755 "specifying the CU base address."));
14757 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
14758 SYMBOL_LOCATION_BATON (sym
) = baton
;
14762 struct dwarf2_locexpr_baton
*baton
;
14764 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14765 sizeof (struct dwarf2_locexpr_baton
));
14766 baton
->per_cu
= cu
->per_cu
;
14767 gdb_assert (baton
->per_cu
);
14769 if (attr_form_is_block (attr
))
14771 /* Note that we're just copying the block's data pointer
14772 here, not the actual data. We're still pointing into the
14773 info_buffer for SYM's objfile; right now we never release
14774 that buffer, but when we do clean up properly this may
14776 baton
->size
= DW_BLOCK (attr
)->size
;
14777 baton
->data
= DW_BLOCK (attr
)->data
;
14781 dwarf2_invalid_attrib_class_complaint ("location description",
14782 SYMBOL_NATURAL_NAME (sym
));
14784 baton
->data
= NULL
;
14787 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14788 SYMBOL_LOCATION_BATON (sym
) = baton
;
14792 /* Return the OBJFILE associated with the compilation unit CU. If CU
14793 came from a separate debuginfo file, then the master objfile is
14797 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
14799 struct objfile
*objfile
= per_cu
->objfile
;
14801 /* Return the master objfile, so that we can report and look up the
14802 correct file containing this variable. */
14803 if (objfile
->separate_debug_objfile_backlink
)
14804 objfile
= objfile
->separate_debug_objfile_backlink
;
14809 /* Return the address size given in the compilation unit header for CU. */
14812 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
14815 return per_cu
->cu
->header
.addr_size
;
14818 /* If the CU is not currently read in, we re-read its header. */
14819 struct objfile
*objfile
= per_cu
->objfile
;
14820 struct dwarf2_per_objfile
*per_objfile
14821 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14822 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14823 struct comp_unit_head cu_header
;
14825 memset (&cu_header
, 0, sizeof cu_header
);
14826 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14827 return cu_header
.addr_size
;
14831 /* Return the offset size given in the compilation unit header for CU. */
14834 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
14837 return per_cu
->cu
->header
.offset_size
;
14840 /* If the CU is not currently read in, we re-read its header. */
14841 struct objfile
*objfile
= per_cu
->objfile
;
14842 struct dwarf2_per_objfile
*per_objfile
14843 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14844 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14845 struct comp_unit_head cu_header
;
14847 memset (&cu_header
, 0, sizeof cu_header
);
14848 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14849 return cu_header
.offset_size
;
14853 /* Return the text offset of the CU. The returned offset comes from
14854 this CU's objfile. If this objfile came from a separate debuginfo
14855 file, then the offset may be different from the corresponding
14856 offset in the parent objfile. */
14859 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
14861 struct objfile
*objfile
= per_cu
->objfile
;
14863 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14866 /* Locate the .debug_info compilation unit from CU's objfile which contains
14867 the DIE at OFFSET. Raises an error on failure. */
14869 static struct dwarf2_per_cu_data
*
14870 dwarf2_find_containing_comp_unit (unsigned int offset
,
14871 struct objfile
*objfile
)
14873 struct dwarf2_per_cu_data
*this_cu
;
14877 high
= dwarf2_per_objfile
->n_comp_units
- 1;
14880 int mid
= low
+ (high
- low
) / 2;
14882 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
14887 gdb_assert (low
== high
);
14888 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
14891 error (_("Dwarf Error: could not find partial DIE containing "
14892 "offset 0x%lx [in module %s]"),
14893 (long) offset
, bfd_get_filename (objfile
->obfd
));
14895 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
14896 return dwarf2_per_objfile
->all_comp_units
[low
-1];
14900 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
14901 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
14902 && offset
>= this_cu
->offset
+ this_cu
->length
)
14903 error (_("invalid dwarf2 offset %u"), offset
);
14904 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
14909 /* Locate the compilation unit from OBJFILE which is located at exactly
14910 OFFSET. Raises an error on failure. */
14912 static struct dwarf2_per_cu_data
*
14913 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
14915 struct dwarf2_per_cu_data
*this_cu
;
14917 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
14918 if (this_cu
->offset
!= offset
)
14919 error (_("no compilation unit with offset %u."), offset
);
14923 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
14926 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
14928 memset (cu
, 0, sizeof (*cu
));
14929 cu
->objfile
= objfile
;
14930 obstack_init (&cu
->comp_unit_obstack
);
14933 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
14936 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
14938 struct attribute
*attr
;
14940 /* Set the language we're debugging. */
14941 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
14943 set_cu_language (DW_UNSND (attr
), cu
);
14946 cu
->language
= language_minimal
;
14947 cu
->language_defn
= language_def (cu
->language
);
14951 /* Release one cached compilation unit, CU. We unlink it from the tree
14952 of compilation units, but we don't remove it from the read_in_chain;
14953 the caller is responsible for that.
14954 NOTE: DATA is a void * because this function is also used as a
14955 cleanup routine. */
14958 free_one_comp_unit (void *data
)
14960 struct dwarf2_cu
*cu
= data
;
14962 if (cu
->per_cu
!= NULL
)
14963 cu
->per_cu
->cu
= NULL
;
14966 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14971 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14972 when we're finished with it. We can't free the pointer itself, but be
14973 sure to unlink it from the cache. Also release any associated storage
14974 and perform cache maintenance.
14976 Only used during partial symbol parsing. */
14979 free_stack_comp_unit (void *data
)
14981 struct dwarf2_cu
*cu
= data
;
14983 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14984 cu
->partial_dies
= NULL
;
14986 if (cu
->per_cu
!= NULL
)
14988 /* This compilation unit is on the stack in our caller, so we
14989 should not xfree it. Just unlink it. */
14990 cu
->per_cu
->cu
= NULL
;
14993 /* If we had a per-cu pointer, then we may have other compilation
14994 units loaded, so age them now. */
14995 age_cached_comp_units ();
14999 /* Free all cached compilation units. */
15002 free_cached_comp_units (void *data
)
15004 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15006 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15007 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15008 while (per_cu
!= NULL
)
15010 struct dwarf2_per_cu_data
*next_cu
;
15012 next_cu
= per_cu
->cu
->read_in_chain
;
15014 free_one_comp_unit (per_cu
->cu
);
15015 *last_chain
= next_cu
;
15021 /* Increase the age counter on each cached compilation unit, and free
15022 any that are too old. */
15025 age_cached_comp_units (void)
15027 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15029 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
15030 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15031 while (per_cu
!= NULL
)
15033 per_cu
->cu
->last_used
++;
15034 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
15035 dwarf2_mark (per_cu
->cu
);
15036 per_cu
= per_cu
->cu
->read_in_chain
;
15039 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15040 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15041 while (per_cu
!= NULL
)
15043 struct dwarf2_per_cu_data
*next_cu
;
15045 next_cu
= per_cu
->cu
->read_in_chain
;
15047 if (!per_cu
->cu
->mark
)
15049 free_one_comp_unit (per_cu
->cu
);
15050 *last_chain
= next_cu
;
15053 last_chain
= &per_cu
->cu
->read_in_chain
;
15059 /* Remove a single compilation unit from the cache. */
15062 free_one_cached_comp_unit (void *target_cu
)
15064 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15066 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15067 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15068 while (per_cu
!= NULL
)
15070 struct dwarf2_per_cu_data
*next_cu
;
15072 next_cu
= per_cu
->cu
->read_in_chain
;
15074 if (per_cu
->cu
== target_cu
)
15076 free_one_comp_unit (per_cu
->cu
);
15077 *last_chain
= next_cu
;
15081 last_chain
= &per_cu
->cu
->read_in_chain
;
15087 /* Release all extra memory associated with OBJFILE. */
15090 dwarf2_free_objfile (struct objfile
*objfile
)
15092 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15094 if (dwarf2_per_objfile
== NULL
)
15097 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
15098 free_cached_comp_units (NULL
);
15100 if (dwarf2_per_objfile
->quick_file_names_table
)
15101 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
15103 /* Everything else should be on the objfile obstack. */
15106 /* A pair of DIE offset and GDB type pointer. We store these
15107 in a hash table separate from the DIEs, and preserve them
15108 when the DIEs are flushed out of cache. */
15110 struct dwarf2_offset_and_type
15112 unsigned int offset
;
15116 /* Hash function for a dwarf2_offset_and_type. */
15119 offset_and_type_hash (const void *item
)
15121 const struct dwarf2_offset_and_type
*ofs
= item
;
15123 return ofs
->offset
;
15126 /* Equality function for a dwarf2_offset_and_type. */
15129 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
15131 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
15132 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
15134 return ofs_lhs
->offset
== ofs_rhs
->offset
;
15137 /* Set the type associated with DIE to TYPE. Save it in CU's hash
15138 table if necessary. For convenience, return TYPE.
15140 The DIEs reading must have careful ordering to:
15141 * Not cause infite loops trying to read in DIEs as a prerequisite for
15142 reading current DIE.
15143 * Not trying to dereference contents of still incompletely read in types
15144 while reading in other DIEs.
15145 * Enable referencing still incompletely read in types just by a pointer to
15146 the type without accessing its fields.
15148 Therefore caller should follow these rules:
15149 * Try to fetch any prerequisite types we may need to build this DIE type
15150 before building the type and calling set_die_type.
15151 * After building type call set_die_type for current DIE as soon as
15152 possible before fetching more types to complete the current type.
15153 * Make the type as complete as possible before fetching more types. */
15155 static struct type
*
15156 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
15158 struct dwarf2_offset_and_type
**slot
, ofs
;
15159 struct objfile
*objfile
= cu
->objfile
;
15160 htab_t
*type_hash_ptr
;
15162 /* For Ada types, make sure that the gnat-specific data is always
15163 initialized (if not already set). There are a few types where
15164 we should not be doing so, because the type-specific area is
15165 already used to hold some other piece of info (eg: TYPE_CODE_FLT
15166 where the type-specific area is used to store the floatformat).
15167 But this is not a problem, because the gnat-specific information
15168 is actually not needed for these types. */
15169 if (need_gnat_info (cu
)
15170 && TYPE_CODE (type
) != TYPE_CODE_FUNC
15171 && TYPE_CODE (type
) != TYPE_CODE_FLT
15172 && !HAVE_GNAT_AUX_INFO (type
))
15173 INIT_GNAT_SPECIFIC (type
);
15175 if (cu
->per_cu
->from_debug_types
)
15176 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
15178 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
15180 if (*type_hash_ptr
== NULL
)
15183 = htab_create_alloc_ex (127,
15184 offset_and_type_hash
,
15185 offset_and_type_eq
,
15187 &objfile
->objfile_obstack
,
15188 hashtab_obstack_allocate
,
15189 dummy_obstack_deallocate
);
15192 ofs
.offset
= die
->offset
;
15194 slot
= (struct dwarf2_offset_and_type
**)
15195 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
15197 complaint (&symfile_complaints
,
15198 _("A problem internal to GDB: DIE 0x%x has type already set"),
15200 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
15205 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
15206 table, or return NULL if the die does not have a saved type. */
15208 static struct type
*
15209 get_die_type_at_offset (unsigned int offset
,
15210 struct dwarf2_per_cu_data
*per_cu
)
15212 struct dwarf2_offset_and_type
*slot
, ofs
;
15215 if (per_cu
->from_debug_types
)
15216 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
15218 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
15219 if (type_hash
== NULL
)
15222 ofs
.offset
= offset
;
15223 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
15230 /* Look up the type for DIE in the appropriate type_hash table,
15231 or return NULL if DIE does not have a saved type. */
15233 static struct type
*
15234 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15236 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
15239 /* Add a dependence relationship from CU to REF_PER_CU. */
15242 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
15243 struct dwarf2_per_cu_data
*ref_per_cu
)
15247 if (cu
->dependencies
== NULL
)
15249 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
15250 NULL
, &cu
->comp_unit_obstack
,
15251 hashtab_obstack_allocate
,
15252 dummy_obstack_deallocate
);
15254 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
15256 *slot
= ref_per_cu
;
15259 /* Subroutine of dwarf2_mark to pass to htab_traverse.
15260 Set the mark field in every compilation unit in the
15261 cache that we must keep because we are keeping CU. */
15264 dwarf2_mark_helper (void **slot
, void *data
)
15266 struct dwarf2_per_cu_data
*per_cu
;
15268 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
15269 if (per_cu
->cu
->mark
)
15271 per_cu
->cu
->mark
= 1;
15273 if (per_cu
->cu
->dependencies
!= NULL
)
15274 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15279 /* Set the mark field in CU and in every other compilation unit in the
15280 cache that we must keep because we are keeping CU. */
15283 dwarf2_mark (struct dwarf2_cu
*cu
)
15288 if (cu
->dependencies
!= NULL
)
15289 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15293 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
15297 per_cu
->cu
->mark
= 0;
15298 per_cu
= per_cu
->cu
->read_in_chain
;
15302 /* Trivial hash function for partial_die_info: the hash value of a DIE
15303 is its offset in .debug_info for this objfile. */
15306 partial_die_hash (const void *item
)
15308 const struct partial_die_info
*part_die
= item
;
15310 return part_die
->offset
;
15313 /* Trivial comparison function for partial_die_info structures: two DIEs
15314 are equal if they have the same offset. */
15317 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
15319 const struct partial_die_info
*part_die_lhs
= item_lhs
;
15320 const struct partial_die_info
*part_die_rhs
= item_rhs
;
15322 return part_die_lhs
->offset
== part_die_rhs
->offset
;
15325 static struct cmd_list_element
*set_dwarf2_cmdlist
;
15326 static struct cmd_list_element
*show_dwarf2_cmdlist
;
15329 set_dwarf2_cmd (char *args
, int from_tty
)
15331 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
15335 show_dwarf2_cmd (char *args
, int from_tty
)
15337 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
15340 /* If section described by INFO was mmapped, munmap it now. */
15343 munmap_section_buffer (struct dwarf2_section_info
*info
)
15345 if (info
->was_mmapped
)
15348 intptr_t begin
= (intptr_t) info
->buffer
;
15349 intptr_t map_begin
= begin
& ~(pagesize
- 1);
15350 size_t map_length
= info
->size
+ begin
- map_begin
;
15352 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
15354 /* Without HAVE_MMAP, we should never be here to begin with. */
15355 gdb_assert_not_reached ("no mmap support");
15360 /* munmap debug sections for OBJFILE, if necessary. */
15363 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
15365 struct dwarf2_per_objfile
*data
= d
;
15367 /* This is sorted according to the order they're defined in to make it easier
15368 to keep in sync. */
15369 munmap_section_buffer (&data
->info
);
15370 munmap_section_buffer (&data
->abbrev
);
15371 munmap_section_buffer (&data
->line
);
15372 munmap_section_buffer (&data
->loc
);
15373 munmap_section_buffer (&data
->macinfo
);
15374 munmap_section_buffer (&data
->str
);
15375 munmap_section_buffer (&data
->ranges
);
15376 munmap_section_buffer (&data
->types
);
15377 munmap_section_buffer (&data
->frame
);
15378 munmap_section_buffer (&data
->eh_frame
);
15379 munmap_section_buffer (&data
->gdb_index
);
15383 /* The "save gdb-index" command. */
15385 /* The contents of the hash table we create when building the string
15387 struct strtab_entry
15389 offset_type offset
;
15393 /* Hash function for a strtab_entry.
15395 Function is used only during write_hash_table so no index format backward
15396 compatibility is needed. */
15399 hash_strtab_entry (const void *e
)
15401 const struct strtab_entry
*entry
= e
;
15402 return mapped_index_string_hash (INT_MAX
, entry
->str
);
15405 /* Equality function for a strtab_entry. */
15408 eq_strtab_entry (const void *a
, const void *b
)
15410 const struct strtab_entry
*ea
= a
;
15411 const struct strtab_entry
*eb
= b
;
15412 return !strcmp (ea
->str
, eb
->str
);
15415 /* Create a strtab_entry hash table. */
15418 create_strtab (void)
15420 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
15421 xfree
, xcalloc
, xfree
);
15424 /* Add a string to the constant pool. Return the string's offset in
15428 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
15431 struct strtab_entry entry
;
15432 struct strtab_entry
*result
;
15435 slot
= htab_find_slot (table
, &entry
, INSERT
);
15440 result
= XNEW (struct strtab_entry
);
15441 result
->offset
= obstack_object_size (cpool
);
15443 obstack_grow_str0 (cpool
, str
);
15446 return result
->offset
;
15449 /* An entry in the symbol table. */
15450 struct symtab_index_entry
15452 /* The name of the symbol. */
15454 /* The offset of the name in the constant pool. */
15455 offset_type index_offset
;
15456 /* A sorted vector of the indices of all the CUs that hold an object
15458 VEC (offset_type
) *cu_indices
;
15461 /* The symbol table. This is a power-of-2-sized hash table. */
15462 struct mapped_symtab
15464 offset_type n_elements
;
15466 struct symtab_index_entry
**data
;
15469 /* Hash function for a symtab_index_entry. */
15472 hash_symtab_entry (const void *e
)
15474 const struct symtab_index_entry
*entry
= e
;
15475 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
15476 sizeof (offset_type
) * VEC_length (offset_type
,
15477 entry
->cu_indices
),
15481 /* Equality function for a symtab_index_entry. */
15484 eq_symtab_entry (const void *a
, const void *b
)
15486 const struct symtab_index_entry
*ea
= a
;
15487 const struct symtab_index_entry
*eb
= b
;
15488 int len
= VEC_length (offset_type
, ea
->cu_indices
);
15489 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
15491 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
15492 VEC_address (offset_type
, eb
->cu_indices
),
15493 sizeof (offset_type
) * len
);
15496 /* Destroy a symtab_index_entry. */
15499 delete_symtab_entry (void *p
)
15501 struct symtab_index_entry
*entry
= p
;
15502 VEC_free (offset_type
, entry
->cu_indices
);
15506 /* Create a hash table holding symtab_index_entry objects. */
15509 create_symbol_hash_table (void)
15511 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
15512 delete_symtab_entry
, xcalloc
, xfree
);
15515 /* Create a new mapped symtab object. */
15517 static struct mapped_symtab
*
15518 create_mapped_symtab (void)
15520 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
15521 symtab
->n_elements
= 0;
15522 symtab
->size
= 1024;
15523 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15527 /* Destroy a mapped_symtab. */
15530 cleanup_mapped_symtab (void *p
)
15532 struct mapped_symtab
*symtab
= p
;
15533 /* The contents of the array are freed when the other hash table is
15535 xfree (symtab
->data
);
15539 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
15542 Function is used only during write_hash_table so no index format backward
15543 compatibility is needed. */
15545 static struct symtab_index_entry
**
15546 find_slot (struct mapped_symtab
*symtab
, const char *name
)
15548 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
15550 index
= hash
& (symtab
->size
- 1);
15551 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
15555 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
15556 return &symtab
->data
[index
];
15557 index
= (index
+ step
) & (symtab
->size
- 1);
15561 /* Expand SYMTAB's hash table. */
15564 hash_expand (struct mapped_symtab
*symtab
)
15566 offset_type old_size
= symtab
->size
;
15568 struct symtab_index_entry
**old_entries
= symtab
->data
;
15571 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15573 for (i
= 0; i
< old_size
; ++i
)
15575 if (old_entries
[i
])
15577 struct symtab_index_entry
**slot
= find_slot (symtab
,
15578 old_entries
[i
]->name
);
15579 *slot
= old_entries
[i
];
15583 xfree (old_entries
);
15586 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
15587 is the index of the CU in which the symbol appears. */
15590 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
15591 offset_type cu_index
)
15593 struct symtab_index_entry
**slot
;
15595 ++symtab
->n_elements
;
15596 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
15597 hash_expand (symtab
);
15599 slot
= find_slot (symtab
, name
);
15602 *slot
= XNEW (struct symtab_index_entry
);
15603 (*slot
)->name
= name
;
15604 (*slot
)->cu_indices
= NULL
;
15606 /* Don't push an index twice. Due to how we add entries we only
15607 have to check the last one. */
15608 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
15609 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
15610 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
15613 /* Add a vector of indices to the constant pool. */
15616 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
15617 struct symtab_index_entry
*entry
)
15621 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
15624 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
15625 offset_type val
= MAYBE_SWAP (len
);
15630 entry
->index_offset
= obstack_object_size (cpool
);
15632 obstack_grow (cpool
, &val
, sizeof (val
));
15634 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
15637 val
= MAYBE_SWAP (iter
);
15638 obstack_grow (cpool
, &val
, sizeof (val
));
15643 struct symtab_index_entry
*old_entry
= *slot
;
15644 entry
->index_offset
= old_entry
->index_offset
;
15647 return entry
->index_offset
;
15650 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15651 constant pool entries going into the obstack CPOOL. */
15654 write_hash_table (struct mapped_symtab
*symtab
,
15655 struct obstack
*output
, struct obstack
*cpool
)
15658 htab_t symbol_hash_table
;
15661 symbol_hash_table
= create_symbol_hash_table ();
15662 str_table
= create_strtab ();
15664 /* We add all the index vectors to the constant pool first, to
15665 ensure alignment is ok. */
15666 for (i
= 0; i
< symtab
->size
; ++i
)
15668 if (symtab
->data
[i
])
15669 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
15672 /* Now write out the hash table. */
15673 for (i
= 0; i
< symtab
->size
; ++i
)
15675 offset_type str_off
, vec_off
;
15677 if (symtab
->data
[i
])
15679 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
15680 vec_off
= symtab
->data
[i
]->index_offset
;
15684 /* While 0 is a valid constant pool index, it is not valid
15685 to have 0 for both offsets. */
15690 str_off
= MAYBE_SWAP (str_off
);
15691 vec_off
= MAYBE_SWAP (vec_off
);
15693 obstack_grow (output
, &str_off
, sizeof (str_off
));
15694 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
15697 htab_delete (str_table
);
15698 htab_delete (symbol_hash_table
);
15701 /* Struct to map psymtab to CU index in the index file. */
15702 struct psymtab_cu_index_map
15704 struct partial_symtab
*psymtab
;
15705 unsigned int cu_index
;
15709 hash_psymtab_cu_index (const void *item
)
15711 const struct psymtab_cu_index_map
*map
= item
;
15713 return htab_hash_pointer (map
->psymtab
);
15717 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
15719 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
15720 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
15722 return lhs
->psymtab
== rhs
->psymtab
;
15725 /* Helper struct for building the address table. */
15726 struct addrmap_index_data
15728 struct objfile
*objfile
;
15729 struct obstack
*addr_obstack
;
15730 htab_t cu_index_htab
;
15732 /* Non-zero if the previous_* fields are valid.
15733 We can't write an entry until we see the next entry (since it is only then
15734 that we know the end of the entry). */
15735 int previous_valid
;
15736 /* Index of the CU in the table of all CUs in the index file. */
15737 unsigned int previous_cu_index
;
15738 /* Start address of the CU. */
15739 CORE_ADDR previous_cu_start
;
15742 /* Write an address entry to OBSTACK. */
15745 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
15746 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
15748 offset_type cu_index_to_write
;
15750 CORE_ADDR baseaddr
;
15752 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15754 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
15755 obstack_grow (obstack
, addr
, 8);
15756 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
15757 obstack_grow (obstack
, addr
, 8);
15758 cu_index_to_write
= MAYBE_SWAP (cu_index
);
15759 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
15762 /* Worker function for traversing an addrmap to build the address table. */
15765 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
15767 struct addrmap_index_data
*data
= datap
;
15768 struct partial_symtab
*pst
= obj
;
15769 offset_type cu_index
;
15772 if (data
->previous_valid
)
15773 add_address_entry (data
->objfile
, data
->addr_obstack
,
15774 data
->previous_cu_start
, start_addr
,
15775 data
->previous_cu_index
);
15777 data
->previous_cu_start
= start_addr
;
15780 struct psymtab_cu_index_map find_map
, *map
;
15781 find_map
.psymtab
= pst
;
15782 map
= htab_find (data
->cu_index_htab
, &find_map
);
15783 gdb_assert (map
!= NULL
);
15784 data
->previous_cu_index
= map
->cu_index
;
15785 data
->previous_valid
= 1;
15788 data
->previous_valid
= 0;
15793 /* Write OBJFILE's address map to OBSTACK.
15794 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
15795 in the index file. */
15798 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
15799 htab_t cu_index_htab
)
15801 struct addrmap_index_data addrmap_index_data
;
15803 /* When writing the address table, we have to cope with the fact that
15804 the addrmap iterator only provides the start of a region; we have to
15805 wait until the next invocation to get the start of the next region. */
15807 addrmap_index_data
.objfile
= objfile
;
15808 addrmap_index_data
.addr_obstack
= obstack
;
15809 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
15810 addrmap_index_data
.previous_valid
= 0;
15812 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
15813 &addrmap_index_data
);
15815 /* It's highly unlikely the last entry (end address = 0xff...ff)
15816 is valid, but we should still handle it.
15817 The end address is recorded as the start of the next region, but that
15818 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
15820 if (addrmap_index_data
.previous_valid
)
15821 add_address_entry (objfile
, obstack
,
15822 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
15823 addrmap_index_data
.previous_cu_index
);
15826 /* Add a list of partial symbols to SYMTAB. */
15829 write_psymbols (struct mapped_symtab
*symtab
,
15831 struct partial_symbol
**psymp
,
15833 offset_type cu_index
,
15836 for (; count
-- > 0; ++psymp
)
15838 void **slot
, *lookup
;
15840 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
15841 error (_("Ada is not currently supported by the index"));
15843 /* We only want to add a given psymbol once. However, we also
15844 want to account for whether it is global or static. So, we
15845 may add it twice, using slightly different values. */
15848 uintptr_t val
= 1 | (uintptr_t) *psymp
;
15850 lookup
= (void *) val
;
15855 /* Only add a given psymbol once. */
15856 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
15860 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
15865 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
15866 exception if there is an error. */
15869 write_obstack (FILE *file
, struct obstack
*obstack
)
15871 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
15873 != obstack_object_size (obstack
))
15874 error (_("couldn't data write to file"));
15877 /* Unlink a file if the argument is not NULL. */
15880 unlink_if_set (void *p
)
15882 char **filename
= p
;
15884 unlink (*filename
);
15887 /* A helper struct used when iterating over debug_types. */
15888 struct signatured_type_index_data
15890 struct objfile
*objfile
;
15891 struct mapped_symtab
*symtab
;
15892 struct obstack
*types_list
;
15897 /* A helper function that writes a single signatured_type to an
15901 write_one_signatured_type (void **slot
, void *d
)
15903 struct signatured_type_index_data
*info
= d
;
15904 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
15905 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
15906 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15909 write_psymbols (info
->symtab
,
15911 info
->objfile
->global_psymbols
.list
15912 + psymtab
->globals_offset
,
15913 psymtab
->n_global_syms
, info
->cu_index
,
15915 write_psymbols (info
->symtab
,
15917 info
->objfile
->static_psymbols
.list
15918 + psymtab
->statics_offset
,
15919 psymtab
->n_static_syms
, info
->cu_index
,
15922 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->offset
);
15923 obstack_grow (info
->types_list
, val
, 8);
15924 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
15925 obstack_grow (info
->types_list
, val
, 8);
15926 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
15927 obstack_grow (info
->types_list
, val
, 8);
15934 /* A cleanup function for an htab_t. */
15937 cleanup_htab (void *arg
)
15942 /* Create an index file for OBJFILE in the directory DIR. */
15945 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
15947 struct cleanup
*cleanup
;
15948 char *filename
, *cleanup_filename
;
15949 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
15950 struct obstack cu_list
, types_cu_list
;
15953 struct mapped_symtab
*symtab
;
15954 offset_type val
, size_of_contents
, total_len
;
15958 htab_t cu_index_htab
;
15959 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
15961 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
15964 if (dwarf2_per_objfile
->using_index
)
15965 error (_("Cannot use an index to create the index"));
15967 if (stat (objfile
->name
, &st
) < 0)
15968 perror_with_name (objfile
->name
);
15970 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
15971 INDEX_SUFFIX
, (char *) NULL
);
15972 cleanup
= make_cleanup (xfree
, filename
);
15974 out_file
= fopen (filename
, "wb");
15976 error (_("Can't open `%s' for writing"), filename
);
15978 cleanup_filename
= filename
;
15979 make_cleanup (unlink_if_set
, &cleanup_filename
);
15981 symtab
= create_mapped_symtab ();
15982 make_cleanup (cleanup_mapped_symtab
, symtab
);
15984 obstack_init (&addr_obstack
);
15985 make_cleanup_obstack_free (&addr_obstack
);
15987 obstack_init (&cu_list
);
15988 make_cleanup_obstack_free (&cu_list
);
15990 obstack_init (&types_cu_list
);
15991 make_cleanup_obstack_free (&types_cu_list
);
15993 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
15994 NULL
, xcalloc
, xfree
);
15995 make_cleanup (cleanup_htab
, psyms_seen
);
15997 /* While we're scanning CU's create a table that maps a psymtab pointer
15998 (which is what addrmap records) to its index (which is what is recorded
15999 in the index file). This will later be needed to write the address
16001 cu_index_htab
= htab_create_alloc (100,
16002 hash_psymtab_cu_index
,
16003 eq_psymtab_cu_index
,
16004 NULL
, xcalloc
, xfree
);
16005 make_cleanup (cleanup_htab
, cu_index_htab
);
16006 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
16007 xmalloc (sizeof (struct psymtab_cu_index_map
)
16008 * dwarf2_per_objfile
->n_comp_units
);
16009 make_cleanup (xfree
, psymtab_cu_index_map
);
16011 /* The CU list is already sorted, so we don't need to do additional
16012 work here. Also, the debug_types entries do not appear in
16013 all_comp_units, but only in their own hash table. */
16014 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
16016 struct dwarf2_per_cu_data
*per_cu
16017 = dwarf2_per_objfile
->all_comp_units
[i
];
16018 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16020 struct psymtab_cu_index_map
*map
;
16023 write_psymbols (symtab
,
16025 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
16026 psymtab
->n_global_syms
, i
,
16028 write_psymbols (symtab
,
16030 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
16031 psymtab
->n_static_syms
, i
,
16034 map
= &psymtab_cu_index_map
[i
];
16035 map
->psymtab
= psymtab
;
16037 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
16038 gdb_assert (slot
!= NULL
);
16039 gdb_assert (*slot
== NULL
);
16042 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
16043 obstack_grow (&cu_list
, val
, 8);
16044 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
16045 obstack_grow (&cu_list
, val
, 8);
16048 /* Dump the address map. */
16049 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
16051 /* Write out the .debug_type entries, if any. */
16052 if (dwarf2_per_objfile
->signatured_types
)
16054 struct signatured_type_index_data sig_data
;
16056 sig_data
.objfile
= objfile
;
16057 sig_data
.symtab
= symtab
;
16058 sig_data
.types_list
= &types_cu_list
;
16059 sig_data
.psyms_seen
= psyms_seen
;
16060 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
16061 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
16062 write_one_signatured_type
, &sig_data
);
16065 obstack_init (&constant_pool
);
16066 make_cleanup_obstack_free (&constant_pool
);
16067 obstack_init (&symtab_obstack
);
16068 make_cleanup_obstack_free (&symtab_obstack
);
16069 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
16071 obstack_init (&contents
);
16072 make_cleanup_obstack_free (&contents
);
16073 size_of_contents
= 6 * sizeof (offset_type
);
16074 total_len
= size_of_contents
;
16076 /* The version number. */
16077 val
= MAYBE_SWAP (5);
16078 obstack_grow (&contents
, &val
, sizeof (val
));
16080 /* The offset of the CU list from the start of the file. */
16081 val
= MAYBE_SWAP (total_len
);
16082 obstack_grow (&contents
, &val
, sizeof (val
));
16083 total_len
+= obstack_object_size (&cu_list
);
16085 /* The offset of the types CU list from the start of the file. */
16086 val
= MAYBE_SWAP (total_len
);
16087 obstack_grow (&contents
, &val
, sizeof (val
));
16088 total_len
+= obstack_object_size (&types_cu_list
);
16090 /* The offset of the address table from the start of the file. */
16091 val
= MAYBE_SWAP (total_len
);
16092 obstack_grow (&contents
, &val
, sizeof (val
));
16093 total_len
+= obstack_object_size (&addr_obstack
);
16095 /* The offset of the symbol table from the start of the file. */
16096 val
= MAYBE_SWAP (total_len
);
16097 obstack_grow (&contents
, &val
, sizeof (val
));
16098 total_len
+= obstack_object_size (&symtab_obstack
);
16100 /* The offset of the constant pool from the start of the file. */
16101 val
= MAYBE_SWAP (total_len
);
16102 obstack_grow (&contents
, &val
, sizeof (val
));
16103 total_len
+= obstack_object_size (&constant_pool
);
16105 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
16107 write_obstack (out_file
, &contents
);
16108 write_obstack (out_file
, &cu_list
);
16109 write_obstack (out_file
, &types_cu_list
);
16110 write_obstack (out_file
, &addr_obstack
);
16111 write_obstack (out_file
, &symtab_obstack
);
16112 write_obstack (out_file
, &constant_pool
);
16116 /* We want to keep the file, so we set cleanup_filename to NULL
16117 here. See unlink_if_set. */
16118 cleanup_filename
= NULL
;
16120 do_cleanups (cleanup
);
16123 /* Implementation of the `save gdb-index' command.
16125 Note that the file format used by this command is documented in the
16126 GDB manual. Any changes here must be documented there. */
16129 save_gdb_index_command (char *arg
, int from_tty
)
16131 struct objfile
*objfile
;
16134 error (_("usage: save gdb-index DIRECTORY"));
16136 ALL_OBJFILES (objfile
)
16140 /* If the objfile does not correspond to an actual file, skip it. */
16141 if (stat (objfile
->name
, &st
) < 0)
16144 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16145 if (dwarf2_per_objfile
)
16147 volatile struct gdb_exception except
;
16149 TRY_CATCH (except
, RETURN_MASK_ERROR
)
16151 write_psymtabs_to_index (objfile
, arg
);
16153 if (except
.reason
< 0)
16154 exception_fprintf (gdb_stderr
, except
,
16155 _("Error while writing index for `%s': "),
16163 int dwarf2_always_disassemble
;
16166 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
16167 struct cmd_list_element
*c
, const char *value
)
16169 fprintf_filtered (file
,
16170 _("Whether to always disassemble "
16171 "DWARF expressions is %s.\n"),
16175 void _initialize_dwarf2_read (void);
16178 _initialize_dwarf2_read (void)
16180 struct cmd_list_element
*c
;
16182 dwarf2_objfile_data_key
16183 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
16185 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
16186 Set DWARF 2 specific variables.\n\
16187 Configure DWARF 2 variables such as the cache size"),
16188 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
16189 0/*allow-unknown*/, &maintenance_set_cmdlist
);
16191 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
16192 Show DWARF 2 specific variables\n\
16193 Show DWARF 2 variables such as the cache size"),
16194 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
16195 0/*allow-unknown*/, &maintenance_show_cmdlist
);
16197 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
16198 &dwarf2_max_cache_age
, _("\
16199 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
16200 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
16201 A higher limit means that cached compilation units will be stored\n\
16202 in memory longer, and more total memory will be used. Zero disables\n\
16203 caching, which can slow down startup."),
16205 show_dwarf2_max_cache_age
,
16206 &set_dwarf2_cmdlist
,
16207 &show_dwarf2_cmdlist
);
16209 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
16210 &dwarf2_always_disassemble
, _("\
16211 Set whether `info address' always disassembles DWARF expressions."), _("\
16212 Show whether `info address' always disassembles DWARF expressions."), _("\
16213 When enabled, DWARF expressions are always printed in an assembly-like\n\
16214 syntax. When disabled, expressions will be printed in a more\n\
16215 conversational style, when possible."),
16217 show_dwarf2_always_disassemble
,
16218 &set_dwarf2_cmdlist
,
16219 &show_dwarf2_cmdlist
);
16221 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
16222 Set debugging of the dwarf2 DIE reader."), _("\
16223 Show debugging of the dwarf2 DIE reader."), _("\
16224 When enabled (non-zero), DIEs are dumped after they are read in.\n\
16225 The value is the maximum depth to print."),
16228 &setdebuglist
, &showdebuglist
);
16230 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
16232 Save a gdb-index file.\n\
16233 Usage: save gdb-index DIRECTORY"),
16235 set_cmd_completer (c
, filename_completer
);