1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2012 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
35 #include "gdb-demangle.h"
36 #include "expression.h"
37 #include "filenames.h" /* for DOSish file names */
40 #include "complaints.h"
42 #include "dwarf2expr.h"
43 #include "dwarf2loc.h"
44 #include "cp-support.h"
50 #include "typeprint.h"
53 #include "exceptions.h"
55 #include "completer.h"
62 #include "gdb_string.h"
63 #include "gdb_assert.h"
64 #include <sys/types.h>
71 #define MAP_FAILED ((void *) -1)
75 typedef struct symbol
*symbolp
;
78 /* .debug_line statement program prologue
79 Because of alignment constraints, this structure has padding and cannot
80 be mapped directly onto the beginning of the .debug_info section. */
81 typedef struct statement_prologue
83 unsigned int total_length
; /* byte length of the statement
85 unsigned short version
; /* version number -- 2 for DWARF
87 unsigned int prologue_length
; /* # bytes between prologue &
89 unsigned char minimum_instruction_length
; /* byte size of
91 unsigned char default_is_stmt
; /* initial value of is_stmt
94 unsigned char line_range
;
95 unsigned char opcode_base
; /* number assigned to first special
97 unsigned char *standard_opcode_lengths
;
101 /* When non-zero, dump DIEs after they are read in. */
102 static int dwarf2_die_debug
= 0;
104 /* When non-zero, cross-check physname against demangler. */
105 static int check_physname
= 0;
109 /* When set, the file that we're processing is known to have debugging
110 info for C++ namespaces. GCC 3.3.x did not produce this information,
111 but later versions do. */
113 static int processing_has_namespace_info
;
115 static const struct objfile_data
*dwarf2_objfile_data_key
;
117 struct dwarf2_section_info
122 /* Not NULL if the section was actually mmapped. */
124 /* Page aligned size of mmapped area. */
125 bfd_size_type map_len
;
126 /* True if we have tried to read this section. */
130 typedef struct dwarf2_section_info dwarf2_section_info_def
;
131 DEF_VEC_O (dwarf2_section_info_def
);
133 /* All offsets in the index are of this type. It must be
134 architecture-independent. */
135 typedef uint32_t offset_type
;
137 DEF_VEC_I (offset_type
);
139 /* A description of the mapped index. The file format is described in
140 a comment by the code that writes the index. */
143 /* Index data format version. */
146 /* The total length of the buffer. */
149 /* A pointer to the address table data. */
150 const gdb_byte
*address_table
;
152 /* Size of the address table data in bytes. */
153 offset_type address_table_size
;
155 /* The symbol table, implemented as a hash table. */
156 const offset_type
*symbol_table
;
158 /* Size in slots, each slot is 2 offset_types. */
159 offset_type symbol_table_slots
;
161 /* A pointer to the constant pool. */
162 const char *constant_pool
;
165 /* Collection of data recorded per objfile.
166 This hangs off of dwarf2_objfile_data_key. */
168 struct dwarf2_per_objfile
170 struct dwarf2_section_info info
;
171 struct dwarf2_section_info abbrev
;
172 struct dwarf2_section_info line
;
173 struct dwarf2_section_info loc
;
174 struct dwarf2_section_info macinfo
;
175 struct dwarf2_section_info macro
;
176 struct dwarf2_section_info str
;
177 struct dwarf2_section_info ranges
;
178 struct dwarf2_section_info frame
;
179 struct dwarf2_section_info eh_frame
;
180 struct dwarf2_section_info gdb_index
;
182 VEC (dwarf2_section_info_def
) *types
;
185 struct objfile
*objfile
;
187 /* A list of all the compilation units. This is used to locate
188 the target compilation unit of a particular reference. */
189 struct dwarf2_per_cu_data
**all_comp_units
;
191 /* The number of compilation units in ALL_COMP_UNITS. */
194 /* The number of .debug_types-related CUs. */
195 int n_type_comp_units
;
197 /* The .debug_types-related CUs. */
198 struct dwarf2_per_cu_data
**type_comp_units
;
200 /* A chain of compilation units that are currently read in, so that
201 they can be freed later. */
202 struct dwarf2_per_cu_data
*read_in_chain
;
204 /* A table mapping .debug_types signatures to its signatured_type entry.
205 This is NULL if the .debug_types section hasn't been read in yet. */
206 htab_t signatured_types
;
208 /* A flag indicating wether this objfile has a section loaded at a
210 int has_section_at_zero
;
212 /* True if we are using the mapped index,
213 or we are faking it for OBJF_READNOW's sake. */
214 unsigned char using_index
;
216 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
217 struct mapped_index
*index_table
;
219 /* When using index_table, this keeps track of all quick_file_names entries.
220 TUs can share line table entries with CUs or other TUs, and there can be
221 a lot more TUs than unique line tables, so we maintain a separate table
222 of all line table entries to support the sharing. */
223 htab_t quick_file_names_table
;
225 /* Set during partial symbol reading, to prevent queueing of full
227 int reading_partial_symbols
;
229 /* Table mapping type .debug_info DIE offsets to types.
230 This is NULL if not allocated yet.
231 It (currently) makes sense to allocate debug_types_type_hash lazily.
232 To keep things simple we allocate both lazily. */
233 htab_t debug_info_type_hash
;
235 /* Table mapping type .debug_types DIE offsets to types.
236 This is NULL if not allocated yet. */
237 htab_t debug_types_type_hash
;
240 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
242 /* Default names of the debugging sections. */
244 /* Note that if the debugging section has been compressed, it might
245 have a name like .zdebug_info. */
247 static const struct dwarf2_debug_sections dwarf2_elf_names
=
249 { ".debug_info", ".zdebug_info" },
250 { ".debug_abbrev", ".zdebug_abbrev" },
251 { ".debug_line", ".zdebug_line" },
252 { ".debug_loc", ".zdebug_loc" },
253 { ".debug_macinfo", ".zdebug_macinfo" },
254 { ".debug_macro", ".zdebug_macro" },
255 { ".debug_str", ".zdebug_str" },
256 { ".debug_ranges", ".zdebug_ranges" },
257 { ".debug_types", ".zdebug_types" },
258 { ".debug_frame", ".zdebug_frame" },
259 { ".eh_frame", NULL
},
260 { ".gdb_index", ".zgdb_index" },
264 /* local data types */
266 /* We hold several abbreviation tables in memory at the same time. */
267 #ifndef ABBREV_HASH_SIZE
268 #define ABBREV_HASH_SIZE 121
271 /* The data in a compilation unit header, after target2host
272 translation, looks like this. */
273 struct comp_unit_head
277 unsigned char addr_size
;
278 unsigned char signed_addr_p
;
279 unsigned int abbrev_offset
;
281 /* Size of file offsets; either 4 or 8. */
282 unsigned int offset_size
;
284 /* Size of the length field; either 4 or 12. */
285 unsigned int initial_length_size
;
287 /* Offset to the first byte of this compilation unit header in the
288 .debug_info section, for resolving relative reference dies. */
291 /* Offset to first die in this cu from the start of the cu.
292 This will be the first byte following the compilation unit header. */
293 unsigned int first_die_offset
;
296 /* Type used for delaying computation of method physnames.
297 See comments for compute_delayed_physnames. */
298 struct delayed_method_info
300 /* The type to which the method is attached, i.e., its parent class. */
303 /* The index of the method in the type's function fieldlists. */
306 /* The index of the method in the fieldlist. */
309 /* The name of the DIE. */
312 /* The DIE associated with this method. */
313 struct die_info
*die
;
316 typedef struct delayed_method_info delayed_method_info
;
317 DEF_VEC_O (delayed_method_info
);
319 /* Internal state when decoding a particular compilation unit. */
322 /* The objfile containing this compilation unit. */
323 struct objfile
*objfile
;
325 /* The header of the compilation unit. */
326 struct comp_unit_head header
;
328 /* Base address of this compilation unit. */
329 CORE_ADDR base_address
;
331 /* Non-zero if base_address has been set. */
334 /* The language we are debugging. */
335 enum language language
;
336 const struct language_defn
*language_defn
;
338 const char *producer
;
340 /* The generic symbol table building routines have separate lists for
341 file scope symbols and all all other scopes (local scopes). So
342 we need to select the right one to pass to add_symbol_to_list().
343 We do it by keeping a pointer to the correct list in list_in_scope.
345 FIXME: The original dwarf code just treated the file scope as the
346 first local scope, and all other local scopes as nested local
347 scopes, and worked fine. Check to see if we really need to
348 distinguish these in buildsym.c. */
349 struct pending
**list_in_scope
;
351 /* DWARF abbreviation table associated with this compilation unit. */
352 struct abbrev_info
**dwarf2_abbrevs
;
354 /* Storage for the abbrev table. */
355 struct obstack abbrev_obstack
;
357 /* Hash table holding all the loaded partial DIEs. */
360 /* Storage for things with the same lifetime as this read-in compilation
361 unit, including partial DIEs. */
362 struct obstack comp_unit_obstack
;
364 /* When multiple dwarf2_cu structures are living in memory, this field
365 chains them all together, so that they can be released efficiently.
366 We will probably also want a generation counter so that most-recently-used
367 compilation units are cached... */
368 struct dwarf2_per_cu_data
*read_in_chain
;
370 /* Backchain to our per_cu entry if the tree has been built. */
371 struct dwarf2_per_cu_data
*per_cu
;
373 /* How many compilation units ago was this CU last referenced? */
376 /* A hash table of die offsets for following references. */
379 /* Full DIEs if read in. */
380 struct die_info
*dies
;
382 /* A set of pointers to dwarf2_per_cu_data objects for compilation
383 units referenced by this one. Only set during full symbol processing;
384 partial symbol tables do not have dependencies. */
387 /* Header data from the line table, during full symbol processing. */
388 struct line_header
*line_header
;
390 /* A list of methods which need to have physnames computed
391 after all type information has been read. */
392 VEC (delayed_method_info
) *method_list
;
394 /* To be copied to symtab->call_site_htab. */
395 htab_t call_site_htab
;
397 /* Mark used when releasing cached dies. */
398 unsigned int mark
: 1;
400 /* This flag will be set if this compilation unit might include
401 inter-compilation-unit references. */
402 unsigned int has_form_ref_addr
: 1;
404 /* This flag will be set if this compilation unit includes any
405 DW_TAG_namespace DIEs. If we know that there are explicit
406 DIEs for namespaces, we don't need to try to infer them
407 from mangled names. */
408 unsigned int has_namespace_info
: 1;
410 /* This CU references .debug_loc. See the symtab->locations_valid field.
411 This test is imperfect as there may exist optimized debug code not using
412 any location list and still facing inlining issues if handled as
413 unoptimized code. For a future better test see GCC PR other/32998. */
414 unsigned int has_loclist
: 1;
417 /* Persistent data held for a compilation unit, even when not
418 processing it. We put a pointer to this structure in the
419 read_symtab_private field of the psymtab. */
421 struct dwarf2_per_cu_data
423 /* The start offset and length of this compilation unit. 2**29-1
424 bytes should suffice to store the length of any compilation unit
425 - if it doesn't, GDB will fall over anyway.
426 NOTE: Unlike comp_unit_head.length, this length includes
427 initial_length_size. */
429 unsigned int length
: 29;
431 /* Flag indicating this compilation unit will be read in before
432 any of the current compilation units are processed. */
433 unsigned int queued
: 1;
435 /* This flag will be set if we need to load absolutely all DIEs
436 for this compilation unit, instead of just the ones we think
437 are interesting. It gets set if we look for a DIE in the
438 hash table and don't find it. */
439 unsigned int load_all_dies
: 1;
441 /* Non-null if this CU is from .debug_types; in which case it points
442 to the section. Otherwise it's from .debug_info. */
443 struct dwarf2_section_info
*debug_types_section
;
445 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
446 of the CU cache it gets reset to NULL again. */
447 struct dwarf2_cu
*cu
;
449 /* The corresponding objfile.
450 Normally we can get the objfile from dwarf2_per_objfile.
451 However we can enter this file with just a "per_cu" handle. */
452 struct objfile
*objfile
;
454 /* When using partial symbol tables, the 'psymtab' field is active.
455 Otherwise the 'quick' field is active. */
458 /* The partial symbol table associated with this compilation unit,
459 or NULL for partial units (which do not have an associated
461 struct partial_symtab
*psymtab
;
463 /* Data needed by the "quick" functions. */
464 struct dwarf2_per_cu_quick_data
*quick
;
468 /* Entry in the signatured_types hash table. */
470 struct signatured_type
474 /* Offset in .debug_types of the type defined by this TU. */
475 unsigned int type_offset
;
477 /* The CU(/TU) of this type. */
478 struct dwarf2_per_cu_data per_cu
;
481 /* Struct used to pass misc. parameters to read_die_and_children, et
482 al. which are used for both .debug_info and .debug_types dies.
483 All parameters here are unchanging for the life of the call. This
484 struct exists to abstract away the constant parameters of die
487 struct die_reader_specs
489 /* The bfd of this objfile. */
492 /* The CU of the DIE we are parsing. */
493 struct dwarf2_cu
*cu
;
495 /* Pointer to start of section buffer.
496 This is either the start of .debug_info or .debug_types. */
497 const gdb_byte
*buffer
;
500 /* The line number information for a compilation unit (found in the
501 .debug_line section) begins with a "statement program header",
502 which contains the following information. */
505 unsigned int total_length
;
506 unsigned short version
;
507 unsigned int header_length
;
508 unsigned char minimum_instruction_length
;
509 unsigned char maximum_ops_per_instruction
;
510 unsigned char default_is_stmt
;
512 unsigned char line_range
;
513 unsigned char opcode_base
;
515 /* standard_opcode_lengths[i] is the number of operands for the
516 standard opcode whose value is i. This means that
517 standard_opcode_lengths[0] is unused, and the last meaningful
518 element is standard_opcode_lengths[opcode_base - 1]. */
519 unsigned char *standard_opcode_lengths
;
521 /* The include_directories table. NOTE! These strings are not
522 allocated with xmalloc; instead, they are pointers into
523 debug_line_buffer. If you try to free them, `free' will get
525 unsigned int num_include_dirs
, include_dirs_size
;
528 /* The file_names table. NOTE! These strings are not allocated
529 with xmalloc; instead, they are pointers into debug_line_buffer.
530 Don't try to free them directly. */
531 unsigned int num_file_names
, file_names_size
;
535 unsigned int dir_index
;
536 unsigned int mod_time
;
538 int included_p
; /* Non-zero if referenced by the Line Number Program. */
539 struct symtab
*symtab
; /* The associated symbol table, if any. */
542 /* The start and end of the statement program following this
543 header. These point into dwarf2_per_objfile->line_buffer. */
544 gdb_byte
*statement_program_start
, *statement_program_end
;
547 /* When we construct a partial symbol table entry we only
548 need this much information. */
549 struct partial_die_info
551 /* Offset of this DIE. */
554 /* DWARF-2 tag for this DIE. */
555 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
557 /* Assorted flags describing the data found in this DIE. */
558 unsigned int has_children
: 1;
559 unsigned int is_external
: 1;
560 unsigned int is_declaration
: 1;
561 unsigned int has_type
: 1;
562 unsigned int has_specification
: 1;
563 unsigned int has_pc_info
: 1;
565 /* Flag set if the SCOPE field of this structure has been
567 unsigned int scope_set
: 1;
569 /* Flag set if the DIE has a byte_size attribute. */
570 unsigned int has_byte_size
: 1;
572 /* Flag set if any of the DIE's children are template arguments. */
573 unsigned int has_template_arguments
: 1;
575 /* Flag set if fixup_partial_die has been called on this die. */
576 unsigned int fixup_called
: 1;
578 /* The name of this DIE. Normally the value of DW_AT_name, but
579 sometimes a default name for unnamed DIEs. */
582 /* The linkage name, if present. */
583 const char *linkage_name
;
585 /* The scope to prepend to our children. This is generally
586 allocated on the comp_unit_obstack, so will disappear
587 when this compilation unit leaves the cache. */
590 /* The location description associated with this DIE, if any. */
591 struct dwarf_block
*locdesc
;
593 /* If HAS_PC_INFO, the PC range associated with this DIE. */
597 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
598 DW_AT_sibling, if any. */
599 /* NOTE: This member isn't strictly necessary, read_partial_die could
600 return DW_AT_sibling values to its caller load_partial_dies. */
603 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
604 DW_AT_specification (or DW_AT_abstract_origin or
606 unsigned int spec_offset
;
608 /* Pointers to this DIE's parent, first child, and next sibling,
610 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
613 /* This data structure holds the information of an abbrev. */
616 unsigned int number
; /* number identifying abbrev */
617 enum dwarf_tag tag
; /* dwarf tag */
618 unsigned short has_children
; /* boolean */
619 unsigned short num_attrs
; /* number of attributes */
620 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
621 struct abbrev_info
*next
; /* next in chain */
626 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
627 ENUM_BITFIELD(dwarf_form
) form
: 16;
630 /* Attributes have a name and a value. */
633 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
634 ENUM_BITFIELD(dwarf_form
) form
: 15;
636 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
637 field should be in u.str (existing only for DW_STRING) but it is kept
638 here for better struct attribute alignment. */
639 unsigned int string_is_canonical
: 1;
644 struct dwarf_block
*blk
;
648 struct signatured_type
*signatured_type
;
653 /* This data structure holds a complete die structure. */
656 /* DWARF-2 tag for this DIE. */
657 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
659 /* Number of attributes */
660 unsigned char num_attrs
;
662 /* True if we're presently building the full type name for the
663 type derived from this DIE. */
664 unsigned char building_fullname
: 1;
669 /* Offset in .debug_info or .debug_types section. */
672 /* The dies in a compilation unit form an n-ary tree. PARENT
673 points to this die's parent; CHILD points to the first child of
674 this node; and all the children of a given node are chained
675 together via their SIBLING fields. */
676 struct die_info
*child
; /* Its first child, if any. */
677 struct die_info
*sibling
; /* Its next sibling, if any. */
678 struct die_info
*parent
; /* Its parent, if any. */
680 /* An array of attributes, with NUM_ATTRS elements. There may be
681 zero, but it's not common and zero-sized arrays are not
682 sufficiently portable C. */
683 struct attribute attrs
[1];
686 /* Get at parts of an attribute structure. */
688 #define DW_STRING(attr) ((attr)->u.str)
689 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
690 #define DW_UNSND(attr) ((attr)->u.unsnd)
691 #define DW_BLOCK(attr) ((attr)->u.blk)
692 #define DW_SND(attr) ((attr)->u.snd)
693 #define DW_ADDR(attr) ((attr)->u.addr)
694 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
696 /* Blocks are a bunch of untyped bytes. */
701 /* Valid only if SIZE is not zero. */
705 #ifndef ATTR_ALLOC_CHUNK
706 #define ATTR_ALLOC_CHUNK 4
709 /* Allocate fields for structs, unions and enums in this size. */
710 #ifndef DW_FIELD_ALLOC_CHUNK
711 #define DW_FIELD_ALLOC_CHUNK 4
714 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
715 but this would require a corresponding change in unpack_field_as_long
717 static int bits_per_byte
= 8;
719 /* The routines that read and process dies for a C struct or C++ class
720 pass lists of data member fields and lists of member function fields
721 in an instance of a field_info structure, as defined below. */
724 /* List of data member and baseclasses fields. */
727 struct nextfield
*next
;
732 *fields
, *baseclasses
;
734 /* Number of fields (including baseclasses). */
737 /* Number of baseclasses. */
740 /* Set if the accesibility of one of the fields is not public. */
741 int non_public_fields
;
743 /* Member function fields array, entries are allocated in the order they
744 are encountered in the object file. */
747 struct nextfnfield
*next
;
748 struct fn_field fnfield
;
752 /* Member function fieldlist array, contains name of possibly overloaded
753 member function, number of overloaded member functions and a pointer
754 to the head of the member function field chain. */
759 struct nextfnfield
*head
;
763 /* Number of entries in the fnfieldlists array. */
766 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
767 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
768 struct typedef_field_list
770 struct typedef_field field
;
771 struct typedef_field_list
*next
;
774 unsigned typedef_field_list_count
;
777 /* One item on the queue of compilation units to read in full symbols
779 struct dwarf2_queue_item
781 struct dwarf2_per_cu_data
*per_cu
;
782 struct dwarf2_queue_item
*next
;
785 /* The current queue. */
786 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
788 /* Loaded secondary compilation units are kept in memory until they
789 have not been referenced for the processing of this many
790 compilation units. Set this to zero to disable caching. Cache
791 sizes of up to at least twenty will improve startup time for
792 typical inter-CU-reference binaries, at an obvious memory cost. */
793 static int dwarf2_max_cache_age
= 5;
795 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
796 struct cmd_list_element
*c
, const char *value
)
798 fprintf_filtered (file
, _("The upper bound on the age of cached "
799 "dwarf2 compilation units is %s.\n"),
804 /* Various complaints about symbol reading that don't abort the process. */
807 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
809 complaint (&symfile_complaints
,
810 _("statement list doesn't fit in .debug_line section"));
814 dwarf2_debug_line_missing_file_complaint (void)
816 complaint (&symfile_complaints
,
817 _(".debug_line section has line data without a file"));
821 dwarf2_debug_line_missing_end_sequence_complaint (void)
823 complaint (&symfile_complaints
,
824 _(".debug_line section has line "
825 "program sequence without an end"));
829 dwarf2_complex_location_expr_complaint (void)
831 complaint (&symfile_complaints
, _("location expression too complex"));
835 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
838 complaint (&symfile_complaints
,
839 _("const value length mismatch for '%s', got %d, expected %d"),
844 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
846 complaint (&symfile_complaints
,
847 _("macro info runs off end of `%s' section"),
848 section
->asection
->name
);
852 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
854 complaint (&symfile_complaints
,
855 _("macro debug info contains a "
856 "malformed macro definition:\n`%s'"),
861 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
863 complaint (&symfile_complaints
,
864 _("invalid attribute class or form for '%s' in '%s'"),
868 /* local function prototypes */
870 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
872 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
875 static void dwarf2_find_base_address (struct die_info
*die
,
876 struct dwarf2_cu
*cu
);
878 static void dwarf2_build_psymtabs_hard (struct objfile
*);
880 static void scan_partial_symbols (struct partial_die_info
*,
881 CORE_ADDR
*, CORE_ADDR
*,
882 int, struct dwarf2_cu
*);
884 static void add_partial_symbol (struct partial_die_info
*,
887 static void add_partial_namespace (struct partial_die_info
*pdi
,
888 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
889 int need_pc
, struct dwarf2_cu
*cu
);
891 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
892 CORE_ADDR
*highpc
, int need_pc
,
893 struct dwarf2_cu
*cu
);
895 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
896 struct dwarf2_cu
*cu
);
898 static void add_partial_subprogram (struct partial_die_info
*pdi
,
899 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
900 int need_pc
, struct dwarf2_cu
*cu
);
902 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
903 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
904 bfd
*abfd
, struct dwarf2_cu
*cu
);
906 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
908 static void psymtab_to_symtab_1 (struct partial_symtab
*);
910 static void dwarf2_read_abbrevs (struct dwarf2_cu
*cu
);
912 static void dwarf2_free_abbrev_table (void *);
914 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
916 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
919 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
922 static struct partial_die_info
*load_partial_dies (bfd
*,
923 gdb_byte
*, gdb_byte
*,
924 int, struct dwarf2_cu
*);
926 static gdb_byte
*read_partial_die (struct partial_die_info
*,
927 struct abbrev_info
*abbrev
,
929 gdb_byte
*, gdb_byte
*,
932 static struct partial_die_info
*find_partial_die (unsigned int,
935 static void fixup_partial_die (struct partial_die_info
*,
938 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
939 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
941 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
942 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
944 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
946 static int read_1_signed_byte (bfd
*, gdb_byte
*);
948 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
950 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
952 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
954 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
957 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
959 static LONGEST read_checked_initial_length_and_offset
960 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
961 unsigned int *, unsigned int *);
963 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
966 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
968 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
970 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
972 static char *read_indirect_string (bfd
*, gdb_byte
*,
973 const struct comp_unit_head
*,
976 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
978 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
980 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
982 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
984 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
987 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
991 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
992 struct dwarf2_cu
*cu
);
994 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
996 static struct die_info
*die_specification (struct die_info
*die
,
997 struct dwarf2_cu
**);
999 static void free_line_header (struct line_header
*lh
);
1001 static void add_file_name (struct line_header
*, char *, unsigned int,
1002 unsigned int, unsigned int);
1004 static struct line_header
*(dwarf_decode_line_header
1005 (unsigned int offset
,
1006 bfd
*abfd
, struct dwarf2_cu
*cu
));
1008 static void dwarf_decode_lines (struct line_header
*, const char *, bfd
*,
1009 struct dwarf2_cu
*, struct partial_symtab
*);
1011 static void dwarf2_start_subfile (char *, const char *, const char *);
1013 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1014 struct dwarf2_cu
*);
1016 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1017 struct dwarf2_cu
*, struct symbol
*);
1019 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1020 struct dwarf2_cu
*);
1022 static void dwarf2_const_value_attr (struct attribute
*attr
,
1025 struct obstack
*obstack
,
1026 struct dwarf2_cu
*cu
, long *value
,
1028 struct dwarf2_locexpr_baton
**baton
);
1030 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1032 static int need_gnat_info (struct dwarf2_cu
*);
1034 static struct type
*die_descriptive_type (struct die_info
*,
1035 struct dwarf2_cu
*);
1037 static void set_descriptive_type (struct type
*, struct die_info
*,
1038 struct dwarf2_cu
*);
1040 static struct type
*die_containing_type (struct die_info
*,
1041 struct dwarf2_cu
*);
1043 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1044 struct dwarf2_cu
*);
1046 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1048 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1050 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1052 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1053 const char *suffix
, int physname
,
1054 struct dwarf2_cu
*cu
);
1056 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1058 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1060 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1062 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1064 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*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 struct signatured_type
*lookup_signatured_type_at_offset
1199 (struct objfile
*objfile
,
1200 struct dwarf2_section_info
*section
,
1201 unsigned int offset
);
1203 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1205 static void read_signatured_type (struct signatured_type
*type_sig
);
1207 /* memory allocation interface */
1209 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1211 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1213 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1215 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1216 char *, bfd
*, struct dwarf2_cu
*,
1217 struct dwarf2_section_info
*,
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 dwarf2_per_cu_data
*per_cu
);
1253 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1254 struct die_info
*comp_unit_die
);
1256 static void free_heap_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
*);
1273 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1275 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1276 struct dwarf2_per_cu_data
*);
1278 static void dwarf2_mark (struct dwarf2_cu
*);
1280 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1282 static struct type
*get_die_type_at_offset (unsigned int,
1283 struct dwarf2_per_cu_data
*per_cu
);
1285 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1287 static void dwarf2_release_queue (void *dummy
);
1289 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
);
1291 static void process_queue (void);
1293 static void find_file_and_directory (struct die_info
*die
,
1294 struct dwarf2_cu
*cu
,
1295 char **name
, char **comp_dir
);
1297 static char *file_full_name (int file
, struct line_header
*lh
,
1298 const char *comp_dir
);
1300 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1303 unsigned int buffer_size
,
1305 int is_debug_types_section
);
1307 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1308 struct dwarf2_cu
*cu
);
1310 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1314 /* Convert VALUE between big- and little-endian. */
1316 byte_swap (offset_type value
)
1320 result
= (value
& 0xff) << 24;
1321 result
|= (value
& 0xff00) << 8;
1322 result
|= (value
& 0xff0000) >> 8;
1323 result
|= (value
& 0xff000000) >> 24;
1327 #define MAYBE_SWAP(V) byte_swap (V)
1330 #define MAYBE_SWAP(V) (V)
1331 #endif /* WORDS_BIGENDIAN */
1333 /* The suffix for an index file. */
1334 #define INDEX_SUFFIX ".gdb-index"
1336 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1337 struct dwarf2_cu
*cu
);
1339 /* Try to locate the sections we need for DWARF 2 debugging
1340 information and return true if we have enough to do something.
1341 NAMES points to the dwarf2 section names, or is NULL if the standard
1342 ELF names are used. */
1345 dwarf2_has_info (struct objfile
*objfile
,
1346 const struct dwarf2_debug_sections
*names
)
1348 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1349 if (!dwarf2_per_objfile
)
1351 /* Initialize per-objfile state. */
1352 struct dwarf2_per_objfile
*data
1353 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1355 memset (data
, 0, sizeof (*data
));
1356 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1357 dwarf2_per_objfile
= data
;
1359 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1361 dwarf2_per_objfile
->objfile
= objfile
;
1363 return (dwarf2_per_objfile
->info
.asection
!= NULL
1364 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1367 /* When loading sections, we look either for uncompressed section or for
1368 compressed section names. */
1371 section_is_p (const char *section_name
,
1372 const struct dwarf2_section_names
*names
)
1374 if (names
->normal
!= NULL
1375 && strcmp (section_name
, names
->normal
) == 0)
1377 if (names
->compressed
!= NULL
1378 && strcmp (section_name
, names
->compressed
) == 0)
1383 /* This function is mapped across the sections and remembers the
1384 offset and size of each of the debugging sections we are interested
1388 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1390 const struct dwarf2_debug_sections
*names
;
1393 names
= &dwarf2_elf_names
;
1395 names
= (const struct dwarf2_debug_sections
*) vnames
;
1397 if (section_is_p (sectp
->name
, &names
->info
))
1399 dwarf2_per_objfile
->info
.asection
= sectp
;
1400 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1402 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1404 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1405 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1407 else if (section_is_p (sectp
->name
, &names
->line
))
1409 dwarf2_per_objfile
->line
.asection
= sectp
;
1410 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1412 else if (section_is_p (sectp
->name
, &names
->loc
))
1414 dwarf2_per_objfile
->loc
.asection
= sectp
;
1415 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1417 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1419 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1420 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1422 else if (section_is_p (sectp
->name
, &names
->macro
))
1424 dwarf2_per_objfile
->macro
.asection
= sectp
;
1425 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1427 else if (section_is_p (sectp
->name
, &names
->str
))
1429 dwarf2_per_objfile
->str
.asection
= sectp
;
1430 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1432 else if (section_is_p (sectp
->name
, &names
->frame
))
1434 dwarf2_per_objfile
->frame
.asection
= sectp
;
1435 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1437 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1439 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1441 if (aflag
& SEC_HAS_CONTENTS
)
1443 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1444 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1447 else if (section_is_p (sectp
->name
, &names
->ranges
))
1449 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1450 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1452 else if (section_is_p (sectp
->name
, &names
->types
))
1454 struct dwarf2_section_info type_section
;
1456 memset (&type_section
, 0, sizeof (type_section
));
1457 type_section
.asection
= sectp
;
1458 type_section
.size
= bfd_get_section_size (sectp
);
1460 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1463 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1465 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1466 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1469 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1470 && bfd_section_vma (abfd
, sectp
) == 0)
1471 dwarf2_per_objfile
->has_section_at_zero
= 1;
1474 /* Decompress a section that was compressed using zlib. Store the
1475 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1478 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1479 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1481 bfd
*abfd
= objfile
->obfd
;
1483 error (_("Support for zlib-compressed DWARF data (from '%s') "
1484 "is disabled in this copy of GDB"),
1485 bfd_get_filename (abfd
));
1487 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1488 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1489 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1490 bfd_size_type uncompressed_size
;
1491 gdb_byte
*uncompressed_buffer
;
1494 int header_size
= 12;
1496 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1497 || bfd_bread (compressed_buffer
,
1498 compressed_size
, abfd
) != compressed_size
)
1499 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1500 bfd_get_filename (abfd
));
1502 /* Read the zlib header. In this case, it should be "ZLIB" followed
1503 by the uncompressed section size, 8 bytes in big-endian order. */
1504 if (compressed_size
< header_size
1505 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1506 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1507 bfd_get_filename (abfd
));
1508 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1509 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1510 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1511 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1512 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1513 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1514 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1515 uncompressed_size
+= compressed_buffer
[11];
1517 /* It is possible the section consists of several compressed
1518 buffers concatenated together, so we uncompress in a loop. */
1522 strm
.avail_in
= compressed_size
- header_size
;
1523 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1524 strm
.avail_out
= uncompressed_size
;
1525 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1527 rc
= inflateInit (&strm
);
1528 while (strm
.avail_in
> 0)
1531 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1532 bfd_get_filename (abfd
), rc
);
1533 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1534 + (uncompressed_size
- strm
.avail_out
));
1535 rc
= inflate (&strm
, Z_FINISH
);
1536 if (rc
!= Z_STREAM_END
)
1537 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1538 bfd_get_filename (abfd
), rc
);
1539 rc
= inflateReset (&strm
);
1541 rc
= inflateEnd (&strm
);
1543 || strm
.avail_out
!= 0)
1544 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1545 bfd_get_filename (abfd
), rc
);
1547 do_cleanups (cleanup
);
1548 *outbuf
= uncompressed_buffer
;
1549 *outsize
= uncompressed_size
;
1553 /* A helper function that decides whether a section is empty. */
1556 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1558 return info
->asection
== NULL
|| info
->size
== 0;
1561 /* Read the contents of the section INFO from object file specified by
1562 OBJFILE, store info about the section into INFO.
1563 If the section is compressed, uncompress it before returning. */
1566 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1568 bfd
*abfd
= objfile
->obfd
;
1569 asection
*sectp
= info
->asection
;
1570 gdb_byte
*buf
, *retbuf
;
1571 unsigned char header
[4];
1575 info
->buffer
= NULL
;
1576 info
->map_addr
= NULL
;
1579 if (dwarf2_section_empty_p (info
))
1582 /* Check if the file has a 4-byte header indicating compression. */
1583 if (info
->size
> sizeof (header
)
1584 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1585 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1587 /* Upon decompression, update the buffer and its size. */
1588 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1590 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1598 pagesize
= getpagesize ();
1600 /* Only try to mmap sections which are large enough: we don't want to
1601 waste space due to fragmentation. Also, only try mmap for sections
1602 without relocations. */
1604 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1606 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1607 MAP_PRIVATE
, sectp
->filepos
,
1608 &info
->map_addr
, &info
->map_len
);
1610 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1612 #if HAVE_POSIX_MADVISE
1613 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1620 /* If we get here, we are a normal, not-compressed section. */
1622 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1624 /* When debugging .o files, we may need to apply relocations; see
1625 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1626 We never compress sections in .o files, so we only need to
1627 try this when the section is not compressed. */
1628 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1631 info
->buffer
= retbuf
;
1635 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1636 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1637 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1638 bfd_get_filename (abfd
));
1641 /* A helper function that returns the size of a section in a safe way.
1642 If you are positive that the section has been read before using the
1643 size, then it is safe to refer to the dwarf2_section_info object's
1644 "size" field directly. In other cases, you must call this
1645 function, because for compressed sections the size field is not set
1646 correctly until the section has been read. */
1648 static bfd_size_type
1649 dwarf2_section_size (struct objfile
*objfile
,
1650 struct dwarf2_section_info
*info
)
1653 dwarf2_read_section (objfile
, info
);
1657 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1661 dwarf2_get_section_info (struct objfile
*objfile
,
1662 enum dwarf2_section_enum sect
,
1663 asection
**sectp
, gdb_byte
**bufp
,
1664 bfd_size_type
*sizep
)
1666 struct dwarf2_per_objfile
*data
1667 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1668 struct dwarf2_section_info
*info
;
1670 /* We may see an objfile without any DWARF, in which case we just
1681 case DWARF2_DEBUG_FRAME
:
1682 info
= &data
->frame
;
1684 case DWARF2_EH_FRAME
:
1685 info
= &data
->eh_frame
;
1688 gdb_assert_not_reached ("unexpected section");
1691 dwarf2_read_section (objfile
, info
);
1693 *sectp
= info
->asection
;
1694 *bufp
= info
->buffer
;
1695 *sizep
= info
->size
;
1699 /* DWARF quick_symbols_functions support. */
1701 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1702 unique line tables, so we maintain a separate table of all .debug_line
1703 derived entries to support the sharing.
1704 All the quick functions need is the list of file names. We discard the
1705 line_header when we're done and don't need to record it here. */
1706 struct quick_file_names
1708 /* The offset in .debug_line of the line table. We hash on this. */
1709 unsigned int offset
;
1711 /* The number of entries in file_names, real_names. */
1712 unsigned int num_file_names
;
1714 /* The file names from the line table, after being run through
1716 const char **file_names
;
1718 /* The file names from the line table after being run through
1719 gdb_realpath. These are computed lazily. */
1720 const char **real_names
;
1723 /* When using the index (and thus not using psymtabs), each CU has an
1724 object of this type. This is used to hold information needed by
1725 the various "quick" methods. */
1726 struct dwarf2_per_cu_quick_data
1728 /* The file table. This can be NULL if there was no file table
1729 or it's currently not read in.
1730 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1731 struct quick_file_names
*file_names
;
1733 /* The corresponding symbol table. This is NULL if symbols for this
1734 CU have not yet been read. */
1735 struct symtab
*symtab
;
1737 /* A temporary mark bit used when iterating over all CUs in
1738 expand_symtabs_matching. */
1739 unsigned int mark
: 1;
1741 /* True if we've tried to read the file table and found there isn't one.
1742 There will be no point in trying to read it again next time. */
1743 unsigned int no_file_data
: 1;
1746 /* Hash function for a quick_file_names. */
1749 hash_file_name_entry (const void *e
)
1751 const struct quick_file_names
*file_data
= e
;
1753 return file_data
->offset
;
1756 /* Equality function for a quick_file_names. */
1759 eq_file_name_entry (const void *a
, const void *b
)
1761 const struct quick_file_names
*ea
= a
;
1762 const struct quick_file_names
*eb
= b
;
1764 return ea
->offset
== eb
->offset
;
1767 /* Delete function for a quick_file_names. */
1770 delete_file_name_entry (void *e
)
1772 struct quick_file_names
*file_data
= e
;
1775 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1777 xfree ((void*) file_data
->file_names
[i
]);
1778 if (file_data
->real_names
)
1779 xfree ((void*) file_data
->real_names
[i
]);
1782 /* The space for the struct itself lives on objfile_obstack,
1783 so we don't free it here. */
1786 /* Create a quick_file_names hash table. */
1789 create_quick_file_names_table (unsigned int nr_initial_entries
)
1791 return htab_create_alloc (nr_initial_entries
,
1792 hash_file_name_entry
, eq_file_name_entry
,
1793 delete_file_name_entry
, xcalloc
, xfree
);
1796 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1797 have to be created afterwards. You should call age_cached_comp_units after
1798 processing PER_CU->CU. dw2_setup must have been already called. */
1801 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1803 if (per_cu
->debug_types_section
)
1804 load_full_type_unit (per_cu
);
1806 load_full_comp_unit (per_cu
);
1808 gdb_assert (per_cu
->cu
!= NULL
);
1810 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1813 /* Read in the symbols for PER_CU. */
1816 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1818 struct cleanup
*back_to
;
1820 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1822 queue_comp_unit (per_cu
);
1828 /* Age the cache, releasing compilation units that have not
1829 been used recently. */
1830 age_cached_comp_units ();
1832 do_cleanups (back_to
);
1835 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1836 the objfile from which this CU came. Returns the resulting symbol
1839 static struct symtab
*
1840 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1842 if (!per_cu
->v
.quick
->symtab
)
1844 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1845 increment_reading_symtab ();
1846 dw2_do_instantiate_symtab (per_cu
);
1847 do_cleanups (back_to
);
1849 return per_cu
->v
.quick
->symtab
;
1852 /* Return the CU given its index. */
1854 static struct dwarf2_per_cu_data
*
1855 dw2_get_cu (int index
)
1857 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1859 index
-= dwarf2_per_objfile
->n_comp_units
;
1860 return dwarf2_per_objfile
->type_comp_units
[index
];
1862 return dwarf2_per_objfile
->all_comp_units
[index
];
1865 /* A helper function that knows how to read a 64-bit value in a way
1866 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1870 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1872 if (sizeof (ULONGEST
) < 8)
1876 /* Ignore the upper 4 bytes if they are all zero. */
1877 for (i
= 0; i
< 4; ++i
)
1878 if (bytes
[i
+ 4] != 0)
1881 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1884 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1888 /* Read the CU list from the mapped index, and use it to create all
1889 the CU objects for this objfile. Return 0 if something went wrong,
1890 1 if everything went ok. */
1893 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1894 offset_type cu_list_elements
)
1898 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1899 dwarf2_per_objfile
->all_comp_units
1900 = obstack_alloc (&objfile
->objfile_obstack
,
1901 dwarf2_per_objfile
->n_comp_units
1902 * sizeof (struct dwarf2_per_cu_data
*));
1904 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1906 struct dwarf2_per_cu_data
*the_cu
;
1907 ULONGEST offset
, length
;
1909 if (!extract_cu_value (cu_list
, &offset
)
1910 || !extract_cu_value (cu_list
+ 8, &length
))
1914 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1915 struct dwarf2_per_cu_data
);
1916 the_cu
->offset
= offset
;
1917 the_cu
->length
= length
;
1918 the_cu
->objfile
= objfile
;
1919 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1920 struct dwarf2_per_cu_quick_data
);
1921 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1927 /* Create the signatured type hash table from the index. */
1930 create_signatured_type_table_from_index (struct objfile
*objfile
,
1931 struct dwarf2_section_info
*section
,
1932 const gdb_byte
*bytes
,
1933 offset_type elements
)
1936 htab_t sig_types_hash
;
1938 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1939 dwarf2_per_objfile
->type_comp_units
1940 = obstack_alloc (&objfile
->objfile_obstack
,
1941 dwarf2_per_objfile
->n_type_comp_units
1942 * sizeof (struct dwarf2_per_cu_data
*));
1944 sig_types_hash
= allocate_signatured_type_table (objfile
);
1946 for (i
= 0; i
< elements
; i
+= 3)
1948 struct signatured_type
*type_sig
;
1949 ULONGEST offset
, type_offset
, signature
;
1952 if (!extract_cu_value (bytes
, &offset
)
1953 || !extract_cu_value (bytes
+ 8, &type_offset
))
1955 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1958 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1959 struct signatured_type
);
1960 type_sig
->signature
= signature
;
1961 type_sig
->type_offset
= type_offset
;
1962 type_sig
->per_cu
.debug_types_section
= section
;
1963 type_sig
->per_cu
.offset
= offset
;
1964 type_sig
->per_cu
.objfile
= objfile
;
1965 type_sig
->per_cu
.v
.quick
1966 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1967 struct dwarf2_per_cu_quick_data
);
1969 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1972 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1975 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1980 /* Read the address map data from the mapped index, and use it to
1981 populate the objfile's psymtabs_addrmap. */
1984 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1986 const gdb_byte
*iter
, *end
;
1987 struct obstack temp_obstack
;
1988 struct addrmap
*mutable_map
;
1989 struct cleanup
*cleanup
;
1992 obstack_init (&temp_obstack
);
1993 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1994 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1996 iter
= index
->address_table
;
1997 end
= iter
+ index
->address_table_size
;
1999 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2003 ULONGEST hi
, lo
, cu_index
;
2004 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2006 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2008 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2011 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2012 dw2_get_cu (cu_index
));
2015 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2016 &objfile
->objfile_obstack
);
2017 do_cleanups (cleanup
);
2020 /* The hash function for strings in the mapped index. This is the same as
2021 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2022 implementation. This is necessary because the hash function is tied to the
2023 format of the mapped index file. The hash values do not have to match with
2026 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2029 mapped_index_string_hash (int index_version
, const void *p
)
2031 const unsigned char *str
= (const unsigned char *) p
;
2035 while ((c
= *str
++) != 0)
2037 if (index_version
>= 5)
2039 r
= r
* 67 + c
- 113;
2045 /* Find a slot in the mapped index INDEX for the object named NAME.
2046 If NAME is found, set *VEC_OUT to point to the CU vector in the
2047 constant pool and return 1. If NAME cannot be found, return 0. */
2050 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2051 offset_type
**vec_out
)
2053 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2055 offset_type slot
, step
;
2056 int (*cmp
) (const char *, const char *);
2058 if (current_language
->la_language
== language_cplus
2059 || current_language
->la_language
== language_java
2060 || current_language
->la_language
== language_fortran
)
2062 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2064 const char *paren
= strchr (name
, '(');
2070 dup
= xmalloc (paren
- name
+ 1);
2071 memcpy (dup
, name
, paren
- name
);
2072 dup
[paren
- name
] = 0;
2074 make_cleanup (xfree
, dup
);
2079 /* Index version 4 did not support case insensitive searches. But the
2080 indexes for case insensitive languages are built in lowercase, therefore
2081 simulate our NAME being searched is also lowercased. */
2082 hash
= mapped_index_string_hash ((index
->version
== 4
2083 && case_sensitivity
== case_sensitive_off
2084 ? 5 : index
->version
),
2087 slot
= hash
& (index
->symbol_table_slots
- 1);
2088 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2089 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2093 /* Convert a slot number to an offset into the table. */
2094 offset_type i
= 2 * slot
;
2096 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2098 do_cleanups (back_to
);
2102 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2103 if (!cmp (name
, str
))
2105 *vec_out
= (offset_type
*) (index
->constant_pool
2106 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2107 do_cleanups (back_to
);
2111 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2115 /* Read the index file. If everything went ok, initialize the "quick"
2116 elements of all the CUs and return 1. Otherwise, return 0. */
2119 dwarf2_read_index (struct objfile
*objfile
)
2122 struct mapped_index
*map
;
2123 offset_type
*metadata
;
2124 const gdb_byte
*cu_list
;
2125 const gdb_byte
*types_list
= NULL
;
2126 offset_type version
, cu_list_elements
;
2127 offset_type types_list_elements
= 0;
2130 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2133 /* Older elfutils strip versions could keep the section in the main
2134 executable while splitting it for the separate debug info file. */
2135 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2136 & SEC_HAS_CONTENTS
) == 0)
2139 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2141 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2142 /* Version check. */
2143 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2144 /* Versions earlier than 3 emitted every copy of a psymbol. This
2145 causes the index to behave very poorly for certain requests. Version 3
2146 contained incomplete addrmap. So, it seems better to just ignore such
2147 indices. Index version 4 uses a different hash function than index
2148 version 5 and later. */
2151 /* Indexes with higher version than the one supported by GDB may be no
2152 longer backward compatible. */
2156 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2157 map
->version
= version
;
2158 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2160 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2163 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2164 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2168 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2169 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2170 - MAYBE_SWAP (metadata
[i
]))
2174 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2175 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2176 - MAYBE_SWAP (metadata
[i
]));
2179 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2180 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2181 - MAYBE_SWAP (metadata
[i
]))
2182 / (2 * sizeof (offset_type
)));
2185 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2187 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2190 if (types_list_elements
)
2192 struct dwarf2_section_info
*section
;
2194 /* We can only handle a single .debug_types when we have an
2196 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2199 section
= VEC_index (dwarf2_section_info_def
,
2200 dwarf2_per_objfile
->types
, 0);
2202 if (!create_signatured_type_table_from_index (objfile
, section
,
2204 types_list_elements
))
2208 create_addrmap_from_index (objfile
, map
);
2210 dwarf2_per_objfile
->index_table
= map
;
2211 dwarf2_per_objfile
->using_index
= 1;
2212 dwarf2_per_objfile
->quick_file_names_table
=
2213 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2218 /* A helper for the "quick" functions which sets the global
2219 dwarf2_per_objfile according to OBJFILE. */
2222 dw2_setup (struct objfile
*objfile
)
2224 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2225 gdb_assert (dwarf2_per_objfile
);
2228 /* A helper for the "quick" functions which attempts to read the line
2229 table for THIS_CU. */
2231 static struct quick_file_names
*
2232 dw2_get_file_names (struct objfile
*objfile
,
2233 struct dwarf2_per_cu_data
*this_cu
)
2235 bfd
*abfd
= objfile
->obfd
;
2236 struct line_header
*lh
;
2237 struct attribute
*attr
;
2238 struct cleanup
*cleanups
;
2239 struct die_info
*comp_unit_die
;
2240 struct dwarf2_section_info
* sec
;
2241 gdb_byte
*info_ptr
, *buffer
;
2242 int has_children
, i
;
2243 struct dwarf2_cu cu
;
2244 unsigned int bytes_read
, buffer_size
;
2245 struct die_reader_specs reader_specs
;
2246 char *name
, *comp_dir
;
2248 struct quick_file_names
*qfn
;
2249 unsigned int line_offset
;
2251 if (this_cu
->v
.quick
->file_names
!= NULL
)
2252 return this_cu
->v
.quick
->file_names
;
2253 /* If we know there is no line data, no point in looking again. */
2254 if (this_cu
->v
.quick
->no_file_data
)
2257 init_one_comp_unit (&cu
, this_cu
);
2258 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2260 if (this_cu
->debug_types_section
)
2261 sec
= this_cu
->debug_types_section
;
2263 sec
= &dwarf2_per_objfile
->info
;
2264 dwarf2_read_section (objfile
, sec
);
2265 buffer_size
= sec
->size
;
2266 buffer
= sec
->buffer
;
2267 info_ptr
= buffer
+ this_cu
->offset
;
2269 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2270 buffer
, buffer_size
,
2272 this_cu
->debug_types_section
!= NULL
);
2274 /* Skip dummy compilation units. */
2275 if (info_ptr
>= buffer
+ buffer_size
2276 || peek_abbrev_code (abfd
, info_ptr
) == 0)
2278 do_cleanups (cleanups
);
2282 dwarf2_read_abbrevs (&cu
);
2283 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2285 init_cu_die_reader (&reader_specs
, &cu
);
2286 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2292 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2295 struct quick_file_names find_entry
;
2297 line_offset
= DW_UNSND (attr
);
2299 /* We may have already read in this line header (TU line header sharing).
2300 If we have we're done. */
2301 find_entry
.offset
= line_offset
;
2302 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2303 &find_entry
, INSERT
);
2306 do_cleanups (cleanups
);
2307 this_cu
->v
.quick
->file_names
= *slot
;
2311 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2315 do_cleanups (cleanups
);
2316 this_cu
->v
.quick
->no_file_data
= 1;
2320 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2321 qfn
->offset
= line_offset
;
2322 gdb_assert (slot
!= NULL
);
2325 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2327 qfn
->num_file_names
= lh
->num_file_names
;
2328 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2329 lh
->num_file_names
* sizeof (char *));
2330 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2331 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2332 qfn
->real_names
= NULL
;
2334 free_line_header (lh
);
2335 do_cleanups (cleanups
);
2337 this_cu
->v
.quick
->file_names
= qfn
;
2341 /* A helper for the "quick" functions which computes and caches the
2342 real path for a given file name from the line table. */
2345 dw2_get_real_path (struct objfile
*objfile
,
2346 struct quick_file_names
*qfn
, int index
)
2348 if (qfn
->real_names
== NULL
)
2349 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2350 qfn
->num_file_names
, sizeof (char *));
2352 if (qfn
->real_names
[index
] == NULL
)
2353 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2355 return qfn
->real_names
[index
];
2358 static struct symtab
*
2359 dw2_find_last_source_symtab (struct objfile
*objfile
)
2363 dw2_setup (objfile
);
2364 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2365 return dw2_instantiate_symtab (dw2_get_cu (index
));
2368 /* Traversal function for dw2_forget_cached_source_info. */
2371 dw2_free_cached_file_names (void **slot
, void *info
)
2373 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2375 if (file_data
->real_names
)
2379 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2381 xfree ((void*) file_data
->real_names
[i
]);
2382 file_data
->real_names
[i
] = NULL
;
2390 dw2_forget_cached_source_info (struct objfile
*objfile
)
2392 dw2_setup (objfile
);
2394 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2395 dw2_free_cached_file_names
, NULL
);
2398 /* Helper function for dw2_map_symtabs_matching_filename that expands
2399 the symtabs and calls the iterator. */
2402 dw2_map_expand_apply (struct objfile
*objfile
,
2403 struct dwarf2_per_cu_data
*per_cu
,
2405 const char *full_path
, const char *real_path
,
2406 int (*callback
) (struct symtab
*, void *),
2409 struct symtab
*last_made
= objfile
->symtabs
;
2411 /* Don't visit already-expanded CUs. */
2412 if (per_cu
->v
.quick
->symtab
)
2415 /* This may expand more than one symtab, and we want to iterate over
2417 dw2_instantiate_symtab (per_cu
);
2419 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2420 objfile
->symtabs
, last_made
);
2423 /* Implementation of the map_symtabs_matching_filename method. */
2426 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2427 const char *full_path
, const char *real_path
,
2428 int (*callback
) (struct symtab
*, void *),
2432 const char *name_basename
= lbasename (name
);
2433 int check_basename
= name_basename
== name
;
2434 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2436 dw2_setup (objfile
);
2438 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2439 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2442 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2443 struct quick_file_names
*file_data
;
2445 /* We only need to look at symtabs not already expanded. */
2446 if (per_cu
->v
.quick
->symtab
)
2449 file_data
= dw2_get_file_names (objfile
, per_cu
);
2450 if (file_data
== NULL
)
2453 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2455 const char *this_name
= file_data
->file_names
[j
];
2457 if (FILENAME_CMP (name
, this_name
) == 0)
2459 if (dw2_map_expand_apply (objfile
, per_cu
,
2460 name
, full_path
, real_path
,
2465 if (check_basename
&& ! base_cu
2466 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2469 /* Before we invoke realpath, which can get expensive when many
2470 files are involved, do a quick comparison of the basenames. */
2471 if (! basenames_may_differ
2472 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2475 if (full_path
!= NULL
)
2477 const char *this_real_name
= dw2_get_real_path (objfile
,
2480 if (this_real_name
!= NULL
2481 && FILENAME_CMP (full_path
, this_real_name
) == 0)
2483 if (dw2_map_expand_apply (objfile
, per_cu
,
2484 name
, full_path
, real_path
,
2490 if (real_path
!= NULL
)
2492 const char *this_real_name
= dw2_get_real_path (objfile
,
2495 if (this_real_name
!= NULL
2496 && FILENAME_CMP (real_path
, this_real_name
) == 0)
2498 if (dw2_map_expand_apply (objfile
, per_cu
,
2499 name
, full_path
, real_path
,
2509 if (dw2_map_expand_apply (objfile
, base_cu
,
2510 name
, full_path
, real_path
,
2518 static struct symtab
*
2519 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2520 const char *name
, domain_enum domain
)
2522 /* We do all the work in the pre_expand_symtabs_matching hook
2527 /* A helper function that expands all symtabs that hold an object
2531 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2533 dw2_setup (objfile
);
2535 /* index_table is NULL if OBJF_READNOW. */
2536 if (dwarf2_per_objfile
->index_table
)
2540 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2543 offset_type i
, len
= MAYBE_SWAP (*vec
);
2544 for (i
= 0; i
< len
; ++i
)
2546 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2547 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2549 dw2_instantiate_symtab (per_cu
);
2556 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2557 enum block_enum block_kind
, const char *name
,
2560 dw2_do_expand_symtabs_matching (objfile
, name
);
2564 dw2_print_stats (struct objfile
*objfile
)
2568 dw2_setup (objfile
);
2570 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2571 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2573 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2575 if (!per_cu
->v
.quick
->symtab
)
2578 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2582 dw2_dump (struct objfile
*objfile
)
2584 /* Nothing worth printing. */
2588 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2589 struct section_offsets
*delta
)
2591 /* There's nothing to relocate here. */
2595 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2596 const char *func_name
)
2598 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2602 dw2_expand_all_symtabs (struct objfile
*objfile
)
2606 dw2_setup (objfile
);
2608 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2609 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2611 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2613 dw2_instantiate_symtab (per_cu
);
2618 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2619 const char *filename
)
2623 dw2_setup (objfile
);
2625 /* We don't need to consider type units here.
2626 This is only called for examining code, e.g. expand_line_sal.
2627 There can be an order of magnitude (or more) more type units
2628 than comp units, and we avoid them if we can. */
2630 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2633 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2634 struct quick_file_names
*file_data
;
2636 /* We only need to look at symtabs not already expanded. */
2637 if (per_cu
->v
.quick
->symtab
)
2640 file_data
= dw2_get_file_names (objfile
, per_cu
);
2641 if (file_data
== NULL
)
2644 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2646 const char *this_name
= file_data
->file_names
[j
];
2647 if (FILENAME_CMP (this_name
, filename
) == 0)
2649 dw2_instantiate_symtab (per_cu
);
2657 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2659 struct dwarf2_per_cu_data
*per_cu
;
2661 struct quick_file_names
*file_data
;
2663 dw2_setup (objfile
);
2665 /* index_table is NULL if OBJF_READNOW. */
2666 if (!dwarf2_per_objfile
->index_table
)
2670 ALL_OBJFILE_SYMTABS (objfile
, s
)
2673 struct blockvector
*bv
= BLOCKVECTOR (s
);
2674 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2675 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2678 return sym
->symtab
->filename
;
2683 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2687 /* Note that this just looks at the very first one named NAME -- but
2688 actually we are looking for a function. find_main_filename
2689 should be rewritten so that it doesn't require a custom hook. It
2690 could just use the ordinary symbol tables. */
2691 /* vec[0] is the length, which must always be >0. */
2692 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2694 file_data
= dw2_get_file_names (objfile
, per_cu
);
2695 if (file_data
== NULL
)
2698 return file_data
->file_names
[file_data
->num_file_names
- 1];
2702 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2703 struct objfile
*objfile
, int global
,
2704 int (*callback
) (struct block
*,
2705 struct symbol
*, void *),
2706 void *data
, symbol_compare_ftype
*match
,
2707 symbol_compare_ftype
*ordered_compare
)
2709 /* Currently unimplemented; used for Ada. The function can be called if the
2710 current language is Ada for a non-Ada objfile using GNU index. As Ada
2711 does not look for non-Ada symbols this function should just return. */
2715 dw2_expand_symtabs_matching
2716 (struct objfile
*objfile
,
2717 int (*file_matcher
) (const char *, void *),
2718 int (*name_matcher
) (const struct language_defn
*, const char *, void *),
2719 enum search_domain kind
,
2724 struct mapped_index
*index
;
2726 dw2_setup (objfile
);
2728 /* index_table is NULL if OBJF_READNOW. */
2729 if (!dwarf2_per_objfile
->index_table
)
2731 index
= dwarf2_per_objfile
->index_table
;
2733 if (file_matcher
!= NULL
)
2734 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2735 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2738 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2739 struct quick_file_names
*file_data
;
2741 per_cu
->v
.quick
->mark
= 0;
2743 /* We only need to look at symtabs not already expanded. */
2744 if (per_cu
->v
.quick
->symtab
)
2747 file_data
= dw2_get_file_names (objfile
, per_cu
);
2748 if (file_data
== NULL
)
2751 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2753 if (file_matcher (file_data
->file_names
[j
], data
))
2755 per_cu
->v
.quick
->mark
= 1;
2761 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2763 offset_type idx
= 2 * iter
;
2765 offset_type
*vec
, vec_len
, vec_idx
;
2767 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2770 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2772 if (! (*name_matcher
) (current_language
, name
, data
))
2775 /* The name was matched, now expand corresponding CUs that were
2777 vec
= (offset_type
*) (index
->constant_pool
2778 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2779 vec_len
= MAYBE_SWAP (vec
[0]);
2780 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2782 struct dwarf2_per_cu_data
*per_cu
;
2784 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2785 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2786 dw2_instantiate_symtab (per_cu
);
2791 static struct symtab
*
2792 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2793 struct minimal_symbol
*msymbol
,
2795 struct obj_section
*section
,
2798 struct dwarf2_per_cu_data
*data
;
2800 dw2_setup (objfile
);
2802 if (!objfile
->psymtabs_addrmap
)
2805 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2809 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2810 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2811 paddress (get_objfile_arch (objfile
), pc
));
2813 return dw2_instantiate_symtab (data
);
2817 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2818 void *data
, int need_fullname
)
2822 dw2_setup (objfile
);
2824 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2825 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2828 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2829 struct quick_file_names
*file_data
;
2831 /* We only need to look at symtabs not already expanded. */
2832 if (per_cu
->v
.quick
->symtab
)
2835 file_data
= dw2_get_file_names (objfile
, per_cu
);
2836 if (file_data
== NULL
)
2839 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2841 const char *this_real_name
;
2844 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
2846 this_real_name
= NULL
;
2847 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2853 dw2_has_symbols (struct objfile
*objfile
)
2858 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2861 dw2_find_last_source_symtab
,
2862 dw2_forget_cached_source_info
,
2863 dw2_map_symtabs_matching_filename
,
2865 dw2_pre_expand_symtabs_matching
,
2869 dw2_expand_symtabs_for_function
,
2870 dw2_expand_all_symtabs
,
2871 dw2_expand_symtabs_with_filename
,
2872 dw2_find_symbol_file
,
2873 dw2_map_matching_symbols
,
2874 dw2_expand_symtabs_matching
,
2875 dw2_find_pc_sect_symtab
,
2876 dw2_map_symbol_filenames
2879 /* Initialize for reading DWARF for this objfile. Return 0 if this
2880 file will use psymtabs, or 1 if using the GNU index. */
2883 dwarf2_initialize_objfile (struct objfile
*objfile
)
2885 /* If we're about to read full symbols, don't bother with the
2886 indices. In this case we also don't care if some other debug
2887 format is making psymtabs, because they are all about to be
2889 if ((objfile
->flags
& OBJF_READNOW
))
2893 dwarf2_per_objfile
->using_index
= 1;
2894 create_all_comp_units (objfile
);
2895 create_debug_types_hash_table (objfile
);
2896 dwarf2_per_objfile
->quick_file_names_table
=
2897 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2899 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2900 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2902 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2904 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2905 struct dwarf2_per_cu_quick_data
);
2908 /* Return 1 so that gdb sees the "quick" functions. However,
2909 these functions will be no-ops because we will have expanded
2914 if (dwarf2_read_index (objfile
))
2922 /* Build a partial symbol table. */
2925 dwarf2_build_psymtabs (struct objfile
*objfile
)
2927 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2929 init_psymbol_list (objfile
, 1024);
2932 dwarf2_build_psymtabs_hard (objfile
);
2935 /* Return TRUE if OFFSET is within CU_HEADER. */
2938 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2940 unsigned int bottom
= cu_header
->offset
;
2941 unsigned int top
= (cu_header
->offset
2943 + cu_header
->initial_length_size
);
2945 return (offset
>= bottom
&& offset
< top
);
2948 /* Read in the comp unit header information from the debug_info at info_ptr.
2949 NOTE: This leaves members offset, first_die_offset to be filled in
2953 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2954 gdb_byte
*info_ptr
, bfd
*abfd
)
2957 unsigned int bytes_read
;
2959 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2960 cu_header
->initial_length_size
= bytes_read
;
2961 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2962 info_ptr
+= bytes_read
;
2963 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2965 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2967 info_ptr
+= bytes_read
;
2968 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2970 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2971 if (signed_addr
< 0)
2972 internal_error (__FILE__
, __LINE__
,
2973 _("read_comp_unit_head: dwarf from non elf file"));
2974 cu_header
->signed_addr_p
= signed_addr
;
2979 /* Read in a CU header and perform some basic error checking. */
2982 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2983 gdb_byte
*buffer
, unsigned int buffer_size
,
2984 bfd
*abfd
, int is_debug_types_section
)
2986 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2988 header
->offset
= beg_of_comp_unit
- buffer
;
2990 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2992 /* If we're reading a type unit, skip over the signature and
2993 type_offset fields. */
2994 if (is_debug_types_section
)
2995 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
2997 header
->first_die_offset
= info_ptr
- beg_of_comp_unit
;
2999 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3000 error (_("Dwarf Error: wrong version in compilation unit header "
3001 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3002 bfd_get_filename (abfd
));
3004 if (header
->abbrev_offset
3005 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3006 &dwarf2_per_objfile
->abbrev
))
3007 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3008 "(offset 0x%lx + 6) [in module %s]"),
3009 (long) header
->abbrev_offset
,
3010 (long) (beg_of_comp_unit
- buffer
),
3011 bfd_get_filename (abfd
));
3013 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
3014 > buffer
+ buffer_size
)
3015 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3016 "(offset 0x%lx + 0) [in module %s]"),
3017 (long) header
->length
,
3018 (long) (beg_of_comp_unit
- buffer
),
3019 bfd_get_filename (abfd
));
3024 /* Read in the types comp unit header information from .debug_types entry at
3025 types_ptr. The result is a pointer to one past the end of the header. */
3028 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
3029 struct dwarf2_section_info
*section
,
3030 ULONGEST
*signature
,
3031 gdb_byte
*types_ptr
, bfd
*abfd
)
3033 gdb_byte
*initial_types_ptr
= types_ptr
;
3035 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
3036 cu_header
->offset
= types_ptr
- section
->buffer
;
3038 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
3040 *signature
= read_8_bytes (abfd
, types_ptr
);
3042 types_ptr
+= cu_header
->offset_size
;
3043 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
3048 /* Allocate a new partial symtab for file named NAME and mark this new
3049 partial symtab as being an include of PST. */
3052 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3053 struct objfile
*objfile
)
3055 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3057 subpst
->section_offsets
= pst
->section_offsets
;
3058 subpst
->textlow
= 0;
3059 subpst
->texthigh
= 0;
3061 subpst
->dependencies
= (struct partial_symtab
**)
3062 obstack_alloc (&objfile
->objfile_obstack
,
3063 sizeof (struct partial_symtab
*));
3064 subpst
->dependencies
[0] = pst
;
3065 subpst
->number_of_dependencies
= 1;
3067 subpst
->globals_offset
= 0;
3068 subpst
->n_global_syms
= 0;
3069 subpst
->statics_offset
= 0;
3070 subpst
->n_static_syms
= 0;
3071 subpst
->symtab
= NULL
;
3072 subpst
->read_symtab
= pst
->read_symtab
;
3075 /* No private part is necessary for include psymtabs. This property
3076 can be used to differentiate between such include psymtabs and
3077 the regular ones. */
3078 subpst
->read_symtab_private
= NULL
;
3081 /* Read the Line Number Program data and extract the list of files
3082 included by the source file represented by PST. Build an include
3083 partial symtab for each of these included files. */
3086 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3087 struct die_info
*die
,
3088 struct partial_symtab
*pst
)
3090 struct objfile
*objfile
= cu
->objfile
;
3091 bfd
*abfd
= objfile
->obfd
;
3092 struct line_header
*lh
= NULL
;
3093 struct attribute
*attr
;
3095 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3098 unsigned int line_offset
= DW_UNSND (attr
);
3100 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3103 return; /* No linetable, so no includes. */
3105 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3106 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
3108 free_line_header (lh
);
3112 hash_type_signature (const void *item
)
3114 const struct signatured_type
*type_sig
= item
;
3116 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3117 return type_sig
->signature
;
3121 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
3123 const struct signatured_type
*lhs
= item_lhs
;
3124 const struct signatured_type
*rhs
= item_rhs
;
3126 return lhs
->signature
== rhs
->signature
;
3129 /* Allocate a hash table for signatured types. */
3132 allocate_signatured_type_table (struct objfile
*objfile
)
3134 return htab_create_alloc_ex (41,
3135 hash_type_signature
,
3138 &objfile
->objfile_obstack
,
3139 hashtab_obstack_allocate
,
3140 dummy_obstack_deallocate
);
3143 /* A helper function to add a signatured type CU to a list. */
3146 add_signatured_type_cu_to_list (void **slot
, void *datum
)
3148 struct signatured_type
*sigt
= *slot
;
3149 struct dwarf2_per_cu_data
***datap
= datum
;
3151 **datap
= &sigt
->per_cu
;
3157 /* Create the hash table of all entries in the .debug_types section.
3158 The result is zero if there is an error (e.g. missing .debug_types section),
3159 otherwise non-zero. */
3162 create_debug_types_hash_table (struct objfile
*objfile
)
3164 htab_t types_htab
= NULL
;
3165 struct dwarf2_per_cu_data
**iter
;
3167 struct dwarf2_section_info
*section
;
3169 if (VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
))
3171 dwarf2_per_objfile
->signatured_types
= NULL
;
3176 VEC_iterate (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
3180 gdb_byte
*info_ptr
, *end_ptr
;
3182 dwarf2_read_section (objfile
, section
);
3183 info_ptr
= section
->buffer
;
3185 if (info_ptr
== NULL
)
3188 if (types_htab
== NULL
)
3189 types_htab
= allocate_signatured_type_table (objfile
);
3191 if (dwarf2_die_debug
)
3192 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3194 end_ptr
= info_ptr
+ section
->size
;
3195 while (info_ptr
< end_ptr
)
3197 unsigned int offset
;
3198 unsigned int offset_size
;
3199 unsigned int type_offset
;
3200 unsigned int length
, initial_length_size
;
3201 unsigned short version
;
3203 struct signatured_type
*type_sig
;
3205 gdb_byte
*ptr
= info_ptr
;
3207 offset
= ptr
- section
->buffer
;
3209 /* We need to read the type's signature in order to build the hash
3210 table, but we don't need to read anything else just yet. */
3212 /* Sanity check to ensure entire cu is present. */
3213 length
= read_initial_length (objfile
->obfd
, ptr
,
3214 &initial_length_size
);
3215 if (ptr
+ length
+ initial_length_size
> end_ptr
)
3217 complaint (&symfile_complaints
,
3218 _("debug type entry runs off end "
3219 "of `.debug_types' section, ignored"));
3223 offset_size
= initial_length_size
== 4 ? 4 : 8;
3224 ptr
+= initial_length_size
;
3225 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3227 ptr
+= offset_size
; /* abbrev offset */
3228 ptr
+= 1; /* address size */
3229 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3231 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3234 /* Skip dummy type units. */
3235 if (ptr
>= end_ptr
|| peek_abbrev_code (objfile
->obfd
, ptr
) == 0)
3237 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3241 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3242 memset (type_sig
, 0, sizeof (*type_sig
));
3243 type_sig
->signature
= signature
;
3244 type_sig
->type_offset
= type_offset
;
3245 type_sig
->per_cu
.objfile
= objfile
;
3246 type_sig
->per_cu
.debug_types_section
= section
;
3247 type_sig
->per_cu
.offset
= offset
;
3249 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3250 gdb_assert (slot
!= NULL
);
3253 const struct signatured_type
*dup_sig
= *slot
;
3255 complaint (&symfile_complaints
,
3256 _("debug type entry at offset 0x%x is duplicate to the "
3257 "entry at offset 0x%x, signature 0x%s"),
3258 offset
, dup_sig
->per_cu
.offset
,
3259 phex (signature
, sizeof (signature
)));
3260 gdb_assert (signature
== dup_sig
->signature
);
3264 if (dwarf2_die_debug
)
3265 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3266 offset
, phex (signature
, sizeof (signature
)));
3268 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3272 dwarf2_per_objfile
->signatured_types
= types_htab
;
3274 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3275 dwarf2_per_objfile
->type_comp_units
3276 = obstack_alloc (&objfile
->objfile_obstack
,
3277 dwarf2_per_objfile
->n_type_comp_units
3278 * sizeof (struct dwarf2_per_cu_data
*));
3279 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3280 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3281 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3282 == dwarf2_per_objfile
->n_type_comp_units
);
3287 /* Lookup a signature based type.
3288 Returns NULL if SIG is not present in the table. */
3290 static struct signatured_type
*
3291 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3293 struct signatured_type find_entry
, *entry
;
3295 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3297 complaint (&symfile_complaints
,
3298 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3302 find_entry
.signature
= sig
;
3303 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3307 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3310 init_cu_die_reader (struct die_reader_specs
*reader
,
3311 struct dwarf2_cu
*cu
)
3313 reader
->abfd
= cu
->objfile
->obfd
;
3315 if (cu
->per_cu
->debug_types_section
)
3317 gdb_assert (cu
->per_cu
->debug_types_section
->readin
);
3318 reader
->buffer
= cu
->per_cu
->debug_types_section
->buffer
;
3322 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3323 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3327 /* Find the base address of the compilation unit for range lists and
3328 location lists. It will normally be specified by DW_AT_low_pc.
3329 In DWARF-3 draft 4, the base address could be overridden by
3330 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3331 compilation units with discontinuous ranges. */
3334 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3336 struct attribute
*attr
;
3339 cu
->base_address
= 0;
3341 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3344 cu
->base_address
= DW_ADDR (attr
);
3349 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3352 cu
->base_address
= DW_ADDR (attr
);
3358 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3359 to combine the common parts.
3360 Process a compilation unit for a psymtab.
3361 BUFFER is a pointer to the beginning of the dwarf section buffer,
3362 either .debug_info or debug_types.
3363 INFO_PTR is a pointer to the start of the CU.
3364 Returns a pointer to the next CU. */
3367 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3368 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3369 unsigned int buffer_size
)
3371 struct objfile
*objfile
= this_cu
->objfile
;
3372 bfd
*abfd
= objfile
->obfd
;
3373 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3374 struct die_info
*comp_unit_die
;
3375 struct partial_symtab
*pst
;
3377 struct cleanup
*back_to_inner
;
3378 struct dwarf2_cu cu
;
3379 int has_children
, has_pc_info
;
3380 struct attribute
*attr
;
3381 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3382 struct die_reader_specs reader_specs
;
3383 const char *filename
;
3385 /* If this compilation unit was already read in, free the
3386 cached copy in order to read it in again. This is
3387 necessary because we skipped some symbols when we first
3388 read in the compilation unit (see load_partial_dies).
3389 This problem could be avoided, but the benefit is
3391 if (this_cu
->cu
!= NULL
)
3392 free_one_cached_comp_unit (this_cu
->cu
);
3394 /* Note that this is a pointer to our stack frame, being
3395 added to a global data structure. It will be cleaned up
3396 in free_stack_comp_unit when we finish with this
3397 compilation unit. */
3398 init_one_comp_unit (&cu
, this_cu
);
3399 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3401 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3402 buffer
, buffer_size
,
3404 this_cu
->debug_types_section
!= NULL
);
3406 /* Skip dummy compilation units. */
3407 if (info_ptr
>= buffer
+ buffer_size
3408 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3410 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3411 + cu
.header
.initial_length_size
);
3412 do_cleanups (back_to_inner
);
3416 cu
.list_in_scope
= &file_symbols
;
3418 /* Read the abbrevs for this compilation unit into a table. */
3419 dwarf2_read_abbrevs (&cu
);
3420 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3422 /* Read the compilation unit die. */
3423 init_cu_die_reader (&reader_specs
, &cu
);
3424 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3427 if (this_cu
->debug_types_section
)
3429 /* LENGTH has not been set yet for type units. */
3430 gdb_assert (this_cu
->offset
== cu
.header
.offset
);
3431 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3433 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3435 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3436 + cu
.header
.initial_length_size
);
3437 do_cleanups (back_to_inner
);
3441 prepare_one_comp_unit (&cu
, comp_unit_die
);
3443 /* Allocate a new partial symbol table structure. */
3444 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3445 if (attr
== NULL
|| !DW_STRING (attr
))
3448 filename
= DW_STRING (attr
);
3449 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3451 /* TEXTLOW and TEXTHIGH are set below. */
3453 objfile
->global_psymbols
.next
,
3454 objfile
->static_psymbols
.next
);
3455 pst
->psymtabs_addrmap_supported
= 1;
3457 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3459 pst
->dirname
= DW_STRING (attr
);
3461 pst
->read_symtab_private
= this_cu
;
3463 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3465 /* Store the function that reads in the rest of the symbol table. */
3466 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3468 this_cu
->v
.psymtab
= pst
;
3470 dwarf2_find_base_address (comp_unit_die
, &cu
);
3472 /* Possibly set the default values of LOWPC and HIGHPC from
3474 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3475 &best_highpc
, &cu
, pst
);
3476 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3477 /* Store the contiguous range if it is not empty; it can be empty for
3478 CUs with no code. */
3479 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3480 best_lowpc
+ baseaddr
,
3481 best_highpc
+ baseaddr
- 1, pst
);
3483 /* Check if comp unit has_children.
3484 If so, read the rest of the partial symbols from this comp unit.
3485 If not, there's no more debug_info for this comp unit. */
3488 struct partial_die_info
*first_die
;
3489 CORE_ADDR lowpc
, highpc
;
3491 lowpc
= ((CORE_ADDR
) -1);
3492 highpc
= ((CORE_ADDR
) 0);
3494 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3496 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3497 ! has_pc_info
, &cu
);
3499 /* If we didn't find a lowpc, set it to highpc to avoid
3500 complaints from `maint check'. */
3501 if (lowpc
== ((CORE_ADDR
) -1))
3504 /* If the compilation unit didn't have an explicit address range,
3505 then use the information extracted from its child dies. */
3509 best_highpc
= highpc
;
3512 pst
->textlow
= best_lowpc
+ baseaddr
;
3513 pst
->texthigh
= best_highpc
+ baseaddr
;
3515 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3516 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3517 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3518 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3519 sort_pst_symbols (pst
);
3521 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3522 + cu
.header
.initial_length_size
);
3524 if (this_cu
->debug_types_section
)
3526 /* It's not clear we want to do anything with stmt lists here.
3527 Waiting to see what gcc ultimately does. */
3531 /* Get the list of files included in the current compilation unit,
3532 and build a psymtab for each of them. */
3533 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3536 do_cleanups (back_to_inner
);
3541 /* Traversal function for htab_traverse_noresize.
3542 Process one .debug_types comp-unit. */
3545 process_type_comp_unit (void **slot
, void *info
)
3547 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3548 struct dwarf2_per_cu_data
*this_cu
;
3550 gdb_assert (info
== NULL
);
3551 this_cu
= &entry
->per_cu
;
3553 gdb_assert (this_cu
->debug_types_section
->readin
);
3554 process_psymtab_comp_unit (this_cu
,
3555 this_cu
->debug_types_section
->buffer
,
3556 (this_cu
->debug_types_section
->buffer
3558 this_cu
->debug_types_section
->size
);
3563 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3564 Build partial symbol tables for the .debug_types comp-units. */
3567 build_type_psymtabs (struct objfile
*objfile
)
3569 if (! create_debug_types_hash_table (objfile
))
3572 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3573 process_type_comp_unit
, NULL
);
3576 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3579 psymtabs_addrmap_cleanup (void *o
)
3581 struct objfile
*objfile
= o
;
3583 objfile
->psymtabs_addrmap
= NULL
;
3586 /* Build the partial symbol table by doing a quick pass through the
3587 .debug_info and .debug_abbrev sections. */
3590 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3593 struct cleanup
*back_to
, *addrmap_cleanup
;
3594 struct obstack temp_obstack
;
3596 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3598 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3599 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3601 /* Any cached compilation units will be linked by the per-objfile
3602 read_in_chain. Make sure to free them when we're done. */
3603 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3605 build_type_psymtabs (objfile
);
3607 create_all_comp_units (objfile
);
3609 /* Create a temporary address map on a temporary obstack. We later
3610 copy this to the final obstack. */
3611 obstack_init (&temp_obstack
);
3612 make_cleanup_obstack_free (&temp_obstack
);
3613 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3614 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3616 /* Since the objects we're extracting from .debug_info vary in
3617 length, only the individual functions to extract them (like
3618 read_comp_unit_head and load_partial_die) can really know whether
3619 the buffer is large enough to hold another complete object.
3621 At the moment, they don't actually check that. If .debug_info
3622 holds just one extra byte after the last compilation unit's dies,
3623 then read_comp_unit_head will happily read off the end of the
3624 buffer. read_partial_die is similarly casual. Those functions
3627 For this loop condition, simply checking whether there's any data
3628 left at all should be sufficient. */
3630 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3631 + dwarf2_per_objfile
->info
.size
))
3633 struct dwarf2_per_cu_data
*this_cu
;
3635 this_cu
= dwarf2_find_comp_unit (info_ptr
3636 - dwarf2_per_objfile
->info
.buffer
,
3639 info_ptr
= process_psymtab_comp_unit (this_cu
,
3640 dwarf2_per_objfile
->info
.buffer
,
3642 dwarf2_per_objfile
->info
.size
);
3645 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3646 &objfile
->objfile_obstack
);
3647 discard_cleanups (addrmap_cleanup
);
3649 do_cleanups (back_to
);
3652 /* Load the partial DIEs for a secondary CU into memory. */
3655 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
3657 struct objfile
*objfile
= this_cu
->objfile
;
3658 bfd
*abfd
= objfile
->obfd
;
3660 struct die_info
*comp_unit_die
;
3661 struct dwarf2_cu
*cu
;
3662 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3664 struct die_reader_specs reader_specs
;
3667 gdb_assert (! this_cu
->debug_types_section
);
3669 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3670 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3672 if (this_cu
->cu
== NULL
)
3674 cu
= xmalloc (sizeof (*cu
));
3675 init_one_comp_unit (cu
, this_cu
);
3679 /* If an error occurs while loading, release our storage. */
3680 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3682 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3683 dwarf2_per_objfile
->info
.buffer
,
3684 dwarf2_per_objfile
->info
.size
,
3687 /* Skip dummy compilation units. */
3688 if (info_ptr
>= (dwarf2_per_objfile
->info
.buffer
3689 + dwarf2_per_objfile
->info
.size
)
3690 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3692 do_cleanups (free_cu_cleanup
);
3696 /* Link this CU into read_in_chain. */
3697 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3698 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3703 info_ptr
+= cu
->header
.first_die_offset
;
3706 /* Read the abbrevs for this compilation unit into a table. */
3707 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3708 dwarf2_read_abbrevs (cu
);
3709 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3711 /* Read the compilation unit die. */
3712 init_cu_die_reader (&reader_specs
, cu
);
3713 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3716 prepare_one_comp_unit (cu
, comp_unit_die
);
3718 /* Check if comp unit has_children.
3719 If so, read the rest of the partial symbols from this comp unit.
3720 If not, there's no more debug_info for this comp unit. */
3722 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3724 do_cleanups (free_abbrevs_cleanup
);
3728 /* We've successfully allocated this compilation unit. Let our
3729 caller clean it up when finished with it. */
3730 discard_cleanups (free_cu_cleanup
);
3734 /* Create a list of all compilation units in OBJFILE.
3735 This is only done for -readnow and building partial symtabs. */
3738 create_all_comp_units (struct objfile
*objfile
)
3742 struct dwarf2_per_cu_data
**all_comp_units
;
3745 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3746 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3750 all_comp_units
= xmalloc (n_allocated
3751 * sizeof (struct dwarf2_per_cu_data
*));
3753 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3754 + dwarf2_per_objfile
->info
.size
)
3756 unsigned int length
, initial_length_size
;
3757 struct dwarf2_per_cu_data
*this_cu
;
3758 unsigned int offset
;
3760 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3762 /* Read just enough information to find out where the next
3763 compilation unit is. */
3764 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3765 &initial_length_size
);
3767 /* Save the compilation unit for later lookup. */
3768 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3769 sizeof (struct dwarf2_per_cu_data
));
3770 memset (this_cu
, 0, sizeof (*this_cu
));
3771 this_cu
->offset
= offset
;
3772 this_cu
->length
= length
+ initial_length_size
;
3773 this_cu
->objfile
= objfile
;
3775 if (n_comp_units
== n_allocated
)
3778 all_comp_units
= xrealloc (all_comp_units
,
3780 * sizeof (struct dwarf2_per_cu_data
*));
3782 all_comp_units
[n_comp_units
++] = this_cu
;
3784 info_ptr
= info_ptr
+ this_cu
->length
;
3787 dwarf2_per_objfile
->all_comp_units
3788 = obstack_alloc (&objfile
->objfile_obstack
,
3789 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3790 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3791 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3792 xfree (all_comp_units
);
3793 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3796 /* Process all loaded DIEs for compilation unit CU, starting at
3797 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3798 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3799 DW_AT_ranges). If NEED_PC is set, then this function will set
3800 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3801 and record the covered ranges in the addrmap. */
3804 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3805 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3807 struct partial_die_info
*pdi
;
3809 /* Now, march along the PDI's, descending into ones which have
3810 interesting children but skipping the children of the other ones,
3811 until we reach the end of the compilation unit. */
3817 fixup_partial_die (pdi
, cu
);
3819 /* Anonymous namespaces or modules have no name but have interesting
3820 children, so we need to look at them. Ditto for anonymous
3823 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3824 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3828 case DW_TAG_subprogram
:
3829 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3831 case DW_TAG_constant
:
3832 case DW_TAG_variable
:
3833 case DW_TAG_typedef
:
3834 case DW_TAG_union_type
:
3835 if (!pdi
->is_declaration
)
3837 add_partial_symbol (pdi
, cu
);
3840 case DW_TAG_class_type
:
3841 case DW_TAG_interface_type
:
3842 case DW_TAG_structure_type
:
3843 if (!pdi
->is_declaration
)
3845 add_partial_symbol (pdi
, cu
);
3848 case DW_TAG_enumeration_type
:
3849 if (!pdi
->is_declaration
)
3850 add_partial_enumeration (pdi
, cu
);
3852 case DW_TAG_base_type
:
3853 case DW_TAG_subrange_type
:
3854 /* File scope base type definitions are added to the partial
3856 add_partial_symbol (pdi
, cu
);
3858 case DW_TAG_namespace
:
3859 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3862 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3869 /* If the die has a sibling, skip to the sibling. */
3871 pdi
= pdi
->die_sibling
;
3875 /* Functions used to compute the fully scoped name of a partial DIE.
3877 Normally, this is simple. For C++, the parent DIE's fully scoped
3878 name is concatenated with "::" and the partial DIE's name. For
3879 Java, the same thing occurs except that "." is used instead of "::".
3880 Enumerators are an exception; they use the scope of their parent
3881 enumeration type, i.e. the name of the enumeration type is not
3882 prepended to the enumerator.
3884 There are two complexities. One is DW_AT_specification; in this
3885 case "parent" means the parent of the target of the specification,
3886 instead of the direct parent of the DIE. The other is compilers
3887 which do not emit DW_TAG_namespace; in this case we try to guess
3888 the fully qualified name of structure types from their members'
3889 linkage names. This must be done using the DIE's children rather
3890 than the children of any DW_AT_specification target. We only need
3891 to do this for structures at the top level, i.e. if the target of
3892 any DW_AT_specification (if any; otherwise the DIE itself) does not
3895 /* Compute the scope prefix associated with PDI's parent, in
3896 compilation unit CU. The result will be allocated on CU's
3897 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3898 field. NULL is returned if no prefix is necessary. */
3900 partial_die_parent_scope (struct partial_die_info
*pdi
,
3901 struct dwarf2_cu
*cu
)
3903 char *grandparent_scope
;
3904 struct partial_die_info
*parent
, *real_pdi
;
3906 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3907 then this means the parent of the specification DIE. */
3910 while (real_pdi
->has_specification
)
3911 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3913 parent
= real_pdi
->die_parent
;
3917 if (parent
->scope_set
)
3918 return parent
->scope
;
3920 fixup_partial_die (parent
, cu
);
3922 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3924 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3925 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3926 Work around this problem here. */
3927 if (cu
->language
== language_cplus
3928 && parent
->tag
== DW_TAG_namespace
3929 && strcmp (parent
->name
, "::") == 0
3930 && grandparent_scope
== NULL
)
3932 parent
->scope
= NULL
;
3933 parent
->scope_set
= 1;
3937 if (pdi
->tag
== DW_TAG_enumerator
)
3938 /* Enumerators should not get the name of the enumeration as a prefix. */
3939 parent
->scope
= grandparent_scope
;
3940 else if (parent
->tag
== DW_TAG_namespace
3941 || parent
->tag
== DW_TAG_module
3942 || parent
->tag
== DW_TAG_structure_type
3943 || parent
->tag
== DW_TAG_class_type
3944 || parent
->tag
== DW_TAG_interface_type
3945 || parent
->tag
== DW_TAG_union_type
3946 || parent
->tag
== DW_TAG_enumeration_type
)
3948 if (grandparent_scope
== NULL
)
3949 parent
->scope
= parent
->name
;
3951 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3953 parent
->name
, 0, cu
);
3957 /* FIXME drow/2004-04-01: What should we be doing with
3958 function-local names? For partial symbols, we should probably be
3960 complaint (&symfile_complaints
,
3961 _("unhandled containing DIE tag %d for DIE at %d"),
3962 parent
->tag
, pdi
->offset
);
3963 parent
->scope
= grandparent_scope
;
3966 parent
->scope_set
= 1;
3967 return parent
->scope
;
3970 /* Return the fully scoped name associated with PDI, from compilation unit
3971 CU. The result will be allocated with malloc. */
3973 partial_die_full_name (struct partial_die_info
*pdi
,
3974 struct dwarf2_cu
*cu
)
3978 /* If this is a template instantiation, we can not work out the
3979 template arguments from partial DIEs. So, unfortunately, we have
3980 to go through the full DIEs. At least any work we do building
3981 types here will be reused if full symbols are loaded later. */
3982 if (pdi
->has_template_arguments
)
3984 fixup_partial_die (pdi
, cu
);
3986 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3988 struct die_info
*die
;
3989 struct attribute attr
;
3990 struct dwarf2_cu
*ref_cu
= cu
;
3993 attr
.form
= DW_FORM_ref_addr
;
3994 attr
.u
.addr
= pdi
->offset
;
3995 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3997 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4001 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4002 if (parent_scope
== NULL
)
4005 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4009 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4011 struct objfile
*objfile
= cu
->objfile
;
4013 char *actual_name
= NULL
;
4014 const struct partial_symbol
*psym
= NULL
;
4016 int built_actual_name
= 0;
4018 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4020 actual_name
= partial_die_full_name (pdi
, cu
);
4022 built_actual_name
= 1;
4024 if (actual_name
== NULL
)
4025 actual_name
= pdi
->name
;
4029 case DW_TAG_subprogram
:
4030 if (pdi
->is_external
|| cu
->language
== language_ada
)
4032 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4033 of the global scope. But in Ada, we want to be able to access
4034 nested procedures globally. So all Ada subprograms are stored
4035 in the global scope. */
4036 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4037 mst_text, objfile); */
4038 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4040 VAR_DOMAIN
, LOC_BLOCK
,
4041 &objfile
->global_psymbols
,
4042 0, pdi
->lowpc
+ baseaddr
,
4043 cu
->language
, objfile
);
4047 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4048 mst_file_text, objfile); */
4049 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4051 VAR_DOMAIN
, LOC_BLOCK
,
4052 &objfile
->static_psymbols
,
4053 0, pdi
->lowpc
+ baseaddr
,
4054 cu
->language
, objfile
);
4057 case DW_TAG_constant
:
4059 struct psymbol_allocation_list
*list
;
4061 if (pdi
->is_external
)
4062 list
= &objfile
->global_psymbols
;
4064 list
= &objfile
->static_psymbols
;
4065 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4066 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4067 list
, 0, 0, cu
->language
, objfile
);
4070 case DW_TAG_variable
:
4072 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4076 && !dwarf2_per_objfile
->has_section_at_zero
)
4078 /* A global or static variable may also have been stripped
4079 out by the linker if unused, in which case its address
4080 will be nullified; do not add such variables into partial
4081 symbol table then. */
4083 else if (pdi
->is_external
)
4086 Don't enter into the minimal symbol tables as there is
4087 a minimal symbol table entry from the ELF symbols already.
4088 Enter into partial symbol table if it has a location
4089 descriptor or a type.
4090 If the location descriptor is missing, new_symbol will create
4091 a LOC_UNRESOLVED symbol, the address of the variable will then
4092 be determined from the minimal symbol table whenever the variable
4094 The address for the partial symbol table entry is not
4095 used by GDB, but it comes in handy for debugging partial symbol
4098 if (pdi
->locdesc
|| pdi
->has_type
)
4099 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4101 VAR_DOMAIN
, LOC_STATIC
,
4102 &objfile
->global_psymbols
,
4104 cu
->language
, objfile
);
4108 /* Static Variable. Skip symbols without location descriptors. */
4109 if (pdi
->locdesc
== NULL
)
4111 if (built_actual_name
)
4112 xfree (actual_name
);
4115 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4116 mst_file_data, objfile); */
4117 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4119 VAR_DOMAIN
, LOC_STATIC
,
4120 &objfile
->static_psymbols
,
4122 cu
->language
, objfile
);
4125 case DW_TAG_typedef
:
4126 case DW_TAG_base_type
:
4127 case DW_TAG_subrange_type
:
4128 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4130 VAR_DOMAIN
, LOC_TYPEDEF
,
4131 &objfile
->static_psymbols
,
4132 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4134 case DW_TAG_namespace
:
4135 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4137 VAR_DOMAIN
, LOC_TYPEDEF
,
4138 &objfile
->global_psymbols
,
4139 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4141 case DW_TAG_class_type
:
4142 case DW_TAG_interface_type
:
4143 case DW_TAG_structure_type
:
4144 case DW_TAG_union_type
:
4145 case DW_TAG_enumeration_type
:
4146 /* Skip external references. The DWARF standard says in the section
4147 about "Structure, Union, and Class Type Entries": "An incomplete
4148 structure, union or class type is represented by a structure,
4149 union or class entry that does not have a byte size attribute
4150 and that has a DW_AT_declaration attribute." */
4151 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4153 if (built_actual_name
)
4154 xfree (actual_name
);
4158 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4159 static vs. global. */
4160 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4162 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4163 (cu
->language
== language_cplus
4164 || cu
->language
== language_java
)
4165 ? &objfile
->global_psymbols
4166 : &objfile
->static_psymbols
,
4167 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4170 case DW_TAG_enumerator
:
4171 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4173 VAR_DOMAIN
, LOC_CONST
,
4174 (cu
->language
== language_cplus
4175 || cu
->language
== language_java
)
4176 ? &objfile
->global_psymbols
4177 : &objfile
->static_psymbols
,
4178 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4184 if (built_actual_name
)
4185 xfree (actual_name
);
4188 /* Read a partial die corresponding to a namespace; also, add a symbol
4189 corresponding to that namespace to the symbol table. NAMESPACE is
4190 the name of the enclosing namespace. */
4193 add_partial_namespace (struct partial_die_info
*pdi
,
4194 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4195 int need_pc
, struct dwarf2_cu
*cu
)
4197 /* Add a symbol for the namespace. */
4199 add_partial_symbol (pdi
, cu
);
4201 /* Now scan partial symbols in that namespace. */
4203 if (pdi
->has_children
)
4204 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4207 /* Read a partial die corresponding to a Fortran module. */
4210 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4211 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4213 /* Now scan partial symbols in that module. */
4215 if (pdi
->has_children
)
4216 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4219 /* Read a partial die corresponding to a subprogram and create a partial
4220 symbol for that subprogram. When the CU language allows it, this
4221 routine also defines a partial symbol for each nested subprogram
4222 that this subprogram contains.
4224 DIE my also be a lexical block, in which case we simply search
4225 recursively for suprograms defined inside that lexical block.
4226 Again, this is only performed when the CU language allows this
4227 type of definitions. */
4230 add_partial_subprogram (struct partial_die_info
*pdi
,
4231 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4232 int need_pc
, struct dwarf2_cu
*cu
)
4234 if (pdi
->tag
== DW_TAG_subprogram
)
4236 if (pdi
->has_pc_info
)
4238 if (pdi
->lowpc
< *lowpc
)
4239 *lowpc
= pdi
->lowpc
;
4240 if (pdi
->highpc
> *highpc
)
4241 *highpc
= pdi
->highpc
;
4245 struct objfile
*objfile
= cu
->objfile
;
4247 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4248 SECT_OFF_TEXT (objfile
));
4249 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4250 pdi
->lowpc
+ baseaddr
,
4251 pdi
->highpc
- 1 + baseaddr
,
4252 cu
->per_cu
->v
.psymtab
);
4254 if (!pdi
->is_declaration
)
4255 /* Ignore subprogram DIEs that do not have a name, they are
4256 illegal. Do not emit a complaint at this point, we will
4257 do so when we convert this psymtab into a symtab. */
4259 add_partial_symbol (pdi
, cu
);
4263 if (! pdi
->has_children
)
4266 if (cu
->language
== language_ada
)
4268 pdi
= pdi
->die_child
;
4271 fixup_partial_die (pdi
, cu
);
4272 if (pdi
->tag
== DW_TAG_subprogram
4273 || pdi
->tag
== DW_TAG_lexical_block
)
4274 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4275 pdi
= pdi
->die_sibling
;
4280 /* Read a partial die corresponding to an enumeration type. */
4283 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4284 struct dwarf2_cu
*cu
)
4286 struct partial_die_info
*pdi
;
4288 if (enum_pdi
->name
!= NULL
)
4289 add_partial_symbol (enum_pdi
, cu
);
4291 pdi
= enum_pdi
->die_child
;
4294 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4295 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4297 add_partial_symbol (pdi
, cu
);
4298 pdi
= pdi
->die_sibling
;
4302 /* Return the initial uleb128 in the die at INFO_PTR. */
4305 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4307 unsigned int bytes_read
;
4309 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4312 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4313 Return the corresponding abbrev, or NULL if the number is zero (indicating
4314 an empty DIE). In either case *BYTES_READ will be set to the length of
4315 the initial number. */
4317 static struct abbrev_info
*
4318 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4319 struct dwarf2_cu
*cu
)
4321 bfd
*abfd
= cu
->objfile
->obfd
;
4322 unsigned int abbrev_number
;
4323 struct abbrev_info
*abbrev
;
4325 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4327 if (abbrev_number
== 0)
4330 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4333 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4334 abbrev_number
, bfd_get_filename (abfd
));
4340 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4341 Returns a pointer to the end of a series of DIEs, terminated by an empty
4342 DIE. Any children of the skipped DIEs will also be skipped. */
4345 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4347 struct abbrev_info
*abbrev
;
4348 unsigned int bytes_read
;
4352 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4354 return info_ptr
+ bytes_read
;
4356 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4360 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4361 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4362 abbrev corresponding to that skipped uleb128 should be passed in
4363 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4367 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4368 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4370 unsigned int bytes_read
;
4371 struct attribute attr
;
4372 bfd
*abfd
= cu
->objfile
->obfd
;
4373 unsigned int form
, i
;
4375 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4377 /* The only abbrev we care about is DW_AT_sibling. */
4378 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4380 read_attribute (&attr
, &abbrev
->attrs
[i
],
4381 abfd
, info_ptr
, cu
);
4382 if (attr
.form
== DW_FORM_ref_addr
)
4383 complaint (&symfile_complaints
,
4384 _("ignoring absolute DW_AT_sibling"));
4386 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4389 /* If it isn't DW_AT_sibling, skip this attribute. */
4390 form
= abbrev
->attrs
[i
].form
;
4394 case DW_FORM_ref_addr
:
4395 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4396 and later it is offset sized. */
4397 if (cu
->header
.version
== 2)
4398 info_ptr
+= cu
->header
.addr_size
;
4400 info_ptr
+= cu
->header
.offset_size
;
4403 info_ptr
+= cu
->header
.addr_size
;
4410 case DW_FORM_flag_present
:
4422 case DW_FORM_ref_sig8
:
4425 case DW_FORM_string
:
4426 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4427 info_ptr
+= bytes_read
;
4429 case DW_FORM_sec_offset
:
4431 info_ptr
+= cu
->header
.offset_size
;
4433 case DW_FORM_exprloc
:
4435 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4436 info_ptr
+= bytes_read
;
4438 case DW_FORM_block1
:
4439 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4441 case DW_FORM_block2
:
4442 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4444 case DW_FORM_block4
:
4445 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4449 case DW_FORM_ref_udata
:
4450 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4452 case DW_FORM_indirect
:
4453 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4454 info_ptr
+= bytes_read
;
4455 /* We need to continue parsing from here, so just go back to
4457 goto skip_attribute
;
4460 error (_("Dwarf Error: Cannot handle %s "
4461 "in DWARF reader [in module %s]"),
4462 dwarf_form_name (form
),
4463 bfd_get_filename (abfd
));
4467 if (abbrev
->has_children
)
4468 return skip_children (buffer
, info_ptr
, cu
);
4473 /* Locate ORIG_PDI's sibling.
4474 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4478 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4479 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4480 bfd
*abfd
, struct dwarf2_cu
*cu
)
4482 /* Do we know the sibling already? */
4484 if (orig_pdi
->sibling
)
4485 return orig_pdi
->sibling
;
4487 /* Are there any children to deal with? */
4489 if (!orig_pdi
->has_children
)
4492 /* Skip the children the long way. */
4494 return skip_children (buffer
, info_ptr
, cu
);
4497 /* Expand this partial symbol table into a full symbol table. */
4500 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4506 warning (_("bug: psymtab for %s is already read in."),
4513 printf_filtered (_("Reading in symbols for %s..."),
4515 gdb_flush (gdb_stdout
);
4518 /* Restore our global data. */
4519 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4520 dwarf2_objfile_data_key
);
4522 /* If this psymtab is constructed from a debug-only objfile, the
4523 has_section_at_zero flag will not necessarily be correct. We
4524 can get the correct value for this flag by looking at the data
4525 associated with the (presumably stripped) associated objfile. */
4526 if (pst
->objfile
->separate_debug_objfile_backlink
)
4528 struct dwarf2_per_objfile
*dpo_backlink
4529 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4530 dwarf2_objfile_data_key
);
4532 dwarf2_per_objfile
->has_section_at_zero
4533 = dpo_backlink
->has_section_at_zero
;
4536 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4538 psymtab_to_symtab_1 (pst
);
4540 /* Finish up the debug error message. */
4542 printf_filtered (_("done.\n"));
4547 /* Reading in full CUs. */
4549 /* Add PER_CU to the queue. */
4552 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4554 struct dwarf2_queue_item
*item
;
4557 item
= xmalloc (sizeof (*item
));
4558 item
->per_cu
= per_cu
;
4561 if (dwarf2_queue
== NULL
)
4562 dwarf2_queue
= item
;
4564 dwarf2_queue_tail
->next
= item
;
4566 dwarf2_queue_tail
= item
;
4569 /* Process the queue. */
4572 process_queue (void)
4574 struct dwarf2_queue_item
*item
, *next_item
;
4576 /* The queue starts out with one item, but following a DIE reference
4577 may load a new CU, adding it to the end of the queue. */
4578 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4580 if (dwarf2_per_objfile
->using_index
4581 ? !item
->per_cu
->v
.quick
->symtab
4582 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4583 process_full_comp_unit (item
->per_cu
);
4585 item
->per_cu
->queued
= 0;
4586 next_item
= item
->next
;
4590 dwarf2_queue_tail
= NULL
;
4593 /* Free all allocated queue entries. This function only releases anything if
4594 an error was thrown; if the queue was processed then it would have been
4595 freed as we went along. */
4598 dwarf2_release_queue (void *dummy
)
4600 struct dwarf2_queue_item
*item
, *last
;
4602 item
= dwarf2_queue
;
4605 /* Anything still marked queued is likely to be in an
4606 inconsistent state, so discard it. */
4607 if (item
->per_cu
->queued
)
4609 if (item
->per_cu
->cu
!= NULL
)
4610 free_one_cached_comp_unit (item
->per_cu
->cu
);
4611 item
->per_cu
->queued
= 0;
4619 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4622 /* Read in full symbols for PST, and anything it depends on. */
4625 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4627 struct dwarf2_per_cu_data
*per_cu
;
4628 struct cleanup
*back_to
;
4631 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4632 if (!pst
->dependencies
[i
]->readin
)
4634 /* Inform about additional files that need to be read in. */
4637 /* FIXME: i18n: Need to make this a single string. */
4638 fputs_filtered (" ", gdb_stdout
);
4640 fputs_filtered ("and ", gdb_stdout
);
4642 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4643 wrap_here (""); /* Flush output. */
4644 gdb_flush (gdb_stdout
);
4646 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4649 per_cu
= pst
->read_symtab_private
;
4653 /* It's an include file, no symbols to read for it.
4654 Everything is in the parent symtab. */
4659 dw2_do_instantiate_symtab (per_cu
);
4662 /* Load the DIEs associated with PER_CU into memory. */
4665 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4667 struct objfile
*objfile
= per_cu
->objfile
;
4668 bfd
*abfd
= objfile
->obfd
;
4669 struct dwarf2_cu
*cu
;
4670 unsigned int offset
;
4671 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4672 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4673 struct attribute
*attr
;
4676 gdb_assert (! per_cu
->debug_types_section
);
4678 /* Set local variables from the partial symbol table info. */
4679 offset
= per_cu
->offset
;
4681 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4682 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4683 beg_of_comp_unit
= info_ptr
;
4685 if (per_cu
->cu
== NULL
)
4687 cu
= xmalloc (sizeof (*cu
));
4688 init_one_comp_unit (cu
, per_cu
);
4692 /* If an error occurs while loading, release our storage. */
4693 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4695 /* Read in the comp_unit header. */
4696 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4698 /* Skip dummy compilation units. */
4699 if (info_ptr
>= (dwarf2_per_objfile
->info
.buffer
4700 + dwarf2_per_objfile
->info
.size
)
4701 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4703 do_cleanups (free_cu_cleanup
);
4707 /* Complete the cu_header. */
4708 cu
->header
.offset
= offset
;
4709 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4711 /* Read the abbrevs for this compilation unit. */
4712 dwarf2_read_abbrevs (cu
);
4713 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4715 /* Link this CU into read_in_chain. */
4716 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4717 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4722 info_ptr
+= cu
->header
.first_die_offset
;
4725 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4727 /* We try not to read any attributes in this function, because not
4728 all CUs needed for references have been loaded yet, and symbol
4729 table processing isn't initialized. But we have to set the CU language,
4730 or we won't be able to build types correctly. */
4731 prepare_one_comp_unit (cu
, cu
->dies
);
4733 /* Similarly, if we do not read the producer, we can not apply
4734 producer-specific interpretation. */
4735 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4737 cu
->producer
= DW_STRING (attr
);
4741 do_cleanups (free_abbrevs_cleanup
);
4743 /* We've successfully allocated this compilation unit. Let our
4744 caller clean it up when finished with it. */
4745 discard_cleanups (free_cu_cleanup
);
4749 /* Add a DIE to the delayed physname list. */
4752 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4753 const char *name
, struct die_info
*die
,
4754 struct dwarf2_cu
*cu
)
4756 struct delayed_method_info mi
;
4758 mi
.fnfield_index
= fnfield_index
;
4762 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4765 /* A cleanup for freeing the delayed method list. */
4768 free_delayed_list (void *ptr
)
4770 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4771 if (cu
->method_list
!= NULL
)
4773 VEC_free (delayed_method_info
, cu
->method_list
);
4774 cu
->method_list
= NULL
;
4778 /* Compute the physnames of any methods on the CU's method list.
4780 The computation of method physnames is delayed in order to avoid the
4781 (bad) condition that one of the method's formal parameters is of an as yet
4785 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4788 struct delayed_method_info
*mi
;
4789 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4791 const char *physname
;
4792 struct fn_fieldlist
*fn_flp
4793 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4794 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4795 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4799 /* Generate full symbol information for PER_CU, whose DIEs have
4800 already been loaded into memory. */
4803 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4805 struct dwarf2_cu
*cu
= per_cu
->cu
;
4806 struct objfile
*objfile
= per_cu
->objfile
;
4807 CORE_ADDR lowpc
, highpc
;
4808 struct symtab
*symtab
;
4809 struct cleanup
*back_to
, *delayed_list_cleanup
;
4812 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4815 back_to
= make_cleanup (really_free_pendings
, NULL
);
4816 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4818 cu
->list_in_scope
= &file_symbols
;
4820 /* Do line number decoding in read_file_scope () */
4821 process_die (cu
->dies
, cu
);
4823 /* Now that we have processed all the DIEs in the CU, all the types
4824 should be complete, and it should now be safe to compute all of the
4826 compute_delayed_physnames (cu
);
4827 do_cleanups (delayed_list_cleanup
);
4829 /* Some compilers don't define a DW_AT_high_pc attribute for the
4830 compilation unit. If the DW_AT_high_pc is missing, synthesize
4831 it, by scanning the DIE's below the compilation unit. */
4832 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4834 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4838 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
4840 /* Set symtab language to language from DW_AT_language. If the
4841 compilation is from a C file generated by language preprocessors, do
4842 not set the language if it was already deduced by start_subfile. */
4843 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4844 symtab
->language
= cu
->language
;
4846 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4847 produce DW_AT_location with location lists but it can be possibly
4848 invalid without -fvar-tracking.
4850 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4851 needed, it would be wrong due to missing DW_AT_producer there.
4853 Still one can confuse GDB by using non-standard GCC compilation
4854 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4856 if (cu
->has_loclist
&& gcc_4_minor
>= 0)
4857 symtab
->locations_valid
= 1;
4859 if (gcc_4_minor
>= 5)
4860 symtab
->epilogue_unwind_valid
= 1;
4862 symtab
->call_site_htab
= cu
->call_site_htab
;
4865 if (dwarf2_per_objfile
->using_index
)
4866 per_cu
->v
.quick
->symtab
= symtab
;
4869 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4870 pst
->symtab
= symtab
;
4874 do_cleanups (back_to
);
4877 /* Process a die and its children. */
4880 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4884 case DW_TAG_padding
:
4886 case DW_TAG_compile_unit
:
4887 read_file_scope (die
, cu
);
4889 case DW_TAG_type_unit
:
4890 read_type_unit_scope (die
, cu
);
4892 case DW_TAG_subprogram
:
4893 case DW_TAG_inlined_subroutine
:
4894 read_func_scope (die
, cu
);
4896 case DW_TAG_lexical_block
:
4897 case DW_TAG_try_block
:
4898 case DW_TAG_catch_block
:
4899 read_lexical_block_scope (die
, cu
);
4901 case DW_TAG_GNU_call_site
:
4902 read_call_site_scope (die
, cu
);
4904 case DW_TAG_class_type
:
4905 case DW_TAG_interface_type
:
4906 case DW_TAG_structure_type
:
4907 case DW_TAG_union_type
:
4908 process_structure_scope (die
, cu
);
4910 case DW_TAG_enumeration_type
:
4911 process_enumeration_scope (die
, cu
);
4914 /* These dies have a type, but processing them does not create
4915 a symbol or recurse to process the children. Therefore we can
4916 read them on-demand through read_type_die. */
4917 case DW_TAG_subroutine_type
:
4918 case DW_TAG_set_type
:
4919 case DW_TAG_array_type
:
4920 case DW_TAG_pointer_type
:
4921 case DW_TAG_ptr_to_member_type
:
4922 case DW_TAG_reference_type
:
4923 case DW_TAG_string_type
:
4926 case DW_TAG_base_type
:
4927 case DW_TAG_subrange_type
:
4928 case DW_TAG_typedef
:
4929 /* Add a typedef symbol for the type definition, if it has a
4931 new_symbol (die
, read_type_die (die
, cu
), cu
);
4933 case DW_TAG_common_block
:
4934 read_common_block (die
, cu
);
4936 case DW_TAG_common_inclusion
:
4938 case DW_TAG_namespace
:
4939 processing_has_namespace_info
= 1;
4940 read_namespace (die
, cu
);
4943 processing_has_namespace_info
= 1;
4944 read_module (die
, cu
);
4946 case DW_TAG_imported_declaration
:
4947 case DW_TAG_imported_module
:
4948 processing_has_namespace_info
= 1;
4949 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4950 || cu
->language
!= language_fortran
))
4951 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4952 dwarf_tag_name (die
->tag
));
4953 read_import_statement (die
, cu
);
4956 new_symbol (die
, NULL
, cu
);
4961 /* A helper function for dwarf2_compute_name which determines whether DIE
4962 needs to have the name of the scope prepended to the name listed in the
4966 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4968 struct attribute
*attr
;
4972 case DW_TAG_namespace
:
4973 case DW_TAG_typedef
:
4974 case DW_TAG_class_type
:
4975 case DW_TAG_interface_type
:
4976 case DW_TAG_structure_type
:
4977 case DW_TAG_union_type
:
4978 case DW_TAG_enumeration_type
:
4979 case DW_TAG_enumerator
:
4980 case DW_TAG_subprogram
:
4984 case DW_TAG_variable
:
4985 case DW_TAG_constant
:
4986 /* We only need to prefix "globally" visible variables. These include
4987 any variable marked with DW_AT_external or any variable that
4988 lives in a namespace. [Variables in anonymous namespaces
4989 require prefixing, but they are not DW_AT_external.] */
4991 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4993 struct dwarf2_cu
*spec_cu
= cu
;
4995 return die_needs_namespace (die_specification (die
, &spec_cu
),
4999 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5000 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
5001 && die
->parent
->tag
!= DW_TAG_module
)
5003 /* A variable in a lexical block of some kind does not need a
5004 namespace, even though in C++ such variables may be external
5005 and have a mangled name. */
5006 if (die
->parent
->tag
== DW_TAG_lexical_block
5007 || die
->parent
->tag
== DW_TAG_try_block
5008 || die
->parent
->tag
== DW_TAG_catch_block
5009 || die
->parent
->tag
== DW_TAG_subprogram
)
5018 /* Retrieve the last character from a mem_file. */
5021 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
5023 char *last_char_p
= (char *) object
;
5026 *last_char_p
= buffer
[length
- 1];
5029 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5030 compute the physname for the object, which include a method's
5031 formal parameters (C++/Java) and return type (Java).
5033 For Ada, return the DIE's linkage name rather than the fully qualified
5034 name. PHYSNAME is ignored..
5036 The result is allocated on the objfile_obstack and canonicalized. */
5039 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5042 struct objfile
*objfile
= cu
->objfile
;
5045 name
= dwarf2_name (die
, cu
);
5047 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5048 compute it by typename_concat inside GDB. */
5049 if (cu
->language
== language_ada
5050 || (cu
->language
== language_fortran
&& physname
))
5052 /* For Ada unit, we prefer the linkage name over the name, as
5053 the former contains the exported name, which the user expects
5054 to be able to reference. Ideally, we want the user to be able
5055 to reference this entity using either natural or linkage name,
5056 but we haven't started looking at this enhancement yet. */
5057 struct attribute
*attr
;
5059 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5061 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5062 if (attr
&& DW_STRING (attr
))
5063 return DW_STRING (attr
);
5066 /* These are the only languages we know how to qualify names in. */
5068 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5069 || cu
->language
== language_fortran
))
5071 if (die_needs_namespace (die
, cu
))
5075 struct ui_file
*buf
;
5077 prefix
= determine_prefix (die
, cu
);
5078 buf
= mem_fileopen ();
5079 if (*prefix
!= '\0')
5081 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5084 fputs_unfiltered (prefixed_name
, buf
);
5085 xfree (prefixed_name
);
5088 fputs_unfiltered (name
, buf
);
5090 /* Template parameters may be specified in the DIE's DW_AT_name, or
5091 as children with DW_TAG_template_type_param or
5092 DW_TAG_value_type_param. If the latter, add them to the name
5093 here. If the name already has template parameters, then
5094 skip this step; some versions of GCC emit both, and
5095 it is more efficient to use the pre-computed name.
5097 Something to keep in mind about this process: it is very
5098 unlikely, or in some cases downright impossible, to produce
5099 something that will match the mangled name of a function.
5100 If the definition of the function has the same debug info,
5101 we should be able to match up with it anyway. But fallbacks
5102 using the minimal symbol, for instance to find a method
5103 implemented in a stripped copy of libstdc++, will not work.
5104 If we do not have debug info for the definition, we will have to
5105 match them up some other way.
5107 When we do name matching there is a related problem with function
5108 templates; two instantiated function templates are allowed to
5109 differ only by their return types, which we do not add here. */
5111 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5113 struct attribute
*attr
;
5114 struct die_info
*child
;
5117 die
->building_fullname
= 1;
5119 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5124 struct dwarf2_locexpr_baton
*baton
;
5127 if (child
->tag
!= DW_TAG_template_type_param
5128 && child
->tag
!= DW_TAG_template_value_param
)
5133 fputs_unfiltered ("<", buf
);
5137 fputs_unfiltered (", ", buf
);
5139 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5142 complaint (&symfile_complaints
,
5143 _("template parameter missing DW_AT_type"));
5144 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5147 type
= die_type (child
, cu
);
5149 if (child
->tag
== DW_TAG_template_type_param
)
5151 c_print_type (type
, "", buf
, -1, 0);
5155 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5158 complaint (&symfile_complaints
,
5159 _("template parameter missing "
5160 "DW_AT_const_value"));
5161 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5165 dwarf2_const_value_attr (attr
, type
, name
,
5166 &cu
->comp_unit_obstack
, cu
,
5167 &value
, &bytes
, &baton
);
5169 if (TYPE_NOSIGN (type
))
5170 /* GDB prints characters as NUMBER 'CHAR'. If that's
5171 changed, this can use value_print instead. */
5172 c_printchar (value
, type
, buf
);
5175 struct value_print_options opts
;
5178 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5182 else if (bytes
!= NULL
)
5184 v
= allocate_value (type
);
5185 memcpy (value_contents_writeable (v
), bytes
,
5186 TYPE_LENGTH (type
));
5189 v
= value_from_longest (type
, value
);
5191 /* Specify decimal so that we do not depend on
5193 get_formatted_print_options (&opts
, 'd');
5195 value_print (v
, buf
, &opts
);
5201 die
->building_fullname
= 0;
5205 /* Close the argument list, with a space if necessary
5206 (nested templates). */
5207 char last_char
= '\0';
5208 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5209 if (last_char
== '>')
5210 fputs_unfiltered (" >", buf
);
5212 fputs_unfiltered (">", buf
);
5216 /* For Java and C++ methods, append formal parameter type
5217 information, if PHYSNAME. */
5219 if (physname
&& die
->tag
== DW_TAG_subprogram
5220 && (cu
->language
== language_cplus
5221 || cu
->language
== language_java
))
5223 struct type
*type
= read_type_die (die
, cu
);
5225 c_type_print_args (type
, buf
, 1, cu
->language
);
5227 if (cu
->language
== language_java
)
5229 /* For java, we must append the return type to method
5231 if (die
->tag
== DW_TAG_subprogram
)
5232 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5235 else if (cu
->language
== language_cplus
)
5237 /* Assume that an artificial first parameter is
5238 "this", but do not crash if it is not. RealView
5239 marks unnamed (and thus unused) parameters as
5240 artificial; there is no way to differentiate
5242 if (TYPE_NFIELDS (type
) > 0
5243 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5244 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5245 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5247 fputs_unfiltered (" const", buf
);
5251 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
5253 ui_file_delete (buf
);
5255 if (cu
->language
== language_cplus
)
5258 = dwarf2_canonicalize_name (name
, cu
,
5259 &objfile
->objfile_obstack
);
5270 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5271 If scope qualifiers are appropriate they will be added. The result
5272 will be allocated on the objfile_obstack, or NULL if the DIE does
5273 not have a name. NAME may either be from a previous call to
5274 dwarf2_name or NULL.
5276 The output string will be canonicalized (if C++/Java). */
5279 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5281 return dwarf2_compute_name (name
, die
, cu
, 0);
5284 /* Construct a physname for the given DIE in CU. NAME may either be
5285 from a previous call to dwarf2_name or NULL. The result will be
5286 allocated on the objfile_objstack or NULL if the DIE does not have a
5289 The output string will be canonicalized (if C++/Java). */
5292 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5294 struct objfile
*objfile
= cu
->objfile
;
5295 struct attribute
*attr
;
5296 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5297 struct cleanup
*back_to
;
5300 /* In this case dwarf2_compute_name is just a shortcut not building anything
5302 if (!die_needs_namespace (die
, cu
))
5303 return dwarf2_compute_name (name
, die
, cu
, 1);
5305 back_to
= make_cleanup (null_cleanup
, NULL
);
5307 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5309 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5311 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5313 if (attr
&& DW_STRING (attr
))
5317 mangled
= DW_STRING (attr
);
5319 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5320 type. It is easier for GDB users to search for such functions as
5321 `name(params)' than `long name(params)'. In such case the minimal
5322 symbol names do not match the full symbol names but for template
5323 functions there is never a need to look up their definition from their
5324 declaration so the only disadvantage remains the minimal symbol
5325 variant `long name(params)' does not have the proper inferior type.
5328 demangled
= cplus_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
5329 | (cu
->language
== language_java
5330 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5334 make_cleanup (xfree
, demangled
);
5344 if (canon
== NULL
|| check_physname
)
5346 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5348 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5350 /* It may not mean a bug in GDB. The compiler could also
5351 compute DW_AT_linkage_name incorrectly. But in such case
5352 GDB would need to be bug-to-bug compatible. */
5354 complaint (&symfile_complaints
,
5355 _("Computed physname <%s> does not match demangled <%s> "
5356 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5357 physname
, canon
, mangled
, die
->offset
, objfile
->name
);
5359 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5360 is available here - over computed PHYSNAME. It is safer
5361 against both buggy GDB and buggy compilers. */
5375 retval
= obsavestring (retval
, strlen (retval
),
5376 &objfile
->objfile_obstack
);
5378 do_cleanups (back_to
);
5382 /* Read the import statement specified by the given die and record it. */
5385 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5387 struct objfile
*objfile
= cu
->objfile
;
5388 struct attribute
*import_attr
;
5389 struct die_info
*imported_die
, *child_die
;
5390 struct dwarf2_cu
*imported_cu
;
5391 const char *imported_name
;
5392 const char *imported_name_prefix
;
5393 const char *canonical_name
;
5394 const char *import_alias
;
5395 const char *imported_declaration
= NULL
;
5396 const char *import_prefix
;
5397 VEC (const_char_ptr
) *excludes
= NULL
;
5398 struct cleanup
*cleanups
;
5402 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5403 if (import_attr
== NULL
)
5405 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5406 dwarf_tag_name (die
->tag
));
5411 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5412 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5413 if (imported_name
== NULL
)
5415 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5417 The import in the following code:
5431 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5432 <52> DW_AT_decl_file : 1
5433 <53> DW_AT_decl_line : 6
5434 <54> DW_AT_import : <0x75>
5435 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5437 <5b> DW_AT_decl_file : 1
5438 <5c> DW_AT_decl_line : 2
5439 <5d> DW_AT_type : <0x6e>
5441 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5442 <76> DW_AT_byte_size : 4
5443 <77> DW_AT_encoding : 5 (signed)
5445 imports the wrong die ( 0x75 instead of 0x58 ).
5446 This case will be ignored until the gcc bug is fixed. */
5450 /* Figure out the local name after import. */
5451 import_alias
= dwarf2_name (die
, cu
);
5453 /* Figure out where the statement is being imported to. */
5454 import_prefix
= determine_prefix (die
, cu
);
5456 /* Figure out what the scope of the imported die is and prepend it
5457 to the name of the imported die. */
5458 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5460 if (imported_die
->tag
!= DW_TAG_namespace
5461 && imported_die
->tag
!= DW_TAG_module
)
5463 imported_declaration
= imported_name
;
5464 canonical_name
= imported_name_prefix
;
5466 else if (strlen (imported_name_prefix
) > 0)
5468 temp
= alloca (strlen (imported_name_prefix
)
5469 + 2 + strlen (imported_name
) + 1);
5470 strcpy (temp
, imported_name_prefix
);
5471 strcat (temp
, "::");
5472 strcat (temp
, imported_name
);
5473 canonical_name
= temp
;
5476 canonical_name
= imported_name
;
5478 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5480 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5481 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5482 child_die
= sibling_die (child_die
))
5484 /* DWARF-4: A Fortran use statement with a “rename list” may be
5485 represented by an imported module entry with an import attribute
5486 referring to the module and owned entries corresponding to those
5487 entities that are renamed as part of being imported. */
5489 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5491 complaint (&symfile_complaints
,
5492 _("child DW_TAG_imported_declaration expected "
5493 "- DIE at 0x%x [in module %s]"),
5494 child_die
->offset
, objfile
->name
);
5498 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5499 if (import_attr
== NULL
)
5501 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5502 dwarf_tag_name (child_die
->tag
));
5507 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5509 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5510 if (imported_name
== NULL
)
5512 complaint (&symfile_complaints
,
5513 _("child DW_TAG_imported_declaration has unknown "
5514 "imported name - DIE at 0x%x [in module %s]"),
5515 child_die
->offset
, objfile
->name
);
5519 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5521 process_die (child_die
, cu
);
5524 cp_add_using_directive (import_prefix
,
5527 imported_declaration
,
5529 &objfile
->objfile_obstack
);
5531 do_cleanups (cleanups
);
5534 /* Cleanup function for read_file_scope. */
5537 free_cu_line_header (void *arg
)
5539 struct dwarf2_cu
*cu
= arg
;
5541 free_line_header (cu
->line_header
);
5542 cu
->line_header
= NULL
;
5546 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5547 char **name
, char **comp_dir
)
5549 struct attribute
*attr
;
5554 /* Find the filename. Do not use dwarf2_name here, since the filename
5555 is not a source language identifier. */
5556 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5559 *name
= DW_STRING (attr
);
5562 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5564 *comp_dir
= DW_STRING (attr
);
5565 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5567 *comp_dir
= ldirname (*name
);
5568 if (*comp_dir
!= NULL
)
5569 make_cleanup (xfree
, *comp_dir
);
5571 if (*comp_dir
!= NULL
)
5573 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5574 directory, get rid of it. */
5575 char *cp
= strchr (*comp_dir
, ':');
5577 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5582 *name
= "<unknown>";
5585 /* Handle DW_AT_stmt_list for a compilation unit. */
5588 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
5589 const char *comp_dir
)
5591 struct attribute
*attr
;
5592 struct objfile
*objfile
= cu
->objfile
;
5593 bfd
*abfd
= objfile
->obfd
;
5595 /* Decode line number information if present. We do this before
5596 processing child DIEs, so that the line header table is available
5597 for DW_AT_decl_file. */
5598 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5601 unsigned int line_offset
= DW_UNSND (attr
);
5602 struct line_header
*line_header
5603 = dwarf_decode_line_header (line_offset
, abfd
, cu
);
5607 cu
->line_header
= line_header
;
5608 make_cleanup (free_cu_line_header
, cu
);
5609 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5614 /* Process DW_TAG_compile_unit. */
5617 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5619 struct objfile
*objfile
= cu
->objfile
;
5620 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5621 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5622 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5623 struct attribute
*attr
;
5625 char *comp_dir
= NULL
;
5626 struct die_info
*child_die
;
5627 bfd
*abfd
= objfile
->obfd
;
5630 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5632 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5634 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5635 from finish_block. */
5636 if (lowpc
== ((CORE_ADDR
) -1))
5641 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5643 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5646 set_cu_language (DW_UNSND (attr
), cu
);
5649 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5651 cu
->producer
= DW_STRING (attr
);
5653 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5654 standardised yet. As a workaround for the language detection we fall
5655 back to the DW_AT_producer string. */
5656 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5657 cu
->language
= language_opencl
;
5659 /* We assume that we're processing GCC output. */
5660 processing_gcc_compilation
= 2;
5662 processing_has_namespace_info
= 0;
5664 start_symtab (name
, comp_dir
, lowpc
);
5665 record_debugformat ("DWARF 2");
5666 record_producer (cu
->producer
);
5668 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5670 /* Process all dies in compilation unit. */
5671 if (die
->child
!= NULL
)
5673 child_die
= die
->child
;
5674 while (child_die
&& child_die
->tag
)
5676 process_die (child_die
, cu
);
5677 child_die
= sibling_die (child_die
);
5681 /* Decode macro information, if present. Dwarf 2 macro information
5682 refers to information in the line number info statement program
5683 header, so we can only read it if we've read the header
5685 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
5686 if (attr
&& cu
->line_header
)
5688 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
5689 complaint (&symfile_complaints
,
5690 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5692 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
5694 &dwarf2_per_objfile
->macro
, 1);
5698 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5699 if (attr
&& cu
->line_header
)
5701 unsigned int macro_offset
= DW_UNSND (attr
);
5703 dwarf_decode_macros (cu
->line_header
, macro_offset
,
5705 &dwarf2_per_objfile
->macinfo
, 0);
5709 do_cleanups (back_to
);
5712 /* Process DW_TAG_type_unit.
5713 For TUs we want to skip the first top level sibling if it's not the
5714 actual type being defined by this TU. In this case the first top
5715 level sibling is there to provide context only. */
5718 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5720 struct objfile
*objfile
= cu
->objfile
;
5721 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5723 struct attribute
*attr
;
5725 char *comp_dir
= NULL
;
5726 struct die_info
*child_die
;
5727 bfd
*abfd
= objfile
->obfd
;
5729 /* start_symtab needs a low pc, but we don't really have one.
5730 Do what read_file_scope would do in the absence of such info. */
5731 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5733 /* Find the filename. Do not use dwarf2_name here, since the filename
5734 is not a source language identifier. */
5735 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5737 name
= DW_STRING (attr
);
5739 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5741 comp_dir
= DW_STRING (attr
);
5742 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5744 comp_dir
= ldirname (name
);
5745 if (comp_dir
!= NULL
)
5746 make_cleanup (xfree
, comp_dir
);
5752 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5754 set_cu_language (DW_UNSND (attr
), cu
);
5756 /* This isn't technically needed today. It is done for symmetry
5757 with read_file_scope. */
5758 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5760 cu
->producer
= DW_STRING (attr
);
5762 /* We assume that we're processing GCC output. */
5763 processing_gcc_compilation
= 2;
5765 processing_has_namespace_info
= 0;
5767 start_symtab (name
, comp_dir
, lowpc
);
5768 record_debugformat ("DWARF 2");
5769 record_producer (cu
->producer
);
5771 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5773 /* Process the dies in the type unit. */
5774 if (die
->child
== NULL
)
5776 dump_die_for_error (die
);
5777 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5778 bfd_get_filename (abfd
));
5781 child_die
= die
->child
;
5783 while (child_die
&& child_die
->tag
)
5785 process_die (child_die
, cu
);
5787 child_die
= sibling_die (child_die
);
5790 do_cleanups (back_to
);
5793 /* qsort helper for inherit_abstract_dies. */
5796 unsigned_int_compar (const void *ap
, const void *bp
)
5798 unsigned int a
= *(unsigned int *) ap
;
5799 unsigned int b
= *(unsigned int *) bp
;
5801 return (a
> b
) - (b
> a
);
5804 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5805 Inherit only the children of the DW_AT_abstract_origin DIE not being
5806 already referenced by DW_AT_abstract_origin from the children of the
5810 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5812 struct die_info
*child_die
;
5813 unsigned die_children_count
;
5814 /* CU offsets which were referenced by children of the current DIE. */
5816 unsigned *offsets_end
, *offsetp
;
5817 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5818 struct die_info
*origin_die
;
5819 /* Iterator of the ORIGIN_DIE children. */
5820 struct die_info
*origin_child_die
;
5821 struct cleanup
*cleanups
;
5822 struct attribute
*attr
;
5823 struct dwarf2_cu
*origin_cu
;
5824 struct pending
**origin_previous_list_in_scope
;
5826 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5830 /* Note that following die references may follow to a die in a
5834 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5836 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5838 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5839 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5841 if (die
->tag
!= origin_die
->tag
5842 && !(die
->tag
== DW_TAG_inlined_subroutine
5843 && origin_die
->tag
== DW_TAG_subprogram
))
5844 complaint (&symfile_complaints
,
5845 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5846 die
->offset
, origin_die
->offset
);
5848 child_die
= die
->child
;
5849 die_children_count
= 0;
5850 while (child_die
&& child_die
->tag
)
5852 child_die
= sibling_die (child_die
);
5853 die_children_count
++;
5855 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5856 cleanups
= make_cleanup (xfree
, offsets
);
5858 offsets_end
= offsets
;
5859 child_die
= die
->child
;
5860 while (child_die
&& child_die
->tag
)
5862 /* For each CHILD_DIE, find the corresponding child of
5863 ORIGIN_DIE. If there is more than one layer of
5864 DW_AT_abstract_origin, follow them all; there shouldn't be,
5865 but GCC versions at least through 4.4 generate this (GCC PR
5867 struct die_info
*child_origin_die
= child_die
;
5868 struct dwarf2_cu
*child_origin_cu
= cu
;
5872 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5876 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5880 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5881 counterpart may exist. */
5882 if (child_origin_die
!= child_die
)
5884 if (child_die
->tag
!= child_origin_die
->tag
5885 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5886 && child_origin_die
->tag
== DW_TAG_subprogram
))
5887 complaint (&symfile_complaints
,
5888 _("Child DIE 0x%x and its abstract origin 0x%x have "
5889 "different tags"), child_die
->offset
,
5890 child_origin_die
->offset
);
5891 if (child_origin_die
->parent
!= origin_die
)
5892 complaint (&symfile_complaints
,
5893 _("Child DIE 0x%x and its abstract origin 0x%x have "
5894 "different parents"), child_die
->offset
,
5895 child_origin_die
->offset
);
5897 *offsets_end
++ = child_origin_die
->offset
;
5899 child_die
= sibling_die (child_die
);
5901 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5902 unsigned_int_compar
);
5903 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5904 if (offsetp
[-1] == *offsetp
)
5905 complaint (&symfile_complaints
,
5906 _("Multiple children of DIE 0x%x refer "
5907 "to DIE 0x%x as their abstract origin"),
5908 die
->offset
, *offsetp
);
5911 origin_child_die
= origin_die
->child
;
5912 while (origin_child_die
&& origin_child_die
->tag
)
5914 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5915 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5917 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5919 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5920 process_die (origin_child_die
, origin_cu
);
5922 origin_child_die
= sibling_die (origin_child_die
);
5924 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5926 do_cleanups (cleanups
);
5930 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5932 struct objfile
*objfile
= cu
->objfile
;
5933 struct context_stack
*new;
5936 struct die_info
*child_die
;
5937 struct attribute
*attr
, *call_line
, *call_file
;
5940 struct block
*block
;
5941 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5942 VEC (symbolp
) *template_args
= NULL
;
5943 struct template_symbol
*templ_func
= NULL
;
5947 /* If we do not have call site information, we can't show the
5948 caller of this inlined function. That's too confusing, so
5949 only use the scope for local variables. */
5950 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5951 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5952 if (call_line
== NULL
|| call_file
== NULL
)
5954 read_lexical_block_scope (die
, cu
);
5959 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5961 name
= dwarf2_name (die
, cu
);
5963 /* Ignore functions with missing or empty names. These are actually
5964 illegal according to the DWARF standard. */
5967 complaint (&symfile_complaints
,
5968 _("missing name for subprogram DIE at %d"), die
->offset
);
5972 /* Ignore functions with missing or invalid low and high pc attributes. */
5973 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5975 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5976 if (!attr
|| !DW_UNSND (attr
))
5977 complaint (&symfile_complaints
,
5978 _("cannot get low and high bounds "
5979 "for subprogram DIE at %d"),
5987 /* If we have any template arguments, then we must allocate a
5988 different sort of symbol. */
5989 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5991 if (child_die
->tag
== DW_TAG_template_type_param
5992 || child_die
->tag
== DW_TAG_template_value_param
)
5994 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5995 struct template_symbol
);
5996 templ_func
->base
.is_cplus_template_function
= 1;
6001 new = push_context (0, lowpc
);
6002 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
6003 (struct symbol
*) templ_func
);
6005 /* If there is a location expression for DW_AT_frame_base, record
6007 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
6009 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
6010 expression is being recorded directly in the function's symbol
6011 and not in a separate frame-base object. I guess this hack is
6012 to avoid adding some sort of frame-base adjunct/annex to the
6013 function's symbol :-(. The problem with doing this is that it
6014 results in a function symbol with a location expression that
6015 has nothing to do with the location of the function, ouch! The
6016 relationship should be: a function's symbol has-a frame base; a
6017 frame-base has-a location expression. */
6018 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
6020 cu
->list_in_scope
= &local_symbols
;
6022 if (die
->child
!= NULL
)
6024 child_die
= die
->child
;
6025 while (child_die
&& child_die
->tag
)
6027 if (child_die
->tag
== DW_TAG_template_type_param
6028 || child_die
->tag
== DW_TAG_template_value_param
)
6030 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6033 VEC_safe_push (symbolp
, template_args
, arg
);
6036 process_die (child_die
, cu
);
6037 child_die
= sibling_die (child_die
);
6041 inherit_abstract_dies (die
, cu
);
6043 /* If we have a DW_AT_specification, we might need to import using
6044 directives from the context of the specification DIE. See the
6045 comment in determine_prefix. */
6046 if (cu
->language
== language_cplus
6047 && dwarf2_attr (die
, DW_AT_specification
, cu
))
6049 struct dwarf2_cu
*spec_cu
= cu
;
6050 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
6054 child_die
= spec_die
->child
;
6055 while (child_die
&& child_die
->tag
)
6057 if (child_die
->tag
== DW_TAG_imported_module
)
6058 process_die (child_die
, spec_cu
);
6059 child_die
= sibling_die (child_die
);
6062 /* In some cases, GCC generates specification DIEs that
6063 themselves contain DW_AT_specification attributes. */
6064 spec_die
= die_specification (spec_die
, &spec_cu
);
6068 new = pop_context ();
6069 /* Make a block for the local symbols within. */
6070 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
6071 lowpc
, highpc
, objfile
);
6073 /* For C++, set the block's scope. */
6074 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
6075 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
6076 determine_prefix (die
, cu
),
6077 processing_has_namespace_info
);
6079 /* If we have address ranges, record them. */
6080 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6082 /* Attach template arguments to function. */
6083 if (! VEC_empty (symbolp
, template_args
))
6085 gdb_assert (templ_func
!= NULL
);
6087 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
6088 templ_func
->template_arguments
6089 = obstack_alloc (&objfile
->objfile_obstack
,
6090 (templ_func
->n_template_arguments
6091 * sizeof (struct symbol
*)));
6092 memcpy (templ_func
->template_arguments
,
6093 VEC_address (symbolp
, template_args
),
6094 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
6095 VEC_free (symbolp
, template_args
);
6098 /* In C++, we can have functions nested inside functions (e.g., when
6099 a function declares a class that has methods). This means that
6100 when we finish processing a function scope, we may need to go
6101 back to building a containing block's symbol lists. */
6102 local_symbols
= new->locals
;
6103 param_symbols
= new->params
;
6104 using_directives
= new->using_directives
;
6106 /* If we've finished processing a top-level function, subsequent
6107 symbols go in the file symbol list. */
6108 if (outermost_context_p ())
6109 cu
->list_in_scope
= &file_symbols
;
6112 /* Process all the DIES contained within a lexical block scope. Start
6113 a new scope, process the dies, and then close the scope. */
6116 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6118 struct objfile
*objfile
= cu
->objfile
;
6119 struct context_stack
*new;
6120 CORE_ADDR lowpc
, highpc
;
6121 struct die_info
*child_die
;
6124 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6126 /* Ignore blocks with missing or invalid low and high pc attributes. */
6127 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6128 as multiple lexical blocks? Handling children in a sane way would
6129 be nasty. Might be easier to properly extend generic blocks to
6131 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6136 push_context (0, lowpc
);
6137 if (die
->child
!= NULL
)
6139 child_die
= die
->child
;
6140 while (child_die
&& child_die
->tag
)
6142 process_die (child_die
, cu
);
6143 child_die
= sibling_die (child_die
);
6146 new = pop_context ();
6148 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6151 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6154 /* Note that recording ranges after traversing children, as we
6155 do here, means that recording a parent's ranges entails
6156 walking across all its children's ranges as they appear in
6157 the address map, which is quadratic behavior.
6159 It would be nicer to record the parent's ranges before
6160 traversing its children, simply overriding whatever you find
6161 there. But since we don't even decide whether to create a
6162 block until after we've traversed its children, that's hard
6164 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6166 local_symbols
= new->locals
;
6167 using_directives
= new->using_directives
;
6170 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6173 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6175 struct objfile
*objfile
= cu
->objfile
;
6176 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6177 CORE_ADDR pc
, baseaddr
;
6178 struct attribute
*attr
;
6179 struct call_site
*call_site
, call_site_local
;
6182 struct die_info
*child_die
;
6184 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6186 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6189 complaint (&symfile_complaints
,
6190 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6191 "DIE 0x%x [in module %s]"),
6192 die
->offset
, objfile
->name
);
6195 pc
= DW_ADDR (attr
) + baseaddr
;
6197 if (cu
->call_site_htab
== NULL
)
6198 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
6199 NULL
, &objfile
->objfile_obstack
,
6200 hashtab_obstack_allocate
, NULL
);
6201 call_site_local
.pc
= pc
;
6202 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
6205 complaint (&symfile_complaints
,
6206 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6207 "DIE 0x%x [in module %s]"),
6208 paddress (gdbarch
, pc
), die
->offset
, objfile
->name
);
6212 /* Count parameters at the caller. */
6215 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6216 child_die
= sibling_die (child_die
))
6218 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6220 complaint (&symfile_complaints
,
6221 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6222 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6223 child_die
->tag
, child_die
->offset
, objfile
->name
);
6230 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
6231 (sizeof (*call_site
)
6232 + (sizeof (*call_site
->parameter
)
6235 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
6238 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
6240 struct die_info
*func_die
;
6242 /* Skip also over DW_TAG_inlined_subroutine. */
6243 for (func_die
= die
->parent
;
6244 func_die
&& func_die
->tag
!= DW_TAG_subprogram
6245 && func_die
->tag
!= DW_TAG_subroutine_type
;
6246 func_die
= func_die
->parent
);
6248 /* DW_AT_GNU_all_call_sites is a superset
6249 of DW_AT_GNU_all_tail_call_sites. */
6251 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
6252 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
6254 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6255 not complete. But keep CALL_SITE for look ups via call_site_htab,
6256 both the initial caller containing the real return address PC and
6257 the final callee containing the current PC of a chain of tail
6258 calls do not need to have the tail call list complete. But any
6259 function candidate for a virtual tail call frame searched via
6260 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6261 determined unambiguously. */
6265 struct type
*func_type
= NULL
;
6268 func_type
= get_die_type (func_die
, cu
);
6269 if (func_type
!= NULL
)
6271 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
6273 /* Enlist this call site to the function. */
6274 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
6275 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
6278 complaint (&symfile_complaints
,
6279 _("Cannot find function owning DW_TAG_GNU_call_site "
6280 "DIE 0x%x [in module %s]"),
6281 die
->offset
, objfile
->name
);
6285 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
6287 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
6288 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
6289 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
6290 /* Keep NULL DWARF_BLOCK. */;
6291 else if (attr_form_is_block (attr
))
6293 struct dwarf2_locexpr_baton
*dlbaton
;
6295 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
6296 dlbaton
->data
= DW_BLOCK (attr
)->data
;
6297 dlbaton
->size
= DW_BLOCK (attr
)->size
;
6298 dlbaton
->per_cu
= cu
->per_cu
;
6300 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
6302 else if (is_ref_attr (attr
))
6304 struct dwarf2_cu
*target_cu
= cu
;
6305 struct die_info
*target_die
;
6307 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
6308 gdb_assert (target_cu
->objfile
== objfile
);
6309 if (die_is_declaration (target_die
, target_cu
))
6311 const char *target_physname
;
6313 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
6314 if (target_physname
== NULL
)
6315 complaint (&symfile_complaints
,
6316 _("DW_AT_GNU_call_site_target target DIE has invalid "
6317 "physname, for referencing DIE 0x%x [in module %s]"),
6318 die
->offset
, objfile
->name
);
6320 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
6326 /* DW_AT_entry_pc should be preferred. */
6327 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
6328 complaint (&symfile_complaints
,
6329 _("DW_AT_GNU_call_site_target target DIE has invalid "
6330 "low pc, for referencing DIE 0x%x [in module %s]"),
6331 die
->offset
, objfile
->name
);
6333 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
6337 complaint (&symfile_complaints
,
6338 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6339 "block nor reference, for DIE 0x%x [in module %s]"),
6340 die
->offset
, objfile
->name
);
6342 call_site
->per_cu
= cu
->per_cu
;
6344 for (child_die
= die
->child
;
6345 child_die
&& child_die
->tag
;
6346 child_die
= sibling_die (child_die
))
6348 struct dwarf2_locexpr_baton
*dlbaton
;
6349 struct call_site_parameter
*parameter
;
6351 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6353 /* Already printed the complaint above. */
6357 gdb_assert (call_site
->parameter_count
< nparams
);
6358 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
6360 /* DW_AT_location specifies the register number. Value of the data
6361 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6363 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
6364 if (!attr
|| !attr_form_is_block (attr
))
6366 complaint (&symfile_complaints
,
6367 _("No DW_FORM_block* DW_AT_location for "
6368 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6369 child_die
->offset
, objfile
->name
);
6372 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
6373 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
6374 if (parameter
->dwarf_reg
== -1
6375 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
6376 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
6377 ¶meter
->fb_offset
))
6379 complaint (&symfile_complaints
,
6380 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6381 "for DW_FORM_block* DW_AT_location for "
6382 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6383 child_die
->offset
, objfile
->name
);
6387 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
6388 if (!attr_form_is_block (attr
))
6390 complaint (&symfile_complaints
,
6391 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6392 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6393 child_die
->offset
, objfile
->name
);
6396 parameter
->value
= DW_BLOCK (attr
)->data
;
6397 parameter
->value_size
= DW_BLOCK (attr
)->size
;
6399 /* Parameters are not pre-cleared by memset above. */
6400 parameter
->data_value
= NULL
;
6401 parameter
->data_value_size
= 0;
6402 call_site
->parameter_count
++;
6404 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
6407 if (!attr_form_is_block (attr
))
6408 complaint (&symfile_complaints
,
6409 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6410 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6411 child_die
->offset
, objfile
->name
);
6414 parameter
->data_value
= DW_BLOCK (attr
)->data
;
6415 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
6421 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6422 Return 1 if the attributes are present and valid, otherwise, return 0.
6423 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6426 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6427 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6428 struct partial_symtab
*ranges_pst
)
6430 struct objfile
*objfile
= cu
->objfile
;
6431 struct comp_unit_head
*cu_header
= &cu
->header
;
6432 bfd
*obfd
= objfile
->obfd
;
6433 unsigned int addr_size
= cu_header
->addr_size
;
6434 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6435 /* Base address selection entry. */
6446 found_base
= cu
->base_known
;
6447 base
= cu
->base_address
;
6449 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6450 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6452 complaint (&symfile_complaints
,
6453 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6457 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6459 /* Read in the largest possible address. */
6460 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6461 if ((marker
& mask
) == mask
)
6463 /* If we found the largest possible address, then
6464 read the base address. */
6465 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6466 buffer
+= 2 * addr_size
;
6467 offset
+= 2 * addr_size
;
6473 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6477 CORE_ADDR range_beginning
, range_end
;
6479 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6480 buffer
+= addr_size
;
6481 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6482 buffer
+= addr_size
;
6483 offset
+= 2 * addr_size
;
6485 /* An end of list marker is a pair of zero addresses. */
6486 if (range_beginning
== 0 && range_end
== 0)
6487 /* Found the end of list entry. */
6490 /* Each base address selection entry is a pair of 2 values.
6491 The first is the largest possible address, the second is
6492 the base address. Check for a base address here. */
6493 if ((range_beginning
& mask
) == mask
)
6495 /* If we found the largest possible address, then
6496 read the base address. */
6497 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6504 /* We have no valid base address for the ranges
6506 complaint (&symfile_complaints
,
6507 _("Invalid .debug_ranges data (no base address)"));
6511 if (range_beginning
> range_end
)
6513 /* Inverted range entries are invalid. */
6514 complaint (&symfile_complaints
,
6515 _("Invalid .debug_ranges data (inverted range)"));
6519 /* Empty range entries have no effect. */
6520 if (range_beginning
== range_end
)
6523 range_beginning
+= base
;
6526 if (ranges_pst
!= NULL
)
6527 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6528 range_beginning
+ baseaddr
,
6529 range_end
- 1 + baseaddr
,
6532 /* FIXME: This is recording everything as a low-high
6533 segment of consecutive addresses. We should have a
6534 data structure for discontiguous block ranges
6538 low
= range_beginning
;
6544 if (range_beginning
< low
)
6545 low
= range_beginning
;
6546 if (range_end
> high
)
6552 /* If the first entry is an end-of-list marker, the range
6553 describes an empty scope, i.e. no instructions. */
6559 *high_return
= high
;
6563 /* Get low and high pc attributes from a die. Return 1 if the attributes
6564 are present and valid, otherwise, return 0. Return -1 if the range is
6565 discontinuous, i.e. derived from DW_AT_ranges information. */
6567 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6568 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6569 struct partial_symtab
*pst
)
6571 struct attribute
*attr
;
6576 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6579 high
= DW_ADDR (attr
);
6580 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6582 low
= DW_ADDR (attr
);
6584 /* Found high w/o low attribute. */
6587 /* Found consecutive range of addresses. */
6592 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6595 /* Value of the DW_AT_ranges attribute is the offset in the
6596 .debug_ranges section. */
6597 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6599 /* Found discontinuous range of addresses. */
6604 /* read_partial_die has also the strict LOW < HIGH requirement. */
6608 /* When using the GNU linker, .gnu.linkonce. sections are used to
6609 eliminate duplicate copies of functions and vtables and such.
6610 The linker will arbitrarily choose one and discard the others.
6611 The AT_*_pc values for such functions refer to local labels in
6612 these sections. If the section from that file was discarded, the
6613 labels are not in the output, so the relocs get a value of 0.
6614 If this is a discarded function, mark the pc bounds as invalid,
6615 so that GDB will ignore it. */
6616 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6625 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6626 its low and high PC addresses. Do nothing if these addresses could not
6627 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6628 and HIGHPC to the high address if greater than HIGHPC. */
6631 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6632 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6633 struct dwarf2_cu
*cu
)
6635 CORE_ADDR low
, high
;
6636 struct die_info
*child
= die
->child
;
6638 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6640 *lowpc
= min (*lowpc
, low
);
6641 *highpc
= max (*highpc
, high
);
6644 /* If the language does not allow nested subprograms (either inside
6645 subprograms or lexical blocks), we're done. */
6646 if (cu
->language
!= language_ada
)
6649 /* Check all the children of the given DIE. If it contains nested
6650 subprograms, then check their pc bounds. Likewise, we need to
6651 check lexical blocks as well, as they may also contain subprogram
6653 while (child
&& child
->tag
)
6655 if (child
->tag
== DW_TAG_subprogram
6656 || child
->tag
== DW_TAG_lexical_block
)
6657 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6658 child
= sibling_die (child
);
6662 /* Get the low and high pc's represented by the scope DIE, and store
6663 them in *LOWPC and *HIGHPC. If the correct values can't be
6664 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6667 get_scope_pc_bounds (struct die_info
*die
,
6668 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6669 struct dwarf2_cu
*cu
)
6671 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6672 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6673 CORE_ADDR current_low
, current_high
;
6675 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6677 best_low
= current_low
;
6678 best_high
= current_high
;
6682 struct die_info
*child
= die
->child
;
6684 while (child
&& child
->tag
)
6686 switch (child
->tag
) {
6687 case DW_TAG_subprogram
:
6688 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6690 case DW_TAG_namespace
:
6692 /* FIXME: carlton/2004-01-16: Should we do this for
6693 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6694 that current GCC's always emit the DIEs corresponding
6695 to definitions of methods of classes as children of a
6696 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6697 the DIEs giving the declarations, which could be
6698 anywhere). But I don't see any reason why the
6699 standards says that they have to be there. */
6700 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6702 if (current_low
!= ((CORE_ADDR
) -1))
6704 best_low
= min (best_low
, current_low
);
6705 best_high
= max (best_high
, current_high
);
6713 child
= sibling_die (child
);
6718 *highpc
= best_high
;
6721 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6724 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6725 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6727 struct objfile
*objfile
= cu
->objfile
;
6728 struct attribute
*attr
;
6730 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6733 CORE_ADDR high
= DW_ADDR (attr
);
6735 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6738 CORE_ADDR low
= DW_ADDR (attr
);
6740 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6744 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6747 bfd
*obfd
= objfile
->obfd
;
6749 /* The value of the DW_AT_ranges attribute is the offset of the
6750 address range list in the .debug_ranges section. */
6751 unsigned long offset
= DW_UNSND (attr
);
6752 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6754 /* For some target architectures, but not others, the
6755 read_address function sign-extends the addresses it returns.
6756 To recognize base address selection entries, we need a
6758 unsigned int addr_size
= cu
->header
.addr_size
;
6759 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6761 /* The base address, to which the next pair is relative. Note
6762 that this 'base' is a DWARF concept: most entries in a range
6763 list are relative, to reduce the number of relocs against the
6764 debugging information. This is separate from this function's
6765 'baseaddr' argument, which GDB uses to relocate debugging
6766 information from a shared library based on the address at
6767 which the library was loaded. */
6768 CORE_ADDR base
= cu
->base_address
;
6769 int base_known
= cu
->base_known
;
6771 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6772 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6774 complaint (&symfile_complaints
,
6775 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6782 unsigned int bytes_read
;
6783 CORE_ADDR start
, end
;
6785 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6786 buffer
+= bytes_read
;
6787 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6788 buffer
+= bytes_read
;
6790 /* Did we find the end of the range list? */
6791 if (start
== 0 && end
== 0)
6794 /* Did we find a base address selection entry? */
6795 else if ((start
& base_select_mask
) == base_select_mask
)
6801 /* We found an ordinary address range. */
6806 complaint (&symfile_complaints
,
6807 _("Invalid .debug_ranges data "
6808 "(no base address)"));
6814 /* Inverted range entries are invalid. */
6815 complaint (&symfile_complaints
,
6816 _("Invalid .debug_ranges data "
6817 "(inverted range)"));
6821 /* Empty range entries have no effect. */
6825 record_block_range (block
,
6826 baseaddr
+ base
+ start
,
6827 baseaddr
+ base
+ end
- 1);
6833 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6834 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6835 during 4.6.0 experimental. */
6838 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6841 int major
, minor
, release
;
6843 if (cu
->producer
== NULL
)
6845 /* For unknown compilers expect their behavior is DWARF version
6848 GCC started to support .debug_types sections by -gdwarf-4 since
6849 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6850 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6851 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6852 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6857 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6859 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6861 /* For non-GCC compilers expect their behavior is DWARF version
6866 cs
= &cu
->producer
[strlen ("GNU ")];
6867 while (*cs
&& !isdigit (*cs
))
6869 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6871 /* Not recognized as GCC. */
6876 return major
< 4 || (major
== 4 && minor
< 6);
6879 /* Return the default accessibility type if it is not overriden by
6880 DW_AT_accessibility. */
6882 static enum dwarf_access_attribute
6883 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6885 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6887 /* The default DWARF 2 accessibility for members is public, the default
6888 accessibility for inheritance is private. */
6890 if (die
->tag
!= DW_TAG_inheritance
)
6891 return DW_ACCESS_public
;
6893 return DW_ACCESS_private
;
6897 /* DWARF 3+ defines the default accessibility a different way. The same
6898 rules apply now for DW_TAG_inheritance as for the members and it only
6899 depends on the container kind. */
6901 if (die
->parent
->tag
== DW_TAG_class_type
)
6902 return DW_ACCESS_private
;
6904 return DW_ACCESS_public
;
6908 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6909 offset. If the attribute was not found return 0, otherwise return
6910 1. If it was found but could not properly be handled, set *OFFSET
6914 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
6917 struct attribute
*attr
;
6919 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6924 /* Note that we do not check for a section offset first here.
6925 This is because DW_AT_data_member_location is new in DWARF 4,
6926 so if we see it, we can assume that a constant form is really
6927 a constant and not a section offset. */
6928 if (attr_form_is_constant (attr
))
6929 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
6930 else if (attr_form_is_section_offset (attr
))
6931 dwarf2_complex_location_expr_complaint ();
6932 else if (attr_form_is_block (attr
))
6933 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6935 dwarf2_complex_location_expr_complaint ();
6943 /* Add an aggregate field to the field list. */
6946 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6947 struct dwarf2_cu
*cu
)
6949 struct objfile
*objfile
= cu
->objfile
;
6950 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6951 struct nextfield
*new_field
;
6952 struct attribute
*attr
;
6954 char *fieldname
= "";
6956 /* Allocate a new field list entry and link it in. */
6957 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6958 make_cleanup (xfree
, new_field
);
6959 memset (new_field
, 0, sizeof (struct nextfield
));
6961 if (die
->tag
== DW_TAG_inheritance
)
6963 new_field
->next
= fip
->baseclasses
;
6964 fip
->baseclasses
= new_field
;
6968 new_field
->next
= fip
->fields
;
6969 fip
->fields
= new_field
;
6973 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6975 new_field
->accessibility
= DW_UNSND (attr
);
6977 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
6978 if (new_field
->accessibility
!= DW_ACCESS_public
)
6979 fip
->non_public_fields
= 1;
6981 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6983 new_field
->virtuality
= DW_UNSND (attr
);
6985 new_field
->virtuality
= DW_VIRTUALITY_none
;
6987 fp
= &new_field
->field
;
6989 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6993 /* Data member other than a C++ static data member. */
6995 /* Get type of field. */
6996 fp
->type
= die_type (die
, cu
);
6998 SET_FIELD_BITPOS (*fp
, 0);
7000 /* Get bit size of field (zero if none). */
7001 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
7004 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
7008 FIELD_BITSIZE (*fp
) = 0;
7011 /* Get bit offset of field. */
7012 if (handle_data_member_location (die
, cu
, &offset
))
7013 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7014 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
7017 if (gdbarch_bits_big_endian (gdbarch
))
7019 /* For big endian bits, the DW_AT_bit_offset gives the
7020 additional bit offset from the MSB of the containing
7021 anonymous object to the MSB of the field. We don't
7022 have to do anything special since we don't need to
7023 know the size of the anonymous object. */
7024 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
7028 /* For little endian bits, compute the bit offset to the
7029 MSB of the anonymous object, subtract off the number of
7030 bits from the MSB of the field to the MSB of the
7031 object, and then subtract off the number of bits of
7032 the field itself. The result is the bit offset of
7033 the LSB of the field. */
7035 int bit_offset
= DW_UNSND (attr
);
7037 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7040 /* The size of the anonymous object containing
7041 the bit field is explicit, so use the
7042 indicated size (in bytes). */
7043 anonymous_size
= DW_UNSND (attr
);
7047 /* The size of the anonymous object containing
7048 the bit field must be inferred from the type
7049 attribute of the data member containing the
7051 anonymous_size
= TYPE_LENGTH (fp
->type
);
7053 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
7054 - bit_offset
- FIELD_BITSIZE (*fp
);
7058 /* Get name of field. */
7059 fieldname
= dwarf2_name (die
, cu
);
7060 if (fieldname
== NULL
)
7063 /* The name is already allocated along with this objfile, so we don't
7064 need to duplicate it for the type. */
7065 fp
->name
= fieldname
;
7067 /* Change accessibility for artificial fields (e.g. virtual table
7068 pointer or virtual base class pointer) to private. */
7069 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
7071 FIELD_ARTIFICIAL (*fp
) = 1;
7072 new_field
->accessibility
= DW_ACCESS_private
;
7073 fip
->non_public_fields
= 1;
7076 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
7078 /* C++ static member. */
7080 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7081 is a declaration, but all versions of G++ as of this writing
7082 (so through at least 3.2.1) incorrectly generate
7083 DW_TAG_variable tags. */
7085 const char *physname
;
7087 /* Get name of field. */
7088 fieldname
= dwarf2_name (die
, cu
);
7089 if (fieldname
== NULL
)
7092 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7094 /* Only create a symbol if this is an external value.
7095 new_symbol checks this and puts the value in the global symbol
7096 table, which we want. If it is not external, new_symbol
7097 will try to put the value in cu->list_in_scope which is wrong. */
7098 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
7100 /* A static const member, not much different than an enum as far as
7101 we're concerned, except that we can support more types. */
7102 new_symbol (die
, NULL
, cu
);
7105 /* Get physical name. */
7106 physname
= dwarf2_physname (fieldname
, die
, cu
);
7108 /* The name is already allocated along with this objfile, so we don't
7109 need to duplicate it for the type. */
7110 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
7111 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7112 FIELD_NAME (*fp
) = fieldname
;
7114 else if (die
->tag
== DW_TAG_inheritance
)
7118 /* C++ base class field. */
7119 if (handle_data_member_location (die
, cu
, &offset
))
7120 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7121 FIELD_BITSIZE (*fp
) = 0;
7122 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7123 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
7124 fip
->nbaseclasses
++;
7128 /* Add a typedef defined in the scope of the FIP's class. */
7131 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
7132 struct dwarf2_cu
*cu
)
7134 struct objfile
*objfile
= cu
->objfile
;
7135 struct typedef_field_list
*new_field
;
7136 struct attribute
*attr
;
7137 struct typedef_field
*fp
;
7138 char *fieldname
= "";
7140 /* Allocate a new field list entry and link it in. */
7141 new_field
= xzalloc (sizeof (*new_field
));
7142 make_cleanup (xfree
, new_field
);
7144 gdb_assert (die
->tag
== DW_TAG_typedef
);
7146 fp
= &new_field
->field
;
7148 /* Get name of field. */
7149 fp
->name
= dwarf2_name (die
, cu
);
7150 if (fp
->name
== NULL
)
7153 fp
->type
= read_type_die (die
, cu
);
7155 new_field
->next
= fip
->typedef_field_list
;
7156 fip
->typedef_field_list
= new_field
;
7157 fip
->typedef_field_list_count
++;
7160 /* Create the vector of fields, and attach it to the type. */
7163 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
7164 struct dwarf2_cu
*cu
)
7166 int nfields
= fip
->nfields
;
7168 /* Record the field count, allocate space for the array of fields,
7169 and create blank accessibility bitfields if necessary. */
7170 TYPE_NFIELDS (type
) = nfields
;
7171 TYPE_FIELDS (type
) = (struct field
*)
7172 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
7173 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
7175 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
7177 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7179 TYPE_FIELD_PRIVATE_BITS (type
) =
7180 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7181 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
7183 TYPE_FIELD_PROTECTED_BITS (type
) =
7184 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7185 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
7187 TYPE_FIELD_IGNORE_BITS (type
) =
7188 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7189 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
7192 /* If the type has baseclasses, allocate and clear a bit vector for
7193 TYPE_FIELD_VIRTUAL_BITS. */
7194 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
7196 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
7197 unsigned char *pointer
;
7199 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7200 pointer
= TYPE_ALLOC (type
, num_bytes
);
7201 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
7202 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
7203 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
7206 /* Copy the saved-up fields into the field vector. Start from the head of
7207 the list, adding to the tail of the field array, so that they end up in
7208 the same order in the array in which they were added to the list. */
7209 while (nfields
-- > 0)
7211 struct nextfield
*fieldp
;
7215 fieldp
= fip
->fields
;
7216 fip
->fields
= fieldp
->next
;
7220 fieldp
= fip
->baseclasses
;
7221 fip
->baseclasses
= fieldp
->next
;
7224 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
7225 switch (fieldp
->accessibility
)
7227 case DW_ACCESS_private
:
7228 if (cu
->language
!= language_ada
)
7229 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
7232 case DW_ACCESS_protected
:
7233 if (cu
->language
!= language_ada
)
7234 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
7237 case DW_ACCESS_public
:
7241 /* Unknown accessibility. Complain and treat it as public. */
7243 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
7244 fieldp
->accessibility
);
7248 if (nfields
< fip
->nbaseclasses
)
7250 switch (fieldp
->virtuality
)
7252 case DW_VIRTUALITY_virtual
:
7253 case DW_VIRTUALITY_pure_virtual
:
7254 if (cu
->language
== language_ada
)
7255 error (_("unexpected virtuality in component of Ada type"));
7256 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
7263 /* Add a member function to the proper fieldlist. */
7266 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
7267 struct type
*type
, struct dwarf2_cu
*cu
)
7269 struct objfile
*objfile
= cu
->objfile
;
7270 struct attribute
*attr
;
7271 struct fnfieldlist
*flp
;
7273 struct fn_field
*fnp
;
7275 struct nextfnfield
*new_fnfield
;
7276 struct type
*this_type
;
7277 enum dwarf_access_attribute accessibility
;
7279 if (cu
->language
== language_ada
)
7280 error (_("unexpected member function in Ada type"));
7282 /* Get name of member function. */
7283 fieldname
= dwarf2_name (die
, cu
);
7284 if (fieldname
== NULL
)
7287 /* Look up member function name in fieldlist. */
7288 for (i
= 0; i
< fip
->nfnfields
; i
++)
7290 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7294 /* Create new list element if necessary. */
7295 if (i
< fip
->nfnfields
)
7296 flp
= &fip
->fnfieldlists
[i
];
7299 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7301 fip
->fnfieldlists
= (struct fnfieldlist
*)
7302 xrealloc (fip
->fnfieldlists
,
7303 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7304 * sizeof (struct fnfieldlist
));
7305 if (fip
->nfnfields
== 0)
7306 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7308 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7309 flp
->name
= fieldname
;
7312 i
= fip
->nfnfields
++;
7315 /* Create a new member function field and chain it to the field list
7317 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7318 make_cleanup (xfree
, new_fnfield
);
7319 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7320 new_fnfield
->next
= flp
->head
;
7321 flp
->head
= new_fnfield
;
7324 /* Fill in the member function field info. */
7325 fnp
= &new_fnfield
->fnfield
;
7327 /* Delay processing of the physname until later. */
7328 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7330 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7335 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7336 fnp
->physname
= physname
? physname
: "";
7339 fnp
->type
= alloc_type (objfile
);
7340 this_type
= read_type_die (die
, cu
);
7341 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7343 int nparams
= TYPE_NFIELDS (this_type
);
7345 /* TYPE is the domain of this method, and THIS_TYPE is the type
7346 of the method itself (TYPE_CODE_METHOD). */
7347 smash_to_method_type (fnp
->type
, type
,
7348 TYPE_TARGET_TYPE (this_type
),
7349 TYPE_FIELDS (this_type
),
7350 TYPE_NFIELDS (this_type
),
7351 TYPE_VARARGS (this_type
));
7353 /* Handle static member functions.
7354 Dwarf2 has no clean way to discern C++ static and non-static
7355 member functions. G++ helps GDB by marking the first
7356 parameter for non-static member functions (which is the this
7357 pointer) as artificial. We obtain this information from
7358 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7359 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7360 fnp
->voffset
= VOFFSET_STATIC
;
7363 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7364 dwarf2_full_name (fieldname
, die
, cu
));
7366 /* Get fcontext from DW_AT_containing_type if present. */
7367 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7368 fnp
->fcontext
= die_containing_type (die
, cu
);
7370 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7371 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7373 /* Get accessibility. */
7374 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7376 accessibility
= DW_UNSND (attr
);
7378 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7379 switch (accessibility
)
7381 case DW_ACCESS_private
:
7382 fnp
->is_private
= 1;
7384 case DW_ACCESS_protected
:
7385 fnp
->is_protected
= 1;
7389 /* Check for artificial methods. */
7390 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7391 if (attr
&& DW_UNSND (attr
) != 0)
7392 fnp
->is_artificial
= 1;
7394 /* Get index in virtual function table if it is a virtual member
7395 function. For older versions of GCC, this is an offset in the
7396 appropriate virtual table, as specified by DW_AT_containing_type.
7397 For everyone else, it is an expression to be evaluated relative
7398 to the object address. */
7400 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7403 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7405 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7407 /* Old-style GCC. */
7408 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7410 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7411 || (DW_BLOCK (attr
)->size
> 1
7412 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7413 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7415 struct dwarf_block blk
;
7418 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7420 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7421 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7422 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7423 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7424 dwarf2_complex_location_expr_complaint ();
7426 fnp
->voffset
/= cu
->header
.addr_size
;
7430 dwarf2_complex_location_expr_complaint ();
7433 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7435 else if (attr_form_is_section_offset (attr
))
7437 dwarf2_complex_location_expr_complaint ();
7441 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7447 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7448 if (attr
&& DW_UNSND (attr
))
7450 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7451 complaint (&symfile_complaints
,
7452 _("Member function \"%s\" (offset %d) is virtual "
7453 "but the vtable offset is not specified"),
7454 fieldname
, die
->offset
);
7455 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7456 TYPE_CPLUS_DYNAMIC (type
) = 1;
7461 /* Create the vector of member function fields, and attach it to the type. */
7464 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7465 struct dwarf2_cu
*cu
)
7467 struct fnfieldlist
*flp
;
7468 int total_length
= 0;
7471 if (cu
->language
== language_ada
)
7472 error (_("unexpected member functions in Ada type"));
7474 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7475 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7476 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7478 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7480 struct nextfnfield
*nfp
= flp
->head
;
7481 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7484 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7485 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7486 fn_flp
->fn_fields
= (struct fn_field
*)
7487 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7488 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7489 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7491 total_length
+= flp
->length
;
7494 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7495 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
7498 /* Returns non-zero if NAME is the name of a vtable member in CU's
7499 language, zero otherwise. */
7501 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7503 static const char vptr
[] = "_vptr";
7504 static const char vtable
[] = "vtable";
7506 /* Look for the C++ and Java forms of the vtable. */
7507 if ((cu
->language
== language_java
7508 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7509 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7510 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7516 /* GCC outputs unnamed structures that are really pointers to member
7517 functions, with the ABI-specified layout. If TYPE describes
7518 such a structure, smash it into a member function type.
7520 GCC shouldn't do this; it should just output pointer to member DIEs.
7521 This is GCC PR debug/28767. */
7524 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7526 struct type
*pfn_type
, *domain_type
, *new_type
;
7528 /* Check for a structure with no name and two children. */
7529 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7532 /* Check for __pfn and __delta members. */
7533 if (TYPE_FIELD_NAME (type
, 0) == NULL
7534 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7535 || TYPE_FIELD_NAME (type
, 1) == NULL
7536 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7539 /* Find the type of the method. */
7540 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7541 if (pfn_type
== NULL
7542 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7543 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7546 /* Look for the "this" argument. */
7547 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7548 if (TYPE_NFIELDS (pfn_type
) == 0
7549 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7550 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7553 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7554 new_type
= alloc_type (objfile
);
7555 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7556 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7557 TYPE_VARARGS (pfn_type
));
7558 smash_to_methodptr_type (type
, new_type
);
7561 /* Called when we find the DIE that starts a structure or union scope
7562 (definition) to create a type for the structure or union. Fill in
7563 the type's name and general properties; the members will not be
7564 processed until process_structure_type.
7566 NOTE: we need to call these functions regardless of whether or not the
7567 DIE has a DW_AT_name attribute, since it might be an anonymous
7568 structure or union. This gets the type entered into our set of
7571 However, if the structure is incomplete (an opaque struct/union)
7572 then suppress creating a symbol table entry for it since gdb only
7573 wants to find the one with the complete definition. Note that if
7574 it is complete, we just call new_symbol, which does it's own
7575 checking about whether the struct/union is anonymous or not (and
7576 suppresses creating a symbol table entry itself). */
7578 static struct type
*
7579 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7581 struct objfile
*objfile
= cu
->objfile
;
7583 struct attribute
*attr
;
7586 /* If the definition of this type lives in .debug_types, read that type.
7587 Don't follow DW_AT_specification though, that will take us back up
7588 the chain and we want to go down. */
7589 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7592 struct dwarf2_cu
*type_cu
= cu
;
7593 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7595 /* We could just recurse on read_structure_type, but we need to call
7596 get_die_type to ensure only one type for this DIE is created.
7597 This is important, for example, because for c++ classes we need
7598 TYPE_NAME set which is only done by new_symbol. Blech. */
7599 type
= read_type_die (type_die
, type_cu
);
7601 /* TYPE_CU may not be the same as CU.
7602 Ensure TYPE is recorded in CU's type_hash table. */
7603 return set_die_type (die
, type
, cu
);
7606 type
= alloc_type (objfile
);
7607 INIT_CPLUS_SPECIFIC (type
);
7609 name
= dwarf2_name (die
, cu
);
7612 if (cu
->language
== language_cplus
7613 || cu
->language
== language_java
)
7615 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7617 /* dwarf2_full_name might have already finished building the DIE's
7618 type. If so, there is no need to continue. */
7619 if (get_die_type (die
, cu
) != NULL
)
7620 return get_die_type (die
, cu
);
7622 TYPE_TAG_NAME (type
) = full_name
;
7623 if (die
->tag
== DW_TAG_structure_type
7624 || die
->tag
== DW_TAG_class_type
)
7625 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7629 /* The name is already allocated along with this objfile, so
7630 we don't need to duplicate it for the type. */
7631 TYPE_TAG_NAME (type
) = (char *) name
;
7632 if (die
->tag
== DW_TAG_class_type
)
7633 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7637 if (die
->tag
== DW_TAG_structure_type
)
7639 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7641 else if (die
->tag
== DW_TAG_union_type
)
7643 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7647 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7650 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7651 TYPE_DECLARED_CLASS (type
) = 1;
7653 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7656 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7660 TYPE_LENGTH (type
) = 0;
7663 TYPE_STUB_SUPPORTED (type
) = 1;
7664 if (die_is_declaration (die
, cu
))
7665 TYPE_STUB (type
) = 1;
7666 else if (attr
== NULL
&& die
->child
== NULL
7667 && producer_is_realview (cu
->producer
))
7668 /* RealView does not output the required DW_AT_declaration
7669 on incomplete types. */
7670 TYPE_STUB (type
) = 1;
7672 /* We need to add the type field to the die immediately so we don't
7673 infinitely recurse when dealing with pointers to the structure
7674 type within the structure itself. */
7675 set_die_type (die
, type
, cu
);
7677 /* set_die_type should be already done. */
7678 set_descriptive_type (type
, die
, cu
);
7683 /* Finish creating a structure or union type, including filling in
7684 its members and creating a symbol for it. */
7687 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7689 struct objfile
*objfile
= cu
->objfile
;
7690 struct die_info
*child_die
= die
->child
;
7693 type
= get_die_type (die
, cu
);
7695 type
= read_structure_type (die
, cu
);
7697 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7699 struct field_info fi
;
7700 struct die_info
*child_die
;
7701 VEC (symbolp
) *template_args
= NULL
;
7702 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7704 memset (&fi
, 0, sizeof (struct field_info
));
7706 child_die
= die
->child
;
7708 while (child_die
&& child_die
->tag
)
7710 if (child_die
->tag
== DW_TAG_member
7711 || child_die
->tag
== DW_TAG_variable
)
7713 /* NOTE: carlton/2002-11-05: A C++ static data member
7714 should be a DW_TAG_member that is a declaration, but
7715 all versions of G++ as of this writing (so through at
7716 least 3.2.1) incorrectly generate DW_TAG_variable
7717 tags for them instead. */
7718 dwarf2_add_field (&fi
, child_die
, cu
);
7720 else if (child_die
->tag
== DW_TAG_subprogram
)
7722 /* C++ member function. */
7723 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7725 else if (child_die
->tag
== DW_TAG_inheritance
)
7727 /* C++ base class field. */
7728 dwarf2_add_field (&fi
, child_die
, cu
);
7730 else if (child_die
->tag
== DW_TAG_typedef
)
7731 dwarf2_add_typedef (&fi
, child_die
, cu
);
7732 else if (child_die
->tag
== DW_TAG_template_type_param
7733 || child_die
->tag
== DW_TAG_template_value_param
)
7735 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7738 VEC_safe_push (symbolp
, template_args
, arg
);
7741 child_die
= sibling_die (child_die
);
7744 /* Attach template arguments to type. */
7745 if (! VEC_empty (symbolp
, template_args
))
7747 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7748 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7749 = VEC_length (symbolp
, template_args
);
7750 TYPE_TEMPLATE_ARGUMENTS (type
)
7751 = obstack_alloc (&objfile
->objfile_obstack
,
7752 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7753 * sizeof (struct symbol
*)));
7754 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7755 VEC_address (symbolp
, template_args
),
7756 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7757 * sizeof (struct symbol
*)));
7758 VEC_free (symbolp
, template_args
);
7761 /* Attach fields and member functions to the type. */
7763 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7766 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7768 /* Get the type which refers to the base class (possibly this
7769 class itself) which contains the vtable pointer for the current
7770 class from the DW_AT_containing_type attribute. This use of
7771 DW_AT_containing_type is a GNU extension. */
7773 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7775 struct type
*t
= die_containing_type (die
, cu
);
7777 TYPE_VPTR_BASETYPE (type
) = t
;
7782 /* Our own class provides vtbl ptr. */
7783 for (i
= TYPE_NFIELDS (t
) - 1;
7784 i
>= TYPE_N_BASECLASSES (t
);
7787 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7789 if (is_vtable_name (fieldname
, cu
))
7791 TYPE_VPTR_FIELDNO (type
) = i
;
7796 /* Complain if virtual function table field not found. */
7797 if (i
< TYPE_N_BASECLASSES (t
))
7798 complaint (&symfile_complaints
,
7799 _("virtual function table pointer "
7800 "not found when defining class '%s'"),
7801 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7806 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7809 else if (cu
->producer
7810 && strncmp (cu
->producer
,
7811 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7813 /* The IBM XLC compiler does not provide direct indication
7814 of the containing type, but the vtable pointer is
7815 always named __vfp. */
7819 for (i
= TYPE_NFIELDS (type
) - 1;
7820 i
>= TYPE_N_BASECLASSES (type
);
7823 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7825 TYPE_VPTR_FIELDNO (type
) = i
;
7826 TYPE_VPTR_BASETYPE (type
) = type
;
7833 /* Copy fi.typedef_field_list linked list elements content into the
7834 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7835 if (fi
.typedef_field_list
)
7837 int i
= fi
.typedef_field_list_count
;
7839 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7840 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7841 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7842 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7844 /* Reverse the list order to keep the debug info elements order. */
7847 struct typedef_field
*dest
, *src
;
7849 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7850 src
= &fi
.typedef_field_list
->field
;
7851 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7856 do_cleanups (back_to
);
7858 if (HAVE_CPLUS_STRUCT (type
))
7859 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
7862 quirk_gcc_member_function_pointer (type
, objfile
);
7864 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7865 snapshots) has been known to create a die giving a declaration
7866 for a class that has, as a child, a die giving a definition for a
7867 nested class. So we have to process our children even if the
7868 current die is a declaration. Normally, of course, a declaration
7869 won't have any children at all. */
7871 while (child_die
!= NULL
&& child_die
->tag
)
7873 if (child_die
->tag
== DW_TAG_member
7874 || child_die
->tag
== DW_TAG_variable
7875 || child_die
->tag
== DW_TAG_inheritance
7876 || child_die
->tag
== DW_TAG_template_value_param
7877 || child_die
->tag
== DW_TAG_template_type_param
)
7882 process_die (child_die
, cu
);
7884 child_die
= sibling_die (child_die
);
7887 /* Do not consider external references. According to the DWARF standard,
7888 these DIEs are identified by the fact that they have no byte_size
7889 attribute, and a declaration attribute. */
7890 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7891 || !die_is_declaration (die
, cu
))
7892 new_symbol (die
, type
, cu
);
7895 /* Given a DW_AT_enumeration_type die, set its type. We do not
7896 complete the type's fields yet, or create any symbols. */
7898 static struct type
*
7899 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7901 struct objfile
*objfile
= cu
->objfile
;
7903 struct attribute
*attr
;
7906 /* If the definition of this type lives in .debug_types, read that type.
7907 Don't follow DW_AT_specification though, that will take us back up
7908 the chain and we want to go down. */
7909 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7912 struct dwarf2_cu
*type_cu
= cu
;
7913 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7915 type
= read_type_die (type_die
, type_cu
);
7917 /* TYPE_CU may not be the same as CU.
7918 Ensure TYPE is recorded in CU's type_hash table. */
7919 return set_die_type (die
, type
, cu
);
7922 type
= alloc_type (objfile
);
7924 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7925 name
= dwarf2_full_name (NULL
, die
, cu
);
7927 TYPE_TAG_NAME (type
) = (char *) name
;
7929 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7932 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7936 TYPE_LENGTH (type
) = 0;
7939 /* The enumeration DIE can be incomplete. In Ada, any type can be
7940 declared as private in the package spec, and then defined only
7941 inside the package body. Such types are known as Taft Amendment
7942 Types. When another package uses such a type, an incomplete DIE
7943 may be generated by the compiler. */
7944 if (die_is_declaration (die
, cu
))
7945 TYPE_STUB (type
) = 1;
7947 return set_die_type (die
, type
, cu
);
7950 /* Given a pointer to a die which begins an enumeration, process all
7951 the dies that define the members of the enumeration, and create the
7952 symbol for the enumeration type.
7954 NOTE: We reverse the order of the element list. */
7957 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7959 struct type
*this_type
;
7961 this_type
= get_die_type (die
, cu
);
7962 if (this_type
== NULL
)
7963 this_type
= read_enumeration_type (die
, cu
);
7965 if (die
->child
!= NULL
)
7967 struct die_info
*child_die
;
7969 struct field
*fields
= NULL
;
7971 int unsigned_enum
= 1;
7974 child_die
= die
->child
;
7975 while (child_die
&& child_die
->tag
)
7977 if (child_die
->tag
!= DW_TAG_enumerator
)
7979 process_die (child_die
, cu
);
7983 name
= dwarf2_name (child_die
, cu
);
7986 sym
= new_symbol (child_die
, this_type
, cu
);
7987 if (SYMBOL_VALUE (sym
) < 0)
7990 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7992 fields
= (struct field
*)
7994 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7995 * sizeof (struct field
));
7998 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7999 FIELD_TYPE (fields
[num_fields
]) = NULL
;
8000 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
8001 FIELD_BITSIZE (fields
[num_fields
]) = 0;
8007 child_die
= sibling_die (child_die
);
8012 TYPE_NFIELDS (this_type
) = num_fields
;
8013 TYPE_FIELDS (this_type
) = (struct field
*)
8014 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
8015 memcpy (TYPE_FIELDS (this_type
), fields
,
8016 sizeof (struct field
) * num_fields
);
8020 TYPE_UNSIGNED (this_type
) = 1;
8023 /* If we are reading an enum from a .debug_types unit, and the enum
8024 is a declaration, and the enum is not the signatured type in the
8025 unit, then we do not want to add a symbol for it. Adding a
8026 symbol would in some cases obscure the true definition of the
8027 enum, giving users an incomplete type when the definition is
8028 actually available. Note that we do not want to do this for all
8029 enums which are just declarations, because C++0x allows forward
8030 enum declarations. */
8031 if (cu
->per_cu
->debug_types_section
8032 && die_is_declaration (die
, cu
))
8034 struct signatured_type
*type_sig
;
8037 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
8038 cu
->per_cu
->debug_types_section
,
8039 cu
->per_cu
->offset
);
8040 if (type_sig
->type_offset
!= die
->offset
)
8044 new_symbol (die
, this_type
, cu
);
8047 /* Extract all information from a DW_TAG_array_type DIE and put it in
8048 the DIE's type field. For now, this only handles one dimensional
8051 static struct type
*
8052 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8054 struct objfile
*objfile
= cu
->objfile
;
8055 struct die_info
*child_die
;
8057 struct type
*element_type
, *range_type
, *index_type
;
8058 struct type
**range_types
= NULL
;
8059 struct attribute
*attr
;
8061 struct cleanup
*back_to
;
8064 element_type
= die_type (die
, cu
);
8066 /* The die_type call above may have already set the type for this DIE. */
8067 type
= get_die_type (die
, cu
);
8071 /* Irix 6.2 native cc creates array types without children for
8072 arrays with unspecified length. */
8073 if (die
->child
== NULL
)
8075 index_type
= objfile_type (objfile
)->builtin_int
;
8076 range_type
= create_range_type (NULL
, index_type
, 0, -1);
8077 type
= create_array_type (NULL
, element_type
, range_type
);
8078 return set_die_type (die
, type
, cu
);
8081 back_to
= make_cleanup (null_cleanup
, NULL
);
8082 child_die
= die
->child
;
8083 while (child_die
&& child_die
->tag
)
8085 if (child_die
->tag
== DW_TAG_subrange_type
)
8087 struct type
*child_type
= read_type_die (child_die
, cu
);
8089 if (child_type
!= NULL
)
8091 /* The range type was succesfully read. Save it for the
8092 array type creation. */
8093 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
8095 range_types
= (struct type
**)
8096 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
8097 * sizeof (struct type
*));
8099 make_cleanup (free_current_contents
, &range_types
);
8101 range_types
[ndim
++] = child_type
;
8104 child_die
= sibling_die (child_die
);
8107 /* Dwarf2 dimensions are output from left to right, create the
8108 necessary array types in backwards order. */
8110 type
= element_type
;
8112 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
8117 type
= create_array_type (NULL
, type
, range_types
[i
++]);
8122 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
8125 /* Understand Dwarf2 support for vector types (like they occur on
8126 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8127 array type. This is not part of the Dwarf2/3 standard yet, but a
8128 custom vendor extension. The main difference between a regular
8129 array and the vector variant is that vectors are passed by value
8131 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
8133 make_vector_type (type
);
8135 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8136 implementation may choose to implement triple vectors using this
8138 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8141 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
8142 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8144 complaint (&symfile_complaints
,
8145 _("DW_AT_byte_size for array type smaller "
8146 "than the total size of elements"));
8149 name
= dwarf2_name (die
, cu
);
8151 TYPE_NAME (type
) = name
;
8153 /* Install the type in the die. */
8154 set_die_type (die
, type
, cu
);
8156 /* set_die_type should be already done. */
8157 set_descriptive_type (type
, die
, cu
);
8159 do_cleanups (back_to
);
8164 static enum dwarf_array_dim_ordering
8165 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
8167 struct attribute
*attr
;
8169 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
8171 if (attr
) return DW_SND (attr
);
8173 /* GNU F77 is a special case, as at 08/2004 array type info is the
8174 opposite order to the dwarf2 specification, but data is still
8175 laid out as per normal fortran.
8177 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8178 version checking. */
8180 if (cu
->language
== language_fortran
8181 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
8183 return DW_ORD_row_major
;
8186 switch (cu
->language_defn
->la_array_ordering
)
8188 case array_column_major
:
8189 return DW_ORD_col_major
;
8190 case array_row_major
:
8192 return DW_ORD_row_major
;
8196 /* Extract all information from a DW_TAG_set_type DIE and put it in
8197 the DIE's type field. */
8199 static struct type
*
8200 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8202 struct type
*domain_type
, *set_type
;
8203 struct attribute
*attr
;
8205 domain_type
= die_type (die
, cu
);
8207 /* The die_type call above may have already set the type for this DIE. */
8208 set_type
= get_die_type (die
, cu
);
8212 set_type
= create_set_type (NULL
, domain_type
);
8214 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8216 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
8218 return set_die_type (die
, set_type
, cu
);
8221 /* First cut: install each common block member as a global variable. */
8224 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
8226 struct die_info
*child_die
;
8227 struct attribute
*attr
;
8229 CORE_ADDR base
= (CORE_ADDR
) 0;
8231 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8234 /* Support the .debug_loc offsets. */
8235 if (attr_form_is_block (attr
))
8237 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
8239 else if (attr_form_is_section_offset (attr
))
8241 dwarf2_complex_location_expr_complaint ();
8245 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8246 "common block member");
8249 if (die
->child
!= NULL
)
8251 child_die
= die
->child
;
8252 while (child_die
&& child_die
->tag
)
8256 sym
= new_symbol (child_die
, NULL
, cu
);
8258 && handle_data_member_location (child_die
, cu
, &offset
))
8260 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
8261 add_symbol_to_list (sym
, &global_symbols
);
8263 child_die
= sibling_die (child_die
);
8268 /* Create a type for a C++ namespace. */
8270 static struct type
*
8271 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8273 struct objfile
*objfile
= cu
->objfile
;
8274 const char *previous_prefix
, *name
;
8278 /* For extensions, reuse the type of the original namespace. */
8279 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
8281 struct die_info
*ext_die
;
8282 struct dwarf2_cu
*ext_cu
= cu
;
8284 ext_die
= dwarf2_extension (die
, &ext_cu
);
8285 type
= read_type_die (ext_die
, ext_cu
);
8287 /* EXT_CU may not be the same as CU.
8288 Ensure TYPE is recorded in CU's type_hash table. */
8289 return set_die_type (die
, type
, cu
);
8292 name
= namespace_name (die
, &is_anonymous
, cu
);
8294 /* Now build the name of the current namespace. */
8296 previous_prefix
= determine_prefix (die
, cu
);
8297 if (previous_prefix
[0] != '\0')
8298 name
= typename_concat (&objfile
->objfile_obstack
,
8299 previous_prefix
, name
, 0, cu
);
8301 /* Create the type. */
8302 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8304 TYPE_NAME (type
) = (char *) name
;
8305 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8307 return set_die_type (die
, type
, cu
);
8310 /* Read a C++ namespace. */
8313 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8315 struct objfile
*objfile
= cu
->objfile
;
8318 /* Add a symbol associated to this if we haven't seen the namespace
8319 before. Also, add a using directive if it's an anonymous
8322 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8326 type
= read_type_die (die
, cu
);
8327 new_symbol (die
, type
, cu
);
8329 namespace_name (die
, &is_anonymous
, cu
);
8332 const char *previous_prefix
= determine_prefix (die
, cu
);
8334 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8335 NULL
, NULL
, &objfile
->objfile_obstack
);
8339 if (die
->child
!= NULL
)
8341 struct die_info
*child_die
= die
->child
;
8343 while (child_die
&& child_die
->tag
)
8345 process_die (child_die
, cu
);
8346 child_die
= sibling_die (child_die
);
8351 /* Read a Fortran module as type. This DIE can be only a declaration used for
8352 imported module. Still we need that type as local Fortran "use ... only"
8353 declaration imports depend on the created type in determine_prefix. */
8355 static struct type
*
8356 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8358 struct objfile
*objfile
= cu
->objfile
;
8362 module_name
= dwarf2_name (die
, cu
);
8364 complaint (&symfile_complaints
,
8365 _("DW_TAG_module has no name, offset 0x%x"),
8367 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8369 /* determine_prefix uses TYPE_TAG_NAME. */
8370 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8372 return set_die_type (die
, type
, cu
);
8375 /* Read a Fortran module. */
8378 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8380 struct die_info
*child_die
= die
->child
;
8382 while (child_die
&& child_die
->tag
)
8384 process_die (child_die
, cu
);
8385 child_die
= sibling_die (child_die
);
8389 /* Return the name of the namespace represented by DIE. Set
8390 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8394 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8396 struct die_info
*current_die
;
8397 const char *name
= NULL
;
8399 /* Loop through the extensions until we find a name. */
8401 for (current_die
= die
;
8402 current_die
!= NULL
;
8403 current_die
= dwarf2_extension (die
, &cu
))
8405 name
= dwarf2_name (current_die
, cu
);
8410 /* Is it an anonymous namespace? */
8412 *is_anonymous
= (name
== NULL
);
8414 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8419 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8420 the user defined type vector. */
8422 static struct type
*
8423 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8425 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8426 struct comp_unit_head
*cu_header
= &cu
->header
;
8428 struct attribute
*attr_byte_size
;
8429 struct attribute
*attr_address_class
;
8430 int byte_size
, addr_class
;
8431 struct type
*target_type
;
8433 target_type
= die_type (die
, cu
);
8435 /* The die_type call above may have already set the type for this DIE. */
8436 type
= get_die_type (die
, cu
);
8440 type
= lookup_pointer_type (target_type
);
8442 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8444 byte_size
= DW_UNSND (attr_byte_size
);
8446 byte_size
= cu_header
->addr_size
;
8448 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8449 if (attr_address_class
)
8450 addr_class
= DW_UNSND (attr_address_class
);
8452 addr_class
= DW_ADDR_none
;
8454 /* If the pointer size or address class is different than the
8455 default, create a type variant marked as such and set the
8456 length accordingly. */
8457 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8459 if (gdbarch_address_class_type_flags_p (gdbarch
))
8463 type_flags
= gdbarch_address_class_type_flags
8464 (gdbarch
, byte_size
, addr_class
);
8465 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8467 type
= make_type_with_address_space (type
, type_flags
);
8469 else if (TYPE_LENGTH (type
) != byte_size
)
8471 complaint (&symfile_complaints
,
8472 _("invalid pointer size %d"), byte_size
);
8476 /* Should we also complain about unhandled address classes? */
8480 TYPE_LENGTH (type
) = byte_size
;
8481 return set_die_type (die
, type
, cu
);
8484 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8485 the user defined type vector. */
8487 static struct type
*
8488 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8491 struct type
*to_type
;
8492 struct type
*domain
;
8494 to_type
= die_type (die
, cu
);
8495 domain
= die_containing_type (die
, cu
);
8497 /* The calls above may have already set the type for this DIE. */
8498 type
= get_die_type (die
, cu
);
8502 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8503 type
= lookup_methodptr_type (to_type
);
8505 type
= lookup_memberptr_type (to_type
, domain
);
8507 return set_die_type (die
, type
, cu
);
8510 /* Extract all information from a DW_TAG_reference_type DIE and add to
8511 the user defined type vector. */
8513 static struct type
*
8514 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8516 struct comp_unit_head
*cu_header
= &cu
->header
;
8517 struct type
*type
, *target_type
;
8518 struct attribute
*attr
;
8520 target_type
= die_type (die
, cu
);
8522 /* The die_type call above may have already set the type for this DIE. */
8523 type
= get_die_type (die
, cu
);
8527 type
= lookup_reference_type (target_type
);
8528 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8531 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8535 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8537 return set_die_type (die
, type
, cu
);
8540 static struct type
*
8541 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8543 struct type
*base_type
, *cv_type
;
8545 base_type
= die_type (die
, cu
);
8547 /* The die_type call above may have already set the type for this DIE. */
8548 cv_type
= get_die_type (die
, cu
);
8552 /* In case the const qualifier is applied to an array type, the element type
8553 is so qualified, not the array type (section 6.7.3 of C99). */
8554 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8556 struct type
*el_type
, *inner_array
;
8558 base_type
= copy_type (base_type
);
8559 inner_array
= base_type
;
8561 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8563 TYPE_TARGET_TYPE (inner_array
) =
8564 copy_type (TYPE_TARGET_TYPE (inner_array
));
8565 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8568 el_type
= TYPE_TARGET_TYPE (inner_array
);
8569 TYPE_TARGET_TYPE (inner_array
) =
8570 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8572 return set_die_type (die
, base_type
, cu
);
8575 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8576 return set_die_type (die
, cv_type
, cu
);
8579 static struct type
*
8580 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8582 struct type
*base_type
, *cv_type
;
8584 base_type
= die_type (die
, cu
);
8586 /* The die_type call above may have already set the type for this DIE. */
8587 cv_type
= get_die_type (die
, cu
);
8591 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8592 return set_die_type (die
, cv_type
, cu
);
8595 /* Extract all information from a DW_TAG_string_type DIE and add to
8596 the user defined type vector. It isn't really a user defined type,
8597 but it behaves like one, with other DIE's using an AT_user_def_type
8598 attribute to reference it. */
8600 static struct type
*
8601 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8603 struct objfile
*objfile
= cu
->objfile
;
8604 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8605 struct type
*type
, *range_type
, *index_type
, *char_type
;
8606 struct attribute
*attr
;
8607 unsigned int length
;
8609 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8612 length
= DW_UNSND (attr
);
8616 /* Check for the DW_AT_byte_size attribute. */
8617 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8620 length
= DW_UNSND (attr
);
8628 index_type
= objfile_type (objfile
)->builtin_int
;
8629 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8630 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8631 type
= create_string_type (NULL
, char_type
, range_type
);
8633 return set_die_type (die
, type
, cu
);
8636 /* Handle DIES due to C code like:
8640 int (*funcp)(int a, long l);
8644 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8646 static struct type
*
8647 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8649 struct objfile
*objfile
= cu
->objfile
;
8650 struct type
*type
; /* Type that this function returns. */
8651 struct type
*ftype
; /* Function that returns above type. */
8652 struct attribute
*attr
;
8654 type
= die_type (die
, cu
);
8656 /* The die_type call above may have already set the type for this DIE. */
8657 ftype
= get_die_type (die
, cu
);
8661 ftype
= lookup_function_type (type
);
8663 /* All functions in C++, Pascal and Java have prototypes. */
8664 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8665 if ((attr
&& (DW_UNSND (attr
) != 0))
8666 || cu
->language
== language_cplus
8667 || cu
->language
== language_java
8668 || cu
->language
== language_pascal
)
8669 TYPE_PROTOTYPED (ftype
) = 1;
8670 else if (producer_is_realview (cu
->producer
))
8671 /* RealView does not emit DW_AT_prototyped. We can not
8672 distinguish prototyped and unprototyped functions; default to
8673 prototyped, since that is more common in modern code (and
8674 RealView warns about unprototyped functions). */
8675 TYPE_PROTOTYPED (ftype
) = 1;
8677 /* Store the calling convention in the type if it's available in
8678 the subroutine die. Otherwise set the calling convention to
8679 the default value DW_CC_normal. */
8680 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8682 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8683 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8684 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8686 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8688 /* We need to add the subroutine type to the die immediately so
8689 we don't infinitely recurse when dealing with parameters
8690 declared as the same subroutine type. */
8691 set_die_type (die
, ftype
, cu
);
8693 if (die
->child
!= NULL
)
8695 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
8696 struct die_info
*child_die
;
8697 int nparams
, iparams
;
8699 /* Count the number of parameters.
8700 FIXME: GDB currently ignores vararg functions, but knows about
8701 vararg member functions. */
8703 child_die
= die
->child
;
8704 while (child_die
&& child_die
->tag
)
8706 if (child_die
->tag
== DW_TAG_formal_parameter
)
8708 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8709 TYPE_VARARGS (ftype
) = 1;
8710 child_die
= sibling_die (child_die
);
8713 /* Allocate storage for parameters and fill them in. */
8714 TYPE_NFIELDS (ftype
) = nparams
;
8715 TYPE_FIELDS (ftype
) = (struct field
*)
8716 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8718 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8719 even if we error out during the parameters reading below. */
8720 for (iparams
= 0; iparams
< nparams
; iparams
++)
8721 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8724 child_die
= die
->child
;
8725 while (child_die
&& child_die
->tag
)
8727 if (child_die
->tag
== DW_TAG_formal_parameter
)
8729 struct type
*arg_type
;
8731 /* DWARF version 2 has no clean way to discern C++
8732 static and non-static member functions. G++ helps
8733 GDB by marking the first parameter for non-static
8734 member functions (which is the this pointer) as
8735 artificial. We pass this information to
8736 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8738 DWARF version 3 added DW_AT_object_pointer, which GCC
8739 4.5 does not yet generate. */
8740 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8742 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8745 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8747 /* GCC/43521: In java, the formal parameter
8748 "this" is sometimes not marked with DW_AT_artificial. */
8749 if (cu
->language
== language_java
)
8751 const char *name
= dwarf2_name (child_die
, cu
);
8753 if (name
&& !strcmp (name
, "this"))
8754 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8757 arg_type
= die_type (child_die
, cu
);
8759 /* RealView does not mark THIS as const, which the testsuite
8760 expects. GCC marks THIS as const in method definitions,
8761 but not in the class specifications (GCC PR 43053). */
8762 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8763 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8766 struct dwarf2_cu
*arg_cu
= cu
;
8767 const char *name
= dwarf2_name (child_die
, cu
);
8769 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8772 /* If the compiler emits this, use it. */
8773 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8776 else if (name
&& strcmp (name
, "this") == 0)
8777 /* Function definitions will have the argument names. */
8779 else if (name
== NULL
&& iparams
== 0)
8780 /* Declarations may not have the names, so like
8781 elsewhere in GDB, assume an artificial first
8782 argument is "this". */
8786 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8790 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8793 child_die
= sibling_die (child_die
);
8800 static struct type
*
8801 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8803 struct objfile
*objfile
= cu
->objfile
;
8804 const char *name
= NULL
;
8805 struct type
*this_type
, *target_type
;
8807 name
= dwarf2_full_name (NULL
, die
, cu
);
8808 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8809 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8810 TYPE_NAME (this_type
) = (char *) name
;
8811 set_die_type (die
, this_type
, cu
);
8812 target_type
= die_type (die
, cu
);
8813 if (target_type
!= this_type
)
8814 TYPE_TARGET_TYPE (this_type
) = target_type
;
8817 /* Self-referential typedefs are, it seems, not allowed by the DWARF
8818 spec and cause infinite loops in GDB. */
8819 complaint (&symfile_complaints
,
8820 _("Self-referential DW_TAG_typedef "
8821 "- DIE at 0x%x [in module %s]"),
8822 die
->offset
, objfile
->name
);
8823 TYPE_TARGET_TYPE (this_type
) = NULL
;
8828 /* Find a representation of a given base type and install
8829 it in the TYPE field of the die. */
8831 static struct type
*
8832 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8834 struct objfile
*objfile
= cu
->objfile
;
8836 struct attribute
*attr
;
8837 int encoding
= 0, size
= 0;
8839 enum type_code code
= TYPE_CODE_INT
;
8841 struct type
*target_type
= NULL
;
8843 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8846 encoding
= DW_UNSND (attr
);
8848 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8851 size
= DW_UNSND (attr
);
8853 name
= dwarf2_name (die
, cu
);
8856 complaint (&symfile_complaints
,
8857 _("DW_AT_name missing from DW_TAG_base_type"));
8862 case DW_ATE_address
:
8863 /* Turn DW_ATE_address into a void * pointer. */
8864 code
= TYPE_CODE_PTR
;
8865 type_flags
|= TYPE_FLAG_UNSIGNED
;
8866 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8868 case DW_ATE_boolean
:
8869 code
= TYPE_CODE_BOOL
;
8870 type_flags
|= TYPE_FLAG_UNSIGNED
;
8872 case DW_ATE_complex_float
:
8873 code
= TYPE_CODE_COMPLEX
;
8874 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8876 case DW_ATE_decimal_float
:
8877 code
= TYPE_CODE_DECFLOAT
;
8880 code
= TYPE_CODE_FLT
;
8884 case DW_ATE_unsigned
:
8885 type_flags
|= TYPE_FLAG_UNSIGNED
;
8886 if (cu
->language
== language_fortran
8888 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
8889 code
= TYPE_CODE_CHAR
;
8891 case DW_ATE_signed_char
:
8892 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8893 || cu
->language
== language_pascal
8894 || cu
->language
== language_fortran
)
8895 code
= TYPE_CODE_CHAR
;
8897 case DW_ATE_unsigned_char
:
8898 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8899 || cu
->language
== language_pascal
8900 || cu
->language
== language_fortran
)
8901 code
= TYPE_CODE_CHAR
;
8902 type_flags
|= TYPE_FLAG_UNSIGNED
;
8905 /* We just treat this as an integer and then recognize the
8906 type by name elsewhere. */
8910 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8911 dwarf_type_encoding_name (encoding
));
8915 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8916 TYPE_NAME (type
) = name
;
8917 TYPE_TARGET_TYPE (type
) = target_type
;
8919 if (name
&& strcmp (name
, "char") == 0)
8920 TYPE_NOSIGN (type
) = 1;
8922 return set_die_type (die
, type
, cu
);
8925 /* Read the given DW_AT_subrange DIE. */
8927 static struct type
*
8928 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8930 struct type
*base_type
;
8931 struct type
*range_type
;
8932 struct attribute
*attr
;
8936 LONGEST negative_mask
;
8938 base_type
= die_type (die
, cu
);
8939 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8940 check_typedef (base_type
);
8942 /* The die_type call above may have already set the type for this DIE. */
8943 range_type
= get_die_type (die
, cu
);
8947 if (cu
->language
== language_fortran
)
8949 /* FORTRAN implies a lower bound of 1, if not given. */
8953 /* FIXME: For variable sized arrays either of these could be
8954 a variable rather than a constant value. We'll allow it,
8955 but we don't know how to handle it. */
8956 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8958 low
= dwarf2_get_attr_constant_value (attr
, 0);
8960 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8963 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
8965 /* GCC encodes arrays with unspecified or dynamic length
8966 with a DW_FORM_block1 attribute or a reference attribute.
8967 FIXME: GDB does not yet know how to handle dynamic
8968 arrays properly, treat them as arrays with unspecified
8971 FIXME: jimb/2003-09-22: GDB does not really know
8972 how to handle arrays of unspecified length
8973 either; we just represent them as zero-length
8974 arrays. Choose an appropriate upper bound given
8975 the lower bound we've computed above. */
8979 high
= dwarf2_get_attr_constant_value (attr
, 1);
8983 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8986 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8987 high
= low
+ count
- 1;
8991 /* Unspecified array length. */
8996 /* Dwarf-2 specifications explicitly allows to create subrange types
8997 without specifying a base type.
8998 In that case, the base type must be set to the type of
8999 the lower bound, upper bound or count, in that order, if any of these
9000 three attributes references an object that has a type.
9001 If no base type is found, the Dwarf-2 specifications say that
9002 a signed integer type of size equal to the size of an address should
9004 For the following C code: `extern char gdb_int [];'
9005 GCC produces an empty range DIE.
9006 FIXME: muller/2010-05-28: Possible references to object for low bound,
9007 high bound or count are not yet handled by this code. */
9008 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
9010 struct objfile
*objfile
= cu
->objfile
;
9011 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9012 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
9013 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
9015 /* Test "int", "long int", and "long long int" objfile types,
9016 and select the first one having a size above or equal to the
9017 architecture address size. */
9018 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9019 base_type
= int_type
;
9022 int_type
= objfile_type (objfile
)->builtin_long
;
9023 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9024 base_type
= int_type
;
9027 int_type
= objfile_type (objfile
)->builtin_long_long
;
9028 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9029 base_type
= int_type
;
9035 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
9036 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
9037 low
|= negative_mask
;
9038 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
9039 high
|= negative_mask
;
9041 range_type
= create_range_type (NULL
, base_type
, low
, high
);
9043 /* Mark arrays with dynamic length at least as an array of unspecified
9044 length. GDB could check the boundary but before it gets implemented at
9045 least allow accessing the array elements. */
9046 if (attr
&& attr_form_is_block (attr
))
9047 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9049 /* Ada expects an empty array on no boundary attributes. */
9050 if (attr
== NULL
&& cu
->language
!= language_ada
)
9051 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9053 name
= dwarf2_name (die
, cu
);
9055 TYPE_NAME (range_type
) = name
;
9057 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9059 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
9061 set_die_type (die
, range_type
, cu
);
9063 /* set_die_type should be already done. */
9064 set_descriptive_type (range_type
, die
, cu
);
9069 static struct type
*
9070 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9074 /* For now, we only support the C meaning of an unspecified type: void. */
9076 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
9077 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
9079 return set_die_type (die
, type
, cu
);
9082 /* Trivial hash function for die_info: the hash value of a DIE
9083 is its offset in .debug_info for this objfile. */
9086 die_hash (const void *item
)
9088 const struct die_info
*die
= item
;
9093 /* Trivial comparison function for die_info structures: two DIEs
9094 are equal if they have the same offset. */
9097 die_eq (const void *item_lhs
, const void *item_rhs
)
9099 const struct die_info
*die_lhs
= item_lhs
;
9100 const struct die_info
*die_rhs
= item_rhs
;
9102 return die_lhs
->offset
== die_rhs
->offset
;
9105 /* Read a whole compilation unit into a linked list of dies. */
9107 static struct die_info
*
9108 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9110 struct die_reader_specs reader_specs
;
9111 int read_abbrevs
= 0;
9112 struct cleanup
*back_to
= NULL
;
9113 struct die_info
*die
;
9115 if (cu
->dwarf2_abbrevs
== NULL
)
9117 dwarf2_read_abbrevs (cu
);
9118 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
9122 gdb_assert (cu
->die_hash
== NULL
);
9124 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9128 &cu
->comp_unit_obstack
,
9129 hashtab_obstack_allocate
,
9130 dummy_obstack_deallocate
);
9132 init_cu_die_reader (&reader_specs
, cu
);
9134 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
9137 do_cleanups (back_to
);
9142 /* Main entry point for reading a DIE and all children.
9143 Read the DIE and dump it if requested. */
9145 static struct die_info
*
9146 read_die_and_children (const struct die_reader_specs
*reader
,
9148 gdb_byte
**new_info_ptr
,
9149 struct die_info
*parent
)
9151 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
9152 new_info_ptr
, parent
);
9154 if (dwarf2_die_debug
)
9156 fprintf_unfiltered (gdb_stdlog
,
9157 "\nRead die from %s of %s:\n",
9158 (reader
->cu
->per_cu
->debug_types_section
9161 reader
->abfd
->filename
);
9162 dump_die (result
, dwarf2_die_debug
);
9168 /* Read a single die and all its descendents. Set the die's sibling
9169 field to NULL; set other fields in the die correctly, and set all
9170 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9171 location of the info_ptr after reading all of those dies. PARENT
9172 is the parent of the die in question. */
9174 static struct die_info
*
9175 read_die_and_children_1 (const struct die_reader_specs
*reader
,
9177 gdb_byte
**new_info_ptr
,
9178 struct die_info
*parent
)
9180 struct die_info
*die
;
9184 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
9187 *new_info_ptr
= cur_ptr
;
9190 store_in_ref_table (die
, reader
->cu
);
9193 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
9197 *new_info_ptr
= cur_ptr
;
9200 die
->sibling
= NULL
;
9201 die
->parent
= parent
;
9205 /* Read a die, all of its descendents, and all of its siblings; set
9206 all of the fields of all of the dies correctly. Arguments are as
9207 in read_die_and_children. */
9209 static struct die_info
*
9210 read_die_and_siblings (const struct die_reader_specs
*reader
,
9212 gdb_byte
**new_info_ptr
,
9213 struct die_info
*parent
)
9215 struct die_info
*first_die
, *last_sibling
;
9219 first_die
= last_sibling
= NULL
;
9223 struct die_info
*die
9224 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
9228 *new_info_ptr
= cur_ptr
;
9235 last_sibling
->sibling
= die
;
9241 /* Read the die from the .debug_info section buffer. Set DIEP to
9242 point to a newly allocated die with its information, except for its
9243 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9244 whether the die has children or not. */
9247 read_full_die (const struct die_reader_specs
*reader
,
9248 struct die_info
**diep
, gdb_byte
*info_ptr
,
9251 unsigned int abbrev_number
, bytes_read
, i
, offset
;
9252 struct abbrev_info
*abbrev
;
9253 struct die_info
*die
;
9254 struct dwarf2_cu
*cu
= reader
->cu
;
9255 bfd
*abfd
= reader
->abfd
;
9257 offset
= info_ptr
- reader
->buffer
;
9258 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9259 info_ptr
+= bytes_read
;
9267 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
9269 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9271 bfd_get_filename (abfd
));
9273 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
9274 die
->offset
= offset
;
9275 die
->tag
= abbrev
->tag
;
9276 die
->abbrev
= abbrev_number
;
9278 die
->num_attrs
= abbrev
->num_attrs
;
9280 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9281 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
9282 abfd
, info_ptr
, cu
);
9285 *has_children
= abbrev
->has_children
;
9289 /* In DWARF version 2, the description of the debugging information is
9290 stored in a separate .debug_abbrev section. Before we read any
9291 dies from a section we read in all abbreviations and install them
9292 in a hash table. This function also sets flags in CU describing
9293 the data found in the abbrev table. */
9296 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
)
9298 bfd
*abfd
= cu
->objfile
->obfd
;
9299 struct comp_unit_head
*cu_header
= &cu
->header
;
9300 gdb_byte
*abbrev_ptr
;
9301 struct abbrev_info
*cur_abbrev
;
9302 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9303 unsigned int abbrev_form
, hash_number
;
9304 struct attr_abbrev
*cur_attrs
;
9305 unsigned int allocated_attrs
;
9307 /* Initialize dwarf2 abbrevs. */
9308 obstack_init (&cu
->abbrev_obstack
);
9309 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9311 * sizeof (struct abbrev_info
*)));
9312 memset (cu
->dwarf2_abbrevs
, 0,
9313 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9315 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
9316 &dwarf2_per_objfile
->abbrev
);
9317 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
9318 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9319 abbrev_ptr
+= bytes_read
;
9321 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9322 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9324 /* Loop until we reach an abbrev number of 0. */
9325 while (abbrev_number
)
9327 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9329 /* read in abbrev header */
9330 cur_abbrev
->number
= abbrev_number
;
9331 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9332 abbrev_ptr
+= bytes_read
;
9333 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9336 if (cur_abbrev
->tag
== DW_TAG_namespace
)
9337 cu
->has_namespace_info
= 1;
9339 /* now read in declarations */
9340 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9341 abbrev_ptr
+= bytes_read
;
9342 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9343 abbrev_ptr
+= bytes_read
;
9346 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9348 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9350 = xrealloc (cur_attrs
, (allocated_attrs
9351 * sizeof (struct attr_abbrev
)));
9354 /* Record whether this compilation unit might have
9355 inter-compilation-unit references. If we don't know what form
9356 this attribute will have, then it might potentially be a
9357 DW_FORM_ref_addr, so we conservatively expect inter-CU
9360 if (abbrev_form
== DW_FORM_ref_addr
9361 || abbrev_form
== DW_FORM_indirect
)
9362 cu
->has_form_ref_addr
= 1;
9364 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9365 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9366 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9367 abbrev_ptr
+= bytes_read
;
9368 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9369 abbrev_ptr
+= bytes_read
;
9372 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9373 (cur_abbrev
->num_attrs
9374 * sizeof (struct attr_abbrev
)));
9375 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9376 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9378 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9379 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9380 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9382 /* Get next abbreviation.
9383 Under Irix6 the abbreviations for a compilation unit are not
9384 always properly terminated with an abbrev number of 0.
9385 Exit loop if we encounter an abbreviation which we have
9386 already read (which means we are about to read the abbreviations
9387 for the next compile unit) or if the end of the abbreviation
9388 table is reached. */
9389 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
9390 >= dwarf2_per_objfile
->abbrev
.size
)
9392 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9393 abbrev_ptr
+= bytes_read
;
9394 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9401 /* Release the memory used by the abbrev table for a compilation unit. */
9404 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9406 struct dwarf2_cu
*cu
= ptr_to_cu
;
9408 obstack_free (&cu
->abbrev_obstack
, NULL
);
9409 cu
->dwarf2_abbrevs
= NULL
;
9412 /* Lookup an abbrev_info structure in the abbrev hash table. */
9414 static struct abbrev_info
*
9415 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9417 unsigned int hash_number
;
9418 struct abbrev_info
*abbrev
;
9420 hash_number
= number
% ABBREV_HASH_SIZE
;
9421 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9425 if (abbrev
->number
== number
)
9428 abbrev
= abbrev
->next
;
9433 /* Returns nonzero if TAG represents a type that we might generate a partial
9437 is_type_tag_for_partial (int tag
)
9442 /* Some types that would be reasonable to generate partial symbols for,
9443 that we don't at present. */
9444 case DW_TAG_array_type
:
9445 case DW_TAG_file_type
:
9446 case DW_TAG_ptr_to_member_type
:
9447 case DW_TAG_set_type
:
9448 case DW_TAG_string_type
:
9449 case DW_TAG_subroutine_type
:
9451 case DW_TAG_base_type
:
9452 case DW_TAG_class_type
:
9453 case DW_TAG_interface_type
:
9454 case DW_TAG_enumeration_type
:
9455 case DW_TAG_structure_type
:
9456 case DW_TAG_subrange_type
:
9457 case DW_TAG_typedef
:
9458 case DW_TAG_union_type
:
9465 /* Load all DIEs that are interesting for partial symbols into memory. */
9467 static struct partial_die_info
*
9468 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9469 int building_psymtab
, struct dwarf2_cu
*cu
)
9471 struct objfile
*objfile
= cu
->objfile
;
9472 struct partial_die_info
*part_die
;
9473 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9474 struct abbrev_info
*abbrev
;
9475 unsigned int bytes_read
;
9476 unsigned int load_all
= 0;
9478 int nesting_level
= 1;
9483 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
9487 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9491 &cu
->comp_unit_obstack
,
9492 hashtab_obstack_allocate
,
9493 dummy_obstack_deallocate
);
9495 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9496 sizeof (struct partial_die_info
));
9500 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9502 /* A NULL abbrev means the end of a series of children. */
9505 if (--nesting_level
== 0)
9507 /* PART_DIE was probably the last thing allocated on the
9508 comp_unit_obstack, so we could call obstack_free
9509 here. We don't do that because the waste is small,
9510 and will be cleaned up when we're done with this
9511 compilation unit. This way, we're also more robust
9512 against other users of the comp_unit_obstack. */
9515 info_ptr
+= bytes_read
;
9516 last_die
= parent_die
;
9517 parent_die
= parent_die
->die_parent
;
9521 /* Check for template arguments. We never save these; if
9522 they're seen, we just mark the parent, and go on our way. */
9523 if (parent_die
!= NULL
9524 && cu
->language
== language_cplus
9525 && (abbrev
->tag
== DW_TAG_template_type_param
9526 || abbrev
->tag
== DW_TAG_template_value_param
))
9528 parent_die
->has_template_arguments
= 1;
9532 /* We don't need a partial DIE for the template argument. */
9533 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9539 /* We only recurse into subprograms looking for template arguments.
9540 Skip their other children. */
9542 && cu
->language
== language_cplus
9543 && parent_die
!= NULL
9544 && parent_die
->tag
== DW_TAG_subprogram
)
9546 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9550 /* Check whether this DIE is interesting enough to save. Normally
9551 we would not be interested in members here, but there may be
9552 later variables referencing them via DW_AT_specification (for
9555 && !is_type_tag_for_partial (abbrev
->tag
)
9556 && abbrev
->tag
!= DW_TAG_constant
9557 && abbrev
->tag
!= DW_TAG_enumerator
9558 && abbrev
->tag
!= DW_TAG_subprogram
9559 && abbrev
->tag
!= DW_TAG_lexical_block
9560 && abbrev
->tag
!= DW_TAG_variable
9561 && abbrev
->tag
!= DW_TAG_namespace
9562 && abbrev
->tag
!= DW_TAG_module
9563 && abbrev
->tag
!= DW_TAG_member
)
9565 /* Otherwise we skip to the next sibling, if any. */
9566 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9570 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9571 buffer
, info_ptr
, cu
);
9573 /* This two-pass algorithm for processing partial symbols has a
9574 high cost in cache pressure. Thus, handle some simple cases
9575 here which cover the majority of C partial symbols. DIEs
9576 which neither have specification tags in them, nor could have
9577 specification tags elsewhere pointing at them, can simply be
9578 processed and discarded.
9580 This segment is also optional; scan_partial_symbols and
9581 add_partial_symbol will handle these DIEs if we chain
9582 them in normally. When compilers which do not emit large
9583 quantities of duplicate debug information are more common,
9584 this code can probably be removed. */
9586 /* Any complete simple types at the top level (pretty much all
9587 of them, for a language without namespaces), can be processed
9589 if (parent_die
== NULL
9590 && part_die
->has_specification
== 0
9591 && part_die
->is_declaration
== 0
9592 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9593 || part_die
->tag
== DW_TAG_base_type
9594 || part_die
->tag
== DW_TAG_subrange_type
))
9596 if (building_psymtab
&& part_die
->name
!= NULL
)
9597 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9598 VAR_DOMAIN
, LOC_TYPEDEF
,
9599 &objfile
->static_psymbols
,
9600 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9601 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9605 /* The exception for DW_TAG_typedef with has_children above is
9606 a workaround of GCC PR debug/47510. In the case of this complaint
9607 type_name_no_tag_or_error will error on such types later.
9609 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9610 it could not find the child DIEs referenced later, this is checked
9611 above. In correct DWARF DW_TAG_typedef should have no children. */
9613 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9614 complaint (&symfile_complaints
,
9615 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9616 "- DIE at 0x%x [in module %s]"),
9617 part_die
->offset
, objfile
->name
);
9619 /* If we're at the second level, and we're an enumerator, and
9620 our parent has no specification (meaning possibly lives in a
9621 namespace elsewhere), then we can add the partial symbol now
9622 instead of queueing it. */
9623 if (part_die
->tag
== DW_TAG_enumerator
9624 && parent_die
!= NULL
9625 && parent_die
->die_parent
== NULL
9626 && parent_die
->tag
== DW_TAG_enumeration_type
9627 && parent_die
->has_specification
== 0)
9629 if (part_die
->name
== NULL
)
9630 complaint (&symfile_complaints
,
9631 _("malformed enumerator DIE ignored"));
9632 else if (building_psymtab
)
9633 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9634 VAR_DOMAIN
, LOC_CONST
,
9635 (cu
->language
== language_cplus
9636 || cu
->language
== language_java
)
9637 ? &objfile
->global_psymbols
9638 : &objfile
->static_psymbols
,
9639 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9641 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9645 /* We'll save this DIE so link it in. */
9646 part_die
->die_parent
= parent_die
;
9647 part_die
->die_sibling
= NULL
;
9648 part_die
->die_child
= NULL
;
9650 if (last_die
&& last_die
== parent_die
)
9651 last_die
->die_child
= part_die
;
9653 last_die
->die_sibling
= part_die
;
9655 last_die
= part_die
;
9657 if (first_die
== NULL
)
9658 first_die
= part_die
;
9660 /* Maybe add the DIE to the hash table. Not all DIEs that we
9661 find interesting need to be in the hash table, because we
9662 also have the parent/sibling/child chains; only those that we
9663 might refer to by offset later during partial symbol reading.
9665 For now this means things that might have be the target of a
9666 DW_AT_specification, DW_AT_abstract_origin, or
9667 DW_AT_extension. DW_AT_extension will refer only to
9668 namespaces; DW_AT_abstract_origin refers to functions (and
9669 many things under the function DIE, but we do not recurse
9670 into function DIEs during partial symbol reading) and
9671 possibly variables as well; DW_AT_specification refers to
9672 declarations. Declarations ought to have the DW_AT_declaration
9673 flag. It happens that GCC forgets to put it in sometimes, but
9674 only for functions, not for types.
9676 Adding more things than necessary to the hash table is harmless
9677 except for the performance cost. Adding too few will result in
9678 wasted time in find_partial_die, when we reread the compilation
9679 unit with load_all_dies set. */
9682 || abbrev
->tag
== DW_TAG_constant
9683 || abbrev
->tag
== DW_TAG_subprogram
9684 || abbrev
->tag
== DW_TAG_variable
9685 || abbrev
->tag
== DW_TAG_namespace
9686 || part_die
->is_declaration
)
9690 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9691 part_die
->offset
, INSERT
);
9695 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9696 sizeof (struct partial_die_info
));
9698 /* For some DIEs we want to follow their children (if any). For C
9699 we have no reason to follow the children of structures; for other
9700 languages we have to, so that we can get at method physnames
9701 to infer fully qualified class names, for DW_AT_specification,
9702 and for C++ template arguments. For C++, we also look one level
9703 inside functions to find template arguments (if the name of the
9704 function does not already contain the template arguments).
9706 For Ada, we need to scan the children of subprograms and lexical
9707 blocks as well because Ada allows the definition of nested
9708 entities that could be interesting for the debugger, such as
9709 nested subprograms for instance. */
9710 if (last_die
->has_children
9712 || last_die
->tag
== DW_TAG_namespace
9713 || last_die
->tag
== DW_TAG_module
9714 || last_die
->tag
== DW_TAG_enumeration_type
9715 || (cu
->language
== language_cplus
9716 && last_die
->tag
== DW_TAG_subprogram
9717 && (last_die
->name
== NULL
9718 || strchr (last_die
->name
, '<') == NULL
))
9719 || (cu
->language
!= language_c
9720 && (last_die
->tag
== DW_TAG_class_type
9721 || last_die
->tag
== DW_TAG_interface_type
9722 || last_die
->tag
== DW_TAG_structure_type
9723 || last_die
->tag
== DW_TAG_union_type
))
9724 || (cu
->language
== language_ada
9725 && (last_die
->tag
== DW_TAG_subprogram
9726 || last_die
->tag
== DW_TAG_lexical_block
))))
9729 parent_die
= last_die
;
9733 /* Otherwise we skip to the next sibling, if any. */
9734 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9736 /* Back to the top, do it again. */
9740 /* Read a minimal amount of information into the minimal die structure. */
9743 read_partial_die (struct partial_die_info
*part_die
,
9744 struct abbrev_info
*abbrev
,
9745 unsigned int abbrev_len
, bfd
*abfd
,
9746 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9747 struct dwarf2_cu
*cu
)
9749 struct objfile
*objfile
= cu
->objfile
;
9751 struct attribute attr
;
9752 int has_low_pc_attr
= 0;
9753 int has_high_pc_attr
= 0;
9755 memset (part_die
, 0, sizeof (struct partial_die_info
));
9757 part_die
->offset
= info_ptr
- buffer
;
9759 info_ptr
+= abbrev_len
;
9764 part_die
->tag
= abbrev
->tag
;
9765 part_die
->has_children
= abbrev
->has_children
;
9767 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9769 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9771 /* Store the data if it is of an attribute we want to keep in a
9772 partial symbol table. */
9776 switch (part_die
->tag
)
9778 case DW_TAG_compile_unit
:
9779 case DW_TAG_type_unit
:
9780 /* Compilation units have a DW_AT_name that is a filename, not
9781 a source language identifier. */
9782 case DW_TAG_enumeration_type
:
9783 case DW_TAG_enumerator
:
9784 /* These tags always have simple identifiers already; no need
9785 to canonicalize them. */
9786 part_die
->name
= DW_STRING (&attr
);
9790 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9791 &objfile
->objfile_obstack
);
9795 case DW_AT_linkage_name
:
9796 case DW_AT_MIPS_linkage_name
:
9797 /* Note that both forms of linkage name might appear. We
9798 assume they will be the same, and we only store the last
9800 if (cu
->language
== language_ada
)
9801 part_die
->name
= DW_STRING (&attr
);
9802 part_die
->linkage_name
= DW_STRING (&attr
);
9805 has_low_pc_attr
= 1;
9806 part_die
->lowpc
= DW_ADDR (&attr
);
9809 has_high_pc_attr
= 1;
9810 part_die
->highpc
= DW_ADDR (&attr
);
9812 case DW_AT_location
:
9813 /* Support the .debug_loc offsets. */
9814 if (attr_form_is_block (&attr
))
9816 part_die
->locdesc
= DW_BLOCK (&attr
);
9818 else if (attr_form_is_section_offset (&attr
))
9820 dwarf2_complex_location_expr_complaint ();
9824 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9825 "partial symbol information");
9828 case DW_AT_external
:
9829 part_die
->is_external
= DW_UNSND (&attr
);
9831 case DW_AT_declaration
:
9832 part_die
->is_declaration
= DW_UNSND (&attr
);
9835 part_die
->has_type
= 1;
9837 case DW_AT_abstract_origin
:
9838 case DW_AT_specification
:
9839 case DW_AT_extension
:
9840 part_die
->has_specification
= 1;
9841 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9844 /* Ignore absolute siblings, they might point outside of
9845 the current compile unit. */
9846 if (attr
.form
== DW_FORM_ref_addr
)
9847 complaint (&symfile_complaints
,
9848 _("ignoring absolute DW_AT_sibling"));
9850 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9852 case DW_AT_byte_size
:
9853 part_die
->has_byte_size
= 1;
9855 case DW_AT_calling_convention
:
9856 /* DWARF doesn't provide a way to identify a program's source-level
9857 entry point. DW_AT_calling_convention attributes are only meant
9858 to describe functions' calling conventions.
9860 However, because it's a necessary piece of information in
9861 Fortran, and because DW_CC_program is the only piece of debugging
9862 information whose definition refers to a 'main program' at all,
9863 several compilers have begun marking Fortran main programs with
9864 DW_CC_program --- even when those functions use the standard
9865 calling conventions.
9867 So until DWARF specifies a way to provide this information and
9868 compilers pick up the new representation, we'll support this
9870 if (DW_UNSND (&attr
) == DW_CC_program
9871 && cu
->language
== language_fortran
)
9873 set_main_name (part_die
->name
);
9875 /* As this DIE has a static linkage the name would be difficult
9876 to look up later. */
9877 language_of_main
= language_fortran
;
9885 if (has_low_pc_attr
&& has_high_pc_attr
)
9887 /* When using the GNU linker, .gnu.linkonce. sections are used to
9888 eliminate duplicate copies of functions and vtables and such.
9889 The linker will arbitrarily choose one and discard the others.
9890 The AT_*_pc values for such functions refer to local labels in
9891 these sections. If the section from that file was discarded, the
9892 labels are not in the output, so the relocs get a value of 0.
9893 If this is a discarded function, mark the pc bounds as invalid,
9894 so that GDB will ignore it. */
9895 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9897 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9899 complaint (&symfile_complaints
,
9900 _("DW_AT_low_pc %s is zero "
9901 "for DIE at 0x%x [in module %s]"),
9902 paddress (gdbarch
, part_die
->lowpc
),
9903 part_die
->offset
, objfile
->name
);
9905 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9906 else if (part_die
->lowpc
>= part_die
->highpc
)
9908 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9910 complaint (&symfile_complaints
,
9911 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9912 "for DIE at 0x%x [in module %s]"),
9913 paddress (gdbarch
, part_die
->lowpc
),
9914 paddress (gdbarch
, part_die
->highpc
),
9915 part_die
->offset
, objfile
->name
);
9918 part_die
->has_pc_info
= 1;
9924 /* Find a cached partial DIE at OFFSET in CU. */
9926 static struct partial_die_info
*
9927 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9929 struct partial_die_info
*lookup_die
= NULL
;
9930 struct partial_die_info part_die
;
9932 part_die
.offset
= offset
;
9933 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9938 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9939 except in the case of .debug_types DIEs which do not reference
9940 outside their CU (they do however referencing other types via
9941 DW_FORM_ref_sig8). */
9943 static struct partial_die_info
*
9944 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9946 struct objfile
*objfile
= cu
->objfile
;
9947 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9948 struct partial_die_info
*pd
= NULL
;
9950 if (cu
->per_cu
->debug_types_section
)
9952 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9958 if (offset_in_cu_p (&cu
->header
, offset
))
9960 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9965 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
9967 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9968 load_partial_comp_unit (per_cu
);
9970 per_cu
->cu
->last_used
= 0;
9971 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9973 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9975 struct cleanup
*back_to
;
9976 struct partial_die_info comp_unit_die
;
9977 struct abbrev_info
*abbrev
;
9978 unsigned int bytes_read
;
9981 per_cu
->load_all_dies
= 1;
9983 /* Re-read the DIEs. */
9984 back_to
= make_cleanup (null_cleanup
, 0);
9985 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9987 dwarf2_read_abbrevs (per_cu
->cu
);
9988 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9990 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9991 + per_cu
->cu
->header
.offset
9992 + per_cu
->cu
->header
.first_die_offset
);
9993 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9994 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9996 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9998 if (comp_unit_die
.has_children
)
9999 load_partial_dies (objfile
->obfd
,
10000 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
10002 do_cleanups (back_to
);
10004 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10010 internal_error (__FILE__
, __LINE__
,
10011 _("could not find partial DIE 0x%x "
10012 "in cache [from module %s]\n"),
10013 offset
, bfd_get_filename (objfile
->obfd
));
10017 /* See if we can figure out if the class lives in a namespace. We do
10018 this by looking for a member function; its demangled name will
10019 contain namespace info, if there is any. */
10022 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
10023 struct dwarf2_cu
*cu
)
10025 /* NOTE: carlton/2003-10-07: Getting the info this way changes
10026 what template types look like, because the demangler
10027 frequently doesn't give the same name as the debug info. We
10028 could fix this by only using the demangled name to get the
10029 prefix (but see comment in read_structure_type). */
10031 struct partial_die_info
*real_pdi
;
10032 struct partial_die_info
*child_pdi
;
10034 /* If this DIE (this DIE's specification, if any) has a parent, then
10035 we should not do this. We'll prepend the parent's fully qualified
10036 name when we create the partial symbol. */
10038 real_pdi
= struct_pdi
;
10039 while (real_pdi
->has_specification
)
10040 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
10042 if (real_pdi
->die_parent
!= NULL
)
10045 for (child_pdi
= struct_pdi
->die_child
;
10047 child_pdi
= child_pdi
->die_sibling
)
10049 if (child_pdi
->tag
== DW_TAG_subprogram
10050 && child_pdi
->linkage_name
!= NULL
)
10052 char *actual_class_name
10053 = language_class_name_from_physname (cu
->language_defn
,
10054 child_pdi
->linkage_name
);
10055 if (actual_class_name
!= NULL
)
10058 = obsavestring (actual_class_name
,
10059 strlen (actual_class_name
),
10060 &cu
->objfile
->objfile_obstack
);
10061 xfree (actual_class_name
);
10068 /* Adjust PART_DIE before generating a symbol for it. This function
10069 may set the is_external flag or change the DIE's name. */
10072 fixup_partial_die (struct partial_die_info
*part_die
,
10073 struct dwarf2_cu
*cu
)
10075 /* Once we've fixed up a die, there's no point in doing so again.
10076 This also avoids a memory leak if we were to call
10077 guess_partial_die_structure_name multiple times. */
10078 if (part_die
->fixup_called
)
10081 /* If we found a reference attribute and the DIE has no name, try
10082 to find a name in the referred to DIE. */
10084 if (part_die
->name
== NULL
&& part_die
->has_specification
)
10086 struct partial_die_info
*spec_die
;
10088 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
10090 fixup_partial_die (spec_die
, cu
);
10092 if (spec_die
->name
)
10094 part_die
->name
= spec_die
->name
;
10096 /* Copy DW_AT_external attribute if it is set. */
10097 if (spec_die
->is_external
)
10098 part_die
->is_external
= spec_die
->is_external
;
10102 /* Set default names for some unnamed DIEs. */
10104 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
10105 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
10107 /* If there is no parent die to provide a namespace, and there are
10108 children, see if we can determine the namespace from their linkage
10110 NOTE: We need to do this even if cu->has_namespace_info != 0.
10111 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
10112 if (cu
->language
== language_cplus
10113 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
10114 && part_die
->die_parent
== NULL
10115 && part_die
->has_children
10116 && (part_die
->tag
== DW_TAG_class_type
10117 || part_die
->tag
== DW_TAG_structure_type
10118 || part_die
->tag
== DW_TAG_union_type
))
10119 guess_partial_die_structure_name (part_die
, cu
);
10121 /* GCC might emit a nameless struct or union that has a linkage
10122 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10123 if (part_die
->name
== NULL
10124 && (part_die
->tag
== DW_TAG_class_type
10125 || part_die
->tag
== DW_TAG_interface_type
10126 || part_die
->tag
== DW_TAG_structure_type
10127 || part_die
->tag
== DW_TAG_union_type
)
10128 && part_die
->linkage_name
!= NULL
)
10132 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
10137 /* Strip any leading namespaces/classes, keep only the base name.
10138 DW_AT_name for named DIEs does not contain the prefixes. */
10139 base
= strrchr (demangled
, ':');
10140 if (base
&& base
> demangled
&& base
[-1] == ':')
10145 part_die
->name
= obsavestring (base
, strlen (base
),
10146 &cu
->objfile
->objfile_obstack
);
10151 part_die
->fixup_called
= 1;
10154 /* Read an attribute value described by an attribute form. */
10157 read_attribute_value (struct attribute
*attr
, unsigned form
,
10158 bfd
*abfd
, gdb_byte
*info_ptr
,
10159 struct dwarf2_cu
*cu
)
10161 struct comp_unit_head
*cu_header
= &cu
->header
;
10162 unsigned int bytes_read
;
10163 struct dwarf_block
*blk
;
10168 case DW_FORM_ref_addr
:
10169 if (cu
->header
.version
== 2)
10170 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10172 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
10173 &cu
->header
, &bytes_read
);
10174 info_ptr
+= bytes_read
;
10177 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10178 info_ptr
+= bytes_read
;
10180 case DW_FORM_block2
:
10181 blk
= dwarf_alloc_block (cu
);
10182 blk
->size
= read_2_bytes (abfd
, info_ptr
);
10184 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10185 info_ptr
+= blk
->size
;
10186 DW_BLOCK (attr
) = blk
;
10188 case DW_FORM_block4
:
10189 blk
= dwarf_alloc_block (cu
);
10190 blk
->size
= read_4_bytes (abfd
, info_ptr
);
10192 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10193 info_ptr
+= blk
->size
;
10194 DW_BLOCK (attr
) = blk
;
10196 case DW_FORM_data2
:
10197 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
10200 case DW_FORM_data4
:
10201 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
10204 case DW_FORM_data8
:
10205 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
10208 case DW_FORM_sec_offset
:
10209 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
10210 info_ptr
+= bytes_read
;
10212 case DW_FORM_string
:
10213 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
10214 DW_STRING_IS_CANONICAL (attr
) = 0;
10215 info_ptr
+= bytes_read
;
10218 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
10220 DW_STRING_IS_CANONICAL (attr
) = 0;
10221 info_ptr
+= bytes_read
;
10223 case DW_FORM_exprloc
:
10224 case DW_FORM_block
:
10225 blk
= dwarf_alloc_block (cu
);
10226 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10227 info_ptr
+= bytes_read
;
10228 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10229 info_ptr
+= blk
->size
;
10230 DW_BLOCK (attr
) = blk
;
10232 case DW_FORM_block1
:
10233 blk
= dwarf_alloc_block (cu
);
10234 blk
->size
= read_1_byte (abfd
, info_ptr
);
10236 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10237 info_ptr
+= blk
->size
;
10238 DW_BLOCK (attr
) = blk
;
10240 case DW_FORM_data1
:
10241 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10245 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10248 case DW_FORM_flag_present
:
10249 DW_UNSND (attr
) = 1;
10251 case DW_FORM_sdata
:
10252 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
10253 info_ptr
+= bytes_read
;
10255 case DW_FORM_udata
:
10256 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10257 info_ptr
+= bytes_read
;
10260 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
10264 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
10268 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
10272 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
10275 case DW_FORM_ref_sig8
:
10276 /* Convert the signature to something we can record in DW_UNSND
10278 NOTE: This is NULL if the type wasn't found. */
10279 DW_SIGNATURED_TYPE (attr
) =
10280 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
10283 case DW_FORM_ref_udata
:
10284 DW_ADDR (attr
) = (cu
->header
.offset
10285 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
10286 info_ptr
+= bytes_read
;
10288 case DW_FORM_indirect
:
10289 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10290 info_ptr
+= bytes_read
;
10291 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
10294 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10295 dwarf_form_name (form
),
10296 bfd_get_filename (abfd
));
10299 /* We have seen instances where the compiler tried to emit a byte
10300 size attribute of -1 which ended up being encoded as an unsigned
10301 0xffffffff. Although 0xffffffff is technically a valid size value,
10302 an object of this size seems pretty unlikely so we can relatively
10303 safely treat these cases as if the size attribute was invalid and
10304 treat them as zero by default. */
10305 if (attr
->name
== DW_AT_byte_size
10306 && form
== DW_FORM_data4
10307 && DW_UNSND (attr
) >= 0xffffffff)
10310 (&symfile_complaints
,
10311 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10312 hex_string (DW_UNSND (attr
)));
10313 DW_UNSND (attr
) = 0;
10319 /* Read an attribute described by an abbreviated attribute. */
10322 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10323 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
10325 attr
->name
= abbrev
->name
;
10326 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
10329 /* Read dwarf information from a buffer. */
10331 static unsigned int
10332 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10334 return bfd_get_8 (abfd
, buf
);
10338 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10340 return bfd_get_signed_8 (abfd
, buf
);
10343 static unsigned int
10344 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10346 return bfd_get_16 (abfd
, buf
);
10350 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10352 return bfd_get_signed_16 (abfd
, buf
);
10355 static unsigned int
10356 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10358 return bfd_get_32 (abfd
, buf
);
10362 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10364 return bfd_get_signed_32 (abfd
, buf
);
10368 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10370 return bfd_get_64 (abfd
, buf
);
10374 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10375 unsigned int *bytes_read
)
10377 struct comp_unit_head
*cu_header
= &cu
->header
;
10378 CORE_ADDR retval
= 0;
10380 if (cu_header
->signed_addr_p
)
10382 switch (cu_header
->addr_size
)
10385 retval
= bfd_get_signed_16 (abfd
, buf
);
10388 retval
= bfd_get_signed_32 (abfd
, buf
);
10391 retval
= bfd_get_signed_64 (abfd
, buf
);
10394 internal_error (__FILE__
, __LINE__
,
10395 _("read_address: bad switch, signed [in module %s]"),
10396 bfd_get_filename (abfd
));
10401 switch (cu_header
->addr_size
)
10404 retval
= bfd_get_16 (abfd
, buf
);
10407 retval
= bfd_get_32 (abfd
, buf
);
10410 retval
= bfd_get_64 (abfd
, buf
);
10413 internal_error (__FILE__
, __LINE__
,
10414 _("read_address: bad switch, "
10415 "unsigned [in module %s]"),
10416 bfd_get_filename (abfd
));
10420 *bytes_read
= cu_header
->addr_size
;
10424 /* Read the initial length from a section. The (draft) DWARF 3
10425 specification allows the initial length to take up either 4 bytes
10426 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10427 bytes describe the length and all offsets will be 8 bytes in length
10430 An older, non-standard 64-bit format is also handled by this
10431 function. The older format in question stores the initial length
10432 as an 8-byte quantity without an escape value. Lengths greater
10433 than 2^32 aren't very common which means that the initial 4 bytes
10434 is almost always zero. Since a length value of zero doesn't make
10435 sense for the 32-bit format, this initial zero can be considered to
10436 be an escape value which indicates the presence of the older 64-bit
10437 format. As written, the code can't detect (old format) lengths
10438 greater than 4GB. If it becomes necessary to handle lengths
10439 somewhat larger than 4GB, we could allow other small values (such
10440 as the non-sensical values of 1, 2, and 3) to also be used as
10441 escape values indicating the presence of the old format.
10443 The value returned via bytes_read should be used to increment the
10444 relevant pointer after calling read_initial_length().
10446 [ Note: read_initial_length() and read_offset() are based on the
10447 document entitled "DWARF Debugging Information Format", revision
10448 3, draft 8, dated November 19, 2001. This document was obtained
10451 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10453 This document is only a draft and is subject to change. (So beware.)
10455 Details regarding the older, non-standard 64-bit format were
10456 determined empirically by examining 64-bit ELF files produced by
10457 the SGI toolchain on an IRIX 6.5 machine.
10459 - Kevin, July 16, 2002
10463 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10465 LONGEST length
= bfd_get_32 (abfd
, buf
);
10467 if (length
== 0xffffffff)
10469 length
= bfd_get_64 (abfd
, buf
+ 4);
10472 else if (length
== 0)
10474 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10475 length
= bfd_get_64 (abfd
, buf
);
10486 /* Cover function for read_initial_length.
10487 Returns the length of the object at BUF, and stores the size of the
10488 initial length in *BYTES_READ and stores the size that offsets will be in
10490 If the initial length size is not equivalent to that specified in
10491 CU_HEADER then issue a complaint.
10492 This is useful when reading non-comp-unit headers. */
10495 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10496 const struct comp_unit_head
*cu_header
,
10497 unsigned int *bytes_read
,
10498 unsigned int *offset_size
)
10500 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10502 gdb_assert (cu_header
->initial_length_size
== 4
10503 || cu_header
->initial_length_size
== 8
10504 || cu_header
->initial_length_size
== 12);
10506 if (cu_header
->initial_length_size
!= *bytes_read
)
10507 complaint (&symfile_complaints
,
10508 _("intermixed 32-bit and 64-bit DWARF sections"));
10510 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10514 /* Read an offset from the data stream. The size of the offset is
10515 given by cu_header->offset_size. */
10518 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10519 unsigned int *bytes_read
)
10521 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10523 *bytes_read
= cu_header
->offset_size
;
10527 /* Read an offset from the data stream. */
10530 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10532 LONGEST retval
= 0;
10534 switch (offset_size
)
10537 retval
= bfd_get_32 (abfd
, buf
);
10540 retval
= bfd_get_64 (abfd
, buf
);
10543 internal_error (__FILE__
, __LINE__
,
10544 _("read_offset_1: bad switch [in module %s]"),
10545 bfd_get_filename (abfd
));
10552 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10554 /* If the size of a host char is 8 bits, we can return a pointer
10555 to the buffer, otherwise we have to copy the data to a buffer
10556 allocated on the temporary obstack. */
10557 gdb_assert (HOST_CHAR_BIT
== 8);
10562 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10564 /* If the size of a host char is 8 bits, we can return a pointer
10565 to the string, otherwise we have to copy the string to a buffer
10566 allocated on the temporary obstack. */
10567 gdb_assert (HOST_CHAR_BIT
== 8);
10570 *bytes_read_ptr
= 1;
10573 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10574 return (char *) buf
;
10578 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
10580 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10581 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10582 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10583 bfd_get_filename (abfd
));
10584 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10585 error (_("DW_FORM_strp pointing outside of "
10586 ".debug_str section [in module %s]"),
10587 bfd_get_filename (abfd
));
10588 gdb_assert (HOST_CHAR_BIT
== 8);
10589 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10591 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10595 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10596 const struct comp_unit_head
*cu_header
,
10597 unsigned int *bytes_read_ptr
)
10599 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10601 return read_indirect_string_at_offset (abfd
, str_offset
);
10604 static unsigned long
10605 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10607 unsigned long result
;
10608 unsigned int num_read
;
10610 unsigned char byte
;
10618 byte
= bfd_get_8 (abfd
, buf
);
10621 result
|= ((unsigned long)(byte
& 127) << shift
);
10622 if ((byte
& 128) == 0)
10628 *bytes_read_ptr
= num_read
;
10633 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10636 int i
, shift
, num_read
;
10637 unsigned char byte
;
10645 byte
= bfd_get_8 (abfd
, buf
);
10648 result
|= ((long)(byte
& 127) << shift
);
10650 if ((byte
& 128) == 0)
10655 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10656 result
|= -(((long)1) << shift
);
10657 *bytes_read_ptr
= num_read
;
10661 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10664 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10670 byte
= bfd_get_8 (abfd
, buf
);
10672 if ((byte
& 128) == 0)
10678 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10685 cu
->language
= language_c
;
10687 case DW_LANG_C_plus_plus
:
10688 cu
->language
= language_cplus
;
10691 cu
->language
= language_d
;
10693 case DW_LANG_Fortran77
:
10694 case DW_LANG_Fortran90
:
10695 case DW_LANG_Fortran95
:
10696 cu
->language
= language_fortran
;
10698 case DW_LANG_Mips_Assembler
:
10699 cu
->language
= language_asm
;
10702 cu
->language
= language_java
;
10704 case DW_LANG_Ada83
:
10705 case DW_LANG_Ada95
:
10706 cu
->language
= language_ada
;
10708 case DW_LANG_Modula2
:
10709 cu
->language
= language_m2
;
10711 case DW_LANG_Pascal83
:
10712 cu
->language
= language_pascal
;
10715 cu
->language
= language_objc
;
10717 case DW_LANG_Cobol74
:
10718 case DW_LANG_Cobol85
:
10720 cu
->language
= language_minimal
;
10723 cu
->language_defn
= language_def (cu
->language
);
10726 /* Return the named attribute or NULL if not there. */
10728 static struct attribute
*
10729 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10732 struct attribute
*spec
= NULL
;
10734 for (i
= 0; i
< die
->num_attrs
; ++i
)
10736 if (die
->attrs
[i
].name
== name
)
10737 return &die
->attrs
[i
];
10738 if (die
->attrs
[i
].name
== DW_AT_specification
10739 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10740 spec
= &die
->attrs
[i
];
10745 die
= follow_die_ref (die
, spec
, &cu
);
10746 return dwarf2_attr (die
, name
, cu
);
10752 /* Return the named attribute or NULL if not there,
10753 but do not follow DW_AT_specification, etc.
10754 This is for use in contexts where we're reading .debug_types dies.
10755 Following DW_AT_specification, DW_AT_abstract_origin will take us
10756 back up the chain, and we want to go down. */
10758 static struct attribute
*
10759 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10760 struct dwarf2_cu
*cu
)
10764 for (i
= 0; i
< die
->num_attrs
; ++i
)
10765 if (die
->attrs
[i
].name
== name
)
10766 return &die
->attrs
[i
];
10771 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10772 and holds a non-zero value. This function should only be used for
10773 DW_FORM_flag or DW_FORM_flag_present attributes. */
10776 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10778 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10780 return (attr
&& DW_UNSND (attr
));
10784 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10786 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10787 which value is non-zero. However, we have to be careful with
10788 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10789 (via dwarf2_flag_true_p) follows this attribute. So we may
10790 end up accidently finding a declaration attribute that belongs
10791 to a different DIE referenced by the specification attribute,
10792 even though the given DIE does not have a declaration attribute. */
10793 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10794 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10797 /* Return the die giving the specification for DIE, if there is
10798 one. *SPEC_CU is the CU containing DIE on input, and the CU
10799 containing the return value on output. If there is no
10800 specification, but there is an abstract origin, that is
10803 static struct die_info
*
10804 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10806 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10809 if (spec_attr
== NULL
)
10810 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10812 if (spec_attr
== NULL
)
10815 return follow_die_ref (die
, spec_attr
, spec_cu
);
10818 /* Free the line_header structure *LH, and any arrays and strings it
10820 NOTE: This is also used as a "cleanup" function. */
10823 free_line_header (struct line_header
*lh
)
10825 if (lh
->standard_opcode_lengths
)
10826 xfree (lh
->standard_opcode_lengths
);
10828 /* Remember that all the lh->file_names[i].name pointers are
10829 pointers into debug_line_buffer, and don't need to be freed. */
10830 if (lh
->file_names
)
10831 xfree (lh
->file_names
);
10833 /* Similarly for the include directory names. */
10834 if (lh
->include_dirs
)
10835 xfree (lh
->include_dirs
);
10840 /* Add an entry to LH's include directory table. */
10843 add_include_dir (struct line_header
*lh
, char *include_dir
)
10845 /* Grow the array if necessary. */
10846 if (lh
->include_dirs_size
== 0)
10848 lh
->include_dirs_size
= 1; /* for testing */
10849 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10850 * sizeof (*lh
->include_dirs
));
10852 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10854 lh
->include_dirs_size
*= 2;
10855 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10856 (lh
->include_dirs_size
10857 * sizeof (*lh
->include_dirs
)));
10860 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10863 /* Add an entry to LH's file name table. */
10866 add_file_name (struct line_header
*lh
,
10868 unsigned int dir_index
,
10869 unsigned int mod_time
,
10870 unsigned int length
)
10872 struct file_entry
*fe
;
10874 /* Grow the array if necessary. */
10875 if (lh
->file_names_size
== 0)
10877 lh
->file_names_size
= 1; /* for testing */
10878 lh
->file_names
= xmalloc (lh
->file_names_size
10879 * sizeof (*lh
->file_names
));
10881 else if (lh
->num_file_names
>= lh
->file_names_size
)
10883 lh
->file_names_size
*= 2;
10884 lh
->file_names
= xrealloc (lh
->file_names
,
10885 (lh
->file_names_size
10886 * sizeof (*lh
->file_names
)));
10889 fe
= &lh
->file_names
[lh
->num_file_names
++];
10891 fe
->dir_index
= dir_index
;
10892 fe
->mod_time
= mod_time
;
10893 fe
->length
= length
;
10894 fe
->included_p
= 0;
10898 /* Read the statement program header starting at OFFSET in
10899 .debug_line, according to the endianness of ABFD. Return a pointer
10900 to a struct line_header, allocated using xmalloc.
10902 NOTE: the strings in the include directory and file name tables of
10903 the returned object point into debug_line_buffer, and must not be
10906 static struct line_header
*
10907 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10908 struct dwarf2_cu
*cu
)
10910 struct cleanup
*back_to
;
10911 struct line_header
*lh
;
10912 gdb_byte
*line_ptr
;
10913 unsigned int bytes_read
, offset_size
;
10915 char *cur_dir
, *cur_file
;
10917 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10918 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10920 complaint (&symfile_complaints
, _("missing .debug_line section"));
10924 /* Make sure that at least there's room for the total_length field.
10925 That could be 12 bytes long, but we're just going to fudge that. */
10926 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10928 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10932 lh
= xmalloc (sizeof (*lh
));
10933 memset (lh
, 0, sizeof (*lh
));
10934 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10937 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10939 /* Read in the header. */
10941 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10942 &bytes_read
, &offset_size
);
10943 line_ptr
+= bytes_read
;
10944 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10945 + dwarf2_per_objfile
->line
.size
))
10947 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10950 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10951 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10953 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10954 line_ptr
+= offset_size
;
10955 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10957 if (lh
->version
>= 4)
10959 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10963 lh
->maximum_ops_per_instruction
= 1;
10965 if (lh
->maximum_ops_per_instruction
== 0)
10967 lh
->maximum_ops_per_instruction
= 1;
10968 complaint (&symfile_complaints
,
10969 _("invalid maximum_ops_per_instruction "
10970 "in `.debug_line' section"));
10973 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10975 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10977 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10979 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10981 lh
->standard_opcode_lengths
10982 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10984 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10985 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10987 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10991 /* Read directory table. */
10992 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10994 line_ptr
+= bytes_read
;
10995 add_include_dir (lh
, cur_dir
);
10997 line_ptr
+= bytes_read
;
10999 /* Read file name table. */
11000 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11002 unsigned int dir_index
, mod_time
, length
;
11004 line_ptr
+= bytes_read
;
11005 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11006 line_ptr
+= bytes_read
;
11007 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11008 line_ptr
+= bytes_read
;
11009 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11010 line_ptr
+= bytes_read
;
11012 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11014 line_ptr
+= bytes_read
;
11015 lh
->statement_program_start
= line_ptr
;
11017 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
11018 + dwarf2_per_objfile
->line
.size
))
11019 complaint (&symfile_complaints
,
11020 _("line number info header doesn't "
11021 "fit in `.debug_line' section"));
11023 discard_cleanups (back_to
);
11027 /* Subroutine of dwarf_decode_lines to simplify it.
11028 Return the file name of the psymtab for included file FILE_INDEX
11029 in line header LH of PST.
11030 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11031 If space for the result is malloc'd, it will be freed by a cleanup.
11032 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
11035 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
11036 const struct partial_symtab
*pst
,
11037 const char *comp_dir
)
11039 const struct file_entry fe
= lh
->file_names
[file_index
];
11040 char *include_name
= fe
.name
;
11041 char *include_name_to_compare
= include_name
;
11042 char *dir_name
= NULL
;
11043 const char *pst_filename
;
11044 char *copied_name
= NULL
;
11048 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
11050 if (!IS_ABSOLUTE_PATH (include_name
)
11051 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
11053 /* Avoid creating a duplicate psymtab for PST.
11054 We do this by comparing INCLUDE_NAME and PST_FILENAME.
11055 Before we do the comparison, however, we need to account
11056 for DIR_NAME and COMP_DIR.
11057 First prepend dir_name (if non-NULL). If we still don't
11058 have an absolute path prepend comp_dir (if non-NULL).
11059 However, the directory we record in the include-file's
11060 psymtab does not contain COMP_DIR (to match the
11061 corresponding symtab(s)).
11066 bash$ gcc -g ./hello.c
11067 include_name = "hello.c"
11069 DW_AT_comp_dir = comp_dir = "/tmp"
11070 DW_AT_name = "./hello.c" */
11072 if (dir_name
!= NULL
)
11074 include_name
= concat (dir_name
, SLASH_STRING
,
11075 include_name
, (char *)NULL
);
11076 include_name_to_compare
= include_name
;
11077 make_cleanup (xfree
, include_name
);
11079 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
11081 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
11082 include_name
, (char *)NULL
);
11086 pst_filename
= pst
->filename
;
11087 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
11089 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
11090 pst_filename
, (char *)NULL
);
11091 pst_filename
= copied_name
;
11094 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
11096 if (include_name_to_compare
!= include_name
)
11097 xfree (include_name_to_compare
);
11098 if (copied_name
!= NULL
)
11099 xfree (copied_name
);
11103 return include_name
;
11106 /* Ignore this record_line request. */
11109 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11114 /* Decode the Line Number Program (LNP) for the given line_header
11115 structure and CU. The actual information extracted and the type
11116 of structures created from the LNP depends on the value of PST.
11118 1. If PST is NULL, then this procedure uses the data from the program
11119 to create all necessary symbol tables, and their linetables.
11121 2. If PST is not NULL, this procedure reads the program to determine
11122 the list of files included by the unit represented by PST, and
11123 builds all the associated partial symbol tables.
11125 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11126 It is used for relative paths in the line table.
11127 NOTE: When processing partial symtabs (pst != NULL),
11128 comp_dir == pst->dirname.
11130 NOTE: It is important that psymtabs have the same file name (via strcmp)
11131 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11132 symtab we don't use it in the name of the psymtabs we create.
11133 E.g. expand_line_sal requires this when finding psymtabs to expand.
11134 A good testcase for this is mb-inline.exp. */
11137 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
11138 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
11140 gdb_byte
*line_ptr
, *extended_end
;
11141 gdb_byte
*line_end
;
11142 unsigned int bytes_read
, extended_len
;
11143 unsigned char op_code
, extended_op
, adj_opcode
;
11144 CORE_ADDR baseaddr
;
11145 struct objfile
*objfile
= cu
->objfile
;
11146 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11147 const int decode_for_pst_p
= (pst
!= NULL
);
11148 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
11149 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11152 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11154 line_ptr
= lh
->statement_program_start
;
11155 line_end
= lh
->statement_program_end
;
11157 /* Read the statement sequences until there's nothing left. */
11158 while (line_ptr
< line_end
)
11160 /* state machine registers */
11161 CORE_ADDR address
= 0;
11162 unsigned int file
= 1;
11163 unsigned int line
= 1;
11164 unsigned int column
= 0;
11165 int is_stmt
= lh
->default_is_stmt
;
11166 int basic_block
= 0;
11167 int end_sequence
= 0;
11169 unsigned char op_index
= 0;
11171 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
11173 /* Start a subfile for the current file of the state machine. */
11174 /* lh->include_dirs and lh->file_names are 0-based, but the
11175 directory and file name numbers in the statement program
11177 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11181 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11183 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11186 /* Decode the table. */
11187 while (!end_sequence
)
11189 op_code
= read_1_byte (abfd
, line_ptr
);
11191 if (line_ptr
> line_end
)
11193 dwarf2_debug_line_missing_end_sequence_complaint ();
11197 if (op_code
>= lh
->opcode_base
)
11199 /* Special operand. */
11200 adj_opcode
= op_code
- lh
->opcode_base
;
11201 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
11202 / lh
->maximum_ops_per_instruction
)
11203 * lh
->minimum_instruction_length
);
11204 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
11205 % lh
->maximum_ops_per_instruction
);
11206 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
11207 if (lh
->num_file_names
< file
|| file
== 0)
11208 dwarf2_debug_line_missing_file_complaint ();
11209 /* For now we ignore lines not starting on an
11210 instruction boundary. */
11211 else if (op_index
== 0)
11213 lh
->file_names
[file
- 1].included_p
= 1;
11214 if (!decode_for_pst_p
&& is_stmt
)
11216 if (last_subfile
!= current_subfile
)
11218 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11220 (*p_record_line
) (last_subfile
, 0, addr
);
11221 last_subfile
= current_subfile
;
11223 /* Append row to matrix using current values. */
11224 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11225 (*p_record_line
) (current_subfile
, line
, addr
);
11230 else switch (op_code
)
11232 case DW_LNS_extended_op
:
11233 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
11235 line_ptr
+= bytes_read
;
11236 extended_end
= line_ptr
+ extended_len
;
11237 extended_op
= read_1_byte (abfd
, line_ptr
);
11239 switch (extended_op
)
11241 case DW_LNE_end_sequence
:
11242 p_record_line
= record_line
;
11245 case DW_LNE_set_address
:
11246 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
11248 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11250 /* This line table is for a function which has been
11251 GCd by the linker. Ignore it. PR gdb/12528 */
11254 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
11256 complaint (&symfile_complaints
,
11257 _(".debug_line address at offset 0x%lx is 0 "
11259 line_offset
, objfile
->name
);
11260 p_record_line
= noop_record_line
;
11264 line_ptr
+= bytes_read
;
11265 address
+= baseaddr
;
11267 case DW_LNE_define_file
:
11270 unsigned int dir_index
, mod_time
, length
;
11272 cur_file
= read_direct_string (abfd
, line_ptr
,
11274 line_ptr
+= bytes_read
;
11276 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11277 line_ptr
+= bytes_read
;
11279 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11280 line_ptr
+= bytes_read
;
11282 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11283 line_ptr
+= bytes_read
;
11284 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11287 case DW_LNE_set_discriminator
:
11288 /* The discriminator is not interesting to the debugger;
11290 line_ptr
= extended_end
;
11293 complaint (&symfile_complaints
,
11294 _("mangled .debug_line section"));
11297 /* Make sure that we parsed the extended op correctly. If e.g.
11298 we expected a different address size than the producer used,
11299 we may have read the wrong number of bytes. */
11300 if (line_ptr
!= extended_end
)
11302 complaint (&symfile_complaints
,
11303 _("mangled .debug_line section"));
11308 if (lh
->num_file_names
< file
|| file
== 0)
11309 dwarf2_debug_line_missing_file_complaint ();
11312 lh
->file_names
[file
- 1].included_p
= 1;
11313 if (!decode_for_pst_p
&& is_stmt
)
11315 if (last_subfile
!= current_subfile
)
11317 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11319 (*p_record_line
) (last_subfile
, 0, addr
);
11320 last_subfile
= current_subfile
;
11322 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11323 (*p_record_line
) (current_subfile
, line
, addr
);
11328 case DW_LNS_advance_pc
:
11331 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11333 address
+= (((op_index
+ adjust
)
11334 / lh
->maximum_ops_per_instruction
)
11335 * lh
->minimum_instruction_length
);
11336 op_index
= ((op_index
+ adjust
)
11337 % lh
->maximum_ops_per_instruction
);
11338 line_ptr
+= bytes_read
;
11341 case DW_LNS_advance_line
:
11342 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11343 line_ptr
+= bytes_read
;
11345 case DW_LNS_set_file
:
11347 /* The arrays lh->include_dirs and lh->file_names are
11348 0-based, but the directory and file name numbers in
11349 the statement program are 1-based. */
11350 struct file_entry
*fe
;
11353 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11354 line_ptr
+= bytes_read
;
11355 if (lh
->num_file_names
< file
|| file
== 0)
11356 dwarf2_debug_line_missing_file_complaint ();
11359 fe
= &lh
->file_names
[file
- 1];
11361 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11362 if (!decode_for_pst_p
)
11364 last_subfile
= current_subfile
;
11365 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11370 case DW_LNS_set_column
:
11371 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11372 line_ptr
+= bytes_read
;
11374 case DW_LNS_negate_stmt
:
11375 is_stmt
= (!is_stmt
);
11377 case DW_LNS_set_basic_block
:
11380 /* Add to the address register of the state machine the
11381 address increment value corresponding to special opcode
11382 255. I.e., this value is scaled by the minimum
11383 instruction length since special opcode 255 would have
11384 scaled the increment. */
11385 case DW_LNS_const_add_pc
:
11387 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11389 address
+= (((op_index
+ adjust
)
11390 / lh
->maximum_ops_per_instruction
)
11391 * lh
->minimum_instruction_length
);
11392 op_index
= ((op_index
+ adjust
)
11393 % lh
->maximum_ops_per_instruction
);
11396 case DW_LNS_fixed_advance_pc
:
11397 address
+= read_2_bytes (abfd
, line_ptr
);
11403 /* Unknown standard opcode, ignore it. */
11406 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11408 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11409 line_ptr
+= bytes_read
;
11414 if (lh
->num_file_names
< file
|| file
== 0)
11415 dwarf2_debug_line_missing_file_complaint ();
11418 lh
->file_names
[file
- 1].included_p
= 1;
11419 if (!decode_for_pst_p
)
11421 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11422 (*p_record_line
) (current_subfile
, 0, addr
);
11427 if (decode_for_pst_p
)
11431 /* Now that we're done scanning the Line Header Program, we can
11432 create the psymtab of each included file. */
11433 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11434 if (lh
->file_names
[file_index
].included_p
== 1)
11436 char *include_name
=
11437 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11438 if (include_name
!= NULL
)
11439 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11444 /* Make sure a symtab is created for every file, even files
11445 which contain only variables (i.e. no code with associated
11449 struct file_entry
*fe
;
11451 for (i
= 0; i
< lh
->num_file_names
; i
++)
11455 fe
= &lh
->file_names
[i
];
11457 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11458 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11460 /* Skip the main file; we don't need it, and it must be
11461 allocated last, so that it will show up before the
11462 non-primary symtabs in the objfile's symtab list. */
11463 if (current_subfile
== first_subfile
)
11466 if (current_subfile
->symtab
== NULL
)
11467 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11469 fe
->symtab
= current_subfile
->symtab
;
11474 /* Start a subfile for DWARF. FILENAME is the name of the file and
11475 DIRNAME the name of the source directory which contains FILENAME
11476 or NULL if not known. COMP_DIR is the compilation directory for the
11477 linetable's compilation unit or NULL if not known.
11478 This routine tries to keep line numbers from identical absolute and
11479 relative file names in a common subfile.
11481 Using the `list' example from the GDB testsuite, which resides in
11482 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11483 of /srcdir/list0.c yields the following debugging information for list0.c:
11485 DW_AT_name: /srcdir/list0.c
11486 DW_AT_comp_dir: /compdir
11487 files.files[0].name: list0.h
11488 files.files[0].dir: /srcdir
11489 files.files[1].name: list0.c
11490 files.files[1].dir: /srcdir
11492 The line number information for list0.c has to end up in a single
11493 subfile, so that `break /srcdir/list0.c:1' works as expected.
11494 start_subfile will ensure that this happens provided that we pass the
11495 concatenation of files.files[1].dir and files.files[1].name as the
11499 dwarf2_start_subfile (char *filename
, const char *dirname
,
11500 const char *comp_dir
)
11504 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11505 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11506 second argument to start_subfile. To be consistent, we do the
11507 same here. In order not to lose the line information directory,
11508 we concatenate it to the filename when it makes sense.
11509 Note that the Dwarf3 standard says (speaking of filenames in line
11510 information): ``The directory index is ignored for file names
11511 that represent full path names''. Thus ignoring dirname in the
11512 `else' branch below isn't an issue. */
11514 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11515 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11517 fullname
= filename
;
11519 start_subfile (fullname
, comp_dir
);
11521 if (fullname
!= filename
)
11526 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11527 struct dwarf2_cu
*cu
)
11529 struct objfile
*objfile
= cu
->objfile
;
11530 struct comp_unit_head
*cu_header
= &cu
->header
;
11532 /* NOTE drow/2003-01-30: There used to be a comment and some special
11533 code here to turn a symbol with DW_AT_external and a
11534 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11535 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11536 with some versions of binutils) where shared libraries could have
11537 relocations against symbols in their debug information - the
11538 minimal symbol would have the right address, but the debug info
11539 would not. It's no longer necessary, because we will explicitly
11540 apply relocations when we read in the debug information now. */
11542 /* A DW_AT_location attribute with no contents indicates that a
11543 variable has been optimized away. */
11544 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11546 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11550 /* Handle one degenerate form of location expression specially, to
11551 preserve GDB's previous behavior when section offsets are
11552 specified. If this is just a DW_OP_addr then mark this symbol
11555 if (attr_form_is_block (attr
)
11556 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11557 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11559 unsigned int dummy
;
11561 SYMBOL_VALUE_ADDRESS (sym
) =
11562 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11563 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11564 fixup_symbol_section (sym
, objfile
);
11565 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11566 SYMBOL_SECTION (sym
));
11570 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11571 expression evaluator, and use LOC_COMPUTED only when necessary
11572 (i.e. when the value of a register or memory location is
11573 referenced, or a thread-local block, etc.). Then again, it might
11574 not be worthwhile. I'm assuming that it isn't unless performance
11575 or memory numbers show me otherwise. */
11577 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11578 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11580 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11581 cu
->has_loclist
= 1;
11584 /* Given a pointer to a DWARF information entry, figure out if we need
11585 to make a symbol table entry for it, and if so, create a new entry
11586 and return a pointer to it.
11587 If TYPE is NULL, determine symbol type from the die, otherwise
11588 used the passed type.
11589 If SPACE is not NULL, use it to hold the new symbol. If it is
11590 NULL, allocate a new symbol on the objfile's obstack. */
11592 static struct symbol
*
11593 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11594 struct symbol
*space
)
11596 struct objfile
*objfile
= cu
->objfile
;
11597 struct symbol
*sym
= NULL
;
11599 struct attribute
*attr
= NULL
;
11600 struct attribute
*attr2
= NULL
;
11601 CORE_ADDR baseaddr
;
11602 struct pending
**list_to_add
= NULL
;
11604 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11606 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11608 name
= dwarf2_name (die
, cu
);
11611 const char *linkagename
;
11612 int suppress_add
= 0;
11617 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11618 OBJSTAT (objfile
, n_syms
++);
11620 /* Cache this symbol's name and the name's demangled form (if any). */
11621 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11622 linkagename
= dwarf2_physname (name
, die
, cu
);
11623 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11625 /* Fortran does not have mangling standard and the mangling does differ
11626 between gfortran, iFort etc. */
11627 if (cu
->language
== language_fortran
11628 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11629 symbol_set_demangled_name (&(sym
->ginfo
),
11630 (char *) dwarf2_full_name (name
, die
, cu
),
11633 /* Default assumptions.
11634 Use the passed type or decode it from the die. */
11635 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11636 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11638 SYMBOL_TYPE (sym
) = type
;
11640 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11641 attr
= dwarf2_attr (die
,
11642 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11646 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11649 attr
= dwarf2_attr (die
,
11650 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11654 int file_index
= DW_UNSND (attr
);
11656 if (cu
->line_header
== NULL
11657 || file_index
> cu
->line_header
->num_file_names
)
11658 complaint (&symfile_complaints
,
11659 _("file index out of range"));
11660 else if (file_index
> 0)
11662 struct file_entry
*fe
;
11664 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11665 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11672 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11675 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11677 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11678 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11679 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11680 add_symbol_to_list (sym
, cu
->list_in_scope
);
11682 case DW_TAG_subprogram
:
11683 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11685 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11686 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11687 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11688 || cu
->language
== language_ada
)
11690 /* Subprograms marked external are stored as a global symbol.
11691 Ada subprograms, whether marked external or not, are always
11692 stored as a global symbol, because we want to be able to
11693 access them globally. For instance, we want to be able
11694 to break on a nested subprogram without having to
11695 specify the context. */
11696 list_to_add
= &global_symbols
;
11700 list_to_add
= cu
->list_in_scope
;
11703 case DW_TAG_inlined_subroutine
:
11704 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11706 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11707 SYMBOL_INLINED (sym
) = 1;
11708 /* Do not add the symbol to any lists. It will be found via
11709 BLOCK_FUNCTION from the blockvector. */
11711 case DW_TAG_template_value_param
:
11713 /* Fall through. */
11714 case DW_TAG_constant
:
11715 case DW_TAG_variable
:
11716 case DW_TAG_member
:
11717 /* Compilation with minimal debug info may result in
11718 variables with missing type entries. Change the
11719 misleading `void' type to something sensible. */
11720 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11722 = objfile_type (objfile
)->nodebug_data_symbol
;
11724 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11725 /* In the case of DW_TAG_member, we should only be called for
11726 static const members. */
11727 if (die
->tag
== DW_TAG_member
)
11729 /* dwarf2_add_field uses die_is_declaration,
11730 so we do the same. */
11731 gdb_assert (die_is_declaration (die
, cu
));
11736 dwarf2_const_value (attr
, sym
, cu
);
11737 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11740 if (attr2
&& (DW_UNSND (attr2
) != 0))
11741 list_to_add
= &global_symbols
;
11743 list_to_add
= cu
->list_in_scope
;
11747 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11750 var_decode_location (attr
, sym
, cu
);
11751 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11752 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11753 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11754 && !dwarf2_per_objfile
->has_section_at_zero
)
11756 /* When a static variable is eliminated by the linker,
11757 the corresponding debug information is not stripped
11758 out, but the variable address is set to null;
11759 do not add such variables into symbol table. */
11761 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11763 /* Workaround gfortran PR debug/40040 - it uses
11764 DW_AT_location for variables in -fPIC libraries which may
11765 get overriden by other libraries/executable and get
11766 a different address. Resolve it by the minimal symbol
11767 which may come from inferior's executable using copy
11768 relocation. Make this workaround only for gfortran as for
11769 other compilers GDB cannot guess the minimal symbol
11770 Fortran mangling kind. */
11771 if (cu
->language
== language_fortran
&& die
->parent
11772 && die
->parent
->tag
== DW_TAG_module
11774 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11775 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11777 /* A variable with DW_AT_external is never static,
11778 but it may be block-scoped. */
11779 list_to_add
= (cu
->list_in_scope
== &file_symbols
11780 ? &global_symbols
: cu
->list_in_scope
);
11783 list_to_add
= cu
->list_in_scope
;
11787 /* We do not know the address of this symbol.
11788 If it is an external symbol and we have type information
11789 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11790 The address of the variable will then be determined from
11791 the minimal symbol table whenever the variable is
11793 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11794 if (attr2
&& (DW_UNSND (attr2
) != 0)
11795 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11797 /* A variable with DW_AT_external is never static, but it
11798 may be block-scoped. */
11799 list_to_add
= (cu
->list_in_scope
== &file_symbols
11800 ? &global_symbols
: cu
->list_in_scope
);
11802 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11804 else if (!die_is_declaration (die
, cu
))
11806 /* Use the default LOC_OPTIMIZED_OUT class. */
11807 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11809 list_to_add
= cu
->list_in_scope
;
11813 case DW_TAG_formal_parameter
:
11814 /* If we are inside a function, mark this as an argument. If
11815 not, we might be looking at an argument to an inlined function
11816 when we do not have enough information to show inlined frames;
11817 pretend it's a local variable in that case so that the user can
11819 if (context_stack_depth
> 0
11820 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11821 SYMBOL_IS_ARGUMENT (sym
) = 1;
11822 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11825 var_decode_location (attr
, sym
, cu
);
11827 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11830 dwarf2_const_value (attr
, sym
, cu
);
11833 list_to_add
= cu
->list_in_scope
;
11835 case DW_TAG_unspecified_parameters
:
11836 /* From varargs functions; gdb doesn't seem to have any
11837 interest in this information, so just ignore it for now.
11840 case DW_TAG_template_type_param
:
11842 /* Fall through. */
11843 case DW_TAG_class_type
:
11844 case DW_TAG_interface_type
:
11845 case DW_TAG_structure_type
:
11846 case DW_TAG_union_type
:
11847 case DW_TAG_set_type
:
11848 case DW_TAG_enumeration_type
:
11849 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11850 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11853 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11854 really ever be static objects: otherwise, if you try
11855 to, say, break of a class's method and you're in a file
11856 which doesn't mention that class, it won't work unless
11857 the check for all static symbols in lookup_symbol_aux
11858 saves you. See the OtherFileClass tests in
11859 gdb.c++/namespace.exp. */
11863 list_to_add
= (cu
->list_in_scope
== &file_symbols
11864 && (cu
->language
== language_cplus
11865 || cu
->language
== language_java
)
11866 ? &global_symbols
: cu
->list_in_scope
);
11868 /* The semantics of C++ state that "struct foo {
11869 ... }" also defines a typedef for "foo". A Java
11870 class declaration also defines a typedef for the
11872 if (cu
->language
== language_cplus
11873 || cu
->language
== language_java
11874 || cu
->language
== language_ada
)
11876 /* The symbol's name is already allocated along
11877 with this objfile, so we don't need to
11878 duplicate it for the type. */
11879 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11880 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11885 case DW_TAG_typedef
:
11886 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11887 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11888 list_to_add
= cu
->list_in_scope
;
11890 case DW_TAG_base_type
:
11891 case DW_TAG_subrange_type
:
11892 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11893 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11894 list_to_add
= cu
->list_in_scope
;
11896 case DW_TAG_enumerator
:
11897 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11900 dwarf2_const_value (attr
, sym
, cu
);
11903 /* NOTE: carlton/2003-11-10: See comment above in the
11904 DW_TAG_class_type, etc. block. */
11906 list_to_add
= (cu
->list_in_scope
== &file_symbols
11907 && (cu
->language
== language_cplus
11908 || cu
->language
== language_java
)
11909 ? &global_symbols
: cu
->list_in_scope
);
11912 case DW_TAG_namespace
:
11913 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11914 list_to_add
= &global_symbols
;
11917 /* Not a tag we recognize. Hopefully we aren't processing
11918 trash data, but since we must specifically ignore things
11919 we don't recognize, there is nothing else we should do at
11921 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11922 dwarf_tag_name (die
->tag
));
11928 sym
->hash_next
= objfile
->template_symbols
;
11929 objfile
->template_symbols
= sym
;
11930 list_to_add
= NULL
;
11933 if (list_to_add
!= NULL
)
11934 add_symbol_to_list (sym
, list_to_add
);
11936 /* For the benefit of old versions of GCC, check for anonymous
11937 namespaces based on the demangled name. */
11938 if (!processing_has_namespace_info
11939 && cu
->language
== language_cplus
)
11940 cp_scan_for_anonymous_namespaces (sym
, objfile
);
11945 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11947 static struct symbol
*
11948 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11950 return new_symbol_full (die
, type
, cu
, NULL
);
11953 /* Given an attr with a DW_FORM_dataN value in host byte order,
11954 zero-extend it as appropriate for the symbol's type. The DWARF
11955 standard (v4) is not entirely clear about the meaning of using
11956 DW_FORM_dataN for a constant with a signed type, where the type is
11957 wider than the data. The conclusion of a discussion on the DWARF
11958 list was that this is unspecified. We choose to always zero-extend
11959 because that is the interpretation long in use by GCC. */
11962 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11963 const char *name
, struct obstack
*obstack
,
11964 struct dwarf2_cu
*cu
, long *value
, int bits
)
11966 struct objfile
*objfile
= cu
->objfile
;
11967 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11968 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11969 LONGEST l
= DW_UNSND (attr
);
11971 if (bits
< sizeof (*value
) * 8)
11973 l
&= ((LONGEST
) 1 << bits
) - 1;
11976 else if (bits
== sizeof (*value
) * 8)
11980 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11981 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11988 /* Read a constant value from an attribute. Either set *VALUE, or if
11989 the value does not fit in *VALUE, set *BYTES - either already
11990 allocated on the objfile obstack, or newly allocated on OBSTACK,
11991 or, set *BATON, if we translated the constant to a location
11995 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11996 const char *name
, struct obstack
*obstack
,
11997 struct dwarf2_cu
*cu
,
11998 long *value
, gdb_byte
**bytes
,
11999 struct dwarf2_locexpr_baton
**baton
)
12001 struct objfile
*objfile
= cu
->objfile
;
12002 struct comp_unit_head
*cu_header
= &cu
->header
;
12003 struct dwarf_block
*blk
;
12004 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
12005 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
12011 switch (attr
->form
)
12017 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
12018 dwarf2_const_value_length_mismatch_complaint (name
,
12019 cu_header
->addr_size
,
12020 TYPE_LENGTH (type
));
12021 /* Symbols of this form are reasonably rare, so we just
12022 piggyback on the existing location code rather than writing
12023 a new implementation of symbol_computed_ops. */
12024 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
12025 sizeof (struct dwarf2_locexpr_baton
));
12026 (*baton
)->per_cu
= cu
->per_cu
;
12027 gdb_assert ((*baton
)->per_cu
);
12029 (*baton
)->size
= 2 + cu_header
->addr_size
;
12030 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
12031 (*baton
)->data
= data
;
12033 data
[0] = DW_OP_addr
;
12034 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
12035 byte_order
, DW_ADDR (attr
));
12036 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
12039 case DW_FORM_string
:
12041 /* DW_STRING is already allocated on the objfile obstack, point
12043 *bytes
= (gdb_byte
*) DW_STRING (attr
);
12045 case DW_FORM_block1
:
12046 case DW_FORM_block2
:
12047 case DW_FORM_block4
:
12048 case DW_FORM_block
:
12049 case DW_FORM_exprloc
:
12050 blk
= DW_BLOCK (attr
);
12051 if (TYPE_LENGTH (type
) != blk
->size
)
12052 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
12053 TYPE_LENGTH (type
));
12054 *bytes
= blk
->data
;
12057 /* The DW_AT_const_value attributes are supposed to carry the
12058 symbol's value "represented as it would be on the target
12059 architecture." By the time we get here, it's already been
12060 converted to host endianness, so we just need to sign- or
12061 zero-extend it as appropriate. */
12062 case DW_FORM_data1
:
12063 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12064 obstack
, cu
, value
, 8);
12066 case DW_FORM_data2
:
12067 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12068 obstack
, cu
, value
, 16);
12070 case DW_FORM_data4
:
12071 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12072 obstack
, cu
, value
, 32);
12074 case DW_FORM_data8
:
12075 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12076 obstack
, cu
, value
, 64);
12079 case DW_FORM_sdata
:
12080 *value
= DW_SND (attr
);
12083 case DW_FORM_udata
:
12084 *value
= DW_UNSND (attr
);
12088 complaint (&symfile_complaints
,
12089 _("unsupported const value attribute form: '%s'"),
12090 dwarf_form_name (attr
->form
));
12097 /* Copy constant value from an attribute to a symbol. */
12100 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
12101 struct dwarf2_cu
*cu
)
12103 struct objfile
*objfile
= cu
->objfile
;
12104 struct comp_unit_head
*cu_header
= &cu
->header
;
12107 struct dwarf2_locexpr_baton
*baton
;
12109 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
12110 SYMBOL_PRINT_NAME (sym
),
12111 &objfile
->objfile_obstack
, cu
,
12112 &value
, &bytes
, &baton
);
12116 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
12117 SYMBOL_LOCATION_BATON (sym
) = baton
;
12118 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
12120 else if (bytes
!= NULL
)
12122 SYMBOL_VALUE_BYTES (sym
) = bytes
;
12123 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
12127 SYMBOL_VALUE (sym
) = value
;
12128 SYMBOL_CLASS (sym
) = LOC_CONST
;
12132 /* Return the type of the die in question using its DW_AT_type attribute. */
12134 static struct type
*
12135 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12137 struct attribute
*type_attr
;
12139 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
12142 /* A missing DW_AT_type represents a void type. */
12143 return objfile_type (cu
->objfile
)->builtin_void
;
12146 return lookup_die_type (die
, type_attr
, cu
);
12149 /* True iff CU's producer generates GNAT Ada auxiliary information
12150 that allows to find parallel types through that information instead
12151 of having to do expensive parallel lookups by type name. */
12154 need_gnat_info (struct dwarf2_cu
*cu
)
12156 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12157 of GNAT produces this auxiliary information, without any indication
12158 that it is produced. Part of enhancing the FSF version of GNAT
12159 to produce that information will be to put in place an indicator
12160 that we can use in order to determine whether the descriptive type
12161 info is available or not. One suggestion that has been made is
12162 to use a new attribute, attached to the CU die. For now, assume
12163 that the descriptive type info is not available. */
12167 /* Return the auxiliary type of the die in question using its
12168 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12169 attribute is not present. */
12171 static struct type
*
12172 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12174 struct attribute
*type_attr
;
12176 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
12180 return lookup_die_type (die
, type_attr
, cu
);
12183 /* If DIE has a descriptive_type attribute, then set the TYPE's
12184 descriptive type accordingly. */
12187 set_descriptive_type (struct type
*type
, struct die_info
*die
,
12188 struct dwarf2_cu
*cu
)
12190 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
12192 if (descriptive_type
)
12194 ALLOCATE_GNAT_AUX_TYPE (type
);
12195 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
12199 /* Return the containing type of the die in question using its
12200 DW_AT_containing_type attribute. */
12202 static struct type
*
12203 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12205 struct attribute
*type_attr
;
12207 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
12209 error (_("Dwarf Error: Problem turning containing type into gdb type "
12210 "[in module %s]"), cu
->objfile
->name
);
12212 return lookup_die_type (die
, type_attr
, cu
);
12215 /* Look up the type of DIE in CU using its type attribute ATTR.
12216 If there is no type substitute an error marker. */
12218 static struct type
*
12219 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
12220 struct dwarf2_cu
*cu
)
12222 struct objfile
*objfile
= cu
->objfile
;
12223 struct type
*this_type
;
12225 /* First see if we have it cached. */
12227 if (is_ref_attr (attr
))
12229 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
12231 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
12233 else if (attr
->form
== DW_FORM_ref_sig8
)
12235 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12236 struct dwarf2_cu
*sig_cu
;
12237 unsigned int offset
;
12239 /* sig_type will be NULL if the signatured type is missing from
12241 if (sig_type
== NULL
)
12242 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12243 "at 0x%x [in module %s]"),
12244 die
->offset
, objfile
->name
);
12246 gdb_assert (sig_type
->per_cu
.debug_types_section
);
12247 offset
= sig_type
->per_cu
.offset
+ sig_type
->type_offset
;
12248 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
12252 dump_die_for_error (die
);
12253 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12254 dwarf_attr_name (attr
->name
), objfile
->name
);
12257 /* If not cached we need to read it in. */
12259 if (this_type
== NULL
)
12261 struct die_info
*type_die
;
12262 struct dwarf2_cu
*type_cu
= cu
;
12264 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
12265 /* If the type is cached, we should have found it above. */
12266 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
12267 this_type
= read_type_die_1 (type_die
, type_cu
);
12270 /* If we still don't have a type use an error marker. */
12272 if (this_type
== NULL
)
12274 char *message
, *saved
;
12276 /* read_type_die already issued a complaint. */
12277 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12281 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
12282 message
, strlen (message
));
12285 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
12291 /* Return the type in DIE, CU.
12292 Returns NULL for invalid types.
12294 This first does a lookup in the appropriate type_hash table,
12295 and only reads the die in if necessary.
12297 NOTE: This can be called when reading in partial or full symbols. */
12299 static struct type
*
12300 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12302 struct type
*this_type
;
12304 this_type
= get_die_type (die
, cu
);
12308 return read_type_die_1 (die
, cu
);
12311 /* Read the type in DIE, CU.
12312 Returns NULL for invalid types. */
12314 static struct type
*
12315 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12317 struct type
*this_type
= NULL
;
12321 case DW_TAG_class_type
:
12322 case DW_TAG_interface_type
:
12323 case DW_TAG_structure_type
:
12324 case DW_TAG_union_type
:
12325 this_type
= read_structure_type (die
, cu
);
12327 case DW_TAG_enumeration_type
:
12328 this_type
= read_enumeration_type (die
, cu
);
12330 case DW_TAG_subprogram
:
12331 case DW_TAG_subroutine_type
:
12332 case DW_TAG_inlined_subroutine
:
12333 this_type
= read_subroutine_type (die
, cu
);
12335 case DW_TAG_array_type
:
12336 this_type
= read_array_type (die
, cu
);
12338 case DW_TAG_set_type
:
12339 this_type
= read_set_type (die
, cu
);
12341 case DW_TAG_pointer_type
:
12342 this_type
= read_tag_pointer_type (die
, cu
);
12344 case DW_TAG_ptr_to_member_type
:
12345 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12347 case DW_TAG_reference_type
:
12348 this_type
= read_tag_reference_type (die
, cu
);
12350 case DW_TAG_const_type
:
12351 this_type
= read_tag_const_type (die
, cu
);
12353 case DW_TAG_volatile_type
:
12354 this_type
= read_tag_volatile_type (die
, cu
);
12356 case DW_TAG_string_type
:
12357 this_type
= read_tag_string_type (die
, cu
);
12359 case DW_TAG_typedef
:
12360 this_type
= read_typedef (die
, cu
);
12362 case DW_TAG_subrange_type
:
12363 this_type
= read_subrange_type (die
, cu
);
12365 case DW_TAG_base_type
:
12366 this_type
= read_base_type (die
, cu
);
12368 case DW_TAG_unspecified_type
:
12369 this_type
= read_unspecified_type (die
, cu
);
12371 case DW_TAG_namespace
:
12372 this_type
= read_namespace_type (die
, cu
);
12374 case DW_TAG_module
:
12375 this_type
= read_module_type (die
, cu
);
12378 complaint (&symfile_complaints
,
12379 _("unexpected tag in read_type_die: '%s'"),
12380 dwarf_tag_name (die
->tag
));
12387 /* See if we can figure out if the class lives in a namespace. We do
12388 this by looking for a member function; its demangled name will
12389 contain namespace info, if there is any.
12390 Return the computed name or NULL.
12391 Space for the result is allocated on the objfile's obstack.
12392 This is the full-die version of guess_partial_die_structure_name.
12393 In this case we know DIE has no useful parent. */
12396 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12398 struct die_info
*spec_die
;
12399 struct dwarf2_cu
*spec_cu
;
12400 struct die_info
*child
;
12403 spec_die
= die_specification (die
, &spec_cu
);
12404 if (spec_die
!= NULL
)
12410 for (child
= die
->child
;
12412 child
= child
->sibling
)
12414 if (child
->tag
== DW_TAG_subprogram
)
12416 struct attribute
*attr
;
12418 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12420 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12424 = language_class_name_from_physname (cu
->language_defn
,
12428 if (actual_name
!= NULL
)
12430 char *die_name
= dwarf2_name (die
, cu
);
12432 if (die_name
!= NULL
12433 && strcmp (die_name
, actual_name
) != 0)
12435 /* Strip off the class name from the full name.
12436 We want the prefix. */
12437 int die_name_len
= strlen (die_name
);
12438 int actual_name_len
= strlen (actual_name
);
12440 /* Test for '::' as a sanity check. */
12441 if (actual_name_len
> die_name_len
+ 2
12442 && actual_name
[actual_name_len
12443 - die_name_len
- 1] == ':')
12445 obsavestring (actual_name
,
12446 actual_name_len
- die_name_len
- 2,
12447 &cu
->objfile
->objfile_obstack
);
12450 xfree (actual_name
);
12459 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12460 prefix part in such case. See
12461 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12464 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12466 struct attribute
*attr
;
12469 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
12470 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
12473 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12474 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
12477 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12479 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12480 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12483 /* dwarf2_name had to be already called. */
12484 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
12486 /* Strip the base name, keep any leading namespaces/classes. */
12487 base
= strrchr (DW_STRING (attr
), ':');
12488 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
12491 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
12492 &cu
->objfile
->objfile_obstack
);
12495 /* Return the name of the namespace/class that DIE is defined within,
12496 or "" if we can't tell. The caller should not xfree the result.
12498 For example, if we're within the method foo() in the following
12508 then determine_prefix on foo's die will return "N::C". */
12511 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12513 struct die_info
*parent
, *spec_die
;
12514 struct dwarf2_cu
*spec_cu
;
12515 struct type
*parent_type
;
12518 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12519 && cu
->language
!= language_fortran
)
12522 retval
= anonymous_struct_prefix (die
, cu
);
12526 /* We have to be careful in the presence of DW_AT_specification.
12527 For example, with GCC 3.4, given the code
12531 // Definition of N::foo.
12535 then we'll have a tree of DIEs like this:
12537 1: DW_TAG_compile_unit
12538 2: DW_TAG_namespace // N
12539 3: DW_TAG_subprogram // declaration of N::foo
12540 4: DW_TAG_subprogram // definition of N::foo
12541 DW_AT_specification // refers to die #3
12543 Thus, when processing die #4, we have to pretend that we're in
12544 the context of its DW_AT_specification, namely the contex of die
12547 spec_die
= die_specification (die
, &spec_cu
);
12548 if (spec_die
== NULL
)
12549 parent
= die
->parent
;
12552 parent
= spec_die
->parent
;
12556 if (parent
== NULL
)
12558 else if (parent
->building_fullname
)
12561 const char *parent_name
;
12563 /* It has been seen on RealView 2.2 built binaries,
12564 DW_TAG_template_type_param types actually _defined_ as
12565 children of the parent class:
12568 template class <class Enum> Class{};
12569 Class<enum E> class_e;
12571 1: DW_TAG_class_type (Class)
12572 2: DW_TAG_enumeration_type (E)
12573 3: DW_TAG_enumerator (enum1:0)
12574 3: DW_TAG_enumerator (enum2:1)
12576 2: DW_TAG_template_type_param
12577 DW_AT_type DW_FORM_ref_udata (E)
12579 Besides being broken debug info, it can put GDB into an
12580 infinite loop. Consider:
12582 When we're building the full name for Class<E>, we'll start
12583 at Class, and go look over its template type parameters,
12584 finding E. We'll then try to build the full name of E, and
12585 reach here. We're now trying to build the full name of E,
12586 and look over the parent DIE for containing scope. In the
12587 broken case, if we followed the parent DIE of E, we'd again
12588 find Class, and once again go look at its template type
12589 arguments, etc., etc. Simply don't consider such parent die
12590 as source-level parent of this die (it can't be, the language
12591 doesn't allow it), and break the loop here. */
12592 name
= dwarf2_name (die
, cu
);
12593 parent_name
= dwarf2_name (parent
, cu
);
12594 complaint (&symfile_complaints
,
12595 _("template param type '%s' defined within parent '%s'"),
12596 name
? name
: "<unknown>",
12597 parent_name
? parent_name
: "<unknown>");
12601 switch (parent
->tag
)
12603 case DW_TAG_namespace
:
12604 parent_type
= read_type_die (parent
, cu
);
12605 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12606 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12607 Work around this problem here. */
12608 if (cu
->language
== language_cplus
12609 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12611 /* We give a name to even anonymous namespaces. */
12612 return TYPE_TAG_NAME (parent_type
);
12613 case DW_TAG_class_type
:
12614 case DW_TAG_interface_type
:
12615 case DW_TAG_structure_type
:
12616 case DW_TAG_union_type
:
12617 case DW_TAG_module
:
12618 parent_type
= read_type_die (parent
, cu
);
12619 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12620 return TYPE_TAG_NAME (parent_type
);
12622 /* An anonymous structure is only allowed non-static data
12623 members; no typedefs, no member functions, et cetera.
12624 So it does not need a prefix. */
12626 case DW_TAG_compile_unit
:
12627 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12628 if (cu
->language
== language_cplus
12629 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12630 && die
->child
!= NULL
12631 && (die
->tag
== DW_TAG_class_type
12632 || die
->tag
== DW_TAG_structure_type
12633 || die
->tag
== DW_TAG_union_type
))
12635 char *name
= guess_full_die_structure_name (die
, cu
);
12641 return determine_prefix (parent
, cu
);
12645 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12646 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12647 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12648 an obconcat, otherwise allocate storage for the result. The CU argument is
12649 used to determine the language and hence, the appropriate separator. */
12651 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12654 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12655 int physname
, struct dwarf2_cu
*cu
)
12657 const char *lead
= "";
12660 if (suffix
== NULL
|| suffix
[0] == '\0'
12661 || prefix
== NULL
|| prefix
[0] == '\0')
12663 else if (cu
->language
== language_java
)
12665 else if (cu
->language
== language_fortran
&& physname
)
12667 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12668 DW_AT_MIPS_linkage_name is preferred and used instead. */
12676 if (prefix
== NULL
)
12678 if (suffix
== NULL
)
12684 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12686 strcpy (retval
, lead
);
12687 strcat (retval
, prefix
);
12688 strcat (retval
, sep
);
12689 strcat (retval
, suffix
);
12694 /* We have an obstack. */
12695 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12699 /* Return sibling of die, NULL if no sibling. */
12701 static struct die_info
*
12702 sibling_die (struct die_info
*die
)
12704 return die
->sibling
;
12707 /* Get name of a die, return NULL if not found. */
12710 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12711 struct obstack
*obstack
)
12713 if (name
&& cu
->language
== language_cplus
)
12715 char *canon_name
= cp_canonicalize_string (name
);
12717 if (canon_name
!= NULL
)
12719 if (strcmp (canon_name
, name
) != 0)
12720 name
= obsavestring (canon_name
, strlen (canon_name
),
12722 xfree (canon_name
);
12729 /* Get name of a die, return NULL if not found. */
12732 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12734 struct attribute
*attr
;
12736 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12737 if ((!attr
|| !DW_STRING (attr
))
12738 && die
->tag
!= DW_TAG_class_type
12739 && die
->tag
!= DW_TAG_interface_type
12740 && die
->tag
!= DW_TAG_structure_type
12741 && die
->tag
!= DW_TAG_union_type
)
12746 case DW_TAG_compile_unit
:
12747 /* Compilation units have a DW_AT_name that is a filename, not
12748 a source language identifier. */
12749 case DW_TAG_enumeration_type
:
12750 case DW_TAG_enumerator
:
12751 /* These tags always have simple identifiers already; no need
12752 to canonicalize them. */
12753 return DW_STRING (attr
);
12755 case DW_TAG_subprogram
:
12756 /* Java constructors will all be named "<init>", so return
12757 the class name when we see this special case. */
12758 if (cu
->language
== language_java
12759 && DW_STRING (attr
) != NULL
12760 && strcmp (DW_STRING (attr
), "<init>") == 0)
12762 struct dwarf2_cu
*spec_cu
= cu
;
12763 struct die_info
*spec_die
;
12765 /* GCJ will output '<init>' for Java constructor names.
12766 For this special case, return the name of the parent class. */
12768 /* GCJ may output suprogram DIEs with AT_specification set.
12769 If so, use the name of the specified DIE. */
12770 spec_die
= die_specification (die
, &spec_cu
);
12771 if (spec_die
!= NULL
)
12772 return dwarf2_name (spec_die
, spec_cu
);
12777 if (die
->tag
== DW_TAG_class_type
)
12778 return dwarf2_name (die
, cu
);
12780 while (die
->tag
!= DW_TAG_compile_unit
);
12784 case DW_TAG_class_type
:
12785 case DW_TAG_interface_type
:
12786 case DW_TAG_structure_type
:
12787 case DW_TAG_union_type
:
12788 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12789 structures or unions. These were of the form "._%d" in GCC 4.1,
12790 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12791 and GCC 4.4. We work around this problem by ignoring these. */
12792 if (attr
&& DW_STRING (attr
)
12793 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12794 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12797 /* GCC might emit a nameless typedef that has a linkage name. See
12798 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12799 if (!attr
|| DW_STRING (attr
) == NULL
)
12801 char *demangled
= NULL
;
12803 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12805 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12807 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12810 /* Avoid demangling DW_STRING (attr) the second time on a second
12811 call for the same DIE. */
12812 if (!DW_STRING_IS_CANONICAL (attr
))
12813 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12819 /* FIXME: we already did this for the partial symbol... */
12820 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
12821 &cu
->objfile
->objfile_obstack
);
12822 DW_STRING_IS_CANONICAL (attr
) = 1;
12825 /* Strip any leading namespaces/classes, keep only the base name.
12826 DW_AT_name for named DIEs does not contain the prefixes. */
12827 base
= strrchr (DW_STRING (attr
), ':');
12828 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
12831 return DW_STRING (attr
);
12840 if (!DW_STRING_IS_CANONICAL (attr
))
12843 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12844 &cu
->objfile
->objfile_obstack
);
12845 DW_STRING_IS_CANONICAL (attr
) = 1;
12847 return DW_STRING (attr
);
12850 /* Return the die that this die in an extension of, or NULL if there
12851 is none. *EXT_CU is the CU containing DIE on input, and the CU
12852 containing the return value on output. */
12854 static struct die_info
*
12855 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12857 struct attribute
*attr
;
12859 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12863 return follow_die_ref (die
, attr
, ext_cu
);
12866 /* Convert a DIE tag into its string name. */
12869 dwarf_tag_name (unsigned tag
)
12873 case DW_TAG_padding
:
12874 return "DW_TAG_padding";
12875 case DW_TAG_array_type
:
12876 return "DW_TAG_array_type";
12877 case DW_TAG_class_type
:
12878 return "DW_TAG_class_type";
12879 case DW_TAG_entry_point
:
12880 return "DW_TAG_entry_point";
12881 case DW_TAG_enumeration_type
:
12882 return "DW_TAG_enumeration_type";
12883 case DW_TAG_formal_parameter
:
12884 return "DW_TAG_formal_parameter";
12885 case DW_TAG_imported_declaration
:
12886 return "DW_TAG_imported_declaration";
12888 return "DW_TAG_label";
12889 case DW_TAG_lexical_block
:
12890 return "DW_TAG_lexical_block";
12891 case DW_TAG_member
:
12892 return "DW_TAG_member";
12893 case DW_TAG_pointer_type
:
12894 return "DW_TAG_pointer_type";
12895 case DW_TAG_reference_type
:
12896 return "DW_TAG_reference_type";
12897 case DW_TAG_compile_unit
:
12898 return "DW_TAG_compile_unit";
12899 case DW_TAG_string_type
:
12900 return "DW_TAG_string_type";
12901 case DW_TAG_structure_type
:
12902 return "DW_TAG_structure_type";
12903 case DW_TAG_subroutine_type
:
12904 return "DW_TAG_subroutine_type";
12905 case DW_TAG_typedef
:
12906 return "DW_TAG_typedef";
12907 case DW_TAG_union_type
:
12908 return "DW_TAG_union_type";
12909 case DW_TAG_unspecified_parameters
:
12910 return "DW_TAG_unspecified_parameters";
12911 case DW_TAG_variant
:
12912 return "DW_TAG_variant";
12913 case DW_TAG_common_block
:
12914 return "DW_TAG_common_block";
12915 case DW_TAG_common_inclusion
:
12916 return "DW_TAG_common_inclusion";
12917 case DW_TAG_inheritance
:
12918 return "DW_TAG_inheritance";
12919 case DW_TAG_inlined_subroutine
:
12920 return "DW_TAG_inlined_subroutine";
12921 case DW_TAG_module
:
12922 return "DW_TAG_module";
12923 case DW_TAG_ptr_to_member_type
:
12924 return "DW_TAG_ptr_to_member_type";
12925 case DW_TAG_set_type
:
12926 return "DW_TAG_set_type";
12927 case DW_TAG_subrange_type
:
12928 return "DW_TAG_subrange_type";
12929 case DW_TAG_with_stmt
:
12930 return "DW_TAG_with_stmt";
12931 case DW_TAG_access_declaration
:
12932 return "DW_TAG_access_declaration";
12933 case DW_TAG_base_type
:
12934 return "DW_TAG_base_type";
12935 case DW_TAG_catch_block
:
12936 return "DW_TAG_catch_block";
12937 case DW_TAG_const_type
:
12938 return "DW_TAG_const_type";
12939 case DW_TAG_constant
:
12940 return "DW_TAG_constant";
12941 case DW_TAG_enumerator
:
12942 return "DW_TAG_enumerator";
12943 case DW_TAG_file_type
:
12944 return "DW_TAG_file_type";
12945 case DW_TAG_friend
:
12946 return "DW_TAG_friend";
12947 case DW_TAG_namelist
:
12948 return "DW_TAG_namelist";
12949 case DW_TAG_namelist_item
:
12950 return "DW_TAG_namelist_item";
12951 case DW_TAG_packed_type
:
12952 return "DW_TAG_packed_type";
12953 case DW_TAG_subprogram
:
12954 return "DW_TAG_subprogram";
12955 case DW_TAG_template_type_param
:
12956 return "DW_TAG_template_type_param";
12957 case DW_TAG_template_value_param
:
12958 return "DW_TAG_template_value_param";
12959 case DW_TAG_thrown_type
:
12960 return "DW_TAG_thrown_type";
12961 case DW_TAG_try_block
:
12962 return "DW_TAG_try_block";
12963 case DW_TAG_variant_part
:
12964 return "DW_TAG_variant_part";
12965 case DW_TAG_variable
:
12966 return "DW_TAG_variable";
12967 case DW_TAG_volatile_type
:
12968 return "DW_TAG_volatile_type";
12969 case DW_TAG_dwarf_procedure
:
12970 return "DW_TAG_dwarf_procedure";
12971 case DW_TAG_restrict_type
:
12972 return "DW_TAG_restrict_type";
12973 case DW_TAG_interface_type
:
12974 return "DW_TAG_interface_type";
12975 case DW_TAG_namespace
:
12976 return "DW_TAG_namespace";
12977 case DW_TAG_imported_module
:
12978 return "DW_TAG_imported_module";
12979 case DW_TAG_unspecified_type
:
12980 return "DW_TAG_unspecified_type";
12981 case DW_TAG_partial_unit
:
12982 return "DW_TAG_partial_unit";
12983 case DW_TAG_imported_unit
:
12984 return "DW_TAG_imported_unit";
12985 case DW_TAG_condition
:
12986 return "DW_TAG_condition";
12987 case DW_TAG_shared_type
:
12988 return "DW_TAG_shared_type";
12989 case DW_TAG_type_unit
:
12990 return "DW_TAG_type_unit";
12991 case DW_TAG_MIPS_loop
:
12992 return "DW_TAG_MIPS_loop";
12993 case DW_TAG_HP_array_descriptor
:
12994 return "DW_TAG_HP_array_descriptor";
12995 case DW_TAG_format_label
:
12996 return "DW_TAG_format_label";
12997 case DW_TAG_function_template
:
12998 return "DW_TAG_function_template";
12999 case DW_TAG_class_template
:
13000 return "DW_TAG_class_template";
13001 case DW_TAG_GNU_BINCL
:
13002 return "DW_TAG_GNU_BINCL";
13003 case DW_TAG_GNU_EINCL
:
13004 return "DW_TAG_GNU_EINCL";
13005 case DW_TAG_upc_shared_type
:
13006 return "DW_TAG_upc_shared_type";
13007 case DW_TAG_upc_strict_type
:
13008 return "DW_TAG_upc_strict_type";
13009 case DW_TAG_upc_relaxed_type
:
13010 return "DW_TAG_upc_relaxed_type";
13011 case DW_TAG_PGI_kanji_type
:
13012 return "DW_TAG_PGI_kanji_type";
13013 case DW_TAG_PGI_interface_block
:
13014 return "DW_TAG_PGI_interface_block";
13015 case DW_TAG_GNU_call_site
:
13016 return "DW_TAG_GNU_call_site";
13018 return "DW_TAG_<unknown>";
13022 /* Convert a DWARF attribute code into its string name. */
13025 dwarf_attr_name (unsigned attr
)
13029 case DW_AT_sibling
:
13030 return "DW_AT_sibling";
13031 case DW_AT_location
:
13032 return "DW_AT_location";
13034 return "DW_AT_name";
13035 case DW_AT_ordering
:
13036 return "DW_AT_ordering";
13037 case DW_AT_subscr_data
:
13038 return "DW_AT_subscr_data";
13039 case DW_AT_byte_size
:
13040 return "DW_AT_byte_size";
13041 case DW_AT_bit_offset
:
13042 return "DW_AT_bit_offset";
13043 case DW_AT_bit_size
:
13044 return "DW_AT_bit_size";
13045 case DW_AT_element_list
:
13046 return "DW_AT_element_list";
13047 case DW_AT_stmt_list
:
13048 return "DW_AT_stmt_list";
13050 return "DW_AT_low_pc";
13051 case DW_AT_high_pc
:
13052 return "DW_AT_high_pc";
13053 case DW_AT_language
:
13054 return "DW_AT_language";
13056 return "DW_AT_member";
13058 return "DW_AT_discr";
13059 case DW_AT_discr_value
:
13060 return "DW_AT_discr_value";
13061 case DW_AT_visibility
:
13062 return "DW_AT_visibility";
13064 return "DW_AT_import";
13065 case DW_AT_string_length
:
13066 return "DW_AT_string_length";
13067 case DW_AT_common_reference
:
13068 return "DW_AT_common_reference";
13069 case DW_AT_comp_dir
:
13070 return "DW_AT_comp_dir";
13071 case DW_AT_const_value
:
13072 return "DW_AT_const_value";
13073 case DW_AT_containing_type
:
13074 return "DW_AT_containing_type";
13075 case DW_AT_default_value
:
13076 return "DW_AT_default_value";
13078 return "DW_AT_inline";
13079 case DW_AT_is_optional
:
13080 return "DW_AT_is_optional";
13081 case DW_AT_lower_bound
:
13082 return "DW_AT_lower_bound";
13083 case DW_AT_producer
:
13084 return "DW_AT_producer";
13085 case DW_AT_prototyped
:
13086 return "DW_AT_prototyped";
13087 case DW_AT_return_addr
:
13088 return "DW_AT_return_addr";
13089 case DW_AT_start_scope
:
13090 return "DW_AT_start_scope";
13091 case DW_AT_bit_stride
:
13092 return "DW_AT_bit_stride";
13093 case DW_AT_upper_bound
:
13094 return "DW_AT_upper_bound";
13095 case DW_AT_abstract_origin
:
13096 return "DW_AT_abstract_origin";
13097 case DW_AT_accessibility
:
13098 return "DW_AT_accessibility";
13099 case DW_AT_address_class
:
13100 return "DW_AT_address_class";
13101 case DW_AT_artificial
:
13102 return "DW_AT_artificial";
13103 case DW_AT_base_types
:
13104 return "DW_AT_base_types";
13105 case DW_AT_calling_convention
:
13106 return "DW_AT_calling_convention";
13108 return "DW_AT_count";
13109 case DW_AT_data_member_location
:
13110 return "DW_AT_data_member_location";
13111 case DW_AT_decl_column
:
13112 return "DW_AT_decl_column";
13113 case DW_AT_decl_file
:
13114 return "DW_AT_decl_file";
13115 case DW_AT_decl_line
:
13116 return "DW_AT_decl_line";
13117 case DW_AT_declaration
:
13118 return "DW_AT_declaration";
13119 case DW_AT_discr_list
:
13120 return "DW_AT_discr_list";
13121 case DW_AT_encoding
:
13122 return "DW_AT_encoding";
13123 case DW_AT_external
:
13124 return "DW_AT_external";
13125 case DW_AT_frame_base
:
13126 return "DW_AT_frame_base";
13128 return "DW_AT_friend";
13129 case DW_AT_identifier_case
:
13130 return "DW_AT_identifier_case";
13131 case DW_AT_macro_info
:
13132 return "DW_AT_macro_info";
13133 case DW_AT_namelist_items
:
13134 return "DW_AT_namelist_items";
13135 case DW_AT_priority
:
13136 return "DW_AT_priority";
13137 case DW_AT_segment
:
13138 return "DW_AT_segment";
13139 case DW_AT_specification
:
13140 return "DW_AT_specification";
13141 case DW_AT_static_link
:
13142 return "DW_AT_static_link";
13144 return "DW_AT_type";
13145 case DW_AT_use_location
:
13146 return "DW_AT_use_location";
13147 case DW_AT_variable_parameter
:
13148 return "DW_AT_variable_parameter";
13149 case DW_AT_virtuality
:
13150 return "DW_AT_virtuality";
13151 case DW_AT_vtable_elem_location
:
13152 return "DW_AT_vtable_elem_location";
13153 /* DWARF 3 values. */
13154 case DW_AT_allocated
:
13155 return "DW_AT_allocated";
13156 case DW_AT_associated
:
13157 return "DW_AT_associated";
13158 case DW_AT_data_location
:
13159 return "DW_AT_data_location";
13160 case DW_AT_byte_stride
:
13161 return "DW_AT_byte_stride";
13162 case DW_AT_entry_pc
:
13163 return "DW_AT_entry_pc";
13164 case DW_AT_use_UTF8
:
13165 return "DW_AT_use_UTF8";
13166 case DW_AT_extension
:
13167 return "DW_AT_extension";
13169 return "DW_AT_ranges";
13170 case DW_AT_trampoline
:
13171 return "DW_AT_trampoline";
13172 case DW_AT_call_column
:
13173 return "DW_AT_call_column";
13174 case DW_AT_call_file
:
13175 return "DW_AT_call_file";
13176 case DW_AT_call_line
:
13177 return "DW_AT_call_line";
13178 case DW_AT_description
:
13179 return "DW_AT_description";
13180 case DW_AT_binary_scale
:
13181 return "DW_AT_binary_scale";
13182 case DW_AT_decimal_scale
:
13183 return "DW_AT_decimal_scale";
13185 return "DW_AT_small";
13186 case DW_AT_decimal_sign
:
13187 return "DW_AT_decimal_sign";
13188 case DW_AT_digit_count
:
13189 return "DW_AT_digit_count";
13190 case DW_AT_picture_string
:
13191 return "DW_AT_picture_string";
13192 case DW_AT_mutable
:
13193 return "DW_AT_mutable";
13194 case DW_AT_threads_scaled
:
13195 return "DW_AT_threads_scaled";
13196 case DW_AT_explicit
:
13197 return "DW_AT_explicit";
13198 case DW_AT_object_pointer
:
13199 return "DW_AT_object_pointer";
13200 case DW_AT_endianity
:
13201 return "DW_AT_endianity";
13202 case DW_AT_elemental
:
13203 return "DW_AT_elemental";
13205 return "DW_AT_pure";
13206 case DW_AT_recursive
:
13207 return "DW_AT_recursive";
13208 /* DWARF 4 values. */
13209 case DW_AT_signature
:
13210 return "DW_AT_signature";
13211 case DW_AT_linkage_name
:
13212 return "DW_AT_linkage_name";
13213 /* SGI/MIPS extensions. */
13214 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13215 case DW_AT_MIPS_fde
:
13216 return "DW_AT_MIPS_fde";
13218 case DW_AT_MIPS_loop_begin
:
13219 return "DW_AT_MIPS_loop_begin";
13220 case DW_AT_MIPS_tail_loop_begin
:
13221 return "DW_AT_MIPS_tail_loop_begin";
13222 case DW_AT_MIPS_epilog_begin
:
13223 return "DW_AT_MIPS_epilog_begin";
13224 case DW_AT_MIPS_loop_unroll_factor
:
13225 return "DW_AT_MIPS_loop_unroll_factor";
13226 case DW_AT_MIPS_software_pipeline_depth
:
13227 return "DW_AT_MIPS_software_pipeline_depth";
13228 case DW_AT_MIPS_linkage_name
:
13229 return "DW_AT_MIPS_linkage_name";
13230 case DW_AT_MIPS_stride
:
13231 return "DW_AT_MIPS_stride";
13232 case DW_AT_MIPS_abstract_name
:
13233 return "DW_AT_MIPS_abstract_name";
13234 case DW_AT_MIPS_clone_origin
:
13235 return "DW_AT_MIPS_clone_origin";
13236 case DW_AT_MIPS_has_inlines
:
13237 return "DW_AT_MIPS_has_inlines";
13238 /* HP extensions. */
13239 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13240 case DW_AT_HP_block_index
:
13241 return "DW_AT_HP_block_index";
13243 case DW_AT_HP_unmodifiable
:
13244 return "DW_AT_HP_unmodifiable";
13245 case DW_AT_HP_actuals_stmt_list
:
13246 return "DW_AT_HP_actuals_stmt_list";
13247 case DW_AT_HP_proc_per_section
:
13248 return "DW_AT_HP_proc_per_section";
13249 case DW_AT_HP_raw_data_ptr
:
13250 return "DW_AT_HP_raw_data_ptr";
13251 case DW_AT_HP_pass_by_reference
:
13252 return "DW_AT_HP_pass_by_reference";
13253 case DW_AT_HP_opt_level
:
13254 return "DW_AT_HP_opt_level";
13255 case DW_AT_HP_prof_version_id
:
13256 return "DW_AT_HP_prof_version_id";
13257 case DW_AT_HP_opt_flags
:
13258 return "DW_AT_HP_opt_flags";
13259 case DW_AT_HP_cold_region_low_pc
:
13260 return "DW_AT_HP_cold_region_low_pc";
13261 case DW_AT_HP_cold_region_high_pc
:
13262 return "DW_AT_HP_cold_region_high_pc";
13263 case DW_AT_HP_all_variables_modifiable
:
13264 return "DW_AT_HP_all_variables_modifiable";
13265 case DW_AT_HP_linkage_name
:
13266 return "DW_AT_HP_linkage_name";
13267 case DW_AT_HP_prof_flags
:
13268 return "DW_AT_HP_prof_flags";
13269 /* GNU extensions. */
13270 case DW_AT_sf_names
:
13271 return "DW_AT_sf_names";
13272 case DW_AT_src_info
:
13273 return "DW_AT_src_info";
13274 case DW_AT_mac_info
:
13275 return "DW_AT_mac_info";
13276 case DW_AT_src_coords
:
13277 return "DW_AT_src_coords";
13278 case DW_AT_body_begin
:
13279 return "DW_AT_body_begin";
13280 case DW_AT_body_end
:
13281 return "DW_AT_body_end";
13282 case DW_AT_GNU_vector
:
13283 return "DW_AT_GNU_vector";
13284 case DW_AT_GNU_odr_signature
:
13285 return "DW_AT_GNU_odr_signature";
13286 /* VMS extensions. */
13287 case DW_AT_VMS_rtnbeg_pd_address
:
13288 return "DW_AT_VMS_rtnbeg_pd_address";
13289 /* UPC extension. */
13290 case DW_AT_upc_threads_scaled
:
13291 return "DW_AT_upc_threads_scaled";
13292 /* PGI (STMicroelectronics) extensions. */
13293 case DW_AT_PGI_lbase
:
13294 return "DW_AT_PGI_lbase";
13295 case DW_AT_PGI_soffset
:
13296 return "DW_AT_PGI_soffset";
13297 case DW_AT_PGI_lstride
:
13298 return "DW_AT_PGI_lstride";
13300 return "DW_AT_<unknown>";
13304 /* Convert a DWARF value form code into its string name. */
13307 dwarf_form_name (unsigned form
)
13312 return "DW_FORM_addr";
13313 case DW_FORM_block2
:
13314 return "DW_FORM_block2";
13315 case DW_FORM_block4
:
13316 return "DW_FORM_block4";
13317 case DW_FORM_data2
:
13318 return "DW_FORM_data2";
13319 case DW_FORM_data4
:
13320 return "DW_FORM_data4";
13321 case DW_FORM_data8
:
13322 return "DW_FORM_data8";
13323 case DW_FORM_string
:
13324 return "DW_FORM_string";
13325 case DW_FORM_block
:
13326 return "DW_FORM_block";
13327 case DW_FORM_block1
:
13328 return "DW_FORM_block1";
13329 case DW_FORM_data1
:
13330 return "DW_FORM_data1";
13332 return "DW_FORM_flag";
13333 case DW_FORM_sdata
:
13334 return "DW_FORM_sdata";
13336 return "DW_FORM_strp";
13337 case DW_FORM_udata
:
13338 return "DW_FORM_udata";
13339 case DW_FORM_ref_addr
:
13340 return "DW_FORM_ref_addr";
13342 return "DW_FORM_ref1";
13344 return "DW_FORM_ref2";
13346 return "DW_FORM_ref4";
13348 return "DW_FORM_ref8";
13349 case DW_FORM_ref_udata
:
13350 return "DW_FORM_ref_udata";
13351 case DW_FORM_indirect
:
13352 return "DW_FORM_indirect";
13353 case DW_FORM_sec_offset
:
13354 return "DW_FORM_sec_offset";
13355 case DW_FORM_exprloc
:
13356 return "DW_FORM_exprloc";
13357 case DW_FORM_flag_present
:
13358 return "DW_FORM_flag_present";
13359 case DW_FORM_ref_sig8
:
13360 return "DW_FORM_ref_sig8";
13362 return "DW_FORM_<unknown>";
13366 /* Convert a DWARF stack opcode into its string name. */
13369 dwarf_stack_op_name (unsigned op
)
13374 return "DW_OP_addr";
13376 return "DW_OP_deref";
13377 case DW_OP_const1u
:
13378 return "DW_OP_const1u";
13379 case DW_OP_const1s
:
13380 return "DW_OP_const1s";
13381 case DW_OP_const2u
:
13382 return "DW_OP_const2u";
13383 case DW_OP_const2s
:
13384 return "DW_OP_const2s";
13385 case DW_OP_const4u
:
13386 return "DW_OP_const4u";
13387 case DW_OP_const4s
:
13388 return "DW_OP_const4s";
13389 case DW_OP_const8u
:
13390 return "DW_OP_const8u";
13391 case DW_OP_const8s
:
13392 return "DW_OP_const8s";
13394 return "DW_OP_constu";
13396 return "DW_OP_consts";
13398 return "DW_OP_dup";
13400 return "DW_OP_drop";
13402 return "DW_OP_over";
13404 return "DW_OP_pick";
13406 return "DW_OP_swap";
13408 return "DW_OP_rot";
13410 return "DW_OP_xderef";
13412 return "DW_OP_abs";
13414 return "DW_OP_and";
13416 return "DW_OP_div";
13418 return "DW_OP_minus";
13420 return "DW_OP_mod";
13422 return "DW_OP_mul";
13424 return "DW_OP_neg";
13426 return "DW_OP_not";
13430 return "DW_OP_plus";
13431 case DW_OP_plus_uconst
:
13432 return "DW_OP_plus_uconst";
13434 return "DW_OP_shl";
13436 return "DW_OP_shr";
13438 return "DW_OP_shra";
13440 return "DW_OP_xor";
13442 return "DW_OP_bra";
13456 return "DW_OP_skip";
13458 return "DW_OP_lit0";
13460 return "DW_OP_lit1";
13462 return "DW_OP_lit2";
13464 return "DW_OP_lit3";
13466 return "DW_OP_lit4";
13468 return "DW_OP_lit5";
13470 return "DW_OP_lit6";
13472 return "DW_OP_lit7";
13474 return "DW_OP_lit8";
13476 return "DW_OP_lit9";
13478 return "DW_OP_lit10";
13480 return "DW_OP_lit11";
13482 return "DW_OP_lit12";
13484 return "DW_OP_lit13";
13486 return "DW_OP_lit14";
13488 return "DW_OP_lit15";
13490 return "DW_OP_lit16";
13492 return "DW_OP_lit17";
13494 return "DW_OP_lit18";
13496 return "DW_OP_lit19";
13498 return "DW_OP_lit20";
13500 return "DW_OP_lit21";
13502 return "DW_OP_lit22";
13504 return "DW_OP_lit23";
13506 return "DW_OP_lit24";
13508 return "DW_OP_lit25";
13510 return "DW_OP_lit26";
13512 return "DW_OP_lit27";
13514 return "DW_OP_lit28";
13516 return "DW_OP_lit29";
13518 return "DW_OP_lit30";
13520 return "DW_OP_lit31";
13522 return "DW_OP_reg0";
13524 return "DW_OP_reg1";
13526 return "DW_OP_reg2";
13528 return "DW_OP_reg3";
13530 return "DW_OP_reg4";
13532 return "DW_OP_reg5";
13534 return "DW_OP_reg6";
13536 return "DW_OP_reg7";
13538 return "DW_OP_reg8";
13540 return "DW_OP_reg9";
13542 return "DW_OP_reg10";
13544 return "DW_OP_reg11";
13546 return "DW_OP_reg12";
13548 return "DW_OP_reg13";
13550 return "DW_OP_reg14";
13552 return "DW_OP_reg15";
13554 return "DW_OP_reg16";
13556 return "DW_OP_reg17";
13558 return "DW_OP_reg18";
13560 return "DW_OP_reg19";
13562 return "DW_OP_reg20";
13564 return "DW_OP_reg21";
13566 return "DW_OP_reg22";
13568 return "DW_OP_reg23";
13570 return "DW_OP_reg24";
13572 return "DW_OP_reg25";
13574 return "DW_OP_reg26";
13576 return "DW_OP_reg27";
13578 return "DW_OP_reg28";
13580 return "DW_OP_reg29";
13582 return "DW_OP_reg30";
13584 return "DW_OP_reg31";
13586 return "DW_OP_breg0";
13588 return "DW_OP_breg1";
13590 return "DW_OP_breg2";
13592 return "DW_OP_breg3";
13594 return "DW_OP_breg4";
13596 return "DW_OP_breg5";
13598 return "DW_OP_breg6";
13600 return "DW_OP_breg7";
13602 return "DW_OP_breg8";
13604 return "DW_OP_breg9";
13606 return "DW_OP_breg10";
13608 return "DW_OP_breg11";
13610 return "DW_OP_breg12";
13612 return "DW_OP_breg13";
13614 return "DW_OP_breg14";
13616 return "DW_OP_breg15";
13618 return "DW_OP_breg16";
13620 return "DW_OP_breg17";
13622 return "DW_OP_breg18";
13624 return "DW_OP_breg19";
13626 return "DW_OP_breg20";
13628 return "DW_OP_breg21";
13630 return "DW_OP_breg22";
13632 return "DW_OP_breg23";
13634 return "DW_OP_breg24";
13636 return "DW_OP_breg25";
13638 return "DW_OP_breg26";
13640 return "DW_OP_breg27";
13642 return "DW_OP_breg28";
13644 return "DW_OP_breg29";
13646 return "DW_OP_breg30";
13648 return "DW_OP_breg31";
13650 return "DW_OP_regx";
13652 return "DW_OP_fbreg";
13654 return "DW_OP_bregx";
13656 return "DW_OP_piece";
13657 case DW_OP_deref_size
:
13658 return "DW_OP_deref_size";
13659 case DW_OP_xderef_size
:
13660 return "DW_OP_xderef_size";
13662 return "DW_OP_nop";
13663 /* DWARF 3 extensions. */
13664 case DW_OP_push_object_address
:
13665 return "DW_OP_push_object_address";
13667 return "DW_OP_call2";
13669 return "DW_OP_call4";
13670 case DW_OP_call_ref
:
13671 return "DW_OP_call_ref";
13672 case DW_OP_form_tls_address
:
13673 return "DW_OP_form_tls_address";
13674 case DW_OP_call_frame_cfa
:
13675 return "DW_OP_call_frame_cfa";
13676 case DW_OP_bit_piece
:
13677 return "DW_OP_bit_piece";
13678 /* DWARF 4 extensions. */
13679 case DW_OP_implicit_value
:
13680 return "DW_OP_implicit_value";
13681 case DW_OP_stack_value
:
13682 return "DW_OP_stack_value";
13683 /* GNU extensions. */
13684 case DW_OP_GNU_push_tls_address
:
13685 return "DW_OP_GNU_push_tls_address";
13686 case DW_OP_GNU_uninit
:
13687 return "DW_OP_GNU_uninit";
13688 case DW_OP_GNU_implicit_pointer
:
13689 return "DW_OP_GNU_implicit_pointer";
13690 case DW_OP_GNU_entry_value
:
13691 return "DW_OP_GNU_entry_value";
13692 case DW_OP_GNU_const_type
:
13693 return "DW_OP_GNU_const_type";
13694 case DW_OP_GNU_regval_type
:
13695 return "DW_OP_GNU_regval_type";
13696 case DW_OP_GNU_deref_type
:
13697 return "DW_OP_GNU_deref_type";
13698 case DW_OP_GNU_convert
:
13699 return "DW_OP_GNU_convert";
13700 case DW_OP_GNU_reinterpret
:
13701 return "DW_OP_GNU_reinterpret";
13708 dwarf_bool_name (unsigned mybool
)
13716 /* Convert a DWARF type code into its string name. */
13719 dwarf_type_encoding_name (unsigned enc
)
13724 return "DW_ATE_void";
13725 case DW_ATE_address
:
13726 return "DW_ATE_address";
13727 case DW_ATE_boolean
:
13728 return "DW_ATE_boolean";
13729 case DW_ATE_complex_float
:
13730 return "DW_ATE_complex_float";
13732 return "DW_ATE_float";
13733 case DW_ATE_signed
:
13734 return "DW_ATE_signed";
13735 case DW_ATE_signed_char
:
13736 return "DW_ATE_signed_char";
13737 case DW_ATE_unsigned
:
13738 return "DW_ATE_unsigned";
13739 case DW_ATE_unsigned_char
:
13740 return "DW_ATE_unsigned_char";
13742 case DW_ATE_imaginary_float
:
13743 return "DW_ATE_imaginary_float";
13744 case DW_ATE_packed_decimal
:
13745 return "DW_ATE_packed_decimal";
13746 case DW_ATE_numeric_string
:
13747 return "DW_ATE_numeric_string";
13748 case DW_ATE_edited
:
13749 return "DW_ATE_edited";
13750 case DW_ATE_signed_fixed
:
13751 return "DW_ATE_signed_fixed";
13752 case DW_ATE_unsigned_fixed
:
13753 return "DW_ATE_unsigned_fixed";
13754 case DW_ATE_decimal_float
:
13755 return "DW_ATE_decimal_float";
13758 return "DW_ATE_UTF";
13759 /* HP extensions. */
13760 case DW_ATE_HP_float80
:
13761 return "DW_ATE_HP_float80";
13762 case DW_ATE_HP_complex_float80
:
13763 return "DW_ATE_HP_complex_float80";
13764 case DW_ATE_HP_float128
:
13765 return "DW_ATE_HP_float128";
13766 case DW_ATE_HP_complex_float128
:
13767 return "DW_ATE_HP_complex_float128";
13768 case DW_ATE_HP_floathpintel
:
13769 return "DW_ATE_HP_floathpintel";
13770 case DW_ATE_HP_imaginary_float80
:
13771 return "DW_ATE_HP_imaginary_float80";
13772 case DW_ATE_HP_imaginary_float128
:
13773 return "DW_ATE_HP_imaginary_float128";
13775 return "DW_ATE_<unknown>";
13779 /* Convert a DWARF call frame info operation to its string name. */
13783 dwarf_cfi_name (unsigned cfi_opc
)
13787 case DW_CFA_advance_loc
:
13788 return "DW_CFA_advance_loc";
13789 case DW_CFA_offset
:
13790 return "DW_CFA_offset";
13791 case DW_CFA_restore
:
13792 return "DW_CFA_restore";
13794 return "DW_CFA_nop";
13795 case DW_CFA_set_loc
:
13796 return "DW_CFA_set_loc";
13797 case DW_CFA_advance_loc1
:
13798 return "DW_CFA_advance_loc1";
13799 case DW_CFA_advance_loc2
:
13800 return "DW_CFA_advance_loc2";
13801 case DW_CFA_advance_loc4
:
13802 return "DW_CFA_advance_loc4";
13803 case DW_CFA_offset_extended
:
13804 return "DW_CFA_offset_extended";
13805 case DW_CFA_restore_extended
:
13806 return "DW_CFA_restore_extended";
13807 case DW_CFA_undefined
:
13808 return "DW_CFA_undefined";
13809 case DW_CFA_same_value
:
13810 return "DW_CFA_same_value";
13811 case DW_CFA_register
:
13812 return "DW_CFA_register";
13813 case DW_CFA_remember_state
:
13814 return "DW_CFA_remember_state";
13815 case DW_CFA_restore_state
:
13816 return "DW_CFA_restore_state";
13817 case DW_CFA_def_cfa
:
13818 return "DW_CFA_def_cfa";
13819 case DW_CFA_def_cfa_register
:
13820 return "DW_CFA_def_cfa_register";
13821 case DW_CFA_def_cfa_offset
:
13822 return "DW_CFA_def_cfa_offset";
13824 case DW_CFA_def_cfa_expression
:
13825 return "DW_CFA_def_cfa_expression";
13826 case DW_CFA_expression
:
13827 return "DW_CFA_expression";
13828 case DW_CFA_offset_extended_sf
:
13829 return "DW_CFA_offset_extended_sf";
13830 case DW_CFA_def_cfa_sf
:
13831 return "DW_CFA_def_cfa_sf";
13832 case DW_CFA_def_cfa_offset_sf
:
13833 return "DW_CFA_def_cfa_offset_sf";
13834 case DW_CFA_val_offset
:
13835 return "DW_CFA_val_offset";
13836 case DW_CFA_val_offset_sf
:
13837 return "DW_CFA_val_offset_sf";
13838 case DW_CFA_val_expression
:
13839 return "DW_CFA_val_expression";
13840 /* SGI/MIPS specific. */
13841 case DW_CFA_MIPS_advance_loc8
:
13842 return "DW_CFA_MIPS_advance_loc8";
13843 /* GNU extensions. */
13844 case DW_CFA_GNU_window_save
:
13845 return "DW_CFA_GNU_window_save";
13846 case DW_CFA_GNU_args_size
:
13847 return "DW_CFA_GNU_args_size";
13848 case DW_CFA_GNU_negative_offset_extended
:
13849 return "DW_CFA_GNU_negative_offset_extended";
13851 return "DW_CFA_<unknown>";
13857 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13861 print_spaces (indent
, f
);
13862 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13863 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13865 if (die
->parent
!= NULL
)
13867 print_spaces (indent
, f
);
13868 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13869 die
->parent
->offset
);
13872 print_spaces (indent
, f
);
13873 fprintf_unfiltered (f
, " has children: %s\n",
13874 dwarf_bool_name (die
->child
!= NULL
));
13876 print_spaces (indent
, f
);
13877 fprintf_unfiltered (f
, " attributes:\n");
13879 for (i
= 0; i
< die
->num_attrs
; ++i
)
13881 print_spaces (indent
, f
);
13882 fprintf_unfiltered (f
, " %s (%s) ",
13883 dwarf_attr_name (die
->attrs
[i
].name
),
13884 dwarf_form_name (die
->attrs
[i
].form
));
13886 switch (die
->attrs
[i
].form
)
13888 case DW_FORM_ref_addr
:
13890 fprintf_unfiltered (f
, "address: ");
13891 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13893 case DW_FORM_block2
:
13894 case DW_FORM_block4
:
13895 case DW_FORM_block
:
13896 case DW_FORM_block1
:
13897 fprintf_unfiltered (f
, "block: size %d",
13898 DW_BLOCK (&die
->attrs
[i
])->size
);
13900 case DW_FORM_exprloc
:
13901 fprintf_unfiltered (f
, "expression: size %u",
13902 DW_BLOCK (&die
->attrs
[i
])->size
);
13907 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13908 (long) (DW_ADDR (&die
->attrs
[i
])));
13910 case DW_FORM_data1
:
13911 case DW_FORM_data2
:
13912 case DW_FORM_data4
:
13913 case DW_FORM_data8
:
13914 case DW_FORM_udata
:
13915 case DW_FORM_sdata
:
13916 fprintf_unfiltered (f
, "constant: %s",
13917 pulongest (DW_UNSND (&die
->attrs
[i
])));
13919 case DW_FORM_sec_offset
:
13920 fprintf_unfiltered (f
, "section offset: %s",
13921 pulongest (DW_UNSND (&die
->attrs
[i
])));
13923 case DW_FORM_ref_sig8
:
13924 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13925 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13926 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
);
13928 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13930 case DW_FORM_string
:
13932 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13933 DW_STRING (&die
->attrs
[i
])
13934 ? DW_STRING (&die
->attrs
[i
]) : "",
13935 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13938 if (DW_UNSND (&die
->attrs
[i
]))
13939 fprintf_unfiltered (f
, "flag: TRUE");
13941 fprintf_unfiltered (f
, "flag: FALSE");
13943 case DW_FORM_flag_present
:
13944 fprintf_unfiltered (f
, "flag: TRUE");
13946 case DW_FORM_indirect
:
13947 /* The reader will have reduced the indirect form to
13948 the "base form" so this form should not occur. */
13949 fprintf_unfiltered (f
,
13950 "unexpected attribute form: DW_FORM_indirect");
13953 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13954 die
->attrs
[i
].form
);
13957 fprintf_unfiltered (f
, "\n");
13962 dump_die_for_error (struct die_info
*die
)
13964 dump_die_shallow (gdb_stderr
, 0, die
);
13968 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13970 int indent
= level
* 4;
13972 gdb_assert (die
!= NULL
);
13974 if (level
>= max_level
)
13977 dump_die_shallow (f
, indent
, die
);
13979 if (die
->child
!= NULL
)
13981 print_spaces (indent
, f
);
13982 fprintf_unfiltered (f
, " Children:");
13983 if (level
+ 1 < max_level
)
13985 fprintf_unfiltered (f
, "\n");
13986 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13990 fprintf_unfiltered (f
,
13991 " [not printed, max nesting level reached]\n");
13995 if (die
->sibling
!= NULL
&& level
> 0)
13997 dump_die_1 (f
, level
, max_level
, die
->sibling
);
14001 /* This is called from the pdie macro in gdbinit.in.
14002 It's not static so gcc will keep a copy callable from gdb. */
14005 dump_die (struct die_info
*die
, int max_level
)
14007 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
14011 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
14015 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
14021 is_ref_attr (struct attribute
*attr
)
14023 switch (attr
->form
)
14025 case DW_FORM_ref_addr
:
14030 case DW_FORM_ref_udata
:
14037 static unsigned int
14038 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14040 if (is_ref_attr (attr
))
14041 return DW_ADDR (attr
);
14043 complaint (&symfile_complaints
,
14044 _("unsupported die ref attribute form: '%s'"),
14045 dwarf_form_name (attr
->form
));
14049 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14050 * the value held by the attribute is not constant. */
14053 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
14055 if (attr
->form
== DW_FORM_sdata
)
14056 return DW_SND (attr
);
14057 else if (attr
->form
== DW_FORM_udata
14058 || attr
->form
== DW_FORM_data1
14059 || attr
->form
== DW_FORM_data2
14060 || attr
->form
== DW_FORM_data4
14061 || attr
->form
== DW_FORM_data8
)
14062 return DW_UNSND (attr
);
14065 complaint (&symfile_complaints
,
14066 _("Attribute value is not a constant (%s)"),
14067 dwarf_form_name (attr
->form
));
14068 return default_value
;
14072 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14073 unit and add it to our queue.
14074 The result is non-zero if PER_CU was queued, otherwise the result is zero
14075 meaning either PER_CU is already queued or it is already loaded. */
14078 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14079 struct dwarf2_per_cu_data
*per_cu
)
14081 /* We may arrive here during partial symbol reading, if we need full
14082 DIEs to process an unusual case (e.g. template arguments). Do
14083 not queue PER_CU, just tell our caller to load its DIEs. */
14084 if (dwarf2_per_objfile
->reading_partial_symbols
)
14086 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14091 /* Mark the dependence relation so that we don't flush PER_CU
14093 dwarf2_add_dependence (this_cu
, per_cu
);
14095 /* If it's already on the queue, we have nothing to do. */
14096 if (per_cu
->queued
)
14099 /* If the compilation unit is already loaded, just mark it as
14101 if (per_cu
->cu
!= NULL
)
14103 per_cu
->cu
->last_used
= 0;
14107 /* Add it to the queue. */
14108 queue_comp_unit (per_cu
);
14113 /* Follow reference or signature attribute ATTR of SRC_DIE.
14114 On entry *REF_CU is the CU of SRC_DIE.
14115 On exit *REF_CU is the CU of the result. */
14117 static struct die_info
*
14118 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14119 struct dwarf2_cu
**ref_cu
)
14121 struct die_info
*die
;
14123 if (is_ref_attr (attr
))
14124 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14125 else if (attr
->form
== DW_FORM_ref_sig8
)
14126 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14129 dump_die_for_error (src_die
);
14130 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14131 (*ref_cu
)->objfile
->name
);
14137 /* Follow reference OFFSET.
14138 On entry *REF_CU is the CU of the source die referencing OFFSET.
14139 On exit *REF_CU is the CU of the result.
14140 Returns NULL if OFFSET is invalid. */
14142 static struct die_info
*
14143 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
14145 struct die_info temp_die
;
14146 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14148 gdb_assert (cu
->per_cu
!= NULL
);
14152 if (cu
->per_cu
->debug_types_section
)
14154 /* .debug_types CUs cannot reference anything outside their CU.
14155 If they need to, they have to reference a signatured type via
14156 DW_FORM_ref_sig8. */
14157 if (! offset_in_cu_p (&cu
->header
, offset
))
14160 else if (! offset_in_cu_p (&cu
->header
, offset
))
14162 struct dwarf2_per_cu_data
*per_cu
;
14164 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14166 /* If necessary, add it to the queue and load its DIEs. */
14167 if (maybe_queue_comp_unit (cu
, per_cu
))
14168 load_full_comp_unit (per_cu
);
14170 target_cu
= per_cu
->cu
;
14172 else if (cu
->dies
== NULL
)
14174 /* We're loading full DIEs during partial symbol reading. */
14175 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14176 load_full_comp_unit (cu
->per_cu
);
14179 *ref_cu
= target_cu
;
14180 temp_die
.offset
= offset
;
14181 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
14184 /* Follow reference attribute ATTR of SRC_DIE.
14185 On entry *REF_CU is the CU of SRC_DIE.
14186 On exit *REF_CU is the CU of the result. */
14188 static struct die_info
*
14189 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14190 struct dwarf2_cu
**ref_cu
)
14192 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
14193 struct dwarf2_cu
*cu
= *ref_cu
;
14194 struct die_info
*die
;
14196 die
= follow_die_offset (offset
, ref_cu
);
14198 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14199 "at 0x%x [in module %s]"),
14200 offset
, src_die
->offset
, cu
->objfile
->name
);
14205 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14206 Returned value is intended for DW_OP_call*. Returned
14207 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14209 struct dwarf2_locexpr_baton
14210 dwarf2_fetch_die_location_block (unsigned int offset
,
14211 struct dwarf2_per_cu_data
*per_cu
,
14212 CORE_ADDR (*get_frame_pc
) (void *baton
),
14215 struct dwarf2_cu
*cu
;
14216 struct die_info
*die
;
14217 struct attribute
*attr
;
14218 struct dwarf2_locexpr_baton retval
;
14220 dw2_setup (per_cu
->objfile
);
14222 if (per_cu
->cu
== NULL
)
14226 die
= follow_die_offset (offset
, &cu
);
14228 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14229 offset
, per_cu
->objfile
->name
);
14231 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14234 /* DWARF: "If there is no such attribute, then there is no effect.".
14235 DATA is ignored if SIZE is 0. */
14237 retval
.data
= NULL
;
14240 else if (attr_form_is_section_offset (attr
))
14242 struct dwarf2_loclist_baton loclist_baton
;
14243 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
14246 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
14248 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
14250 retval
.size
= size
;
14254 if (!attr_form_is_block (attr
))
14255 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14256 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14257 offset
, per_cu
->objfile
->name
);
14259 retval
.data
= DW_BLOCK (attr
)->data
;
14260 retval
.size
= DW_BLOCK (attr
)->size
;
14262 retval
.per_cu
= cu
->per_cu
;
14264 age_cached_comp_units ();
14269 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14273 dwarf2_get_die_type (unsigned int die_offset
,
14274 struct dwarf2_per_cu_data
*per_cu
)
14276 dw2_setup (per_cu
->objfile
);
14277 return get_die_type_at_offset (die_offset
, per_cu
);
14280 /* Follow the signature attribute ATTR in SRC_DIE.
14281 On entry *REF_CU is the CU of SRC_DIE.
14282 On exit *REF_CU is the CU of the result. */
14284 static struct die_info
*
14285 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
14286 struct dwarf2_cu
**ref_cu
)
14288 struct objfile
*objfile
= (*ref_cu
)->objfile
;
14289 struct die_info temp_die
;
14290 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14291 struct dwarf2_cu
*sig_cu
;
14292 struct die_info
*die
;
14294 /* sig_type will be NULL if the signatured type is missing from
14296 if (sig_type
== NULL
)
14297 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14298 "at 0x%x [in module %s]"),
14299 src_die
->offset
, objfile
->name
);
14301 /* If necessary, add it to the queue and load its DIEs. */
14303 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14304 read_signatured_type (sig_type
);
14306 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14308 sig_cu
= sig_type
->per_cu
.cu
;
14309 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
14310 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
14317 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14318 "from DIE at 0x%x [in module %s]"),
14319 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
14322 /* Given an offset of a signatured type, return its signatured_type. */
14324 static struct signatured_type
*
14325 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14326 struct dwarf2_section_info
*section
,
14327 unsigned int offset
)
14329 gdb_byte
*info_ptr
= section
->buffer
+ offset
;
14330 unsigned int length
, initial_length_size
;
14331 unsigned int sig_offset
;
14332 struct signatured_type find_entry
, *type_sig
;
14334 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14335 sig_offset
= (initial_length_size
14337 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14338 + 1 /*address_size*/);
14339 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14340 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14342 /* This is only used to lookup previously recorded types.
14343 If we didn't find it, it's our bug. */
14344 gdb_assert (type_sig
!= NULL
);
14345 gdb_assert (offset
== type_sig
->per_cu
.offset
);
14350 /* Load the DIEs associated with type unit PER_CU into memory. */
14353 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
14355 struct objfile
*objfile
= per_cu
->objfile
;
14356 struct dwarf2_section_info
*sect
= per_cu
->debug_types_section
;
14357 unsigned int offset
= per_cu
->offset
;
14358 struct signatured_type
*type_sig
;
14360 dwarf2_read_section (objfile
, sect
);
14362 /* We have the section offset, but we need the signature to do the
14363 hash table lookup. */
14364 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
14365 the signature to assert we found the right one.
14366 Ok, but it's a lot of work. We should simplify things so any needed
14367 assert doesn't require all this clumsiness. */
14368 type_sig
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14370 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14372 read_signatured_type (type_sig
);
14374 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
14377 /* Read in a signatured type and build its CU and DIEs. */
14380 read_signatured_type (struct signatured_type
*type_sig
)
14382 struct objfile
*objfile
= type_sig
->per_cu
.objfile
;
14383 gdb_byte
*types_ptr
;
14384 struct die_reader_specs reader_specs
;
14385 struct dwarf2_cu
*cu
;
14386 ULONGEST signature
;
14387 struct cleanup
*back_to
, *free_cu_cleanup
;
14388 struct dwarf2_section_info
*section
= type_sig
->per_cu
.debug_types_section
;
14390 dwarf2_read_section (objfile
, section
);
14391 types_ptr
= section
->buffer
+ type_sig
->per_cu
.offset
;
14393 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14395 cu
= xmalloc (sizeof (*cu
));
14396 init_one_comp_unit (cu
, &type_sig
->per_cu
);
14398 /* If an error occurs while loading, release our storage. */
14399 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
14401 types_ptr
= read_type_comp_unit_head (&cu
->header
, section
, &signature
,
14402 types_ptr
, objfile
->obfd
);
14403 gdb_assert (signature
== type_sig
->signature
);
14406 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14410 &cu
->comp_unit_obstack
,
14411 hashtab_obstack_allocate
,
14412 dummy_obstack_deallocate
);
14414 dwarf2_read_abbrevs (cu
);
14415 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
14417 init_cu_die_reader (&reader_specs
, cu
);
14419 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14422 /* We try not to read any attributes in this function, because not
14423 all CUs needed for references have been loaded yet, and symbol
14424 table processing isn't initialized. But we have to set the CU language,
14425 or we won't be able to build types correctly. */
14426 prepare_one_comp_unit (cu
, cu
->dies
);
14428 do_cleanups (back_to
);
14430 /* We've successfully allocated this compilation unit. Let our caller
14431 clean it up when finished with it. */
14432 discard_cleanups (free_cu_cleanup
);
14434 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14435 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
14438 /* Decode simple location descriptions.
14439 Given a pointer to a dwarf block that defines a location, compute
14440 the location and return the value.
14442 NOTE drow/2003-11-18: This function is called in two situations
14443 now: for the address of static or global variables (partial symbols
14444 only) and for offsets into structures which are expected to be
14445 (more or less) constant. The partial symbol case should go away,
14446 and only the constant case should remain. That will let this
14447 function complain more accurately. A few special modes are allowed
14448 without complaint for global variables (for instance, global
14449 register values and thread-local values).
14451 A location description containing no operations indicates that the
14452 object is optimized out. The return value is 0 for that case.
14453 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14454 callers will only want a very basic result and this can become a
14457 Note that stack[0] is unused except as a default error return. */
14460 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14462 struct objfile
*objfile
= cu
->objfile
;
14464 int size
= blk
->size
;
14465 gdb_byte
*data
= blk
->data
;
14466 CORE_ADDR stack
[64];
14468 unsigned int bytes_read
, unsnd
;
14474 stack
[++stacki
] = 0;
14513 stack
[++stacki
] = op
- DW_OP_lit0
;
14548 stack
[++stacki
] = op
- DW_OP_reg0
;
14550 dwarf2_complex_location_expr_complaint ();
14554 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14556 stack
[++stacki
] = unsnd
;
14558 dwarf2_complex_location_expr_complaint ();
14562 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14567 case DW_OP_const1u
:
14568 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14572 case DW_OP_const1s
:
14573 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14577 case DW_OP_const2u
:
14578 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14582 case DW_OP_const2s
:
14583 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14587 case DW_OP_const4u
:
14588 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14592 case DW_OP_const4s
:
14593 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14597 case DW_OP_const8u
:
14598 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
14603 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14609 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14614 stack
[stacki
+ 1] = stack
[stacki
];
14619 stack
[stacki
- 1] += stack
[stacki
];
14623 case DW_OP_plus_uconst
:
14624 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14630 stack
[stacki
- 1] -= stack
[stacki
];
14635 /* If we're not the last op, then we definitely can't encode
14636 this using GDB's address_class enum. This is valid for partial
14637 global symbols, although the variable's address will be bogus
14640 dwarf2_complex_location_expr_complaint ();
14643 case DW_OP_GNU_push_tls_address
:
14644 /* The top of the stack has the offset from the beginning
14645 of the thread control block at which the variable is located. */
14646 /* Nothing should follow this operator, so the top of stack would
14648 /* This is valid for partial global symbols, but the variable's
14649 address will be bogus in the psymtab. Make it always at least
14650 non-zero to not look as a variable garbage collected by linker
14651 which have DW_OP_addr 0. */
14653 dwarf2_complex_location_expr_complaint ();
14657 case DW_OP_GNU_uninit
:
14662 const char *name
= dwarf_stack_op_name (op
);
14665 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14668 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14672 return (stack
[stacki
]);
14675 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14676 outside of the allocated space. Also enforce minimum>0. */
14677 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14679 complaint (&symfile_complaints
,
14680 _("location description stack overflow"));
14686 complaint (&symfile_complaints
,
14687 _("location description stack underflow"));
14691 return (stack
[stacki
]);
14694 /* memory allocation interface */
14696 static struct dwarf_block
*
14697 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14699 struct dwarf_block
*blk
;
14701 blk
= (struct dwarf_block
*)
14702 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14706 static struct abbrev_info
*
14707 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14709 struct abbrev_info
*abbrev
;
14711 abbrev
= (struct abbrev_info
*)
14712 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14713 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14717 static struct die_info
*
14718 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14720 struct die_info
*die
;
14721 size_t size
= sizeof (struct die_info
);
14724 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14726 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14727 memset (die
, 0, sizeof (struct die_info
));
14732 /* Macro support. */
14734 /* Return the full name of file number I in *LH's file name table.
14735 Use COMP_DIR as the name of the current directory of the
14736 compilation. The result is allocated using xmalloc; the caller is
14737 responsible for freeing it. */
14739 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14741 /* Is the file number a valid index into the line header's file name
14742 table? Remember that file numbers start with one, not zero. */
14743 if (1 <= file
&& file
<= lh
->num_file_names
)
14745 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14747 if (IS_ABSOLUTE_PATH (fe
->name
))
14748 return xstrdup (fe
->name
);
14756 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14762 dir_len
= strlen (dir
);
14763 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14764 strcpy (full_name
, dir
);
14765 full_name
[dir_len
] = '/';
14766 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14770 return xstrdup (fe
->name
);
14775 /* The compiler produced a bogus file number. We can at least
14776 record the macro definitions made in the file, even if we
14777 won't be able to find the file by name. */
14778 char fake_name
[80];
14780 sprintf (fake_name
, "<bad macro file number %d>", file
);
14782 complaint (&symfile_complaints
,
14783 _("bad file number in macro information (%d)"),
14786 return xstrdup (fake_name
);
14791 static struct macro_source_file
*
14792 macro_start_file (int file
, int line
,
14793 struct macro_source_file
*current_file
,
14794 const char *comp_dir
,
14795 struct line_header
*lh
, struct objfile
*objfile
)
14797 /* The full name of this source file. */
14798 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14800 /* We don't create a macro table for this compilation unit
14801 at all until we actually get a filename. */
14802 if (! pending_macros
)
14803 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14804 objfile
->macro_cache
);
14806 if (! current_file
)
14807 /* If we have no current file, then this must be the start_file
14808 directive for the compilation unit's main source file. */
14809 current_file
= macro_set_main (pending_macros
, full_name
);
14811 current_file
= macro_include (current_file
, line
, full_name
);
14815 return current_file
;
14819 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14820 followed by a null byte. */
14822 copy_string (const char *buf
, int len
)
14824 char *s
= xmalloc (len
+ 1);
14826 memcpy (s
, buf
, len
);
14832 static const char *
14833 consume_improper_spaces (const char *p
, const char *body
)
14837 complaint (&symfile_complaints
,
14838 _("macro definition contains spaces "
14839 "in formal argument list:\n`%s'"),
14851 parse_macro_definition (struct macro_source_file
*file
, int line
,
14856 /* The body string takes one of two forms. For object-like macro
14857 definitions, it should be:
14859 <macro name> " " <definition>
14861 For function-like macro definitions, it should be:
14863 <macro name> "() " <definition>
14865 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14867 Spaces may appear only where explicitly indicated, and in the
14870 The Dwarf 2 spec says that an object-like macro's name is always
14871 followed by a space, but versions of GCC around March 2002 omit
14872 the space when the macro's definition is the empty string.
14874 The Dwarf 2 spec says that there should be no spaces between the
14875 formal arguments in a function-like macro's formal argument list,
14876 but versions of GCC around March 2002 include spaces after the
14880 /* Find the extent of the macro name. The macro name is terminated
14881 by either a space or null character (for an object-like macro) or
14882 an opening paren (for a function-like macro). */
14883 for (p
= body
; *p
; p
++)
14884 if (*p
== ' ' || *p
== '(')
14887 if (*p
== ' ' || *p
== '\0')
14889 /* It's an object-like macro. */
14890 int name_len
= p
- body
;
14891 char *name
= copy_string (body
, name_len
);
14892 const char *replacement
;
14895 replacement
= body
+ name_len
+ 1;
14898 dwarf2_macro_malformed_definition_complaint (body
);
14899 replacement
= body
+ name_len
;
14902 macro_define_object (file
, line
, name
, replacement
);
14906 else if (*p
== '(')
14908 /* It's a function-like macro. */
14909 char *name
= copy_string (body
, p
- body
);
14912 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14916 p
= consume_improper_spaces (p
, body
);
14918 /* Parse the formal argument list. */
14919 while (*p
&& *p
!= ')')
14921 /* Find the extent of the current argument name. */
14922 const char *arg_start
= p
;
14924 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14927 if (! *p
|| p
== arg_start
)
14928 dwarf2_macro_malformed_definition_complaint (body
);
14931 /* Make sure argv has room for the new argument. */
14932 if (argc
>= argv_size
)
14935 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14938 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14941 p
= consume_improper_spaces (p
, body
);
14943 /* Consume the comma, if present. */
14948 p
= consume_improper_spaces (p
, body
);
14957 /* Perfectly formed definition, no complaints. */
14958 macro_define_function (file
, line
, name
,
14959 argc
, (const char **) argv
,
14961 else if (*p
== '\0')
14963 /* Complain, but do define it. */
14964 dwarf2_macro_malformed_definition_complaint (body
);
14965 macro_define_function (file
, line
, name
,
14966 argc
, (const char **) argv
,
14970 /* Just complain. */
14971 dwarf2_macro_malformed_definition_complaint (body
);
14974 /* Just complain. */
14975 dwarf2_macro_malformed_definition_complaint (body
);
14981 for (i
= 0; i
< argc
; i
++)
14987 dwarf2_macro_malformed_definition_complaint (body
);
14990 /* Skip some bytes from BYTES according to the form given in FORM.
14991 Returns the new pointer. */
14994 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
14995 enum dwarf_form form
,
14996 unsigned int offset_size
,
14997 struct dwarf2_section_info
*section
)
14999 unsigned int bytes_read
;
15003 case DW_FORM_data1
:
15008 case DW_FORM_data2
:
15012 case DW_FORM_data4
:
15016 case DW_FORM_data8
:
15020 case DW_FORM_string
:
15021 read_direct_string (abfd
, bytes
, &bytes_read
);
15022 bytes
+= bytes_read
;
15025 case DW_FORM_sec_offset
:
15027 bytes
+= offset_size
;
15030 case DW_FORM_block
:
15031 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
15032 bytes
+= bytes_read
;
15035 case DW_FORM_block1
:
15036 bytes
+= 1 + read_1_byte (abfd
, bytes
);
15038 case DW_FORM_block2
:
15039 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
15041 case DW_FORM_block4
:
15042 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
15045 case DW_FORM_sdata
:
15046 case DW_FORM_udata
:
15047 bytes
= skip_leb128 (abfd
, bytes
);
15053 complaint (&symfile_complaints
,
15054 _("invalid form 0x%x in `%s'"),
15056 section
->asection
->name
);
15064 /* A helper for dwarf_decode_macros that handles skipping an unknown
15065 opcode. Returns an updated pointer to the macro data buffer; or,
15066 on error, issues a complaint and returns NULL. */
15069 skip_unknown_opcode (unsigned int opcode
,
15070 gdb_byte
**opcode_definitions
,
15073 unsigned int offset_size
,
15074 struct dwarf2_section_info
*section
)
15076 unsigned int bytes_read
, i
;
15080 if (opcode_definitions
[opcode
] == NULL
)
15082 complaint (&symfile_complaints
,
15083 _("unrecognized DW_MACFINO opcode 0x%x"),
15088 defn
= opcode_definitions
[opcode
];
15089 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15090 defn
+= bytes_read
;
15092 for (i
= 0; i
< arg
; ++i
)
15094 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
15095 if (mac_ptr
== NULL
)
15097 /* skip_form_bytes already issued the complaint. */
15105 /* A helper function which parses the header of a macro section.
15106 If the macro section is the extended (for now called "GNU") type,
15107 then this updates *OFFSET_SIZE. Returns a pointer to just after
15108 the header, or issues a complaint and returns NULL on error. */
15111 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15114 unsigned int *offset_size
,
15115 int section_is_gnu
)
15117 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15119 if (section_is_gnu
)
15121 unsigned int version
, flags
;
15123 version
= read_2_bytes (abfd
, mac_ptr
);
15126 complaint (&symfile_complaints
,
15127 _("unrecognized version `%d' in .debug_macro section"),
15133 flags
= read_1_byte (abfd
, mac_ptr
);
15135 *offset_size
= (flags
& 1) ? 8 : 4;
15137 if ((flags
& 2) != 0)
15138 /* We don't need the line table offset. */
15139 mac_ptr
+= *offset_size
;
15141 /* Vendor opcode descriptions. */
15142 if ((flags
& 4) != 0)
15144 unsigned int i
, count
;
15146 count
= read_1_byte (abfd
, mac_ptr
);
15148 for (i
= 0; i
< count
; ++i
)
15150 unsigned int opcode
, bytes_read
;
15153 opcode
= read_1_byte (abfd
, mac_ptr
);
15155 opcode_definitions
[opcode
] = mac_ptr
;
15156 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15157 mac_ptr
+= bytes_read
;
15166 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15167 including DW_GNU_MACINFO_transparent_include. */
15170 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15171 struct macro_source_file
*current_file
,
15172 struct line_header
*lh
, char *comp_dir
,
15173 struct dwarf2_section_info
*section
,
15174 int section_is_gnu
,
15175 unsigned int offset_size
,
15176 struct objfile
*objfile
)
15178 enum dwarf_macro_record_type macinfo_type
;
15179 int at_commandline
;
15180 gdb_byte
*opcode_definitions
[256];
15182 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15183 &offset_size
, section_is_gnu
);
15184 if (mac_ptr
== NULL
)
15186 /* We already issued a complaint. */
15190 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15191 GDB is still reading the definitions from command line. First
15192 DW_MACINFO_start_file will need to be ignored as it was already executed
15193 to create CURRENT_FILE for the main source holding also the command line
15194 definitions. On first met DW_MACINFO_start_file this flag is reset to
15195 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15197 at_commandline
= 1;
15201 /* Do we at least have room for a macinfo type byte? */
15202 if (mac_ptr
>= mac_end
)
15204 dwarf2_macros_too_long_complaint (section
);
15208 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15211 /* Note that we rely on the fact that the corresponding GNU and
15212 DWARF constants are the same. */
15213 switch (macinfo_type
)
15215 /* A zero macinfo type indicates the end of the macro
15220 case DW_MACRO_GNU_define
:
15221 case DW_MACRO_GNU_undef
:
15222 case DW_MACRO_GNU_define_indirect
:
15223 case DW_MACRO_GNU_undef_indirect
:
15225 unsigned int bytes_read
;
15230 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15231 mac_ptr
+= bytes_read
;
15233 if (macinfo_type
== DW_MACRO_GNU_define
15234 || macinfo_type
== DW_MACRO_GNU_undef
)
15236 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15237 mac_ptr
+= bytes_read
;
15241 LONGEST str_offset
;
15243 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15244 mac_ptr
+= offset_size
;
15246 body
= read_indirect_string_at_offset (abfd
, str_offset
);
15249 is_define
= (macinfo_type
== DW_MACRO_GNU_define
15250 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
15251 if (! current_file
)
15253 /* DWARF violation as no main source is present. */
15254 complaint (&symfile_complaints
,
15255 _("debug info with no main source gives macro %s "
15257 is_define
? _("definition") : _("undefinition"),
15261 if ((line
== 0 && !at_commandline
)
15262 || (line
!= 0 && at_commandline
))
15263 complaint (&symfile_complaints
,
15264 _("debug info gives %s macro %s with %s line %d: %s"),
15265 at_commandline
? _("command-line") : _("in-file"),
15266 is_define
? _("definition") : _("undefinition"),
15267 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
15270 parse_macro_definition (current_file
, line
, body
);
15273 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
15274 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
15275 macro_undef (current_file
, line
, body
);
15280 case DW_MACRO_GNU_start_file
:
15282 unsigned int bytes_read
;
15285 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15286 mac_ptr
+= bytes_read
;
15287 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15288 mac_ptr
+= bytes_read
;
15290 if ((line
== 0 && !at_commandline
)
15291 || (line
!= 0 && at_commandline
))
15292 complaint (&symfile_complaints
,
15293 _("debug info gives source %d included "
15294 "from %s at %s line %d"),
15295 file
, at_commandline
? _("command-line") : _("file"),
15296 line
== 0 ? _("zero") : _("non-zero"), line
);
15298 if (at_commandline
)
15300 /* This DW_MACRO_GNU_start_file was executed in the
15302 at_commandline
= 0;
15305 current_file
= macro_start_file (file
, line
,
15306 current_file
, comp_dir
,
15311 case DW_MACRO_GNU_end_file
:
15312 if (! current_file
)
15313 complaint (&symfile_complaints
,
15314 _("macro debug info has an unmatched "
15315 "`close_file' directive"));
15318 current_file
= current_file
->included_by
;
15319 if (! current_file
)
15321 enum dwarf_macro_record_type next_type
;
15323 /* GCC circa March 2002 doesn't produce the zero
15324 type byte marking the end of the compilation
15325 unit. Complain if it's not there, but exit no
15328 /* Do we at least have room for a macinfo type byte? */
15329 if (mac_ptr
>= mac_end
)
15331 dwarf2_macros_too_long_complaint (section
);
15335 /* We don't increment mac_ptr here, so this is just
15337 next_type
= read_1_byte (abfd
, mac_ptr
);
15338 if (next_type
!= 0)
15339 complaint (&symfile_complaints
,
15340 _("no terminating 0-type entry for "
15341 "macros in `.debug_macinfo' section"));
15348 case DW_MACRO_GNU_transparent_include
:
15352 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15353 mac_ptr
+= offset_size
;
15355 dwarf_decode_macro_bytes (abfd
,
15356 section
->buffer
+ offset
,
15357 mac_end
, current_file
,
15359 section
, section_is_gnu
,
15360 offset_size
, objfile
);
15364 case DW_MACINFO_vendor_ext
:
15365 if (!section_is_gnu
)
15367 unsigned int bytes_read
;
15370 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15371 mac_ptr
+= bytes_read
;
15372 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15373 mac_ptr
+= bytes_read
;
15375 /* We don't recognize any vendor extensions. */
15381 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15382 mac_ptr
, abfd
, offset_size
,
15384 if (mac_ptr
== NULL
)
15388 } while (macinfo_type
!= 0);
15392 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
15393 char *comp_dir
, bfd
*abfd
,
15394 struct dwarf2_cu
*cu
,
15395 struct dwarf2_section_info
*section
,
15396 int section_is_gnu
)
15398 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15399 gdb_byte
*mac_ptr
, *mac_end
;
15400 struct macro_source_file
*current_file
= 0;
15401 enum dwarf_macro_record_type macinfo_type
;
15402 unsigned int offset_size
= cu
->header
.offset_size
;
15403 gdb_byte
*opcode_definitions
[256];
15405 dwarf2_read_section (objfile
, section
);
15406 if (section
->buffer
== NULL
)
15408 complaint (&symfile_complaints
, _("missing %s section"),
15409 section
->asection
->name
);
15413 /* First pass: Find the name of the base filename.
15414 This filename is needed in order to process all macros whose definition
15415 (or undefinition) comes from the command line. These macros are defined
15416 before the first DW_MACINFO_start_file entry, and yet still need to be
15417 associated to the base file.
15419 To determine the base file name, we scan the macro definitions until we
15420 reach the first DW_MACINFO_start_file entry. We then initialize
15421 CURRENT_FILE accordingly so that any macro definition found before the
15422 first DW_MACINFO_start_file can still be associated to the base file. */
15424 mac_ptr
= section
->buffer
+ offset
;
15425 mac_end
= section
->buffer
+ section
->size
;
15427 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15428 &offset_size
, section_is_gnu
);
15429 if (mac_ptr
== NULL
)
15431 /* We already issued a complaint. */
15437 /* Do we at least have room for a macinfo type byte? */
15438 if (mac_ptr
>= mac_end
)
15440 /* Complaint is printed during the second pass as GDB will probably
15441 stop the first pass earlier upon finding
15442 DW_MACINFO_start_file. */
15446 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15449 /* Note that we rely on the fact that the corresponding GNU and
15450 DWARF constants are the same. */
15451 switch (macinfo_type
)
15453 /* A zero macinfo type indicates the end of the macro
15458 case DW_MACRO_GNU_define
:
15459 case DW_MACRO_GNU_undef
:
15460 /* Only skip the data by MAC_PTR. */
15462 unsigned int bytes_read
;
15464 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15465 mac_ptr
+= bytes_read
;
15466 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15467 mac_ptr
+= bytes_read
;
15471 case DW_MACRO_GNU_start_file
:
15473 unsigned int bytes_read
;
15476 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15477 mac_ptr
+= bytes_read
;
15478 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15479 mac_ptr
+= bytes_read
;
15481 current_file
= macro_start_file (file
, line
, current_file
,
15482 comp_dir
, lh
, objfile
);
15486 case DW_MACRO_GNU_end_file
:
15487 /* No data to skip by MAC_PTR. */
15490 case DW_MACRO_GNU_define_indirect
:
15491 case DW_MACRO_GNU_undef_indirect
:
15493 unsigned int bytes_read
;
15495 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15496 mac_ptr
+= bytes_read
;
15497 mac_ptr
+= offset_size
;
15501 case DW_MACRO_GNU_transparent_include
:
15502 /* Note that, according to the spec, a transparent include
15503 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15504 skip this opcode. */
15505 mac_ptr
+= offset_size
;
15508 case DW_MACINFO_vendor_ext
:
15509 /* Only skip the data by MAC_PTR. */
15510 if (!section_is_gnu
)
15512 unsigned int bytes_read
;
15514 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15515 mac_ptr
+= bytes_read
;
15516 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15517 mac_ptr
+= bytes_read
;
15522 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15523 mac_ptr
, abfd
, offset_size
,
15525 if (mac_ptr
== NULL
)
15529 } while (macinfo_type
!= 0 && current_file
== NULL
);
15531 /* Second pass: Process all entries.
15533 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15534 command-line macro definitions/undefinitions. This flag is unset when we
15535 reach the first DW_MACINFO_start_file entry. */
15537 dwarf_decode_macro_bytes (abfd
, section
->buffer
+ offset
, mac_end
,
15538 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
15539 offset_size
, objfile
);
15542 /* Check if the attribute's form is a DW_FORM_block*
15543 if so return true else false. */
15545 attr_form_is_block (struct attribute
*attr
)
15547 return (attr
== NULL
? 0 :
15548 attr
->form
== DW_FORM_block1
15549 || attr
->form
== DW_FORM_block2
15550 || attr
->form
== DW_FORM_block4
15551 || attr
->form
== DW_FORM_block
15552 || attr
->form
== DW_FORM_exprloc
);
15555 /* Return non-zero if ATTR's value is a section offset --- classes
15556 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15557 You may use DW_UNSND (attr) to retrieve such offsets.
15559 Section 7.5.4, "Attribute Encodings", explains that no attribute
15560 may have a value that belongs to more than one of these classes; it
15561 would be ambiguous if we did, because we use the same forms for all
15564 attr_form_is_section_offset (struct attribute
*attr
)
15566 return (attr
->form
== DW_FORM_data4
15567 || attr
->form
== DW_FORM_data8
15568 || attr
->form
== DW_FORM_sec_offset
);
15572 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15573 zero otherwise. When this function returns true, you can apply
15574 dwarf2_get_attr_constant_value to it.
15576 However, note that for some attributes you must check
15577 attr_form_is_section_offset before using this test. DW_FORM_data4
15578 and DW_FORM_data8 are members of both the constant class, and of
15579 the classes that contain offsets into other debug sections
15580 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15581 that, if an attribute's can be either a constant or one of the
15582 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15583 taken as section offsets, not constants. */
15585 attr_form_is_constant (struct attribute
*attr
)
15587 switch (attr
->form
)
15589 case DW_FORM_sdata
:
15590 case DW_FORM_udata
:
15591 case DW_FORM_data1
:
15592 case DW_FORM_data2
:
15593 case DW_FORM_data4
:
15594 case DW_FORM_data8
:
15601 /* A helper function that fills in a dwarf2_loclist_baton. */
15604 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15605 struct dwarf2_loclist_baton
*baton
,
15606 struct attribute
*attr
)
15608 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15609 &dwarf2_per_objfile
->loc
);
15611 baton
->per_cu
= cu
->per_cu
;
15612 gdb_assert (baton
->per_cu
);
15613 /* We don't know how long the location list is, but make sure we
15614 don't run off the edge of the section. */
15615 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15616 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15617 baton
->base_address
= cu
->base_address
;
15621 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15622 struct dwarf2_cu
*cu
)
15624 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15626 if (attr_form_is_section_offset (attr
)
15627 /* ".debug_loc" may not exist at all, or the offset may be outside
15628 the section. If so, fall through to the complaint in the
15630 && DW_UNSND (attr
) < dwarf2_section_size (objfile
,
15631 &dwarf2_per_objfile
->loc
))
15633 struct dwarf2_loclist_baton
*baton
;
15635 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15636 sizeof (struct dwarf2_loclist_baton
));
15638 fill_in_loclist_baton (cu
, baton
, attr
);
15640 if (cu
->base_known
== 0)
15641 complaint (&symfile_complaints
,
15642 _("Location list used without "
15643 "specifying the CU base address."));
15645 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15646 SYMBOL_LOCATION_BATON (sym
) = baton
;
15650 struct dwarf2_locexpr_baton
*baton
;
15652 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15653 sizeof (struct dwarf2_locexpr_baton
));
15654 baton
->per_cu
= cu
->per_cu
;
15655 gdb_assert (baton
->per_cu
);
15657 if (attr_form_is_block (attr
))
15659 /* Note that we're just copying the block's data pointer
15660 here, not the actual data. We're still pointing into the
15661 info_buffer for SYM's objfile; right now we never release
15662 that buffer, but when we do clean up properly this may
15664 baton
->size
= DW_BLOCK (attr
)->size
;
15665 baton
->data
= DW_BLOCK (attr
)->data
;
15669 dwarf2_invalid_attrib_class_complaint ("location description",
15670 SYMBOL_NATURAL_NAME (sym
));
15674 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15675 SYMBOL_LOCATION_BATON (sym
) = baton
;
15679 /* Return the OBJFILE associated with the compilation unit CU. If CU
15680 came from a separate debuginfo file, then the master objfile is
15684 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
15686 struct objfile
*objfile
= per_cu
->objfile
;
15688 /* Return the master objfile, so that we can report and look up the
15689 correct file containing this variable. */
15690 if (objfile
->separate_debug_objfile_backlink
)
15691 objfile
= objfile
->separate_debug_objfile_backlink
;
15696 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15697 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15698 CU_HEADERP first. */
15700 static const struct comp_unit_head
*
15701 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
15702 struct dwarf2_per_cu_data
*per_cu
)
15704 struct objfile
*objfile
;
15705 struct dwarf2_per_objfile
*per_objfile
;
15706 gdb_byte
*info_ptr
;
15709 return &per_cu
->cu
->header
;
15711 objfile
= per_cu
->objfile
;
15712 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15713 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
15715 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
15716 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
15721 /* Return the address size given in the compilation unit header for CU. */
15724 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15726 struct comp_unit_head cu_header_local
;
15727 const struct comp_unit_head
*cu_headerp
;
15729 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15731 return cu_headerp
->addr_size
;
15734 /* Return the offset size given in the compilation unit header for CU. */
15737 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
15739 struct comp_unit_head cu_header_local
;
15740 const struct comp_unit_head
*cu_headerp
;
15742 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15744 return cu_headerp
->offset_size
;
15747 /* See its dwarf2loc.h declaration. */
15750 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15752 struct comp_unit_head cu_header_local
;
15753 const struct comp_unit_head
*cu_headerp
;
15755 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15757 if (cu_headerp
->version
== 2)
15758 return cu_headerp
->addr_size
;
15760 return cu_headerp
->offset_size
;
15763 /* Return the text offset of the CU. The returned offset comes from
15764 this CU's objfile. If this objfile came from a separate debuginfo
15765 file, then the offset may be different from the corresponding
15766 offset in the parent objfile. */
15769 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
15771 struct objfile
*objfile
= per_cu
->objfile
;
15773 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15776 /* Locate the .debug_info compilation unit from CU's objfile which contains
15777 the DIE at OFFSET. Raises an error on failure. */
15779 static struct dwarf2_per_cu_data
*
15780 dwarf2_find_containing_comp_unit (unsigned int offset
,
15781 struct objfile
*objfile
)
15783 struct dwarf2_per_cu_data
*this_cu
;
15787 high
= dwarf2_per_objfile
->n_comp_units
- 1;
15790 int mid
= low
+ (high
- low
) / 2;
15792 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
15797 gdb_assert (low
== high
);
15798 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
15801 error (_("Dwarf Error: could not find partial DIE containing "
15802 "offset 0x%lx [in module %s]"),
15803 (long) offset
, bfd_get_filename (objfile
->obfd
));
15805 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
15806 return dwarf2_per_objfile
->all_comp_units
[low
-1];
15810 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
15811 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
15812 && offset
>= this_cu
->offset
+ this_cu
->length
)
15813 error (_("invalid dwarf2 offset %u"), offset
);
15814 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
15819 /* Locate the compilation unit from OBJFILE which is located at exactly
15820 OFFSET. Raises an error on failure. */
15822 static struct dwarf2_per_cu_data
*
15823 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
15825 struct dwarf2_per_cu_data
*this_cu
;
15827 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
15828 if (this_cu
->offset
!= offset
)
15829 error (_("no compilation unit with offset %u."), offset
);
15833 /* Initialize dwarf2_cu CU, owned by PER_CU. */
15836 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
15838 memset (cu
, 0, sizeof (*cu
));
15840 cu
->per_cu
= per_cu
;
15841 cu
->objfile
= per_cu
->objfile
;
15842 obstack_init (&cu
->comp_unit_obstack
);
15845 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15848 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
15850 struct attribute
*attr
;
15852 /* Set the language we're debugging. */
15853 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
15855 set_cu_language (DW_UNSND (attr
), cu
);
15858 cu
->language
= language_minimal
;
15859 cu
->language_defn
= language_def (cu
->language
);
15863 /* Release one cached compilation unit, CU. We unlink it from the tree
15864 of compilation units, but we don't remove it from the read_in_chain;
15865 the caller is responsible for that.
15866 NOTE: DATA is a void * because this function is also used as a
15867 cleanup routine. */
15870 free_heap_comp_unit (void *data
)
15872 struct dwarf2_cu
*cu
= data
;
15874 gdb_assert (cu
->per_cu
!= NULL
);
15875 cu
->per_cu
->cu
= NULL
;
15878 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15883 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15884 when we're finished with it. We can't free the pointer itself, but be
15885 sure to unlink it from the cache. Also release any associated storage
15886 and perform cache maintenance.
15888 Only used during partial symbol parsing. */
15891 free_stack_comp_unit (void *data
)
15893 struct dwarf2_cu
*cu
= data
;
15895 gdb_assert (cu
->per_cu
!= NULL
);
15896 cu
->per_cu
->cu
= NULL
;
15899 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15900 cu
->partial_dies
= NULL
;
15902 /* The previous code only did this if per_cu != NULL.
15903 But that would always succeed, so now we just unconditionally do
15904 the aging. This seems like the wrong place to do such aging,
15905 but cleaning that up is left for later. */
15906 age_cached_comp_units ();
15909 /* Free all cached compilation units. */
15912 free_cached_comp_units (void *data
)
15914 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15916 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15917 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15918 while (per_cu
!= NULL
)
15920 struct dwarf2_per_cu_data
*next_cu
;
15922 next_cu
= per_cu
->cu
->read_in_chain
;
15924 free_heap_comp_unit (per_cu
->cu
);
15925 *last_chain
= next_cu
;
15931 /* Increase the age counter on each cached compilation unit, and free
15932 any that are too old. */
15935 age_cached_comp_units (void)
15937 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15939 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
15940 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15941 while (per_cu
!= NULL
)
15943 per_cu
->cu
->last_used
++;
15944 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
15945 dwarf2_mark (per_cu
->cu
);
15946 per_cu
= per_cu
->cu
->read_in_chain
;
15949 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15950 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15951 while (per_cu
!= NULL
)
15953 struct dwarf2_per_cu_data
*next_cu
;
15955 next_cu
= per_cu
->cu
->read_in_chain
;
15957 if (!per_cu
->cu
->mark
)
15959 free_heap_comp_unit (per_cu
->cu
);
15960 *last_chain
= next_cu
;
15963 last_chain
= &per_cu
->cu
->read_in_chain
;
15969 /* Remove a single compilation unit from the cache. */
15972 free_one_cached_comp_unit (void *target_cu
)
15974 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15976 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15977 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15978 while (per_cu
!= NULL
)
15980 struct dwarf2_per_cu_data
*next_cu
;
15982 next_cu
= per_cu
->cu
->read_in_chain
;
15984 if (per_cu
->cu
== target_cu
)
15986 free_heap_comp_unit (per_cu
->cu
);
15987 *last_chain
= next_cu
;
15991 last_chain
= &per_cu
->cu
->read_in_chain
;
15997 /* Release all extra memory associated with OBJFILE. */
16000 dwarf2_free_objfile (struct objfile
*objfile
)
16002 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16004 if (dwarf2_per_objfile
== NULL
)
16007 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16008 free_cached_comp_units (NULL
);
16010 if (dwarf2_per_objfile
->quick_file_names_table
)
16011 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
16013 /* Everything else should be on the objfile obstack. */
16016 /* A pair of DIE offset and GDB type pointer. We store these
16017 in a hash table separate from the DIEs, and preserve them
16018 when the DIEs are flushed out of cache. */
16020 struct dwarf2_offset_and_type
16022 unsigned int offset
;
16026 /* Hash function for a dwarf2_offset_and_type. */
16029 offset_and_type_hash (const void *item
)
16031 const struct dwarf2_offset_and_type
*ofs
= item
;
16033 return ofs
->offset
;
16036 /* Equality function for a dwarf2_offset_and_type. */
16039 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
16041 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
16042 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
16044 return ofs_lhs
->offset
== ofs_rhs
->offset
;
16047 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16048 table if necessary. For convenience, return TYPE.
16050 The DIEs reading must have careful ordering to:
16051 * Not cause infite loops trying to read in DIEs as a prerequisite for
16052 reading current DIE.
16053 * Not trying to dereference contents of still incompletely read in types
16054 while reading in other DIEs.
16055 * Enable referencing still incompletely read in types just by a pointer to
16056 the type without accessing its fields.
16058 Therefore caller should follow these rules:
16059 * Try to fetch any prerequisite types we may need to build this DIE type
16060 before building the type and calling set_die_type.
16061 * After building type call set_die_type for current DIE as soon as
16062 possible before fetching more types to complete the current type.
16063 * Make the type as complete as possible before fetching more types. */
16065 static struct type
*
16066 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16068 struct dwarf2_offset_and_type
**slot
, ofs
;
16069 struct objfile
*objfile
= cu
->objfile
;
16070 htab_t
*type_hash_ptr
;
16072 /* For Ada types, make sure that the gnat-specific data is always
16073 initialized (if not already set). There are a few types where
16074 we should not be doing so, because the type-specific area is
16075 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16076 where the type-specific area is used to store the floatformat).
16077 But this is not a problem, because the gnat-specific information
16078 is actually not needed for these types. */
16079 if (need_gnat_info (cu
)
16080 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16081 && TYPE_CODE (type
) != TYPE_CODE_FLT
16082 && !HAVE_GNAT_AUX_INFO (type
))
16083 INIT_GNAT_SPECIFIC (type
);
16085 if (cu
->per_cu
->debug_types_section
)
16086 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
16088 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
16090 if (*type_hash_ptr
== NULL
)
16093 = htab_create_alloc_ex (127,
16094 offset_and_type_hash
,
16095 offset_and_type_eq
,
16097 &objfile
->objfile_obstack
,
16098 hashtab_obstack_allocate
,
16099 dummy_obstack_deallocate
);
16102 ofs
.offset
= die
->offset
;
16104 slot
= (struct dwarf2_offset_and_type
**)
16105 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
16107 complaint (&symfile_complaints
,
16108 _("A problem internal to GDB: DIE 0x%x has type already set"),
16110 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16115 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
16116 table, or return NULL if the die does not have a saved type. */
16118 static struct type
*
16119 get_die_type_at_offset (unsigned int offset
,
16120 struct dwarf2_per_cu_data
*per_cu
)
16122 struct dwarf2_offset_and_type
*slot
, ofs
;
16125 if (per_cu
->debug_types_section
)
16126 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
16128 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
16129 if (type_hash
== NULL
)
16132 ofs
.offset
= offset
;
16133 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
16140 /* Look up the type for DIE in the appropriate type_hash table,
16141 or return NULL if DIE does not have a saved type. */
16143 static struct type
*
16144 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16146 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16149 /* Add a dependence relationship from CU to REF_PER_CU. */
16152 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16153 struct dwarf2_per_cu_data
*ref_per_cu
)
16157 if (cu
->dependencies
== NULL
)
16159 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16160 NULL
, &cu
->comp_unit_obstack
,
16161 hashtab_obstack_allocate
,
16162 dummy_obstack_deallocate
);
16164 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16166 *slot
= ref_per_cu
;
16169 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16170 Set the mark field in every compilation unit in the
16171 cache that we must keep because we are keeping CU. */
16174 dwarf2_mark_helper (void **slot
, void *data
)
16176 struct dwarf2_per_cu_data
*per_cu
;
16178 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
16180 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16181 reading of the chain. As such dependencies remain valid it is not much
16182 useful to track and undo them during QUIT cleanups. */
16183 if (per_cu
->cu
== NULL
)
16186 if (per_cu
->cu
->mark
)
16188 per_cu
->cu
->mark
= 1;
16190 if (per_cu
->cu
->dependencies
!= NULL
)
16191 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16196 /* Set the mark field in CU and in every other compilation unit in the
16197 cache that we must keep because we are keeping CU. */
16200 dwarf2_mark (struct dwarf2_cu
*cu
)
16205 if (cu
->dependencies
!= NULL
)
16206 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16210 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
16214 per_cu
->cu
->mark
= 0;
16215 per_cu
= per_cu
->cu
->read_in_chain
;
16219 /* Trivial hash function for partial_die_info: the hash value of a DIE
16220 is its offset in .debug_info for this objfile. */
16223 partial_die_hash (const void *item
)
16225 const struct partial_die_info
*part_die
= item
;
16227 return part_die
->offset
;
16230 /* Trivial comparison function for partial_die_info structures: two DIEs
16231 are equal if they have the same offset. */
16234 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
16236 const struct partial_die_info
*part_die_lhs
= item_lhs
;
16237 const struct partial_die_info
*part_die_rhs
= item_rhs
;
16239 return part_die_lhs
->offset
== part_die_rhs
->offset
;
16242 static struct cmd_list_element
*set_dwarf2_cmdlist
;
16243 static struct cmd_list_element
*show_dwarf2_cmdlist
;
16246 set_dwarf2_cmd (char *args
, int from_tty
)
16248 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
16252 show_dwarf2_cmd (char *args
, int from_tty
)
16254 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
16257 /* If section described by INFO was mmapped, munmap it now. */
16260 munmap_section_buffer (struct dwarf2_section_info
*info
)
16262 if (info
->map_addr
!= NULL
)
16267 res
= munmap (info
->map_addr
, info
->map_len
);
16268 gdb_assert (res
== 0);
16270 /* Without HAVE_MMAP, we should never be here to begin with. */
16271 gdb_assert_not_reached ("no mmap support");
16276 /* munmap debug sections for OBJFILE, if necessary. */
16279 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
16281 struct dwarf2_per_objfile
*data
= d
;
16283 struct dwarf2_section_info
*section
;
16285 /* This is sorted according to the order they're defined in to make it easier
16286 to keep in sync. */
16287 munmap_section_buffer (&data
->info
);
16288 munmap_section_buffer (&data
->abbrev
);
16289 munmap_section_buffer (&data
->line
);
16290 munmap_section_buffer (&data
->loc
);
16291 munmap_section_buffer (&data
->macinfo
);
16292 munmap_section_buffer (&data
->macro
);
16293 munmap_section_buffer (&data
->str
);
16294 munmap_section_buffer (&data
->ranges
);
16295 munmap_section_buffer (&data
->frame
);
16296 munmap_section_buffer (&data
->eh_frame
);
16297 munmap_section_buffer (&data
->gdb_index
);
16300 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
16302 munmap_section_buffer (section
);
16304 VEC_free (dwarf2_section_info_def
, data
->types
);
16308 /* The "save gdb-index" command. */
16310 /* The contents of the hash table we create when building the string
16312 struct strtab_entry
16314 offset_type offset
;
16318 /* Hash function for a strtab_entry.
16320 Function is used only during write_hash_table so no index format backward
16321 compatibility is needed. */
16324 hash_strtab_entry (const void *e
)
16326 const struct strtab_entry
*entry
= e
;
16327 return mapped_index_string_hash (INT_MAX
, entry
->str
);
16330 /* Equality function for a strtab_entry. */
16333 eq_strtab_entry (const void *a
, const void *b
)
16335 const struct strtab_entry
*ea
= a
;
16336 const struct strtab_entry
*eb
= b
;
16337 return !strcmp (ea
->str
, eb
->str
);
16340 /* Create a strtab_entry hash table. */
16343 create_strtab (void)
16345 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
16346 xfree
, xcalloc
, xfree
);
16349 /* Add a string to the constant pool. Return the string's offset in
16353 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
16356 struct strtab_entry entry
;
16357 struct strtab_entry
*result
;
16360 slot
= htab_find_slot (table
, &entry
, INSERT
);
16365 result
= XNEW (struct strtab_entry
);
16366 result
->offset
= obstack_object_size (cpool
);
16368 obstack_grow_str0 (cpool
, str
);
16371 return result
->offset
;
16374 /* An entry in the symbol table. */
16375 struct symtab_index_entry
16377 /* The name of the symbol. */
16379 /* The offset of the name in the constant pool. */
16380 offset_type index_offset
;
16381 /* A sorted vector of the indices of all the CUs that hold an object
16383 VEC (offset_type
) *cu_indices
;
16386 /* The symbol table. This is a power-of-2-sized hash table. */
16387 struct mapped_symtab
16389 offset_type n_elements
;
16391 struct symtab_index_entry
**data
;
16394 /* Hash function for a symtab_index_entry. */
16397 hash_symtab_entry (const void *e
)
16399 const struct symtab_index_entry
*entry
= e
;
16400 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
16401 sizeof (offset_type
) * VEC_length (offset_type
,
16402 entry
->cu_indices
),
16406 /* Equality function for a symtab_index_entry. */
16409 eq_symtab_entry (const void *a
, const void *b
)
16411 const struct symtab_index_entry
*ea
= a
;
16412 const struct symtab_index_entry
*eb
= b
;
16413 int len
= VEC_length (offset_type
, ea
->cu_indices
);
16414 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
16416 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
16417 VEC_address (offset_type
, eb
->cu_indices
),
16418 sizeof (offset_type
) * len
);
16421 /* Destroy a symtab_index_entry. */
16424 delete_symtab_entry (void *p
)
16426 struct symtab_index_entry
*entry
= p
;
16427 VEC_free (offset_type
, entry
->cu_indices
);
16431 /* Create a hash table holding symtab_index_entry objects. */
16434 create_symbol_hash_table (void)
16436 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
16437 delete_symtab_entry
, xcalloc
, xfree
);
16440 /* Create a new mapped symtab object. */
16442 static struct mapped_symtab
*
16443 create_mapped_symtab (void)
16445 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
16446 symtab
->n_elements
= 0;
16447 symtab
->size
= 1024;
16448 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16452 /* Destroy a mapped_symtab. */
16455 cleanup_mapped_symtab (void *p
)
16457 struct mapped_symtab
*symtab
= p
;
16458 /* The contents of the array are freed when the other hash table is
16460 xfree (symtab
->data
);
16464 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16467 Function is used only during write_hash_table so no index format backward
16468 compatibility is needed. */
16470 static struct symtab_index_entry
**
16471 find_slot (struct mapped_symtab
*symtab
, const char *name
)
16473 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
16475 index
= hash
& (symtab
->size
- 1);
16476 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
16480 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
16481 return &symtab
->data
[index
];
16482 index
= (index
+ step
) & (symtab
->size
- 1);
16486 /* Expand SYMTAB's hash table. */
16489 hash_expand (struct mapped_symtab
*symtab
)
16491 offset_type old_size
= symtab
->size
;
16493 struct symtab_index_entry
**old_entries
= symtab
->data
;
16496 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16498 for (i
= 0; i
< old_size
; ++i
)
16500 if (old_entries
[i
])
16502 struct symtab_index_entry
**slot
= find_slot (symtab
,
16503 old_entries
[i
]->name
);
16504 *slot
= old_entries
[i
];
16508 xfree (old_entries
);
16511 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16512 is the index of the CU in which the symbol appears. */
16515 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
16516 offset_type cu_index
)
16518 struct symtab_index_entry
**slot
;
16520 ++symtab
->n_elements
;
16521 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
16522 hash_expand (symtab
);
16524 slot
= find_slot (symtab
, name
);
16527 *slot
= XNEW (struct symtab_index_entry
);
16528 (*slot
)->name
= name
;
16529 (*slot
)->cu_indices
= NULL
;
16531 /* Don't push an index twice. Due to how we add entries we only
16532 have to check the last one. */
16533 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
16534 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
16535 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
16538 /* Add a vector of indices to the constant pool. */
16541 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
16542 struct symtab_index_entry
*entry
)
16546 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
16549 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
16550 offset_type val
= MAYBE_SWAP (len
);
16555 entry
->index_offset
= obstack_object_size (cpool
);
16557 obstack_grow (cpool
, &val
, sizeof (val
));
16559 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
16562 val
= MAYBE_SWAP (iter
);
16563 obstack_grow (cpool
, &val
, sizeof (val
));
16568 struct symtab_index_entry
*old_entry
= *slot
;
16569 entry
->index_offset
= old_entry
->index_offset
;
16572 return entry
->index_offset
;
16575 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16576 constant pool entries going into the obstack CPOOL. */
16579 write_hash_table (struct mapped_symtab
*symtab
,
16580 struct obstack
*output
, struct obstack
*cpool
)
16583 htab_t symbol_hash_table
;
16586 symbol_hash_table
= create_symbol_hash_table ();
16587 str_table
= create_strtab ();
16589 /* We add all the index vectors to the constant pool first, to
16590 ensure alignment is ok. */
16591 for (i
= 0; i
< symtab
->size
; ++i
)
16593 if (symtab
->data
[i
])
16594 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
16597 /* Now write out the hash table. */
16598 for (i
= 0; i
< symtab
->size
; ++i
)
16600 offset_type str_off
, vec_off
;
16602 if (symtab
->data
[i
])
16604 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
16605 vec_off
= symtab
->data
[i
]->index_offset
;
16609 /* While 0 is a valid constant pool index, it is not valid
16610 to have 0 for both offsets. */
16615 str_off
= MAYBE_SWAP (str_off
);
16616 vec_off
= MAYBE_SWAP (vec_off
);
16618 obstack_grow (output
, &str_off
, sizeof (str_off
));
16619 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
16622 htab_delete (str_table
);
16623 htab_delete (symbol_hash_table
);
16626 /* Struct to map psymtab to CU index in the index file. */
16627 struct psymtab_cu_index_map
16629 struct partial_symtab
*psymtab
;
16630 unsigned int cu_index
;
16634 hash_psymtab_cu_index (const void *item
)
16636 const struct psymtab_cu_index_map
*map
= item
;
16638 return htab_hash_pointer (map
->psymtab
);
16642 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16644 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16645 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16647 return lhs
->psymtab
== rhs
->psymtab
;
16650 /* Helper struct for building the address table. */
16651 struct addrmap_index_data
16653 struct objfile
*objfile
;
16654 struct obstack
*addr_obstack
;
16655 htab_t cu_index_htab
;
16657 /* Non-zero if the previous_* fields are valid.
16658 We can't write an entry until we see the next entry (since it is only then
16659 that we know the end of the entry). */
16660 int previous_valid
;
16661 /* Index of the CU in the table of all CUs in the index file. */
16662 unsigned int previous_cu_index
;
16663 /* Start address of the CU. */
16664 CORE_ADDR previous_cu_start
;
16667 /* Write an address entry to OBSTACK. */
16670 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16671 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16673 offset_type cu_index_to_write
;
16675 CORE_ADDR baseaddr
;
16677 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16679 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16680 obstack_grow (obstack
, addr
, 8);
16681 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16682 obstack_grow (obstack
, addr
, 8);
16683 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16684 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16687 /* Worker function for traversing an addrmap to build the address table. */
16690 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
16692 struct addrmap_index_data
*data
= datap
;
16693 struct partial_symtab
*pst
= obj
;
16694 offset_type cu_index
;
16697 if (data
->previous_valid
)
16698 add_address_entry (data
->objfile
, data
->addr_obstack
,
16699 data
->previous_cu_start
, start_addr
,
16700 data
->previous_cu_index
);
16702 data
->previous_cu_start
= start_addr
;
16705 struct psymtab_cu_index_map find_map
, *map
;
16706 find_map
.psymtab
= pst
;
16707 map
= htab_find (data
->cu_index_htab
, &find_map
);
16708 gdb_assert (map
!= NULL
);
16709 data
->previous_cu_index
= map
->cu_index
;
16710 data
->previous_valid
= 1;
16713 data
->previous_valid
= 0;
16718 /* Write OBJFILE's address map to OBSTACK.
16719 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16720 in the index file. */
16723 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
16724 htab_t cu_index_htab
)
16726 struct addrmap_index_data addrmap_index_data
;
16728 /* When writing the address table, we have to cope with the fact that
16729 the addrmap iterator only provides the start of a region; we have to
16730 wait until the next invocation to get the start of the next region. */
16732 addrmap_index_data
.objfile
= objfile
;
16733 addrmap_index_data
.addr_obstack
= obstack
;
16734 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
16735 addrmap_index_data
.previous_valid
= 0;
16737 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
16738 &addrmap_index_data
);
16740 /* It's highly unlikely the last entry (end address = 0xff...ff)
16741 is valid, but we should still handle it.
16742 The end address is recorded as the start of the next region, but that
16743 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16745 if (addrmap_index_data
.previous_valid
)
16746 add_address_entry (objfile
, obstack
,
16747 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
16748 addrmap_index_data
.previous_cu_index
);
16751 /* Add a list of partial symbols to SYMTAB. */
16754 write_psymbols (struct mapped_symtab
*symtab
,
16756 struct partial_symbol
**psymp
,
16758 offset_type cu_index
,
16761 for (; count
-- > 0; ++psymp
)
16763 void **slot
, *lookup
;
16765 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
16766 error (_("Ada is not currently supported by the index"));
16768 /* We only want to add a given psymbol once. However, we also
16769 want to account for whether it is global or static. So, we
16770 may add it twice, using slightly different values. */
16773 uintptr_t val
= 1 | (uintptr_t) *psymp
;
16775 lookup
= (void *) val
;
16780 /* Only add a given psymbol once. */
16781 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
16785 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (*psymp
), cu_index
);
16790 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16791 exception if there is an error. */
16794 write_obstack (FILE *file
, struct obstack
*obstack
)
16796 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
16798 != obstack_object_size (obstack
))
16799 error (_("couldn't data write to file"));
16802 /* Unlink a file if the argument is not NULL. */
16805 unlink_if_set (void *p
)
16807 char **filename
= p
;
16809 unlink (*filename
);
16812 /* A helper struct used when iterating over debug_types. */
16813 struct signatured_type_index_data
16815 struct objfile
*objfile
;
16816 struct mapped_symtab
*symtab
;
16817 struct obstack
*types_list
;
16822 /* A helper function that writes a single signatured_type to an
16826 write_one_signatured_type (void **slot
, void *d
)
16828 struct signatured_type_index_data
*info
= d
;
16829 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
16830 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
16831 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16834 write_psymbols (info
->symtab
,
16836 info
->objfile
->global_psymbols
.list
16837 + psymtab
->globals_offset
,
16838 psymtab
->n_global_syms
, info
->cu_index
,
16840 write_psymbols (info
->symtab
,
16842 info
->objfile
->static_psymbols
.list
16843 + psymtab
->statics_offset
,
16844 psymtab
->n_static_syms
, info
->cu_index
,
16847 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->per_cu
.offset
);
16848 obstack_grow (info
->types_list
, val
, 8);
16849 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
16850 obstack_grow (info
->types_list
, val
, 8);
16851 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
16852 obstack_grow (info
->types_list
, val
, 8);
16859 /* Create an index file for OBJFILE in the directory DIR. */
16862 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
16864 struct cleanup
*cleanup
;
16865 char *filename
, *cleanup_filename
;
16866 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
16867 struct obstack cu_list
, types_cu_list
;
16870 struct mapped_symtab
*symtab
;
16871 offset_type val
, size_of_contents
, total_len
;
16875 htab_t cu_index_htab
;
16876 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
16878 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
16881 if (dwarf2_per_objfile
->using_index
)
16882 error (_("Cannot use an index to create the index"));
16884 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
16885 error (_("Cannot make an index when the file has multiple .debug_types sections"));
16887 if (stat (objfile
->name
, &st
) < 0)
16888 perror_with_name (objfile
->name
);
16890 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
16891 INDEX_SUFFIX
, (char *) NULL
);
16892 cleanup
= make_cleanup (xfree
, filename
);
16894 out_file
= fopen (filename
, "wb");
16896 error (_("Can't open `%s' for writing"), filename
);
16898 cleanup_filename
= filename
;
16899 make_cleanup (unlink_if_set
, &cleanup_filename
);
16901 symtab
= create_mapped_symtab ();
16902 make_cleanup (cleanup_mapped_symtab
, symtab
);
16904 obstack_init (&addr_obstack
);
16905 make_cleanup_obstack_free (&addr_obstack
);
16907 obstack_init (&cu_list
);
16908 make_cleanup_obstack_free (&cu_list
);
16910 obstack_init (&types_cu_list
);
16911 make_cleanup_obstack_free (&types_cu_list
);
16913 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
16914 NULL
, xcalloc
, xfree
);
16915 make_cleanup_htab_delete (psyms_seen
);
16917 /* While we're scanning CU's create a table that maps a psymtab pointer
16918 (which is what addrmap records) to its index (which is what is recorded
16919 in the index file). This will later be needed to write the address
16921 cu_index_htab
= htab_create_alloc (100,
16922 hash_psymtab_cu_index
,
16923 eq_psymtab_cu_index
,
16924 NULL
, xcalloc
, xfree
);
16925 make_cleanup_htab_delete (cu_index_htab
);
16926 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
16927 xmalloc (sizeof (struct psymtab_cu_index_map
)
16928 * dwarf2_per_objfile
->n_comp_units
);
16929 make_cleanup (xfree
, psymtab_cu_index_map
);
16931 /* The CU list is already sorted, so we don't need to do additional
16932 work here. Also, the debug_types entries do not appear in
16933 all_comp_units, but only in their own hash table. */
16934 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
16936 struct dwarf2_per_cu_data
*per_cu
16937 = dwarf2_per_objfile
->all_comp_units
[i
];
16938 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16940 struct psymtab_cu_index_map
*map
;
16943 write_psymbols (symtab
,
16945 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
16946 psymtab
->n_global_syms
, i
,
16948 write_psymbols (symtab
,
16950 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
16951 psymtab
->n_static_syms
, i
,
16954 map
= &psymtab_cu_index_map
[i
];
16955 map
->psymtab
= psymtab
;
16957 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
16958 gdb_assert (slot
!= NULL
);
16959 gdb_assert (*slot
== NULL
);
16962 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
16963 obstack_grow (&cu_list
, val
, 8);
16964 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
16965 obstack_grow (&cu_list
, val
, 8);
16968 /* Dump the address map. */
16969 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
16971 /* Write out the .debug_type entries, if any. */
16972 if (dwarf2_per_objfile
->signatured_types
)
16974 struct signatured_type_index_data sig_data
;
16976 sig_data
.objfile
= objfile
;
16977 sig_data
.symtab
= symtab
;
16978 sig_data
.types_list
= &types_cu_list
;
16979 sig_data
.psyms_seen
= psyms_seen
;
16980 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
16981 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
16982 write_one_signatured_type
, &sig_data
);
16985 obstack_init (&constant_pool
);
16986 make_cleanup_obstack_free (&constant_pool
);
16987 obstack_init (&symtab_obstack
);
16988 make_cleanup_obstack_free (&symtab_obstack
);
16989 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
16991 obstack_init (&contents
);
16992 make_cleanup_obstack_free (&contents
);
16993 size_of_contents
= 6 * sizeof (offset_type
);
16994 total_len
= size_of_contents
;
16996 /* The version number. */
16997 val
= MAYBE_SWAP (5);
16998 obstack_grow (&contents
, &val
, sizeof (val
));
17000 /* The offset of the CU list from the start of the file. */
17001 val
= MAYBE_SWAP (total_len
);
17002 obstack_grow (&contents
, &val
, sizeof (val
));
17003 total_len
+= obstack_object_size (&cu_list
);
17005 /* The offset of the types CU list from the start of the file. */
17006 val
= MAYBE_SWAP (total_len
);
17007 obstack_grow (&contents
, &val
, sizeof (val
));
17008 total_len
+= obstack_object_size (&types_cu_list
);
17010 /* The offset of the address table from the start of the file. */
17011 val
= MAYBE_SWAP (total_len
);
17012 obstack_grow (&contents
, &val
, sizeof (val
));
17013 total_len
+= obstack_object_size (&addr_obstack
);
17015 /* The offset of the symbol table from the start of the file. */
17016 val
= MAYBE_SWAP (total_len
);
17017 obstack_grow (&contents
, &val
, sizeof (val
));
17018 total_len
+= obstack_object_size (&symtab_obstack
);
17020 /* The offset of the constant pool from the start of the file. */
17021 val
= MAYBE_SWAP (total_len
);
17022 obstack_grow (&contents
, &val
, sizeof (val
));
17023 total_len
+= obstack_object_size (&constant_pool
);
17025 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
17027 write_obstack (out_file
, &contents
);
17028 write_obstack (out_file
, &cu_list
);
17029 write_obstack (out_file
, &types_cu_list
);
17030 write_obstack (out_file
, &addr_obstack
);
17031 write_obstack (out_file
, &symtab_obstack
);
17032 write_obstack (out_file
, &constant_pool
);
17036 /* We want to keep the file, so we set cleanup_filename to NULL
17037 here. See unlink_if_set. */
17038 cleanup_filename
= NULL
;
17040 do_cleanups (cleanup
);
17043 /* Implementation of the `save gdb-index' command.
17045 Note that the file format used by this command is documented in the
17046 GDB manual. Any changes here must be documented there. */
17049 save_gdb_index_command (char *arg
, int from_tty
)
17051 struct objfile
*objfile
;
17054 error (_("usage: save gdb-index DIRECTORY"));
17056 ALL_OBJFILES (objfile
)
17060 /* If the objfile does not correspond to an actual file, skip it. */
17061 if (stat (objfile
->name
, &st
) < 0)
17064 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17065 if (dwarf2_per_objfile
)
17067 volatile struct gdb_exception except
;
17069 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17071 write_psymtabs_to_index (objfile
, arg
);
17073 if (except
.reason
< 0)
17074 exception_fprintf (gdb_stderr
, except
,
17075 _("Error while writing index for `%s': "),
17083 int dwarf2_always_disassemble
;
17086 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17087 struct cmd_list_element
*c
, const char *value
)
17089 fprintf_filtered (file
,
17090 _("Whether to always disassemble "
17091 "DWARF expressions is %s.\n"),
17096 show_check_physname (struct ui_file
*file
, int from_tty
,
17097 struct cmd_list_element
*c
, const char *value
)
17099 fprintf_filtered (file
,
17100 _("Whether to check \"physname\" is %s.\n"),
17104 void _initialize_dwarf2_read (void);
17107 _initialize_dwarf2_read (void)
17109 struct cmd_list_element
*c
;
17111 dwarf2_objfile_data_key
17112 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17114 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17115 Set DWARF 2 specific variables.\n\
17116 Configure DWARF 2 variables such as the cache size"),
17117 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17118 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17120 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17121 Show DWARF 2 specific variables\n\
17122 Show DWARF 2 variables such as the cache size"),
17123 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17124 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17126 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17127 &dwarf2_max_cache_age
, _("\
17128 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17129 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17130 A higher limit means that cached compilation units will be stored\n\
17131 in memory longer, and more total memory will be used. Zero disables\n\
17132 caching, which can slow down startup."),
17134 show_dwarf2_max_cache_age
,
17135 &set_dwarf2_cmdlist
,
17136 &show_dwarf2_cmdlist
);
17138 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17139 &dwarf2_always_disassemble
, _("\
17140 Set whether `info address' always disassembles DWARF expressions."), _("\
17141 Show whether `info address' always disassembles DWARF expressions."), _("\
17142 When enabled, DWARF expressions are always printed in an assembly-like\n\
17143 syntax. When disabled, expressions will be printed in a more\n\
17144 conversational style, when possible."),
17146 show_dwarf2_always_disassemble
,
17147 &set_dwarf2_cmdlist
,
17148 &show_dwarf2_cmdlist
);
17150 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
17151 Set debugging of the dwarf2 DIE reader."), _("\
17152 Show debugging of the dwarf2 DIE reader."), _("\
17153 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17154 The value is the maximum depth to print."),
17157 &setdebuglist
, &showdebuglist
);
17159 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
17160 Set cross-checking of \"physname\" code against demangler."), _("\
17161 Show cross-checking of \"physname\" code against demangler."), _("\
17162 When enabled, GDB's internal \"physname\" code is checked against\n\
17164 NULL
, show_check_physname
,
17165 &setdebuglist
, &showdebuglist
);
17167 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
17169 Save a gdb-index file.\n\
17170 Usage: save gdb-index DIRECTORY"),
17172 set_cmd_completer (c
, filename_completer
);